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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: fuinsert.cxx,v $
* $Revision: 1.48 $
*
* 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.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"
#include "fuinsert.hxx"
#include <comphelper/storagehelper.hxx>
#include <comphelper/processfactory.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <svx/svxdlg.hxx>
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <tools/urlobj.hxx>
#include <svl/urihelper.hxx>
#include <svtools/sores.hxx>
#include <svtools/insdlg.hxx>
#include <sfx2/request.hxx>
#include <svl/globalnameitem.hxx>
#include <unotools/pathoptions.hxx>
#include <svx/pfiledlg.hxx>
#include <svx/impgrf.hxx>
#include <svx/dialogs.hrc>
#include <svx/linkmgr.hxx>
#include <svx/svdetc.hxx>
#include <avmedia/mediawindow.hxx>
#ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
#include <unotools/ucbstreamhelper.hxx>
#endif
#include <sfx2/printer.hxx>
#include <sot/clsids.hxx>
#include <svtools/sfxecode.hxx>
#include <svtools/transfer.hxx>
#include <svl/urlbmk.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdomedia.hxx>
#ifndef _EDITENG_HXX //autogen
#include <svx/editeng.hxx>
#endif
#include <sot/storage.hxx>
#include <sot/formats.hxx>
#include <svx/svdpagv.hxx>
#ifndef _MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#include <svx/opengrf.hxx>
#include <sfx2/viewfrm.hxx>
#include "app.hrc"
#include "misc.hxx"
#include "sdresid.hxx"
#include "View.hxx"
#include "app.hxx"
#include "Window.hxx"
#include "drawview.hxx"
#include "DrawViewShell.hxx"
#include "DrawDocShell.hxx"
#include "GraphicDocShell.hxx"
#include "strings.hrc"
#include "drawdoc.hxx"
#include "sdgrffilter.hxx"
#include "sdxfer.hxx"
#include <vcl/svapp.hxx>
#include "undo/undoobjects.hxx"
using namespace com::sun::star;
namespace sd {
TYPEINIT1( FuInsertGraphic, FuPoor );
TYPEINIT1( FuInsertClipboard, FuPoor );
TYPEINIT1( FuInsertOLE, FuPoor );
TYPEINIT1( FuInsertAVMedia, FuPoor );
/*************************************************************************
|*
|* FuInsertGraphic::Konstruktor
|*
\************************************************************************/
FuInsertGraphic::FuInsertGraphic (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
FunctionReference FuInsertGraphic::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
FunctionReference xFunc( new FuInsertGraphic( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
#ifdef _MSC_VER
#pragma optimize ( "", off )
#endif
void FuInsertGraphic::DoExecute( SfxRequest& )
{
SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC));
if( aDlg.Execute() == GRFILTER_OK )
{
Graphic aGraphic;
int nError = aDlg.GetGraphic(aGraphic);
if( nError == GRFILTER_OK )
{
if( mpViewShell && mpViewShell->ISA(DrawViewShell))
{
sal_Int8 nAction = DND_ACTION_COPY;
SdrObject* pPickObj = mpView->GetEmptyPresentationObject( PRESOBJ_GRAPHIC );
if( pPickObj )
nAction = DND_ACTION_LINK;
Point aPos;
Rectangle aRect(aPos, mpWindow->GetOutputSizePixel() );
aPos = aRect.Center();
aPos = mpWindow->PixelToLogic(aPos);
SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, NULL);
if(pGrafObj && aDlg.IsAsLink())
{
// store link only?
String aFltName(aDlg.GetCurrentFilter());
String aPath(aDlg.GetPath());
pGrafObj->SetGraphicLink(aPath, aFltName);
}
}
}
else
{
SdGRFFilter::HandleGraphicFilterError( (USHORT)nError, GetGrfFilter()->GetLastError().nStreamError );
}
}
}
#ifdef _MSC_VER
#pragma optimize ( "", on )
#endif
/*************************************************************************
|*
|* FuInsertClipboard::Konstruktor
|*
\************************************************************************/
FuInsertClipboard::FuInsertClipboard (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
FunctionReference FuInsertClipboard::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
FunctionReference xFunc( new FuInsertClipboard( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
void FuInsertClipboard::DoExecute( SfxRequest& )
{
TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mpWindow ) );
ULONG nFormatId;
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( mpViewShell->GetActiveWindow() );
if ( pDlg )
{
const String aEmptyString;
::com::sun::star::datatransfer::DataFlavor aFlavor;
pDlg->Insert( SOT_FORMATSTR_ID_EMBED_SOURCE, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_LINK_SOURCE, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_DRAWING, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_SVXB, aEmptyString );
pDlg->Insert( FORMAT_GDIMETAFILE, aEmptyString );
pDlg->Insert( FORMAT_BITMAP, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aEmptyString );
pDlg->Insert( FORMAT_STRING, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_HTML, aEmptyString );
pDlg->Insert( FORMAT_RTF, aEmptyString );
pDlg->Insert( SOT_FORMATSTR_ID_EDITENGINE, aEmptyString );
//TODO/MBA: testing
nFormatId = pDlg->GetFormat( aDataHelper );
if( nFormatId && aDataHelper.GetTransferable().is() )
{
sal_Int8 nAction = DND_ACTION_COPY;
if( !mpView->InsertData( aDataHelper,
mpWindow->PixelToLogic( Rectangle( Point(), mpWindow->GetOutputSizePixel() ).Center() ),
nAction, FALSE, nFormatId ) &&
( mpViewShell && mpViewShell->ISA( DrawViewShell ) ) )
{
DrawViewShell* pDrViewSh = static_cast<DrawViewShell*>(mpViewShell);
INetBookmark aINetBookmark( aEmptyStr, aEmptyStr );
if( ( aDataHelper.HasFormat( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ) &&
aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark ) ) ||
( aDataHelper.HasFormat( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) &&
aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR, aINetBookmark ) ) ||
( aDataHelper.HasFormat( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) &&
aDataHelper.GetINetBookmark( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR, aINetBookmark ) ) )
{
pDrViewSh->InsertURLField( aINetBookmark.GetURL(), aINetBookmark.GetDescription(), aEmptyStr, NULL );
}
}
}
delete pDlg;
}
}
/*************************************************************************
|*
|* FuInsertOLE::Konstruktor
|*
\************************************************************************/
FuInsertOLE::FuInsertOLE (
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
FunctionReference FuInsertOLE::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
FunctionReference xFunc( new FuInsertOLE( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
void FuInsertOLE::DoExecute( SfxRequest& rReq )
{
if ( nSlotId == SID_ATTR_TABLE ||
nSlotId == SID_INSERT_DIAGRAM ||
nSlotId == SID_INSERT_MATH )
{
PresObjKind ePresObjKind = (nSlotId == SID_INSERT_DIAGRAM) ? PRESOBJ_CHART : PRESOBJ_OBJECT;
SdrObject* pPickObj = mpView->GetEmptyPresentationObject( ePresObjKind );
/**********************************************************************
* Diagramm oder StarCalc-Tabelle einfuegen
**********************************************************************/
::rtl::OUString aObjName;
SvGlobalName aName;
if (nSlotId == SID_INSERT_DIAGRAM)
aName = SvGlobalName( SO3_SCH_CLASSID);
else if (nSlotId == SID_ATTR_TABLE)
aName = SvGlobalName(SO3_SC_CLASSID);
else if (nSlotId == SID_INSERT_MATH)
aName = SvGlobalName(SO3_SM_CLASSID);
uno::Reference < embed::XEmbeddedObject > xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
GetEmbeddedObjectContainer().CreateEmbeddedObject( aName.GetByteSequence(), aObjName );
if ( xObj.is() )
{
sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
Rectangle aRect;
if( pPickObj )
{
aRect = pPickObj->GetLogicRect();
awt::Size aSz;
aSz.Width = aRect.GetWidth();
aSz.Height = aRect.GetHeight();
xObj->setVisualAreaSize( nAspect, aSz );
}
else
{
awt::Size aSz;
try
{
aSz = xObj->getVisualAreaSize( nAspect );
}
catch ( embed::NoVisualAreaSizeException& )
{
// the default size will be set later
}
Size aSize( aSz.Width, aSz.Height );
if (aSize.Height() == 0 || aSize.Width() == 0)
{
// Rechteck mit ausgewogenem Kantenverhaeltnis
aSize.Width() = 14100;
aSize.Height() = 10000;
Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aUnit );
aSz.Width = aTmp.Width();
aSz.Height = aTmp.Height();
xObj->setVisualAreaSize( nAspect, aSz );
}
else
{
aSize = OutputDevice::LogicToLogic(aSize, aUnit, MAP_100TH_MM);
}
Point aPos;
Rectangle aWinRect(aPos, mpWindow->GetOutputSizePixel() );
aPos = aWinRect.Center();
aPos = mpWindow->PixelToLogic(aPos);
aPos.X() -= aSize.Width() / 2;
aPos.Y() -= aSize.Height() / 2;
aRect = Rectangle(aPos, aSize);
}
SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
SdrPageView* pPV = mpView->GetSdrPageView();
// if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
if( pPickObj )
{
SdPage* pPage = static_cast< SdPage* >(pPickObj->GetPage());
if(pPage && pPage->IsPresObj(pPickObj))
{
pPage->InsertPresObj( pOleObj, ePresObjKind );
pOleObj->SetUserCall(pPickObj->GetUserCall());
}
}
bool bRet = true;
if( pPickObj )
mpView->ReplaceObjectAtView(pPickObj, *pPV, pOleObj, TRUE );
else
bRet = mpView->InsertObjectAtView(pOleObj, *pPV, SDRINSERT_SETDEFLAYER);
if( bRet )
{
if (nSlotId == SID_INSERT_DIAGRAM)
{
pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarChart" ) ) );
}
else if (nSlotId == SID_ATTR_TABLE)
{
pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarCalc" ) ) );
}
else if (nSlotId == SID_INSERT_MATH)
{
pOleObj->SetProgName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarMath" ) ) );
}
//HMHmpView->HideMarkHdl();
pOleObj->SetLogicRect(aRect);
Size aTmp( OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aUnit ) );
awt::Size aVisualSize;
aVisualSize.Width = aTmp.Width();
aVisualSize.Height = aTmp.Height();
xObj->setVisualAreaSize( nAspect, aVisualSize );
mpViewShell->ActivateObject(pOleObj, SVVERB_SHOW);
if (nSlotId == SID_INSERT_DIAGRAM)
{
// note, that this call modified the chart model which
// results in a change notification. So call this after
// everything else is finished.
mpViewShell->AdaptDefaultsForChart( xObj );
}
}
}
else
{
ErrorHandler::HandleError(* new StringErrorInfo(ERRCODE_SFX_OLEGENERAL,
aEmptyStr ) );
}
}
else
{
/**********************************************************************
* Objekt einfuegen
**********************************************************************/
sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
BOOL bCreateNew = FALSE;
uno::Reference < embed::XEmbeddedObject > xObj;
uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
SvObjectServerList aServerLst;
::rtl::OUString aName;
::rtl::OUString aIconMediaType;
uno::Reference< io::XInputStream > xIconMetaFile;
SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
if ( nSlotId == SID_INSERT_OBJECT && pNameItem )
{
SvGlobalName aClassName = pNameItem->GetValue();
xObj = mpViewShell->GetViewFrame()->GetObjectShell()->
GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
}
else
{
switch ( nSlotId )
{
case SID_INSERT_OBJECT :
{
aServerLst.FillInsertObjects();
if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW)
{
aServerLst.Remove( GraphicDocShell::Factory().GetClassId() );
}
else
{
aServerLst.Remove( DrawDocShell::Factory().GetClassId() );
}
// intentionally no break!
}
case SID_INSERT_PLUGIN :
case SID_INSERT_APPLET :
case SID_INSERT_FLOATINGFRAME :
{
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
SfxAbstractInsertObjectDialog* pDlg =
pFact->CreateInsertObjectDialog( mpViewShell->GetActiveWindow(), nSlotId,
xStorage, &aServerLst );
if ( pDlg )
{
pDlg->Execute();
bCreateNew = pDlg->IsCreateNew();
xObj = pDlg->GetObject();
xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
if ( xIconMetaFile.is() )
nAspect = embed::Aspects::MSOLE_ICON;
if ( xObj.is() )
mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
DELETEZ( pDlg );
}
break;
}
case SID_INSERT_SOUND :
case SID_INSERT_VIDEO :
{
// create special filedialog for plugins
SvxPluginFileDlg aPluginFileDialog (mpWindow, nSlotId);
if( ERRCODE_NONE == aPluginFileDialog.Execute () )
{
// get URL
String aStrURL(aPluginFileDialog.GetPath());
INetURLObject aURL( aStrURL, INET_PROT_FILE );
if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
{
// create a plugin object
xObj = mpViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_PLUGIN_CLASSID ).GetByteSequence(), aName );
}
if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
{
// set properties from dialog
uno::Reference < embed::XComponentSupplier > xSup( xObj, uno::UNO_QUERY );
if ( xSup.is() )
{
uno::Reference < beans::XPropertySet > xSet( xSup->getComponent(), uno::UNO_QUERY );
if ( xSet.is() )
{
xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
}
}
}
else
{
// PlugIn konnte nicht erzeugt werden
String aStrErr( SdResId( STR_ERROR_OBJNOCREATE_PLUGIN ) );
String aMask;
aMask += sal_Unicode('%');
aStrErr.SearchAndReplace( aMask, aStrURL );
ErrorBox( mpWindow, WB_3DLOOK | WB_OK, aStrErr ).Execute();
}
}
}
}
}
try
{
if (xObj.is())
{
//TODO/LATER: needs status for RESIZEONPRINTERCHANGE
//if( SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE & xObj->getStatus( nAspect ) )
// aIPObj->OnDocumentPrinterChanged( mpDocSh->GetPrinter(FALSE) );
BOOL bInsertNewObject = TRUE;
Size aSize;
MapUnit aMapUnit = MAP_100TH_MM;
if ( nAspect != embed::Aspects::MSOLE_ICON )
{
awt::Size aSz;
try
{
aSz = xObj->getVisualAreaSize( nAspect );
}
catch( embed::NoVisualAreaSizeException& )
{
// the default size will be set later
}
aSize =Size( aSz.Width, aSz.Height );
aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
if (aSize.Height() == 0 || aSize.Width() == 0)
{
// Rechteck mit ausgewogenem Kantenverhaeltnis
aSize.Width() = 14100;
aSize.Height() = 10000;
Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
aSz.Width = aTmp.Width();
aSz.Height = aTmp.Height();
xObj->setVisualAreaSize( nAspect, aSz );
}
else
{
aSize = OutputDevice::LogicToLogic(aSize, aMapUnit, MAP_100TH_MM);
}
}
if ( mpView->AreObjectsMarked() )
{
/**********************************************************
* Ist ein leeres OLE-Objekt vorhanden?
**********************************************************/
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1)
{
SdrMark* pMark = rMarkList.GetMark(0);
SdrObject* pObj = pMark->GetMarkedSdrObj();
if (pObj->GetObjInventor() == SdrInventor &&
pObj->GetObjIdentifier() == OBJ_OLE2)
{
if ( !( (SdrOle2Obj*) pObj)->GetObjRef().is() )
{
/**************************************************
* Das leere OLE-Objekt bekommt ein neues IPObj
**************************************************/
bInsertNewObject = FALSE;
pObj->SetEmptyPresObj(FALSE);
( (SdrOle2Obj*) pObj)->SetOutlinerParaObject(NULL);
( (SdrOle2Obj*) pObj)->SetObjRef(xObj);
( (SdrOle2Obj*) pObj)->SetPersistName(aName);
( (SdrOle2Obj*) pObj)->SetName(aName);
( (SdrOle2Obj*) pObj)->SetAspect(nAspect);
Rectangle aRect = ( (SdrOle2Obj*) pObj)->GetLogicRect();
//HMHmpView->HideMarkHdl();
if ( nAspect == embed::Aspects::MSOLE_ICON )
{
if( xIconMetaFile.is() )
( (SdrOle2Obj*) pObj)->SetGraphicToObj( xIconMetaFile, aIconMediaType );
}
else
{
Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
awt::Size aSz( aTmp.Width(), aTmp.Height() );
xObj->setVisualAreaSize( nAspect, aSz );
}
}
}
}
}
if (bInsertNewObject)
{
/**************************************************************
* Ein neues OLE-Objekt wird erzeugt
**************************************************************/
SdrPageView* pPV = mpView->GetSdrPageView();
Size aPageSize = pPV->GetPage()->GetSize();
// get the size from the iconified object
::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
if ( nAspect == embed::Aspects::MSOLE_ICON )
{
aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
MapMode aMapMode( MAP_100TH_MM );
aSize = aObjRef.GetSize( &aMapMode );
}
Point aPnt ((aPageSize.Width() - aSize.Width()) / 2,
(aPageSize.Height() - aSize.Height()) / 2);
Rectangle aRect (aPnt, aSize);
SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
if( mpView->InsertObjectAtView(pObj, *pPV, SDRINSERT_SETDEFLAYER) )
{
// #73279# Math objects change their object size during InsertObject.
// New size must be set in SdrObject, or a wrong scale will be set at
// ActivateObject.
if ( nAspect != embed::Aspects::MSOLE_ICON )
{
try
{
awt::Size aSz = xObj->getVisualAreaSize( nAspect );
Size aNewSize = Window::LogicToLogic( Size( aSz.Width, aSz.Height ),
MapMode( aMapUnit ), MapMode( MAP_100TH_MM ) );
if ( aNewSize != aSize )
{
aRect.SetSize( aNewSize );
pObj->SetLogicRect( aRect );
}
}
catch( embed::NoVisualAreaSizeException& )
{}
}
if (bCreateNew)
{
//HMHmpView->HideMarkHdl();
pObj->SetLogicRect(aRect);
if ( nAspect != embed::Aspects::MSOLE_ICON )
{
Size aTmp = OutputDevice::LogicToLogic( aRect.GetSize(), MAP_100TH_MM, aMapUnit );
awt::Size aSz( aTmp.Width(), aTmp.Height() );
xObj->setVisualAreaSize( nAspect, aSz );
}
mpViewShell->ActivateObject(pObj, SVVERB_SHOW);
}
Size aVisSizePixel = mpWindow->GetOutputSizePixel();
Rectangle aVisAreaWin = mpWindow->PixelToLogic( Rectangle( Point(0,0), aVisSizePixel) );
mpViewShell->VisAreaChanged(aVisAreaWin);
mpDocSh->SetVisArea(aVisAreaWin);
}
}
}
}
catch (uno::Exception&)
{
// For some reason the object can not be inserted. For example
// because it is password protected and is not properly unlocked.
}
}
}
/*************************************************************************
|*
|* FuInsertAVMedia::Konstruktor
|*
\************************************************************************/
FuInsertAVMedia::FuInsertAVMedia(
ViewShell* pViewSh,
::sd::Window* pWin,
::sd::View* pView,
SdDrawDocument* pDoc,
SfxRequest& rReq)
: FuPoor(pViewSh, pWin, pView, pDoc, rReq)
{
}
FunctionReference FuInsertAVMedia::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
FunctionReference xFunc( new FuInsertAVMedia( pViewSh, pWin, pView, pDoc, rReq ) );
xFunc->DoExecute(rReq);
return xFunc;
}
void FuInsertAVMedia::DoExecute( SfxRequest& rReq )
{
::rtl::OUString aURL;
const SfxItemSet* pReqArgs = rReq.GetArgs();
bool bAPI = false;
if( pReqArgs )
{
const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, &pReqArgs->Get( rReq.GetSlot() ) );
if( pStringItem )
{
aURL = pStringItem->GetValue();
bAPI = aURL.getLength();
}
}
if( bAPI || ::avmedia::MediaWindow::executeMediaURLDialog( mpWindow, aURL ) )
{
Size aPrefSize;
if( mpWindow )
mpWindow->EnterWait();
if( !::avmedia::MediaWindow::isMediaURL( aURL, true, &aPrefSize ) )
{
if( mpWindow )
mpWindow->LeaveWait();
if( !bAPI )
::avmedia::MediaWindow::executeFormatErrorBox( mpWindow );
}
else
{
Point aPos;
Size aSize;
sal_Int8 nAction = DND_ACTION_COPY;
if( aPrefSize.Width() && aPrefSize.Height() )
{
if( mpWindow )
aSize = mpWindow->PixelToLogic( aPrefSize, MAP_100TH_MM );
else
aSize = Application::GetDefaultDevice()->PixelToLogic( aPrefSize, MAP_100TH_MM );
}
else
aSize = Size( 5000, 5000 );
if( mpWindow )
{
aPos = mpWindow->PixelToLogic( Rectangle( aPos, mpWindow->GetOutputSizePixel() ).Center() );
aPos.X() -= aSize.Width() >> 1;
aPos.Y() -= aSize.Height() >> 1;
}
mpView->InsertMediaURL( aURL, nAction, aPos, aSize ) ;
if( mpWindow )
mpWindow->LeaveWait();
}
}
}
} // end of namespace sd
|