Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "sfx2/titledockwin.hxx"
22 : : #include "sfx2/bindings.hxx"
23 : : #include "sfx2/dispatch.hxx"
24 : : #include "sfxlocal.hrc"
25 : : #include "sfxresid.hxx"
26 : :
27 : : #include <svl/eitem.hxx>
28 : :
29 : : //......................................................................................................................
30 : : namespace sfx2
31 : : {
32 : : //......................................................................................................................
33 : :
34 : : //==================================================================================================================
35 : : //= TitledDockingWindow
36 : : //==================================================================================================================
37 : : //------------------------------------------------------------------------------------------------------------------
38 : 0 : 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 [ # # ][ # # ]: 0 : ,m_nTitleBarHeight(0)
[ # # ][ # # ]
47 : : {
48 [ # # ]: 0 : impl_construct();
49 : 0 : }
50 : :
51 : : //------------------------------------------------------------------------------------------------------------------
52 : 156 : 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 [ + - ][ + - ]: 156 : ,m_bLayoutPending( false )
[ + - ][ + - ]
60 : : {
61 [ + - ]: 156 : impl_construct();
62 : 156 : }
63 : :
64 : : //------------------------------------------------------------------------------------------------------------------
65 : 156 : void TitledDockingWindow::impl_construct()
66 : : {
67 [ + - ]: 156 : SetBackground( Wallpaper() );
68 : :
69 : 156 : m_aToolbox.SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
70 : 156 : m_aToolbox.SetOutStyle( TOOLBOX_STYLE_FLAT );
71 [ + - ]: 156 : m_aToolbox.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
72 : 156 : m_aToolbox.Show();
73 : 156 : impl_resetToolBox();
74 : :
75 : 156 : m_aContentWindow.Show();
76 : 156 : }
77 : :
78 : : //------------------------------------------------------------------------------------------------------------------
79 [ + - ][ + - ]: 156 : TitledDockingWindow::~TitledDockingWindow()
[ + - ]
80 : : {
81 [ - + ]: 156 : }
82 : :
83 : : //------------------------------------------------------------------------------------------------------------------
84 : 208 : void TitledDockingWindow::SetTitle( const String& i_rTitle )
85 : : {
86 : 208 : m_sTitle = i_rTitle;
87 : 208 : Invalidate();
88 : 208 : }
89 : :
90 : : //------------------------------------------------------------------------------------------------------------------
91 : 0 : void TitledDockingWindow::SetText( const String& i_rText )
92 : : {
93 : 0 : SfxDockingWindow::SetText( i_rText );
94 [ # # ]: 0 : if ( m_sTitle.Len() == 0 )
95 : : // our text is used as title, too => repaint
96 : 0 : Invalidate();
97 : 0 : }
98 : :
99 : : //------------------------------------------------------------------------------------------------------------------
100 : 411 : void TitledDockingWindow::Resize()
101 : : {
102 : 411 : SfxDockingWindow::Resize();
103 : 411 : impl_scheduleLayout();
104 : 411 : }
105 : :
106 : : //------------------------------------------------------------------------------------------------------------------
107 : 163 : void TitledDockingWindow::onLayoutDone()
108 : : {
109 : : // not interested in
110 : 163 : }
111 : :
112 : : //------------------------------------------------------------------------------------------------------------------
113 : 437 : void TitledDockingWindow::impl_scheduleLayout()
114 : : {
115 : 437 : m_bLayoutPending = true;
116 : 437 : }
117 : :
118 : : //------------------------------------------------------------------------------------------------------------------
119 : 163 : void TitledDockingWindow::impl_layout()
120 : : {
121 : 163 : m_bLayoutPending = false;
122 : :
123 [ + - ][ + - ]: 163 : m_aToolbox.ShowItem( 1, !IsFloatingMode() );
124 : :
125 [ + - ]: 163 : const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
126 [ + - ]: 163 : Size aWindowSize( GetOutputSizePixel() );
127 : :
128 : : // position the tool box
129 : 163 : m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
130 [ + + ]: 163 : if ( aToolBoxSize.Height() > m_nTitleBarHeight )
131 : 30 : m_nTitleBarHeight = aToolBoxSize.Height();
132 : : m_aToolbox.SetPosSizePixel(
133 : : Point(
134 : 163 : aWindowSize.Width() - aToolBoxSize.Width(),
135 : 163 : ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
136 : : ),
137 : : aToolBoxSize
138 [ + - ]: 163 : );
139 : :
140 : : // Place the content window.
141 [ - + ]: 163 : if ( m_nTitleBarHeight < aToolBoxSize.Height() )
142 : 0 : m_nTitleBarHeight = aToolBoxSize.Height();
143 : 163 : aWindowSize.Height() -= m_nTitleBarHeight;
144 : : m_aContentWindow.SetPosSizePixel(
145 : 163 : Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
146 : : Size(
147 : 163 : aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
148 : 163 : aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
149 : : )
150 [ + - ]: 326 : );
151 : :
152 [ + - ]: 163 : onLayoutDone();
153 : 163 : }
154 : :
155 : : //------------------------------------------------------------------------------------------------------------------
156 : 280 : void TitledDockingWindow::Paint( const Rectangle& i_rArea )
157 : : {
158 [ + + ]: 280 : if ( m_bLayoutPending )
159 [ + - ]: 163 : impl_layout();
160 : :
161 [ + - ]: 280 : SfxDockingWindow::Paint( i_rArea );
162 : :
163 [ + - ]: 280 : Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
164 : :
165 [ + - ]: 280 : SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
166 [ + - ]: 280 : SetLineColor();
167 : :
168 : : // bold font
169 [ + - ]: 280 : Font aFont( GetFont() );
170 [ + - ]: 280 : aFont.SetWeight( WEIGHT_BOLD );
171 [ + - ]: 280 : SetFont( aFont );
172 : :
173 : : // Set border values.
174 [ + - ]: 280 : Size aWindowSize( GetOutputSizePixel() );
175 : 280 : int nOuterLeft = 0;
176 : 280 : int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
177 : 280 : int nOuterRight = aWindowSize.Width() - 1;
178 : 280 : int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
179 : 280 : int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
180 : 280 : int nOuterBottom = aWindowSize.Height() - 1;
181 : 280 : int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
182 : :
183 : : // Paint title bar background.
184 : : Rectangle aTitleBarBox( Rectangle(
185 : : nOuterLeft,
186 : : 0,
187 : : nOuterRight,
188 : : nInnerTop-1
189 [ + - ]: 280 : ) );
190 [ + - ]: 280 : DrawRect( aTitleBarBox );
191 : :
192 [ + - ]: 280 : if ( nInnerLeft > nOuterLeft )
193 [ + - ][ + - ]: 280 : DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
194 [ + - ]: 280 : if ( nOuterRight > nInnerRight )
195 [ + - ][ + - ]: 280 : DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
196 [ + - ]: 280 : if ( nInnerBottom < nOuterBottom )
197 [ + - ][ + - ]: 280 : DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );
198 : :
199 : : // Paint bevel border.
200 [ + - ]: 280 : SetFillColor();
201 [ + - ]: 280 : SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
202 [ + - ]: 280 : if ( m_aBorder.Top() > 0 )
203 [ + - ]: 280 : DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
204 [ + - ]: 280 : if ( m_aBorder.Left() > 0 )
205 [ + - ]: 280 : DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );
206 : :
207 [ + - ]: 280 : SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
208 [ + - ]: 280 : if ( m_aBorder.Bottom() > 0 )
209 [ + - ]: 280 : DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
210 [ + - ]: 280 : if ( m_aBorder.Right() > 0 )
211 [ + - ]: 280 : DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );
212 : :
213 : : // Paint title bar text.
214 [ + - ]: 280 : SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
215 : 280 : aTitleBarBox.Left() += 3;
216 [ + - ][ + - ]: 280 : DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
[ + - ]
217 : :
218 : : // Restore original values of the output device.
219 [ + - ][ + - ]: 280 : Pop();
220 : 280 : }
221 : :
222 : : //------------------------------------------------------------------------------------------------------------------
223 : 280 : String TitledDockingWindow::impl_getTitle() const
224 : : {
225 [ + - ]: 280 : return m_sTitle.Len() ? m_sTitle : GetText();
226 : : }
227 : :
228 : : //------------------------------------------------------------------------------------------------------------------
229 : 182 : void TitledDockingWindow::impl_resetToolBox()
230 : : {
231 [ + - ]: 182 : m_aToolbox.Clear();
232 : :
233 : : // Get the closer bitmap and set it as right most button.
234 [ + - ][ + - ]: 182 : Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
235 [ + - ]: 182 : m_aToolbox.InsertItem( 1, aImage );
236 [ + - ][ + - ]: 182 : m_aToolbox.ShowItem( 1 );
237 : 182 : }
238 : :
239 : : //------------------------------------------------------------------------------------------------------------------
240 : 26 : sal_uInt16 TitledDockingWindow::impl_addDropDownToolBoxItem( const String& i_rItemText, const rtl::OString& i_nHelpId, const Link& i_rCallback )
241 : : {
242 : : // Add the menu before the closer button.
243 : 26 : const sal_uInt16 nItemCount( m_aToolbox.GetItemCount() );
244 : 26 : const sal_uInt16 nItemId( nItemCount + 1 );
245 [ + - ]: 26 : m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
246 : 26 : m_aToolbox.SetHelpId( nItemId, i_nHelpId );
247 : 26 : m_aToolbox.SetClickHdl( i_rCallback );
248 : 26 : m_aToolbox.SetDropdownClickHdl( i_rCallback );
249 : :
250 : : // The tool box has likely changed its size. The title bar has to be
251 : : // resized.
252 : 26 : impl_scheduleLayout();
253 : 26 : Invalidate();
254 : :
255 : 26 : return nItemId;
256 : : }
257 : :
258 : : //------------------------------------------------------------------------------------------------------------------
259 : 0 : IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
260 : : {
261 : 0 : const sal_uInt16 nId = pToolBox->GetCurItemId();
262 : :
263 [ # # ]: 0 : if ( nId == 1 )
264 : : {
265 : : // the closer
266 [ # # ]: 0 : EndTracking();
267 : 0 : const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
268 [ # # ]: 0 : const SfxBoolItem aVisibility( nChildWindowId, sal_False );
269 : 0 : GetBindings().GetDispatcher()->Execute(
270 : : nChildWindowId,
271 : : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
272 : : &aVisibility,
273 : : NULL
274 [ # # ][ # # ]: 0 : );
275 : : }
276 : :
277 : 0 : return 0;
278 : : }
279 : :
280 : : //------------------------------------------------------------------------------------------------------------------
281 : 0 : void TitledDockingWindow::StateChanged( StateChangedType i_nType )
282 : : {
283 [ # # ]: 0 : switch ( i_nType )
284 : : {
285 : : case STATE_CHANGE_INITSHOW:
286 : 0 : impl_scheduleLayout();
287 : 0 : break;
288 : : }
289 : 0 : SfxDockingWindow::StateChanged( i_nType );
290 : 0 : }
291 : :
292 : : //------------------------------------------------------------------------------------------------------------------
293 : 0 : void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, sal_Bool i_bFloatMode )
294 : : {
295 : 0 : SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );
296 : :
297 [ # # ]: 0 : if ( m_aEndDockingHdl.IsSet() )
298 : 0 : m_aEndDockingHdl.Call( this );
299 : 0 : }
300 : :
301 : : //------------------------------------------------------------------------------------------------------------------
302 : 0 : void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
303 : : {
304 : 0 : SfxDockingWindow::DataChanged( i_rDataChangedEvent );
305 : :
306 [ # # # ]: 0 : switch ( i_rDataChangedEvent.GetType() )
307 : : {
308 : : case DATACHANGED_SETTINGS:
309 [ # # ]: 0 : if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
310 : 0 : break;
311 : : // else fall through.
312 : : case DATACHANGED_FONTS:
313 : : case DATACHANGED_FONTSUBSTITUTION:
314 : : {
315 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
316 : :
317 : : // Font.
318 [ # # ]: 0 : Font aFont = rStyleSettings.GetAppFont();
319 [ # # ][ # # ]: 0 : if ( IsControlFont() )
320 [ # # ][ # # ]: 0 : aFont.Merge( GetControlFont() );
[ # # ]
321 [ # # ]: 0 : SetZoomedPointFont( aFont );
322 : :
323 : : // Color.
324 : 0 : Color aColor;
325 [ # # ][ # # ]: 0 : if ( IsControlForeground() )
326 [ # # ]: 0 : aColor = GetControlForeground();
327 : : else
328 : 0 : aColor = rStyleSettings.GetButtonTextColor();
329 [ # # ]: 0 : SetTextColor( aColor );
330 [ # # ]: 0 : SetTextFillColor();
331 : :
332 [ # # ]: 0 : impl_scheduleLayout();
333 [ # # ][ # # ]: 0 : Invalidate();
334 : : }
335 : 0 : break;
336 : : }
337 : 0 : }
338 : :
339 : : //......................................................................................................................
340 : : } // namespace sfx2
341 : : //......................................................................................................................
342 : :
343 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|