summaryrefslogtreecommitdiff
path: root/basctl/source/basicide/moduldlg.cxx
blob: 5184fa867e7c2a67adab9028949f721ed1cfd357 (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
/*************************************************************************
 *
 *  $RCSfile: moduldlg.cxx,v $
 *
 *  $Revision: 1.24 $
 *
 *  last change: $Author: rt $ $Date: 2004-05-19 08:02:38 $
 *
 *  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 <memory>

#ifndef _SFX_IPFRM_HXX
#include <sfx2/ipfrm.hxx>
#endif

#include <ide_pch.hxx>

#pragma hdrstop

#include <moduldlg.hrc>
#include <moduldlg.hxx>
#include <basidesh.hrc>
#include <basidesh.hxx>
#include <bastypes.hxx>
#include <basobj.hxx>
#include <baside2.hrc>
#include <sbxitem.hxx>
#include <iderdll.hxx>

#ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
#include <com/sun/star/io/XInputStreamProvider.hpp>
#endif
#ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
#include <com/sun/star/script/XLibraryContainer2.hpp>
#endif
#ifndef _COM_SUN_STAR_SCRIPT_XLIBRARYCONTAINERPASSWORD_HPP_
#include <com/sun/star/script/XLibraryContainerPassword.hpp>
#endif

#ifndef _SBXCLASS_HXX //autogen
#include <svtools/sbx.hxx>
#endif

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


ExtBasicTreeListBox::ExtBasicTreeListBox( Window* pParent, const ResId& rRes )
    : BasicTreeListBox( pParent, rRes )
{
}



ExtBasicTreeListBox::~ExtBasicTreeListBox()
{
}

BOOL __EXPORT ExtBasicTreeListBox::EditingEntry( SvLBoxEntry* pEntry, Selection& )
{
    BOOL bRet = FALSE;

    if ( pEntry )
    {
        USHORT nDepth = GetModel()->GetDepth( pEntry );

        if ( nDepth == 2 )
        {
            SvLBoxEntry* pLibEntry = GetParent( pEntry );
            BasicManager* pBasMgr = BasicIDE::FindBasicManager( GetEntryText( GetParent( pLibEntry ) ) );
            if ( pBasMgr )
            {
                SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
                ::rtl::OUString aOULibName( GetEntryText( pLibEntry ) );
                Reference< script::XLibraryContainer2 > xModLibContainer( BasicIDE::GetModuleLibraryContainer( pShell ), UNO_QUERY );
                Reference< script::XLibraryContainer2 > xDlgLibContainer( BasicIDE::GetDialogLibraryContainer( pShell ), UNO_QUERY );
                if ( !( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
                        ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) )
                {
                    // allow editing only for libraries, which are not readonly
                    bRet = TRUE;
                }
            }
        }
    }

    return bRet;
}

BOOL __EXPORT ExtBasicTreeListBox::EditedEntry( SvLBoxEntry* pEntry, const String& rNewText )
{
    BOOL bValid = BasicIDE::IsValidSbxName( rNewText );
    String aCurText( GetEntryText( pEntry ) );
    if ( bValid && ( aCurText != rNewText ) )
    {
        SbxItem aSbxItem = GetSbxItem( pEntry );
        aSbxItem.SetName( rNewText );
        SfxObjectShell* pShell = aSbxItem.GetShell();
        String aLibName = aSbxItem.GetLibName();
        USHORT nType = aSbxItem.GetType();

        try
        {
            if ( nType == BASICIDE_TYPE_MODULE )
            {
                BasicIDE::RenameModule( pShell, aLibName, aCurText, rNewText );
            }
            else if ( nType == BASICIDE_TYPE_DIALOG )
            {
                BasicIDE::RenameDialog( pShell, aLibName, aCurText, rNewText );
            }

            BasicIDE::MarkDocShellModified( pShell );
        }
        catch ( container::ElementExistException& )
        {
            ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
            return FALSE;
        }
        catch ( container::NoSuchElementException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }

        BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
        SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
        SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
        if( pDispatcher )
        {
            pDispatcher->Execute( SID_BASICIDE_SBXRENAMED,
                                  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
        }

        // OV-Bug?!
        SetEntryText( pEntry, rNewText );
        SetCurEntry( pEntry );
        SetCurEntry( pEntry );
        Select( pEntry, FALSE );
        Select( pEntry );       // damit Handler gerufen wird => Edit updaten
    }
    if ( !bValid )
        ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute();
    return bValid;
}


DragDropMode __EXPORT ExtBasicTreeListBox::NotifyStartDrag( TransferDataContainer& rData, SvLBoxEntry* pEntry )
{
    DragDropMode nMode = SV_DRAGDROP_NONE;

    if ( pEntry )
    {
        USHORT nDepth = GetModel()->GetDepth( pEntry );

        if ( nDepth == 2 )
        {
            nMode = SV_DRAGDROP_CTRL_COPY;

            SvLBoxEntry* pLibEntry = GetParent( pEntry );
            BasicManager* pBasMgr = BasicIDE::FindBasicManager( GetEntryText( GetParent( pLibEntry ) ) );
            if ( pBasMgr )
            {
                SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
                ::rtl::OUString aOULibName( GetEntryText( pLibEntry ) );
                Reference< script::XLibraryContainer2 > xModLibContainer( BasicIDE::GetModuleLibraryContainer( pShell ), UNO_QUERY );
                Reference< script::XLibraryContainer2 > xDlgLibContainer( BasicIDE::GetDialogLibraryContainer( pShell ), UNO_QUERY );
                if ( !( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
                        ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) )
                {
                    // allow MOVE mode only for libraries, which are not readonly
                    nMode |= SV_DRAGDROP_CTRL_MOVE;
                }
            }
        }
    }

    return nMode;
}


BOOL __EXPORT ExtBasicTreeListBox::NotifyAcceptDrop( SvLBoxEntry* pEntry )
{
    // don't drop on a BasicManager (nDepth == 0)
    USHORT nDepth = pEntry ? GetModel()->GetDepth( pEntry ) : 0;
    BOOL bValid = nDepth ? TRUE : FALSE;

    // don't drop in the same library
    SvLBoxEntry* pSelected = FirstSelected();
    if ( ( nDepth == 1 ) && ( pEntry == GetParent( pSelected ) ) )
        bValid = FALSE;
    else if ( ( nDepth == 2 ) && ( GetParent( pEntry ) == GetParent( pSelected ) ) )
        bValid = FALSE;

    // don't drop on a library, which is not loaded, readonly or password protected
    if ( bValid && ( nDepth == 1 || nDepth == 2) )
    {
        SvLBoxEntry* pLibEntry = 0;
        if ( nDepth == 1 )
            pLibEntry = pEntry;
        else if ( nDepth == 2 )
            pLibEntry = GetParent( pEntry );

        BasicManager* pBasMgr = BasicIDE::FindBasicManager( GetEntryText( GetParent( pLibEntry ) ) );
        if ( pBasMgr )
        {
            SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
            ::rtl::OUString aOULibName( GetEntryText( pLibEntry ) );

            // check if module library is not loaded, readonly or password protected
            Reference< script::XLibraryContainer2 > xModLibContainer( BasicIDE::GetModuleLibraryContainer( pShell ), UNO_QUERY );
            if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
            {
                if ( !xModLibContainer->isLibraryLoaded( aOULibName ) )
                    bValid = FALSE;

                if ( xModLibContainer->isLibraryReadOnly( aOULibName ) )
                    bValid = FALSE;

                Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
                if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
                    bValid = FALSE;
            }

            // check if dialog library is not loaded or readonly
            Reference< script::XLibraryContainer2 > xDlgLibContainer( BasicIDE::GetDialogLibraryContainer( pShell ), UNO_QUERY );
            if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) )
            {
                if ( !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
                    bValid = FALSE;

                if ( xDlgLibContainer->isLibraryReadOnly( aOULibName ) )
                    bValid = FALSE;
            }
        }
        else
            bValid = FALSE;
    }

    // check, if module/dialog with this name is already existing in target library
    if ( bValid && ( nDepth == 1 || nDepth == 2 ) )
    {
        // get target parent
        SvLBoxEntry* pNewParent;
        if ( nDepth == 1 )
        {
            pNewParent = pEntry;
        }
        else if ( nDepth == 2 )
        {
            pNewParent = GetParent( pEntry );
        }

        // get target basic
        SbxVariable* pVar = FindVariable( pNewParent ); // parent is Basic
        DBG_ASSERT( pVar && pVar->ISA( StarBASIC ), "Parent ist kein Basic!" );
        StarBASIC* pDestBasic = (StarBASIC*)pVar;

        // get target shell and target library name
        String aDestLibName = pDestBasic->GetName();
        SfxObjectShell* pDestShell = 0;
        BasicManager* pDestBasMgr = BasicIDE::FindBasicManager( pDestBasic );
        if ( pDestBasMgr )
            pDestShell = BasicIDE::FindDocShell( pDestBasMgr );

        // a module/dialog is copied/moved
        SbxItem aSbxItem = GetSbxItem( pSelected );

        // get source module/dialog name
        String aSourceName = aSbxItem.GetName();

        // module/dialog already existing?
        if ( ( aSbxItem.GetType() == BASICIDE_TYPE_MODULE && BasicIDE::HasModule( pDestShell, aDestLibName, aSourceName ) ) ||
             ( aSbxItem.GetType() == BASICIDE_TYPE_DIALOG && BasicIDE::HasDialog( pDestShell, aDestLibName, aSourceName ) ) )
        {
            bValid = FALSE;
        }
    }

    return bValid;
}


BOOL __EXPORT ExtBasicTreeListBox::NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos )
{
    return NotifyCopyingMoving( pTarget, pEntry,
                                    rpNewParent, rNewChildPos, TRUE );
}


BOOL __EXPORT ExtBasicTreeListBox::NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos )
{
//  return FALSE;   // Wie kopiere ich ein SBX ?!
    return NotifyCopyingMoving( pTarget, pEntry,
                                    rpNewParent, rNewChildPos, FALSE );
}


BOOL __EXPORT ExtBasicTreeListBox::NotifyCopyingMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
                        SvLBoxEntry*& rpNewParent, ULONG& rNewChildPos, BOOL bMove )
{
    DBG_ASSERT( pEntry, "Kein Eintrag?" );  // Hier ASS ok, sollte nicht mit
    DBG_ASSERT( pTarget, "Kein Ziel?" );    // NULL (ganz vorne) erreicht werden
    USHORT nDepth = GetModel()->GetDepth( pTarget );
    DBG_ASSERT( nDepth, "Tiefe?" );
    if ( nDepth == 1 )
    {
        // Target = Basic => Modul/Dialog unter das Basic haengen...
        rpNewParent = pTarget;
        rNewChildPos = 0;
    }
    else if ( nDepth == 2 )
    {
        // Target = Modul/Dialog => Modul/Dialog unter das uebergeordnete Basic haengen...
        rpNewParent = GetParent( pTarget );
        rNewChildPos = GetModel()->GetRelPos( pTarget ) + 1;
    }

    USHORT nDestPos = (USHORT)rNewChildPos; // evtl. anpassen...

    // get target basic
    SbxVariable* pVar = FindVariable( rpNewParent );    // parent is Basic
    DBG_ASSERT( pVar && pVar->ISA( StarBASIC ), "Parent ist kein Basic!" );
    StarBASIC* pDestBasic = (StarBASIC*)pVar;

    // get target shell and target library name
    String aDestLibName = pDestBasic->GetName();
    SfxObjectShell* pDestShell = 0;
    BasicManager* pDestBasMgr = BasicIDE::FindBasicManager( pDestBasic );
    if ( pDestBasMgr )
        pDestShell = BasicIDE::FindDocShell( pDestBasMgr );

    // get sbx item
    SbxItem aSbxItem = GetSbxItem( FirstSelected() );

    // get source shell, library name and module/dialog name
    SfxObjectShell* pSourceShell = aSbxItem.GetShell();
    String aSourceLibName = aSbxItem.GetLibName();
    String aSourceName = aSbxItem.GetName();
    USHORT nType = aSbxItem.GetType();

    // get source basic
    BasicManager* pSourceBasMgr;
    if ( pSourceShell )
        pSourceBasMgr = pSourceShell->GetBasicManager();
    else
        pSourceBasMgr = SFX_APP()->GetBasicManager();

    StarBASIC* pSourceBasic = 0;
    if ( pSourceBasMgr )
        pSourceBasic = pSourceBasMgr->GetLib( aSourceLibName );
    DBG_ASSERT( pSourceBasic, "Woher kommt das Object?" );

    // get dispatcher
    BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
    SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;

    if ( bMove )    // move
    {
        // remove source module/dialog window
        if ( pSourceBasic != pDestBasic )
        {
            if( pDispatcher )
            {
                pDispatcher->Execute( SID_BASICIDE_SBXDELETED,
                                      SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
            }
        }

        try
        {
            if ( nType == BASICIDE_TYPE_MODULE )    // module
            {
                // get module
                ::rtl::OUString aModule = BasicIDE::GetModule( pSourceShell, aSourceLibName, aSourceName );

                // remove module from source library
                BasicIDE::RemoveModule( pSourceShell, aSourceLibName, aSourceName );
                BasicIDE::MarkDocShellModified( pSourceShell );

                // insert module into target library
                BasicIDE::InsertModule( pDestShell, aDestLibName, aSourceName, aModule );
                BasicIDE::MarkDocShellModified( pDestShell );
            }
            else if ( nType == BASICIDE_TYPE_DIALOG )   // dialog
            {
                // get dialog
                Reference< io::XInputStreamProvider > xISP( BasicIDE::GetDialog( pSourceShell, aSourceLibName, aSourceName ) );

                if ( xISP.is() )
                {
                    // remove dialog from source library
                    BasicIDE::RemoveDialog( pSourceShell, aSourceLibName, aSourceName );
                    BasicIDE::MarkDocShellModified( pSourceShell );

                    // insert dialog into target library
                    BasicIDE::InsertDialog( pDestShell, aDestLibName, aSourceName, xISP );
                    BasicIDE::MarkDocShellModified( pDestShell );
                }
            }
        }
        catch ( container::ElementExistException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
        catch ( container::NoSuchElementException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
    }
    else    // copy
    {
        try
        {
            if ( nType == BASICIDE_TYPE_MODULE )    // module
            {
                // get module
                ::rtl::OUString aModule = BasicIDE::GetModule( pSourceShell, aSourceLibName, aSourceName );

                // insert module into target library
                BasicIDE::InsertModule( pDestShell, aDestLibName, aSourceName, aModule );
                BasicIDE::MarkDocShellModified( pDestShell );
            }
            else if ( nType == BASICIDE_TYPE_DIALOG )   // dialog
            {
                // get dialog
                Reference< io::XInputStreamProvider > xISP( BasicIDE::GetDialog( pSourceShell, aSourceLibName, aSourceName ) );

                if ( xISP.is() )
                {
                    // insert dialog into target library
                    BasicIDE::InsertDialog( pDestShell, aDestLibName, aSourceName, xISP );
                    BasicIDE::MarkDocShellModified( pDestShell );
                }
            }
        }
        catch ( container::ElementExistException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
        catch ( container::NoSuchElementException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
    }

    // create target module/dialog window
    if ( pSourceBasic != pDestBasic )
    {
        // set sbxitem to target lib
        aSbxItem.SetShell( pDestShell );
        aSbxItem.SetLibName( aDestLibName );

        if( pDispatcher )
        {
            pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
                                  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
        }
    }

    return 2;   // Aufklappen...
}


OrganizeDialog::OrganizeDialog( Window* pParent, INT16 tabId )
    :   TabDialog( pParent, IDEResId( RID_TD_ORGANIZE ) ),
        aTabCtrl( this, IDEResId( RID_TC_ORGANIZE ) )
{
    FreeResource();
    aTabCtrl.SetActivatePageHdl( LINK( this, OrganizeDialog, ActivatePageHdl ) );
    if( tabId == 0 )
    {
        aTabCtrl.SetCurPageId( RID_TP_MOD );
    }
    else if ( tabId == 1 )
    {
        aTabCtrl.SetCurPageId( RID_TP_DLG );
    }
    else
    {
        aTabCtrl.SetCurPageId( RID_TP_LIB );
    }


    ActivatePageHdl( &aTabCtrl );

    BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
    SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
    if( pDispatcher )
    {
        pDispatcher->Execute( SID_BASICIDE_STOREALLMODULESOURCES );
    }
}

void OrganizeDialog::SetCurrentModule( const String& rMacroDescr )
{
    TabPage* pTP = aTabCtrl.GetTabPage( RID_TP_MOD );
    if ( pTP )
        ((ObjectPage*)pTP)->SetCurrentModule( rMacroDescr );
}

__EXPORT OrganizeDialog::~OrganizeDialog()
{
    for ( USHORT i = 0; i < aTabCtrl.GetPageCount(); i++ )
        delete aTabCtrl.GetTabPage( aTabCtrl.GetPageId( i ) );
};

short OrganizeDialog::Execute()
{
    Window* pPrevDlgParent = Application::GetDefDialogParent();
    Application::SetDefDialogParent( this );
    short nRet = TabDialog::Execute();
    Application::SetDefDialogParent( pPrevDlgParent );
    return nRet;
}


IMPL_LINK( OrganizeDialog, ActivatePageHdl, TabControl *, pTabCtrl )
{
    USHORT nId = pTabCtrl->GetCurPageId();
    // Wenn TabPage noch nicht erzeugt wurde, dann erzeugen
    if ( !pTabCtrl->GetTabPage( nId ) )
    {
        TabPage* pNewTabPage = 0;
        switch ( nId )
        {
            case RID_TP_MOD:
            {
                pNewTabPage = new ObjectPage( pTabCtrl, BROWSEMODE_MODULES );
                ((ObjectPage*)pNewTabPage)->SetTabDlg( this );
            }
            break;
            case RID_TP_DLG:
            {
                pNewTabPage = new ObjectPage( pTabCtrl, BROWSEMODE_OBJS );
                ((ObjectPage*)pNewTabPage)->SetTabDlg( this );
            }
            break;
            case RID_TP_LIB:
            {
                pNewTabPage = new LibPage( pTabCtrl );
                ((LibPage*)pNewTabPage)->SetTabDlg( this );
            }
            break;
            default:    DBG_ERROR( "PageHdl: Unbekannte ID!" );
        }
        DBG_ASSERT( pNewTabPage, "Keine Page!" );
        pTabCtrl->SetTabPage( nId, pNewTabPage );
    }
    return 0;
}




ObjectPage::ObjectPage( Window * pParent, USHORT nMode ) :
        TabPage(        pParent,IDEResId( RID_TP_MODULS ) ),
        aLibText(       this,   IDEResId( RID_STR_LIB ) ),
        aBasicBox(      this,   IDEResId( RID_TRLBOX ) ),
//      aEdit(          this,   IDEResId( RID_EDIT ) ),
        aEditButton(    this,   IDEResId( RID_PB_EDIT ) ),
        aCloseButton(   this,   IDEResId( RID_PB_CLOSE ) ),
        aNewModButton(  this,   IDEResId( RID_PB_NEWMOD ) ),
        aNewDlgButton(  this,   IDEResId( RID_PB_NEWDLG ) ),
        aDelButton(     this,   IDEResId( RID_PB_DELETE ) )
{
    FreeResource();
    pTabDlg = 0;

    aEditButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
    aDelButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
    aCloseButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
    aBasicBox.SetSelectHdl( LINK( this, ObjectPage, BasicBoxHighlightHdl ) );

//  aEdit.SetModifyHdl( LINK( this, ObjectPage, EditModifyHdl ) );

    if( nMode == BROWSEMODE_MODULES )
    {
        aNewModButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
        aNewDlgButton.Hide();
    }
    else if ( nMode == BROWSEMODE_OBJS )
    {
        aNewDlgButton.SetClickHdl( LINK( this, ObjectPage, ButtonHdl ) );
        aNewModButton.Hide();
    }

    aBasicBox.SetDragDropMode( SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY );
    aBasicBox.EnableInplaceEditing( TRUE );

    aBasicBox.SetMode( nMode );
    aBasicBox.SetWindowBits( WB_HASLINES );

    aEditButton.GrabFocus();
    CheckButtons();
}

void __EXPORT ObjectPage::ActivatePage()
{
    aBasicBox.Clear();
    aBasicBox.ScanAllBasics();
    aBasicBox.ExpandAllTrees();

    ImplMarkCurrentModule();
}

void ObjectPage::ImplMarkCurrentModule()
{
    if ( aCurEntryDescr.Len() )
    {
        SvLBoxEntry* pEntry = FindMostMatchingEntry( aBasicBox, aCurEntryDescr );
        if ( pEntry )
            aBasicBox.SetCurEntry( pEntry );
    }
}

void __EXPORT ObjectPage::DeactivatePage()
{
    SvLBoxEntry* pEntry = aBasicBox.GetCurEntry();
    if ( pEntry )
        aCurEntryDescr = CreateEntryDescription( aBasicBox, pEntry );
}

void ObjectPage::CheckButtons()
{
    BOOL bReadOnly = FALSE;
    BOOL bEnableNew = FALSE;

//  String aEditText( aEdit.GetText() );

    // Der Name muss nur im aktuellen Basic/Lib eindeutig sein
    SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
    USHORT nDepth = pCurEntry ? aBasicBox.GetModel()->GetDepth( pCurEntry ) : 0;

    // enable/disable edit button
    if ( nDepth == 2 )
        aEditButton.Enable();
    else
        aEditButton.Disable();

    // check, if corresponding libraries are readonly
    if ( nDepth == 1 || nDepth == 2 )
    {
        SvLBoxEntry* pLibEntry = 0;
        if ( nDepth == 1 )
            pLibEntry = pCurEntry;
        else if ( nDepth == 2)
            pLibEntry = aBasicBox.GetParent( pCurEntry );
        BasicManager* pBasMgr = BasicIDE::FindBasicManager( aBasicBox.GetEntryText( aBasicBox.GetParent( pLibEntry ) ) );
        if ( pBasMgr )
        {
            SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
            ::rtl::OUString aOULibName( aBasicBox.GetEntryText( pLibEntry ) );
            Reference< script::XLibraryContainer2 > xModLibContainer( BasicIDE::GetModuleLibraryContainer( pShell ), UNO_QUERY );
            Reference< script::XLibraryContainer2 > xDlgLibContainer( BasicIDE::GetDialogLibraryContainer( pShell ), UNO_QUERY );
            if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
                 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
            {
                bReadOnly = TRUE;
            }
        }
    }

    // enable/disable new module/dialog buttons
    if ( bReadOnly )
    {
        aNewModButton.Disable();
        aNewDlgButton.Disable();
    }
    else
    {
        aNewModButton.Enable();
        aNewDlgButton.Enable();
    }

    SvLBoxEntry* pEntry = pCurEntry;
    while ( pEntry && ( ((BasicEntry*)pEntry->GetUserData())->GetType() != OBJTYPE_LIB ) )
        pEntry = aBasicBox.GetParent( pEntry );

/*
    if ( pEntry && aEditText.Len() )
    {
        String aLibText = aBasicBox.GetEntryText( pEntry );
        if ( ( pEntry != pCurEntry ) || ( aLibText != aEditText ) )
            bEnableNew = TRUE;
        pEntry = aBasicBox.FirstChild( pEntry );
        while ( pEntry )
        {
            String aEntryText = aBasicBox.GetEntryText( pEntry );
            if ( aEntryText == aEditText )
            {
                bEnableNew = FALSE;
                break;
            }
            pEntry = aBasicBox.NextSibling( pEntry );
        }
    }
*/
    if ( bEnableNew )
    {
        aDelButton.Disable();
    }
    else
    {
        if ( pCurEntry )
        {
            BYTE nType = ((BasicEntry*)pCurEntry->GetUserData())->GetType();
            if ( !bReadOnly && ( ( nType == OBJTYPE_OBJECT ) || ( nType == OBJTYPE_MODULE ) ) )
                aDelButton.Enable();
            else
                aDelButton.Disable();
        }
    }
}

IMPL_LINK( ObjectPage, BasicBoxHighlightHdl, BasicTreeListBox *, pBox )
{
    if ( !pBox->IsSelected( pBox->GetHdlEntry() ) )
        return 0;

/*
    SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
    if ( pCurEntry )
    {
        USHORT nDepth = aBasicBox.GetModel()->GetDepth( pCurEntry );
        if ( nDepth == 2 )
            aEdit.SetText( aBasicBox.GetEntryText( pCurEntry ) );
        else
            aEdit.SetText( String() );
    }
*/
    CheckButtons();
    return 0;
}


/*
IMPL_LINK_INLINE_START( ObjectPage, EditModifyHdl, Edit *, pEdit )
{
    CheckButtons();
    return 0;
}
IMPL_LINK_INLINE_END( ObjectPage, EditModifyHdl, Edit *, pEdit )
*/

IMPL_LINK( ObjectPage, ButtonHdl, Button *, pButton )
{
    if ( pButton == &aEditButton )
    {
        SfxViewFrame* pViewFrame = SfxViewFrame::Current();
        SfxDispatcher* pDispatcher = ( pViewFrame && !pViewFrame->ISA( SfxInPlaceFrame ) ) ? pViewFrame->GetDispatcher() : NULL;
        if ( pDispatcher )
        {
            pDispatcher->Execute( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON );
        }
        else
        {
            SfxAllItemSet aArgs( SFX_APP()->GetPool() );
            SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs );
            SFX_APP()->ExecuteSlot( aRequest );
        }
        BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
        pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
        pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
        SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
        DBG_ASSERT( pCurEntry, "Entry?!" );
        if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) == 2 )
        {
            SbxItem aSbxItem = aBasicBox.GetSbxItem( pCurEntry );
            if( pDispatcher )
            {
                pDispatcher->Execute( SID_BASICIDE_SHOWSBX, SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
            }
        }
        else    // Nur Lib selektiert
        {
            DBG_ASSERT( aBasicBox.GetModel()->GetDepth( pCurEntry ) == 1, "Kein LibEntry?!" );
            String aLib( aBasicBox.GetEntryText( pCurEntry ) );
            String aBasMgr( aBasicBox.GetEntryText( aBasicBox.GetParent( pCurEntry ) ) );
            String aLibAndMgr( CreateMgrAndLibStr( aBasMgr, aLib ) );
            SfxStringItem aLibName( SID_BASICIDE_ARG_LIBNAME, aLibAndMgr );
            if( pDispatcher )
            {
                pDispatcher->Execute( SID_BASICIDE_LIBSELECTED, SFX_CALLMODE_ASYNCHRON, &aLibName, 0L );
            }
        }
        EndTabDialog( 1 );
    }
    else if ( pButton == &aNewModButton )
        NewModule();
    else if ( pButton == &aNewDlgButton )
        NewDialog();
    else if ( pButton == &aDelButton )
        DeleteCurrent();
    else if ( pButton == &aCloseButton )
        EndTabDialog( 0 );

    return 0;
}



StarBASIC* ObjectPage::GetSelectedBasic()
{
    StarBASIC* pBasic = 0;
    String aLibName, aModOrDlg, aSub;
    BasicManager* pBasMgr = aBasicBox.GetSelectedSbx( aLibName, aModOrDlg, aSub );
    DBG_ASSERT( pBasMgr, "Kein BasicManager!" );
    SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );

    if ( !aLibName.Len() )
        aLibName = String::CreateFromAscii("Standard");

    if ( aLibName.Len() )
    {
        BOOL bOK = TRUE;
        ::rtl::OUString aOULibName( aLibName );

        // check, if the module library is not loaded
        Reference< script::XLibraryContainer > xModLibContainer( BasicIDE::GetModuleLibraryContainer( pShell ), UNO_QUERY );
        if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) )
        {
            // check password
            Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
            if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
            {
                String aPassword;
                bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
            }

            // load library
            if ( bOK )
                xModLibContainer->loadLibrary( aOULibName );
        }

        // check, if the dialog library is not loaded
        Reference< script::XLibraryContainer > xDlgLibContainer( BasicIDE::GetDialogLibraryContainer( pShell ), UNO_QUERY );
        if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) )
        {
            // load library
            if ( bOK )
                xDlgLibContainer->loadLibrary( aOULibName );
        }

        // get Basic
        if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) )
        {
            if ( bOK )
            {
                pBasic = pBasMgr->GetLib( aLibName );
                DBG_ASSERT( pBasic, "ObjectPage::GetSelectedBasic: Error loading library!" );
            }
        }
    }

    return pBasic;
}

/*
BOOL ObjectPage::UseEditText()
{
    SvLBoxEntry* pSel = aBasicBox.FirstSelected();
    if ( pSel )
    {
        String aSelected( aBasicBox.GetEntryText( pSel ) );
        if ( aSelected == aEdit.GetText() )
            return FALSE;
    }
    return TRUE;
}
*/

void ObjectPage::NewModule()
{
    StarBASIC* pLib = GetSelectedBasic();
    DBG_ASSERT( pLib, "Keine Lib!" );
    if ( pLib )
    {
        String aLibName = pLib->GetName();
        BasicManager* pBasMgr = BasicIDE::FindBasicManager( pLib );
        if ( pBasMgr )
        {
            SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
            String aModName;
            createModImpl( static_cast<Window*>( this ), pShell,
                           pLib, aBasicBox, aLibName, aModName, true );
        }
    }
}

void ObjectPage::NewDialog()
{
    StarBASIC* pLib = GetSelectedBasic();
    DBG_ASSERT( pLib, "Keine Lib!" );
    if ( pLib )
    {
        String aLibName = pLib->GetName();
        BasicManager* pBasMgr = BasicIDE::FindBasicManager( pLib );
        if ( pBasMgr )
        {
            SfxObjectShell* pShell = BasicIDE::FindDocShell( pBasMgr );
            std::auto_ptr< NewObjectDialog > xNewDlg(
                new NewObjectDialog(this, NEWOBJECTMODE_DLG, true));
            xNewDlg->SetObjectName( BasicIDE::CreateDialogName( pShell, aLibName ) );

            if (xNewDlg->Execute() != 0)
            {
                String aDlgName( xNewDlg->GetObjectName() );
                if (aDlgName.Len() == 0)
                    aDlgName = BasicIDE::CreateDialogName(pShell, aLibName);

                try
                {
                    Reference< io::XInputStreamProvider > xISP( BasicIDE::CreateDialog( pShell, aLibName, aDlgName ) );
                    SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, pShell, aLibName, aDlgName, BASICIDE_TYPE_DIALOG );
                    BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
                    SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
                    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
                    if( pDispatcher )
                    {
                        pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
                                              SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
                    }
                    SvLBoxEntry* pLibEntry = aBasicBox.FindLibEntry( pLib );
                    DBG_ASSERT( pLibEntry, "Libeintrag nicht gefunden!" );
                    SvLBoxEntry * pEntry = aBasicBox.insertEntry(
                        aDlgName, IMGID_OBJECT, pLibEntry, false,
                        std::auto_ptr< BasicEntry >(new BasicEntry(
                                                        OBJTYPE_OBJECT)));
                    DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" );
                    aBasicBox.SetCurEntry( pEntry );
                    aBasicBox.Select( aBasicBox.GetCurEntry() );        // OV-Bug?!
                }
                catch ( container::ElementExistException& )
                {
                    ErrorBox( this, WB_OK | WB_DEF_OK,
                            String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
                }
                catch ( container::NoSuchElementException& e )
                {
                    ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
                    DBG_ERROR( aBStr.GetBuffer() );
                }
            }
        }
    }
}

void ObjectPage::DeleteCurrent()
{
    SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
    DBG_ASSERT( pCurEntry, "Kein aktueller Eintrag!" );
    SbxItem aSbxItem = aBasicBox.GetSbxItem( pCurEntry );
    SfxObjectShell* pShell = aSbxItem.GetShell();
    String aLibName = aSbxItem.GetLibName();
    String aName = aSbxItem.GetName();
    USHORT nType = aSbxItem.GetType();

    if ( ( nType == BASICIDE_TYPE_MODULE && QueryDelModule( aName, this ) ) ||
         ( nType == BASICIDE_TYPE_DIALOG && QueryDelDialog( aName, this ) ) )
    {
        aBasicBox.GetModel()->Remove( pCurEntry );
        if ( aBasicBox.GetCurEntry() )  // OV-Bug ?
            aBasicBox.Select( aBasicBox.GetCurEntry() );
        BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
        SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
        SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
        if( pDispatcher )
        {
            pDispatcher->Execute( SID_BASICIDE_SBXDELETED,
                                  SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
        }

        try
        {
            if ( nType == BASICIDE_TYPE_MODULE )
            {
                BasicIDE::RemoveModule( pShell, aLibName, aName );
            }
            else if ( nType == BASICIDE_TYPE_DIALOG )
            {
                BasicIDE::RemoveDialog( pShell, aLibName, aName );
            }

            BasicIDE::MarkDocShellModified( pShell );
        }
        catch ( container::NoSuchElementException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
    }
}



void ObjectPage::EndTabDialog( USHORT nRet )
{
    DBG_ASSERT( pTabDlg, "TabDlg nicht gesetzt!" );
    if ( pTabDlg )
        pTabDlg->EndDialog( nRet );
}


LibDialog::LibDialog( Window* pParent )
    : ModalDialog( pParent, IDEResId( RID_DLG_LIBS ) ),
        aOKButton(      this, IDEResId( RID_PB_OK ) ),
        aCancelButton(  this, IDEResId( RID_PB_CANCEL ) ),
        aStorageName(   this, IDEResId( RID_FT_STORAGENAME ) ),
        aLibBox(        this, IDEResId( RID_CTRL_LIBS ) ),
        aFixedLine(     this, IDEResId( RID_FL_OPTIONS ) ),
        aReferenceBox(  this, IDEResId( RID_CB_REF ) ),
        aReplaceBox(    this, IDEResId( RID_CB_REPL ) )
{
    SetText( String( IDEResId( RID_STR_APPENDLIBS ) ) );
    FreeResource();
}


LibDialog::~LibDialog()
{
}

void LibDialog::SetStorageName( const String& rName )
{
    String aName( IDEResId( RID_STR_FILENAME ) );
    aName += rName;
    aStorageName.SetText( aName );
}

// Helper function
SbModule* createModImpl( Window* pWin, SfxObjectShell* pShell, StarBASIC* pLib,
    BasicTreeListBox& rBasicBox, const String& aLibName, String aModName, bool bMain )
{
    SbModule* pModule = NULL;

    std::auto_ptr< NewObjectDialog > xNewDlg(
        new NewObjectDialog( pWin, NEWOBJECTMODE_MOD, true ) );
    if ( aModName.Len() == 0 )
        aModName = BasicIDE::CreateModuleName( pShell, aLibName );
    xNewDlg->SetObjectName( aModName );

    if (xNewDlg->Execute() != 0)
    {
        if ( xNewDlg->GetObjectName().Len() )
            aModName = xNewDlg->GetObjectName();

        try
        {
            ::rtl::OUString aModule = BasicIDE::CreateModule( pShell, aLibName, aModName, bMain );
            pModule = pLib->FindModule( aModName );

            SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, pShell, aLibName, aModName, BASICIDE_TYPE_MODULE );
            BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
            SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
            SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
            if( pDispatcher )
            {
                pDispatcher->Execute( SID_BASICIDE_SBXINSERTED,
                                      SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
            }
            SvLBoxEntry* pLibEntry = rBasicBox.FindLibEntry( pLib );
            DBG_ASSERT( pLibEntry, "Libeintrag nicht gefunden!" );
            SvLBoxEntry * pEntry = rBasicBox.insertEntry(
                aModName, IMGID_MODULE, pLibEntry, false,
                std::auto_ptr< BasicEntry >(new BasicEntry(
                                                OBJTYPE_MODULE)));
            DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" );
            rBasicBox.SetCurEntry( pEntry );
            rBasicBox.Select( rBasicBox.GetCurEntry() );        // OV-Bug?!
        }
        catch ( container::ElementExistException& )
        {
            ErrorBox( pWin, WB_OK | WB_DEF_OK,
                    String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute();
        }
        catch ( container::NoSuchElementException& e )
        {
            ByteString aBStr( String(e.Message), RTL_TEXTENCODING_ASCII_US );
            DBG_ERROR( aBStr.GetBuffer() );
        }
    }
    return pModule;
}