1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
10  * OpenOffice.org is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License version 3
12  * only, as published by the Free Software Foundation.
13  *
14  * OpenOffice.org is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License version 3 for more details
18  * (a copy is included in the LICENSE file that accompanied this code).
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with OpenOffice.org.  If not, see
22  * <http://www.openoffice.org/license.html>
23  * for a copy of the LGPLv3 License.
24  *
25  ************************************************************************/
26 
27 #include "precompiled_sfx2.hxx"
28 
29 #include "sfx2/titledockwin.hxx"
30 #include "sfx2/bindings.hxx"
31 #include "sfx2/dispatch.hxx"
32 #include "sfxlocal.hrc"
33 #include "sfxresid.hxx"
34 
35 #include <svl/eitem.hxx>
36 
37 //......................................................................................................................
38 namespace sfx2
39 {
40 //......................................................................................................................
41 
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)
55     {
56         impl_construct();
57     }
58 
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 )
68     {
69         impl_construct();
70     }
71 
72 	//------------------------------------------------------------------------------------------------------------------
73     void TitledDockingWindow::impl_construct()
74     {
75         SetBackground( Wallpaper() );
76 
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();
82 
83         m_aContentWindow.Show();
84     }
85 
86 	//------------------------------------------------------------------------------------------------------------------
87     TitledDockingWindow::~TitledDockingWindow()
88     {
89     }
90 
91 	//------------------------------------------------------------------------------------------------------------------
92     void TitledDockingWindow::SetTitle( const String& i_rTitle )
93     {
94         m_sTitle = i_rTitle;
95         Invalidate();
96     }
97 
98 	//------------------------------------------------------------------------------------------------------------------
99     String TitledDockingWindow::GetTitle() const
100     {
101         return impl_getTitle();
102     }
103 
104 	//------------------------------------------------------------------------------------------------------------------
105     void TitledDockingWindow::SetText( const String& i_rText )
106     {
107         SfxDockingWindow::SetText( i_rText );
108         if ( m_sTitle.Len() == 0 )
109             // our text is used as title, too => repaint
110             Invalidate();
111     }
112 
113     //------------------------------------------------------------------------------------------------------------------
114     void TitledDockingWindow::Resize()
115     {
116         SfxDockingWindow::Resize();
117         impl_scheduleLayout();
118     }
119 
120 	//------------------------------------------------------------------------------------------------------------------
121     void TitledDockingWindow::onLayoutDone()
122     {
123         // not interested in
124     }
125 
126 	//------------------------------------------------------------------------------------------------------------------
127     void TitledDockingWindow::impl_scheduleLayout()
128     {
129         m_bLayoutPending = true;
130     }
131 
132 	//------------------------------------------------------------------------------------------------------------------
133     void TitledDockingWindow::impl_layout()
134     {
135         m_bLayoutPending = false;
136 
137         m_aToolbox.ShowItem( 1, !IsFloatingMode() );
138 
139         const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
140         Size aWindowSize( GetOutputSizePixel() );
141 
142         // position the tool box
143         m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
144         if ( aToolBoxSize.Height() > m_nTitleBarHeight )
145             m_nTitleBarHeight = aToolBoxSize.Height();
146         m_aToolbox.SetPosSizePixel(
147             Point(
148                 aWindowSize.Width() - aToolBoxSize.Width(),
149                 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
150             ),
151             aToolBoxSize
152         );
153 
154         // Place the content window.
155         if ( m_nTitleBarHeight < aToolBoxSize.Height() )
156             m_nTitleBarHeight = aToolBoxSize.Height();
157         aWindowSize.Height() -= m_nTitleBarHeight;
158         m_aContentWindow.SetPosSizePixel(
159             Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
160             Size(
161                 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
162                 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
163             )
164         );
165 
166         onLayoutDone();
167     }
168 
169 	//------------------------------------------------------------------------------------------------------------------
170     void TitledDockingWindow::Paint( const Rectangle& i_rArea )
171     {
172         if ( m_bLayoutPending )
173             impl_layout();
174 
175         SfxDockingWindow::Paint( i_rArea );
176 
177         Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
178 
179         SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
180         SetLineColor();
181 
182         // bold font
183         Font aFont( GetFont() );
184         aFont.SetWeight( WEIGHT_BOLD );
185         SetFont( aFont );
186 
187         // Set border values.
188         Size aWindowSize( GetOutputSizePixel() );
189         int nOuterLeft = 0;
190         int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
191         int nOuterRight = aWindowSize.Width() - 1;
192         int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
193         int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
194         int nOuterBottom = aWindowSize.Height() - 1;
195         int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
196 
197         // Paint title bar background.
198         Rectangle aTitleBarBox( Rectangle(
199             nOuterLeft,
200             0,
201             nOuterRight,
202             nInnerTop-1
203         ) );
204         DrawRect( aTitleBarBox );
205 
206         if ( nInnerLeft > nOuterLeft )
207             DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
208         if ( nOuterRight > nInnerRight )
209             DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
210         if ( nInnerBottom < nOuterBottom )
211             DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );
212 
213         // Paint bevel border.
214         SetFillColor();
215         SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
216         if ( m_aBorder.Top() > 0 )
217             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
218         if ( m_aBorder.Left() > 0 )
219             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );
220 
221         SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
222         if ( m_aBorder.Bottom() > 0 )
223             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
224         if ( m_aBorder.Right() > 0 )
225             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );
226 
227         // Paint title bar text.
228         SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
229         aTitleBarBox.Left() += 3;
230         DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
231 
232         // Restore original values of the output device.
233         Pop();
234     }
235 
236 	//------------------------------------------------------------------------------------------------------------------
237     String TitledDockingWindow::impl_getTitle() const
238     {
239         return m_sTitle.Len() ? m_sTitle : GetText();
240     }
241 
242 	//------------------------------------------------------------------------------------------------------------------
243     void TitledDockingWindow::impl_resetToolBox()
244     {
245         m_aToolbox.Clear();
246 
247         // Get the closer bitmap and set it as right most button.
248         Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
249         Image aImageHC( SfxResId( SFX_IMG_CLOSE_DOC_HC ) );
250         m_aToolbox.InsertItem( 1,
251                 GetSettings().GetStyleSettings().GetHighContrastMode()
252             ?   aImageHC
253             :   aImage
254         );
255         m_aToolbox.ShowItem( 1 );
256     }
257 
258 	//------------------------------------------------------------------------------------------------------------------
259     sal_uInt16 TitledDockingWindow::impl_addDropDownToolBoxItem( const String& i_rItemText, const rtl::OString& i_nHelpId, const Link& i_rCallback )
260     {
261         // Add the menu before the closer button.
262         const sal_uInt16 nItemCount( m_aToolbox.GetItemCount() );
263 	    const sal_uInt16 nItemId( nItemCount + 1 );
264         m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
265 	    m_aToolbox.SetHelpId( nItemId, i_nHelpId );
266 	    m_aToolbox.SetClickHdl( i_rCallback );
267 	    m_aToolbox.SetDropdownClickHdl( i_rCallback );
268 
269         // The tool box has likely changed its size. The title bar has to be
270         // resized.
271         impl_scheduleLayout();
272         Invalidate();
273 
274         return nItemId;
275     }
276 
277 	//------------------------------------------------------------------------------------------------------------------
278     IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
279     {
280 	    const sal_uInt16 nId = pToolBox->GetCurItemId();
281 
282 	    if ( nId == 1 )
283         {
284             // the closer
285             EndTracking();
286             const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
287             const SfxBoolItem aVisibility( nChildWindowId, sal_False );
288             GetBindings().GetDispatcher()->Execute(
289                 nChildWindowId,
290                 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
291                 &aVisibility,
292                 NULL
293             );
294         }
295 
296 	    return 0;
297     }
298 
299 	//------------------------------------------------------------------------------------------------------------------
300     void TitledDockingWindow::StateChanged( StateChangedType i_nType )
301     {
302         switch ( i_nType )
303         {
304             case STATE_CHANGE_INITSHOW:
305                 impl_scheduleLayout();
306                 break;
307         }
308         SfxDockingWindow::StateChanged( i_nType );
309     }
310 
311 	//------------------------------------------------------------------------------------------------------------------
312     void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, sal_Bool i_bFloatMode )
313     {
314         SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );
315 
316         if ( m_aEndDockingHdl.IsSet() )
317             m_aEndDockingHdl.Call( this );
318     }
319 
320 	//------------------------------------------------------------------------------------------------------------------
321     void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
322     {
323         SfxDockingWindow::DataChanged( i_rDataChangedEvent );
324 
325         switch ( i_rDataChangedEvent.GetType() )
326         {
327             case DATACHANGED_SETTINGS:
328                 if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
329                     break;
330                 // else fall through.
331             case DATACHANGED_FONTS:
332             case DATACHANGED_FONTSUBSTITUTION:
333             {
334                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
335 
336                 // Font.
337                 Font aFont = rStyleSettings.GetAppFont();
338                 if ( IsControlFont() )
339                     aFont.Merge( GetControlFont() );
340                 SetZoomedPointFont( aFont );
341 
342                 // Color.
343                 Color aColor;
344                 if ( IsControlForeground() )
345                     aColor = GetControlForeground();
346                 else
347                     aColor = rStyleSettings.GetButtonTextColor();
348                 SetTextColor( aColor );
349                 SetTextFillColor();
350 
351                 impl_scheduleLayout();
352                 Invalidate();
353             }
354             break;
355         }
356     }
357 
358 //......................................................................................................................
359 } // namespace sfx2
360 //......................................................................................................................
361