xref: /AOO41X/main/vcl/source/control/fixed.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include "tools/rc.h"
28 
29 #include "vcl/decoview.hxx"
30 #include "vcl/event.hxx"
31 #include "vcl/fixed.hxx"
32 
33 #include "controldata.hxx"
34 #include "window.h"
35 
36 // =======================================================================
37 
38 #define FIXEDLINE_TEXT_BORDER    4
39 
40 #define FIXEDTEXT_VIEW_STYLE    (WB_3DLOOK |                        \
41                                  WB_LEFT | WB_CENTER | WB_RIGHT |   \
42                                  WB_TOP | WB_VCENTER | WB_BOTTOM |  \
43                                  WB_WORDBREAK | WB_NOLABEL |        \
44                                  WB_INFO | WB_PATHELLIPSIS)
45 #define FIXEDLINE_VIEW_STYLE    (WB_3DLOOK | WB_NOLABEL)
46 #define FIXEDBITMAP_VIEW_STYLE  (WB_3DLOOK |                        \
47                                  WB_LEFT | WB_CENTER | WB_RIGHT |   \
48                                  WB_TOP | WB_VCENTER | WB_BOTTOM |  \
49                                  WB_SCALE)
50 #define FIXEDIMAGE_VIEW_STYLE   (WB_3DLOOK |                        \
51                                  WB_LEFT | WB_CENTER | WB_RIGHT |   \
52                                  WB_TOP | WB_VCENTER | WB_BOTTOM |  \
53                                  WB_SCALE)
54 
55 // =======================================================================
56 
ImplCalcPos(WinBits nStyle,const Point & rPos,const Size & rObjSize,const Size & rWinSize)57 static Point ImplCalcPos( WinBits nStyle, const Point& rPos,
58                           const Size& rObjSize, const Size& rWinSize )
59 {
60     long    nX;
61     long    nY;
62 
63     if ( nStyle & WB_LEFT )
64         nX = 0;
65     else if ( nStyle & WB_RIGHT )
66         nX = rWinSize.Width()-rObjSize.Width();
67     else
68         nX = (rWinSize.Width()-rObjSize.Width())/2;
69 
70     if ( nStyle & WB_TOP )
71         nY = 0;
72     else if ( nStyle & WB_BOTTOM )
73         nY = rWinSize.Height()-rObjSize.Height();
74     else
75         nY = (rWinSize.Height()-rObjSize.Height())/2;
76 
77     if ( nStyle & WB_TOPLEFTVISIBLE )
78     {
79         if ( nX < 0 )
80             nX = 0;
81         if ( nY < 0 )
82             nY = 0;
83     }
84 
85     Point aPos( nX+rPos.X(), nY+rPos.Y() );
86     return aPos;
87 }
88 
89 // =======================================================================
90 
ImplInit(Window * pParent,WinBits nStyle)91 void FixedText::ImplInit( Window* pParent, WinBits nStyle )
92 {
93     nStyle = ImplInitStyle( nStyle );
94     Control::ImplInit( pParent, nStyle, NULL );
95     ImplInitSettings( sal_True, sal_True, sal_True );
96 }
97 
98 // -----------------------------------------------------------------------
99 
ImplInitStyle(WinBits nStyle)100 WinBits FixedText::ImplInitStyle( WinBits nStyle )
101 {
102     if ( !(nStyle & WB_NOGROUP) )
103         nStyle |= WB_GROUP;
104     return nStyle;
105 }
106 
107 // -----------------------------------------------------------------
108 
GetCanonicalFont(const StyleSettings & _rStyle) const109 const Font& FixedText::GetCanonicalFont( const StyleSettings& _rStyle ) const
110 {
111     return ( GetStyle() & WB_INFO ) ? _rStyle.GetInfoFont() : _rStyle.GetLabelFont();
112 }
113 
114 // -----------------------------------------------------------------
GetCanonicalTextColor(const StyleSettings & _rStyle) const115 const Color& FixedText::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
116 {
117     return ( GetStyle() & WB_INFO ) ? _rStyle.GetInfoTextColor() : _rStyle.GetLabelTextColor();
118 }
119 
120 // -----------------------------------------------------------------------
121 
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)122 void FixedText::ImplInitSettings( sal_Bool bFont,
123                                   sal_Bool bForeground, sal_Bool bBackground )
124 {
125     Control::ImplInitSettings( bFont, bForeground );
126 
127     if ( bBackground )
128     {
129         Window* pParent = GetParent();
130         if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
131         {
132             EnableChildTransparentMode( sal_True );
133             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
134             SetPaintTransparent( sal_True );
135             SetBackground();
136         }
137         else
138         {
139             EnableChildTransparentMode( sal_False );
140             SetParentClipMode( 0 );
141             SetPaintTransparent( sal_False );
142 
143             if ( IsControlBackground() )
144                 SetBackground( GetControlBackground() );
145             else
146                 SetBackground( pParent->GetBackground() );
147         }
148     }
149 }
150 
151 // -----------------------------------------------------------------------
152 
FixedText(Window * pParent,WinBits nStyle)153 FixedText::FixedText( Window* pParent, WinBits nStyle ) :
154     Control( WINDOW_FIXEDTEXT )
155 {
156     ImplInit( pParent, nStyle );
157 }
158 
159 // -----------------------------------------------------------------------
160 
FixedText(Window * pParent,const ResId & rResId)161 FixedText::FixedText( Window* pParent, const ResId& rResId ) :
162     Control( WINDOW_FIXEDTEXT )
163 {
164     rResId.SetRT( RSC_TEXT );
165     WinBits nStyle = ImplInitRes( rResId );
166     ImplInit( pParent, nStyle );
167     ImplLoadRes( rResId );
168 
169     if ( !(nStyle & WB_HIDE) )
170         Show();
171 }
172 
173 // -----------------------------------------------------------------------
174 
FixedText(Window * pParent,const ResId & rResId,bool bDisableAccessibleLabelForRelation)175 FixedText::FixedText( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabelForRelation ) :
176     Control( WINDOW_FIXEDTEXT )
177 {
178     rResId.SetRT( RSC_TEXT );
179     WinBits nStyle = ImplInitRes( rResId );
180     ImplInit( pParent, nStyle );
181     ImplLoadRes( rResId );
182     if ( bDisableAccessibleLabelForRelation )
183         ImplGetWindowImpl()->mbDisableAccessibleLabelForRelation = sal_True;
184 
185     if ( !(nStyle & WB_HIDE) )
186         Show();
187 }
188 
189 // -----------------------------------------------------------------------
190 
ImplGetTextStyle(WinBits nWinStyle)191 sal_uInt16 FixedText::ImplGetTextStyle( WinBits nWinStyle )
192 {
193     sal_uInt16 nTextStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_ENDELLIPSIS;
194 
195     if( ! (nWinStyle & WB_NOMULTILINE) )
196         nTextStyle |= TEXT_DRAW_MULTILINE;
197 
198     if ( nWinStyle & WB_RIGHT )
199         nTextStyle |= TEXT_DRAW_RIGHT;
200     else if ( nWinStyle & WB_CENTER )
201         nTextStyle |= TEXT_DRAW_CENTER;
202     else
203         nTextStyle |= TEXT_DRAW_LEFT;
204     if ( nWinStyle & WB_BOTTOM )
205         nTextStyle |= TEXT_DRAW_BOTTOM;
206     else if ( nWinStyle & WB_VCENTER )
207         nTextStyle |= TEXT_DRAW_VCENTER;
208     else
209         nTextStyle |= TEXT_DRAW_TOP;
210     if ( nWinStyle & WB_WORDBREAK )
211     {
212         nTextStyle |= TEXT_DRAW_WORDBREAK;
213         if ( (nWinStyle & WB_HYPHENATION ) == WB_HYPHENATION )
214             nTextStyle |= TEXT_DRAW_WORDBREAK_HYPHENATION;
215     }
216     if ( nWinStyle & WB_NOLABEL )
217         nTextStyle &= ~TEXT_DRAW_MNEMONIC;
218 
219     return nTextStyle;
220 }
221 
222 // -----------------------------------------------------------------------
223 
ImplDraw(OutputDevice * pDev,sal_uLong nDrawFlags,const Point & rPos,const Size & rSize,bool bFillLayout) const224 void FixedText::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
225                           const Point& rPos, const Size& rSize,
226                           bool bFillLayout
227                           ) const
228 {
229     const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
230     WinBits                 nWinStyle = GetStyle();
231     XubString               aText( GetText() );
232     sal_uInt16                  nTextStyle = FixedText::ImplGetTextStyle( nWinStyle );
233     Point                   aPos = rPos;
234 
235     if ( nWinStyle & WB_EXTRAOFFSET )
236         aPos.X() += 2;
237 
238     if ( nWinStyle & WB_PATHELLIPSIS )
239     {
240         nTextStyle &= ~(TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK);
241         nTextStyle |= TEXT_DRAW_PATHELLIPSIS;
242     }
243     if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
244     {
245         if ( nTextStyle & TEXT_DRAW_MNEMONIC )
246         {
247             aText = GetNonMnemonicString( aText );
248             nTextStyle &= ~TEXT_DRAW_MNEMONIC;
249         }
250     }
251     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
252     {
253         if ( !IsEnabled() )
254             nTextStyle |= TEXT_DRAW_DISABLE;
255     }
256     if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
257          (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
258         nTextStyle |= TEXT_DRAW_MONO;
259 
260     if( bFillLayout )
261         mpControlData->mpLayoutData->m_aDisplayText = String();
262 
263     Rectangle aRect( Rectangle( aPos, rSize ) );
264     DrawControlText( *pDev, aRect, aText, nTextStyle,
265         bFillLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL,
266         bFillLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL
267     );
268 }
269 
270 // -----------------------------------------------------------------------
271 
Paint(const Rectangle &)272 void FixedText::Paint( const Rectangle& )
273 {
274     ImplDraw( this, 0, Point(), GetOutputSizePixel() );
275 }
276 
277 // -----------------------------------------------------------------------
278 
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)279 void FixedText::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
280                       sal_uLong nFlags )
281 {
282     ImplInitSettings( sal_True, sal_True, sal_True );
283 
284     Point       aPos  = pDev->LogicToPixel( rPos );
285     Size        aSize = pDev->LogicToPixel( rSize );
286     Font        aFont = GetDrawPixelFont( pDev );
287 
288     pDev->Push();
289     pDev->SetMapMode();
290     pDev->SetFont( aFont );
291     if ( nFlags & WINDOW_DRAW_MONO )
292         pDev->SetTextColor( Color( COL_BLACK ) );
293     else
294         pDev->SetTextColor( GetTextColor() );
295     pDev->SetTextFillColor();
296 
297     sal_Bool bBorder = !(nFlags & WINDOW_DRAW_NOBORDER ) && (GetStyle() & WB_BORDER);
298     sal_Bool bBackground = !(nFlags & WINDOW_DRAW_NOBACKGROUND) && IsControlBackground();
299     if ( bBorder || bBackground )
300     {
301         Rectangle aRect( aPos, aSize );
302         if ( bBorder )
303         {
304             ImplDrawFrame( pDev, aRect );
305         }
306         if ( bBackground )
307         {
308             pDev->SetFillColor( GetControlBackground() );
309             pDev->DrawRect( aRect );
310         }
311     }
312 
313     ImplDraw( pDev, nFlags, aPos, aSize );
314     pDev->Pop();
315 }
316 
317 // -----------------------------------------------------------------------
318 
Resize()319 void FixedText::Resize()
320 {
321     Control::Resize();
322     Invalidate();
323 }
324 
325 // -----------------------------------------------------------------------
326 
StateChanged(StateChangedType nType)327 void FixedText::StateChanged( StateChangedType nType )
328 {
329     Control::StateChanged( nType );
330 
331     if ( (nType == STATE_CHANGE_ENABLE) ||
332          (nType == STATE_CHANGE_TEXT) ||
333          (nType == STATE_CHANGE_UPDATEMODE) )
334     {
335         if ( IsReallyVisible() && IsUpdateMode() )
336             Invalidate();
337     }
338     else if ( nType == STATE_CHANGE_STYLE )
339     {
340         SetStyle( ImplInitStyle( GetStyle() ) );
341         if ( (GetPrevStyle() & FIXEDTEXT_VIEW_STYLE) !=
342              (GetStyle() & FIXEDTEXT_VIEW_STYLE) )
343         {
344             ImplInitSettings( sal_True, sal_False, sal_False );
345             Invalidate();
346         }
347     }
348     else if ( (nType == STATE_CHANGE_ZOOM)  ||
349               (nType == STATE_CHANGE_CONTROLFONT) )
350     {
351         ImplInitSettings( sal_True, sal_False, sal_False );
352         Invalidate();
353     }
354     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
355     {
356         ImplInitSettings( sal_False, sal_True, sal_False );
357         Invalidate();
358     }
359     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
360     {
361         ImplInitSettings( sal_False, sal_False, sal_True );
362         Invalidate();
363     }
364 }
365 
366 // -----------------------------------------------------------------------
367 
DataChanged(const DataChangedEvent & rDCEvt)368 void FixedText::DataChanged( const DataChangedEvent& rDCEvt )
369 {
370     Control::DataChanged( rDCEvt );
371 
372     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
373          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
374          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
375           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
376     {
377         ImplInitSettings( sal_True, sal_True, sal_True );
378         Invalidate();
379     }
380 }
381 
382 // -----------------------------------------------------------------------
383 
CalcMinimumTextSize(Control const * pControl,long nMaxWidth)384 Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth )
385 {
386     sal_uInt16 nStyle = ImplGetTextStyle( pControl->GetStyle() );
387     if ( !( pControl->GetStyle() & WB_NOLABEL ) )
388         nStyle |= TEXT_DRAW_MNEMONIC;
389 
390     Size aSize = pControl->GetTextRect( Rectangle( Point(), Size( (nMaxWidth ? nMaxWidth : 0x7fffffff), 0x7fffffff ) ),
391                                        pControl->GetText(), nStyle ).GetSize();
392 
393     if ( pControl->GetStyle() & WB_EXTRAOFFSET )
394         aSize.Width() += 2;
395 
396     // GetTextRect verkraftet keinen leeren String:
397     if ( aSize.Width() < 0 )
398         aSize.Width() = 0;
399     if ( aSize.Height() <= 0 )
400         aSize.Height() = pControl->GetTextHeight();
401 
402     return aSize;
403 }
404 
CalcMinimumSize(long nMaxWidth) const405 Size FixedText::CalcMinimumSize( long nMaxWidth ) const
406 {
407     return CalcWindowSize( CalcMinimumTextSize ( this, nMaxWidth ) );
408 }
409 // -----------------------------------------------------------------------
410 
GetOptimalSize(WindowSizeType eType) const411 Size FixedText::GetOptimalSize(WindowSizeType eType) const
412 {
413     switch (eType) {
414     case WINDOWSIZE_MINIMUM:
415         return CalcMinimumSize();
416     default:
417         return Control::GetOptimalSize( eType );
418     }
419 }
420 
421 // -----------------------------------------------------------------------
422 
FillLayoutData() const423 void  FixedText::FillLayoutData() const
424 {
425     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
426     ImplDraw( const_cast<FixedText*>(this), 0, Point(), GetOutputSizePixel(), true );
427 }
428 
429 // =======================================================================
430 
ImplInit(Window * pParent,WinBits nStyle)431 void FixedLine::ImplInit( Window* pParent, WinBits nStyle )
432 {
433     nStyle = ImplInitStyle( nStyle );
434     Control::ImplInit( pParent, nStyle, NULL );
435     ImplInitSettings( sal_True, sal_True, sal_True );
436 }
437 
438 // -----------------------------------------------------------------------
439 
ImplInitStyle(WinBits nStyle)440 WinBits FixedLine::ImplInitStyle( WinBits nStyle )
441 {
442     if ( !(nStyle & WB_NOGROUP) )
443         nStyle |= WB_GROUP;
444     return nStyle;
445 }
446 
447 // -----------------------------------------------------------------
448 
GetCanonicalFont(const StyleSettings & _rStyle) const449 const Font& FixedLine::GetCanonicalFont( const StyleSettings& _rStyle ) const
450 {
451     return _rStyle.GetGroupFont();
452 }
453 
454 // -----------------------------------------------------------------
GetCanonicalTextColor(const StyleSettings & _rStyle) const455 const Color& FixedLine::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
456 {
457     return _rStyle.GetGroupTextColor();
458 }
459 
460 // -----------------------------------------------------------------------
461 
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)462 void FixedLine::ImplInitSettings( sal_Bool bFont,
463                                   sal_Bool bForeground, sal_Bool bBackground )
464 {
465     Control::ImplInitSettings( bFont, bForeground );
466 
467     if ( bBackground )
468     {
469         Window* pParent = GetParent();
470         if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
471         {
472             EnableChildTransparentMode( sal_True );
473             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
474             SetPaintTransparent( sal_True );
475             SetBackground();
476         }
477         else
478         {
479             EnableChildTransparentMode( sal_False );
480             SetParentClipMode( 0 );
481             SetPaintTransparent( sal_False );
482 
483             if ( IsControlBackground() )
484                 SetBackground( GetControlBackground() );
485             else
486                 SetBackground( pParent->GetBackground() );
487         }
488     }
489 }
490 
491 // -----------------------------------------------------------------------
492 
ImplDraw(bool bLayout)493 void FixedLine::ImplDraw( bool bLayout )
494 {
495     Size                    aOutSize = GetOutputSizePixel();
496     String                  aText = GetText();
497     WinBits                 nWinStyle = GetStyle();
498     MetricVector*           pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
499     String*                 pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
500 
501     DecorationView aDecoView( this );
502     if ( !aText.Len() )
503     {
504         if( !pVector )
505         {
506             long nX = 0;
507             long nY = 0;
508 
509             if ( nWinStyle & WB_VERT )
510             {
511                 nX = (aOutSize.Width()-1)/2;
512                 aDecoView.DrawSeparator( Point( nX, 0 ), Point( nX, aOutSize.Height()-1 ) );
513             }
514             else
515             {
516                 nY = (aOutSize.Height()-1)/2;
517                 aDecoView.DrawSeparator( Point( 0, nY ), Point( aOutSize.Width()-1, nY ), false );
518             }
519         }
520     }
521     else if( (nWinStyle & WB_VERT) )
522     {
523         long nWidth = GetTextWidth( aText );
524         Push( PUSH_FONT );
525         Font aFont( GetFont() );
526         aFont.SetOrientation( 900 );
527         SetFont( aFont );
528         Point aStartPt( aOutSize.Width()/2, aOutSize.Height()-1 );
529         if( (nWinStyle & WB_VCENTER) )
530             aStartPt.Y() -= (aOutSize.Height() - nWidth)/2;
531         Point aTextPt( aStartPt );
532         aTextPt.X() -= GetTextHeight()/2;
533         DrawText( aTextPt, aText, 0, STRING_LEN, pVector, pDisplayText );
534         Pop();
535         if( aOutSize.Height() - aStartPt.Y() > FIXEDLINE_TEXT_BORDER )
536             aDecoView.DrawSeparator( Point( aStartPt.X(), aOutSize.Height()-1 ),
537                                      Point( aStartPt.X(), aStartPt.Y() + FIXEDLINE_TEXT_BORDER ) );
538         if( aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER > 0 )
539             aDecoView.DrawSeparator( Point( aStartPt.X(), aStartPt.Y() - nWidth - FIXEDLINE_TEXT_BORDER ),
540                                      Point( aStartPt.X(), 0 ) );
541     }
542     else
543     {
544         sal_uInt16      nStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_ENDELLIPSIS;
545         Rectangle   aRect( 0, 0, aOutSize.Width(), aOutSize.Height() );
546         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
547         if( (nWinStyle & WB_CENTER) )
548             nStyle |= TEXT_DRAW_CENTER;
549 
550         if ( !IsEnabled() )
551             nStyle |= TEXT_DRAW_DISABLE;
552         if ( GetStyle() & WB_NOLABEL )
553             nStyle &= ~TEXT_DRAW_MNEMONIC;
554         if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
555             nStyle |= TEXT_DRAW_MONO;
556 
557         DrawControlText( *this, aRect, aText, nStyle, pVector, pDisplayText );
558 
559         if( !pVector )
560         {
561             long nTop = aRect.Top() + ((aRect.GetHeight()-1)/2);
562             aDecoView.DrawSeparator( Point( aRect.Right()+FIXEDLINE_TEXT_BORDER, nTop ), Point( aOutSize.Width()-1, nTop ), false );
563             if( aRect.Left() > FIXEDLINE_TEXT_BORDER )
564                 aDecoView.DrawSeparator( Point( 0, nTop ), Point( aRect.Left()-FIXEDLINE_TEXT_BORDER, nTop ), false );
565         }
566     }
567 }
568 
569 // -----------------------------------------------------------------------
570 
FixedLine(Window * pParent,WinBits nStyle)571 FixedLine::FixedLine( Window* pParent, WinBits nStyle ) :
572     Control( WINDOW_FIXEDLINE )
573 {
574     ImplInit( pParent, nStyle );
575     SetSizePixel( Size( 2, 2 ) );
576 }
577 
578 // -----------------------------------------------------------------------
579 
FixedLine(Window * pParent,const ResId & rResId)580 FixedLine::FixedLine( Window* pParent, const ResId& rResId ) :
581     Control( WINDOW_FIXEDLINE )
582 {
583     rResId.SetRT( RSC_FIXEDLINE );
584     WinBits nStyle = ImplInitRes( rResId );
585     ImplInit( pParent, nStyle );
586     ImplLoadRes( rResId );
587 
588     if ( !(nStyle & WB_HIDE) )
589         Show();
590 }
591 
592 // -----------------------------------------------------------------------
593 
FillLayoutData() const594 void  FixedLine::FillLayoutData() const
595 {
596     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
597     const_cast<FixedLine*>(this)->ImplDraw( true );
598 }
599 
600 
601 // -----------------------------------------------------------------------
602 
Paint(const Rectangle &)603 void FixedLine::Paint( const Rectangle& )
604 {
605     ImplDraw();
606 }
607 
608 // -----------------------------------------------------------------------
609 
Draw(OutputDevice *,const Point &,const Size &,sal_uLong)610 void FixedLine::Draw( OutputDevice*, const Point&, const Size&, sal_uLong )
611 {
612 }
613 
614 // -----------------------------------------------------------------------
615 
Resize()616 void FixedLine::Resize()
617 {
618     Control::Resize();
619     Invalidate();
620 }
621 
622 // -----------------------------------------------------------------------
623 
StateChanged(StateChangedType nType)624 void FixedLine::StateChanged( StateChangedType nType )
625 {
626     Control::StateChanged( nType );
627 
628     if ( (nType == STATE_CHANGE_ENABLE) ||
629          (nType == STATE_CHANGE_TEXT) ||
630          (nType == STATE_CHANGE_UPDATEMODE) )
631     {
632         if ( IsReallyVisible() && IsUpdateMode() )
633             Invalidate();
634     }
635     else if ( nType == STATE_CHANGE_STYLE )
636     {
637         SetStyle( ImplInitStyle( GetStyle() ) );
638         if ( (GetPrevStyle() & FIXEDLINE_VIEW_STYLE) !=
639              (GetStyle() & FIXEDLINE_VIEW_STYLE) )
640             Invalidate();
641     }
642     else if ( (nType == STATE_CHANGE_ZOOM)  ||
643               (nType == STATE_CHANGE_STYLE) ||
644               (nType == STATE_CHANGE_CONTROLFONT) )
645     {
646         ImplInitSettings( sal_True, sal_False, sal_False );
647         Invalidate();
648     }
649     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
650     {
651         ImplInitSettings( sal_False, sal_True, sal_False );
652         Invalidate();
653     }
654     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
655     {
656         ImplInitSettings( sal_False, sal_False, sal_True );
657         Invalidate();
658     }
659 }
660 
661 // -----------------------------------------------------------------------
662 
DataChanged(const DataChangedEvent & rDCEvt)663 void FixedLine::DataChanged( const DataChangedEvent& rDCEvt )
664 {
665     Control::DataChanged( rDCEvt );
666 
667     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
668          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
669          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
670           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
671     {
672         ImplInitSettings( sal_True, sal_True, sal_True );
673         Invalidate();
674     }
675 }
676 
677 // -----------------------------------------------------------------------
678 
GetOptimalSize(WindowSizeType eType) const679 Size FixedLine::GetOptimalSize(WindowSizeType eType) const
680 {
681     switch (eType) {
682     case WINDOWSIZE_MINIMUM:
683         return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) );
684     default:
685         return Control::GetOptimalSize( eType );
686     }
687 }
688 
689 // =======================================================================
690 
ImplInit(Window * pParent,WinBits nStyle)691 void FixedBitmap::ImplInit( Window* pParent, WinBits nStyle )
692 {
693     nStyle = ImplInitStyle( nStyle );
694     Control::ImplInit( pParent, nStyle, NULL );
695     ImplInitSettings();
696 }
697 
698 // -----------------------------------------------------------------------
699 
ImplInitStyle(WinBits nStyle)700 WinBits FixedBitmap::ImplInitStyle( WinBits nStyle )
701 {
702     if ( !(nStyle & WB_NOGROUP) )
703         nStyle |= WB_GROUP;
704     return nStyle;
705 }
706 
707 // -----------------------------------------------------------------------
708 
ImplInitSettings()709 void FixedBitmap::ImplInitSettings()
710 {
711     Window* pParent = GetParent();
712     if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
713     {
714         EnableChildTransparentMode( sal_True );
715         SetParentClipMode( PARENTCLIPMODE_NOCLIP );
716         SetPaintTransparent( sal_True );
717         SetBackground();
718     }
719     else
720     {
721         EnableChildTransparentMode( sal_False );
722         SetParentClipMode( 0 );
723         SetPaintTransparent( sal_False );
724 
725         if ( IsControlBackground() )
726             SetBackground( GetControlBackground() );
727         else
728             SetBackground( pParent->GetBackground() );
729     }
730 }
731 
732 // -----------------------------------------------------------------------
733 
ImplLoadRes(const ResId & rResId)734 void FixedBitmap::ImplLoadRes( const ResId& rResId )
735 {
736     Control::ImplLoadRes( rResId );
737 
738     sal_uLong nObjMask = ReadLongRes();
739 
740     if ( RSC_FIXEDBITMAP_BITMAP & nObjMask )
741     {
742         maBitmap = Bitmap( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
743         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
744     }
745 }
746 
747 // -----------------------------------------------------------------------
748 
FixedBitmap(Window * pParent,WinBits nStyle)749 FixedBitmap::FixedBitmap( Window* pParent, WinBits nStyle ) :
750     Control( WINDOW_FIXEDBITMAP )
751 {
752     ImplInit( pParent, nStyle );
753 }
754 
755 // -----------------------------------------------------------------------
756 
FixedBitmap(Window * pParent,const ResId & rResId)757 FixedBitmap::FixedBitmap( Window* pParent, const ResId& rResId ) :
758     Control( WINDOW_FIXEDBITMAP )
759 {
760     rResId.SetRT( RSC_FIXEDBITMAP );
761     WinBits nStyle = ImplInitRes( rResId );
762     ImplInit( pParent, nStyle );
763     ImplLoadRes( rResId );
764 
765     if ( !(nStyle & WB_HIDE) )
766         Show();
767 }
768 
769 // -----------------------------------------------------------------------
770 
~FixedBitmap()771 FixedBitmap::~FixedBitmap()
772 {
773 }
774 
775 // -----------------------------------------------------------------------
776 
ImplDraw(OutputDevice * pDev,sal_uLong,const Point & rPos,const Size & rSize)777 void FixedBitmap::ImplDraw( OutputDevice* pDev, sal_uLong /* nDrawFlags */,
778                             const Point& rPos, const Size& rSize )
779 {
780     sal_uInt16 nStyle = 0;
781     Bitmap* pBitmap = &maBitmap;
782     Color aCol;
783     if( !!maBitmapHC )
784     {
785         if( GetSettings().GetStyleSettings().GetHighContrastMode() )
786             pBitmap = &maBitmapHC;
787     }
788 
789     if( nStyle & IMAGE_DRAW_COLORTRANSFORM )
790     {
791         // only images support IMAGE_DRAW_COLORTRANSFORM
792         Image aImage( maBitmap );
793         if ( !(!aImage) )
794         {
795             if ( GetStyle() & WB_SCALE )
796                 pDev->DrawImage( rPos, rSize, aImage, nStyle );
797             else
798             {
799                 Point aPos = ImplCalcPos( GetStyle(), rPos, aImage.GetSizePixel(), rSize );
800                 pDev->DrawImage( aPos, aImage, nStyle );
801             }
802         }
803     }
804     else
805     {
806         // Haben wir ueberhaupt eine Bitmap
807         if ( !(!(*pBitmap)) )
808         {
809             if ( GetStyle() & WB_SCALE )
810                 pDev->DrawBitmap( rPos, rSize, *pBitmap );
811             else
812             {
813                 Point aPos = ImplCalcPos( GetStyle(), rPos, pBitmap->GetSizePixel(), rSize );
814                 pDev->DrawBitmap( aPos, *pBitmap );
815             }
816         }
817     }
818 }
819 
820 // -----------------------------------------------------------------------
821 
Paint(const Rectangle &)822 void FixedBitmap::Paint( const Rectangle& )
823 {
824     ImplDraw( this, 0, Point(), GetOutputSizePixel() );
825 }
826 
827 // -----------------------------------------------------------------------
828 
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)829 void FixedBitmap::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
830                         sal_uLong nFlags )
831 {
832     Point       aPos  = pDev->LogicToPixel( rPos );
833     Size        aSize = pDev->LogicToPixel( rSize );
834     Rectangle   aRect( aPos, aSize );
835 
836     pDev->Push();
837     pDev->SetMapMode();
838 
839     // Border
840     if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
841     {
842         DecorationView aDecoView( pDev );
843         aRect = aDecoView.DrawFrame( aRect, FRAME_DRAW_DOUBLEIN );
844     }
845     pDev->IntersectClipRegion( aRect );
846     ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
847 
848     pDev->Pop();
849 }
850 
851 // -----------------------------------------------------------------------
852 
Resize()853 void FixedBitmap::Resize()
854 {
855     Control::Resize();
856     Invalidate();
857 }
858 
859 // -----------------------------------------------------------------------
860 
StateChanged(StateChangedType nType)861 void FixedBitmap::StateChanged( StateChangedType nType )
862 {
863     Control::StateChanged( nType );
864 
865     if ( (nType == STATE_CHANGE_DATA) ||
866          (nType == STATE_CHANGE_UPDATEMODE) )
867     {
868         if ( IsReallyVisible() && IsUpdateMode() )
869             Invalidate();
870     }
871     else if ( nType == STATE_CHANGE_STYLE )
872     {
873         SetStyle( ImplInitStyle( GetStyle() ) );
874         if ( (GetPrevStyle() & FIXEDBITMAP_VIEW_STYLE) !=
875              (GetStyle() & FIXEDBITMAP_VIEW_STYLE) )
876             Invalidate();
877     }
878     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
879     {
880         ImplInitSettings();
881         Invalidate();
882     }
883 }
884 
885 // -----------------------------------------------------------------------
886 
DataChanged(const DataChangedEvent & rDCEvt)887 void FixedBitmap::DataChanged( const DataChangedEvent& rDCEvt )
888 {
889     Control::DataChanged( rDCEvt );
890 
891     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
892          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
893     {
894         ImplInitSettings();
895         Invalidate();
896     }
897 }
898 
899 // -----------------------------------------------------------------------
900 
SetBitmap(const Bitmap & rBitmap)901 void FixedBitmap::SetBitmap( const Bitmap& rBitmap )
902 {
903     maBitmap = rBitmap;
904     StateChanged( STATE_CHANGE_DATA );
905 }
906 
907 // -----------------------------------------------------------------------
908 
SetModeBitmap(const Bitmap & rBitmap,BmpColorMode eMode)909 sal_Bool FixedBitmap::SetModeBitmap( const Bitmap& rBitmap, BmpColorMode eMode )
910 {
911     if( eMode == BMP_COLOR_NORMAL )
912         SetBitmap( rBitmap );
913     else if( eMode == BMP_COLOR_HIGHCONTRAST )
914     {
915         maBitmapHC = rBitmap;
916         StateChanged( STATE_CHANGE_DATA );
917     }
918     else
919         return sal_False;
920     return sal_True;
921 }
922 
923 // -----------------------------------------------------------------------
924 
GetModeBitmap(BmpColorMode eMode) const925 const Bitmap& FixedBitmap::GetModeBitmap( BmpColorMode eMode) const
926 {
927     if( eMode == BMP_COLOR_HIGHCONTRAST )
928         return maBitmapHC;
929     else
930         return maBitmap;
931 }
932 
933 // =======================================================================
934 
ImplInit(Window * pParent,WinBits nStyle)935 void FixedImage::ImplInit( Window* pParent, WinBits nStyle )
936 {
937     nStyle = ImplInitStyle( nStyle );
938     mbInUserDraw = sal_False;
939     Control::ImplInit( pParent, nStyle, NULL );
940     ImplInitSettings();
941 }
942 
943 // -----------------------------------------------------------------------
944 
ImplInitStyle(WinBits nStyle)945 WinBits FixedImage::ImplInitStyle( WinBits nStyle )
946 {
947     if ( !(nStyle & WB_NOGROUP) )
948         nStyle |= WB_GROUP;
949     return nStyle;
950 }
951 
952 // -----------------------------------------------------------------------
953 
ImplInitSettings()954 void FixedImage::ImplInitSettings()
955 {
956     Window* pParent = GetParent();
957     if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
958     {
959         EnableChildTransparentMode( sal_True );
960         SetParentClipMode( PARENTCLIPMODE_NOCLIP );
961         SetPaintTransparent( sal_True );
962         SetBackground();
963     }
964     else
965     {
966         EnableChildTransparentMode( sal_False );
967         SetParentClipMode( 0 );
968         SetPaintTransparent( sal_False );
969 
970         if ( IsControlBackground() )
971             SetBackground( GetControlBackground() );
972         else
973             SetBackground( pParent->GetBackground() );
974     }
975 }
976 
977 // -----------------------------------------------------------------------
978 
ImplLoadRes(const ResId & rResId)979 void FixedImage::ImplLoadRes( const ResId& rResId )
980 {
981     Control::ImplLoadRes( rResId );
982 
983     sal_uLong nObjMask = ReadLongRes();
984 
985     if ( RSC_FIXEDIMAGE_IMAGE & nObjMask )
986     {
987         maImage = Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) );
988         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
989     }
990 }
991 
992 // -----------------------------------------------------------------------
993 
FixedImage(Window * pParent,WinBits nStyle)994 FixedImage::FixedImage( Window* pParent, WinBits nStyle ) :
995     Control( WINDOW_FIXEDIMAGE )
996 {
997     ImplInit( pParent, nStyle );
998 }
999 
1000 // -----------------------------------------------------------------------
1001 
FixedImage(Window * pParent,const ResId & rResId)1002 FixedImage::FixedImage( Window* pParent, const ResId& rResId ) :
1003     Control( WINDOW_FIXEDIMAGE )
1004 {
1005     rResId.SetRT( RSC_FIXEDIMAGE );
1006     WinBits nStyle = ImplInitRes( rResId );
1007     ImplInit( pParent, nStyle );
1008     ImplLoadRes( rResId );
1009 
1010     if ( !(nStyle & WB_HIDE) )
1011         Show();
1012 }
1013 
1014 // -----------------------------------------------------------------------
1015 
~FixedImage()1016 FixedImage::~FixedImage()
1017 {
1018 }
1019 
1020 // -----------------------------------------------------------------------
1021 
ImplDraw(OutputDevice * pDev,sal_uLong nDrawFlags,const Point & rPos,const Size & rSize)1022 void FixedImage::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
1023                            const Point& rPos, const Size& rSize )
1024 {
1025     sal_uInt16 nStyle = 0;
1026     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
1027     {
1028         if ( !IsEnabled() )
1029             nStyle |= IMAGE_DRAW_DISABLE;
1030     }
1031 
1032     Image *pImage = &maImage;
1033     Color aCol;
1034     if( !!maImageHC )
1035     {
1036         if( GetSettings().GetStyleSettings().GetHighContrastMode() )
1037             pImage = &maImageHC;
1038     }
1039 
1040     // Haben wir ueberhaupt ein Image
1041     if ( !(!(*pImage)) )
1042     {
1043         if ( GetStyle() & WB_SCALE )
1044             pDev->DrawImage( rPos, rSize, *pImage, nStyle );
1045         else
1046         {
1047             Point aPos = ImplCalcPos( GetStyle(), rPos, pImage->GetSizePixel(), rSize );
1048             pDev->DrawImage( aPos, *pImage, nStyle );
1049         }
1050     }
1051 
1052     mbInUserDraw = sal_True;
1053     UserDrawEvent aUDEvt( pDev, Rectangle( rPos, rSize ), 0, nStyle );
1054     UserDraw( aUDEvt );
1055     mbInUserDraw = sal_False;
1056 }
1057 
1058 // -----------------------------------------------------------------------
1059 
Paint(const Rectangle &)1060 void FixedImage::Paint( const Rectangle& )
1061 {
1062     ImplDraw( this, 0, Point(), GetOutputSizePixel() );
1063 }
1064 
1065 // -----------------------------------------------------------------------
1066 
GetOptimalSize(WindowSizeType) const1067 Size FixedImage::GetOptimalSize( WindowSizeType ) const
1068 {
1069     const Image* pImage = GetSettings().GetStyleSettings().GetHighContrastMode() ? &maImageHC : &maImage;
1070     return pImage->GetSizePixel();
1071 }
1072 
1073 // -----------------------------------------------------------------------
1074 
UserDraw(const UserDrawEvent &)1075 void FixedImage::UserDraw( const UserDrawEvent& )
1076 {
1077 }
1078 
1079 // -----------------------------------------------------------------------
1080 
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)1081 void FixedImage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1082                        sal_uLong nFlags )
1083 {
1084     Point       aPos  = pDev->LogicToPixel( rPos );
1085     Size        aSize = pDev->LogicToPixel( rSize );
1086     Rectangle   aRect( aPos, aSize );
1087 
1088     pDev->Push();
1089     pDev->SetMapMode();
1090 
1091     // Border
1092     if ( !(nFlags & WINDOW_DRAW_NOBORDER) && (GetStyle() & WB_BORDER) )
1093     {
1094         ImplDrawFrame( pDev, aRect );
1095     }
1096     pDev->IntersectClipRegion( aRect );
1097     ImplDraw( pDev, nFlags, aRect.TopLeft(), aRect.GetSize() );
1098 
1099     pDev->Pop();
1100 }
1101 
1102 // -----------------------------------------------------------------------
1103 
Resize()1104 void FixedImage::Resize()
1105 {
1106     Control::Resize();
1107     Invalidate();
1108 }
1109 
1110 // -----------------------------------------------------------------------
1111 
StateChanged(StateChangedType nType)1112 void FixedImage::StateChanged( StateChangedType nType )
1113 {
1114     Control::StateChanged( nType );
1115 
1116     if ( (nType == STATE_CHANGE_ENABLE) ||
1117          (nType == STATE_CHANGE_DATA) ||
1118          (nType == STATE_CHANGE_UPDATEMODE) )
1119     {
1120         if ( IsReallyVisible() && IsUpdateMode() )
1121             Invalidate();
1122     }
1123     else if ( nType == STATE_CHANGE_STYLE )
1124     {
1125         SetStyle( ImplInitStyle( GetStyle() ) );
1126         if ( (GetPrevStyle() & FIXEDIMAGE_VIEW_STYLE) !=
1127              (GetStyle() & FIXEDIMAGE_VIEW_STYLE) )
1128             Invalidate();
1129     }
1130     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1131     {
1132         ImplInitSettings();
1133         Invalidate();
1134     }
1135 }
1136 
1137 // -----------------------------------------------------------------------
1138 
DataChanged(const DataChangedEvent & rDCEvt)1139 void FixedImage::DataChanged( const DataChangedEvent& rDCEvt )
1140 {
1141     Control::DataChanged( rDCEvt );
1142 
1143     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1144          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1145     {
1146         ImplInitSettings();
1147         Invalidate();
1148     }
1149 }
1150 
1151 // -----------------------------------------------------------------------
1152 
SetImage(const Image & rImage)1153 void FixedImage::SetImage( const Image& rImage )
1154 {
1155     if ( rImage != maImage )
1156     {
1157         maImage = rImage;
1158         StateChanged( STATE_CHANGE_DATA );
1159     }
1160 }
1161 
1162 // -----------------------------------------------------------------------
1163 
SetModeImage(const Image & rImage,BmpColorMode eMode)1164 sal_Bool FixedImage::SetModeImage( const Image& rImage, BmpColorMode eMode )
1165 {
1166     if( eMode == BMP_COLOR_NORMAL )
1167         SetImage( rImage );
1168     else if( eMode == BMP_COLOR_HIGHCONTRAST )
1169     {
1170         if( maImageHC != rImage )
1171         {
1172             maImageHC = rImage;
1173             StateChanged( STATE_CHANGE_DATA );
1174         }
1175     }
1176     else
1177         return sal_False;
1178     return sal_True;
1179 }
1180 
1181 // -----------------------------------------------------------------------
1182 
GetModeImage(BmpColorMode eMode) const1183 const Image& FixedImage::GetModeImage( BmpColorMode eMode ) const
1184 {
1185     if( eMode == BMP_COLOR_HIGHCONTRAST )
1186         return maImageHC;
1187     else
1188         return maImage;
1189 }
1190 
1191 // -----------------------------------------------------------------------
1192 
CalcImagePos(const Point & rPos,const Size & rObjSize,const Size & rWinSize)1193 Point FixedImage::CalcImagePos( const Point& rPos,
1194                                 const Size& rObjSize, const Size& rWinSize )
1195 {
1196     return ImplCalcPos( GetStyle(), rPos, rObjSize, rWinSize );
1197 }
1198