summaryrefslogtreecommitdiff
path: root/svx/source/dialog/impgrf.cxx
blob: 5675c9aad1e64193bbbd2e3b0f4bbcf7a731233c (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
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
/*************************************************************************
 *
 *  $RCSfile: impgrf.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: pb $ $Date: 2000-09-26 06:36:00 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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 for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

// include ------------------------------------------------------------------

#include <limits.h>             // USHRT_MAX

#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _BIGINT_HXX
#include <tools/bigint.hxx>
#endif
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXDOCFILE_HXX
#include <sfx2/docfile.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SV_WAITOBJ_HXX //autogen
#include <vcl/waitobj.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
#include <svtools/pathoptions.hxx>
#endif
#ifndef _SFX_INIMGR_HXX
#include <sfx2/inimgr.hxx>
#endif
#pragma hdrstop

#include <ucbhelper/content.hxx>

#ifndef _COM_SUN_STAR_UCB_COMMANDABORTEDEXCEPTION_HPP_
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#endif

using namespace ::ucb;
using namespace com::sun::star::uno;

#include "dialogs.hrc"
#include "impgrf.hrc"

#define _SVX_IMPGRF_CXX
#include "impgrf.hxx"

#include "dialmgr.hxx"
#include "svxerr.hxx"
#include "helpid.hrc"

// defines ---------------------------------------------------------------

#define IMPGRF_INIKEY_ASLINK        "ImportGraphicAsLink"
#define IMPGRF_INIKEY_PREVIEW       "ImportGraphicPreview"

#ifdef MAC
#define IMPGRF_GRAPHIC_FILTER_FILE  "Filterlist"
#else
#define IMPGRF_GRAPHIC_FILTER_FILE  "install.ini"
#endif

#define IMPGRF_GRAPHIC_OPTIONS_FILE "fltopt.ini"

// C-Funktion ------------------------------------------------------------

USHORT GetImportFormatCount( GraphicFilter& rFlt )
{
    if ( rFlt.GetImportFormatCount() )
        return rFlt.GetImportFormatCount();
    else
        return 4;
}

// -----------------------------------------------------------------------

String GetImportFormatName( GraphicFilter& rFlt,
                            USHORT nFormat, String pFmtStrs[] )
{
    if ( rFlt.GetImportFormatCount() )
        return rFlt.GetImportFormatName( nFormat );
    else
        return pFmtStrs[STR_FLT_BMP + nFormat].GetToken( 0, ',' );
}

// -----------------------------------------------------------------------

String GetImportFormatWildcard( GraphicFilter& rFlt,
                                USHORT nFormat, String pFmtStrs[] )
{
    if ( rFlt.GetImportFormatCount() )
        return rFlt.GetImportWildcard( nFormat );
    else
        return pFmtStrs[STR_FLT_BMP + nFormat].GetToken( 1, ',' );
}

// -----------------------------------------------------------------------

String GetImportFormatOSType( GraphicFilter& rFlt, USHORT nFormat, String pFmtStrs[] )
{
    String aOSType;

    if ( rFlt.GetImportFormatCount() )
        aOSType = rFlt.GetImportFormatType( nFormat );
    else
    {
#ifdef MAC
        aOSType = pFmtStrs[STR_FLT_BMP + nFormat].GetToken( 2, ',' );
#endif
    }
    return aOSType;
}

// -----------------------------------------------------------------------

GraphicFilter* DialogsResMgr::GetGrfFilter_Impl()
{
    if( !pGrapicFilter )
    {
        pGrapicFilter = new GraphicFilter;
        ::FillFilter( *pGrapicFilter );
    }
    const Link aLink;
    pGrapicFilter->SetStartFilterHdl( aLink );
    pGrapicFilter->SetEndFilterHdl( aLink );
    pGrapicFilter->SetUpdatePercentHdl( aLink );
    return pGrapicFilter;
}

// -----------------------------------------------------------------------

GraphicFilter* GetGrfFilter()
{
    return (*(DialogsResMgr**)GetAppData(SHL_SVX))->GetGrfFilter_Impl();
}

// -----------------------------------------------------------------------

USHORT FillFilter( GraphicFilter& rFilter )
{
    ResMgr* pMgr = DIALOG_MGR();
    SvtPathOptions aPathOpt;
    String aModulesPath( aPathOpt.GetModulePath() );
    String aFullConfigPath;

    for ( xub_StrLen i = 0, nCount = aModulesPath.GetTokenCount(); i < nCount; i++ )
    {
        INetURLObject aToken( aModulesPath.GetToken( i ), INET_PROT_FILE );
        aToken.insertName( DEFINE_CONST_UNICODE(IMPGRF_GRAPHIC_FILTER_FILE) );

        if ( aFullConfigPath.Len() )
            aFullConfigPath += sal_Unicode(';');

        aFullConfigPath += aToken.getFSysPath( INetURLObject::FSYS_DETECT );;
    }

    rFilter.SetConfigPath( aFullConfigPath );

    INetURLObject aFilterPath( aPathOpt.GetFilterPath(), INET_PROT_FILE );
    rFilter.SetFilterPath( aFilterPath.getFSysPath( INetURLObject::FSYS_DETECT ) );

    INetURLObject aFltOptFile( aPathOpt.GetUserConfigPath(), INET_PROT_FILE );
    aFltOptFile.Append(
        UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( IMPGRF_GRAPHIC_OPTIONS_FILE ) ) );
    rFilter.SetOptionsConfigPath( aFltOptFile );

    return rFilter.GetImportFormatCount();
}

sal_Bool IsFolder_Impl( const String& rURL )
{
    sal_Bool bRet = sal_False;
    try
    {
        Content aCnt( rURL, Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
        bRet = aCnt.isFolder();
    }
    catch( ::com::sun::star::ucb::CommandAbortedException& )
    {
        DBG_ERRORFILE( "CommandAbortedException" );
    }
    catch( ContentCreationException& )
    {
        DBG_ERRORFILE( "ContentCreationException" );
    }
    catch( ... )
    {
        DBG_ERRORFILE( "Any other exception" );
    }

    return bRet;
}

// -----------------------------------------------------------------------

#pragma optimize( "", off )

int LoadGraphic( const String &rPath, const String &rFilterName,
                 Graphic& rGraphic, GraphicFilter* pFilter,
                 USHORT* pDeterminedFormat )
{
    if ( !pFilter )
        pFilter = ::GetGrfFilter();

    const int nFilter = rFilterName.Len() && pFilter->GetImportFormatCount()
                    ? pFilter->GetImportFormatNumber( rFilterName )
                    : GRFILTER_FORMAT_DONTKNOW;

    SfxMedium* pMed = 0;

    // dann teste mal auf File-Protokoll:
    SvStream* pStream = NULL;
    INetURLObject aURL( rPath );

    if ( aURL.HasError() || INET_PROT_NOT_VALID == aURL.GetProtocol() )
    {
        aURL.SetSmartProtocol( INET_PROT_FILE );
        aURL.SetSmartURL( rPath );
    }
    else if ( INET_PROT_FILE != aURL.GetProtocol() )
    {
        // z.Z. nur auf die aktuelle DocShell
        pMed = new SfxMedium( rPath, STREAM_READ, TRUE );
        pMed->SetTransferPriority( SFX_TFPRIO_SYNCHRON );
        pMed->DownLoad();
        pStream = pMed->GetInStream();
    }
    int nRes = GRFILTER_OK;

    if ( !pStream )
        nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat );
    else
        nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream,
                                       nFilter, pDeterminedFormat );

#ifndef PRODUCT
    if( nRes )
    {
        if( pMed )
        {
            DBG_WARNING3( "GrafikFehler [%d] - [%s] URL[%s]",
                            nRes,
                            pMed->GetPhysicalName().GetBuffer(),
                            rPath.GetBuffer() );
        }
        else
        {
            DBG_WARNING2( "GrafikFehler [%d] - [%s]", nRes, rPath.GetBuffer() );
        }
    }
#endif

    if ( pMed )
        delete pMed;
    return nRes;
}

#pragma optimize( "", on )

// -----------------------------------------------------------------------

BOOL IsGraphicError_Impl( const USHORT nError, USHORT& rErrInfo )
{
    // default: format error
    rErrInfo = nError ? STR_GRFILTER_FORMATERROR : 0;

    switch ( nError )
    {
        case GRFILTER_OPENERROR:
            rErrInfo = STR_GRFILTER_OPENERROR;
            break;
        case GRFILTER_IOERROR:
            rErrInfo = STR_GRFILTER_IOERROR;
            break;
        case GRFILTER_FORMATERROR:
            rErrInfo = STR_GRFILTER_FORMATERROR;
            break;
        case GRFILTER_VERSIONERROR:
            rErrInfo = STR_GRFILTER_VERSIONERROR;
            break;
        case GRFILTER_FILTERERROR:
            rErrInfo = STR_GRFILTER_FILTERERROR;
            break;
    }
    return (BOOL)nError;
}

// struct SvxImportGraphicRes_Impl ---------------------------------------

struct SvxImportGraphicRes_Impl : public Resource
{
    SvxImportGraphicRes_Impl( USHORT nResId );
    ~SvxImportGraphicRes_Impl();

    String*     pStrings;
    BOOL        bSaveAs;
};

// -----------------------------------------------------------------------

SvxImportGraphicRes_Impl::SvxImportGraphicRes_Impl( USHORT nResId ) :

    Resource( SVX_RES( nResId ) ),

    pStrings( 0 ),
    bSaveAs( FALSE )

{
    USHORT nCount = STR_IMPORTGRAPHIC_COUNT+1;
    pStrings = new String[nCount];
    pStrings[0] = String();           // ein Dummy

    for ( USHORT i = 1; i < nCount; ++i )
        pStrings[i] = String( ResId(i) );
    FreeResource();
}

// -----------------------------------------------------------------------

SvxImportGraphicRes_Impl::~SvxImportGraphicRes_Impl()
{
    __DELETE(STR_IMPORTGRAPHIC_COUNT)pStrings;
}

// class SvxGraphicHdl_Impl ----------------------------------------------

class SvxGraphicHdl_Impl
{
public:
    SvxGraphicHdl_Impl();
    ~SvxGraphicHdl_Impl();

    void            GraphicPreview( SvxImportGraphicDialog* pDlg );

private:
friend class SvxImportGraphicDialog;

    Graphic*        pPreviewGrf;
    String          aPreviewPath;

    int             InsertGraphic( const String& rPath, const String& rFilter );
};

// class SvxGraphicPrevWin_Impl ------------------------------------------

class SvxGraphicPrevWin_Impl : public Window
{
public:
    SvxGraphicPrevWin_Impl( Window *pParent, WinBits nBits );
    ~SvxGraphicPrevWin_Impl();

    void        SetGraphic( Graphic* pPict, const String& rFile );
    Graphic*    CreateTempGraphic( Graphic* pPict );
    void        SetMessage( const String& rMessage );

private:
friend class SvxImportGraphicDialog;

    Graphic*    pTempGraphic;
    Graphic*    pGraphic;   // Grafik ...
    String      aMessage;   // oder Fehlermeldung
    String      aFile;      // Dateiname

    void        MouseButtonDown( const MouseEvent& );
    void        Paint( const Rectangle& );
};

// -----------------------------------------------------------------------

SvxGraphicPrevWin_Impl::SvxGraphicPrevWin_Impl( Window* pParent, WinBits nBits ) :

    Window( pParent, nBits ),

    pTempGraphic( NULL ),
    pGraphic    ( NULL )

{
    // Transparenter Font f"ur Message-Ausgabe
    Font aFont( GetFont() );
    aFont.SetTransparent( TRUE );
    SetFont( aFont );
}

// -----------------------------------------------------------------------

void SvxGraphicPrevWin_Impl::MouseButtonDown( const MouseEvent& )
{
    SvxImportGraphicDialog *pDlg = (SvxImportGraphicDialog*)GetParent();

    if ( pDlg->pPreviewBox )
    {
        pDlg->pPreviewBox->Check();
        ( (Link&)pDlg->pPreviewBox->GetClickHdl() ).Call( pDlg->pPreviewBox );
    }
}

// -----------------------------------------------------------------------

void SvxGraphicPrevWin_Impl::Paint( const Rectangle& )
{
    Size aOutSizePix = GetOutputSizePixel();

    if( pGraphic )
    {
        Size aNewSizePix( LogicToPixel( pGraphic->GetPrefSize(),
                                        pGraphic->GetPrefMapMode() ) );

        if( aNewSizePix.Height() && aOutSizePix.Height() )
        {
            Point           aPos;
            const double    fGrfWH = (double) aNewSizePix.Width() / aNewSizePix.Height();
            const double    fWinWH = (double) aOutSizePix.Width() / aOutSizePix.Height();

            // Bitmap an Fenstergroesse anpassen
            if( fGrfWH < fWinWH )
            {
                aNewSizePix.Width() = (long) ( aOutSizePix.Height() * fGrfWH );
                aNewSizePix.Height() = aOutSizePix.Height();
            }
            else
            {
                aNewSizePix.Width() = aOutSizePix.Width();
                aNewSizePix.Height()= (long) ( aOutSizePix.Width() / fGrfWH );
            }

            WaitObject aWaitPtr( this );

            aPos.X() = ( aOutSizePix.Width()  - aNewSizePix.Width() ) >> 1;
            aPos.Y() = ( aOutSizePix.Height() - aNewSizePix.Height() ) >> 1;

            if( pGraphic->IsAnimated() )
                pGraphic->StartAnimation( this, aPos, aNewSizePix );
            else
                pGraphic->Draw( this, aPos, aNewSizePix );
        }
    }
    else
    {
        SetLineColor( Color( COL_BLACK ) );

        if ( aMessage.Len() )
        {
            // Fehlermeldung zeilenweise ausgeben
            UniString aStrSpace( sal_Unicode( ' ' ) ), aStrChar( sal_Unicode( 'X' ) );
            xub_StrLen i,
                       nCount  = aMessage.GetTokenCount( sal_Unicode( ' ' ) ),
                       x       = 2,
                       y       = 2,
                       nSpaceW = GetTextWidth( aStrSpace ),
                       nCharH  = GetTextHeight();
            for ( i = 0; i < nCount; i++ )
            {
                String aWord = aMessage.GetToken( i, sal_Unicode( ' ' ) );
                long nWordW = GetTextWidth( aWord );
                if ( x != 2 && x + nWordW > aOutSizePix.Width() - 2 )
                {
                    x  = 2;
                    y += nCharH;
                }
                DrawText( Point( x, y ), aWord );
                x += nWordW + nSpaceW;
            }
        }
        else
        {
            // Kreuz malen
            DrawLine( Point( 0, 0),
                      Point( aOutSizePix.Width()  - 1,
                             aOutSizePix.Height() - 1 ) );
            DrawLine( Point( 0, aOutSizePix.Height() - 1),
                      Point( aOutSizePix.Width() - 1, 0 ) );
        }
    }

    // Zeichnen abgeschlossen
    ( (SvxImportGraphicDialog*)GetParent() )->SetPreviewing( FALSE );
}

// -----------------------------------------------------------------------

void SvxGraphicPrevWin_Impl::SetGraphic( Graphic* pPict, const String& rFile )
{
    delete pGraphic;
    pGraphic = pPict;

    if ( pGraphic )
    {
        aMessage.Erase();
        aFile = rFile;
    }
    else
        aFile.Erase();

    Invalidate();
}

// -----------------------------------------------------------------------

Graphic* SvxGraphicPrevWin_Impl::CreateTempGraphic( Graphic* pPict )
{
    DELETEZ(pTempGraphic);

    if ( pPict )
        pTempGraphic = new Graphic( *pPict );
    return pTempGraphic;
}

// -----------------------------------------------------------------------

void SvxGraphicPrevWin_Impl::SetMessage( const String& rMessage )
{
    delete pGraphic;
    pGraphic = 0;
    aMessage = rMessage;
}

// -----------------------------------------------------------------------

SvxGraphicPrevWin_Impl::~SvxGraphicPrevWin_Impl()
{
    delete pTempGraphic;
    delete pGraphic;
}

// class SvxImportGraphicDialog ------------------------------------------

SvxImportGraphicDialog::SvxImportGraphicDialog
(
    Window*         pParent,
    const String&   rTitle,
    const USHORT    nEnable,
    WinBits         nFlags
) :
    SfxFileDialog( pParent, nFlags ),

    pMedium             ( 0 ),
    pStandardButton     ( 0 ),
    pInternetButton     ( 0 ),
    pPropertiesButton   ( 0 ),
    pFilterButton       ( 0 ),
    pLinkBox            ( 0 ),
    pPreviewBox         ( 0 ),
    bPreviewing         ( FALSE )

{
    if (nEnable & ENABLE_EMPTY_FILENAMES)
        EnableEmptyFilename();

    Construct_Impl( rTitle, nEnable );
    pResImpl->bSaveAs = WB_SAVEAS == (nFlags&WB_SAVEAS);
}

//-------------------------------------------------------------------------

void SvxImportGraphicDialog::Construct_Impl( const String &rTitle, USHORT nEnable )
{
    pResImpl = new SvxImportGraphicRes_Impl( RID_SVXRES_IMPORTGRAPHIC );

    SetFilterSelectHdl(
        LINK( this, SvxImportGraphicDialog, FilterSelectHdl_Impl ) );

    // Titel
    SetText( rTitle );

    // Ggf. "Eigenschaften" und "Verkn"upfung"
    SfxApplication* pSfxApp = SFX_APP();
    SvtPathOptions aPathOpt;

    if ( ( ( ENABLE_LINK & nEnable ) && ( ENABLE_PROPERTY & nEnable ) ) ||
         ( ENABLE_PROP_WITHOUTLINK & nEnable ) )
    {
        pPropertiesButton = new PushButton( this );
        pPropertiesButton->SetText( pResImpl->pStrings[STR_PROPERTIES] );
        pPropertiesButton->SetClickHdl(
            LINK( this, SvxImportGraphicDialog, PropertiesHdl_Impl ) );
        pPropertiesButton->SetHelpId( HID_IMPGRF_BTN_PROPERTIES );
        AddControl( pPropertiesButton );
        pPropertiesButton->Show();
    }

    // FilterButton jetzt immer
    pFilterButton = new PushButton( this );
    pFilterButton->SetText( pResImpl->pStrings[STR_FILTER] );
    pFilterButton->SetClickHdl( LINK( this, SvxImportGraphicDialog, FilterHdl_Impl ) );
    pFilterButton->SetHelpId( HID_IMPGRF_BTN_FILTER );
    AddControl( pFilterButton );
    pFilterButton->Show();
    SfxIniManager* pIniMgr = SFX_INIMANAGER();

    if ( ENABLE_LINK & nEnable )
    {
        BOOL bLink = FALSE;
        const SfxPoolItem* pLink = pSfxApp->GetItem( SID_IMPORT_GRAPH_LINK );

        if ( pLink )
            bLink = ( (const SfxBoolItem*)pLink )->GetValue();
        else
            bLink = (BOOL)pIniMgr->Get( SFX_GROUP_COMMON, UniString::CreateFromAscii(
                           RTL_CONSTASCII_STRINGPARAM( IMPGRF_INIKEY_ASLINK ) ) ).ToInt32();
        pLinkBox = new CheckBox( this );
        pLinkBox->SetText( pResImpl->pStrings[STR_LINK] );
        pLinkBox->Check( bLink );
        pLinkBox->SetHelpId( HID_IMPGRF_CB_LINK );
        AddControl( pLinkBox );
        pLinkBox->Show();
    }

    // static Werte besorgen
    const SfxPoolItem* pPrevItem = pSfxApp->GetItem( SID_IMPORT_GRAPH_PREVIEW );
    BOOL bShowPreview = FALSE;

    if ( pPrevItem )
        bShowPreview = ( (SfxBoolItem*)pPrevItem )->GetValue();
    else
        bShowPreview = (BOOL)pIniMgr->Get( SFX_GROUP_COMMON, UniString::CreateFromAscii(
                              RTL_CONSTASCII_STRINGPARAM( IMPGRF_INIKEY_PREVIEW ) ) ).ToInt32();

    // "Vorschau"
    pPreviewBox = new CheckBox( this );
    pPreviewBox->SetText( pResImpl->pStrings[STR_PREVIEW] );
    pPreviewBox->SetClickHdl( LINK( this, SvxImportGraphicDialog, PreviewHdl_Impl ) );
    pPreviewBox->Check( bShowPreview );
    pPreviewBox->SetHelpId( HID_IMPGRF_CB_PREVIEW );
    AddControl( pPreviewBox );
    pPreviewBox->Show();

    // Preview-Fenster erst hier erzeugen
    pPrevWin = new SvxGraphicPrevWin_Impl( this, WinBits( WB_BORDER ) );
    pPrevWin->SetBackground( Wallpaper( Color( COL_WHITE ) ) );
    AddControl( pPrevWin );
    pPrevWin->Show();

    const SfxStringItem* pPathItem =
        (const SfxStringItem*)pSfxApp->GetItem( SID_IMPORT_GRAPH_LASTPATH );
    const SfxStringItem* pFilterItem =
        (const SfxStringItem*)pSfxApp->GetItem( SID_IMPORT_GRAPH_LASTFILTER );

    // Filter ermitteln
    GraphicFilter*  pGraphicFilter = GetGrfFilter();
    USHORT          i, nCount = pGraphicFilter->GetImportFormatCount();

    // Filter "Alle"
    String aExtensions;

    for ( i = 0; i < nCount; i++ )
    {
        String aWildcard =
            ::GetImportFormatWildcard( *pGraphicFilter, i, pResImpl->pStrings );

        if ( aExtensions.Search( aWildcard ) == STRING_NOTFOUND )
        {
            if ( aExtensions.Len() )
                aExtensions += sal_Unicode(';');
            aExtensions += aWildcard;
        }
    }
#if defined(WIN) || defined(WNT)
    if ( aExtensions.Len() < 240 )
        AddFilter( pResImpl->pStrings[STR_IMPORT_ALL], aExtensions );
    else
        AddFilter( SVX_RESSTR( RID_SVXSTR_ALL_FILES ),
                   UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "*.*" ) ) );
#else
    AddFilter( pResImpl->pStrings[STR_IMPORT_ALL], aExtensions );
#endif

    // Filter eintragen

    for ( i = 0; i < nCount; i++ )
    {
        String aName =
            ::GetImportFormatName( *pGraphicFilter, i, pResImpl->pStrings );
        String aWildcard =
            ::GetImportFormatWildcard( *pGraphicFilter, i, pResImpl->pStrings );
        String aOSType =
            ::GetImportFormatOSType( *pGraphicFilter, i, pResImpl->pStrings );
        AddFilter( aName, aWildcard, aOSType );
    }

    // Pfad und Filter setzen
    aStartPath = aPathOpt.GetGraphicPath();
    FASTBOOL bGrfPath = ( aStartPath.Len() > 0 );
    if ( !bGrfPath )
        aStartPath = aPathOpt.GetWorkPath();
    SetStandardDir( aStartPath );
    String aLastPath;
    if ( pPathItem )
      aLastPath = pPathItem->GetValue();

    if ( aLastPath.Len() )
        SetPath( aLastPath, TRUE );
    else
    {
        String aPath =  aStartPath;

        if ( bGrfPath )
        {
            INetURLObject aTemp( aPath, INET_PROT_FILE );
            aTemp.setFinalSlash();
            aPath = aTemp.getFSysPath( INetURLObject::FSYS_DETECT );
        }
        SetPath( aPath, TRUE );
    }

    String aLastFilter;

    if ( pFilterItem )
        aLastFilter = pFilterItem->GetValue();

    if ( aLastFilter.Len() )
        SetCurFilter( aLastFilter );
    else
        SetCurFilter( pResImpl->pStrings[STR_IMPORT_ALL] );

    // aPreviewTimer
    aPrevTimer.SetTimeout( 500 );
    aPrevTimer.SetTimeoutHdl(
        LINK( this, SvxImportGraphicDialog, TimeOutHdl_Impl ) );

    FilterSelectHdl_Impl( NULL );
}

// -----------------------------------------------------------------------

SvxImportGraphicDialog::~SvxImportGraphicDialog()
{
    ReleaseOwnerShip( pPrevWin );
    ReleaseOwnerShip( pPropertiesButton );
    ReleaseOwnerShip( pLinkBox );
    ReleaseOwnerShip( pPreviewBox );
    ReleaseOwnerShip( pStandardButton );
    ReleaseOwnerShip( pInternetButton );
    ReleaseOwnerShip( pFilterButton );
    delete pPrevWin;
    delete pPropertiesButton;
    delete pLinkBox;
    delete pPreviewBox;
    delete pStandardButton;
    delete pInternetButton;
    delete pFilterButton;
    delete pResImpl;
    delete pMedium;
}

// -----------------------------------------------------------------------

void SvxImportGraphicDialog::FileSelect()
{
    // falls User neu selektiert hat, dann die Internetselektion vergessen
    String aSelPath = SfxFileDialog::GetPath();
    sal_Bool bFolder = IsFolder_Impl( aSelPath );

    if ( bFolder || aSelPath == aCurrPath )
        // keine Datei selektiert, sondern Verzeichnis gewechselt
        // oder gleiche Datei selektiert
        return;
    else
        aCurrPath = aSelPath;

    // falls gew"unscht, Preview antriggern
    if ( pPreviewBox && pPreviewBox->IsChecked() )
        aPrevTimer.Start();
}

// -----------------------------------------------------------------------

BOOL SvxImportGraphicDialog::IsURL() const
{
    return FALSE;
}

// -----------------------------------------------------------------------

short SvxImportGraphicDialog::Execute()
{
    short  nRet;
    USHORT nFound = 0;
    SfxApplication* pSfxApp = SFX_APP();
    GraphicFilter*  pGraphicFilter = GetGrfFilter();

    do
    {
        InitSize( UniString::CreateFromAscii(
                  RTL_CONSTASCII_STRINGPARAM( "ImpGrfDialogSize" ) ) );
        nRet = SfxFileDialog::Execute();
        String aGrfPath = GetPath();

        if ( nRet == RET_OK && aGrfPath.Len())
        {
            INetURLObject aObj( aGrfPath );

            // zuletzt verwendeten Filter merken
            pSfxApp->PutItem( SfxStringItem( SID_IMPORT_GRAPH_LASTFILTER, GetCurFilter() ) );

            // fall File-System,

            if ( !IsURL() && INET_PROT_FILE == aObj.GetProtocol() )
            {
                // dann den zuletzt verwendeten Pfad merken
                INetURLObject aTemp = aObj;
                aTemp.removeSegment();
                aTemp.setFinalSlash();
                pSfxApp->PutItem( SfxStringItem( SID_IMPORT_GRAPH_LASTPATH,
                                                 aTemp.getFSysPath( INetURLObject::FSYS_DETECT ) ) );
            }

            // merken, ob der Benutzer Linken und Preview eingeschaltet hat
            BOOL bLink = pLinkBox ? pLinkBox->IsChecked() : FALSE;
            pSfxApp->PutItem( SfxBoolItem( SID_IMPORT_GRAPH_LINK, bLink ) );
            sal_Unicode cTemp = bLink ? '1' : '0';
            SFX_INIMANAGER()->Set( String( cTemp ), SFX_GROUP_COMMON, UniString::CreateFromAscii(
                                   RTL_CONSTASCII_STRINGPARAM( IMPGRF_INIKEY_ASLINK ) ) );
            cTemp = pPreviewBox && pPreviewBox->IsChecked() ? '1' : '0';
            SFX_INIMANAGER()->Set( String( cTemp ), SFX_GROUP_COMMON, UniString::CreateFromAscii(
                                   RTL_CONSTASCII_STRINGPARAM( IMPGRF_INIKEY_PREVIEW ) ) );

            // Open?
            if ( !pResImpl->bSaveAs )
            {
                // pr"uefen, ob die Grafik geladen werden kann
                nFound = USHRT_MAX;
                SvStream* pStream = NULL;
                SfxMedium* pMed = NULL;

                if ( INET_PROT_FILE != aObj.GetProtocol() )
                {
                    pMed = new SfxMedium( aObj.GetMainURL(), STREAM_READ, TRUE );
                    pMed->SetTransferPriority( SFX_TFPRIO_SYNCHRON );
                    pMed->DownLoad();
                    pStream = pMed->GetInStream();
                }
                USHORT nImpRet = 0;
                USHORT nRetFormat = 0;
                USHORT nFormatNum = pGraphicFilter->
                            GetImportFormatNumber( GetCurFilter() );

                if ( !pStream )
                    nImpRet = pGraphicFilter->CanImportGraphic( aObj, nFormatNum, &nRetFormat );
                else
                    nImpRet = pGraphicFilter->CanImportGraphic( aObj.GetMainURL(), *pStream, nFormatNum, &nRetFormat );

                if ( GRFILTER_OK != nImpRet )
                {
                    if ( !pStream )
                        nImpRet = pGraphicFilter->CanImportGraphic( aObj, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
                    else
                        nImpRet = pGraphicFilter->CanImportGraphic( aObj.GetMainURL(), *pStream,
                                        GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
                }

                if ( GRFILTER_OK == nImpRet )
                    nFound = nRetFormat;

                // konnte sie nicht geladen werden?
                if ( nFound == USHRT_MAX )
                {
                    // Fehlermeldung
                    Window *pParent = GetParent();

                    if ( !pParent->IsReallyVisible() )
                        pParent = NULL;

                    USHORT nErrInfo;
                    IsGraphicError_Impl( nImpRet, nErrInfo );
                    InfoBox aInfoBox( pParent, pResImpl->pStrings[nErrInfo] );
                    aInfoBox.Execute();
                }
                else
                {
                    // passenden Filter setzen
                    String sFmt( ::GetImportFormatName(
                        *pGraphicFilter, nFound, pResImpl->pStrings ) );
                    SetCurFilter( sFmt );
                }

                if ( pPrevWin && pPrevWin->pGraphic &&
                     pPrevWin->pGraphic->IsAnimated() )
                    pPrevWin->pGraphic->StopAnimation( pPrevWin );
            }
        }
    }
    while ( nRet == RET_OK && nFound == USHRT_MAX );
    return nRet;
}

// -----------------------------------------------------------------------

void SvxImportGraphicDialog::SetPath( const String& rPath, BOOL bDir, BOOL bLink )
{
    // Leere Verzeichnisse ignorieren
    if ( bDir && !rPath.Len() )
        return;

    // Bei Pfaden ggf. Delimiter anhaengen
    String aPath( rPath );

    if ( !bDir && pLinkBox )
        pLinkBox->Check( bLink );

    if ( !aPath.Len() )
        return;

    INetURLObject aTmp;
    aTmp.SetSmartURL( rPath );

    if ( aTmp.GetProtocol() != INET_PROT_FILE )
    {
        SFX_APP()->PutItem( SfxStringItem( SID_IMPORT_GRAPH_LASTURL, rPath ) );
        return;
    }
    else if ( bDir )
    {
        aTmp.setFinalSlash();
        aPath = aTmp.getFSysPath( INetURLObject::FSYS_DETECT );
    }

    if ( !bDir || IsFolder_Impl( aTmp.GetMainURL() ) )
        SfxFileDialog::SetPath( aPath );
    else
    {
        String aTmp( pResImpl->pStrings[STR_PATH_NOT_FOUND1] );
        aTmp += aPath;
        aTmp += pResImpl->pStrings[STR_PATH_NOT_FOUND2];
        Window* pBoxParent;

        if ( IsInExecute() )
            pBoxParent = this;
        else
            pBoxParent = GetParent();
        InfoBox( pBoxParent, aTmp ).Execute();
    }
}

// -----------------------------------------------------------------------

Graphic* SvxImportGraphicDialog::GetGraphic() const
{
    Graphic* pGraphic = NULL;
    FASTBOOL bForcePreview = FALSE;

    if ( ( !pPrevWin || !pPrevWin->pGraphic ) && pPreviewBox )
    {
        // wenn die Grafik noch nicht geladen ist (Vorschau ausgeschaltet),
        // dann die Vorschau anschalten und dadurch die Grafik laden
        if ( !pPreviewBox->IsChecked() )
        {
            pPreviewBox->Check( TRUE );
            bForcePreview = TRUE;
        }
        ( (SvxImportGraphicDialog*)this )->PreviewHdl_Impl( NULL );
    }

    if ( pPrevWin )
    {
        INetURLObject aFile( pPrevWin->aFile );
        INetURLObject aCurFile( GetPath() );
        if ( aFile == aCurFile )
        {
            pGraphic = pPrevWin->pGraphic;

            // falls Grafik gelinkt eingef"ugt werden soll, native Link zur"ucksetzen
            if ( pGraphic && AsLink() )
                pGraphic->SetLink( GfxLink() );
        }
    }

    if ( bForcePreview && pPrevWin )
    {
        pGraphic = pPrevWin->CreateTempGraphic( pGraphic );
        pPreviewBox->Check( FALSE );
        ( (SvxImportGraphicDialog*)this )->PreviewHdl_Impl( (Button*)-1 );
        pPreviewBox->Enable();
    }

    return pGraphic;
}

// -----------------------------------------------------------------------

String SvxImportGraphicDialog::GetPath() const
{
    return SfxFileDialog::GetPath();
}

// -----------------------------------------------------------------------

IMPL_LINK_INLINE_START( SvxImportGraphicDialog, StandardHdl_Impl, Button *, EMPTYARG )
{
    SetPath( aStartPath, TRUE );
    return 0;
}
IMPL_LINK_INLINE_END( SvxImportGraphicDialog, StandardHdl_Impl, Button *, EMPTYARG )

// -----------------------------------------------------------------------

IMPL_LINK_INLINE_START( SvxImportGraphicDialog, PropertiesHdl_Impl, Button *, EMPTYARG )
{
    aPropertyLink.Call( this );
    return 0;
}
IMPL_LINK_INLINE_END( SvxImportGraphicDialog, PropertiesHdl_Impl, Button *, EMPTYARG )

// -----------------------------------------------------------------------

#ifdef WNT
#pragma optimize( "", off )
#endif

IMPL_LINK( SvxImportGraphicDialog, FilterHdl_Impl, Button *, EMPTYARG )
{
    GraphicFilter* pGraphicFilter = GetGrfFilter();
    USHORT nFormat = pGraphicFilter->GetImportFormatNumber( GetCurFilter() );

    if ( pGraphicFilter->DoImportDialog( this, nFormat ) )
        PreviewHdl_Impl( 0 );
    return 0;
}

// -----------------------------------------------------------------------

IMPL_LINK( SvxImportGraphicDialog, PreviewHdl_Impl, Button *, pButton )
{
    BOOL bPreview = FALSE;

    if ( pPreviewBox && pPreviewBox->IsChecked() )
    {
        if ( !bPreviewing )
        {
            WaitObject aWaitPtr( this );
            bPreview = TRUE;
            SvxGraphicHdl_Impl aGrfImp;
            aGrfImp.GraphicPreview( this );
        }
        else
            aPrevTimer.Start();
    }
    else
    {
        String aEmpty;
        bPreview = FALSE;
        pPrevWin->SetMessage( aEmpty );
        pPrevWin->SetGraphic( 0, aEmpty );
        // wieder zur"ucksetzen, damit das Kreuz auch richtig gemalt wird
        pPrevWin->SetMapMode( MAP_PIXEL );
    }

    if ( IsInExecute() )
        // wenn Preview "uber GetGraphic() eingeschaltet wurde, nicht merken
        SFX_APP()->PutItem( SfxBoolItem( SID_IMPORT_GRAPH_PREVIEW, bPreview ) );

    return 0;
}

#ifdef WNT
#pragma optimize( "", on )
#endif

// -----------------------------------------------------------------------

IMPL_LINK_INLINE_START( SvxImportGraphicDialog, TimeOutHdl_Impl, Timer *, EMPTYARG )
{
    PreviewHdl_Impl( 0 );
    return 0;
}
IMPL_LINK_INLINE_END( SvxImportGraphicDialog, TimeOutHdl_Impl, Timer *, EMPTYARG )

// -----------------------------------------------------------------------

IMPL_LINK( SvxImportGraphicDialog, FilterSelectHdl_Impl, void*, EMPTYARG )
{
    if ( !pFilterButton )
        return 0;

    GraphicFilter* pGraphicFilter = GetGrfFilter();
    BOOL bEnable = pGraphicFilter->HasImportDialog(
        pGraphicFilter->GetImportFormatNumber( GetCurFilter() ) );

    if ( bEnable )
        pFilterButton->Enable();
    else
        pFilterButton->Disable();
    return 1;
}

// -----------------------------------------------------------------------

long SvxImportGraphicDialog::OK()
{
    if ( !bPreviewing )
        aPrevTimer.Stop();
    return (long)!bPreviewing;
}

// -----------------------------------------------------------------------

void SvxImportGraphicDialog::SetPreviewing( BOOL bPrev )
{
    bPreviewing = bPrev;

    if ( pPreviewBox )
    {
        if ( !bPreviewing )
            pPreviewBox->Enable();
        else
            pPreviewBox->Disable();
    }
}

// SvxGraphicHdl_Impl ----------------------------------------------------

SvxGraphicHdl_Impl::SvxGraphicHdl_Impl()
{
    pPreviewGrf = NULL;
}

// -----------------------------------------------------------------------

SvxGraphicHdl_Impl::~SvxGraphicHdl_Impl()
{
}

// -----------------------------------------------------------------------

void SvxGraphicHdl_Impl::GraphicPreview( SvxImportGraphicDialog* pDlg )
{
    SvxImportGraphicRes_Impl* pResImpl =
        new SvxImportGraphicRes_Impl( RID_SVXRES_IMPORTGRAPHIC );

    // Grafik einlesen
    aPreviewPath = pDlg->GetPath();
    SvStream* pStream = NULL;
    SfxMedium* pMed = NULL;
    INetURLObject aUrl( aPreviewPath );

    if ( aUrl.HasError() || INET_PROT_NOT_VALID == aUrl.GetProtocol() )
    {
        aUrl.SetSmartProtocol( INET_PROT_FILE );
        aUrl.SetSmartURL( aPreviewPath );
    }
    else if ( INET_PROT_FILE != aUrl.GetProtocol() )
    {
        pMed = new SfxMedium( aPreviewPath, STREAM_READ, TRUE );
        pMed->SetTransferPriority( SFX_TFPRIO_SYNCHRON );
        pMed->DownLoad();       // nur mal das Medium anfassen (DownLoaden)
        pStream = pMed->GetInStream();
    }

    if ( !pStream && IsFolder_Impl( aPreviewPath ) )
    {
        aPreviewPath.Erase();
        delete pResImpl;
        delete pMed;
        return;
    }

    // OK in FileDialog verweigern
    pDlg->SetPreviewing( TRUE );

    // Filter erkennen
    GraphicFilter& rGrf = pDlg->GetFilter();
    USHORT nRetFormat = GRFILTER_FORMAT_DONTKNOW;
    USHORT nFormatNum = rGrf.GetImportFormatNumber( pDlg->GetCurFilter() );
    USHORT nImpRet = GRFILTER_OK;

    if ( !pStream )
        nImpRet = rGrf.CanImportGraphic( aUrl, nFormatNum, &nRetFormat );
    else
        nImpRet = rGrf.CanImportGraphic( aPreviewPath, *pStream,
                                         nFormatNum, &nRetFormat );

    if ( GRFILTER_OK != nImpRet )
    {
        if ( !pStream )
            nImpRet = rGrf.CanImportGraphic( aUrl, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
        else
            nImpRet = rGrf.CanImportGraphic( aPreviewPath, *pStream, GRFILTER_FORMAT_DONTKNOW, &nRetFormat );
    }
    String sFmt( rGrf.GetImportFormatName( nRetFormat ) );
    USHORT nError = InsertGraphic( aPreviewPath, sFmt );

    // Format ist ungleich Current Filter, jetzt mit AutoDetection
    if( nError == GRFILTER_FORMATERROR )
        nError = InsertGraphic( aPreviewPath, String() );

    USHORT nErrInfo;
    BOOL bError = IsGraphicError_Impl( nError, nErrInfo );

    if ( bError )
    {
        pDlg->GetPreviewWindow().SetMessage( pResImpl->pStrings[nErrInfo] );
        pPreviewGrf = 0;
    }
    pDlg->GetPreviewWindow().SetGraphic( pPreviewGrf, aPreviewPath );
    delete pResImpl;
    delete pMed;
}

// -----------------------------------------------------------------------

int SvxGraphicHdl_Impl::InsertGraphic( const String &rPath, const String &rFilter )
{
    Graphic* pImpGrf = new Graphic;

    int nRes = LoadGraphic( rPath, rFilter, *pImpGrf );

    if ( nRes )
    {
        delete pImpGrf;
        pImpGrf = 0;
    }
    pPreviewGrf = pImpGrf;
    return nRes;
}