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 /***************************************************************************
24 **
25 **       Von StatementList werden alle Statements abgeleitet.
26 **   Es gibt immer nur eine Statementliste, die verpointert ist.
27 **       jederzeit kann das der Anfang der Kette abgefragt werden.
28 **
29 **
30 **
31 **
32 **
33 **
34 **
35 ***************************************************************************/
36 #ifndef _STATEMNT_HXX
37 #define _STATEMNT_HXX
38 
39 #include <tools/wintypes.hxx>
40 #include <tools/string.hxx>
41 #include <tools/debug.hxx>
42 #include <tools/time.hxx>
43 #ifndef _SV_DRAG_HXX //autogen
44 //#include <vcl/drag.hxx>
45 #endif
46 #include <vcl/menu.hxx>
47 #include <vcl/svapp.hxx>
48 #include <tools/fsys.hxx>
49 #include <sot/storage.hxx>
50 #include <basic/sbstar.hxx>
51 #include <vcl/event.hxx>
52 #include <com/sun/star/beans/PropertyValue.hpp>
53 #include <automation/commtypes.hxx>
54 
55 class Window;
56 class SystemWindow;
57 class Point;
58 class SfxPoolItem;
59 
60 class ScrollBar;
61 
62 class SCmdStream;
63 class RetStream;
64 class ImplRemoteControl;
65 
66 class TTProfiler;
67 class TTProperties;
68 
69 class Dir;
70 
71 class CommunicationLink;
72 
73 #if OSL_DEBUG_LEVEL > 1
74 class EditWindow;
75 #endif
76 
77 #ifdef __cplusplus
78 extern "C"
79 {
80 #endif
81     void SAL_CALL osl_TestToolDebugPrint( const sal_Char *pString );
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 
87 #define IsVisible IsReallyVisible
88 #define GET_REAL_PARENT() GetWindow( WINDOW_REALPARENT )
89 
90 // switch behaviour of ImplMouse* and ImplKeyInput
91 #define FORCE_DIRECT_CALL   sal_True
92 
93 typedef sal_uInt16 SearchFlags;
94 #define SEARCH_NOOVERLAP			((SearchFlags) 0x0001)
95 #define SEARCH_NO_TOPLEVEL_WIN		((SearchFlags) 0x0002)
96 #define SEARCH_FOCUS_FIRST      	((SearchFlags) 0x0004)
97 #define SEARCH_FIND_DISABLED      	((SearchFlags) 0x0008)
98 
99 class Search
100 {
101 	SearchFlags nmSearchFlags;
102 public:
Search(SearchFlags nSearchFlags=0)103 	Search( SearchFlags nSearchFlags = 0): nmSearchFlags(nSearchFlags) {}
~Search()104 	virtual ~Search() {}
105 
106 	virtual sal_Bool IsWinOK( Window *pWin ) = 0;
GetSearchFlags()107 	SearchFlags GetSearchFlags() { return nmSearchFlags; }
AddSearchFlags(SearchFlags aNewFlags)108     void AddSearchFlags( SearchFlags aNewFlags ) { nmSearchFlags |= aNewFlags; }
RemoveSearchFlags(SearchFlags aRemoveFlags)109 	void RemoveSearchFlags( SearchFlags aRemoveFlags ) { nmSearchFlags &= ( ~aRemoveFlags ); }
HasSearchFlag(SearchFlags aQueryFlag)110 	sal_Bool HasSearchFlag( SearchFlags aQueryFlag ) { return (nmSearchFlags & aQueryFlag) == aQueryFlag; }
111 };
112 
113 sal_Bool IsDialog(Window *pWin);		// Ist *pWin von SystemWindow abgeleitet (Kann es Active sein)
114 sal_Bool IsAccessable(Window *pWin);	// Ist *pWin Zugreifbar (�ber IsEnabled und Parents gepr�ft)
115 
116 
117 //class SafePointer : CriticalSection
118 class SafePointer
119 {
120 	SafePointer *pSelf;
121 public:
SafePointer()122 	SafePointer()   { pSelf = this; }
~SafePointer()123 	virtual ~SafePointer()  { DBG_ASSERT(pSelf==this,"Destructor von Nicht existierendem Objekt aufgerufen");
124 							  pSelf = NULL; }
125 //	static sal_Bool IsValid( SafePointer *pThis ) { return pThis == pThis->pSelf; }
126 // virtual      operator -> (); { DBG_ASSERT(pMyself == this,"-> von Nicht existierendem Objekt aufgerufen"); }
127 };
128 
129 
130 class DisplayHidWin;
131 class StatementCommand;
132 class TranslateWin;
133 
134 struct TTSettings
135 {
136     // DisplayHID
137    	StatementCommand *pDisplayInstance;
138 	DisplayHidWin *pDisplayHidWin;
139 	Window *Old;
140     Window *Act;
141 	String aOriginalCaption;
142 
143     // Translate
144 	TranslateWin *pTranslateWin;
145 	sal_Bool bToTop;
146 };
147 
148 
149 TTSettings* GetTTSettings();
150 
151 
152 #define MAX_RETRIES 9
153 class StatementList : public SafePointer
154 {
155 private:
156     StatementList(const StatementList&);
157     StatementList & operator=(const StatementList&);
158 
159 protected:
160 	StatementList();
161 	sal_uInt16 nRetryCount;
162 	void QueStatement(StatementList *pAfterThis);
163 	sal_Bool bStatementInQue;
164 	static sal_uInt16 nUseBindings;
165 
166 	static TTProfiler *pProfiler;
167 	void InitProfile();
168 	void SendProfile( String aText );
169 	static StatementList *pCurrentProfileStatement;
170 
171 	static sal_Bool bIsInReschedule;
172         static sal_uInt16 nModalCount;
173 	static Window *pLastFocusWindow;		// Wenn dieses sich �ndert wird Safe Reschedule abgebrochen
174 	static sal_Bool bWasDragManager;			// Wenn dieses sich �ndert wird Safe Reschedule abgebrochen
175 	static sal_Bool bWasPopupMenu;				// Wenn dieses sich �ndert wird Safe Reschedule abgebrochen
176    	static sal_Bool bBasicWasRunning;
177 
178 	static sal_uInt16 nMinTypeKeysDelay;				/// Verz�gerung der einzelnen Anschl�ge f�r TypeKeys
179 	static sal_uInt16 nMaxTypeKeysDelay;
180 	static sal_Bool bDoTypeKeysDelay;
181 
182 	static Window* pFirstDocFrame;
183 
184     static sal_Bool bIsSlotInExecute;
185 
186 public:
IsInReschedule()187 	static sal_Bool IsInReschedule() { return bIsInReschedule; }
SafeReschedule(sal_Bool bYield=sal_False)188 	void SafeReschedule( sal_Bool bYield = sal_False )	// Setzt Flag, so da� nicht schon der n�chste Befehl ausgef�hrt wird
189 	{
190 		nModalCount = Application::GetModalModeCount();
191 		bIsInReschedule = sal_True;
192 		pLastFocusWindow = GetpApp()->GetFocusWindow();
193 		bWasDragManager = false /*!= DragManager::GetDragManager()*/;
194 		bWasPopupMenu = NULL != PopupMenu::GetActivePopupMenu();
195         bBasicWasRunning = StarBASIC::IsRunning();
196 		bWasExecuting = bExecuting;
197 		if ( bYield )
198 			GetpApp()->Yield();
199 		else
200 			GetpApp()->Reschedule();
201 		bExecuting = bWasExecuting;
202         bBasicWasRunning = sal_False;
203 		bWasPopupMenu = sal_False;
204 		bWasDragManager = sal_False;
205 		pLastFocusWindow = NULL;
206 		bIsInReschedule = sal_False;
207 		nModalCount = 0;
208 	}
MaybeResetSafeReschedule()209 	static sal_Bool MaybeResetSafeReschedule()
210 	{		// Implementierung mu� hier zwar nicht sein, ist aber �bersichtlicher so
211 		if ( !bIsInReschedule )
212 			return sal_False;
213 
214 		if ( pLastFocusWindow != GetpApp()->GetFocusWindow()
215 			|| ( Application::GetModalModeCount() > nModalCount )
216 //			|| ( DragManager::GetDragManager() && !bWasDragManager )
217 			|| ( PopupMenu::GetActivePopupMenu() && !bWasPopupMenu )
218 			|| ( StarBASIC::IsRunning() && !bBasicWasRunning ) )
219 		{
220 			bIsInReschedule = sal_False;
221 			pLastFocusWindow = NULL;
222 			return sal_True;
223 		}
224 		else
225 			return sal_False;
226 	}
NormalReschedule()227 	static void NormalReschedule()	// Setzt das flag nicht
228 	{
229 		GetpApp()->Reschedule();
230 	}
231 #define Reschedule RescheduleNichtBenutzen_StattdessenSafeRescheduleAnStatementList
232 
233 	static Window* GetMouseWin();
234 	static sal_Bool WinPtrValid(Window *pTest);
235 	static Window* SearchAllWin( Window *pBase, Search &aSearch, sal_Bool MaybeBase = sal_True );
236 protected:
237 	static Window* SearchClientWin( Window *pBase, Search &aSearch, sal_Bool MaybeBase = sal_True );
238 
239 	Window* SearchTree( rtl::OString aUId, sal_Bool bSearchButtonOnToolbox = sal_False );
240 	Window* GetActive( WindowType nRT, sal_Bool MaybeBase = sal_True );
241 	Window* GetFocus( WindowType nRT, sal_Bool MaybeBase = sal_True );
242 	Window* GetAnyActive( sal_Bool MaybeBase = sal_True );
243     ScrollBar* GetScrollBar( Window *pBase, sal_uInt16 nDirection, sal_Bool MaybeBase = sal_True );
244 	Window* GetPopupFloatingWin( sal_Bool MaybeBase = sal_True );
245     Menu* GetMatchingMenu( Window* pWin, Menu* pBaseMenu = NULL );
246 	Window* GetWinByRT( Window *pBase, WindowType nRT, sal_Bool MaybeBase = sal_True, sal_uInt16 nSkip = 0, sal_Bool bSearchAll = sal_False );
247 	sal_uInt16 CountWinByRT( Window *pBase, WindowType nRT, sal_Bool MaybeBase = sal_True );
248     Window* GetDocWin( sal_uInt16 nNr );
249     sal_uInt16 GetDocWinCount();
250 	Window* GetFadeSplitWin( Window *pBase, WindowAlign nAlign, sal_Bool MaybeBase = sal_True );
251 	sal_Bool ValueOK(rtl::OString nId, String aBezeichnung, sal_uLong nValue, sal_uLong nMax);
252 
253     sal_uInt16 GetCurrentMenues( PopupMenu *&pPopup, MenuBar *&pMenuBar, Menu *&pMenu );
254 
255 public:
256 //  void AddStatement( StatementList *pNewStatement );
257 
258 	virtual ~StatementList();
259 	void Advance();
260 	virtual sal_Bool Execute() = 0;
261 /***************************************************************************
262 ** Bestimmt erst den n�chsten Befehl, setzt Current
263 ** und f�hrt dann aus.
264 ** Returnwert gibt an, ob Befehl nochmal ausgef�hrt
265 ** werden soll. Dann mu� auch der UserEvent verlassen werden, um der Applikation
266 ** normales Arbeiten zu erm�glichen (Dialog schliessen)
267 ** sal_True bedeutet, dass alles klar gegangen ist
268 ** sal_False bedeutet nochmal Bitte
269 ***************************************************************************/
270 
271 	void ReportError(String aMessage);
272 	void ReportError(rtl::OString aUId, String aMessage);
273 	void ReportError(String aMessage, sal_uLong nWhatever);
274 
275 	static void DirectLog( sal_uLong nType, String aString );
276 
277 	String Tree(Window *pBase, int Indent);
278 	String ClientTree(Window *pBase, int Indent);
279 
280 	StatementList *pNext;
281 	static StatementList /**pCurrent,*/ *pFirst;
282 	static sal_Bool bReadingCommands;
283 	static rtl::OString aWindowWaitUId;
284 	static Window *pWindowWaitPointer;
285 	static rtl::OString aWindowWaitOldHelpId;
286 	static rtl::OString aWindowWaitOldUniqueId;
287 	static RetStream *pRet;
288 	static sal_Bool IsError;
289 	static sal_Bool bDying;
290 	static sal_Bool bExecuting;				// Gesetzt, wenn ein Befehl rescheduled ohne einen neuen Befehl zu erlauben
291 	sal_Bool bWasExecuting;	        		// Wurde bei einem MaybeResetSafeReschedule resettet, so wird der Zustand danach wiederhergestellt
292 	static sal_uInt16 aSubMenuId1;			// Untermen�s bei PopupMenus
293 	static sal_uInt16 aSubMenuId2;			// erstmal 2-Stufig
294 	static sal_uInt16 aSubMenuId3;			// and now even 3 levels #i31512#
295     static SystemWindow *pMenuWindow;   // when using MenuBar as base for MenuCommands
296 	static TTProperties *pTTProperties;	// Hier stehen die SlotIDs aus dem SFX drin
297 
298 	sal_Bool CheckWindowWait();			//True heisst, dass Window noch existiert
299 									//False -> Window weg;
300 	static void SetFirstDocFrame( Window* pWin );
301 	static Window* GetFirstDocFrame();
302 	static sal_Bool IsFirstDocFrame( Window* pWin );
303 	static sal_Bool IsDocWin( Window* pWin );
304 	static sal_Bool IsIMEWin( Window* pWin );    // Input Window for CJK under Solaris
305     static sal_Bool IsDocFrame( Window* pWin );
306     static MenuBar* GetDocFrameMenuBar( Window* pWin );
307     static sal_uInt16 GetDocFrameCount();
308 
309     static sal_Bool bCatchGPF;
310 
311 	static sal_Bool bUsePostEvents;         // use Application::Post*Event or own impl to handle key and mouseevents
312 
313 #if OSL_DEBUG_LEVEL > 1
314 	static EditWindow *m_pDbgWin;
315 #endif
316 };
317 
318 class StatementSlot : public StatementList	//Slots aufrufen
319 {
320 protected:
321 	sal_uInt16 nAnzahl;
322 	SfxPoolItem **pItemArr;
323     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> aArgs;
324 	sal_uInt16 nFunctionId;     // can get removed when the old (numeric) slothandling is removed
325     String aUnoUrl;
326     sal_Bool bMenuClosed;
327 
328     StatementSlot();
329     void AddReferer();
330 public:
331 	StatementSlot( SCmdStream *pIn );
332 	StatementSlot( sal_uLong nSlot, SfxPoolItem* pItem = NULL );
333 	virtual ~StatementSlot();
334 	virtual sal_Bool Execute();
335 };
336 
337 class StatementUnoSlot : public StatementSlot	//Uno Slots aufrufen
338 {
339 public:
340 	StatementUnoSlot(SCmdStream *pIn);
341 };
342 
343 class StatementCommand : public StatementList	// Befehl ausf�hren (wintree, resetaplication ...)
344 {
345 	friend class ImplRemoteControl;
346 protected:
347 	sal_uInt16 nMethodId;
348 	sal_uInt16 nParams;
349 	comm_USHORT nNr1,nNr2,nNr3,nNr4;
350 	comm_ULONG nLNr1;
351 	String aString1,aString2;
352 	sal_Bool bBool1,bBool2;
353 
354 	Window* GetNextOverlap( Window* pBase );
355 	Window* GetNextRecoverWin();
356 
357 	static sal_uInt16 nDirPos;
358 	static Dir *pDir;
359 	static pfunc_osl_printDebugMessage pOriginal_osl_DebugMessageFunc;
360 
361 
362 	sal_Bool UnpackStorage( SotStorageRef xStorage, DirEntry &aBaseDir );
363 
364     void HandleSAXParser();
365 
366 public:
367 	StatementCommand( SCmdStream *pIn );
368 	StatementCommand( StatementList *pAfterThis, sal_uInt16 MethodId, sal_uInt16 Params, sal_uInt16 Nr1 );
369 	virtual sal_Bool Execute();
370 	sal_Bool DisplayHID();
371 	void Translate();
372 	void WriteControlData( Window *pBase, sal_uLong nConf, sal_Bool bFirst = sal_True );
373 
374 };
375 
376 
377 enum TTHotSpots  { MitteLinks, Mitte, MitteOben };
378 
379 class StatementControl : public StatementList
380 {
381 protected:
382 	rtl::OString aUId;
383 	sal_uInt16 nMethodId;
384 	sal_uInt16 nParams;
385 	comm_USHORT nNr1,nNr2,nNr3,nNr4;
386 	comm_ULONG nLNr1;
387 	String aString1,aString2;
388 	sal_Bool bBool1,bBool2;
389 	sal_Bool ControlOK( Window *pControl, const sal_Char* aBezeichnung );
390 	void AnimateMouse( Window *pControl, TTHotSpots aWohin );
391 	void AnimateMouse( Window *pControl, Point aWohin );
392 
393 	sal_Bool MaybeDoTypeKeysDelay( Window *pTestWindow );
394 
395 	sal_Bool HandleVisibleControls( Window *pControl );
396 	sal_Bool HandleCommonMethods( Window *pControl );
397 
398 public:
399 	StatementControl( SCmdStream *pIn, sal_uInt16 nControlType );
400 	virtual sal_Bool Execute();
401 
402 };
403 
404 class StatementFlow : public StatementList		// Kommunikation mit Sequence
405 {
406 	sal_uInt16 nArt;
407 
408 	sal_uInt16 nParams;
409 	comm_USHORT nSNr1;
410 	comm_ULONG nLNr1;
411 	String aString1;
412 	sal_Bool bBool1;
413 
414 
415 public:
416 	StatementFlow (sal_uLong nServiceId, SCmdStream *pIn, ImplRemoteControl *pRC );
417 	StatementFlow( StatementList *pAfterThis, sal_uInt16 nArtP );
418 	virtual sal_Bool Execute();
419 	static CommunicationLink *pCommLink;
420 	static sal_Bool bSending;
421 
422 	static sal_Bool bUseIPC;	// Soll zur r�ckmeldung IPC verwendet werden?
423 	static ImplRemoteControl *pRemoteControl;	// Static f�r 2. Constructor
424 
425 private:
426 	void SendViaSocket();
427 };
428 
429 class SearchUID : public Search
430 {
431 	Window *pMaybeResult;
432 	Window *pAlternateResult;
433 	rtl::OString aUId;
434 	sal_Bool bSearchButtonOnToolbox;
435 public:
SearchUID(rtl::OString aUIdP,sal_Bool bSearchButtonOnToolboxP)436 	SearchUID( rtl::OString aUIdP, sal_Bool bSearchButtonOnToolboxP ): Search( SEARCH_FOCUS_FIRST ), pMaybeResult(NULL), pAlternateResult(NULL), aUId(aUIdP), bSearchButtonOnToolbox(bSearchButtonOnToolboxP) {}
437 	virtual sal_Bool IsWinOK( Window *pWin );
GetMaybeWin()438 	Window* GetMaybeWin() { return pMaybeResult; }
GetAlternateResultWin()439 	Window* GetAlternateResultWin() { return pAlternateResult; }
440 };
441 class SearchActive : public Search
442 {
443 	WindowType nRT;
444 public:
SearchActive(WindowType nRTP)445 	SearchActive( WindowType nRTP ): nRT(nRTP) {}
446 	virtual sal_Bool IsWinOK( Window *pWin );
447 };
448 class SearchPopupFloatingWin : public Search
449 {
450 public:
SearchPopupFloatingWin()451 	SearchPopupFloatingWin(): Search( SEARCH_FOCUS_FIRST ) {}
452 	virtual sal_Bool IsWinOK( Window *pWin );
453 };
454 class SearchRT : public Search
455 {
456 	WindowType mnRT;
457     sal_uInt16 mnSkip;
458     sal_uInt16 mnCount;
459 public:
SearchRT(WindowType nRTP,SearchFlags nSearchFlags,sal_uInt16 nSkip=0)460 	SearchRT( WindowType nRTP, SearchFlags nSearchFlags, sal_uInt16 nSkip = 0 ): Search(nSearchFlags), mnRT(nRTP), mnSkip( nSkip ), mnCount( 0 ) {}
461 	virtual sal_Bool IsWinOK( Window *pWin );
GetCount()462     sal_uInt16 GetCount(){ return mnCount; }
463 };
464 class SearchScroll : public SearchRT
465 {
466 	sal_uInt16 nDirection;
467 public:
SearchScroll(sal_uInt16 nDir,SearchFlags nSearchFlags)468 	SearchScroll( sal_uInt16 nDir, SearchFlags nSearchFlags ): SearchRT(WINDOW_SCROLLBAR, nSearchFlags), nDirection(nDir) {}
469 	virtual sal_Bool IsWinOK( Window *pWin );
470 };
471 class SearchWinPtr : public Search
472 {
473 	Window *pTest;
474 public:
SearchWinPtr(Window * pTestP)475 	SearchWinPtr( Window *pTestP ): pTest(pTestP) {}
476 	virtual sal_Bool IsWinOK( Window *pWin );
477 };
478 class SearchFadeSplitWin : public Search
479 {
480 	WindowAlign nAlign;
481 public:
SearchFadeSplitWin(WindowAlign nAlignP)482 	SearchFadeSplitWin( WindowAlign nAlignP ): nAlign(nAlignP) {}
483 	virtual sal_Bool IsWinOK( Window *pWin );
484 };
485 
486 
487 void ImplKeyInput( Window* pWin, KeyEvent &aKEvnt, sal_Bool bForceDirect=sal_False );
488 void ImplMouseMove( Window* pWin, MouseEvent &aMEvnt, sal_Bool bForceDirect=sal_False );
489 void ImplMouseButtonDown( Window* pWin, MouseEvent &aMEvnt, sal_Bool bForceDirect=sal_False );
490 void ImplMouseButtonUp( Window* pWin, MouseEvent &aMEvnt, sal_Bool bForceDirect=sal_False );
491 void ImplCommand( Window* pWin, CommandEvent &aCmdEvnt );
492 void ImplEventWait( sal_uLong nID );
493 
494 #endif
495