fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / sidebar / insert / InsertPropertyPanel.cxx
blob590759bd7568dd6d86baf841b2543a94cc6a92ee
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 .
19 #include "InsertPropertyPanel.hxx"
20 #include "sfx2/sidebar/CommandInfoProvider.hxx"
22 #include <sfx2/sidebar/Theme.hxx>
23 #include <sfx2/sidebar/Tools.hxx>
24 #include <sfx2/sidebar/ControlFactory.hxx>
25 #include <sfx2/sidebar/ControllerFactory.hxx>
27 #include <svx/dialmgr.hxx>
28 #include <svtools/miscopt.hxx>
29 #include <svtools/generictoolboxcontroller.hxx>
30 #include <vcl/toolbox.hxx>
31 #include <sfx2/tbxctrl.hxx>
32 #include <framework/sfxhelperfunctions.hxx>
33 #include <framework/imageproducer.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <cppuhelper/compbase1.hxx>
36 #include <cppuhelper/basemutex.hxx>
38 #include <com/sun/star/frame/XStatusListener.hpp>
40 using namespace css;
41 using namespace css::uno;
42 using ::rtl::OUString;
43 using ::sfx2::sidebar::SidebarToolBox;
45 namespace svx { namespace sidebar {
48 InsertPropertyPanel::InsertPropertyPanel (
49 vcl::Window* pParent,
50 const css::uno::Reference<css::frame::XFrame>& rxFrame)
51 : PanelLayout(pParent, "InsertPropertyPanel", "svx/ui/sidebarinsert.ui", rxFrame),
52 mxFrame(rxFrame)
54 get(mpStandardShapesToolBox, "standardshapes");
55 get(mpCustomShapesToolBox, "customshapes");
57 mpStandardShapesToolBox->Show();
58 mpCustomShapesToolBox->Show();
60 // Listen to all tool box selection events.
61 // FIXME: This is an incredibly ugly hack that we should kill at some
62 // stage. It is needed because the mpCustomShapesToolBox somehow does not
63 // get the right controller, and so the images there are not updated when
64 // the user selects eg. a callout. But using the help id's to get/update
65 // it (that is what functionSelected() does) is not the way to go in
66 // general ;-)
67 // In other words, we should find the underlying problem, and remove the
68 // WindowEventListener for good.
69 vcl::Window* pTopWindow = pParent;
70 while (pTopWindow->GetParent() != NULL)
71 pTopWindow = pTopWindow->GetParent();
72 pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
75 InsertPropertyPanel::~InsertPropertyPanel()
77 disposeOnce();
80 void InsertPropertyPanel::dispose()
82 // Remove window child listener.
83 vcl::Window* pTopWindow = this;
84 while (pTopWindow->GetParent() != NULL)
85 pTopWindow = pTopWindow->GetParent();
86 pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
87 mpStandardShapesToolBox.clear();
88 mpCustomShapesToolBox.clear();
89 PanelLayout::dispose();
95 IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent)
97 // We will be getting a lot of window events (well, basically all
98 // of them), so reject early everything that is not connected to
99 // toolbox selection.
100 if (pEvent == NULL)
101 return 1;
102 if ( ! pEvent->ISA(VclWindowEvent))
103 return 1;
104 if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT)
105 return 1;
107 VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(pEvent);
108 vcl::Window* pWindow = pWindowEvent ? pWindowEvent->GetWindow() : NULL;
109 ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
110 if (pToolBox == NULL)
111 return 1;
113 // Extract name of (sub)toolbar from help id.
114 OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8));
115 if (sToolbarName.getLength() == 0)
116 return 1;
117 const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName));
118 if (aURL.Path.getLength() == 0)
119 return 1;
121 // Get item id.
122 sal_uInt16 nId = pToolBox->GetCurItemId();
123 if (nId == 0)
124 return 1;
126 SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox.get());
127 if (pSidebarToolBox == NULL)
128 return 1;
129 sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path));
130 if (nItemId == 0)
132 pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox.get());
133 if (pSidebarToolBox == NULL)
134 return 1;
135 nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path);
136 if (nItemId == 0)
137 return 1;
140 Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY);
141 if ( ! xController.is() )
142 return 1;
144 const OUString sCommand (pToolBox->GetItemCommand(nId));
145 xController->functionSelected(sCommand);
147 return 1;
151 } } // end of namespace svx::sidebar
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */