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