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