Line data Source code
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 : #include "InsertPropertyPanel.hxx"
20 : #include "sfx2/sidebar/CommandInfoProvider.hxx"
21 :
22 : #include <sfx2/sidebar/Theme.hxx>
23 : #include <sfx2/sidebar/Tools.hxx>
24 : #include <sfx2/sidebar/ControlFactory.hxx>
25 : #include <sfx2/sidebar/ControllerFactory.hxx>
26 :
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>
37 :
38 : #include <com/sun/star/frame/XStatusListener.hpp>
39 :
40 : using namespace css;
41 : using namespace css::uno;
42 : using ::rtl::OUString;
43 : using ::sfx2::sidebar::SidebarToolBox;
44 :
45 : namespace svx { namespace sidebar {
46 :
47 :
48 0 : 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 0 : mxFrame(rxFrame)
53 : {
54 0 : get(mpStandardShapesToolBox, "standardshapes");
55 0 : get(mpCustomShapesToolBox, "customshapes");
56 :
57 0 : mpStandardShapesToolBox->Show();
58 0 : mpCustomShapesToolBox->Show();
59 :
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 0 : vcl::Window* pTopWindow = pParent;
70 0 : while (pTopWindow->GetParent() != NULL)
71 0 : pTopWindow = pTopWindow->GetParent();
72 0 : pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
73 0 : }
74 :
75 :
76 :
77 :
78 0 : InsertPropertyPanel::~InsertPropertyPanel (void)
79 : {
80 : // Remove window child listener.
81 0 : vcl::Window* pTopWindow = this;
82 0 : while (pTopWindow->GetParent() != NULL)
83 0 : pTopWindow = pTopWindow->GetParent();
84 0 : pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
85 0 : }
86 :
87 :
88 :
89 :
90 0 : IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent)
91 : {
92 : // We will be getting a lot of window events (well, basically all
93 : // of them), so reject early everything that is not connected to
94 : // toolbox selection.
95 0 : if (pEvent == NULL)
96 0 : return 1;
97 0 : if ( ! pEvent->ISA(VclWindowEvent))
98 0 : return 1;
99 0 : if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT)
100 0 : return 1;
101 :
102 0 : VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(pEvent);
103 0 : vcl::Window* pWindow = pWindowEvent ? pWindowEvent->GetWindow() : NULL;
104 0 : ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
105 0 : if (pToolBox == NULL)
106 0 : return 1;
107 :
108 : // Extract name of (sub)toolbar from help id.
109 0 : OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8));
110 0 : if (sToolbarName.getLength() == 0)
111 0 : return 1;
112 0 : const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName));
113 0 : if (aURL.Path.getLength() == 0)
114 0 : return 1;
115 :
116 : // Get item id.
117 0 : sal_uInt16 nId = pToolBox->GetCurItemId();
118 0 : if (nId == 0)
119 0 : return 1;
120 :
121 0 : SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox);
122 0 : if (pSidebarToolBox == NULL)
123 0 : return 1;
124 0 : sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path));
125 0 : if (nItemId == 0)
126 : {
127 0 : pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox);
128 0 : if (pSidebarToolBox == NULL)
129 0 : return 1;
130 0 : nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path);
131 0 : if (nItemId == 0)
132 0 : return 1;
133 : }
134 :
135 0 : Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY);
136 0 : if ( ! xController.is() )
137 0 : return 1;
138 :
139 0 : const OUString sCommand (pToolBox->GetItemCommand(nId));
140 0 : xController->functionSelected(sCommand);
141 :
142 0 : return 1;
143 : }
144 :
145 :
146 594 : } } // end of namespace svx::sidebar
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|