10d4dbf8bSAndre Fischer /**************************************************************
20d4dbf8bSAndre Fischer  *
30d4dbf8bSAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
40d4dbf8bSAndre Fischer  * or more contributor license agreements.  See the NOTICE file
50d4dbf8bSAndre Fischer  * distributed with this work for additional information
60d4dbf8bSAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
70d4dbf8bSAndre Fischer  * to you under the Apache License, Version 2.0 (the
80d4dbf8bSAndre Fischer  * "License"); you may not use this file except in compliance
90d4dbf8bSAndre Fischer  * with the License.  You may obtain a copy of the License at
100d4dbf8bSAndre Fischer  *
110d4dbf8bSAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
120d4dbf8bSAndre Fischer  *
130d4dbf8bSAndre Fischer  * Unless required by applicable law or agreed to in writing,
140d4dbf8bSAndre Fischer  * software distributed under the License is distributed on an
150d4dbf8bSAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160d4dbf8bSAndre Fischer  * KIND, either express or implied.  See the License for the
170d4dbf8bSAndre Fischer  * specific language governing permissions and limitations
180d4dbf8bSAndre Fischer  * under the License.
190d4dbf8bSAndre Fischer  *
200d4dbf8bSAndre Fischer  *************************************************************/
210d4dbf8bSAndre Fischer 
220d4dbf8bSAndre Fischer #include "precompiled_svx.hxx"
230d4dbf8bSAndre Fischer 
240d4dbf8bSAndre Fischer #include "InsertPropertyPanel.hxx"
250d4dbf8bSAndre Fischer #include "InsertPropertyPanel.hrc"
260d4dbf8bSAndre Fischer #include "sfx2/sidebar/CommandInfoProvider.hxx"
270d4dbf8bSAndre Fischer 
280d4dbf8bSAndre Fischer #include <sfx2/sidebar/Theme.hxx>
290d4dbf8bSAndre Fischer #include <sfx2/sidebar/Tools.hxx>
300d4dbf8bSAndre Fischer #include <sfx2/sidebar/ControlFactory.hxx>
31*ae13266dSAndre Fischer #include <sfx2/sidebar/ControllerFactory.hxx>
320d4dbf8bSAndre Fischer 
330d4dbf8bSAndre Fischer #include <svx/dialmgr.hxx>
340d4dbf8bSAndre Fischer #include <svtools/miscopt.hxx>
351d5c86bfSAndre Fischer #include <svtools/generictoolboxcontroller.hxx>
360d4dbf8bSAndre Fischer #include <vcl/toolbox.hxx>
370d4dbf8bSAndre Fischer #include <sfx2/tbxctrl.hxx>
380d4dbf8bSAndre Fischer #include <framework/sfxhelperfunctions.hxx>
390d4dbf8bSAndre Fischer #include <framework/imageproducer.hxx>
400d4dbf8bSAndre Fischer #include <comphelper/processfactory.hxx>
410d4dbf8bSAndre Fischer #include <cppuhelper/compbase1.hxx>
420d4dbf8bSAndre Fischer #include <cppuhelper/basemutex.hxx>
430d4dbf8bSAndre Fischer 
440d4dbf8bSAndre Fischer #include <com/sun/star/frame/XStatusListener.hpp>
450d4dbf8bSAndre Fischer 
460d4dbf8bSAndre Fischer using namespace css;
470d4dbf8bSAndre Fischer using namespace cssu;
480d4dbf8bSAndre Fischer using ::rtl::OUString;
49*ae13266dSAndre Fischer using ::sfx2::sidebar::SidebarToolBox;
500d4dbf8bSAndre Fischer 
510d4dbf8bSAndre Fischer namespace svx { namespace sidebar {
520d4dbf8bSAndre Fischer 
530d4dbf8bSAndre Fischer 
InsertPropertyPanel(Window * pParent,const cssu::Reference<css::frame::XFrame> & rxFrame)540d4dbf8bSAndre Fischer InsertPropertyPanel::InsertPropertyPanel (
550d4dbf8bSAndre Fischer     Window* pParent,
560d4dbf8bSAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame)
570d4dbf8bSAndre Fischer     :	Control(pParent, SVX_RES(RID_SIDEBAR_INSERT_PANEL)),
580d4dbf8bSAndre Fischer         mpStandardShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
590d4dbf8bSAndre Fischer         mpStandardShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox(
600d4dbf8bSAndre Fischer                 mpStandardShapesBackground.get(),
61*ae13266dSAndre Fischer                 SVX_RES(TB_INSERT_STANDARD),
62*ae13266dSAndre Fischer                 rxFrame)),
630d4dbf8bSAndre Fischer         mpCustomShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
640d4dbf8bSAndre Fischer         mpCustomShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox(
650d4dbf8bSAndre Fischer                 mpCustomShapesBackground.get(),
66*ae13266dSAndre Fischer                 SVX_RES(TB_INSERT_CUSTOM),
67*ae13266dSAndre Fischer                 rxFrame)),
680d4dbf8bSAndre Fischer         mxFrame(rxFrame)
690d4dbf8bSAndre Fischer {
700d4dbf8bSAndre Fischer     FreeResource();
710d4dbf8bSAndre Fischer 
720d4dbf8bSAndre Fischer     mpStandardShapesToolBox->Show();
730d4dbf8bSAndre Fischer     mpCustomShapesToolBox->Show();
740d4dbf8bSAndre Fischer 
750d4dbf8bSAndre Fischer     // Listen to all tool box selection events.
760d4dbf8bSAndre Fischer     Window* pTopWindow = pParent;
770d4dbf8bSAndre Fischer     while (pTopWindow->GetParent() != NULL)
780d4dbf8bSAndre Fischer         pTopWindow = pTopWindow->GetParent();
790d4dbf8bSAndre Fischer     pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
800d4dbf8bSAndre Fischer }
810d4dbf8bSAndre Fischer 
820d4dbf8bSAndre Fischer 
830d4dbf8bSAndre Fischer 
840d4dbf8bSAndre Fischer 
~InsertPropertyPanel(void)850d4dbf8bSAndre Fischer InsertPropertyPanel::~InsertPropertyPanel (void)
860d4dbf8bSAndre Fischer {
870d4dbf8bSAndre Fischer     // Remove window child listener.
880d4dbf8bSAndre Fischer     Window* pTopWindow = this;
890d4dbf8bSAndre Fischer     while (pTopWindow->GetParent() != NULL)
900d4dbf8bSAndre Fischer         pTopWindow = pTopWindow->GetParent();
910d4dbf8bSAndre Fischer     pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
920d4dbf8bSAndre Fischer 
930d4dbf8bSAndre Fischer     mpStandardShapesToolBox.reset();
940d4dbf8bSAndre Fischer     mpCustomShapesToolBox.reset();
950d4dbf8bSAndre Fischer     mpStandardShapesBackground.reset();
960d4dbf8bSAndre Fischer     mpCustomShapesBackground.reset();
970d4dbf8bSAndre Fischer }
980d4dbf8bSAndre Fischer 
990d4dbf8bSAndre Fischer 
1000d4dbf8bSAndre Fischer 
1010d4dbf8bSAndre Fischer 
IMPL_LINK(InsertPropertyPanel,WindowEventListener,VclSimpleEvent *,pEvent)1020d4dbf8bSAndre Fischer IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent)
1030d4dbf8bSAndre Fischer {
1040d4dbf8bSAndre Fischer     // We will be getting a lot of window events (well, basically all
1050d4dbf8bSAndre Fischer     // of them), so reject early everything that is not connected to
1060d4dbf8bSAndre Fischer     // toolbox selection.
1070d4dbf8bSAndre Fischer     if (pEvent == NULL)
1080d4dbf8bSAndre Fischer         return 1;
1090d4dbf8bSAndre Fischer     if ( ! pEvent->ISA(VclWindowEvent))
1100d4dbf8bSAndre Fischer         return 1;
1110d4dbf8bSAndre Fischer     if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT)
1120d4dbf8bSAndre Fischer         return 1;
1130d4dbf8bSAndre Fischer 
114*ae13266dSAndre Fischer     Window* pWindow = dynamic_cast<VclWindowEvent*>(pEvent)->GetWindow();
115*ae13266dSAndre Fischer     ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
1160d4dbf8bSAndre Fischer     if (pToolBox == NULL)
1170d4dbf8bSAndre Fischer         return 1;
1180d4dbf8bSAndre Fischer 
1190d4dbf8bSAndre Fischer     // Extract name of (sub)toolbar from help id.
1200d4dbf8bSAndre Fischer     OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8));
1210d4dbf8bSAndre Fischer     if (sToolbarName.getLength() == 0)
1220d4dbf8bSAndre Fischer         return 1;
1230d4dbf8bSAndre Fischer     const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName));
1240d4dbf8bSAndre Fischer     if (aURL.Path.getLength() == 0)
1250d4dbf8bSAndre Fischer         return 1;
1260d4dbf8bSAndre Fischer 
1270d4dbf8bSAndre Fischer     // Get item id.
1280d4dbf8bSAndre Fischer     sal_uInt16 nId = pToolBox->GetCurItemId();
1290d4dbf8bSAndre Fischer     if (nId == 0)
1300d4dbf8bSAndre Fischer         return 1;
1310d4dbf8bSAndre Fischer 
132*ae13266dSAndre Fischer     SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox.get());
133*ae13266dSAndre Fischer     if (pSidebarToolBox == NULL)
134*ae13266dSAndre Fischer         return 1;
135*ae13266dSAndre Fischer     sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path));
136*ae13266dSAndre Fischer     if (nItemId == 0)
137*ae13266dSAndre Fischer     {
138*ae13266dSAndre Fischer         pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox.get());
139*ae13266dSAndre Fischer         if (pSidebarToolBox == NULL)
140*ae13266dSAndre Fischer             return 1;
141*ae13266dSAndre Fischer         nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path);
142*ae13266dSAndre Fischer         if (nItemId == 0)
143*ae13266dSAndre Fischer             return 1;
144*ae13266dSAndre Fischer     }
145*ae13266dSAndre Fischer 
146*ae13266dSAndre Fischer     Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY);
1470d4dbf8bSAndre Fischer     if ( ! xController.is())
1480d4dbf8bSAndre Fischer         return 1;
1490d4dbf8bSAndre Fischer 
1500d4dbf8bSAndre Fischer     const OUString sCommand (pToolBox->GetItemCommand(nId));
1510d4dbf8bSAndre Fischer     xController->functionSelected(sCommand);
1520d4dbf8bSAndre Fischer 
1530d4dbf8bSAndre Fischer     return 1;
1540d4dbf8bSAndre Fischer }
1550d4dbf8bSAndre Fischer 
1560d4dbf8bSAndre Fischer 
1570d4dbf8bSAndre Fischer } } // end of namespace svx::sidebar
158