xref: /trunk/main/basctl/source/inc/bastypes.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 _BASTYPES_HXX
24 #define _BASTYPES_HXX
25 
26 #include <svheader.hxx>
27 
28 #include <iderid.hxx>
29 
30 #include "scriptdocument.hxx"
31 
32 class ModulWindow;
33 class SfxRequest;
34 class SvTreeListBox;
35 class SvLBoxEntry;
36 class ScrollBar;
37 class SbModule;
38 class BasicManager;
39 class SfxItemSet;
40 #include <vcl/dockwin.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <basic/sbstar.hxx>
43 
44 #include <iderid.hxx>
45 
46 #include <tools/table.hxx>
47 
48 #include <svtools/tabbar.hxx>
49 #include <com/sun/star/script/XLibraryContainer.hpp>
50 
51 #include <hash_map>
52 
53 #define LINE_SEP_CR		0x0D
54 #define LINE_SEP		0x0A
55 
56 // Implementation: baside2b.cxx
57 sal_Int32 searchEOL( const ::rtl::OUString& rStr, sal_Int32 fromIndex );
58 
59 
60 // Bedeutung von bToBeKilled:
61 // Wenn in Reschedule-Schleife, darf ich das Fenster nicht zerstoeren.
62 // Es muss erst aus der Reschedule-Schleife Fallen, um sich dann
63 // selbst zu zerstoeren.
64 // Geht so leider nicht: Destroying Window with living Child!
65 
66 
67 struct BasicStatus
68 {
69 //	sal_Bool	bCompiled		: 1;
70 	sal_Bool	bIsRunning		: 1;
71 	sal_Bool	bError			: 1;
72 	sal_Bool	bIsInReschedule	: 1;
73 	sal_uInt16	nBasicFlags;
74 
BasicStatusBasicStatus75 	BasicStatus()	{
76 			bIsRunning = sal_False; bError = sal_False;
77 			nBasicFlags = 0; bIsInReschedule = sal_False; }
78 };
79 
80 struct BreakPoint
81 {
82 	sal_Bool	bEnabled;
83 	sal_Bool	bTemp;
84 	sal_uLong 	nLine;
85 	sal_uLong	nStopAfter;
86     sal_uLong   nHitCount;
87 
BreakPointBreakPoint88 	BreakPoint( sal_uLong nL )	{ nLine = nL; nStopAfter = 0; nHitCount = 0; bEnabled = sal_True; bTemp = sal_False; }
89 
90 };
91 
92 class BasicDockingWindow : public DockingWindow
93 {
94 	Rectangle		aFloatingPosAndSize;
95 
96 protected:
97 	virtual sal_Bool 	Docking( const Point& rPos, Rectangle& rRect );
98 	virtual void	EndDocking( const Rectangle& rRect, sal_Bool bFloatMode );
99 	virtual void    ToggleFloatingMode();
100 	virtual sal_Bool	PrepareToggleFloatingMode();
101 	virtual void	StartDocking();
102 
103 public:
104 	BasicDockingWindow( Window* pParent );
105 };
106 
107 DECLARE_LIST( BreakPL, BreakPoint* )
108 class BreakPointList : public BreakPL
109 {
110 private:
111     void operator =(BreakPointList); // not implemented
112 
113 public:
114     BreakPointList();
115 
116     BreakPointList(BreakPointList const & rList);
117 
118     ~BreakPointList();
119 
120     void reset();
121 
122     void transfer(BreakPointList & rList);
123 
124 	void		InsertSorted( BreakPoint* pBrk );
125 	BreakPoint*	FindBreakPoint( sal_uLong nLine );
126 	void		AdjustBreakPoints( sal_uLong nLine, sal_Bool bInserted );
127 	void		SetBreakPointsInBasic( SbModule* pModule );
128     void        ResetHitCount();
129 };
130 
131 // helper class for sorting TabBar
132 class TabBarSortHelper
133 {
134 public:
135 	sal_uInt16			nPageId;
136 	String			aPageText;
137 
operator <(const TabBarSortHelper & rComp) const138 	bool operator<(const TabBarSortHelper& rComp) const { return (aPageText.CompareIgnoreCaseToAscii( rComp.aPageText ) == COMPARE_LESS); }
139 };
140 
141 class BasicIDETabBar : public TabBar
142 {
143 protected:
144 	virtual void	MouseButtonDown( const MouseEvent& rMEvt );
145 	virtual void	Command( const CommandEvent& rCEvt );
146 
147 	virtual long	AllowRenaming();
148 	virtual void	EndRenaming();
149 
150 public:
151 					BasicIDETabBar( Window* pParent );
152 
153 	void			Sort();
154 };
155 
156 #define BASWIN_OK				0x00
157 #define BASWIN_RUNNINGBASIC		0x01
158 #define BASWIN_TOBEKILLED		0x02
159 #define BASWIN_SUSPENDED		0x04
160 #define BASWIN_INRESCHEDULE		0x08
161 
162 class Printer;
163 class BasicEntryDescriptor;
164 
165 namespace svl
166 {
167     class IUndoManager;
168 }
169 
170 class IDEBaseWindow : public Window
171 {
172 private:
173 	ScrollBar*		pShellHScrollBar;
174 	ScrollBar*		pShellVScrollBar;
175 
176 	DECL_LINK( ScrollHdl, ScrollBar * );
177 	sal_uInt8			nStatus;
178 
179 	ScriptDocument      m_aDocument;
180 	String			    m_aLibName;
181 	String			    m_aName;
182 
183 protected:
184 	virtual void	DoScroll( ScrollBar* pCurScrollBar );
185 
186 public:
187 					TYPEINFO();
188 					IDEBaseWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName );
189 	virtual		 	~IDEBaseWindow();
190 
191 	void			Init();
192 	virtual void	DoInit();
193 	virtual void	Deactivating();
194 	void			GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll );
195 
GetHScrollBar() const196 	ScrollBar*		GetHScrollBar()	const { return pShellHScrollBar; }
GetVScrollBar() const197 	ScrollBar*		GetVScrollBar()	const { return pShellVScrollBar; }
198 
199 	virtual void	ExecuteCommand( SfxRequest& rReq );
200 	virtual void	GetState( SfxItemSet& );
201     virtual long    Notify( NotifyEvent& rNEvt );
202 
203 	virtual void	StoreData();
204 	virtual void	UpdateData();
205 	virtual sal_Bool 	CanClose();
206 
207     // return number of pages to be printed
208     virtual sal_Int32 countPages( Printer* pPrinter ) = 0;
209     // print page
210     virtual void printPage( sal_Int32 nPage, Printer* pPrinter ) = 0;
211 
212 	virtual String	GetTitle();
213 	String 			CreateQualifiedName();
214     virtual BasicEntryDescriptor CreateEntryDescriptor() = 0;
215 
216 	virtual sal_Bool	IsModified();
217     virtual sal_Bool    IsPasteAllowed();
218 
219 	virtual sal_Bool 	AllowUndo();
220 
221 	virtual void	SetReadOnly( sal_Bool bReadOnly );
222     virtual sal_Bool    IsReadOnly();
223 
GetStatus()224 	sal_uInt8			GetStatus()				{ return nStatus; }
SetStatus(sal_uInt8 n)225 	void			SetStatus( sal_uInt8 n )		{ nStatus = n; }
AddStatus(sal_uInt8 n)226 	void			AddStatus( sal_uInt8 n )		{ nStatus = nStatus | n; }
ClearStatus(sal_uInt8 n)227 	void			ClearStatus( sal_uInt8 n )	{ nStatus = nStatus & ~n; }
228 
229 	virtual Window*	GetLayoutWindow();
230 
231     virtual ::svl::IUndoManager*
232                     GetUndoManager();
233 
234 	virtual sal_uInt16	GetSearchOptions();
235 
236 	virtual void	BasicStarted();
237 	virtual void	BasicStopped();
238 
IsSuspended() const239 	sal_Bool			IsSuspended() const
240 						{ return ( nStatus & BASWIN_SUSPENDED ) ? sal_True : sal_False; }
241 
242 	const ScriptDocument&
GetDocument() const243                     GetDocument() const { return m_aDocument; }
SetDocument(const ScriptDocument & rDocument)244 	void			SetDocument( const ScriptDocument& rDocument ) { m_aDocument = rDocument; }
IsDocument(const ScriptDocument & rDocument) const245     bool            IsDocument( const ScriptDocument& rDocument ) const { return rDocument == m_aDocument; }
GetLibName() const246 	const String&	GetLibName() const { return m_aLibName; }
SetLibName(const String & aLibName)247 	void			SetLibName( const String& aLibName ) { m_aLibName = aLibName; }
GetName() const248 	const String&	GetName() const { return m_aName; }
SetName(const String & aName)249 	void			SetName( const String& aName ) { m_aName = aName; }
250 };
251 
252 class LibInfoKey
253 {
254 private:
255 	ScriptDocument      m_aDocument;
256     String              m_aLibName;
257 
258 public:
259     LibInfoKey( const ScriptDocument& rDocument, const String& rLibName );
260     ~LibInfoKey();
261 
262     LibInfoKey( const LibInfoKey& rKey );
263     LibInfoKey& operator=( const LibInfoKey& rKey );
264 
265     bool operator==( const LibInfoKey& rKey ) const;
266 
267 	const ScriptDocument&
GetDocument() const268                     GetDocument() const { return m_aDocument; }
GetLibName() const269     const String&   GetLibName() const { return m_aLibName; }
270 };
271 
272 class LibInfoItem
273 {
274 private:
275 	ScriptDocument      m_aDocument;
276     String              m_aLibName;
277 	String              m_aCurrentName;
278     sal_uInt16              m_nCurrentType;
279 
280 public:
281     LibInfoItem( const ScriptDocument& rDocument, const String& rLibName, const String& rCurrentName, sal_uInt16 nCurrentType );
282     ~LibInfoItem();
283 
284     LibInfoItem( const LibInfoItem& rItem );
285     LibInfoItem& operator=( const LibInfoItem& rItem );
286 
287 	const ScriptDocument&
GetDocument() const288                     GetDocument() const { return m_aDocument; }
GetLibName() const289     const String&   GetLibName() const { return m_aLibName; }
GetCurrentName() const290     const String&   GetCurrentName() const { return m_aCurrentName; }
GetCurrentType() const291     sal_uInt16          GetCurrentType() const { return m_nCurrentType; }
292 };
293 
294 class LibInfos
295 {
296 private:
297 
298     struct LibInfoKeyHash
299     {
operator ()LibInfos::LibInfoKeyHash300         size_t operator()( const LibInfoKey& rKey ) const
301         {
302             size_t nHash = (size_t) rKey.GetDocument().hashCode();
303             nHash += (size_t) ::rtl::OUString( rKey.GetLibName() ).hashCode();
304             return nHash;
305 	    }
306     };
307 
308     typedef ::std::hash_map< LibInfoKey, LibInfoItem*, LibInfoKeyHash, ::std::equal_to< LibInfoKey > > LibInfoMap;
309     LibInfoMap  m_aLibInfoMap;
310 
311 public:
312                     LibInfos();
313                     ~LibInfos();
314 
315     void            InsertInfo( LibInfoItem* pItem );
316     void            RemoveInfoFor( const ScriptDocument& _rDocument );
317 
318     LibInfoItem*    GetInfo( const LibInfoKey& rKey );
319 };
320 
321 void            CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, sal_Bool bEraseTrailingEmptyLines = sal_False );
322 String			CreateMgrAndLibStr( const String& rMgrName, const String& rLibName );
323 sal_uLong			CalcLineCount( SvStream& rStream );
324 
325 sal_Bool            QueryReplaceMacro( const String& rName, Window* pParent = 0 );
326 sal_Bool			QueryDelMacro( const String& rName, Window* pParent = 0 );
327 sal_Bool			QueryDelDialog( const String& rName, Window* pParent = 0 );
328 sal_Bool			QueryDelModule( const String& rName, Window* pParent = 0 );
329 sal_Bool			QueryDelLib( const String& rName, sal_Bool bRef = sal_False, Window* pParent = 0 );
330 sal_Bool            QueryPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xLibContainer, const String& rLibName, String& rPassword, sal_Bool bRepeat = sal_False, sal_Bool bNewTitle = sal_False );
331 
332 class ModuleInfoHelper
333 {
334 ModuleInfoHelper();
335 ModuleInfoHelper(const ModuleInfoHelper&);
336 ModuleInfoHelper& operator = (const ModuleInfoHelper&);
337 public:
338     static void getObjectName( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rLib, const String& rModName, String& rObjName );
339     static sal_Int32 getModuleType(  const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rLib, const String& rModName );
340 };
341 #endif	// _BASTYPES_HXX
342