Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / titledockwin.cxx
bloba8cb0a1610c9bc78f2cc0c117367763c0eb48203
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 //......................................................................................................................
30 namespace sfx2
32 //......................................................................................................................
34 //==================================================================================================================
35 //= TitledDockingWindow
36 //==================================================================================================================
37 //------------------------------------------------------------------------------------------------------------------
38 TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
39 WinBits i_nStyle )
40 :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
41 ,m_sTitle()
42 ,m_aToolbox( this )
43 ,m_aContentWindow( this, WB_DIALOGCONTROL )
44 ,m_aBorder( 3, 1, 3, 3 )
45 ,m_bLayoutPending( false )
46 ,m_nTitleBarHeight(0)
48 impl_construct();
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 )
55 ,m_sTitle()
56 ,m_aToolbox( this )
57 ,m_aContentWindow( this )
58 ,m_aBorder( 3, 1, 3, 3 )
59 ,m_bLayoutPending( false )
61 impl_construct();
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() ) );
72 m_aToolbox.Show();
73 impl_resetToolBox();
75 m_aContentWindow.Show();
78 //------------------------------------------------------------------------------------------------------------------
79 TitledDockingWindow::~TitledDockingWindow()
83 //------------------------------------------------------------------------------------------------------------------
84 void TitledDockingWindow::SetTitle( const String& i_rTitle )
86 m_sTitle = i_rTitle;
87 Invalidate();
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
96 Invalidate();
99 //------------------------------------------------------------------------------------------------------------------
100 void TitledDockingWindow::Resize()
102 SfxDockingWindow::Resize();
103 impl_scheduleLayout();
106 //------------------------------------------------------------------------------------------------------------------
107 void TitledDockingWindow::onLayoutDone()
109 // not interested in
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(
133 Point(
134 aWindowSize.Width() - aToolBoxSize.Width(),
135 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
137 aToolBoxSize
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() ),
146 Size(
147 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
148 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
152 onLayoutDone();
155 //------------------------------------------------------------------------------------------------------------------
156 void TitledDockingWindow::Paint( const Rectangle& i_rArea )
158 if ( m_bLayoutPending )
159 impl_layout();
161 SfxDockingWindow::Paint( i_rArea );
163 Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
165 SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
166 SetLineColor();
168 // bold font
169 Font aFont( GetFont() );
170 aFont.SetWeight( WEIGHT_BOLD );
171 SetFont( aFont );
173 // Set border values.
174 Size aWindowSize( GetOutputSizePixel() );
175 int nOuterLeft = 0;
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(
185 nOuterLeft,
187 nOuterRight,
188 nInnerTop-1
189 ) );
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.
200 SetFillColor();
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.
219 Pop();
222 //------------------------------------------------------------------------------------------------------------------
223 String TitledDockingWindow::impl_getTitle() const
225 return !m_sTitle.isEmpty() ? m_sTitle : GetText();
228 //------------------------------------------------------------------------------------------------------------------
229 void TitledDockingWindow::impl_resetToolBox()
231 m_aToolbox.Clear();
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
251 // resized.
252 impl_scheduleLayout();
253 Invalidate();
255 return nItemId;
258 //------------------------------------------------------------------------------------------------------------------
259 IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
261 const sal_uInt16 nId = pToolBox->GetCurItemId();
263 if ( nId == 1 )
265 // the closer
266 EndTracking();
267 const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
268 const SfxBoolItem aVisibility( nChildWindowId, sal_False );
269 GetBindings().GetDispatcher()->Execute(
270 nChildWindowId,
271 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
272 &aVisibility,
273 NULL
277 return 0;
280 //------------------------------------------------------------------------------------------------------------------
281 void TitledDockingWindow::StateChanged( StateChangedType i_nType )
283 switch ( i_nType )
285 case STATE_CHANGE_INITSHOW:
286 impl_scheduleLayout();
287 break;
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)
310 break;
311 // else fall through.
312 case DATACHANGED_FONTS:
313 case DATACHANGED_FONTSUBSTITUTION:
315 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
317 // Font.
318 Font aFont = rStyleSettings.GetAppFont();
319 if ( IsControlFont() )
320 aFont.Merge( GetControlFont() );
321 SetZoomedPointFont( aFont );
323 // Color.
324 Color aColor;
325 if ( IsControlForeground() )
326 aColor = GetControlForeground();
327 else
328 aColor = rStyleSettings.GetButtonTextColor();
329 SetTextColor( aColor );
330 SetTextFillColor();
332 impl_scheduleLayout();
333 Invalidate();
335 break;
339 //......................................................................................................................
340 } // namespace sfx2
341 //......................................................................................................................
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */