1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: statemnt.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 /***************************************************************************
32 ** Von StatementList werden alle Statements abgeleitet.
33 ** Es gibt immer nur eine Statementliste, die verpointert ist.
34 ** jederzeit kann das der Anfang der Kette abgefragt werden.
42 ***************************************************************************/
46 #include <vcl/wintypes.hxx>
47 #include <tools/string.hxx>
48 #include <tools/debug.hxx>
49 #include <tools/time.hxx>
50 #ifndef _SV_DRAG_HXX //autogen
51 //#include <vcl/drag.hxx>
53 #include <vcl/menu.hxx>
54 #include <vcl/svapp.hxx>
55 #include <tools/fsys.hxx>
56 #include <sot/storage.hxx>
57 #include <basic/sbstar.hxx>
58 #include <vcl/event.hxx>
59 #include <com/sun/star/beans/PropertyValue.hpp>
60 #include <vcl/smartid.hxx>
61 #include <automation/commtypes.hxx>
72 class ImplRemoteControl
;
79 class CommunicationLink
;
81 #if OSL_DEBUG_LEVEL > 1
89 void SAL_CALL
osl_TestToolDebugPrint( const sal_Char
*pString
);
95 #define IsVisible IsReallyVisible
96 #define GET_REAL_PARENT() GetWindow( WINDOW_REALPARENT )
98 // switch behaviour of ImplMouse* and ImplKeyInput
99 #define FORCE_DIRECT_CALL TRUE
101 typedef USHORT SearchFlags
;
102 #define SEARCH_NOOVERLAP ((SearchFlags) 0x0001)
103 #define SEARCH_NO_TOPLEVEL_WIN ((SearchFlags) 0x0002)
104 #define SEARCH_FOCUS_FIRST ((SearchFlags) 0x0004)
105 #define SEARCH_FIND_DISABLED ((SearchFlags) 0x0008)
109 SearchFlags nmSearchFlags
;
111 Search( SearchFlags nSearchFlags
= 0): nmSearchFlags(nSearchFlags
) {}
114 virtual BOOL
IsWinOK( Window
*pWin
) = 0;
115 SearchFlags
GetSearchFlags() { return nmSearchFlags
; }
116 void AddSearchFlags( SearchFlags aNewFlags
) { nmSearchFlags
|= aNewFlags
; }
117 void RemoveSearchFlags( SearchFlags aRemoveFlags
) { nmSearchFlags
&= ( ~aRemoveFlags
); }
118 BOOL
HasSearchFlag( SearchFlags aQueryFlag
) { return (nmSearchFlags
& aQueryFlag
) == aQueryFlag
; }
121 BOOL
IsDialog(Window
*pWin
); // Ist *pWin von SystemWindow abgeleitet (Kann es Active sein)
122 BOOL
IsAccessable(Window
*pWin
); // Ist *pWin Zugreifbar (über IsEnabled und Parents geprüft)
125 //class SafePointer : CriticalSection
130 SafePointer() { pSelf
= this; }
131 virtual ~SafePointer() { DBG_ASSERT(pSelf
==this,"Destructor von Nicht existierendem Objekt aufgerufen");
133 // static BOOL IsValid( SafePointer *pThis ) { return pThis == pThis->pSelf; }
134 // virtual operator -> (); { DBG_ASSERT(pMyself == this,"-> von Nicht existierendem Objekt aufgerufen"); }
139 class StatementCommand
;
145 StatementCommand
*pDisplayInstance
;
146 DisplayHidWin
*pDisplayHidWin
;
149 String aOriginalCaption
;
152 TranslateWin
*pTranslateWin
;
157 TTSettings
* GetTTSettings();
160 #define MAX_RETRIES 9
161 class StatementList
: public SafePointer
164 StatementList(const StatementList
&);
165 StatementList
& operator=(const StatementList
&);
170 void QueStatement(StatementList
*pAfterThis
);
171 BOOL bStatementInQue
;
172 static USHORT nUseBindings
;
174 static TTProfiler
*pProfiler
;
176 void SendProfile( String aText
);
177 static StatementList
*pCurrentProfileStatement
;
179 static BOOL bIsInReschedule
;
180 static USHORT nModalCount
;
181 static Window
*pLastFocusWindow
; // Wenn dieses sich ändert wird Safe Reschedule abgebrochen
182 static BOOL bWasDragManager
; // Wenn dieses sich ändert wird Safe Reschedule abgebrochen
183 static BOOL bWasPopupMenu
; // Wenn dieses sich ändert wird Safe Reschedule abgebrochen
184 static BOOL bBasicWasRunning
;
186 static USHORT nMinTypeKeysDelay
; /// Verzögerung der einzelnen Anschläge für TypeKeys
187 static USHORT nMaxTypeKeysDelay
;
188 static BOOL bDoTypeKeysDelay
;
190 static Window
* pFirstDocFrame
;
192 static BOOL bIsSlotInExecute
;
195 static BOOL
IsInReschedule() { return bIsInReschedule
; }
196 void SafeReschedule( BOOL bYield
= FALSE
) // Setzt Flag, so daß nicht schon der nächste Befehl ausgeführt wird
198 nModalCount
= Application::GetModalModeCount();
199 bIsInReschedule
= TRUE
;
200 pLastFocusWindow
= GetpApp()->GetFocusWindow();
201 bWasDragManager
= false /*!= DragManager::GetDragManager()*/;
202 bWasPopupMenu
= NULL
!= PopupMenu::GetActivePopupMenu();
203 bBasicWasRunning
= StarBASIC::IsRunning();
204 bWasExecuting
= bExecuting
;
208 GetpApp()->Reschedule();
209 bExecuting
= bWasExecuting
;
210 bBasicWasRunning
= FALSE
;
211 bWasPopupMenu
= FALSE
;
212 bWasDragManager
= FALSE
;
213 pLastFocusWindow
= NULL
;
214 bIsInReschedule
= FALSE
;
217 static BOOL
MaybeResetSafeReschedule()
218 { // Implementierung muß hier zwar nicht sein, ist aber übersichtlicher so
219 if ( !bIsInReschedule
)
222 if ( pLastFocusWindow
!= GetpApp()->GetFocusWindow()
223 || ( Application::GetModalModeCount() > nModalCount
)
224 // || ( DragManager::GetDragManager() && !bWasDragManager )
225 || ( PopupMenu::GetActivePopupMenu() && !bWasPopupMenu
)
226 || ( StarBASIC::IsRunning() && !bBasicWasRunning
) )
228 bIsInReschedule
= FALSE
;
229 pLastFocusWindow
= NULL
;
235 static void NormalReschedule() // Setzt das flag nicht
237 GetpApp()->Reschedule();
239 #define Reschedule RescheduleNichtBenutzen_StattdessenSafeRescheduleAnStatementList
241 static Window
* GetMouseWin();
242 static BOOL
WinPtrValid(Window
*pTest
);
243 static Window
* SearchAllWin( Window
*pBase
, Search
&aSearch
, BOOL MaybeBase
= TRUE
);
245 static Window
* SearchClientWin( Window
*pBase
, Search
&aSearch
, BOOL MaybeBase
= TRUE
);
247 Window
* SearchTree( SmartId aUId
, BOOL bSearchButtonOnToolbox
= FALSE
);
248 Window
* GetActive( WindowType nRT
, BOOL MaybeBase
= TRUE
);
249 Window
* GetFocus( WindowType nRT
, BOOL MaybeBase
= TRUE
);
250 Window
* GetAnyActive( BOOL MaybeBase
= TRUE
);
251 ScrollBar
* GetScrollBar( Window
*pBase
, USHORT nDirection
, BOOL MaybeBase
= TRUE
);
252 Window
* GetPopupFloatingWin( BOOL MaybeBase
= TRUE
);
253 Menu
* GetMatchingMenu( Window
* pWin
, Menu
* pBaseMenu
= NULL
);
254 Window
* GetWinByRT( Window
*pBase
, WindowType nRT
, BOOL MaybeBase
= TRUE
, USHORT nSkip
= 0, BOOL bSearchAll
= FALSE
);
255 USHORT
CountWinByRT( Window
*pBase
, WindowType nRT
, BOOL MaybeBase
= TRUE
);
256 Window
* GetDocWin( USHORT nNr
);
257 USHORT
GetDocWinCount();
258 Window
* GetFadeSplitWin( Window
*pBase
, WindowAlign nAlign
, BOOL MaybeBase
= TRUE
);
259 BOOL
ValueOK(SmartId nId
, String aBezeichnung
, ULONG nValue
, ULONG nMax
);
261 USHORT
GetCurrentMenues( PopupMenu
*&pPopup
, MenuBar
*&pMenuBar
, Menu
*&pMenu
);
264 // void AddStatement( StatementList *pNewStatement );
266 virtual ~StatementList();
268 virtual BOOL
Execute() = 0;
269 /***************************************************************************
270 ** Bestimmt erst den nächsten Befehl, setzt Current
271 ** und führt dann aus.
272 ** Returnwert gibt an, ob Befehl nochmal ausgeführt
273 ** werden soll. Dann muß auch der UserEvent verlassen werden, um der Applikation
274 ** normales Arbeiten zu ermöglichen (Dialog schliessen)
275 ** TRUE bedeutet, dass alles klar gegangen ist
276 ** FALSE bedeutet nochmal Bitte
277 ***************************************************************************/
279 void ReportError(String aMessage
);
280 void ReportError(SmartId aUId
, String aMessage
);
281 void ReportError(String aMessage
, ULONG nWhatever
);
283 static void DirectLog( ULONG nType
, String aString
);
285 String
Tree(Window
*pBase
, int Indent
);
286 String
ClientTree(Window
*pBase
, int Indent
);
288 StatementList
*pNext
;
289 static StatementList
/**pCurrent,*/ *pFirst
;
290 static BOOL bReadingCommands
;
291 static SmartId aWindowWaitUId
;
292 static Window
*pWindowWaitPointer
;
293 static SmartId aWindowWaitOldHelpId
;
294 static SmartId aWindowWaitOldUniqueId
;
295 static RetStream
*pRet
;
298 static BOOL bExecuting
; // Gesetzt, wenn ein Befehl rescheduled ohne einen neuen Befehl zu erlauben
299 BOOL bWasExecuting
; // Wurde bei einem MaybeResetSafeReschedule resettet, so wird der Zustand danach wiederhergestellt
300 static SmartId aSubMenuId1
; // Untermenüs bei PopupMenus
301 static SmartId aSubMenuId2
; // erstmal 2-Stufig
302 static SmartId aSubMenuId3
; // and now even 3 levels #i31512#
303 static SystemWindow
*pMenuWindow
; // when using MenuBar as base for MenuCommands
304 static TTProperties
*pTTProperties
; // Hier stehen die SlotIDs aus dem SFX drin
306 BOOL
CheckWindowWait(); //True heisst, dass Window noch existiert
307 //False -> Window weg;
308 static void SetFirstDocFrame( Window
* pWin
);
309 static Window
* GetFirstDocFrame();
310 static BOOL
IsFirstDocFrame( Window
* pWin
);
311 static BOOL
IsDocWin( Window
* pWin
);
312 static BOOL
IsIMEWin( Window
* pWin
); // Input Window for CJK under Solaris
313 static BOOL
IsDocFrame( Window
* pWin
);
314 static MenuBar
* GetDocFrameMenuBar( Window
* pWin
);
315 static USHORT
GetDocFrameCount();
317 static BOOL bCatchGPF
;
319 static BOOL bUsePostEvents
; // use Application::Post*Event or own impl to handle key and mouseevents
321 #if OSL_DEBUG_LEVEL > 1
322 static EditWindow
*m_pDbgWin
;
326 class StatementSlot
: public StatementList
//Slots aufrufen
330 SfxPoolItem
**pItemArr
;
331 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
332 USHORT nFunctionId
; // can get removed when the old (numeric) slothandling is removed
339 StatementSlot( SCmdStream
*pIn
);
340 StatementSlot( ULONG nSlot
, SfxPoolItem
* pItem
= NULL
);
341 virtual ~StatementSlot();
342 virtual BOOL
Execute();
345 class StatementUnoSlot
: public StatementSlot
//Uno Slots aufrufen
348 StatementUnoSlot(SCmdStream
*pIn
);
351 class StatementCommand
: public StatementList
// Befehl ausführen (wintree, resetaplication ...)
353 friend class ImplRemoteControl
;
356 SmartId aSmartMethodId
;
358 comm_USHORT nNr1
,nNr2
,nNr3
,nNr4
;
360 String aString1
,aString2
;
363 Window
* GetNextOverlap( Window
* pBase
);
364 Window
* GetNextRecoverWin();
366 static USHORT nDirPos
;
368 static pfunc_osl_printDebugMessage pOriginal_osl_DebugMessageFunc
;
371 BOOL
UnpackStorage( SotStorageRef xStorage
, DirEntry
&aBaseDir
);
373 void HandleSAXParser();
376 StatementCommand( SCmdStream
*pIn
);
377 StatementCommand( StatementList
*pAfterThis
, USHORT MethodId
, USHORT Params
, USHORT Nr1
);
378 virtual BOOL
Execute();
381 void WriteControlData( Window
*pBase
, ULONG nConf
, BOOL bFirst
= TRUE
);
386 enum TTHotSpots
{ MitteLinks
, Mitte
, MitteOben
};
388 class StatementControl
: public StatementList
394 comm_USHORT nNr1
,nNr2
,nNr3
,nNr4
;
396 String aString1
,aString2
;
398 BOOL
ControlOK( Window
*pControl
, const sal_Char
* aBezeichnung
);
399 void AnimateMouse( Window
*pControl
, TTHotSpots aWohin
);
400 void AnimateMouse( Window
*pControl
, Point aWohin
);
402 BOOL
MaybeDoTypeKeysDelay( Window
*pTestWindow
);
404 BOOL
HandleVisibleControls( Window
*pControl
);
405 BOOL
HandleCommonMethods( Window
*pControl
);
408 StatementControl( SCmdStream
*pIn
, USHORT nControlType
);
409 virtual BOOL
Execute();
413 class StatementFlow
: public StatementList
// Kommunikation mit Sequence
425 StatementFlow (ULONG nServiceId
, SCmdStream
*pIn
, ImplRemoteControl
*pRC
);
426 StatementFlow( StatementList
*pAfterThis
, USHORT nArtP
);
427 virtual BOOL
Execute();
428 static CommunicationLink
*pCommLink
;
429 static BOOL bSending
;
431 static BOOL bUseIPC
; // Soll zur rückmeldung IPC verwendet werden?
432 static ImplRemoteControl
*pRemoteControl
; // Static für 2. Constructor
435 void SendViaSocket();
438 class SearchUID
: public Search
440 Window
*pMaybeResult
;
441 Window
*pAlternateResult
;
443 BOOL bSearchButtonOnToolbox
;
445 SearchUID( SmartId aUIdP
, BOOL bSearchButtonOnToolboxP
): Search( SEARCH_FOCUS_FIRST
), pMaybeResult(NULL
), pAlternateResult(NULL
), aUId(aUIdP
), bSearchButtonOnToolbox(bSearchButtonOnToolboxP
) {}
446 virtual BOOL
IsWinOK( Window
*pWin
);
447 Window
* GetMaybeWin() { return pMaybeResult
; }
448 Window
* GetAlternateResultWin() { return pAlternateResult
; }
450 class SearchActive
: public Search
454 SearchActive( WindowType nRTP
): nRT(nRTP
) {}
455 virtual BOOL
IsWinOK( Window
*pWin
);
457 class SearchPopupFloatingWin
: public Search
460 SearchPopupFloatingWin(): Search( SEARCH_FOCUS_FIRST
) {}
461 virtual BOOL
IsWinOK( Window
*pWin
);
463 class SearchRT
: public Search
469 SearchRT( WindowType nRTP
, SearchFlags nSearchFlags
, USHORT nSkip
= 0 ): Search(nSearchFlags
), mnRT(nRTP
), mnSkip( nSkip
), mnCount( 0 ) {}
470 virtual BOOL
IsWinOK( Window
*pWin
);
471 USHORT
GetCount(){ return mnCount
; }
473 class SearchScroll
: public SearchRT
477 SearchScroll( USHORT nDir
, SearchFlags nSearchFlags
): SearchRT(WINDOW_SCROLLBAR
, nSearchFlags
), nDirection(nDir
) {}
478 virtual BOOL
IsWinOK( Window
*pWin
);
480 class SearchWinPtr
: public Search
484 SearchWinPtr( Window
*pTestP
): pTest(pTestP
) {}
485 virtual BOOL
IsWinOK( Window
*pWin
);
487 class SearchFadeSplitWin
: public Search
491 SearchFadeSplitWin( WindowAlign nAlignP
): nAlign(nAlignP
) {}
492 virtual BOOL
IsWinOK( Window
*pWin
);
496 void ImplKeyInput( Window
* pWin
, KeyEvent
&aKEvnt
, BOOL bForceDirect
=FALSE
);
497 void ImplMouseMove( Window
* pWin
, MouseEvent
&aMEvnt
, BOOL bForceDirect
=FALSE
);
498 void ImplMouseButtonDown( Window
* pWin
, MouseEvent
&aMEvnt
, BOOL bForceDirect
=FALSE
);
499 void ImplMouseButtonUp( Window
* pWin
, MouseEvent
&aMEvnt
, BOOL bForceDirect
=FALSE
);
500 void ImplCommand( Window
* pWin
, CommandEvent
&aCmdEvnt
);
501 void ImplEventWait( ULONG nID
);