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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "backingwindow.hxx"
#include <vcl/svapp.hxx>
#include <vcl/virdev.hxx>
#include <unotools/dynamicmenuoptions.hxx>
#include <svtools/openfiledroptargetlistener.hxx>
#include <svtools/colorcfg.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <toolkit/awt/vclxmenu.hxx>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/document/UpdateDocMode.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/configuration/theDefaultProvider.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::document;
const char WRITER_URL[] = "private:factory/swriter";
const char CALC_URL[] = "private:factory/scalc";
const char IMPRESS_WIZARD_URL[] = "private:factory/simpress?slot=6686";
const char DRAW_URL[] = "private:factory/sdraw";
const char BASE_URL[] = "private:factory/sdatabase?Interactive";
const char MATH_URL[] = "private:factory/smath";
const char TEMPLATE_URL[] = "slot:5500";
const char OPEN_URL[] = ".uno:Open";
const char SERVICENAME_CFGREADACCESS[] = "com.sun.star.configuration.ConfigurationAccess";
const int nTemplateItemMaxWidth = 160;
const int nTemplateItemMaxHeight = 148;
const int nTemplateItemPadding = 5;
const int nTemplateItemMaxTextLength = 20;
const int nTemplateItemThumbnailMaxHeight = 96;
BackingWindow::BackingWindow( Window* i_pParent ) :
Window( i_pParent ),
mxDesktop( Desktop::create(comphelper::getProcessComponentContext()) ),
mbInitControls( false ),
mnHideExternalLinks( 0 ),
mpAccExec( NULL )
{
m_pUIBuilder = new VclBuilder(this, getUIRootDir(),
"sfx/ui/startcenter.ui",
"StartCenter" );
get(mpOpenButton, "open_all");
get(mpOpenWriterButton, "open_writer");
get(mpOpenCalcButton, "open_calc");
get(mpOpenImpressButton, "open_impress");
get(mpOpenDrawButton, "open_draw");
get(mpOpenDatabaseButton, "open_database");
get(mpOpenMathButton, "open_math");
get(mpTemplateButton, "templates_all");
get(mpTemplateWriterButton, "templates_writer");
get(mpTemplateCalcButton, "templates_calc");
get(mpTemplateImpressButton, "templates_impress");
get(mpTemplateDrawButton, "templates_draw");
get(mpTemplateDatabaseButton, "templates_database");
get(mpTemplateMathButton, "templates_math");
get(mpModuleNotebook, "modules_notebook");
get(mpWriterButton, "writer");
get(mpCalcButton, "calc");
get(mpImpressButton, "impress");
get(mpDrawButton, "draw");
get(mpDBButton, "database");
get(mpMathButton, "math");
get(mpWriterAllButton, "writer_all");
get(mpCalcAllButton, "calc_all");
get(mpImpressAllButton, "impress_all");
get(mpDrawAllButton, "draw_all");
get(mpDBAllButton, "database_all");
get(mpMathAllButton, "math_all");
get(mpWriterShowTemplateButton, "show_writer_template");
get(mpCalcShowTemplateButton, "show_calc_template");
get(mpImpressShowTemplateButton, "show_impress_template");
get(mpDrawShowTemplateButton, "show_draw_template");
get(mpWriterShowRecentButton, "show_writer_recent");
get(mpCalcShowRecentButton, "show_calc_recent");
get(mpImpressShowRecentButton, "show_impress_recent");
get(mpDrawShowRecentButton, "show_draw_recent");
get( mpAllRecentThumbnails, "all_recent");
get( mpWriterRecentThumbnails, "writer_recent");
get( mpCalcRecentThumbnails, "calc_recent");
get( mpImpressRecentThumbnails, "impress_recent");
get( mpDrawRecentThumbnails, "draw_recent");
get( mpDatabaseRecentThumbnails, "database_recent");
get( mpMathRecentThumbnails, "math_recent");
get( mpWriterTemplateThumbnails, "writer_templates");
get( mpCalcTemplateThumbnails, "calc_templates");
get( mpImpressTemplateThumbnails, "impress_templates");
get( mpDrawTemplateThumbnails, "draw_templates");
maDndWindows.push_back(mpAllRecentThumbnails);
maDndWindows.push_back(mpWriterRecentThumbnails);
maDndWindows.push_back(mpCalcRecentThumbnails);
maDndWindows.push_back(mpImpressRecentThumbnails);
maDndWindows.push_back(mpDrawRecentThumbnails);
maDndWindows.push_back(mpDatabaseRecentThumbnails);
maDndWindows.push_back(mpMathRecentThumbnails);
maDndWindows.push_back(mpWriterTemplateThumbnails);
maDndWindows.push_back(mpCalcTemplateThumbnails);
maDndWindows.push_back(mpImpressTemplateThumbnails);
maDndWindows.push_back(mpDrawTemplateThumbnails);
try
{
mxContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
Reference<lang::XMultiServiceFactory> xConfig = configuration::theDefaultProvider::get( mxContext );
Sequence<Any> args(1);
PropertyValue val(
"nodepath",
0,
Any(OUString("/org.openoffice.Office.Common/Help/StartCenter")),
PropertyState_DIRECT_VALUE);
args.getArray()[0] <<= val;
Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
if( xNameAccess.is() )
{
//throws css::container::NoSuchElementException, css::lang::WrappedTargetException
Any value( xNameAccess->getByName("StartCenterHideExternalLinks") );
mnHideExternalLinks = value.get<sal_Int32>();
}
}
catch (const Exception& e)
{
SAL_WARN( "fwk", "BackingWindow - caught an exception! " << e.Message );
}
// fdo#34392: we do the layout dynamically, the layout depends on the font,
// so we should handle data changed events (font changing) of the last child
// control, at this point all the controls have updated settings (i.e. font).
EnableChildTransparentMode();
SetStyle( GetStyle() | WB_DIALOGCONTROL );
// get dispatch provider
Reference<XDesktop2> xDesktop = Desktop::create( comphelper::getProcessComponentContext() );
mxDesktopDispatchProvider = xDesktop;
mpOpenButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenWriterButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenCalcButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenImpressButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenDrawButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenDatabaseButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpOpenMathButton ->SetHelpId( ".HelpId:StartCenter:OpenButton" );
mpTemplateButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateWriterButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateCalcButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateImpressButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateDrawButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateDatabaseButton->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpTemplateMathButton ->SetHelpId( ".HelpId:StartCenter:TemplateButton" );
mpWriterButton ->SetHelpId( ".HelpId:StartCenter:WriterButton" );
mpCalcButton ->SetHelpId( ".HelpId:StartCenter:CalcButton" );
mpImpressButton ->SetHelpId( ".HelpId:StartCenter:ImpressButton" );
mpDrawButton ->SetHelpId( ".HelpId:StartCenter:DrawButton" );
mpDBButton ->SetHelpId( ".HelpId:StartCenter:DBButton" );
mpMathButton ->SetHelpId( ".HelpId:StartCenter:MathButton" );
mpWriterAllButton ->SetHelpId( ".HelpId:StartCenter:WriterButton" );
mpCalcAllButton ->SetHelpId( ".HelpId:StartCenter:CalcButton" );
mpImpressAllButton ->SetHelpId( ".HelpId:StartCenter:ImpressButton" );
mpDrawAllButton ->SetHelpId( ".HelpId:StartCenter:DrawButton" );
mpDBAllButton ->SetHelpId( ".HelpId:StartCenter:DBButton" );
mpMathAllButton ->SetHelpId( ".HelpId:StartCenter:MathButton" );
// init background
SetBackground();
}
BackingWindow::~BackingWindow()
{
mpWriterTemplateThumbnails ->setOpenTemplateHdl(Link());
mpCalcTemplateThumbnails ->setOpenTemplateHdl(Link());
mpImpressTemplateThumbnails ->setOpenTemplateHdl(Link());
mpDrawTemplateThumbnails ->setOpenTemplateHdl(Link());
// deregister drag&drop helper
if (mxDropTargetListener.is())
{
for (std::vector<Window*>::iterator aI = maDndWindows.begin(),
aEnd = maDndWindows.end(); aI != aEnd; ++aI)
{
Window *pDndWin = *aI;
css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget =
pDndWin->GetDropTarget();
if (xDropTarget.is())
{
xDropTarget->removeDropTargetListener(mxDropTargetListener);
xDropTarget->setActive(false);
}
}
mxDropTargetListener = css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >();
}
}
void BackingWindow::initControls()
{
if( mbInitControls )
return;
mbInitControls = true;
// collect the URLs of the entries in the File/New menu
SvtModuleOptions aModuleOptions;
std::set< OUString > aFileNewAppsAvailable;
SvtDynamicMenuOptions aOpt;
Sequence < Sequence < PropertyValue > > aNewMenu = aOpt.GetMenu( E_NEWMENU );
const OUString sURLKey( "URL" );
const Sequence< PropertyValue >* pNewMenu = aNewMenu.getConstArray();
const Sequence< PropertyValue >* pNewMenuEnd = aNewMenu.getConstArray() + aNewMenu.getLength();
for ( ; pNewMenu != pNewMenuEnd; ++pNewMenu )
{
comphelper::SequenceAsHashMap aEntryItems( *pNewMenu );
OUString sURL( aEntryItems.getUnpackedValueOrDefault( sURLKey, OUString() ) );
if ( !sURL.isEmpty() )
aFileNewAppsAvailable.insert( sURL );
}
setupModuleTab( "tab_writer", mpWriterRecentThumbnails, TYPE_WRITER,
WRITER_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SWRITER );
setupModuleTab( "tab_calc", mpCalcRecentThumbnails, TYPE_CALC,
DRAW_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SDRAW );
setupModuleTab( "tab_impress", mpImpressRecentThumbnails, TYPE_IMPRESS,
CALC_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SCALC );
setupModuleTab( "tab_draw", mpDrawRecentThumbnails, TYPE_DRAW,
BASE_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SDATABASE );
setupModuleTab( "tab_database", mpDatabaseRecentThumbnails, TYPE_DATABASE,
IMPRESS_WIZARD_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SIMPRESS );
setupModuleTab( "tab_math", mpMathRecentThumbnails, TYPE_MATH,
MATH_URL, aFileNewAppsAvailable, aModuleOptions,
SvtModuleOptions::E_SMATH );
// File types for mpAllRecentThumbnails are added in the above calls
// of setupModuleTab. TYPE_OTHER is always added.
mpAllRecentThumbnails->mnFileTypes |= TYPE_OTHER;
mpAllRecentThumbnails->loadRecentDocs();
mpAllRecentThumbnails->ShowTooltips( true );
setupButton( mpWriterButton );
setupButton( mpDrawButton );
setupButton( mpCalcButton );
setupButton( mpDBButton );
setupButton( mpImpressButton );
setupButton( mpMathButton );
setupButton( mpWriterAllButton );
setupButton( mpDrawAllButton );
setupButton( mpCalcAllButton );
setupButton( mpDBAllButton );
setupButton( mpImpressAllButton );
setupButton( mpMathAllButton );
setupButton( mpOpenButton );
setupButton( mpOpenWriterButton );
setupButton( mpOpenCalcButton );
setupButton( mpOpenImpressButton );
setupButton( mpOpenDrawButton );
setupButton( mpOpenDatabaseButton );
setupButton( mpOpenMathButton );
setupButton( mpTemplateButton );
setupButton( mpTemplateWriterButton );
setupButton( mpTemplateCalcButton );
setupButton( mpTemplateImpressButton );
setupButton( mpTemplateDrawButton );
setupButton( mpTemplateDatabaseButton );
setupButton( mpTemplateMathButton );
setupTemplateView( mpWriterTemplateThumbnails, FILTER_APP_WRITER,
mpWriterShowRecentButton, mpWriterShowTemplateButton );
setupTemplateView( mpCalcTemplateThumbnails, FILTER_APP_CALC,
mpCalcShowRecentButton, mpCalcShowTemplateButton );
setupTemplateView( mpImpressTemplateThumbnails, FILTER_APP_IMPRESS,
mpImpressShowRecentButton, mpImpressShowTemplateButton );
setupTemplateView( mpDrawTemplateThumbnails, FILTER_APP_DRAW,
mpDrawShowRecentButton, mpDrawShowTemplateButton );
Resize();
}
void BackingWindow::setupModuleTab(const OString& rTabName, RecentDocsView* pRecView, int nFileTypes,
const OUString &rURL, const std::set<OUString>& rURLS, SvtModuleOptions& rOpt,
SvtModuleOptions::EModule eMod)
{
if( !rURL.isEmpty() && (!rOpt.IsModuleInstalled( eMod ) || rURLS.find( rURL ) == rURLS.end()) )
{
// disable the parts that are not installed
mpModuleNotebook->RemovePage( mpModuleNotebook->GetPageId(rTabName) );
}
else
{
// if a module is installed, add that filetype to the "All" page
mpAllRecentThumbnails-> mnFileTypes |= nFileTypes;
pRecView->mnFileTypes |= nFileTypes;
pRecView->loadRecentDocs();
pRecView->ShowTooltips( true );
}
}
void BackingWindow::setupButton( PushButton* pButton )
{
pButton->SetClickHdl( LINK( this, BackingWindow, ClickHdl ) );
}
void BackingWindow::setupTemplateView( TemplateLocalView* pView, FILTER_APPLICATION eFilter,
PushButton* pRecentButton, PushButton* pTemplateButton )
{
// setup view
pView->SetStyle(pView->GetStyle() | WB_VSCROLL);
pView->setItemMaxTextLength(nTemplateItemMaxTextLength);
pView->setItemDimensions(nTemplateItemMaxWidth, nTemplateItemThumbnailMaxHeight,
nTemplateItemMaxHeight-nTemplateItemThumbnailMaxHeight,
nTemplateItemPadding);
pView->filterItems(ViewFilter_Application(eFilter));
pView->Populate();
pView->Hide(); // hidden by default
pView->showRootRegion();
pView->setOpenTemplateHdl( LINK( this, BackingWindow, OpenTemplateHdl ) );
// setup buttons
pRecentButton->SetClickHdl( LINK( this, BackingWindow, RecentTemplateToggleHdl ) );
pTemplateButton->SetClickHdl( LINK( this, BackingWindow, RecentTemplateToggleHdl ) );
pRecentButton->Hide(); // hidden by default
}
void BackingWindow::Paint( const Rectangle& )
{
Resize();
Wallpaper aBack( svtools::ColorConfig().GetColorValue(::svtools::APPBACKGROUND).nColor );
Region aClip( Rectangle( Point( 0, 0 ), GetOutputSizePixel() ) );
aClip.Exclude( maStartCentButtons );
Push( PUSH_CLIPREGION );
IntersectClipRegion( aClip );
DrawWallpaper( Rectangle( Point( 0, 0 ), GetOutputSizePixel() ), aBack );
Pop();
VirtualDevice aDev( *this );
aDev.EnableRTL( IsRTLEnabled() );
aDev.SetOutputSizePixel( maStartCentButtons.GetSize() );
Point aOffset( Point( 0, 0 ) - maStartCentButtons.TopLeft());
aDev.DrawWallpaper( Rectangle( aOffset, GetOutputSizePixel() ), aBack );
DrawOutDev( maStartCentButtons.TopLeft(), maStartCentButtons.GetSize(),
Point( 0, 0 ), maStartCentButtons.GetSize(),
aDev );
}
long BackingWindow::Notify( NotifyEvent& rNEvt )
{
if( rNEvt.GetType() == EVENT_KEYINPUT )
{
// try the 'normal' accelerators (so that eg. Ctrl+Q works)
if( !mpAccExec )
{
mpAccExec = svt::AcceleratorExecute::createAcceleratorHelper();
mpAccExec->init( comphelper::getProcessComponentContext(), mxFrame);
}
const KeyEvent* pEvt = rNEvt.GetKeyEvent();
const KeyCode& rKeyCode(pEvt->GetKeyCode());
if( pEvt && mpAccExec->execute(rKeyCode) )
return 1;
}
return Window::Notify( rNEvt );
}
void BackingWindow::setOwningFrame( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& xFrame )
{
mxFrame = xFrame;
if( ! mbInitControls )
initControls();
// establish drag&drop mode
mxDropTargetListener.set(new OpenFileDropTargetListener(mxContext, mxFrame));
for (std::vector<Window*>::iterator aI = maDndWindows.begin(),
aEnd = maDndWindows.end(); aI != aEnd; ++aI)
{
Window *pDndWin = *aI;
css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget =
pDndWin->GetDropTarget();
if (xDropTarget.is())
{
xDropTarget->addDropTargetListener(mxDropTargetListener);
xDropTarget->setActive(true);
}
}
}
void BackingWindow::Resize()
{
maStartCentButtons = Rectangle( Point(0, 0), GetOutputSizePixel() );
if (isLayoutEnabled(this))
VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD),
maStartCentButtons.TopLeft(), maStartCentButtons.GetSize());
if( !IsInPaint())
Invalidate();
}
IMPL_LINK( BackingWindow, ClickHdl, Button*, pButton )
{
// dispatch the appropriate URL and end the dialog
if( pButton == mpWriterButton || pButton == mpWriterAllButton )
dispatchURL( WRITER_URL );
else if( pButton == mpCalcButton || pButton == mpCalcAllButton )
dispatchURL( CALC_URL );
else if( pButton == mpImpressButton || pButton == mpImpressAllButton )
dispatchURL( IMPRESS_WIZARD_URL );
else if( pButton == mpDrawButton || pButton == mpDrawAllButton )
dispatchURL( DRAW_URL );
else if( pButton == mpDBButton || pButton == mpDBAllButton )
dispatchURL( BASE_URL );
else if( pButton == mpMathButton || pButton == mpMathAllButton )
dispatchURL( MATH_URL );
else if( pButton == mpOpenButton ||
pButton == mpOpenWriterButton || pButton == mpOpenCalcButton ||
pButton == mpOpenImpressButton || pButton == mpOpenDrawButton ||
pButton == mpOpenDatabaseButton || pButton == mpOpenMathButton )
{
Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
PropertyValue* pArg = aArgs.getArray();
pArg[0].Name = "Referer";
pArg[0].Value <<= OUString("private:user");
dispatchURL( OPEN_URL, OUString(), xFrame, aArgs );
}
else if( pButton == mpTemplateButton ||
pButton == mpTemplateWriterButton || pButton == mpTemplateCalcButton ||
pButton == mpTemplateImpressButton || pButton == mpTemplateDrawButton ||
pButton == mpTemplateDatabaseButton || pButton == mpTemplateMathButton )
{
Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
Sequence< com::sun::star::beans::PropertyValue > aArgs(1);
PropertyValue* pArg = aArgs.getArray();
pArg[0].Name = OUString("Referer");
pArg[0].Value <<= OUString("private:user");
dispatchURL( TEMPLATE_URL, OUString(), xFrame, aArgs );
}
return 0;
}
IMPL_LINK( BackingWindow, RecentTemplateToggleHdl, Button*, pButton )
{
// writer
if( pButton == mpWriterShowTemplateButton )
{
mpWriterRecentThumbnails->Hide();
mpWriterShowTemplateButton->Hide();
mpWriterTemplateThumbnails->Show();
mpWriterShowRecentButton->Show();
mpWriterShowRecentButton->GrabFocus();
}
else if( pButton == mpWriterShowRecentButton )
{
mpWriterTemplateThumbnails->Hide();
mpWriterShowRecentButton->Hide();
mpWriterRecentThumbnails->Show();
mpWriterShowTemplateButton->Show();
mpWriterShowTemplateButton->GrabFocus();
}
// calc
else if( pButton == mpCalcShowTemplateButton )
{
mpCalcRecentThumbnails->Hide();
mpCalcShowTemplateButton->Hide();
mpCalcTemplateThumbnails->Show();
mpCalcShowRecentButton->Show();
mpCalcShowRecentButton->GrabFocus();
}
else if( pButton == mpCalcShowRecentButton )
{
mpCalcTemplateThumbnails->Hide();
mpCalcShowRecentButton->Hide();
mpCalcRecentThumbnails->Show();
mpCalcShowTemplateButton->Show();
mpCalcShowTemplateButton->GrabFocus();
}
// impress
else if( pButton == mpImpressShowTemplateButton )
{
mpImpressRecentThumbnails->Hide();
mpImpressShowTemplateButton->Hide();
mpImpressTemplateThumbnails->Show();
mpImpressShowRecentButton->Show();
mpImpressShowRecentButton->GrabFocus();
}
else if( pButton == mpImpressShowRecentButton )
{
mpImpressTemplateThumbnails->Hide();
mpImpressShowRecentButton->Hide();
mpImpressRecentThumbnails->Show();
mpImpressShowTemplateButton->Show();
mpImpressShowTemplateButton->GrabFocus();
}
// draw
else if( pButton == mpDrawShowTemplateButton )
{
mpDrawRecentThumbnails->Hide();
mpDrawShowTemplateButton->Hide();
mpDrawTemplateThumbnails->Show();
mpDrawShowRecentButton->Show();
mpDrawShowRecentButton->GrabFocus();
}
else if( pButton == mpDrawShowRecentButton )
{
mpDrawTemplateThumbnails->Hide();
mpDrawShowRecentButton->Hide();
mpDrawRecentThumbnails->Show();
mpDrawShowTemplateButton->Show();
mpDrawShowTemplateButton->GrabFocus();
}
return 0;
}
IMPL_LINK( BackingWindow, OpenTemplateHdl, ThumbnailViewItem*, pItem)
{
uno::Sequence< PropertyValue > aArgs(4);
aArgs[0].Name = "AsTemplate";
aArgs[0].Value <<= sal_True;
aArgs[1].Name = "MacroExecutionMode";
aArgs[1].Value <<= MacroExecMode::USE_CONFIG;
aArgs[2].Name = "UpdateDocMode";
aArgs[2].Value <<= UpdateDocMode::ACCORDING_TO_CONFIG;
aArgs[3].Name = "InteractionHandler";
aArgs[3].Value <<= task::InteractionHandler::createWithParent( ::comphelper::getProcessComponentContext(), 0 );
TemplateViewItem *pTemplateItem = static_cast<TemplateViewItem*>(pItem);
try
{
mxDesktop->loadComponentFromURL(pTemplateItem->getPath(),"_default", 0, aArgs );
}
catch( const uno::Exception& )
{
}
return 0;
}
struct ImplDelayedDispatch
{
Reference< XDispatch > xDispatch;
com::sun::star::util::URL aDispatchURL;
Sequence< PropertyValue > aArgs;
ImplDelayedDispatch( const Reference< XDispatch >& i_xDispatch,
const com::sun::star::util::URL& i_rURL,
const Sequence< PropertyValue >& i_rArgs )
: xDispatch( i_xDispatch ),
aDispatchURL( i_rURL ),
aArgs( i_rArgs )
{
}
~ImplDelayedDispatch() {}
};
static long implDispatchDelayed( void*, void* pArg )
{
struct ImplDelayedDispatch* pDispatch = reinterpret_cast<ImplDelayedDispatch*>(pArg);
try
{
pDispatch->xDispatch->dispatch( pDispatch->aDispatchURL, pDispatch->aArgs );
}
catch (const Exception&)
{
}
// clean up
delete pDispatch;
return 0;
}
void BackingWindow::dispatchURL( const OUString& i_rURL,
const OUString& rTarget,
const Reference< XDispatchProvider >& i_xProv,
const Sequence< PropertyValue >& i_rArgs )
{
// if no special dispatch provider is given, get the desktop
Reference< XDispatchProvider > xProvider( i_xProv.is() ? i_xProv : mxDesktopDispatchProvider );
// check for dispatch provider
if( !xProvider.is())
return;
// get an URL transformer to clean up the URL
com::sun::star::util::URL aDispatchURL;
aDispatchURL.Complete = i_rURL;
Reference < com::sun::star::util::XURLTransformer > xURLTransformer(
com::sun::star::util::URLTransformer::create( comphelper::getProcessComponentContext() ) );
try
{
// clean up the URL
xURLTransformer->parseStrict( aDispatchURL );
// get a Dispatch for the URL and target
Reference< XDispatch > xDispatch(
xProvider->queryDispatch( aDispatchURL, rTarget, 0 )
);
// dispatch the URL
if ( xDispatch.is() )
{
ImplDelayedDispatch* pDisp = new ImplDelayedDispatch( xDispatch, aDispatchURL, i_rArgs );
sal_uLong nEventId = 0;
if( ! Application::PostUserEvent( nEventId, Link( NULL, implDispatchDelayed ), pDisp ) )
delete pDisp; // event could not be posted for unknown reason, at least don't leak
}
}
catch (const com::sun::star::uno::RuntimeException&)
{
throw;
}
catch (const com::sun::star::uno::Exception&)
{
}
}
Size BackingWindow::GetOptimalSize() const
{
if (isLayoutEnabled(this))
return VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
return Window::GetOptimalSize();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab:*/
|