1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/sfxresid.hxx>
27 #include <svl/eitem.hxx>
28 #include <vcl/settings.hxx>
33 //= TitledDockingWindow
34 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, vcl::Window
* i_pParent
,
36 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, i_nStyle
)
38 ,m_aToolbox( VclPtr
<ToolBox
>::Create(this) )
39 ,m_aContentWindow( VclPtr
<vcl::Window
>::Create(this, WB_DIALOGCONTROL
) )
40 ,m_aBorder( 3, 1, 3, 3 )
41 ,m_bLayoutPending( false )
47 void TitledDockingWindow::impl_construct()
49 SetBackground( Wallpaper() );
51 m_aToolbox
->SetSelectHdl( LINK( this, TitledDockingWindow
, OnToolboxItemSelected
) );
52 m_aToolbox
->SetOutStyle( TOOLBOX_STYLE_FLAT
);
53 m_aToolbox
->SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
57 m_aContentWindow
->Show();
60 TitledDockingWindow::~TitledDockingWindow()
65 void TitledDockingWindow::dispose()
67 m_aToolbox
.disposeAndClear();
68 m_aContentWindow
.disposeAndClear();
69 SfxDockingWindow::dispose();
72 void TitledDockingWindow::SetTitle( const OUString
& i_rTitle
)
79 void TitledDockingWindow::SetText( const OUString
& i_rText
)
81 SfxDockingWindow::SetText( i_rText
);
82 if ( m_sTitle
.isEmpty() )
83 // our text is used as title, too => repaint
88 void TitledDockingWindow::Resize()
90 SfxDockingWindow::Resize();
91 impl_scheduleLayout();
95 void TitledDockingWindow::onLayoutDone()
101 void TitledDockingWindow::impl_scheduleLayout()
103 m_bLayoutPending
= true;
107 void TitledDockingWindow::impl_layout()
109 m_bLayoutPending
= false;
111 m_aToolbox
->ShowItem( 1, !IsFloatingMode() );
113 const Size
aToolBoxSize( m_aToolbox
->CalcWindowSizePixel() );
114 Size
aWindowSize( GetOutputSizePixel() );
116 // position the tool box
117 m_nTitleBarHeight
= GetSettings().GetStyleSettings().GetTitleHeight();
118 if ( aToolBoxSize
.Height() > m_nTitleBarHeight
)
119 m_nTitleBarHeight
= aToolBoxSize
.Height();
120 m_aToolbox
->SetPosSizePixel(
122 aWindowSize
.Width() - aToolBoxSize
.Width(),
123 ( m_nTitleBarHeight
- aToolBoxSize
.Height() ) / 2
128 // Place the content window.
129 if ( m_nTitleBarHeight
< aToolBoxSize
.Height() )
130 m_nTitleBarHeight
= aToolBoxSize
.Height();
131 aWindowSize
.Height() -= m_nTitleBarHeight
;
132 m_aContentWindow
->SetPosSizePixel(
133 Point( m_aBorder
.Left(), m_nTitleBarHeight
+ m_aBorder
.Top() ),
135 aWindowSize
.Width() - m_aBorder
.Left() - m_aBorder
.Right(),
136 aWindowSize
.Height() - m_aBorder
.Top() - m_aBorder
.Bottom()
143 void TitledDockingWindow::ApplySettings(vcl::RenderContext
& rRenderContext
)
145 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
148 ApplyControlFont(rRenderContext
, rStyleSettings
.GetAppFont());
151 ApplyControlForeground(rRenderContext
, rStyleSettings
.GetButtonTextColor());
152 rRenderContext
.SetTextFillColor();
155 void TitledDockingWindow::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& i_rArea
)
157 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
159 if (m_bLayoutPending
)
162 SfxDockingWindow::Paint(rRenderContext
, i_rArea
);
164 rRenderContext
.Push(PushFlags::FONT
| PushFlags::FILLCOLOR
| PushFlags::LINECOLOR
);
166 rRenderContext
.SetFillColor(rStyleSettings
.GetDialogColor());
167 rRenderContext
.SetLineColor();
170 vcl::Font
aFont(rRenderContext
.GetFont());
171 aFont
.SetWeight(WEIGHT_BOLD
);
172 rRenderContext
.SetFont(aFont
);
174 // Set border values.
175 Size
aWindowSize(GetOutputSizePixel());
177 int nInnerLeft
= nOuterLeft
+ m_aBorder
.Left() - 1;
178 int nOuterRight
= aWindowSize
.Width() - 1;
179 int nInnerRight
= nOuterRight
- m_aBorder
.Right() + 1;
180 int nInnerTop
= m_nTitleBarHeight
+ m_aBorder
.Top() - 1;
181 int nOuterBottom
= aWindowSize
.Height() - 1;
182 int nInnerBottom
= nOuterBottom
- m_aBorder
.Bottom() + 1;
184 // Paint title bar background.
185 Rectangle
aTitleBarBox(Rectangle(nOuterLeft
, 0, nOuterRight
, nInnerTop
- 1));
186 rRenderContext
.DrawRect(aTitleBarBox
);
188 if (nInnerLeft
> nOuterLeft
)
189 rRenderContext
.DrawRect(Rectangle(nOuterLeft
, nInnerTop
, nInnerLeft
, nInnerBottom
));
190 if (nOuterRight
> nInnerRight
)
191 rRenderContext
.DrawRect(Rectangle(nInnerRight
, nInnerTop
, nOuterRight
, nInnerBottom
));
192 if (nInnerBottom
< nOuterBottom
)
193 rRenderContext
.DrawRect(Rectangle(nOuterLeft
, nInnerBottom
, nOuterRight
, nOuterBottom
));
195 // Paint bevel border.
196 rRenderContext
.SetFillColor();
197 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
198 if (m_aBorder
.Top() > 0)
199 rRenderContext
.DrawLine(Point(nInnerLeft
, nInnerTop
), Point(nInnerLeft
, nInnerBottom
));
200 if (m_aBorder
.Left() > 0)
201 rRenderContext
.DrawLine(Point(nInnerLeft
, nInnerTop
), Point(nInnerRight
, nInnerTop
));
203 rRenderContext
.SetLineColor(rStyleSettings
.GetLightColor());
204 if (m_aBorder
.Bottom() > 0)
205 rRenderContext
.DrawLine(Point(nInnerRight
, nInnerBottom
), Point(nInnerLeft
, nInnerBottom
));
206 if (m_aBorder
.Right() > 0)
207 rRenderContext
.DrawLine(Point(nInnerRight
, nInnerBottom
), Point(nInnerRight
, nInnerTop
));
209 // Paint title bar text.
210 rRenderContext
.SetLineColor(rStyleSettings
.GetActiveTextColor());
211 aTitleBarBox
.Left() += 3;
212 rRenderContext
.DrawText(aTitleBarBox
, impl_getTitle(),
213 DrawTextFlags::Left
| DrawTextFlags::VCenter
| DrawTextFlags::MultiLine
| DrawTextFlags::WordBreak
);
215 // Restore original values of the output device.
216 rRenderContext
.Pop();
220 OUString
TitledDockingWindow::impl_getTitle() const
222 return !m_sTitle
.isEmpty() ? m_sTitle
: GetText();
226 void TitledDockingWindow::impl_resetToolBox()
230 // Get the closer bitmap and set it as right most button.
231 Image
aImage( SfxResId( SFX_IMG_CLOSE_DOC
) );
232 m_aToolbox
->InsertItem( 1, aImage
);
233 m_aToolbox
->ShowItem( 1 );
237 sal_uInt16
TitledDockingWindow::impl_addDropDownToolBoxItem( const OUString
& i_rItemText
, const OString
& i_nHelpId
, const Link
<ToolBox
*, void>& i_rCallback
)
239 // Add the menu before the closer button.
240 const sal_uInt16
nItemCount( m_aToolbox
->GetItemCount() );
241 const sal_uInt16
nItemId( nItemCount
+ 1 );
242 m_aToolbox
->InsertItem( nItemId
, i_rItemText
, ToolBoxItemBits::DROPDOWNONLY
, nItemCount
> 0 ? nItemCount
- 1 : TOOLBOX_APPEND
);
243 m_aToolbox
->SetHelpId( nItemId
, i_nHelpId
);
244 m_aToolbox
->SetClickHdl( i_rCallback
);
245 m_aToolbox
->SetDropdownClickHdl( i_rCallback
);
247 // The tool box has likely changed its size. The title bar has to be
249 impl_scheduleLayout();
256 IMPL_LINK_TYPED( TitledDockingWindow
, OnToolboxItemSelected
, ToolBox
*, pToolBox
, void )
258 const sal_uInt16 nId
= pToolBox
->GetCurItemId();
264 const sal_uInt16
nChildWindowId( GetChildWindow_Impl()->GetType() );
265 const SfxBoolItem
aVisibility( nChildWindowId
, false );
266 GetBindings().GetDispatcher()->Execute(
268 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
276 void TitledDockingWindow::StateChanged( StateChangedType i_nType
)
280 case StateChangedType::InitShow
:
281 impl_scheduleLayout();
285 SfxDockingWindow::StateChanged( i_nType
);
288 void TitledDockingWindow::EndDocking( const Rectangle
& i_rRect
, bool i_bFloatMode
)
290 SfxDockingWindow::EndDocking( i_rRect
, i_bFloatMode
);
292 if ( m_aEndDockingHdl
.IsSet() )
293 m_aEndDockingHdl
.Call( this );
297 void TitledDockingWindow::DataChanged( const DataChangedEvent
& i_rDataChangedEvent
)
299 SfxDockingWindow::DataChanged( i_rDataChangedEvent
);
301 switch ( i_rDataChangedEvent
.GetType() )
303 case DataChangedEventType::SETTINGS
:
304 if ( !( i_rDataChangedEvent
.GetFlags() & AllSettingsFlags::STYLE
) )
306 // else fall through.
307 case DataChangedEventType::FONTS
:
308 case DataChangedEventType::FONTSUBSTITUTION
:
310 impl_scheduleLayout();
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */