merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / PaneDockingWindow.cxx
blob6f1ae1df215d0baf49f26f72b0cc539e3f8e3f5d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PaneDockingWindow.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "PaneDockingWindow.hxx"
35 #include "Window.hxx"
36 #include "ViewShellBase.hxx"
37 #include "sdresid.hxx"
38 #include "res_bmp.hrc"
39 #include <sfx2/dispatch.hxx>
40 #include <vcl/toolbox.hxx>
41 #include <vcl/taskpanelist.hxx>
42 #include "framework/FrameworkHelper.hxx"
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::drawing::framework;
48 namespace sd {
50 PaneDockingWindow::PaneDockingWindow (
51 SfxBindings *_pBindings,
52 SfxChildWindow *pChildWindow,
53 ::Window* pParent,
54 const ResId& rResId,
55 const ::rtl::OUString& rsPaneURL,
56 const ::rtl::OUString& rsTitle)
57 : SfxDockingWindow (
58 _pBindings,
59 pChildWindow,
60 pParent,
61 rResId
63 msPaneURL(rsPaneURL),
64 msTitle(rsTitle),
65 mpTitleToolBox(),
66 maBorder (3,1,3,3),
67 mnChildWindowId(pChildWindow->GetType()),
68 mpContentWindow(new ::Window(this)),
69 mbIsLayoutPending(false)
71 SetBackground (Wallpaper());
73 InitializeTitleToolBox();
75 // Tell the system window about the new docking window so that it can be
76 // reached via the keyboard.
77 SystemWindow* pSystemWindow = GetSystemWindow();
78 if (pSystemWindow != NULL)
79 pSystemWindow->GetTaskPaneList()->AddWindow(this);
81 mpContentWindow->Show();
87 PaneDockingWindow::~PaneDockingWindow (void)
89 // Tell the next system window that the docking window is no longer
90 // available.
91 SystemWindow* pSystemWindow = GetSystemWindow();
92 if (pSystemWindow != NULL)
93 pSystemWindow->GetTaskPaneList()->RemoveWindow(this);
94 mpTitleToolBox.reset();
100 void PaneDockingWindow::SetTitle (const String& rsTitle)
102 msTitle = rsTitle;
103 Invalidate();
109 void PaneDockingWindow::Resize (void)
111 SfxDockingWindow::Resize();
112 mbIsLayoutPending = true;
118 void PaneDockingWindow::Layout (void)
120 mbIsLayoutPending = false;
122 Size aWindowSize (GetOutputSizePixel());
123 Size aToolBoxSize (0,0);
124 int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());
126 // Place the title tool box.
127 if (mpTitleToolBox.get() != NULL)
129 if (IsFloatingMode())
130 mpTitleToolBox->HideItem (1);
131 else
132 mpTitleToolBox->ShowItem (1);
134 aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
135 if (aToolBoxSize.Height() > nTitleBarHeight)
136 nTitleBarHeight = aToolBoxSize.Height();
137 mpTitleToolBox->SetPosSizePixel (
138 Point(aWindowSize.Width()-aToolBoxSize.Width(),
139 (nTitleBarHeight-aToolBoxSize.Height())/2),
140 aToolBoxSize);
143 // Place the content window.
144 if (nTitleBarHeight < aToolBoxSize.Height())
145 nTitleBarHeight = aToolBoxSize.Height();
146 aWindowSize.Height() -= nTitleBarHeight;
147 mpContentWindow->SetPosSizePixel(
148 Point(maBorder.Left(),nTitleBarHeight+maBorder.Top()),
149 Size (aWindowSize.Width()-maBorder.Left()-maBorder.Right(),
150 aWindowSize.Height()-maBorder.Top()-maBorder.Bottom()));
156 void PaneDockingWindow::Paint (const Rectangle& rRectangle)
158 if (mbIsLayoutPending)
159 Layout();
161 SfxDockingWindow::Paint (rRectangle);
162 int nTitleBarHeight (GetSettings().GetStyleSettings().GetTitleHeight());
163 Size aToolBoxSize = mpTitleToolBox->CalcWindowSizePixel();
164 if (aToolBoxSize.Height() > nTitleBarHeight)
165 nTitleBarHeight = aToolBoxSize.Height();
166 Color aOriginalLineColor (GetLineColor());
167 Color aOriginalFillColor (GetFillColor());
168 SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
169 SetLineColor ();
171 // Make font bold.
172 const Font& rOriginalFont (GetFont());
173 Font aFont (rOriginalFont);
174 aFont.SetWeight (WEIGHT_BOLD);
175 SetFont (aFont);
177 // Set border values.
178 Size aWindowSize (GetOutputSizePixel());
179 int nOuterLeft = 0;
180 int nInnerLeft = nOuterLeft + maBorder.Left() - 1;
181 int nOuterRight = aWindowSize.Width() - 1;
182 int nInnerRight = nOuterRight - maBorder.Right() + 1;
183 int nInnerTop = nTitleBarHeight + maBorder.Top() - 1;
184 int nOuterBottom = aWindowSize.Height() - 1;
185 int nInnerBottom = nOuterBottom - maBorder.Bottom() + 1;
187 // Paint title bar background.
188 Rectangle aTitleBarBox (Rectangle(
189 nOuterLeft,
191 nOuterRight,
192 nInnerTop-1));
193 DrawRect (aTitleBarBox);
195 if (nInnerLeft > nOuterLeft)
196 DrawRect (
197 Rectangle (nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom));
198 if (nOuterRight > nInnerRight)
199 DrawRect (
200 Rectangle (nInnerRight, nInnerTop, nOuterRight, nInnerBottom));
201 if (nInnerBottom < nOuterBottom)
202 DrawRect (
203 Rectangle (nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom));
205 // Paint bevel border.
206 SetFillColor ();
207 SetLineColor (GetSettings().GetStyleSettings().GetShadowColor());
208 if (maBorder.Top() > 0)
209 DrawLine (
210 Point(nInnerLeft,nInnerTop),
211 Point(nInnerLeft,nInnerBottom));
212 if (maBorder.Left() > 0)
213 DrawLine (
214 Point(nInnerLeft,nInnerTop),
215 Point(nInnerRight,nInnerTop));
216 SetLineColor (GetSettings().GetStyleSettings().GetLightColor());
217 if (maBorder.Bottom() > 0)
218 DrawLine (
219 Point(nInnerRight,nInnerBottom),
220 Point(nInnerLeft,nInnerBottom));
221 if (maBorder.Right() > 0)
222 DrawLine (
223 Point(nInnerRight,nInnerBottom),
224 Point(nInnerRight,nInnerTop));
226 // Paint title bar text.
227 SetLineColor (GetSettings().GetStyleSettings().GetActiveTextColor());
228 SetFillColor ();
229 aTitleBarBox.Left() += 3;
230 DrawText (aTitleBarBox, msTitle,
231 TEXT_DRAW_LEFT
232 | TEXT_DRAW_VCENTER
233 | TEXT_DRAW_MULTILINE
234 | TEXT_DRAW_WORDBREAK);
236 // Restore original values of the output device.
237 SetFont (rOriginalFont);
238 SetFillColor (aOriginalFillColor);
244 void PaneDockingWindow::InitializeTitleToolBox (void)
246 if (mpTitleToolBox.get() == NULL)
248 // Initialize the title tool box.
249 mpTitleToolBox.reset (new ToolBox(this));
250 mpTitleToolBox->SetSelectHdl (
251 LINK(this, PaneDockingWindow, ToolboxSelectHandler));
252 mpTitleToolBox->SetOutStyle (TOOLBOX_STYLE_FLAT);
253 mpTitleToolBox->SetBackground (Wallpaper (
254 GetSettings().GetStyleSettings().GetDialogColor()));
255 mpTitleToolBox->Show();
257 else
258 mpTitleToolBox->Clear();
260 // Get the closer bitmap and set it as right most button.
261 Bitmap aBitmap (SdResId (BMP_CLOSE_DOC));
262 Bitmap aBitmapHC (SdResId (BMP_CLOSE_DOC_H));
263 Image aImage = Image (aBitmap, Color (COL_LIGHTMAGENTA));
264 Image aImageHC = Image (aBitmapHC, Color (BMP_COLOR_HIGHCONTRAST));
265 mpTitleToolBox->InsertItem (1,
266 GetSettings().GetStyleSettings().GetMenuBarColor().IsDark()
267 ? aImageHC
268 : aImage);
269 mpTitleToolBox->ShowItem (1);
275 USHORT PaneDockingWindow::AddMenu (
276 const String& rsMenuName,
277 ULONG nHelpId,
278 const Link& rCallback)
280 // Add the menu before the closer button.
281 USHORT nItemCount (mpTitleToolBox->GetItemCount());
282 USHORT nItemId (nItemCount+1);
283 mpTitleToolBox->InsertItem (
284 nItemId,
285 rsMenuName,
286 TIB_DROPDOWNONLY,
287 nItemCount>0 ? nItemCount-1 : (USHORT)-1);
288 mpTitleToolBox->SetHelpId( nItemId, nHelpId );
289 mpTitleToolBox->SetClickHdl (rCallback);
290 mpTitleToolBox->SetDropdownClickHdl (rCallback);
292 // The tool box has likely changed its size. The title bar has to be
293 // resized.
294 Resize();
295 Invalidate();
297 return nItemCount+1;
303 IMPL_LINK(PaneDockingWindow, ToolboxSelectHandler, ToolBox*, pToolBox)
305 USHORT nId = pToolBox->GetCurItemId();
307 if (nId == 1)
309 EndTracking();
310 SfxBoolItem aVisibility (mnChildWindowId, FALSE);
311 GetBindings().GetDispatcher()->Execute (
312 mnChildWindowId,
313 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
314 &aVisibility,
315 NULL);
318 return 0;
324 long PaneDockingWindow::Notify( NotifyEvent& rNEvt )
326 return SfxDockingWindow::Notify (rNEvt);
332 void PaneDockingWindow::StateChanged( StateChangedType nType )
334 switch (nType)
336 case STATE_CHANGE_INITSHOW:
337 Resize();
338 break;
340 case STATE_CHANGE_VISIBLE:
341 // The visibility of the docking window has changed. Tell the
342 // ConfigurationController so that it can activate or deactivate
343 // a/the view for the pane.
344 // Without this the side panes remain empty after closing an
345 // in-place slide show.
346 ViewShellBase* pBase = ViewShellBase::GetViewShellBase(
347 GetBindings().GetDispatcher()->GetFrame());
348 if (pBase != NULL)
350 framework::FrameworkHelper::Instance(*pBase)->UpdateConfiguration();
352 break;
354 SfxDockingWindow::StateChanged (nType);
360 void PaneDockingWindow::DataChanged (const DataChangedEvent& rEvent)
362 SfxDockingWindow::DataChanged (rEvent);
364 switch (rEvent.GetType())
366 case DATACHANGED_SETTINGS:
367 if ((rEvent.GetFlags() & SETTINGS_STYLE) == 0)
368 break;
369 // else fall through.
370 case DATACHANGED_FONTS:
371 case DATACHANGED_FONTSUBSTITUTION:
373 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
375 // Font.
376 Font aFont = rStyleSettings.GetAppFont();
377 if (IsControlFont())
378 aFont.Merge(GetControlFont());
379 SetZoomedPointFont(aFont);
381 // Color.
382 Color aColor;
383 if (IsControlForeground())
384 aColor = GetControlForeground();
385 else
386 aColor = rStyleSettings.GetButtonTextColor();
387 SetTextColor(aColor);
388 SetTextFillColor();
390 Resize();
391 Invalidate();
393 break;
400 ::Window* PaneDockingWindow::GetContentWindow (void)
402 return mpContentWindow.get();
408 ::boost::shared_ptr<ToolBox> PaneDockingWindow::GetTitleToolBox (void) const
410 return mpTitleToolBox;
414 } // end of namespace ::sd