ControllerFactory.cxx (ae13266d) | ControllerFactory.cxx (d46a1e42) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 13 unchanged lines hidden (view full) --- 22#include "precompiled_sfx2.hxx" 23 24#include "sfx2/sidebar/ControllerFactory.hxx" 25#include "sfx2/sidebar/CommandInfoProvider.hxx" 26#include "sfx2/sidebar/Tools.hxx" 27 28#include <com/sun/star/frame/XToolbarController.hpp> 29#include <com/sun/star/frame/XFrame.hpp> | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 13 unchanged lines hidden (view full) --- 22#include "precompiled_sfx2.hxx" 23 24#include "sfx2/sidebar/ControllerFactory.hxx" 25#include "sfx2/sidebar/CommandInfoProvider.hxx" 26#include "sfx2/sidebar/Tools.hxx" 27 28#include <com/sun/star/frame/XToolbarController.hpp> 29#include <com/sun/star/frame/XFrame.hpp> |
30#include <com/sun/star/frame/XUIControllerFactory.hpp> |
|
30 31#include <framework/sfxhelperfunctions.hxx> 32#include <svtools/generictoolboxcontroller.hxx> 33#include <comphelper/processfactory.hxx> | 31 32#include <framework/sfxhelperfunctions.hxx> 33#include <svtools/generictoolboxcontroller.hxx> 34#include <comphelper/processfactory.hxx> |
35#include <toolkit/helper/vclunohelper.hxx> |
|
34 35 36using namespace css; 37using namespace cssu; 38using ::rtl::OUString; 39 40 41namespace sfx2 { namespace sidebar { 42 43Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( 44 ToolBox* pToolBox, 45 const sal_uInt16 nItemId, 46 const OUString& rsCommandName, | 36 37 38using namespace css; 39using namespace cssu; 40using ::rtl::OUString; 41 42 43namespace sfx2 { namespace sidebar { 44 45Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( 46 ToolBox* pToolBox, 47 const sal_uInt16 nItemId, 48 const OUString& rsCommandName, |
47 const Reference<frame::XFrame>& rxFrame) | 49 const Reference<frame::XFrame>& rxFrame, 50 const Reference<awt::XWindow>& rxParentWindow, 51 const sal_Int32 nWidth) |
48{ | 52{ |
53 Reference<frame::XToolbarController> xController ( 54 CreateToolBarController( 55 pToolBox, 56 rsCommandName, 57 rxFrame, 58 nWidth)); 59 |
|
49 // Create a controller for the new item. | 60 // Create a controller for the new item. |
50 Reference<frame::XToolbarController> xController( 51 static_cast<XWeak*>(::framework::CreateToolBoxController( 52 rxFrame, 53 pToolBox, 54 nItemId, 55 rsCommandName)), | 61 if ( ! xController.is()) 62 { 63 xController.set( 64 static_cast<XWeak*>(::framework::CreateToolBoxController( 65 rxFrame, 66 pToolBox, 67 nItemId, 68 rsCommandName)), |
56 UNO_QUERY); | 69 UNO_QUERY); |
70 } |
|
57 if ( ! xController.is()) | 71 if ( ! xController.is()) |
72 { |
|
58 xController.set( 59 static_cast<XWeak*>(new svt::GenericToolboxController( 60 ::comphelper::getProcessServiceFactory(), 61 rxFrame, 62 pToolBox, 63 nItemId, 64 rsCommandName)), 65 UNO_QUERY); | 73 xController.set( 74 static_cast<XWeak*>(new svt::GenericToolboxController( 75 ::comphelper::getProcessServiceFactory(), 76 rxFrame, 77 pToolBox, 78 nItemId, 79 rsCommandName)), 80 UNO_QUERY); |
81 } |
|
66 67 // Initialize the controller with eg a service factory. 68 Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY); 69 if (xInitialization.is()) 70 { 71 beans::PropertyValue aPropValue; 72 std::vector<Any> aPropertyVector; 73 --- 7 unchanged lines hidden (view full) --- 81 82 aPropValue.Name = A2S("CommandURL"); 83 aPropValue.Value <<= rsCommandName; 84 aPropertyVector.push_back(makeAny(aPropValue)); 85 86 Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); 87 xInitialization->initialize(aArgs); 88 } | 82 83 // Initialize the controller with eg a service factory. 84 Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY); 85 if (xInitialization.is()) 86 { 87 beans::PropertyValue aPropValue; 88 std::vector<Any> aPropertyVector; 89 --- 7 unchanged lines hidden (view full) --- 97 98 aPropValue.Name = A2S("CommandURL"); 99 aPropValue.Value <<= rsCommandName; 100 aPropertyVector.push_back(makeAny(aPropValue)); 101 102 Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); 103 xInitialization->initialize(aArgs); 104 } |
89 90 Reference<util::XUpdatable> xUpdatable (xController, UNO_QUERY); 91 if (xUpdatable.is()) 92 xUpdatable->update(); | |
93 | 105 |
94 // Add label. | |
95 if (xController.is()) 96 { | 106 if (xController.is()) 107 { |
97 const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( 98 rsCommandName, 99 rxFrame)); 100 pToolBox->SetQuickHelpText(nItemId, sLabel); 101 pToolBox->EnableItem(nItemId); | 108 if (rxParentWindow.is()) 109 { 110 Reference<awt::XWindow> xItemWindow (xController->createItemWindow(rxParentWindow)); 111 Window* pItemWindow = VCLUnoHelper::GetWindow(xItemWindow); 112 if (pItemWindow != NULL) 113 { 114 WindowType nType = pItemWindow->GetType(); 115 if (nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX) 116 pItemWindow->SetAccessibleName(pToolBox->GetItemText(nItemId)); 117 if (nWidth > 0) 118 pItemWindow->SetSizePixel(Size(nWidth, pItemWindow->GetSizePixel().Height())); 119 pToolBox->SetItemWindow(nItemId, pItemWindow); 120 } 121 } 122 123 Reference<util::XUpdatable> xUpdatable (xController, UNO_QUERY); 124 if (xUpdatable.is()) 125 xUpdatable->update(); 126 127 // Add label. 128 if (xController.is()) 129 { 130 const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( 131 rsCommandName, 132 rxFrame)); 133 pToolBox->SetQuickHelpText(nItemId, sLabel); 134 pToolBox->EnableItem(nItemId); 135 } |
102 } 103 104 return xController; 105} 106 107 | 136 } 137 138 return xController; 139} 140 141 |
142 143 144Reference<frame::XToolbarController> ControllerFactory::CreateToolBarController( 145 ToolBox* pToolBox, 146 const OUString& rsCommandName, 147 const Reference<frame::XFrame>& rxFrame, 148 const sal_Int32 nWidth) 149{ 150 try 151 { 152 Reference<frame::XUIControllerFactory> xFactory ( 153 comphelper::getProcessServiceFactory()->createInstance(A2S("com.sun.star.frame.ToolbarControllerFactory")), 154 UNO_QUERY); 155 OUString sModuleName (Tools::GetModuleName(rxFrame)); 156 157 if (xFactory.is() && xFactory->hasController(rsCommandName, sModuleName)) 158 { 159 beans::PropertyValue aPropValue; 160 std::vector<Any> aPropertyVector; 161 162 aPropValue.Name = A2S("ModuleIdentifier"); 163 aPropValue.Value <<= sModuleName; 164 aPropertyVector.push_back( makeAny( aPropValue )); 165 166 aPropValue.Name = A2S("Frame"); 167 aPropValue.Value <<= rxFrame; 168 aPropertyVector.push_back( makeAny( aPropValue )); 169 170 aPropValue.Name = A2S("ServiceManager"); 171 aPropValue.Value <<= comphelper::getProcessServiceFactory(); 172 aPropertyVector.push_back( makeAny( aPropValue )); 173 174 aPropValue.Name = A2S("ParentWindow"); 175 aPropValue.Value <<= VCLUnoHelper::GetInterface(pToolBox); 176 aPropertyVector.push_back( makeAny( aPropValue )); 177 178 if (nWidth > 0) 179 { 180 aPropValue.Name = A2S("Width"); 181 aPropValue.Value <<= nWidth; 182 aPropertyVector.push_back( makeAny( aPropValue )); 183 } 184 185 Reference<beans::XPropertySet> xFactoryProperties (comphelper::getProcessServiceFactory(), UNO_QUERY); 186 Reference<XComponentContext > xComponentContext; 187 if (xFactoryProperties.is()) 188 xFactoryProperties->getPropertyValue(A2S("DefaultContext")) >>= xComponentContext; 189 190 Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); 191 return Reference<frame::XToolbarController>( 192 xFactory->createInstanceWithArgumentsAndContext( 193 rsCommandName, 194 aArgs, 195 xComponentContext), 196 UNO_QUERY); 197 } 198 } 199 catch (Exception& rException) 200 { 201 // Ignore exception. 202 } 203 return NULL; 204} 205 |
|
108} } // end of namespace sfx2::sidebar | 206} } // end of namespace sfx2::sidebar |