1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include "sfx2/titledockwin.hxx"
30 #include "sfx2/bindings.hxx"
31 #include "sfx2/dispatch.hxx"
32 #include "sfxlocal.hrc"
33 #include "sfxresid.hxx"
35 #include <svl/eitem.hxx>
37 //......................................................................................................................
40 //......................................................................................................................
42 //==================================================================================================================
43 //= TitledDockingWindow
44 //==================================================================================================================
45 //------------------------------------------------------------------------------------------------------------------
46 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, Window
* i_pParent
,
48 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, i_nStyle
)
51 ,m_aContentWindow( this, WB_DIALOGCONTROL
)
52 ,m_aBorder( 3, 1, 3, 3 )
53 ,m_bLayoutPending( false )
59 //------------------------------------------------------------------------------------------------------------------
60 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, Window
* i_pParent
,
61 const ResId
& i_rResId
)
62 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, i_rResId
)
65 ,m_aContentWindow( this )
66 ,m_aBorder( 3, 1, 3, 3 )
67 ,m_bLayoutPending( false )
72 //------------------------------------------------------------------------------------------------------------------
73 void TitledDockingWindow::impl_construct()
75 SetBackground( Wallpaper() );
77 m_aToolbox
.SetSelectHdl( LINK( this, TitledDockingWindow
, OnToolboxItemSelected
) );
78 m_aToolbox
.SetOutStyle( TOOLBOX_STYLE_FLAT
);
79 m_aToolbox
.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
83 m_aContentWindow
.Show();
86 //------------------------------------------------------------------------------------------------------------------
87 TitledDockingWindow::~TitledDockingWindow()
91 //------------------------------------------------------------------------------------------------------------------
92 void TitledDockingWindow::SetTitle( const String
& i_rTitle
)
98 //------------------------------------------------------------------------------------------------------------------
99 void TitledDockingWindow::SetText( const String
& i_rText
)
101 SfxDockingWindow::SetText( i_rText
);
102 if ( m_sTitle
.Len() == 0 )
103 // our text is used as title, too => repaint
107 //------------------------------------------------------------------------------------------------------------------
108 void TitledDockingWindow::Resize()
110 SfxDockingWindow::Resize();
111 impl_scheduleLayout();
114 //------------------------------------------------------------------------------------------------------------------
115 void TitledDockingWindow::onLayoutDone()
120 //------------------------------------------------------------------------------------------------------------------
121 void TitledDockingWindow::impl_scheduleLayout()
123 m_bLayoutPending
= true;
126 //------------------------------------------------------------------------------------------------------------------
127 void TitledDockingWindow::impl_layout()
129 m_bLayoutPending
= false;
131 m_aToolbox
.ShowItem( 1, !IsFloatingMode() );
133 const Size
aToolBoxSize( m_aToolbox
.CalcWindowSizePixel() );
134 Size
aWindowSize( GetOutputSizePixel() );
136 // position the tool box
137 m_nTitleBarHeight
= GetSettings().GetStyleSettings().GetTitleHeight();
138 if ( aToolBoxSize
.Height() > m_nTitleBarHeight
)
139 m_nTitleBarHeight
= aToolBoxSize
.Height();
140 m_aToolbox
.SetPosSizePixel(
142 aWindowSize
.Width() - aToolBoxSize
.Width(),
143 ( m_nTitleBarHeight
- aToolBoxSize
.Height() ) / 2
148 // Place the content window.
149 if ( m_nTitleBarHeight
< aToolBoxSize
.Height() )
150 m_nTitleBarHeight
= aToolBoxSize
.Height();
151 aWindowSize
.Height() -= m_nTitleBarHeight
;
152 m_aContentWindow
.SetPosSizePixel(
153 Point( m_aBorder
.Left(), m_nTitleBarHeight
+ m_aBorder
.Top() ),
155 aWindowSize
.Width() - m_aBorder
.Left() - m_aBorder
.Right(),
156 aWindowSize
.Height() - m_aBorder
.Top() - m_aBorder
.Bottom()
163 //------------------------------------------------------------------------------------------------------------------
164 void TitledDockingWindow::Paint( const Rectangle
& i_rArea
)
166 if ( m_bLayoutPending
)
169 SfxDockingWindow::Paint( i_rArea
);
171 Push( PUSH_FONT
| PUSH_FILLCOLOR
| PUSH_LINECOLOR
);
173 SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
177 Font
aFont( GetFont() );
178 aFont
.SetWeight( WEIGHT_BOLD
);
181 // Set border values.
182 Size
aWindowSize( GetOutputSizePixel() );
184 int nInnerLeft
= nOuterLeft
+ m_aBorder
.Left() - 1;
185 int nOuterRight
= aWindowSize
.Width() - 1;
186 int nInnerRight
= nOuterRight
- m_aBorder
.Right() + 1;
187 int nInnerTop
= m_nTitleBarHeight
+ m_aBorder
.Top() - 1;
188 int nOuterBottom
= aWindowSize
.Height() - 1;
189 int nInnerBottom
= nOuterBottom
- m_aBorder
.Bottom() + 1;
191 // Paint title bar background.
192 Rectangle
aTitleBarBox( Rectangle(
198 DrawRect( aTitleBarBox
);
200 if ( nInnerLeft
> nOuterLeft
)
201 DrawRect( Rectangle( nOuterLeft
, nInnerTop
, nInnerLeft
, nInnerBottom
) );
202 if ( nOuterRight
> nInnerRight
)
203 DrawRect( Rectangle( nInnerRight
, nInnerTop
, nOuterRight
, nInnerBottom
) );
204 if ( nInnerBottom
< nOuterBottom
)
205 DrawRect( Rectangle( nOuterLeft
, nInnerBottom
, nOuterRight
, nOuterBottom
) );
207 // Paint bevel border.
209 SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
210 if ( m_aBorder
.Top() > 0 )
211 DrawLine( Point( nInnerLeft
, nInnerTop
), Point( nInnerLeft
, nInnerBottom
) );
212 if ( m_aBorder
.Left() > 0 )
213 DrawLine( Point( nInnerLeft
, nInnerTop
), Point( nInnerRight
, nInnerTop
) );
215 SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
216 if ( m_aBorder
.Bottom() > 0 )
217 DrawLine( Point( nInnerRight
, nInnerBottom
), Point( nInnerLeft
, nInnerBottom
) );
218 if ( m_aBorder
.Right() > 0 )
219 DrawLine( Point( nInnerRight
, nInnerBottom
), Point( nInnerRight
, nInnerTop
) );
221 // Paint title bar text.
222 SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
223 aTitleBarBox
.Left() += 3;
224 DrawText( aTitleBarBox
, impl_getTitle(), TEXT_DRAW_LEFT
| TEXT_DRAW_VCENTER
| TEXT_DRAW_MULTILINE
| TEXT_DRAW_WORDBREAK
);
226 // Restore original values of the output device.
230 //------------------------------------------------------------------------------------------------------------------
231 String
TitledDockingWindow::impl_getTitle() const
233 return m_sTitle
.Len() ? m_sTitle
: GetText();
236 //------------------------------------------------------------------------------------------------------------------
237 void TitledDockingWindow::impl_resetToolBox()
241 // Get the closer bitmap and set it as right most button.
242 Image
aImage( SfxResId( SFX_IMG_CLOSE_DOC
) );
243 m_aToolbox
.InsertItem( 1, aImage
);
244 m_aToolbox
.ShowItem( 1 );
247 //------------------------------------------------------------------------------------------------------------------
248 sal_uInt16
TitledDockingWindow::impl_addDropDownToolBoxItem( const String
& i_rItemText
, const rtl::OString
& i_nHelpId
, const Link
& i_rCallback
)
250 // Add the menu before the closer button.
251 const sal_uInt16
nItemCount( m_aToolbox
.GetItemCount() );
252 const sal_uInt16
nItemId( nItemCount
+ 1 );
253 m_aToolbox
.InsertItem( nItemId
, i_rItemText
, TIB_DROPDOWNONLY
, nItemCount
> 0 ? nItemCount
- 1 : TOOLBOX_APPEND
);
254 m_aToolbox
.SetHelpId( nItemId
, i_nHelpId
);
255 m_aToolbox
.SetClickHdl( i_rCallback
);
256 m_aToolbox
.SetDropdownClickHdl( i_rCallback
);
258 // The tool box has likely changed its size. The title bar has to be
260 impl_scheduleLayout();
266 //------------------------------------------------------------------------------------------------------------------
267 IMPL_LINK( TitledDockingWindow
, OnToolboxItemSelected
, ToolBox
*, pToolBox
)
269 const sal_uInt16 nId
= pToolBox
->GetCurItemId();
275 const sal_uInt16
nChildWindowId( GetChildWindow_Impl()->GetType() );
276 const SfxBoolItem
aVisibility( nChildWindowId
, sal_False
);
277 GetBindings().GetDispatcher()->Execute(
279 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
288 //------------------------------------------------------------------------------------------------------------------
289 void TitledDockingWindow::StateChanged( StateChangedType i_nType
)
293 case STATE_CHANGE_INITSHOW
:
294 impl_scheduleLayout();
297 SfxDockingWindow::StateChanged( i_nType
);
300 //------------------------------------------------------------------------------------------------------------------
301 void TitledDockingWindow::EndDocking( const Rectangle
& i_rRect
, sal_Bool i_bFloatMode
)
303 SfxDockingWindow::EndDocking( i_rRect
, i_bFloatMode
);
305 if ( m_aEndDockingHdl
.IsSet() )
306 m_aEndDockingHdl
.Call( this );
309 //------------------------------------------------------------------------------------------------------------------
310 void TitledDockingWindow::DataChanged( const DataChangedEvent
& i_rDataChangedEvent
)
312 SfxDockingWindow::DataChanged( i_rDataChangedEvent
);
314 switch ( i_rDataChangedEvent
.GetType() )
316 case DATACHANGED_SETTINGS
:
317 if ( ( i_rDataChangedEvent
.GetFlags() & SETTINGS_STYLE
) == 0)
319 // else fall through.
320 case DATACHANGED_FONTS
:
321 case DATACHANGED_FONTSUBSTITUTION
:
323 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
326 Font aFont
= rStyleSettings
.GetAppFont();
327 if ( IsControlFont() )
328 aFont
.Merge( GetControlFont() );
329 SetZoomedPointFont( aFont
);
333 if ( IsControlForeground() )
334 aColor
= GetControlForeground();
336 aColor
= rStyleSettings
.GetButtonTextColor();
337 SetTextColor( aColor
);
340 impl_scheduleLayout();
347 //......................................................................................................................
349 //......................................................................................................................
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */