Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / titledockwin.cxx
blobe923fdc07a286900d3c92bd9982bccdfe97e04e8
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 //......................................................................................................................
38 namespace sfx2
40 //......................................................................................................................
42 //==================================================================================================================
43 //= TitledDockingWindow
44 //==================================================================================================================
45 //------------------------------------------------------------------------------------------------------------------
46 TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
47 WinBits i_nStyle )
48 :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
49 ,m_sTitle()
50 ,m_aToolbox( this )
51 ,m_aContentWindow( this, WB_DIALOGCONTROL )
52 ,m_aBorder( 3, 1, 3, 3 )
53 ,m_bLayoutPending( false )
54 ,m_nTitleBarHeight(0)
56 impl_construct();
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 )
63 ,m_sTitle()
64 ,m_aToolbox( this )
65 ,m_aContentWindow( this )
66 ,m_aBorder( 3, 1, 3, 3 )
67 ,m_bLayoutPending( false )
69 impl_construct();
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() ) );
80 m_aToolbox.Show();
81 impl_resetToolBox();
83 m_aContentWindow.Show();
86 //------------------------------------------------------------------------------------------------------------------
87 TitledDockingWindow::~TitledDockingWindow()
91 //------------------------------------------------------------------------------------------------------------------
92 void TitledDockingWindow::SetTitle( const String& i_rTitle )
94 m_sTitle = i_rTitle;
95 Invalidate();
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
104 Invalidate();
107 //------------------------------------------------------------------------------------------------------------------
108 void TitledDockingWindow::Resize()
110 SfxDockingWindow::Resize();
111 impl_scheduleLayout();
114 //------------------------------------------------------------------------------------------------------------------
115 void TitledDockingWindow::onLayoutDone()
117 // not interested in
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(
141 Point(
142 aWindowSize.Width() - aToolBoxSize.Width(),
143 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
145 aToolBoxSize
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() ),
154 Size(
155 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
156 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
160 onLayoutDone();
163 //------------------------------------------------------------------------------------------------------------------
164 void TitledDockingWindow::Paint( const Rectangle& i_rArea )
166 if ( m_bLayoutPending )
167 impl_layout();
169 SfxDockingWindow::Paint( i_rArea );
171 Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
173 SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
174 SetLineColor();
176 // bold font
177 Font aFont( GetFont() );
178 aFont.SetWeight( WEIGHT_BOLD );
179 SetFont( aFont );
181 // Set border values.
182 Size aWindowSize( GetOutputSizePixel() );
183 int nOuterLeft = 0;
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(
193 nOuterLeft,
195 nOuterRight,
196 nInnerTop-1
197 ) );
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.
208 SetFillColor();
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.
227 Pop();
230 //------------------------------------------------------------------------------------------------------------------
231 String TitledDockingWindow::impl_getTitle() const
233 return m_sTitle.Len() ? m_sTitle : GetText();
236 //------------------------------------------------------------------------------------------------------------------
237 void TitledDockingWindow::impl_resetToolBox()
239 m_aToolbox.Clear();
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
259 // resized.
260 impl_scheduleLayout();
261 Invalidate();
263 return nItemId;
266 //------------------------------------------------------------------------------------------------------------------
267 IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
269 const sal_uInt16 nId = pToolBox->GetCurItemId();
271 if ( nId == 1 )
273 // the closer
274 EndTracking();
275 const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
276 const SfxBoolItem aVisibility( nChildWindowId, sal_False );
277 GetBindings().GetDispatcher()->Execute(
278 nChildWindowId,
279 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
280 &aVisibility,
281 NULL
285 return 0;
288 //------------------------------------------------------------------------------------------------------------------
289 void TitledDockingWindow::StateChanged( StateChangedType i_nType )
291 switch ( i_nType )
293 case STATE_CHANGE_INITSHOW:
294 impl_scheduleLayout();
295 break;
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)
318 break;
319 // else fall through.
320 case DATACHANGED_FONTS:
321 case DATACHANGED_FONTSUBSTITUTION:
323 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
325 // Font.
326 Font aFont = rStyleSettings.GetAppFont();
327 if ( IsControlFont() )
328 aFont.Merge( GetControlFont() );
329 SetZoomedPointFont( aFont );
331 // Color.
332 Color aColor;
333 if ( IsControlForeground() )
334 aColor = GetControlForeground();
335 else
336 aColor = rStyleSettings.GetButtonTextColor();
337 SetTextColor( aColor );
338 SetTextFillColor();
340 impl_scheduleLayout();
341 Invalidate();
343 break;
347 //......................................................................................................................
348 } // namespace sfx2
349 //......................................................................................................................
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */