nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / dialog / titledockwin.cxx
blob7483ee8d193d2b09d7c25d0e0db42d6de8f7261a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
33 namespace sfx2
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_sTitle()
39 ,m_aToolbox( VclPtr<ToolBox>::Create(this) )
40 ,m_aContentWindow( VclPtr<vcl::Window>::Create(this, WB_DIALOGCONTROL) )
41 ,m_aBorder( 3, 1, 3, 3 )
42 ,m_bLayoutPending( false )
43 ,m_nTitleBarHeight(0)
45 SetBackground( Wallpaper() );
47 m_aToolbox->SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
48 m_aToolbox->SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
49 m_aToolbox->Show();
50 impl_resetToolBox();
52 m_aContentWindow->Show();
55 TitledDockingWindow::~TitledDockingWindow()
57 disposeOnce();
60 void TitledDockingWindow::dispose()
62 m_aToolbox.disposeAndClear();
63 m_aContentWindow.disposeAndClear();
64 SfxDockingWindow::dispose();
67 void TitledDockingWindow::SetTitle( const OUString& i_rTitle )
69 m_sTitle = i_rTitle;
70 Invalidate();
74 void TitledDockingWindow::SetText( const OUString& i_rText )
76 SfxDockingWindow::SetText( i_rText );
77 if ( m_sTitle.isEmpty() )
78 // our text is used as title, too => repaint
79 Invalidate();
83 void TitledDockingWindow::Resize()
85 SfxDockingWindow::Resize();
86 impl_scheduleLayout();
90 void TitledDockingWindow::impl_scheduleLayout()
92 m_bLayoutPending = true;
96 void TitledDockingWindow::impl_layout()
98 m_bLayoutPending = false;
100 m_aToolbox->ShowItem( 1, !IsFloatingMode() );
102 const Size aToolBoxSize( m_aToolbox->CalcWindowSizePixel() );
103 Size aWindowSize( GetOutputSizePixel() );
105 // position the tool box
106 m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
107 if ( aToolBoxSize.Height() > m_nTitleBarHeight )
108 m_nTitleBarHeight = aToolBoxSize.Height();
109 m_aToolbox->SetPosSizePixel(
110 Point(
111 aWindowSize.Width() - aToolBoxSize.Width(),
112 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
114 aToolBoxSize
117 // Place the content window.
118 if ( m_nTitleBarHeight < aToolBoxSize.Height() )
119 m_nTitleBarHeight = aToolBoxSize.Height();
120 aWindowSize.AdjustHeight( -m_nTitleBarHeight );
121 m_aContentWindow->SetPosSizePixel(
122 Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
123 Size(
124 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
125 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
130 void TitledDockingWindow::ApplySettings(vcl::RenderContext& rRenderContext)
132 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
134 // Font
135 ApplyControlFont(rRenderContext, rStyleSettings.GetAppFont());
137 // Color
138 ApplyControlForeground(rRenderContext, rStyleSettings.GetButtonTextColor());
139 rRenderContext.SetTextFillColor();
142 void TitledDockingWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& i_rArea)
144 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
146 if (m_bLayoutPending)
147 impl_layout();
149 SfxDockingWindow::Paint(rRenderContext, i_rArea);
151 rRenderContext.Push(PushFlags::FONT | PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
153 rRenderContext.SetFillColor(rStyleSettings.GetDialogColor());
154 rRenderContext.SetLineColor();
156 // bold font
157 vcl::Font aFont(rRenderContext.GetFont());
158 aFont.SetWeight(WEIGHT_BOLD);
159 rRenderContext.SetFont(aFont);
161 // Set border values.
162 Size aWindowSize(GetOutputSizePixel());
163 int nOuterLeft = 0;
164 int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
165 int nOuterRight = aWindowSize.Width() - 1;
166 int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
167 int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
168 int nOuterBottom = aWindowSize.Height() - 1;
169 int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
171 // Paint title bar background.
172 tools::Rectangle aTitleBarBox(tools::Rectangle(nOuterLeft, 0, nOuterRight, nInnerTop - 1));
173 rRenderContext.DrawRect(aTitleBarBox);
175 if (nInnerLeft > nOuterLeft)
176 rRenderContext.DrawRect(tools::Rectangle(nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom));
177 if (nOuterRight > nInnerRight)
178 rRenderContext.DrawRect(tools::Rectangle(nInnerRight, nInnerTop, nOuterRight, nInnerBottom));
179 if (nInnerBottom < nOuterBottom)
180 rRenderContext.DrawRect(tools::Rectangle(nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom));
182 // Paint bevel border.
183 rRenderContext.SetFillColor();
184 rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
185 if (m_aBorder.Top() > 0)
186 rRenderContext.DrawLine(Point(nInnerLeft, nInnerTop), Point(nInnerLeft, nInnerBottom));
187 if (m_aBorder.Left() > 0)
188 rRenderContext.DrawLine(Point(nInnerLeft, nInnerTop), Point(nInnerRight, nInnerTop));
190 rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
191 if (m_aBorder.Bottom() > 0)
192 rRenderContext.DrawLine(Point(nInnerRight, nInnerBottom), Point(nInnerLeft, nInnerBottom));
193 if (m_aBorder.Right() > 0)
194 rRenderContext.DrawLine(Point(nInnerRight, nInnerBottom), Point(nInnerRight, nInnerTop));
196 // Paint title bar text.
197 rRenderContext.SetLineColor(rStyleSettings.GetActiveTextColor());
198 aTitleBarBox.AdjustLeft(3 );
199 rRenderContext.DrawText(aTitleBarBox,
200 !m_sTitle.isEmpty() ? m_sTitle : GetText(),
201 DrawTextFlags::Left | DrawTextFlags::VCenter | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
203 // Restore original values of the output device.
204 rRenderContext.Pop();
208 void TitledDockingWindow::impl_resetToolBox()
210 m_aToolbox->Clear();
212 // Get the closer bitmap and set it as right most button.
213 m_aToolbox->InsertItem(1, Image(StockImage::Yes, SFX_BMP_CLOSE_DOC));
214 m_aToolbox->SetQuickHelpText(1, SfxResId(STR_CLOSE_PANE));
215 m_aToolbox->ShowItem( 1 );
219 IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox, void )
221 const sal_uInt16 nId = pToolBox->GetCurItemId();
223 if ( nId == 1 )
225 // the closer
226 EndTracking();
227 const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
228 const SfxBoolItem aVisibility( nChildWindowId, false );
229 GetBindings().GetDispatcher()->ExecuteList(
230 nChildWindowId,
231 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
232 { &aVisibility }
238 void TitledDockingWindow::StateChanged( StateChangedType i_nType )
240 switch ( i_nType )
242 case StateChangedType::InitShow:
243 impl_scheduleLayout();
244 break;
245 default:;
247 SfxDockingWindow::StateChanged( i_nType );
250 void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
252 SfxDockingWindow::DataChanged( i_rDataChangedEvent );
254 switch ( i_rDataChangedEvent.GetType() )
256 case DataChangedEventType::SETTINGS:
257 if ( !( i_rDataChangedEvent.GetFlags() & AllSettingsFlags::STYLE ) )
258 break;
259 [[fallthrough]];
260 case DataChangedEventType::FONTS:
261 case DataChangedEventType::FONTSUBSTITUTION:
263 impl_scheduleLayout();
264 Invalidate();
266 break;
267 default: break;
272 } // namespace sfx2
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */