1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "precompiled_sd.hxx"
#include "CustomToolPanel.hxx"
#include "framework/FrameworkHelper.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/drawing/framework/ResourceId.hpp>
#include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/drawing/framework/XPane2.hpp>
/** === end UNO includes === **/
#include <comphelper/processfactory.hxx>
#include <unotools/confignode.hxx>
#include <tools/diagnose_ex.h>
#if OSL_DEBUG_LEVEL > 0
#include <rtl/strbuf.hxx>
#endif
//......................................................................................................................
namespace sd { namespace toolpanel
{
//......................................................................................................................
/** === begin UNO using === **/
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Type;
using ::com::sun::star::drawing::framework::XConfigurationController;
using ::com::sun::star::drawing::framework::XResourceId;
using ::com::sun::star::drawing::framework::ResourceId;
using ::com::sun::star::drawing::framework::XResource;
using ::com::sun::star::awt::XWindow;
using ::com::sun::star::accessibility::XAccessible;
using ::com::sun::star::drawing::framework::XPane2;
/** === end UNO using === **/
namespace PosSize = ::com::sun::star::awt::PosSize;
//==================================================================================================================
//= helper
//==================================================================================================================
namespace
{
::rtl::OUString lcl_getPanelConfig( const ::utl::OConfigurationNode& i_rPanelConfig, const sal_Char* i_pAsciiPropName )
{
::rtl::OUString sConfigValue;
OSL_VERIFY( i_rPanelConfig.getNodeValue( i_pAsciiPropName ) >>= sConfigValue );
if ( sConfigValue.getLength() == 0 )
{
#if OSL_DEBUG_LEVEL > 0
::rtl::OStringBuffer aMessage;
aMessage.append( "lcl_getPanelConfig: invalid config value (" );
aMessage.append( i_pAsciiPropName );
aMessage.append( ") for panel config '" );
aMessage.append( ::rtl::OUStringToOString( i_rPanelConfig.getLocalName(), RTL_TEXTENCODING_UTF8 ) );
aMessage.append( "'" );
OSL_ENSURE( false, aMessage.makeStringAndClear().getStr() );
#endif
}
return sConfigValue;
}
}
//==================================================================================================================
//= CustomToolPanel
//==================================================================================================================
//------------------------------------------------------------------------------------------------------------------
CustomToolPanel::CustomToolPanel( ToolPanelDeck& i_rPanelDeck, const ::utl::OConfigurationNode& i_rPanelConfig,
const Reference< XResourceId >& i_rPaneResourceId, const ::boost::shared_ptr< framework::FrameworkHelper >& i_pFrameworkHelper )
:TaskPaneToolPanel( i_rPanelDeck, lcl_getPanelConfig( i_rPanelConfig, "DisplayTitle" ), Image() /* TODO */, SmartId() /* TODO */ )
,m_pFrameworkHelper( i_pFrameworkHelper )
,m_xPanelResourceId()
,m_xResource()
,m_xToolPanel()
,m_bAttemptedPanelCreation( false )
,m_nResourceAccessLock( 0 )
{
ENSURE_OR_THROW( m_pFrameworkHelper.get() != NULL, "invalid framework helper" );
ENSURE_OR_THROW( i_rPaneResourceId.is(), "invalid pane resource id" );
try
{
::rtl::OUString sPanelResourceURL( lcl_getPanelConfig( i_rPanelConfig, "ResourceURL" ) );
m_xPanelResourceId.set(
ResourceId::createWithAnchor(
::comphelper::getProcessComponentContext(),
sPanelResourceURL,
i_rPaneResourceId ),
UNO_SET_THROW
);
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
//------------------------------------------------------------------------------------------------------------------
CustomToolPanel::~CustomToolPanel()
{
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::Activate( ::Window& i_rParentWindow )
{
OSL_ENSURE( &getPanelWindowAnchor() == &i_rParentWindow,
"CustomToolPanel::Activate: invalid new parent window" );
// getPanelWindowAnchor() is what is returned in the TaskPane's XPane::getWindow method. So,
// any custom panel which is loaded into the TaskPane will use this window as parent window.
// Consequently, this is the window which shall be passed here, since this method is intended to
// re-create the panel with the given parent.
// we do not need to do anything here. The XResourceFactory::createResource method of the custom
// tool panel already created and showed the window.
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::Deactivate()
{
// When a certain tool panel is activated, this is routed through the drawing framework, which ensures
// that the resource associated with the previously active panel is deactivated, which calls the
// XResourceFactory::destroyResource at our custom panel's factory.
// So, we do not have to do anything here - except forgetting the XResource, at it might (or might not,
// if cached by the factory) be re-created next time.
m_xResource.clear();
m_xToolPanel.clear();
m_bAttemptedPanelCreation = false;
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::SetSizePixel( const Size& i_rPanelWindowSize )
{
impl_ensurePanel();
if ( !m_xToolPanel.is() )
// if the custom panel does not support XPanel, this just means it is its own responsibility
// to resize/layout everything within the pane window.
return;
try
{
Reference< XWindow > xPanelWindow( m_xToolPanel->getWindow(), UNO_SET_THROW );
xPanelWindow->setPosSize( 0, 0, i_rPanelWindowSize.Width(), i_rPanelWindowSize.Height(),
PosSize::POSSIZE );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::GrabFocus()
{
impl_ensurePanel();
if ( !m_xToolPanel.is() )
// if the custom panel does not support XPanel, this just means it is its own responsibility
// to care for focus handling
return;
try
{
Reference< XWindow > xPanelWindow( m_xToolPanel->getWindow(), UNO_SET_THROW );
xPanelWindow->setFocus();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::Dispose()
{
// nothing to do here. Lifetime handling of the XResource which this panel represents is done by
// the drawing framework, we ourself do not have resources to release.
TaskPaneToolPanel::Dispose();
}
//------------------------------------------------------------------------------------------------------------------
Reference< XAccessible > CustomToolPanel::CreatePanelAccessible( const Reference< XAccessible >& i_rParentAccessible )
{
ENSURE_OR_RETURN( !isDisposed(), "CustomToolPanel::CreatePanelAccessible: already disposed!", NULL );
(void)i_rParentAccessible;
// an XResource might also be an XPane2, which can provide an XAccessible. Check this first.
const Reference< XPane2 > xPane( m_xResource, UNO_QUERY );
if ( xPane.is() )
{
const Reference< XAccessible > xPaneAccessible( xPane->getAccessible() );
if ( xPaneAccessible.is() )
return xPaneAccessible;
}
// if we have an XToolPanel, ask it for its XWindow, and query it
impl_ensurePanel();
if ( !m_xToolPanel.is() )
return NULL;
const Reference< XAccessible > xPanelWindowAccessible( m_xToolPanel->getWindow(), UNO_QUERY );
if ( xPanelWindowAccessible.is() )
return xPanelWindowAccessible;
// maybe the XToolPanel itself can provide an XAccessible?
const Reference< XAccessible > xPanelAccessible( m_xToolPanel, UNO_QUERY );
if ( xPanelAccessible.is() )
return xPanelAccessible;
OSL_ENSURE( false, "CustomToolPanel::CreatePanelAccessible: no XAccessible for the custom panel!" );
return NULL;
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::LockResourceAccess()
{
++m_nResourceAccessLock;
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::UnlockResourceAccess()
{
OSL_ENSURE( m_nResourceAccessLock > 0, "CustomToolPanel::UnlockResourceAccess: not locked!" );
--m_nResourceAccessLock;
}
//------------------------------------------------------------------------------------------------------------------
const Reference< XResourceId >& CustomToolPanel::getResourceId() const
{
return m_xPanelResourceId;
}
//------------------------------------------------------------------------------------------------------------------
void CustomToolPanel::impl_ensurePanel()
{
ENSURE_OR_RETURN_VOID( !isDisposed(), "already disposed" );
if ( ( m_nResourceAccessLock == 0 ) && !m_bAttemptedPanelCreation )
{
m_bAttemptedPanelCreation = true;
try
{
Reference< XConfigurationController > xConfigController( m_pFrameworkHelper->GetConfigurationController(), UNO_QUERY_THROW );
m_xResource.set( xConfigController->getResource( m_xPanelResourceId ), UNO_QUERY_THROW );
m_xToolPanel.set( m_xResource, UNO_QUERY );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
//......................................................................................................................
} } // namespace sd::toolpanel
//......................................................................................................................
|