LibreOffice Module sd (master) 1
titledockwin.cxx
Go to the documentation of this file.
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
21#include <sfx2/bindings.hxx>
22#include <sfx2/dispatch.hxx>
23#include <svl/eitem.hxx>
24#include <vcl/event.hxx>
25#include <vcl/settings.hxx>
26#include <vcl/splitwin.hxx>
27#include <vcl/toolbox.hxx>
28
29#include <ViewShellBase.hxx>
30#include <bitmaps.hlst>
31#include <strings.hrc>
32#include <sdresid.hxx>
33#include <titledockwin.hxx>
34
35namespace sd
36{
37 //= TitledDockingWindow
38 TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, vcl::Window* i_pParent, const OUString& rsTitle )
39 :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, WB_MOVEABLE|WB_CLOSEABLE|WB_DOCKABLE|WB_HIDE|WB_3DLOOK )
40 ,m_aToolbox( VclPtr<ToolBox>::Create(this) )
41 ,m_aContentWindow( VclPtr<vcl::Window>::Create(this, WB_DIALOGCONTROL) )
42 ,m_aBorder( 3, 1, 3, 3 )
43 ,m_nTitleBarHeight(0)
44 {
45 SetBackground( Wallpaper() );
46
47 m_aToolbox->SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
48 m_aToolbox->SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
49 m_aToolbox->Show();
51
52 m_aContentWindow->Show();
53
54 m_sTitle = rsTitle;
55 Invalidate();
56 SetSizePixel(LogicToPixel(Size(80,200), MapMode(MapUnit::MapAppFont)));
57 }
58
60 {
61 disposeOnce();
62 }
63
65 {
69 }
70
71 void TitledDockingWindow::SetText( const OUString& i_rText )
72 {
73 SfxDockingWindow::SetText( i_rText );
74 if ( m_sTitle.isEmpty() )
75 // our text is used as title, too => repaint
76 Invalidate();
77 }
78
79
81 {
84 }
85
86
88 {
89 m_aToolbox->ShowItem( ToolBoxItemId(1), !IsFloatingMode() );
90
91 const Size aToolBoxSize( m_aToolbox->CalcWindowSizePixel() );
92 Size aWindowSize( GetOutputSizePixel() );
93
94 // position the tool box
95 m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
96 if ( aToolBoxSize.Height() > m_nTitleBarHeight )
97 m_nTitleBarHeight = aToolBoxSize.Height();
98 m_aToolbox->SetPosSizePixel(
99 Point(
100 aWindowSize.Width() - aToolBoxSize.Width(),
101 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
102 ),
103 aToolBoxSize
104 );
105
106 // Place the content window.
107 if ( m_nTitleBarHeight < aToolBoxSize.Height() )
108 m_nTitleBarHeight = aToolBoxSize.Height();
109 aWindowSize.AdjustHeight( -m_nTitleBarHeight );
110 m_aContentWindow->SetPosSizePixel(
112 Size(
113 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
114 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
115 )
116 );
117 }
118
120 {
121 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
122
123 // Font
124 ApplyControlFont(rRenderContext, rStyleSettings.GetAppFont());
125
126 // Color
127 ApplyControlForeground(rRenderContext, rStyleSettings.GetButtonTextColor());
128 rRenderContext.SetTextFillColor();
129 }
130
131 void TitledDockingWindow::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& i_rArea)
132 {
133 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
134
135 SfxDockingWindow::Paint(rRenderContext, i_rArea);
136
138
139 rRenderContext.SetFillColor(rStyleSettings.GetDialogColor());
140 rRenderContext.SetLineColor();
141
142 // bold font
143 vcl::Font aFont(rRenderContext.GetFont());
144 aFont.SetWeight(WEIGHT_BOLD);
145 rRenderContext.SetFont(aFont);
146
147 // Set border values.
148 Size aWindowSize(GetOutputSizePixel());
149 int nOuterLeft = 0;
150 int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
151 int nOuterRight = aWindowSize.Width() - 1;
152 int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
153 int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
154 int nOuterBottom = aWindowSize.Height() - 1;
155 int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
156
157 // Paint title bar background.
158 ::tools::Rectangle aTitleBarBox(nOuterLeft, 0, nOuterRight, nInnerTop - 1);
159 rRenderContext.DrawRect(aTitleBarBox);
160
161 if (nInnerLeft > nOuterLeft)
162 rRenderContext.DrawRect(::tools::Rectangle(nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom));
163 if (nOuterRight > nInnerRight)
164 rRenderContext.DrawRect(::tools::Rectangle(nInnerRight, nInnerTop, nOuterRight, nInnerBottom));
165 if (nInnerBottom < nOuterBottom)
166 rRenderContext.DrawRect(::tools::Rectangle(nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom));
167
168 // Paint bevel border.
169 rRenderContext.SetFillColor();
170 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
171 if (m_aBorder.Top() > 0)
172 rRenderContext.DrawLine(Point(nInnerLeft, nInnerTop), Point(nInnerLeft, nInnerBottom));
173 if (m_aBorder.Left() > 0)
174 rRenderContext.DrawLine(Point(nInnerLeft, nInnerTop), Point(nInnerRight, nInnerTop));
175
176 rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
177 if (m_aBorder.Bottom() > 0)
178 rRenderContext.DrawLine(Point(nInnerRight, nInnerBottom), Point(nInnerLeft, nInnerBottom));
179 if (m_aBorder.Right() > 0)
180 rRenderContext.DrawLine(Point(nInnerRight, nInnerBottom), Point(nInnerRight, nInnerTop));
181
182 // Paint title bar text.
183 rRenderContext.SetLineColor(rStyleSettings.GetActiveTextColor());
184 aTitleBarBox.AdjustLeft(3 );
185 rRenderContext.DrawText(aTitleBarBox,
186 !m_sTitle.isEmpty() ? m_sTitle : GetText(),
187 DrawTextFlags::Left | DrawTextFlags::VCenter | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
188
189 // Restore original values of the output device.
190 rRenderContext.Pop();
191 }
192
193
195 {
196 m_aToolbox->Clear();
197
198 // Get the closer bitmap and set it as right most button.
199 m_aToolbox->InsertItem(ToolBoxItemId(1), Image(StockImage::Yes, SFX_BMP_CLOSE_DOC));
200 m_aToolbox->SetQuickHelpText(ToolBoxItemId(1), SdResId(STR_CLOSE_PANE));
201 m_aToolbox->ShowItem( ToolBoxItemId(1) );
202 }
203
204
205 IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox, void )
206 {
207 const ToolBoxItemId nId = pToolBox->GetCurItemId();
208
209 if ( nId == ToolBoxItemId(1) )
210 {
211 // the closer
212 EndTracking();
213 const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
214 const SfxBoolItem aVisibility( nChildWindowId, false );
216 nChildWindowId,
217 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
218 { &aVisibility }
219 );
220 }
221 }
222
223
225 {
226 switch (i_nType)
227 {
228 case StateChangedType::InitShow:
229 Resize();
231 impl_layout();
232 break;
233
234 case StateChangedType::Visible:
235 {
236 // The visibility of the docking window has changed. Tell the
237 // ConfigurationController so that it can activate or deactivate
238 // a/the view for the pane.
239 // Without this the side panes remain empty after closing an
240 // in-place slide show.
242 GetBindings().GetDispatcher()->GetFrame());
243 if (pBase != nullptr)
244 {
245 framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
246 }
247 }
248 break;
249
250 default:;
251 }
253 }
254
255 void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
256 {
257 SfxDockingWindow::DataChanged( i_rDataChangedEvent );
258
259 switch ( i_rDataChangedEvent.GetType() )
260 {
261 case DataChangedEventType::SETTINGS:
262 if ( !( i_rDataChangedEvent.GetFlags() & AllSettingsFlags::STYLE ) )
263 break;
264 [[fallthrough]];
265 case DataChangedEventType::FONTS:
266 case DataChangedEventType::FONTSUBSTITUTION:
267 {
268 impl_layout();
269 Invalidate();
270 }
271 break;
272 default: break;
273 }
274 }
275
277 {
278 if (rEvent.GetButtons() == MOUSE_LEFT)
279 {
280 // For some strange reason we have to set the WB_DIALOGCONTROL at
281 // the content window in order to have it pass focus to its content
282 // window. Without setting this flag here that works only on views
283 // that have not been taken from the cash and relocated to this pane
284 // docking window.
287 }
288 SfxDockingWindow::MouseButtonDown(rEvent);
289 }
290
291 void TitledDockingWindow::SetValidSizeRange (const Range& rValidSizeRange)
292 {
293 SplitWindow* pSplitWindow = dynamic_cast<SplitWindow*>(GetParent());
294 if (pSplitWindow == nullptr)
295 return;
296
297 const sal_uInt16 nId (pSplitWindow->GetItemId(static_cast< vcl::Window*>(this)));
298 const sal_uInt16 nSetId (pSplitWindow->GetSet(nId));
299 // Because the TitledDockingWindow paints its own decoration, we have
300 // to compensate the valid size range for that.
301 const SvBorder aBorder (GetDecorationBorder());
302 sal_Int32 nCompensation (pSplitWindow->IsHorizontal()
303 ? aBorder.Top() + aBorder.Bottom()
304 : aBorder.Left() + aBorder.Right());
305 pSplitWindow->SetItemSizeRange(
306 nSetId,
307 Range(
308 rValidSizeRange.Min() + nCompensation,
309 rValidSizeRange.Max() + nCompensation));
310 }
311
313 {
314 SplitWindow* pSplitWindow = dynamic_cast<SplitWindow*>(GetParent());
315 if (pSplitWindow == nullptr)
316 return UnknownOrientation;
317 else if (pSplitWindow->IsHorizontal())
319 else
320 return VerticalOrientation;
321 }
322
323} // namespace sfx2
324
325
326/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
sal_uInt16 GetButtons() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void SetLineColor()
void SetFillColor()
void SetTextFillColor()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const AllSettings & GetSettings() const
tools::Long Max() const
tools::Long Min() const
SfxDispatcher * GetDispatcher() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual void Resize() override
SfxBindings & GetBindings() const
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
virtual void StateChanged(StateChangedType nStateChange) override
virtual void dispose() override
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
constexpr tools::Long Width() const
sal_uInt16 GetItemId(vcl::Window *pWindow) const
void SetItemSizeRange(sal_uInt16 nId, const Range &rRange)
bool IsHorizontal() const
sal_uInt16 GetSet(sal_uInt16 nId) const
const Color & GetShadowColor() const
const Color & GetLightColor() const
const Color & GetDialogColor() const
const vcl::Font & GetAppFont() const
const Color & GetButtonTextColor() const
const Color & GetActiveTextColor() const
tools::Long & Left()
tools::Long & Top()
tools::Long & Right()
tools::Long & Bottom()
void disposeAndClear()
virtual void SetText(const OUString &i_rText) override
SvBorder m_aBorder
The border that is painted around the inner window.
const SvBorder & GetDecorationBorder() const
Return the border that is painted around the inner window as decoration.
int m_nTitleBarHeight
Height of the title bar.
void impl_resetToolBox()
internal version of ResetToolBox
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
virtual ~TitledDockingWindow() override
TitledDockingWindow(SfxBindings *i_pBindings, SfxChildWindow *i_pChildWindow, vcl::Window *i_pParent, const OUString &rsTitle)
Create a new docking window.
virtual void Paint(vcl::RenderContext &rRenderContext, const ::tools::Rectangle &i_rArea) override
VclPtr< Window > m_aContentWindow
vcl::Window & GetContentWindow()
returns the content window, which is to be used as parent window for any content to be displayed in t...
virtual void MouseButtonDown(const MouseEvent &rEvent) override
virtual void DataChanged(const DataChangedEvent &i_rDataChangedEvent) override
virtual void StateChanged(StateChangedType i_nType) override
virtual void Resize() override
VclPtr< ToolBox > m_aToolbox
void SetValidSizeRange(const Range &rValidSizeRange)
When docked the given range is passed to the parent SplitWindow.
Orientation GetOrientation() const
When the TitledDockingWindow is docked and managed by a split window it can derive its orientation fr...
virtual void dispose() override
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
static ViewShellBase * GetViewShellBase(SfxViewFrame const *pFrame)
When given a view frame this static method returns the corresponding sd::ViewShellBase object.
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
static ::std::shared_ptr< FrameworkHelper > Instance(ViewShellBase &rBase)
Return the FrameworkHelper object that is associated with the given ViewShellBase.
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
void SetWeight(FontWeight)
void SetStyle(WinBits nStyle)
void GrabFocus()
virtual SfxBindings & GetBindings() override
#define MOUSE_LEFT
WEIGHT_BOLD
SfxDispatcher * GetDispatcher()
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
sal_Int16 nId
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
StateChangedType
WinBits const WB_CLOSEABLE
WinBits const WB_MOVEABLE
WinBits const WB_DIALOGCONTROL
WinBits const WB_DOCKABLE
WinBits const WB_3DLOOK
WinBits const WB_HIDE