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 <sfx2/strings.hrc>
25 #include <bitmaps.hlst>
26 #include <sfx2/sfxresid.hxx>
28 #include <svl/eitem.hxx>
29 #include <vcl/settings.hxx>
30 #include <vcl/event.hxx>
35 //= TitledDockingWindow
36 TitledDockingWindow::TitledDockingWindow( SfxBindings
* i_pBindings
, SfxChildWindow
* i_pChildWindow
, vcl::Window
* i_pParent
)
37 :SfxDockingWindow( i_pBindings
, i_pChildWindow
, i_pParent
, WB_MOVEABLE
|WB_CLOSEABLE
|WB_DOCKABLE
|WB_HIDE
|WB_3DLOOK
)
38 ,m_aToolbox( VclPtr
<ToolBox
>::Create(this) )
39 ,m_aContentWindow( VclPtr
<vcl::Window
>::Create(this, WB_DIALOGCONTROL
) )
40 ,m_aBorder( 3, 1, 3, 3 )
43 SetBackground( Wallpaper() );
45 m_aToolbox
->SetSelectHdl( LINK( this, TitledDockingWindow
, OnToolboxItemSelected
) );
46 m_aToolbox
->SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
50 m_aContentWindow
->Show();
53 TitledDockingWindow::~TitledDockingWindow()
58 void TitledDockingWindow::dispose()
60 m_aToolbox
.disposeAndClear();
61 m_aContentWindow
.disposeAndClear();
62 SfxDockingWindow::dispose();
65 void TitledDockingWindow::SetTitle( const OUString
& i_rTitle
)
72 void TitledDockingWindow::SetText( const OUString
& i_rText
)
74 SfxDockingWindow::SetText( i_rText
);
75 if ( m_sTitle
.isEmpty() )
76 // our text is used as title, too => repaint
81 void TitledDockingWindow::Resize()
83 SfxDockingWindow::Resize();
88 void TitledDockingWindow::impl_layout()
90 m_aToolbox
->ShowItem( ToolBoxItemId(1), !IsFloatingMode() );
92 const Size
aToolBoxSize( m_aToolbox
->CalcWindowSizePixel() );
93 Size
aWindowSize( GetOutputSizePixel() );
95 // position the tool box
96 m_nTitleBarHeight
= GetSettings().GetStyleSettings().GetTitleHeight();
97 if ( aToolBoxSize
.Height() > m_nTitleBarHeight
)
98 m_nTitleBarHeight
= aToolBoxSize
.Height();
99 m_aToolbox
->SetPosSizePixel(
101 aWindowSize
.Width() - aToolBoxSize
.Width(),
102 ( m_nTitleBarHeight
- aToolBoxSize
.Height() ) / 2
107 // Place the content window.
108 if ( m_nTitleBarHeight
< aToolBoxSize
.Height() )
109 m_nTitleBarHeight
= aToolBoxSize
.Height();
110 aWindowSize
.AdjustHeight( -m_nTitleBarHeight
);
111 m_aContentWindow
->SetPosSizePixel(
112 Point( m_aBorder
.Left(), m_nTitleBarHeight
+ m_aBorder
.Top() ),
114 aWindowSize
.Width() - m_aBorder
.Left() - m_aBorder
.Right(),
115 aWindowSize
.Height() - m_aBorder
.Top() - m_aBorder
.Bottom()
120 void TitledDockingWindow::ApplySettings(vcl::RenderContext
& rRenderContext
)
122 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
125 ApplyControlFont(rRenderContext
, rStyleSettings
.GetAppFont());
128 ApplyControlForeground(rRenderContext
, rStyleSettings
.GetButtonTextColor());
129 rRenderContext
.SetTextFillColor();
132 void TitledDockingWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& i_rArea
)
134 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
136 SfxDockingWindow::Paint(rRenderContext
, i_rArea
);
138 rRenderContext
.Push(vcl::PushFlags::FONT
| vcl::PushFlags::FILLCOLOR
| vcl::PushFlags::LINECOLOR
);
140 rRenderContext
.SetFillColor(rStyleSettings
.GetDialogColor());
141 rRenderContext
.SetLineColor();
144 vcl::Font
aFont(rRenderContext
.GetFont());
145 aFont
.SetWeight(WEIGHT_BOLD
);
146 rRenderContext
.SetFont(aFont
);
148 // Set border values.
149 Size
aWindowSize(GetOutputSizePixel());
151 int nInnerLeft
= nOuterLeft
+ m_aBorder
.Left() - 1;
152 int nOuterRight
= aWindowSize
.Width() - 1;
153 int nInnerRight
= nOuterRight
- m_aBorder
.Right() + 1;
154 int nInnerTop
= m_nTitleBarHeight
+ m_aBorder
.Top() - 1;
155 int nOuterBottom
= aWindowSize
.Height() - 1;
156 int nInnerBottom
= nOuterBottom
- m_aBorder
.Bottom() + 1;
158 // Paint title bar background.
159 tools::Rectangle
aTitleBarBox(tools::Rectangle(nOuterLeft
, 0, nOuterRight
, nInnerTop
- 1));
160 rRenderContext
.DrawRect(aTitleBarBox
);
162 if (nInnerLeft
> nOuterLeft
)
163 rRenderContext
.DrawRect(tools::Rectangle(nOuterLeft
, nInnerTop
, nInnerLeft
, nInnerBottom
));
164 if (nOuterRight
> nInnerRight
)
165 rRenderContext
.DrawRect(tools::Rectangle(nInnerRight
, nInnerTop
, nOuterRight
, nInnerBottom
));
166 if (nInnerBottom
< nOuterBottom
)
167 rRenderContext
.DrawRect(tools::Rectangle(nOuterLeft
, nInnerBottom
, nOuterRight
, nOuterBottom
));
169 // Paint bevel border.
170 rRenderContext
.SetFillColor();
171 rRenderContext
.SetLineColor(rStyleSettings
.GetShadowColor());
172 if (m_aBorder
.Top() > 0)
173 rRenderContext
.DrawLine(Point(nInnerLeft
, nInnerTop
), Point(nInnerLeft
, nInnerBottom
));
174 if (m_aBorder
.Left() > 0)
175 rRenderContext
.DrawLine(Point(nInnerLeft
, nInnerTop
), Point(nInnerRight
, nInnerTop
));
177 rRenderContext
.SetLineColor(rStyleSettings
.GetLightColor());
178 if (m_aBorder
.Bottom() > 0)
179 rRenderContext
.DrawLine(Point(nInnerRight
, nInnerBottom
), Point(nInnerLeft
, nInnerBottom
));
180 if (m_aBorder
.Right() > 0)
181 rRenderContext
.DrawLine(Point(nInnerRight
, nInnerBottom
), Point(nInnerRight
, nInnerTop
));
183 // Paint title bar text.
184 rRenderContext
.SetLineColor(rStyleSettings
.GetActiveTextColor());
185 aTitleBarBox
.AdjustLeft(3 );
186 rRenderContext
.DrawText(aTitleBarBox
,
187 !m_sTitle
.isEmpty() ? m_sTitle
: GetText(),
188 DrawTextFlags::Left
| DrawTextFlags::VCenter
| DrawTextFlags::MultiLine
| DrawTextFlags::WordBreak
);
190 // Restore original values of the output device.
191 rRenderContext
.Pop();
195 void TitledDockingWindow::impl_resetToolBox()
199 // Get the closer bitmap and set it as right most button.
200 m_aToolbox
->InsertItem(ToolBoxItemId(1), Image(StockImage::Yes
, SFX_BMP_CLOSE_DOC
));
201 m_aToolbox
->SetQuickHelpText(ToolBoxItemId(1), SfxResId(STR_CLOSE_PANE
));
202 m_aToolbox
->ShowItem( ToolBoxItemId(1) );
206 IMPL_LINK( TitledDockingWindow
, OnToolboxItemSelected
, ToolBox
*, pToolBox
, void )
208 const ToolBoxItemId nId
= pToolBox
->GetCurItemId();
210 if ( nId
== ToolBoxItemId(1) )
214 const sal_uInt16
nChildWindowId( GetChildWindow_Impl()->GetType() );
215 const SfxBoolItem
aVisibility( nChildWindowId
, false );
216 GetBindings().GetDispatcher()->ExecuteList(
218 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
,
225 void TitledDockingWindow::StateChanged( StateChangedType i_nType
)
229 case StateChangedType::InitShow
:
234 SfxDockingWindow::StateChanged( i_nType
);
237 void TitledDockingWindow::DataChanged( const DataChangedEvent
& i_rDataChangedEvent
)
239 SfxDockingWindow::DataChanged( i_rDataChangedEvent
);
241 switch ( i_rDataChangedEvent
.GetType() )
243 case DataChangedEventType::SETTINGS
:
244 if ( !( i_rDataChangedEvent
.GetFlags() & AllSettingsFlags::STYLE
) )
247 case DataChangedEventType::FONTS
:
248 case DataChangedEventType::FONTSUBSTITUTION
:
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */