summaryrefslogtreecommitdiffstats
path: root/binfilter/bf_so3/source/inplace/plugin.cxx
blob: 4ef1d62133c8fb0d46c74d7168d74cf4b44527ea (plain)
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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
/* -*- 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 <ctype.h>
#include <stdio.h>

#include <vcl/bitmap.hxx>
#include "bf_so3/plugin.hxx"
#include <comphelper/classids.hxx>
#include <sot/exchange.hxx>
#include <vcl/svapp.hxx>
#include <vcl/stdtext.hxx>
#include <tools/debug.hxx>
#include <comphelper/processfactory.hxx>

#include "bf_so3/ipclient.hxx"
#include <bf_so3/svstor.hxx>
#include "bf_so3/ipwin.hxx"
#include <svuidlg.hrc>
#include <tools/urlobj.hxx>
#include "bf_so3/soerr.hxx"
#include "bf_so3/staticbaseurl.hxx"

#define SoResId( id )   ResId( id, *SOAPP->GetResMgr() )

#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/plugin/PluginMode.hpp>
#include <com/sun/star/plugin/XPlugin.hpp>
#include <com/sun/star/plugin/XPluginManager.hpp>

using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::plugin;

using ::rtl::OUString;
using ::rtl::OUStringToOString;

namespace binfilter {

class SvPlugInEnvironment_Impl
{
public:
    Reference< XPlugin >    _xPlugin;
    String                  _aMimeType;
};

//=========================================================================
SvPlugInEnvironment::SvPlugInEnvironment
(
    SvContainerEnvironment * pFrm,  /* Das Callback Gegenst"uck zum
                                       InPlace-Environment */
    SvPlugInObject * pObjP          /* Das zum Environment geh"orende
                                       Objekt */
)
    : SvInPlaceEnvironment( pFrm, pObjP )
    , pObj( pObjP )
    , pImpl( new SvPlugInEnvironment_Impl )
/*  [Beschreibung]

    Das Environment wird im <SvPlugInObject::InPlaceActivate()> angelegt.
    Durch die Verbindung mit dem Container Environment kann "uber die
    UI-Tools und Fenster verhandelt werden.

    [Querverweise]

    <SvInPlaceEnvironment>, <SvContainerEnvironment>
*/
{
    // Das Border- und Clip-Window werden erzeugt
    MakeWindows();
    SvInPlaceWindow * pBW = GetBorderWin();
    pBW->SetHatchBorderPixel( Size() );
}


BOOL SvPlugInEnvironment::MIMETypeDetected( const String& rMIME )
{
    (void)rMIME;

    // obsolete -> should be removed
    return TRUE;
}


//=========================================================================
SvPlugInEnvironment::~SvPlugInEnvironment()
/*  [Beschreibung]

    Die angelegten Fenster werden zerst"ort.
*/
{
    Reference< XComponent > xComp( pImpl->_xPlugin, UNO_QUERY );
    if (xComp.is())
        xComp->dispose();

    // statt DeleteEditWin() auf NULL setzen und durch den Manager
    // zerst"oren
    SetEditWin( NULL );
    DeleteWindows();
    delete pImpl;
}

//=========================================================================
void * SvPlugInEnvironment::GetJavaPeer
(
    Window * //pPlugWin Plugin, zu dem die JavaKlasse besorgt wird
)
{
    return NULL;
}

//=========================================================================
void SvPlugInEnvironment::DocWinResize()
/*  [Beschreibung]

    Ist es ein Full-PlugIn, dann wird das IP-Fenster entsprechend
    der Gr"osse des DocWindows angepasst.

    [Querverweise]

    <SvPlugInEnvironment::RectsChangedPixel()>
*/
{
}

//=========================================================================
void SvPlugInEnvironment::RectsChangedPixel
(
    const Rectangle & rObjRect, /* Position und Gr"osse relativ zum
                                   EditWin des Containers */
    const Rectangle & rClip     /* Clipping des Containers auf das Objekt */
)
/*  [Beschreibung]

    Der Container "andert die Gr"osse oder Position des Objektes. Dies
    wird an das PlugIn gemeldet.

    [Querverweise]

    <SvInPlaceEnvironment::RectsChangedPixel()>
*/
{
    Reference< awt::XWindow > xWindow( pImpl->_xPlugin, UNO_QUERY );
    if (xWindow.is())
        xWindow->setPosSize( 0, 0, rObjRect.getWidth(), rObjRect.getHeight(), WINDOW_POSSIZE_SIZE );
    SvInPlaceEnvironment::RectsChangedPixel( rObjRect, rClip );
}

//=========================================================================
struct SvPlugInData_Impl
/*  [Beschreibung]

    In diesem struct werden sich Member von SvPlugInData gemerkt, um
    nicht immer inkompatibel zu werden.
*/
{
    BOOL                    bRegisterFailed;    /* TRUE, wenn das registrieren
                                                    eines PlugIns nicht klappt */
                SvPlugInData_Impl()
                    : bRegisterFailed( FALSE )
                {}
};

//=========================================================================
//============== SvPlugInObject ===========================================
//=========================================================================
SO2_IMPL_BASIC_CLASS1_DLL( SvPlugInObject, SvFactory, SvInPlaceObject,
              SvGlobalName( SO3_PLUGIN_CLASSID ) )
//                SvGlobalName( 0xc1b5d281, 0x4870, 0x11d0,
//                              0x89, 0xca, 0x0, 0x80, 0x29, 0xe4, 0xb0, 0xb1) )


//=========================================================================
SvPlugInObject::SvPlugInObject()
    : pPlugInEnv( NULL )
    , pImpl( new SvPlugInData_Impl )
    , pURL( NULL )
    , nPlugInMode( PLUGIN_EMBEDED ) // muss noch ge"ndert werden
/*  [Beschreibung]

    Konstruktor der Klasse SvPlugInObject. Die Verbliste und das
    Format werden global initialisiert.
*/
{
    SoDll * pSoApp = SOAPP;
    if( !pSoApp->pPlugInVerbList )
    {
        pSoApp->pPlugInVerbList = new SvVerbList();
        // Alle unterstuetzten Verben anlegen
        pSoApp->pPlugInVerbList->Append(
                SvVerb( 0, SoResId( STR_VERB_OPEN ).toString() ) );
        pSoApp->nPlugInDocFormat =
                SotExchange::RegisterFormatName( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PlugIn Object" ) ) );
    }
    // Verben der Superklasse bekanntgeben, um GetVerbs nicht
    // ueberlagern zu muessen
    SetVerbList( pSoApp->pPlugInVerbList );
}

//=========================================================================
SvPlugInObject::~SvPlugInObject()
/*  [Beschreibung]

    Destruktor der Klasse SvPlugInObject.
*/
{
    delete pURL;
    delete pImpl;
}

BOOL SvPlugInObject::StartPlugIn( )
/*  [Beschreibung]

    Die Methode startet das PlugIn. Es ist notwendig, dass das Objekt
    im InPlace-Active ist.
*/
{
    SvPlugInEnvironment* pEnv = (SvPlugInEnvironment*)GetIPEnv();
    if( !pEnv )
        return FALSE;

    ULONG nCount = aCmdList.Count();
    Sequence< OUString > aCmds( nCount ), aArgs( nCount );
    OUString *pCmds = aCmds.getArray(), *pArgs = aArgs.getArray();
    for( ULONG i = 0; i < nCount; i++ )
    {
        SvCommand & rCmd = aCmdList.GetObject( i );
        pCmds[i] = rCmd.GetCommand();
        pArgs[i] = rCmd.GetArgument();
    }

    Reference< XMultiServiceFactory > xFac( ::comphelper::getProcessServiceFactory() );
    Reference< XPluginManager > xPMgr( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.plugin.PluginManager" )) ), UNO_QUERY );
    if (! xPMgr.is() )
        ShowServiceNotAvailableError( NULL, String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PluginManager" ) ), TRUE );

    SvInPlaceWindow * pBW = pEnv->GetBorderWin();
    DBG_ASSERT( pBW, "### no border window!" );

    INT16 nMode = (PlugInMode)nPlugInMode == PLUGIN_EMBEDED ? PluginMode::EMBED : PluginMode::FULL;
    if (xPMgr.is() && pBW)
    {
        Reference< XPlugin > xPlugin = xPMgr->createPluginFromURL(
            xPMgr->createPluginContext(), nMode, aCmds, aArgs, Reference< awt::XToolkit >(),
            Reference< awt::XWindowPeer >( pBW->GetComponentInterface() ),
            pURL ? pURL->GetMainURL( INetURLObject::NO_DECODE ) : rtl::OUString() );

        if( ! GetIPEnv() )
            return FALSE;
        // Environment can be discarded already by Application::Reschedule

        pEnv->pImpl->_xPlugin = xPlugin;

        if (pEnv->pImpl->_xPlugin.is())
        {
            pEnv->SetEditWin( pBW );
            // Fenster zuordnen (fuers Resize)
            pBW->SetObjWin( pBW );

            Reference< awt::XWindow > xWindow( pEnv->pImpl->_xPlugin, UNO_QUERY );
            if (xWindow.is())
            {
                Size aSize( pBW->GetSizePixel() );
                xWindow->setPosSize( 0, 0, aSize.getWidth(), aSize.getHeight(), WINDOW_POSSIZE_SIZE );
                xWindow->setVisible( TRUE );
            }
            if( ! pURL )
            {
                try
                {
                    Reference< awt::XControl > xControl( pEnv->pImpl->_xPlugin, UNO_QUERY );
                    if( xControl.is() )
                    {
                        Reference< awt::XControlModel > xModel = xControl->getModel();
                        Reference< XPropertySet > xProp( xModel, UNO_QUERY );
                        if( xProp.is() )
                        {
                            Any aValue = xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
                            OUString aVal;
                            aValue >>= aVal;
                            pURL = new INetURLObject( String( aVal ) );
                        }
                    }
                }
                catch(...)
                {
                }
            }
        }
    }

    return !pImpl->bRegisterFailed;
}


//=========================================================================
void SvPlugInObject::DataChanged_Impl
(
    BOOL bOnlyEmbedSource   /* TRUE, es "andert sich nur die persistenten
                               Daten. FALSE, auch das MetaFile "andert
                               sich */
)
/*  [Beschreibung]

    Wenn die Daten sich "andern, muss das Modiy-Flag gesetzt werden.
    Ausserdem m"ussen alle angemeldeten Advises benachrichtigt werden.
    In Abh"angigkeit des Parameters wird angezeigt, dass sich auch
    die View und das Mtf ge"andert hat.
*/
{
    if( IsEnableSetModified() )
    { // nicht im init oder deinit
        SetModified( TRUE );
        if( !bOnlyEmbedSource )
            ViewChanged( ASPECT_CONTENT );
    }
}

//=========================================================================
void SvPlugInObject::FillClass
(
    SvGlobalName * pClassName,  /* Der Typ der Klasse */
    ULONG * pFormat,            /* Das Dateiformat in dem geschrieben wird */
    String * pAppName,          /* Der Applikationsname */
    String * pFullTypeName,     /* Der genaue Name des Typs */
    String * pShortTypeName,    /* Der kurze Name des Typs  */
    long /*nFileFormat*/        /* F"ur dieses Office-Format sollen die
                                   Parameter gef"ullt werden */
) const
/*  [Beschreibung]

    Mit dieser Methode werden Informationen "uber das Objekt angefordert.
    Wird das Objekt gesichert, dann werden diese Informationen in den
    Storage geschrieben.

    [Anmerkung]

    Da diese Information nicht vom PlugIn ermittelt werden kann, m"ussen
    Standardwerte angegeben werden. Dies bedeutet, von aussen gibt es
    nur den Typ PlugIn, in den man nicht hinein schauen kann.
*/
{
    *pClassName     = *GetSvFactory();
    *pFormat        = SOAPP->nPlugInDocFormat;
    *pAppName       = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PlugIn" ) );
    *pFullTypeName  = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PlugIn" ) );
    *pShortTypeName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "PlugIn" ) );
}


//=========================================================================
void SvPlugInObject::Open
(
    BOOL bOpen  /* TRUE, es handelt sich um eine Open.
                   FALSE, es handelt sich um Close. */
)
/*  [Beschreibung]

    Die Verbindung zum Client wird ge"offnet oder geschlossen.

    [Querverweise]

    <SvEmbeddedObject::Open()>
*/
{
    // l"asst Environment los
    SvInPlaceObject::Open( bOpen );
}

//=========================================================================
void SvPlugInObject::Embed
(
    BOOL bEmbed /* TRUE, OutPlace Aktivierung beginnt.
                   FALSE, OutPlace Aktivierung endet. */
)
/*  [Beschreibung]

    Das Objekt wird OutPlace aktiviert oder deaktiviert. Es soll nicht
    aktiviert werden k"onnen. Die Aktivierung wird abgebrochen.

    [Querverweise]

    <SvEmbeddedObject::Embed()>
*/
{
    if( bEmbed )
        DoClose();
}

//=========================================================================
void SvPlugInObject::InPlaceActivate
(
    BOOL bActivate  /* TRUE, InPlace Aktivierung beginnt.
                       FALSE, InPlace Aktivierung endet. */
)
/*  [Beschreibung]

    Das Objekt wird InPlace aktiviert oder deaktiviert.

    [Querverweise]

    <SvInPlaceObject::InPlaceActivate()>
*/
{
    if( bActivate )
    {
        SvContainerEnvironment * pEnv;
        pEnv = GetIPClient()->GetEnv();
        // Wenn schon eines drin sitzt, ist es das des Sfx
        pPlugInEnv = (SvPlugInEnvironment*) GetIPEnv();
        if( !pPlugInEnv )
        {
            pPlugInEnv = new SvPlugInEnvironment( pEnv, this );
            // wird in die Verwaltung eingesetzt
            SetIPEnv( pPlugInEnv );
        }

        StartPlugIn();
    }

    SvInPlaceObject::InPlaceActivate( bActivate );

    if( !bActivate )
    {
        DELETEZ( pPlugInEnv );
        SetIPEnv( pPlugInEnv );
    }
}

//=========================================================================
ErrCode SvPlugInObject::Verb
(
    long                nVerb,      /* welche Art des Aktivierens ist
                                       gew"unscht */
    SvEmbeddedClient *  pCl,        /* Callback-Svhnittstelle des Aufruffers */
    Window *            pWin,       /* Parent auf dem aktiviert werden soll */
    const Rectangle * pWorkRectPixel/* Position und Gr"osse, an der das Objekt
                                       aktiviert werden soll */
)
/*  [Beschreibung]

    Es wird Versucht ein PlugIn zu starten. Es gibt nur die M"oglichkeit
    InPlace zu aktivieren. Deshalb sind auch nur die Verben gestattet,
    die dies ausl"osen.

    [R"uckgabewert]

    ErrCode     ERRCODE_NONE, es wurde InPlace aktiviert.
                ERRCODE_SO_NOT_INPLACEACTIVE, es wurde nicht InPlace
                aktiviert.

    [Querverweise]

    <SvPseudoObject::Verb>
*/
{
    (void)pCl;
    (void)pWin;
    (void)pWorkRectPixel;

    ErrCode nRet = ERRCODE_SO_NOT_INPLACEACTIVE;
    Reference< XMultiServiceFactory > xFac( ::comphelper::getProcessServiceFactory() );
    Sequence< OUString > aNames( xFac->getAvailableServiceNames() );
    const OUString * pNames = aNames.getConstArray();
    INT32 nPos;
    for ( nPos = aNames.getLength(); nPos--; )
    {
        if (pNames[nPos].compareToAscii("com.sun.star.plugin.PluginManager") == 0)
            break;
    }
    if (nPos < 0 || pImpl->bRegisterFailed)
        return nRet;

    switch( nVerb )
    {
        case SVVERB_SHOW:
        case SVVERB_IPACTIVATE:
        case 0L:
            if( PLUGIN_EMBEDED == ((PlugInMode)nPlugInMode) )
                nRet = GetProtocol().IPProtocol();
            else
                nRet = GetProtocol().UIProtocol();
            break;
        case SVVERB_HIDE:
            nRet = DoInPlaceActivate( FALSE );
            break;
    }
    return nRet;
}

//=========================================================================
void SvPlugInObject::SetVisArea
(
    const Rectangle & rVisArea  /* neue Position und Groesse des
                                   sichtbaren Ausschnitts */
)
/*  [Beschreibung]

    Der sichtbare Ausschnitt beginnt immer an der Position (0, 0).
*/
{
    Rectangle aR( rVisArea );
    aR.SetPos( Point() );
    SvInPlaceObject::SetVisArea( aR );

    DataChanged_Impl( TRUE );
}

//=========================================================================
void SoPaintReplacement( const Rectangle &rRect, String &rText,
                         OutputDevice *pOut )
{
    MapMode aMM( MAP_APPFONT );
    Size aAppFontSz = pOut->LogicToLogic( Size( 0, 8 ), &aMM, NULL );
    Font aFnt( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Helvetica" ) ), aAppFontSz );
    aFnt.SetTransparent( TRUE );
    aFnt.SetColor( Color( COL_LIGHTRED ) );
    aFnt.SetWeight( WEIGHT_BOLD );
    aFnt.SetFamily( FAMILY_SWISS );

    pOut->Push();
    pOut->SetBackground();
    pOut->SetFont( aFnt );

    Point aPt;
    // Nun den Text so skalieren, dass er in das Rect passt.
    // Wir fangen mit der Defaultsize an und gehen 1-AppFont runter
    for( USHORT i = 8; i > 2; i-- )
    {
        aPt.X() = (rRect.GetWidth()  - pOut->GetTextWidth( rText )) / 2;
        aPt.Y() = (rRect.GetHeight() - pOut->GetTextHeight()) / 2;

        BOOL bTiny = FALSE;
        if( aPt.X() < 0 ) bTiny = TRUE, aPt.X() = 0;
        if( aPt.Y() < 0 ) bTiny = TRUE, aPt.Y() = 0;
        if( bTiny )
        {
            // heruntergehen bei kleinen Bildern
            aFnt.SetSize( Size( 0, aAppFontSz.Height() * i / 8 ) );
            pOut->SetFont( aFnt );
        }
        else
            break;
    }

    Bitmap aBmp( SoResId( BMP_PLUGIN ) );
    long nHeight = rRect.GetHeight() - pOut->GetTextHeight();
    long nWidth = rRect.GetWidth();
    if( nHeight > 0 )
    {
        aPt.Y() = nHeight;
        Point   aP = rRect.TopLeft();
        Size    aBmpSize = aBmp.GetSizePixel();
        // Bitmap einpassen
        if( nHeight * 10 / nWidth
          > aBmpSize.Height() * 10 / aBmpSize.Width() )
        {
            // nach der Breite ausrichten
            // Proportion beibehalten
            long nH = nWidth * aBmpSize.Height() / aBmpSize.Width();
            // zentrieren
            aP.Y() += (nHeight - nH) / 2;
            nHeight = nH;
        }
        else
        {
            // nach der H"ohe ausrichten
            // Proportion beibehalten
            long nW = nHeight * aBmpSize.Width() / aBmpSize.Height();
            // zentrieren
            aP.X() += (nWidth - nW) / 2;
            nWidth = nW;
        }
        pOut->DrawBitmap( aP, Size( nWidth, nHeight ), aBmp );
    }

    pOut->IntersectClipRegion( rRect );
    aPt += rRect.TopLeft();
    pOut->DrawText( aPt, rText );
    pOut->Pop();
}

//=========================================================================
void SvPlugInObject::Draw
(
    OutputDevice *  pDev,   /* in dieses Device findet die Ausgabe statt */
    const JobSetup &,       /* fuer dieses Device soll formatiert werden */
    USHORT          nAspect /* Darstellungsvariante des Objektes */
)
/*  [Beschreibung]

    Ein Ausgabe ist nicht m"oglich. Deswegen wird eine Bitmap
    und als Unterschrift der URL ausgegeben,

    [Querverweise]

    <SvEmbeddedObject::Draw>
*/
{
    Rectangle aVisArea_ = GetVisArea( nAspect );
    String aOut;
    if( pURL)
        aOut = pURL->GetMainURL(INetURLObject::DECODE_TO_IURI);
    SoPaintReplacement( aVisArea_, aOut, pDev );
}

//=========================================================================
BOOL SvPlugInObject::InitNew
(
    SvStorage * pStor   /* Storage auf dem das Objekt arbeitet. Der kann
                           auch NULL sein, das Bedeutet, es wird auf einem
                           tempor"aren Storage gearbeitet */
)
/*  [Beschreibung]

    Nach dem Konstruktor muss diese Methode oder Load gerufen werden,
    um das Objekt zu initialisieren.
    <SvPersist::InitNew>

    [R"uckgabewert]

    BOOL            TRUE, Initialisierung hat geklappt.
                    FALSE, Initialisierung hat nicht geklappt, das Objekt
                    muss sofort freigegeben werden.

    [Querverweise]

*/
{
    if( SvInPlaceObject::InitNew( pStor ) )
    {
        // Standardgr"osse
        SetVisArea( Rectangle( Point(), Size( 10000, 10000 ) ) );
        return TRUE;
    }
    return FALSE;
}

//=========================================================================
#define DOCNAME "plugin"
#define PLUGIN_VERS 2

BOOL SvPlugInObject::Load
(
    SvStorage * pStor   /* Storage aus dem das Objekt geladen wird. */
)
/*  [Beschreibung]

    Nach dem Konstruktor muss diese Methode oder InitNew gerufen werden,
    um das Objekt zu initialisieren.

    [R"uckgabewert]

    BOOL            TRUE, das Objekt wurde geladen.
                    FALSE, das Objekt wurde nicht geladen, es
                    muss sofort freigegeben werden.

    [Querverweise]

    <SvPersist::Load>
*/
{
    if( SvInPlaceObject::Load( pStor ) )
    {
        SvStorageStreamRef xStm;
        xStm = pStor->OpenStream( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( DOCNAME ) ), STREAM_STD_READ );
        xStm->SetVersion( pStor->GetVersion() );
        xStm->SetBufferSize( 8192 );

        // nicht vorhandener Stream ist kein Fehler
        if( xStm->GetError() == SVSTREAM_FILE_NOT_FOUND )
            return TRUE;

        BYTE nVer;
        *xStm >> nVer;
        if( nVer == 1 || nVer == PLUGIN_VERS )
        {
            *xStm >> nPlugInMode;
            // we only support embedding
            nPlugInMode = (USHORT)PLUGIN_EMBEDED;

            *xStm >> aCmdList;
            DBG_ASSERT( !pURL, "pURL exists in load" );
            BYTE bURLExist;
            *xStm >> bURLExist;
            if( bURLExist )
            {
                if( nVer == 1 )
                {
                    String aURL = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*xStm,
                        RTL_TEXTENCODING_ASCII_US);
                    pURL = new INetURLObject( aURL );
                    // Ignore, not necessary
                    BOOL bStrict;
                    *xStm >> bStrict;
                }
                else
                {
                    String aURL = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*xStm,
                        RTL_TEXTENCODING_ASCII_US);
                    pURL = new INetURLObject(
                        ::binfilter::StaticBaseUrl::RelToAbs( aURL ));
                }
            }

            String aMimeType = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(*xStm,
                RTL_TEXTENCODING_ASCII_US);
        }
        else
            xStm->SetError( ERRCODE_IO_WRONGVERSION );

        return xStm->GetError() == ERRCODE_NONE;
    }
    return FALSE;
}

//=========================================================================
void SvPlugInObject::HandsOff()
/*  [Beschreibung]

    Ab diesen Zeitpunkt, bis zum <SvPlugInObject::SaveCompleted>,
    darf auf den Storage im Objekt nicht zugegriffen werden.

    [Querverweise]

    <SvPersist::HandsOff>
*/
{
    SvInPlaceObject::HandsOff();
}

//=========================================================================
ULONG SvPlugInObject::GetMiscStatus() const
/*  [Beschreibung]

    Da ein PlugIn immer aktiviert wird, es ein Link ist und er
    keine UI-Tools braucht, muss dieser Status zur"uckgegeben werden.

    [R"uckgabewert]

    ULONG           Es wird immer  SVOBJ_MISCSTATUS_LINK,
                    SVOBJ_MISCSTATUS_INSIDEOUT und
                    SVOBJ_MISCSTATUS_ACTIVATEWHENVISIBLE zur"uckgegeben

    [Querverweise]

    <SvPseudoObject::GetMiscStatus()>
*/
{
    ULONG nMisc = 0;

    //nMisc = SVOBJ_MISCSTATUS_LINK;
    if( PLUGIN_EMBEDED == ((PlugInMode)nPlugInMode) )
    {
        nMisc |= SVOBJ_MISCSTATUS_INSIDEOUT;
        if( !pImpl->bRegisterFailed )
            nMisc |= SVOBJ_MISCSTATUS_ACTIVATEWHENVISIBLE;
    }
    else if( PLUGIN_FULL == ((PlugInMode)nPlugInMode) )
    {
        nMisc |= SVOBJ_MISCSTATUS_INSIDEOUT;
    }

    nMisc |= SVOBJ_MISCSTATUS_SPECIALOBJECT;
    return nMisc;
}

//=========================================================================
BOOL SvPlugInObject::IsLink() const
/*  [Beschreibung]

    Dieser Typ von Objekt ist immer ein Link.

    [R"uckgabewert]

    BOOL            Immer TRUE.

    [Querverweise]

    <SvPseudoObject::IsLink()>
*/
{
    //return TRUE;
    return FALSE;
}

//=========================================================================
void SvPlugInObject::SetCommandList
(
    const SvCommandList & rList /* Die Liste der Kommnados */
)
/*  [Beschreibung]

    Die Liste der Kommandos, die "ubergeben werden, wenn das PlugIn
    gestartet wird.

    [Anmerkung]

    Ein bereits gestartetes PlugIn wird dadurch nicht beeinflusst.
    Die neuen Kommandos werden erst beim n"achsten starten ausgew"ahlt.
*/
{
    aCmdList = rList;

    DataChanged_Impl( TRUE );
}

//=========================================================================
void SvPlugInObject::SetURL
(
    const INetURLObject & rURL  /* Der Verweis auf die Quelle */
)
/*  [Beschreibung]

    Der Verweis auf die Quelle wird "uebergeben.

    [Anmerkung]

    Ein bereits gestartetes PlugIn wird dadurch nicht beeinflusst.
    Die neue Quelle wird erst beim n"achsten starten ausgew"ahlt.
*/
{
    if( !pURL )
    {
        pURL = new INetURLObject( rURL );
    }
    else if( *pURL != rURL )
    {
        *pURL = rURL;
        DataChanged_Impl( FALSE );
    }
}

//=========================================================================
void SvPlugInObject::SetMimeType
(
    const String & rMimeType
)
{
    (void)rMimeType;
}

//=========================================================================
const String & SvPlugInObject::GetMimeType() const
{
    static String aEmpty;
    SvPlugInEnvironment* pEnv = (SvPlugInEnvironment*)GetIPEnv();
    if( pEnv )
    {
        try
        {
            Reference< awt::XControl > xControl( pEnv->pImpl->_xPlugin, UNO_QUERY );
            if( xControl.is() )
            {
                Reference< awt::XControlModel > xModel = xControl->getModel();
                Reference< XPropertySet > xProp( xModel, UNO_QUERY );
                if( xProp.is() )
                {
                    Any aValue = xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TYPE" ) ) );
                    OUString aVal;
                    aValue >>= aVal;
                    pEnv->pImpl->_aMimeType = aVal;
#if OSL_DEBUG_LEVEL > 1
                    fprintf( stderr, "got mimetype %s from plugin\n", OUStringToOString( pEnv->pImpl->_aMimeType, RTL_TEXTENCODING_ASCII_US ).getStr() );
#endif
                }
            }
        }
        catch(...)
        {
        }

        return pEnv->pImpl->_aMimeType;
    }
    return aEmpty;
}

//=========================================================================
void SvPlugInObject::SetPlugInMode
(
    USHORT nPlugIn  /* Der Modus in dem das PlugIn gestartet werden soll.
                       Um nicht inet.hxx zu includen. */
)
{
    (void)nPlugIn;
}


}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */