1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sfx2.hxx"
25 
26 #include "sfx2/titledockwin.hxx"
27 #include "sfx2/bindings.hxx"
28 #include "sfx2/dispatch.hxx"
29 #include "sfxlocal.hrc"
30 #include "sfxresid.hxx"
31 
32 #include <svl/eitem.hxx>
33 
34 //......................................................................................................................
35 namespace sfx2
36 {
37 //......................................................................................................................
38 
39 	//==================================================================================================================
40 	//= TitledDockingWindow
41 	//==================================================================================================================
42 	//------------------------------------------------------------------------------------------------------------------
TitledDockingWindow(SfxBindings * i_pBindings,SfxChildWindow * i_pChildWindow,Window * i_pParent,WinBits i_nStyle)43     TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
44             WinBits i_nStyle )
45         :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
46         ,m_sTitle()
47         ,m_aToolbox( this )
48         ,m_aContentWindow( this, WB_DIALOGCONTROL )
49         ,m_aBorder( 3, 1, 3, 3 )
50         ,m_bLayoutPending( false )
51         ,m_nTitleBarHeight(0)
52     {
53         impl_construct();
54     }
55 
56 	//------------------------------------------------------------------------------------------------------------------
TitledDockingWindow(SfxBindings * i_pBindings,SfxChildWindow * i_pChildWindow,Window * i_pParent,const ResId & i_rResId)57     TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
58             const ResId& i_rResId )
59         :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_rResId )
60         ,m_sTitle()
61         ,m_aToolbox( this )
62         ,m_aContentWindow( this )
63         ,m_aBorder( 3, 1, 3, 3 )
64         ,m_bLayoutPending( false )
65     {
66         impl_construct();
67     }
68 
69 	//------------------------------------------------------------------------------------------------------------------
impl_construct()70     void TitledDockingWindow::impl_construct()
71     {
72         SetBackground( Wallpaper() );
73 
74         m_aToolbox.SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
75         m_aToolbox.SetOutStyle( TOOLBOX_STYLE_FLAT );
76         m_aToolbox.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
77         m_aToolbox.Show();
78         impl_resetToolBox();
79 
80         m_aContentWindow.Show();
81     }
82 
83 	//------------------------------------------------------------------------------------------------------------------
~TitledDockingWindow()84     TitledDockingWindow::~TitledDockingWindow()
85     {
86     }
87 
88 	//------------------------------------------------------------------------------------------------------------------
SetTitle(const String & i_rTitle)89     void TitledDockingWindow::SetTitle( const String& i_rTitle )
90     {
91         m_sTitle = i_rTitle;
92         Invalidate();
93     }
94 
95 	//------------------------------------------------------------------------------------------------------------------
GetTitle() const96     String TitledDockingWindow::GetTitle() const
97     {
98         return impl_getTitle();
99     }
100 
101 	//------------------------------------------------------------------------------------------------------------------
SetText(const String & i_rText)102     void TitledDockingWindow::SetText( const String& i_rText )
103     {
104         SfxDockingWindow::SetText( i_rText );
105         if ( m_sTitle.Len() == 0 )
106             // our text is used as title, too => repaint
107             Invalidate();
108     }
109 
110     //------------------------------------------------------------------------------------------------------------------
Resize()111     void TitledDockingWindow::Resize()
112     {
113         SfxDockingWindow::Resize();
114         impl_scheduleLayout();
115     }
116 
117 	//------------------------------------------------------------------------------------------------------------------
onLayoutDone()118     void TitledDockingWindow::onLayoutDone()
119     {
120         // not interested in
121     }
122 
123 	//------------------------------------------------------------------------------------------------------------------
impl_scheduleLayout()124     void TitledDockingWindow::impl_scheduleLayout()
125     {
126         m_bLayoutPending = true;
127     }
128 
129 	//------------------------------------------------------------------------------------------------------------------
impl_layout()130     void TitledDockingWindow::impl_layout()
131     {
132         m_bLayoutPending = false;
133 
134         m_aToolbox.ShowItem( 1, !IsFloatingMode() );
135 
136         const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
137         Size aWindowSize( GetOutputSizePixel() );
138 
139         // position the tool box
140         m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
141         if ( aToolBoxSize.Height() > m_nTitleBarHeight )
142             m_nTitleBarHeight = aToolBoxSize.Height();
143         m_aToolbox.SetPosSizePixel(
144             Point(
145                 aWindowSize.Width() - aToolBoxSize.Width(),
146                 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
147             ),
148             aToolBoxSize
149         );
150 
151         // Place the content window.
152         if ( m_nTitleBarHeight < aToolBoxSize.Height() )
153             m_nTitleBarHeight = aToolBoxSize.Height();
154         aWindowSize.Height() -= m_nTitleBarHeight;
155         m_aContentWindow.SetPosSizePixel(
156             Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
157             Size(
158                 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
159                 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
160             )
161         );
162 
163         onLayoutDone();
164     }
165 
166 	//------------------------------------------------------------------------------------------------------------------
Paint(const Rectangle & i_rArea)167     void TitledDockingWindow::Paint( const Rectangle& i_rArea )
168     {
169         if ( m_bLayoutPending )
170             impl_layout();
171 
172         SfxDockingWindow::Paint( i_rArea );
173 
174         Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
175 
176         SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
177         SetLineColor();
178 
179         // bold font
180         Font aFont( GetFont() );
181         aFont.SetWeight( WEIGHT_BOLD );
182         SetFont( aFont );
183 
184         // Set border values.
185         Size aWindowSize( GetOutputSizePixel() );
186         int nOuterLeft = 0;
187         int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
188         int nOuterRight = aWindowSize.Width() - 1;
189         int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
190         int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
191         int nOuterBottom = aWindowSize.Height() - 1;
192         int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
193 
194         // Paint title bar background.
195         Rectangle aTitleBarBox( Rectangle(
196             nOuterLeft,
197             0,
198             nOuterRight,
199             nInnerTop-1
200         ) );
201         DrawRect( aTitleBarBox );
202 
203         if ( nInnerLeft > nOuterLeft )
204             DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
205         if ( nOuterRight > nInnerRight )
206             DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
207         if ( nInnerBottom < nOuterBottom )
208             DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );
209 
210         // Paint bevel border.
211         SetFillColor();
212         SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
213         if ( m_aBorder.Top() > 0 )
214             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
215         if ( m_aBorder.Left() > 0 )
216             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );
217 
218         SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
219         if ( m_aBorder.Bottom() > 0 )
220             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
221         if ( m_aBorder.Right() > 0 )
222             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );
223 
224         // Paint title bar text.
225         SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
226         aTitleBarBox.Left() += 3;
227         DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
228 
229         // Restore original values of the output device.
230         Pop();
231     }
232 
233 	//------------------------------------------------------------------------------------------------------------------
impl_getTitle() const234     String TitledDockingWindow::impl_getTitle() const
235     {
236         return m_sTitle.Len() ? m_sTitle : GetText();
237     }
238 
239 	//------------------------------------------------------------------------------------------------------------------
impl_resetToolBox()240     void TitledDockingWindow::impl_resetToolBox()
241     {
242         m_aToolbox.Clear();
243 
244         // Get the closer bitmap and set it as right most button.
245         Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
246         Image aImageHC( SfxResId( SFX_IMG_CLOSE_DOC_HC ) );
247         m_aToolbox.InsertItem( 1,
248                 GetSettings().GetStyleSettings().GetHighContrastMode()
249             ?   aImageHC
250             :   aImage
251         );
252         m_aToolbox.ShowItem( 1 );
253     }
254 
255 	//------------------------------------------------------------------------------------------------------------------
impl_addDropDownToolBoxItem(const String & i_rItemText,const rtl::OString & i_nHelpId,const Link & i_rCallback)256     sal_uInt16 TitledDockingWindow::impl_addDropDownToolBoxItem( const String& i_rItemText, const rtl::OString& i_nHelpId, const Link& i_rCallback )
257     {
258         // Add the menu before the closer button.
259         const sal_uInt16 nItemCount( m_aToolbox.GetItemCount() );
260 	    const sal_uInt16 nItemId( nItemCount + 1 );
261         m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
262 	    m_aToolbox.SetHelpId( nItemId, i_nHelpId );
263 	    m_aToolbox.SetClickHdl( i_rCallback );
264 	    m_aToolbox.SetDropdownClickHdl( i_rCallback );
265 
266         // The tool box has likely changed its size. The title bar has to be
267         // resized.
268         impl_scheduleLayout();
269         Invalidate();
270 
271         return nItemId;
272     }
273 
274 	//------------------------------------------------------------------------------------------------------------------
IMPL_LINK(TitledDockingWindow,OnToolboxItemSelected,ToolBox *,pToolBox)275     IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
276     {
277 	    const sal_uInt16 nId = pToolBox->GetCurItemId();
278 
279 	    if ( nId == 1 )
280         {
281             // the closer
282             EndTracking();
283             const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
284             const SfxBoolItem aVisibility( nChildWindowId, sal_False );
285             GetBindings().GetDispatcher()->Execute(
286                 nChildWindowId,
287                 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
288                 &aVisibility,
289                 NULL
290             );
291         }
292 
293 	    return 0;
294     }
295 
296 	//------------------------------------------------------------------------------------------------------------------
StateChanged(StateChangedType i_nType)297     void TitledDockingWindow::StateChanged( StateChangedType i_nType )
298     {
299         switch ( i_nType )
300         {
301             case STATE_CHANGE_INITSHOW:
302                 impl_scheduleLayout();
303                 break;
304         }
305         SfxDockingWindow::StateChanged( i_nType );
306     }
307 
308 	//------------------------------------------------------------------------------------------------------------------
EndDocking(const Rectangle & i_rRect,sal_Bool i_bFloatMode)309     void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, sal_Bool i_bFloatMode )
310     {
311         SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );
312 
313         if ( m_aEndDockingHdl.IsSet() )
314             m_aEndDockingHdl.Call( this );
315     }
316 
317 	//------------------------------------------------------------------------------------------------------------------
DataChanged(const DataChangedEvent & i_rDataChangedEvent)318     void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
319     {
320         SfxDockingWindow::DataChanged( i_rDataChangedEvent );
321 
322         switch ( i_rDataChangedEvent.GetType() )
323         {
324             case DATACHANGED_SETTINGS:
325                 if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
326                     break;
327                 // else fall through.
328             case DATACHANGED_FONTS:
329             case DATACHANGED_FONTSUBSTITUTION:
330             {
331                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
332 
333                 // Font.
334                 Font aFont = rStyleSettings.GetAppFont();
335                 if ( IsControlFont() )
336                     aFont.Merge( GetControlFont() );
337                 SetZoomedPointFont( aFont );
338 
339                 // Color.
340                 Color aColor;
341                 if ( IsControlForeground() )
342                     aColor = GetControlForeground();
343                 else
344                     aColor = rStyleSettings.GetButtonTextColor();
345                 SetTextColor( aColor );
346                 SetTextFillColor();
347 
348                 impl_scheduleLayout();
349                 Invalidate();
350             }
351             break;
352         }
353     }
354 
355 //......................................................................................................................
356 } // namespace sfx2
357 //......................................................................................................................
358