Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * This file incorporates work covered by the following license notice:
9 : *
10 : * Licensed to the Apache Software Foundation (ASF) under one or more
11 : * contributor license agreements. See the NOTICE file distributed
12 : * with this work for additional information regarding copyright
13 : * ownership. The ASF licenses this file to you under the Apache
14 : * License, Version 2.0 (the "License"); you may not use this file
15 : * except in compliance with the License. You may obtain a copy of
16 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 : */
18 : #include "InsertPropertyPanel.hxx"
19 : #include "sfx2/sidebar/CommandInfoProvider.hxx"
20 :
21 : #include <sfx2/sidebar/Theme.hxx>
22 : #include <sfx2/sidebar/Tools.hxx>
23 : #include <sfx2/sidebar/ControlFactory.hxx>
24 : #include <sfx2/sidebar/ControllerFactory.hxx>
25 :
26 : #include <svx/dialmgr.hxx>
27 : #include <svtools/miscopt.hxx>
28 : #include <svtools/generictoolboxcontroller.hxx>
29 : #include <vcl/toolbox.hxx>
30 : #include <sfx2/tbxctrl.hxx>
31 : #include <framework/sfxhelperfunctions.hxx>
32 : #include <framework/imageproducer.hxx>
33 : #include <comphelper/processfactory.hxx>
34 : #include <cppuhelper/compbase1.hxx>
35 : #include <cppuhelper/basemutex.hxx>
36 :
37 : #include <com/sun/star/frame/XStatusListener.hpp>
38 :
39 : using namespace css;
40 : using namespace cssu;
41 : using ::rtl::OUString;
42 : using ::sfx2::sidebar::SidebarToolBox;
43 :
44 : namespace svx { namespace sidebar {
45 :
46 :
47 0 : InsertPropertyPanel::InsertPropertyPanel (
48 : Window* pParent,
49 : const cssu::Reference<css::frame::XFrame>& rxFrame)
50 : : PanelLayout(pParent, "InsertPropertyPanel", "svx/ui/sidebarinsert.ui", rxFrame),
51 0 : mxFrame(rxFrame)
52 : {
53 0 : get(mpStandardShapesToolBox, "standardshapes");
54 0 : get(mpCustomShapesToolBox, "customshapes");
55 :
56 0 : mpStandardShapesToolBox->Show();
57 0 : mpCustomShapesToolBox->Show();
58 :
59 : // Listen to all tool box selection events.
60 : // FIXME: This is an incredibly ugly hack that we should kill at some
61 : // stage. It is needed because the mpCustomShapesToolBox somehow does not
62 : // get the right controller, and so the images there are not updated when
63 : // the user selects eg. a callout. But using the help id's to get/update
64 : // it (that is what functionSelected() does) is not the way to go in
65 : // general ;-)
66 : // In other words, we should find the underlying problem, and remove the
67 : // WindowEventListener for good.
68 0 : Window* pTopWindow = pParent;
69 0 : while (pTopWindow->GetParent() != NULL)
70 0 : pTopWindow = pTopWindow->GetParent();
71 0 : pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
72 0 : }
73 :
74 :
75 :
76 :
77 0 : InsertPropertyPanel::~InsertPropertyPanel (void)
78 : {
79 : // Remove window child listener.
80 0 : Window* pTopWindow = this;
81 0 : while (pTopWindow->GetParent() != NULL)
82 0 : pTopWindow = pTopWindow->GetParent();
83 0 : pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
84 0 : }
85 :
86 :
87 :
88 :
89 0 : IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent)
90 : {
91 : // We will be getting a lot of window events (well, basically all
92 : // of them), so reject early everything that is not connected to
93 : // toolbox selection.
94 0 : if (pEvent == NULL)
95 0 : return 1;
96 0 : if ( ! pEvent->ISA(VclWindowEvent))
97 0 : return 1;
98 0 : if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT)
99 0 : return 1;
100 :
101 0 : Window* pWindow = dynamic_cast<VclWindowEvent*>(pEvent)->GetWindow();
102 0 : ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
103 0 : if (pToolBox == NULL)
104 0 : return 1;
105 :
106 : // Extract name of (sub)toolbar from help id.
107 0 : OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8));
108 0 : if (sToolbarName.getLength() == 0)
109 0 : return 1;
110 0 : const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName));
111 0 : if (aURL.Path.getLength() == 0)
112 0 : return 1;
113 :
114 : // Get item id.
115 0 : sal_uInt16 nId = pToolBox->GetCurItemId();
116 0 : if (nId == 0)
117 0 : return 1;
118 :
119 0 : SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox);
120 0 : if (pSidebarToolBox == NULL)
121 0 : return 1;
122 0 : sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path));
123 0 : if (nItemId == 0)
124 : {
125 0 : pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox);
126 0 : if (pSidebarToolBox == NULL)
127 0 : return 1;
128 0 : nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path);
129 0 : if (nItemId == 0)
130 0 : return 1;
131 : }
132 :
133 0 : Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY);
134 0 : if ( ! xController.is() )
135 0 : return 1;
136 :
137 0 : const OUString sCommand (pToolBox->GetItemCommand(nId));
138 0 : xController->functionSelected(sCommand);
139 :
140 0 : return 1;
141 : }
142 :
143 :
144 : } } // end of namespace svx::sidebar
|