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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#include "wrapper.hxx"
#include <com/sun/star/awt/XFixedText.hpp>
#include <com/sun/star/awt/XDialog2.hpp>
#include <com/sun/star/awt/WindowAttribute.hpp>
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#include <comphelper/processfactory.hxx>
#include <vcl/window.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include "layoutcore.hxx"
#include "../layout/factory.hxx"
#include "../layout/root.hxx"
using namespace ::com::sun::star;
namespace layout
{
// Context bits ...
class ContextImpl
{
uno::Reference< awt::XLayoutRoot > mxRoot;
uno::Reference< container::XNameAccess > mxNameAccess;
PeerHandle mxTopLevel;
public:
ContextImpl( char const *pPath )
{
uno::Sequence< uno::Any > aParams( 1 );
aParams[0] <<= rtl::OUString( pPath, strlen( pPath ), RTL_TEXTENCODING_UTF8 );
uno::Reference< lang::XSingleServiceFactory > xFactory(
comphelper::createProcessComponent(
rtl::OUString::createFromAscii( "com.sun.star.awt.Layout" ) ),
uno::UNO_QUERY );
if ( !xFactory.is() )
{
throw uno::RuntimeException(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ),
uno::Reference< uno::XInterface >() );
}
mxRoot = uno::Reference< awt::XLayoutRoot >(
xFactory->createInstanceWithArguments( aParams ),
uno::UNO_QUERY );
mxNameAccess = uno::Reference< container::XNameAccess >( mxRoot, uno::UNO_QUERY );
}
~ContextImpl()
{
}
PeerHandle getByName( const rtl::OUString &rName )
{
uno::Any val = mxNameAccess->getByName( rName );
PeerHandle xRet;
val >>= xRet;
return xRet;
}
PeerHandle getTopLevel() { return mxTopLevel; }
void setTopLevel( PeerHandle xToplevel ) { mxTopLevel = xToplevel; }
PeerHandle getRoot() { return mxRoot; }
};
Context::Context( const char *pPath )
: pImpl( new ContextImpl( pPath ) )
{
}
Context::~Context()
{
delete pImpl;
pImpl = NULL;
}
void Context::setToplevel( PeerHandle xToplevel )
{
pImpl->setTopLevel( xToplevel );
}
PeerHandle Context::getToplevel()
{
return pImpl->getTopLevel();
}
PeerHandle Context::getRoot()
{
return pImpl->getRoot();
}
PeerHandle Context::GetPeerHandle( const char *pId, sal_uInt32 nId ) const
{
PeerHandle xHandle;
xHandle = pImpl->getByName( rtl::OUString( pId, strlen( pId ), RTL_TEXTENCODING_UTF8 ) );
if ( !xHandle.is() )
{
DBG_ERROR1( "Failed to fetch widget '%s'", pId );
}
if ( nId != 0 )
{
rtl::OString aStr = rtl::OString::valueOf( (sal_Int32) nId );
xHandle = GetPeerHandle( aStr, 0 );
}
return xHandle;
}
// Window/Dialog
class DialogImpl : public WindowImpl
{
public:
uno::Reference< awt::XDialog2 > mxDialog;
DialogImpl( Context *pCtx, const PeerHandle &xPeer, Window *pWindow )
: WindowImpl( pCtx, xPeer, pWindow )
, mxDialog( xPeer, uno::UNO_QUERY )
{
}
};
// Accessors
DECL_GET_IMPL_IMPL( Control )
DECL_GET_IMPL_IMPL( Dialog )
Window::Window( WindowImpl *pImpl )
: mpImpl( pImpl )
{
}
Window::~Window()
{
/* likely to be an UNO object - with floating references */
mpImpl->wrapperGone();
mpImpl = NULL;
}
Context *Window::getContext()
{
return this && mpImpl ? mpImpl->mpCtx : NULL;
}
PeerHandle Window::GetPeer()
{
if (!mpImpl)
return PeerHandle();
return mpImpl->mxWindow;
}
struct ToolkitVclPropsMap
{
WinBits vclStyle;
long initAttr;
const char *propName;
// the value to give the prop to enable/disable it -- not the most brilliant
// type declaration and storage, but does the work... properties are
// either a boolean or a short since they are either a directly wrappers for
// a WinBit, or aggregates related (like Align for WB_LEFT, _RIGHT and _CENTER).
bool isBoolean;
short enableProp, disableProp;
};
#define TYPE_BOOL true
#define TYPE_SHORT false
#define NOTYPE 0
static const ToolkitVclPropsMap toolkitVclPropsMap[] =
{
{ WB_BORDER, awt::WindowAttribute::BORDER, "Border", TYPE_SHORT, 1, 0 },
{ WB_NOBORDER, awt::VclWindowPeerAttribute::NOBORDER, "Border", TYPE_SHORT, 0, 1 },
{ WB_SIZEABLE, awt::WindowAttribute::SIZEABLE, NULL, NOTYPE, 0, 0 },
{ WB_MOVEABLE, awt::WindowAttribute::MOVEABLE, NULL, NOTYPE, 0, 0 },
{ WB_CLOSEABLE, awt::WindowAttribute::CLOSEABLE, NULL, NOTYPE, 0, 0 },
{ WB_HSCROLL, awt::VclWindowPeerAttribute::HSCROLL, NULL, NOTYPE, 0, 0 },
{ WB_VSCROLL, awt::VclWindowPeerAttribute::VSCROLL, NULL, NOTYPE, 0, 0 },
{ WB_LEFT, awt::VclWindowPeerAttribute::LEFT, "Align", TYPE_SHORT, 0, 0 },
{ WB_CENTER, awt::VclWindowPeerAttribute::CENTER, "Align", TYPE_SHORT, 1, 0 },
{ WB_RIGHT, awt::VclWindowPeerAttribute::RIGHT, "Align", TYPE_SHORT, 2, 0 },
{ WB_SPIN, awt::VclWindowPeerAttribute::SPIN, NULL, NOTYPE, 0, 0 },
{ WB_SORT, awt::VclWindowPeerAttribute::SORT, NULL, NOTYPE, 0, 0 },
{ WB_DROPDOWN, awt::VclWindowPeerAttribute::DROPDOWN, "Dropdown", TYPE_BOOL, 1, 0 },
{ WB_DEFBUTTON, awt::VclWindowPeerAttribute::DEFBUTTON, "DefaultButton", TYPE_BOOL, 1, 0 },
{ WB_READONLY, awt::VclWindowPeerAttribute::READONLY, NULL, NOTYPE, 0, 0 },
{ WB_CLIPCHILDREN, awt::VclWindowPeerAttribute::CLIPCHILDREN, NULL, NOTYPE, 0, 0 },
{ WB_GROUP, awt::VclWindowPeerAttribute::GROUP, NULL, NOTYPE, 0, 0 },
{ WB_OK, awt::VclWindowPeerAttribute::OK, NULL, NOTYPE, 0, 0 },
{ WB_OK_CANCEL, awt::VclWindowPeerAttribute::OK_CANCEL, NULL, NOTYPE, 0, 0 },
{ WB_YES_NO, awt::VclWindowPeerAttribute::YES_NO, NULL, NOTYPE, 0, 0 },
{ WB_YES_NO_CANCEL, awt::VclWindowPeerAttribute::YES_NO_CANCEL, NULL, NOTYPE, 1, 0 },
{ WB_RETRY_CANCEL, awt::VclWindowPeerAttribute::RETRY_CANCEL, NULL, NOTYPE, 1, 0 },
{ WB_DEF_OK, awt::VclWindowPeerAttribute::DEF_OK, NULL, NOTYPE, 0, 0 },
{ WB_DEF_CANCEL, awt::VclWindowPeerAttribute::DEF_CANCEL, NULL, NOTYPE, 1, 0 },
{ WB_DEF_RETRY, awt::VclWindowPeerAttribute::DEF_RETRY, NULL, NOTYPE, 0, 0 },
{ WB_DEF_YES, awt::VclWindowPeerAttribute::DEF_YES, NULL, NOTYPE, 0, 0 },
{ WB_DEF_NO, awt::VclWindowPeerAttribute::DEF_NO, NULL, NOTYPE, 0, 0 },
{ WB_AUTOHSCROLL, awt::VclWindowPeerAttribute::AUTOHSCROLL, "AutoHScroll", TYPE_BOOL, 1, 0 },
{ WB_AUTOVSCROLL, awt::VclWindowPeerAttribute::AUTOVSCROLL, "AutoVScroll", TYPE_BOOL, 1, 0 },
{ WB_WORDBREAK, 0, "MultiLine", TYPE_BOOL, 1, 0 },
{ WB_NOPOINTERFOCUS, 0, "FocusOnClick", TYPE_BOOL, 1, 0 },
{ WB_TOGGLE, 0, "Toggle", TYPE_BOOL, 1, 0 },
{ WB_REPEAT, 0, "Repeat", TYPE_BOOL, 1, 0 },
{ WB_NOHIDESELECTION, 0, "HideInactiveSelection", TYPE_BOOL, 1, 0 },
};
#undef TYPE_BOOL
#undef TYPE_SHORT
#undef NOTYPE
static const int toolkitVclPropsMapLen =
sizeof( toolkitVclPropsMap ) / sizeof( ToolkitVclPropsMap );
void Window::SetStyle( WinBits nStyle )
{
uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer;
for( int i = 0; i < toolkitVclPropsMapLen; i++ )
{
if ( toolkitVclPropsMap[ i ].propName )
{
short nValue;
if ( nStyle & toolkitVclPropsMap[ i ].vclStyle )
nValue = toolkitVclPropsMap[ i ].enableProp;
else
nValue = toolkitVclPropsMap[ i ].disableProp;
uno::Any aValue;
if ( toolkitVclPropsMap[ i ].isBoolean )
aValue = uno::makeAny( (bool) nValue );
else
aValue = uno::makeAny( (short) nValue );
mpImpl->setProperty( toolkitVclPropsMap[ i ].propName, aValue );
}
}
}
WinBits Window::GetStyle()
{
uno::Reference< awt::XVclWindowPeer > xPeer = mpImpl->mxVclPeer;
WinBits ret = 0;
for( int i = 0; i < toolkitVclPropsMapLen; i++ )
{
if ( toolkitVclPropsMap[ i ].propName )
{
short nValue;
if ( toolkitVclPropsMap[ i ].isBoolean )
{
bool bValue;
mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= bValue;
nValue = bValue ? 1 : 0;
}
else
mpImpl->getProperty( toolkitVclPropsMap[ i ].propName ) >>= nValue;
if ( nValue == toolkitVclPropsMap[ i ].enableProp )
ret |= toolkitVclPropsMap[i].vclStyle;
}
}
return ret;
}
/* Unpleasant way to get an xToolkit pointer ... */
uno::Reference< awt::XToolkit > getToolkit()
{
static uno::Reference< awt::XToolkit > xToolkit;
if (!xToolkit.is())
{
// Urgh ...
xToolkit = uno::Reference< awt::XToolkit >(
::comphelper::getProcessServiceFactory()->createInstance(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ),
uno::UNO_QUERY );
if ( !xToolkit.is() )
throw uno::RuntimeException(
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "failed to create toolkit!") ),
uno::Reference< uno::XInterface >() );
}
return xToolkit;
}
PeerHandle Window::CreatePeer( Window *pParent, WinBits nStyle, const char *pName)
{
long nWinAttrbs = 0;
for( int i = 0; i < toolkitVclPropsMapLen; i++ )
if ( nStyle & toolkitVclPropsMap[ i ].vclStyle )
nWinAttrbs |= toolkitVclPropsMap[ i ].initAttr;
return layoutimpl::createWidget( getToolkit(), pParent->GetPeer(),
rtl::OUString::createFromAscii( pName ), nWinAttrbs );
#if 0
awt::WindowDescriptor desc;
// debugging help ...
desc.Bounds.X = 0;
desc.Bounds.Y = 0;
desc.Bounds.Width = 300;
desc.Bounds.Height = 200;
desc.ParentIndex = 0;
// FIXME: this code should be shared with
// toolkit/source/awt/vclxtoolkit.cxx (ImplGetWinBits)
desc.WindowAttributes = 0;
for( int i = 0; i < toolkitVclPropsMapLen; i++ )
if ( nStyle & toolkitVclPropsMap[ i ].vclStyle )
desc.WindowAttributes |= toolkitVclPropsMap[ i ].initAttr;
desc.WindowServiceName = rtl::OUString( pName, strlen( pName ),
RTL_TEXTENCODING_ASCII_US );
// FIXME: we really want to walk up the peer hierarchy
// and get the top-level that this requires.
if ( pParent != NULL )
{
PeerHandle hdl = pParent->GetPeer();
desc.Parent = uno::Reference< awt::XWindowPeer >( hdl, uno::UNO_QUERY );
}
PeerHandle xPeer = getToolkit()->createWindow( desc );
// not all WinBits have an equivalent attribute, some are available through
// properties though
for( int i = 0; i < toolkitVclPropsMapLen; i++ )
if ( nStyle & toolkitVclPropsMap[ i ].vclStyle &&
!toolkitVclPropsMap[ i ].initAttr &&
toolkitVclPropsMap[ i ].propName )
{
uno::Any aValue;
if ( toolkitVclPropsMap[ i ].isBoolean )
aValue = uno::makeAny( (bool) toolkitVclPropsMap[ i ].enableProp );
else
aValue = uno::makeAny( (short) toolkitVclPropsMap[ i ].enableProp );
layoutimpl::prophlp::setProperty( xPeer,
rtl::OUString::createFromAscii( toolkitVclPropsMap[ i ].propName ), aValue );
}
return xPeer;
#endif
}
void Window::Enable( bool bEnable )
{
if ( !getImpl().mxWindow.is() )
return;
getImpl().mxWindow->setEnable( bEnable );
}
void Window::Show( BOOL bVisible )
{
if ( !getImpl().mxWindow.is() )
return;
getImpl().mxWindow->setVisible( bVisible );
}
void Window::GrabFocus()
{
if ( !getImpl().mxWindow.is() )
return;
getImpl().mxWindow->setFocus();
}
Dialog::Dialog( Window *pParent, const char *pXMLPath, const char *pId, sal_uInt32 nId )
: Context( pXMLPath )
, Window( new DialogImpl( this, Context::GetPeerHandle( pId, nId ), this ) )
{
if ( pParent )
SetParent( pParent );
}
Dialog::Dialog( ::Window *pParent, const char *pXMLPath, const char *pId, sal_uInt32 nId )
: Context( pXMLPath )
, Window( new DialogImpl( this, Context::GetPeerHandle( pId, nId ), this ) )
{
if ( pParent )
SetParent( pParent );
}
void Dialog::SetParent( ::Window *pParent )
{
uno::Reference <awt::XWindow> ref( GetPeer(), uno::UNO_QUERY );
::Window *window = VCLXWindow::GetImplementation( ref )->GetWindow();
window->SetParent( pParent );
}
void Dialog::SetParent( Window *pParent )
{
uno::Reference <awt::XWindow> parentRef( pParent->GetPeer(), uno::UNO_QUERY );
::Window *parentWindow = VCLXWindow::GetImplementation( parentRef )->GetWindow();
SetParent( parentWindow );
}
short Dialog::Execute()
{
if ( !getImpl().mxDialog.is() )
return -1;
return getImpl().mxDialog->execute();
}
void Dialog::EndDialog( long nResult )
{
if ( !getImpl().mxDialog.is() )
return;
getImpl().mxDialog->endDialog( nResult );
}
void Dialog::SetText( const String& rStr )
{
if ( !getImpl().mxDialog.is() )
return;
getImpl().mxDialog->setTitle( rStr );
}
class FixedLineImpl : public ControlImpl
{
public:
FixedLineImpl( Context *pCtx, const PeerHandle &xPeer, Window *pWindow )
: ControlImpl( pCtx, xPeer, pWindow )
{
}
};
DECL_CONSTRUCTOR_IMPLS( FixedLine, Control, "hfixedline" );
DECL_GET_IMPL_IMPL( FixedLine )
class FixedTextImpl : public ControlImpl
{
public:
uno::Reference< awt::XFixedText > mxFixedText;
FixedTextImpl( Context *pCtx, const PeerHandle &xPeer, Window *pWindow )
: ControlImpl( pCtx, xPeer, pWindow )
, mxFixedText( xPeer, uno::UNO_QUERY )
{
}
virtual void SAL_CALL disposing( const css::lang::EventObject& /* Source */ )
throw (css::uno::RuntimeException)
{
mxFixedText.clear();
}
};
DECL_CONSTRUCTOR_IMPLS( FixedText, Control, "fixedtext" );
DECL_GET_IMPL_IMPL( FixedText )
void FixedText::SetText( const String& rStr )
{
if ( !getImpl().mxFixedText.is() )
return;
getImpl().mxFixedText->setText( rStr );
}
class FixedInfoImpl : public FixedTextImpl
{
public:
FixedInfoImpl( Context *pCtx, const PeerHandle &xPeer, Window *pWindow )
: FixedTextImpl( pCtx, xPeer, pWindow )
{
}
};
DECL_CONSTRUCTOR_IMPLS( FixedInfo, FixedText, "fixedinfo" );
DECL_GET_IMPL_IMPL( FixedInfo )
}; // end namespace layout
|