1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "sfx2/titledockwin.hxx"
22 #include "sfx2/bindings.hxx"
23 #include "sfx2/dispatch.hxx"
24 #include "sfxlocal.hrc"
25 #include "sfxresid.hxx"
27 #include <svl/eitem.hxx>
29 //......................................................................................................................
32 //......................................................................................................................
34 //==================================================================================================================
35 //= TitledDockingWindow
36 //==================================================================================================================
37 //------------------------------------------------------------------------------------------------------------------
38 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, Window
* i_pParent
,
40 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, i_nStyle
)
43 ,m_aContentWindow( this, WB_DIALOGCONTROL
)
44 ,m_aBorder( 3, 1, 3, 3 )
45 ,m_bLayoutPending( false )
51 //------------------------------------------------------------------------------------------------------------------
52 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, Window
* i_pParent
,
53 const ResId
& i_rResId
)
54 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, i_rResId
)
57 ,m_aContentWindow( this )
58 ,m_aBorder( 3, 1, 3, 3 )
59 ,m_bLayoutPending( false )
64 //------------------------------------------------------------------------------------------------------------------
65 void TitledDockingWindow::impl_construct()
67 SetBackground( Wallpaper() );
69 m_aToolbox
.SetSelectHdl( LINK( this, TitledDockingWindow
, OnToolboxItemSelected
) );
70 m_aToolbox
.SetOutStyle( TOOLBOX_STYLE_FLAT
);
71 m_aToolbox
.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
75 m_aContentWindow
.Show();
78 //------------------------------------------------------------------------------------------------------------------
79 TitledDockingWindow::~TitledDockingWindow()
83 //------------------------------------------------------------------------------------------------------------------
84 void TitledDockingWindow::SetTitle( const String
& i_rTitle
)
90 //------------------------------------------------------------------------------------------------------------------
91 void TitledDockingWindow::SetText( const OUString
& i_rText
)
93 SfxDockingWindow::SetText( i_rText
);
94 if ( m_sTitle
.isEmpty() )
95 // our text is used as title, too => repaint
99 //------------------------------------------------------------------------------------------------------------------
100 void TitledDockingWindow::Resize()
102 SfxDockingWindow::Resize();
103 impl_scheduleLayout();
106 //------------------------------------------------------------------------------------------------------------------
107 void TitledDockingWindow::onLayoutDone()
112 //------------------------------------------------------------------------------------------------------------------
113 void TitledDockingWindow::impl_scheduleLayout()
115 m_bLayoutPending
= true;
118 //------------------------------------------------------------------------------------------------------------------
119 void TitledDockingWindow::impl_layout()
121 m_bLayoutPending
= false;
123 m_aToolbox
.ShowItem( 1, !IsFloatingMode() );
125 const Size
aToolBoxSize( m_aToolbox
.CalcWindowSizePixel() );
126 Size
aWindowSize( GetOutputSizePixel() );
128 // position the tool box
129 m_nTitleBarHeight
= GetSettings().GetStyleSettings().GetTitleHeight();
130 if ( aToolBoxSize
.Height() > m_nTitleBarHeight
)
131 m_nTitleBarHeight
= aToolBoxSize
.Height();
132 m_aToolbox
.SetPosSizePixel(
134 aWindowSize
.Width() - aToolBoxSize
.Width(),
135 ( m_nTitleBarHeight
- aToolBoxSize
.Height() ) / 2
140 // Place the content window.
141 if ( m_nTitleBarHeight
< aToolBoxSize
.Height() )
142 m_nTitleBarHeight
= aToolBoxSize
.Height();
143 aWindowSize
.Height() -= m_nTitleBarHeight
;
144 m_aContentWindow
.SetPosSizePixel(
145 Point( m_aBorder
.Left(), m_nTitleBarHeight
+ m_aBorder
.Top() ),
147 aWindowSize
.Width() - m_aBorder
.Left() - m_aBorder
.Right(),
148 aWindowSize
.Height() - m_aBorder
.Top() - m_aBorder
.Bottom()
155 //------------------------------------------------------------------------------------------------------------------
156 void TitledDockingWindow::Paint( const Rectangle
& i_rArea
)
158 if ( m_bLayoutPending
)
161 SfxDockingWindow::Paint( i_rArea
);
163 Push( PUSH_FONT
| PUSH_FILLCOLOR
| PUSH_LINECOLOR
);
165 SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
169 Font
aFont( GetFont() );
170 aFont
.SetWeight( WEIGHT_BOLD
);
173 // Set border values.
174 Size
aWindowSize( GetOutputSizePixel() );
176 int nInnerLeft
= nOuterLeft
+ m_aBorder
.Left() - 1;
177 int nOuterRight
= aWindowSize
.Width() - 1;
178 int nInnerRight
= nOuterRight
- m_aBorder
.Right() + 1;
179 int nInnerTop
= m_nTitleBarHeight
+ m_aBorder
.Top() - 1;
180 int nOuterBottom
= aWindowSize
.Height() - 1;
181 int nInnerBottom
= nOuterBottom
- m_aBorder
.Bottom() + 1;
183 // Paint title bar background.
184 Rectangle
aTitleBarBox( Rectangle(
190 DrawRect( aTitleBarBox
);
192 if ( nInnerLeft
> nOuterLeft
)
193 DrawRect( Rectangle( nOuterLeft
, nInnerTop
, nInnerLeft
, nInnerBottom
) );
194 if ( nOuterRight
> nInnerRight
)
195 DrawRect( Rectangle( nInnerRight
, nInnerTop
, nOuterRight
, nInnerBottom
) );
196 if ( nInnerBottom
< nOuterBottom
)
197 DrawRect( Rectangle( nOuterLeft
, nInnerBottom
, nOuterRight
, nOuterBottom
) );
199 // Paint bevel border.
201 SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
202 if ( m_aBorder
.Top() > 0 )
203 DrawLine( Point( nInnerLeft
, nInnerTop
), Point( nInnerLeft
, nInnerBottom
) );
204 if ( m_aBorder
.Left() > 0 )
205 DrawLine( Point( nInnerLeft
, nInnerTop
), Point( nInnerRight
, nInnerTop
) );
207 SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
208 if ( m_aBorder
.Bottom() > 0 )
209 DrawLine( Point( nInnerRight
, nInnerBottom
), Point( nInnerLeft
, nInnerBottom
) );
210 if ( m_aBorder
.Right() > 0 )
211 DrawLine( Point( nInnerRight
, nInnerBottom
), Point( nInnerRight
, nInnerTop
) );
213 // Paint title bar text.
214 SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
215 aTitleBarBox
.Left() += 3;
216 DrawText( aTitleBarBox
, impl_getTitle(), TEXT_DRAW_LEFT
| TEXT_DRAW_VCENTER
| TEXT_DRAW_MULTILINE
| TEXT_DRAW_WORDBREAK
);
218 // Restore original values of the output device.
222 //------------------------------------------------------------------------------------------------------------------
223 String
TitledDockingWindow::impl_getTitle() const
225 return !m_sTitle
.isEmpty() ? m_sTitle
: GetText();
228 //------------------------------------------------------------------------------------------------------------------
229 void TitledDockingWindow::impl_resetToolBox()
233 // Get the closer bitmap and set it as right most button.
234 Image
aImage( SfxResId( SFX_IMG_CLOSE_DOC
) );
235 m_aToolbox
.InsertItem( 1, aImage
);
236 m_aToolbox
.ShowItem( 1 );
239 //------------------------------------------------------------------------------------------------------------------
240 sal_uInt16
TitledDockingWindow::impl_addDropDownToolBoxItem( const String
& i_rItemText
, const OString
& i_nHelpId
, const Link
& i_rCallback
)
242 // Add the menu before the closer button.
243 const sal_uInt16
nItemCount( m_aToolbox
.GetItemCount() );
244 const sal_uInt16
nItemId( nItemCount
+ 1 );
245 m_aToolbox
.InsertItem( nItemId
, i_rItemText
, TIB_DROPDOWNONLY
, nItemCount
> 0 ? nItemCount
- 1 : TOOLBOX_APPEND
);
246 m_aToolbox
.SetHelpId( nItemId
, i_nHelpId
);
247 m_aToolbox
.SetClickHdl( i_rCallback
);
248 m_aToolbox
.SetDropdownClickHdl( i_rCallback
);
250 // The tool box has likely changed its size. The title bar has to be
252 impl_scheduleLayout();
258 //------------------------------------------------------------------------------------------------------------------
259 IMPL_LINK( TitledDockingWindow
, OnToolboxItemSelected
, ToolBox
*, pToolBox
)
261 const sal_uInt16 nId
= pToolBox
->GetCurItemId();
267 const sal_uInt16
nChildWindowId( GetChildWindow_Impl()->GetType() );
268 const SfxBoolItem
aVisibility( nChildWindowId
, sal_False
);
269 GetBindings().GetDispatcher()->Execute(
271 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
280 //------------------------------------------------------------------------------------------------------------------
281 void TitledDockingWindow::StateChanged( StateChangedType i_nType
)
285 case STATE_CHANGE_INITSHOW
:
286 impl_scheduleLayout();
289 SfxDockingWindow::StateChanged( i_nType
);
292 //------------------------------------------------------------------------------------------------------------------
293 void TitledDockingWindow::EndDocking( const Rectangle
& i_rRect
, sal_Bool i_bFloatMode
)
295 SfxDockingWindow::EndDocking( i_rRect
, i_bFloatMode
);
297 if ( m_aEndDockingHdl
.IsSet() )
298 m_aEndDockingHdl
.Call( this );
301 //------------------------------------------------------------------------------------------------------------------
302 void TitledDockingWindow::DataChanged( const DataChangedEvent
& i_rDataChangedEvent
)
304 SfxDockingWindow::DataChanged( i_rDataChangedEvent
);
306 switch ( i_rDataChangedEvent
.GetType() )
308 case DATACHANGED_SETTINGS
:
309 if ( ( i_rDataChangedEvent
.GetFlags() & SETTINGS_STYLE
) == 0)
311 // else fall through.
312 case DATACHANGED_FONTS
:
313 case DATACHANGED_FONTSUBSTITUTION
:
315 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
318 Font aFont
= rStyleSettings
.GetAppFont();
319 if ( IsControlFont() )
320 aFont
.Merge( GetControlFont() );
321 SetZoomedPointFont( aFont
);
325 if ( IsControlForeground() )
326 aColor
= GetControlForeground();
328 aColor
= rStyleSettings
.GetButtonTextColor();
329 SetTextColor( aColor
);
332 impl_scheduleLayout();
339 //......................................................................................................................
341 //......................................................................................................................
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */