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