xref: /trunk/main/basctl/source/basicide/bastype2.hxx (revision 96821c26)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _BASTYPE2_HXX
24 #define _BASTYPE2_HXX
25 
26 #include "doceventnotifier.hxx"
27 
28 #include <memory>
29 #include "tools/solar.h"
30 
31 #define _SVICNVW_HXX
32 #include <svtools/svtreebx.hxx>
33 #include <svl/lstner.hxx>
34 #include <basic/sbstar.hxx>
35 #include <sbxitem.hxx>
36 #include "basobj.hxx"
37 
38 enum BasicEntryType { OBJ_TYPE_UNKNOWN, OBJ_TYPE_DOCUMENT, OBJ_TYPE_LIBRARY, OBJ_TYPE_MODULE, OBJ_TYPE_DIALOG, OBJ_TYPE_METHOD, OBJ_TYPE_DOCUMENT_OBJECTS, OBJ_TYPE_USERFORMS, OBJ_TYPE_NORMAL_MODULES, OBJ_TYPE_CLASS_MODULES };
39 
40 #define BROWSEMODE_MODULES		0x01
41 #define BROWSEMODE_SUBS			0x02
42 #define BROWSEMODE_DIALOGS		0x04
43 
44 class SbMethod;
45 class SbxObject;
46 class SbModule;
47 class SvLBoxEntry;
48 class SbxVariable;
49 class String;
50 
51 
52 class BasicEntry
53 {
54 private:
55     BasicEntryType  m_eType;
56 
57 public:
BasicEntry(BasicEntryType eType)58                     BasicEntry( BasicEntryType eType )  { m_eType = eType; }
BasicEntry(const BasicEntry & r)59                     BasicEntry( const BasicEntry& r )   { m_eType = r.m_eType; }
60     virtual         ~BasicEntry();
61 
GetType() const62     BasicEntryType  GetType() const                     { return m_eType; }
63 };
64 
65 class BasicDocumentEntry : public BasicEntry
66 {
67 private:
68     ScriptDocument      m_aDocument;
69     LibraryLocation     m_eLocation;
70 
71 public:
72                     BasicDocumentEntry( const ScriptDocument& rDocument, LibraryLocation eLocation, BasicEntryType eType = OBJ_TYPE_DOCUMENT );
73     virtual         ~BasicDocumentEntry();
74 
75     const ScriptDocument&
GetDocument() const76                     GetDocument() const { return m_aDocument; }
GetLocation() const77     LibraryLocation GetLocation() const { return m_eLocation; }
78 };
79 
80 class BasicLibEntry : public BasicDocumentEntry
81 {
82 private:
83     String          m_aLibName;
84 
85 public:
86                     BasicLibEntry( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, BasicEntryType eType = OBJ_TYPE_LIBRARY );
87     virtual         ~BasicLibEntry();
88 
GetLibName() const89     const String&   GetLibName() const { return m_aLibName; }
90 };
91 
92 class BasicEntryDescriptor
93 {
94     ScriptDocument          m_aDocument;
95     LibraryLocation         m_eLocation;
96     String                  m_aLibName;
97     String                  m_aLibSubName;  // for vba entry:  Document Objects, Class Modules, Forms and Normal Modules
98     String                  m_aName;
99     String                  m_aMethodName;
100     BasicEntryType          m_eType;
101 
102 public:
103                             BasicEntryDescriptor();
104 	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, BasicEntryType eType );
105 	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, const String& rMethodName, BasicEntryType eType );
106     virtual                 ~BasicEntryDescriptor();
107 
108                             BasicEntryDescriptor( const BasicEntryDescriptor& rDesc );
109     BasicEntryDescriptor&   operator=( const BasicEntryDescriptor& rDesc );
110     bool                    operator==( const BasicEntryDescriptor& rDesc ) const;
111 
112     const ScriptDocument&
GetDocument() const113                             GetDocument() const { return m_aDocument; }
SetDocument(const ScriptDocument & rDocument)114     void                    SetDocument( const ScriptDocument& rDocument ) { m_aDocument = rDocument; }
115 
GetLocation() const116     LibraryLocation         GetLocation() const { return m_eLocation; }
SetLocation(LibraryLocation eLocation)117     void                    SetLocation( LibraryLocation eLocation ) { m_eLocation = eLocation; }
118 
GetLibName() const119     const String&           GetLibName() const { return m_aLibName; }
SetLibName(const String & aLibName)120     void                    SetLibName( const String& aLibName ) { m_aLibName = aLibName; }
121 
GetLibSubName() const122     const String&           GetLibSubName() const { return m_aLibSubName; }
SetLibSubName(const String & aLibSubName)123     void                    SetLibSubName( const String& aLibSubName ) { m_aLibSubName = aLibSubName; }
124 
GetName() const125     const String&           GetName() const { return m_aName; }
SetName(const String & aName)126     void                    SetName( const String& aName ) { m_aName = aName; }
127 
GetMethodName() const128     const String&           GetMethodName() const { return m_aMethodName; }
SetMethodName(const String & aMethodName)129     void                    SetMethodName( const String& aMethodName ) { m_aMethodName = aMethodName; }
130 
GetType() const131     BasicEntryType          GetType() const { return m_eType; }
SetType(BasicEntryType eType)132     void                    SetType( BasicEntryType eType ) { m_eType = eType; }
133 };
134 
135 
136 /****************************************
137 	Zuordnung von Typen und Pointern in BasicEntrys:
138 
139 	OBJ_TYPE_DOCUMENT        BasicDocumentEntry
140 	OBJ_TYPE_LIBRARY         BasicEntry
141     OBJ_TYPE_MODULE          BasicEntry
142     OBJ_TYPE_DIALOG          BasicEntry
143     OBJ_TYPE_METHOD          BasicEntry
144 
145 ******************************************/
146 
147 class BasicTreeListBox  :public SvTreeListBox
148                         ,public ::basctl::DocumentEventListener
149 {
150 private:
151     sal_uInt16                          nMode;
152     ::basctl::DocumentEventNotifier m_aNotifier;
153 
154     void            SetEntryBitmaps( SvLBoxEntry * pEntry, const Image& rImage, const Image& rImageHC );
155 
156 protected:
157 	virtual void			RequestingChilds( SvLBoxEntry* pParent );
158 	virtual void 			ExpandedHdl();
159 	virtual SvLBoxEntry* 	CloneEntry( SvLBoxEntry* pSource );
160 	virtual long			ExpandingHdl();
161 
162     void                    ImpCreateLibEntries( SvLBoxEntry* pShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation );
163 	void 					ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName );
164 	void 					ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName );
165 	void 					ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const String& rLibName );
166     SvLBoxEntry*            ImpFindEntry( SvLBoxEntry* pParent, const String& rText );
167 
168     // DocumentEventListener
169     virtual void onDocumentCreated( const ScriptDocument& _rDocument );
170     virtual void onDocumentOpened( const ScriptDocument& _rDocument );
171     virtual void onDocumentSave( const ScriptDocument& _rDocument );
172     virtual void onDocumentSaveDone( const ScriptDocument& _rDocument );
173     virtual void onDocumentSaveAs( const ScriptDocument& _rDocument );
174     virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument );
175     virtual void onDocumentClosed( const ScriptDocument& _rDocument );
176     virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument );
177     virtual void onDocumentModeChanged( const ScriptDocument& _rDocument );
178 
179 public:
180 					BasicTreeListBox( Window* pParent, const ResId& rRes );
181 					~BasicTreeListBox();
182 
183     void            ScanEntry( const ScriptDocument& rDocument, LibraryLocation eLocation );
184     void            ScanAllEntries();
185 	void			UpdateEntries();
186 
187 	sal_Bool			IsEntryProtected( SvLBoxEntry* pEntry );
188 
SetMode(sal_uInt16 nM)189 	void			SetMode( sal_uInt16 nM ) { nMode = nM; }
GetMode() const190 	sal_uInt16			GetMode() const { return nMode; }
191 
192 	SbModule*		FindModule( SvLBoxEntry* pEntry );
193 	SbxVariable*	FindVariable( SvLBoxEntry* pEntry );
194     SvLBoxEntry*    FindRootEntry( const ScriptDocument& rDocument, LibraryLocation eLocation );
195     SvLBoxEntry*    FindEntry( SvLBoxEntry* pParent, const String& rText, BasicEntryType eType );
196 
197     BasicEntryDescriptor    GetEntryDescriptor( SvLBoxEntry* pEntry );
198 
199     sal_uInt16          ConvertType( BasicEntryType eType );
200     bool            IsValidEntry( SvLBoxEntry* pEntry );
201 
202     SvLBoxEntry*    AddEntry( const String& rText, const Image& rImage, const Image& rImageHC,
203                               SvLBoxEntry* pParent, bool bChildrenOnDemand,
204                               std::auto_ptr< BasicEntry > aUserData );
205 
206     String          GetRootEntryName( const ScriptDocument& rDocument, LibraryLocation eLocation ) const;
207     void            GetRootEntryBitmaps( const ScriptDocument& rDocument, Image& rImage, Image& rImageHC );
208 
209     void            SetCurrentEntry( BasicEntryDescriptor& rDesc );
210 
211 private:
212     LibraryType     GetLibraryType() const;
213 };
214 
215 #endif	// _BASTYPE2_HXX
216