update dev300-m58
[ooovba.git] / automation / source / server / recorder.cxx
blobad5c111ebeea452ae956ff2262af2a9de50b1831
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: recorder.cxx,v $
10 * $Revision: 1.13 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_automation.hxx"
33 #include <osl/mutex.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/vclevent.hxx>
37 #include <vcl/button.hxx>
38 #include <vcl/edit.hxx>
39 #include <vcl/spinfld.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <vcl/lstbox.hxx>
43 #include <vcl/sound.hxx>
44 #include <vcl/combobox.hxx>
45 #include <vcl/floatwin.hxx>
46 #include <basic/ttstrhlp.hxx>
47 #include "statemnt.hxx"
48 #include "retstrm.hxx"
49 #include "rcontrol.hxx"
50 #include "recorder.hxx"
52 #include <comphelper/uieventslogger.hxx>
54 MacroRecorder* MacroRecorder::pMacroRecorder = NULL;
56 MacroRecorder::MacroRecorder()
57 : pLastWin( NULL )
58 , pEditModify( NULL )
59 , pActionParent( NULL )
60 , aKeyUniqueID()
61 , pKeyWin( NULL )
62 , bKeyFollowFocus( FALSE )
63 , m_bRecord( FALSE )
64 , m_bLog( FALSE )
66 aHookRefresh.SetTimeout( 500 );
67 aHookRefresh.SetTimeoutHdl( LINK( this, MacroRecorder, HookRefreshHdl) );
68 aHookRefresh.Start();
69 aEventListenerHdl = LINK( this, MacroRecorder, EventListener );
70 AddEventHooks();
73 MacroRecorder::~MacroRecorder()
75 aHookRefresh.Stop();
76 RemoveEventHooks();
79 void MacroRecorder::AddEventHooks()
81 Window *pTopLevel = Application::GetFirstTopLevelWindow();
82 while ( pTopLevel )
84 Window *pParent = pTopLevel;
85 while ( pParent->GetParent() )
86 pParent = pParent->GetParent();
88 pParent->RemoveChildEventListener( aEventListenerHdl ); // might be instrumented already
89 pParent->AddChildEventListener( aEventListenerHdl );
91 pTopLevel = Application::GetNextTopLevelWindow( pTopLevel );
95 void MacroRecorder::RemoveEventHooks()
97 Window *pTopLevel = Application::GetFirstTopLevelWindow();
98 while ( pTopLevel )
100 pTopLevel->RemoveChildEventListener( aEventListenerHdl );
101 pTopLevel = Application::GetNextTopLevelWindow( pTopLevel );
105 IMPL_LINK( MacroRecorder, HookRefreshHdl, void*, EMPTYARG )
107 AddEventHooks();
108 return 0;
111 void MacroRecorder::LogVCL( SmartId aParentID, USHORT nVCLWindowType, SmartId aID, String aMethod, USHORT nParam )
113 ::comphelper::UiEventsLogger::logVcl( aParentID.GetText(), nVCLWindowType, aID.GetText(), aMethod, nParam );
116 void MacroRecorder::LogVCL( SmartId aParentID, USHORT nVCLWindowType, SmartId aID, String aMethod )
118 ::comphelper::UiEventsLogger::logVcl( aParentID.GetText(), nVCLWindowType, aID.GetText(), aMethod );
121 Window* MacroRecorder::GetParentWithID( Window* pThis )
123 Window *pOverlap = pThis->GetWindow( WINDOW_OVERLAP );
124 while ( pOverlap != pThis && !pThis->GetSmartUniqueOrHelpId().HasAny() && pThis->GET_REAL_PARENT() )
125 pThis = pThis->GET_REAL_PARENT();
126 return pThis;
129 SmartId MacroRecorder::GetParentID( Window* pThis )
131 if ( pThis->GetParent() )
132 return pThis->GetParent()->GetSmartUniqueOrHelpId();
133 else
134 return SmartId();
137 IMPL_LINK( MacroRecorder, EventListener, VclSimpleEvent*, pEvent )
139 BOOL bSendData = FALSE;
141 if ( pEvent->ISA( VclWindowEvent ) )
143 VclWindowEvent* pWinEvent = ( VclWindowEvent* ) pEvent;
144 Window* pWin = pWinEvent->GetWindow();
145 ULONG nEventID = pWinEvent->GetId();
146 #if OSL_DEBUG_LEVEL > 1
147 if ( nEventID >= 1001 && nEventID != VCLEVENT_WINDOW_KEYUP )
148 nEventID = pWinEvent->GetId(); // Just something to set a breakpoint
149 else
150 return 0;
151 #endif
153 // check for different action after collecting keys
154 // send if there_is_something_to_send
155 // and eather event_is_not_of_interest
156 // or ( new_window and new_window_is_interesting ) ( ignore interesting events to uninteresting window )
158 if ( aKeyString.Len()
159 && ( ( nEventID != VCLEVENT_WINDOW_KEYINPUT
160 && nEventID != VCLEVENT_WINDOW_MOUSEMOVE
161 && nEventID != VCLEVENT_WINDOW_COMMAND
162 && nEventID != VCLEVENT_WINDOW_KEYUP )
163 || ( pKeyWin != pWin
164 && ( pWin->GetType() == WINDOW_CONTROL || pWin->GetType() == WINDOW_WINDOW )
169 if ( m_bRecord )
171 // we cannot access pKeyWin since it might have dissapeared
172 if ( bKeyFollowFocus )
173 StatementList::pRet->GenReturn( RET_MacroRecorder, aKeyUniqueID, (USHORT)M_TypeKeys, aKeyString, bKeyFollowFocus );
174 else
175 StatementList::pRet->GenReturn( RET_MacroRecorder, aKeyUniqueID, (USHORT)M_TypeKeys, aKeyString );
176 #if OSL_DEBUG_LEVEL > 1
177 StatementList::pRet->GenReturn( RET_MacroRecorder, aKeyUniqueID, (USHORT)M_TypeKeys, String::CreateFromInt32( nEventID ) );
178 #endif
179 bSendData = TRUE;
181 if ( m_bLog )
183 // HACK Too many KeyEvents generated LogVCL( SmartId(), 0, aKeyUniqueID, CUniString("TypeKeys"), aKeyString.Len() );
185 // cleanup
186 aKeyString.Erase();
187 pKeyWin = NULL;
188 bKeyFollowFocus = FALSE;
191 switch ( pWin->GetType() )
193 case WINDOW_TABPAGE:
194 switch( nEventID )
196 case VCLEVENT_WINDOW_ACTIVATE:
197 if ( m_bRecord )
199 StatementList::pRet->GenReturn( RET_MacroRecorder, SmartId(), (comm_USHORT)(M_SetPage|M_RET_NUM_CONTROL), static_cast<comm_ULONG>(pWin->GetSmartUniqueOrHelpId().GetNum()) ); //GetNum() ULONG != comm_ULONG on 64bit
200 bSendData = TRUE;
202 if ( m_bLog )
204 LogVCL( SmartId(), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("SetPage") );
206 break;
208 break;
209 case WINDOW_RADIOBUTTON:
210 case WINDOW_IMAGERADIOBUTTON:
211 switch( nEventID )
213 case VCLEVENT_BUTTON_CLICK: // VCLEVENT_RADIOBUTTON_TOGGLE
215 if ( ((RadioButton*)pWin)->IsChecked() )
217 if ( m_bRecord )
219 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), (comm_USHORT)M_Check );
220 bSendData = TRUE;
222 if ( m_bLog )
224 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Check") );
228 break;
230 break;
231 case WINDOW_CHECKBOX:
232 case WINDOW_TRISTATEBOX:
233 switch( nEventID )
235 case VCLEVENT_BUTTON_CLICK: //VCLEVENT_CHECKBOX_TOGGLE:
237 comm_USHORT nMethod;
238 String aMethod;
239 switch ( ((TriStateBox*)pWin)->GetState() )
241 case STATE_CHECK: nMethod = M_Check; aMethod = CUniString("Check"); break;
242 case STATE_NOCHECK: nMethod = M_UnCheck; aMethod = CUniString("UnCheck"); break;
243 case STATE_DONTKNOW: nMethod = M_TriState; aMethod = CUniString("TriState"); break;
244 default: nMethod = M_Check;
245 DBG_ERROR( "Unknown state in TriStateBox::GetState()" );
247 if ( m_bRecord )
249 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), nMethod );
250 bSendData = TRUE;
252 if ( m_bLog )
254 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), aMethod );
257 break;
259 break;
260 case WINDOW_EDIT:
261 case WINDOW_MULTILINEEDIT:
262 switch( nEventID )
264 case VCLEVENT_EDIT_MODIFY:
265 pEditModify = pWin;
266 aEditModifyString = ((Edit*)pWin)->GetText();
267 break;
269 break;
270 case WINDOW_MULTILISTBOX:
271 switch( nEventID )
273 case VCLEVENT_LISTBOX_SELECT:
274 Sound::Beep();
276 case WINDOW_LISTBOX:
277 switch( nEventID )
279 // case VCLEVENT_LISTBOX_DOUBLECLICK:
280 case VCLEVENT_LISTBOX_SELECT:
281 if ( m_bRecord )
283 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), (comm_USHORT)M_Select, comm_ULONG( ((ListBox*)pWin)->GetSelectEntryPos() +1 ) );
284 bSendData = TRUE;
286 if ( m_bLog )
288 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Select"), ((ListBox*)pWin)->GetSelectEntryPos() );
290 break;
292 break;
293 case WINDOW_COMBOBOX:
294 case WINDOW_PATTERNBOX:
295 case WINDOW_NUMERICBOX:
296 case WINDOW_METRICBOX:
297 case WINDOW_CURRENCYBOX:
298 case WINDOW_DATEBOX:
299 case WINDOW_TIMEBOX:
300 switch( nEventID )
302 case VCLEVENT_EDIT_MODIFY:
303 pEditModify = pWin;
304 aEditModifyString = ((Edit*)pWin)->GetText();
305 break;
306 case VCLEVENT_COMBOBOX_SELECT:
308 pEditModify = NULL;
309 aEditModifyString.Erase();
311 USHORT nPos = ((ComboBox*)pWin)->GetEntryPos(((ComboBox*)pWin)->GetText());
312 if ( m_bRecord )
314 if ( nPos == COMBOBOX_ENTRY_NOTFOUND )
315 Sound::Beep();
316 else
318 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), (comm_USHORT)M_Select, (comm_ULONG) nPos+1 );
319 bSendData = TRUE;
322 if ( m_bLog )
324 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Select"), nPos );
328 break;
329 case WINDOW_PUSHBUTTON:
330 case WINDOW_OKBUTTON:
331 case WINDOW_CANCELBUTTON:
332 case WINDOW_IMAGEBUTTON:
333 case WINDOW_MOREBUTTON:
334 case WINDOW_HELPBUTTON:
335 switch( nEventID )
337 case VCLEVENT_BUTTON_CLICK:
338 Window* pParent = pWin->GetParent();
339 BOOL bDone = FALSE;
340 if ( pParent->IsDialog() && !pWin->GetSmartUniqueOrHelpId().HasAny() )
342 switch ( pParent->GetType() )
344 case WINDOW_MESSBOX:
345 case WINDOW_INFOBOX:
346 case WINDOW_WARNINGBOX:
347 case WINDOW_ERRORBOX:
348 case WINDOW_QUERYBOX:
349 case WINDOW_BUTTONDIALOG:
351 comm_USHORT nMethod;
352 String aMethod;
353 ButtonDialog* pBD = (ButtonDialog*)pParent;
355 // we have to find the current Button ID ourselves since it is not generated at this point :-(
356 USHORT nCurrentButtonId = 0xffff; // Some wild value to wak up people
357 USHORT i;
358 for ( i = 0; i < pBD->GetButtonCount() ; i++ )
360 if ( pBD->GetPushButton( pBD->GetButtonId(i) ) == pWin )
362 nCurrentButtonId = pBD->GetButtonId(i);
363 break;
367 switch ( nCurrentButtonId )
369 case BUTTONID_OK: nMethod = M_OK; aMethod = CUniString("OK"); break;
370 case BUTTONID_CANCEL: nMethod = M_Cancel; aMethod = CUniString("Cancel"); break;
371 case BUTTONID_YES: nMethod = M_Yes; aMethod = CUniString("Yes"); break;
372 case BUTTONID_NO: nMethod = M_No; aMethod = CUniString("No"); break;
373 case BUTTONID_RETRY: nMethod = M_Repeat; aMethod = CUniString("Repeat"); break;
374 case BUTTONID_HELP: nMethod = M_Help; aMethod = CUniString("Help"); break;
375 default: nMethod = M_Click; aMethod = CUniString("Click");
377 if ( m_bRecord )
379 if ( nMethod != M_Click )
380 StatementList::pRet->GenReturn( RET_MacroRecorder, SmartId( 0 ), nMethod );
381 else
382 StatementList::pRet->GenReturn( RET_MacroRecorder, SmartId( 0 ), nMethod, (comm_ULONG)nCurrentButtonId );
383 bSendData = TRUE;
385 if ( m_bLog )
387 if ( nMethod != M_Click )
388 LogVCL( SmartId(), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), aMethod );
389 else
390 LogVCL( SmartId(), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), aMethod, nCurrentButtonId );
391 bDone = TRUE;
394 break;
395 default:
397 comm_USHORT nMethod;
398 String aMethod;
399 switch ( pWin->GetType() )
401 case WINDOW_OKBUTTON: nMethod = M_OK; aMethod = CUniString("OK"); break;
402 case WINDOW_CANCELBUTTON: nMethod = M_Cancel; aMethod = CUniString("Cancel"); break;
403 case WINDOW_HELPBUTTON: nMethod = M_Help; aMethod = CUniString("Help"); break;
404 default: nMethod = M_Default;aMethod = CUniString("Unknown Button");
405 DBG_ERROR( "Unknown Button" );
407 if ( m_bRecord )
409 StatementList::pRet->GenReturn( RET_MacroRecorder, pParent->GetSmartUniqueOrHelpId(), nMethod );
410 bSendData = TRUE;
412 if ( m_bLog )
414 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), aMethod );
415 bDone = TRUE;
418 break;
421 if ( m_bRecord )
423 if ( !bSendData && pWin->GetSmartUniqueOrHelpId().HasAny() )
425 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), (comm_USHORT)M_Click );
426 bSendData = TRUE;
429 if ( m_bLog )
431 if ( !bDone )
432 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Click") );
435 break;
436 /* case C_MoreButton:
437 switch( nEventID )
439 case M_IsOpen :
440 pRet->GenReturn ( RET_Value, nUId, ((MoreButton*)pControl)->GetState());
441 break;
442 case M_Click :
443 ((MoreButton*)pControl)->Click();
444 break;
445 case M_Open :
446 ((MoreButton*)pControl)->SetState(TRUE);
447 break;
448 case M_Close :
449 ((MoreButton*)pControl)->SetState(FALSE);
450 break;
451 default:
452 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "MoreButton" ) );
453 break;
455 break;*/
456 case WINDOW_SPINFIELD:
457 case WINDOW_PATTERNFIELD:
458 case WINDOW_NUMERICFIELD:
459 case WINDOW_METRICFIELD:
460 case WINDOW_CURRENCYFIELD:
461 case WINDOW_DATEFIELD:
462 case WINDOW_TIMEFIELD:
463 switch( nEventID )
465 case VCLEVENT_SPINFIELD_UP:
466 case VCLEVENT_SPINFIELD_DOWN:
467 case VCLEVENT_SPINFIELD_FIRST:
468 case VCLEVENT_SPINFIELD_LAST:
470 pEditModify = NULL;
471 aEditModifyString.Erase();
473 comm_USHORT nMethod;
474 String aMethod;
475 switch ( nEventID )
477 case VCLEVENT_SPINFIELD_UP: nMethod = M_More; aMethod = CUniString("More"); break;
478 case VCLEVENT_SPINFIELD_DOWN: nMethod = M_Less; aMethod = CUniString("Less"); break;
479 case VCLEVENT_SPINFIELD_FIRST: nMethod = M_ToMin; aMethod = CUniString("ToMin"); break;
480 case VCLEVENT_SPINFIELD_LAST: nMethod = M_ToMax; aMethod = CUniString("ToMax"); break;
481 default: nMethod = M_ToMin; aMethod = CUniString("Unknown");
482 DBG_ERROR( "Unknown EventID in Spinfield" );
484 if ( m_bRecord )
486 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), nMethod );
487 bSendData = TRUE;
489 if ( m_bLog )
491 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), aMethod );
494 break;
495 case VCLEVENT_EDIT_MODIFY:
496 pEditModify = pWin;
497 aEditModifyString = ((SpinField*)pWin)->GetText();
498 break;
500 break;
502 case WINDOW_MENUBUTTON:
503 switch( nEventID )
505 case VCLEVENT_BUTTON_CLICK:
506 if ( m_bRecord )
508 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), (comm_USHORT)M_Click );
509 bSendData = TRUE;
511 if ( m_bLog )
513 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Click") );
515 break;
516 /* Keyevent or Timeout
517 case M_Open :
519 MouseEvent aMEvnt;
520 Point aPt( pControl->GetSizePixel().Width() / 2, pControl->GetSizePixel().Height() / 2 );
521 aMEvnt = MouseEvent( aPt,1,MOUSE_SIMPLECLICK,MOUSE_LEFT );
522 ImplMouseButtonDown( pControl, aMEvnt );
524 ULONG nStart = Time::GetSystemTicks();
525 ULONG nDelay = pControl->GetSettings().GetMouseSettings().GetActionDelay();
526 while ( ( Time::GetSystemTicks() - nStart ) < nDelay + 100 )
527 SafeReschedule();
529 ImplMouseButtonUp ( pControl, aMEvnt );
531 break;*/
533 break;
534 case WINDOW_TOOLBOX:
536 ToolBox *pTB = ((ToolBox*)pWin);
537 switch( nEventID )
539 case VCLEVENT_TOOLBOX_SELECT:
540 { // a Button has been clicked
541 // so this cannot be a tearoff or OpenMenu anymore
542 pActionParent = NULL;
543 // compare to 1 for floating ToolBoxes
544 if ( m_bRecord )
546 if ( !pWin->GetSmartUniqueOrHelpId().HasAny() || pWin->GetSmartUniqueOrHelpId().Matches( 1 ) )
547 // generate direct Button access
548 StatementList::pRet->GenReturn( RET_MacroRecorder, SmartId( pTB->GetItemCommand( pTB->GetCurItemId() ) ), (comm_USHORT)(M_Click) );
549 else
550 // access via Toolbox
551 StatementList::pRet->GenReturn( RET_MacroRecorder, pTB->GetSmartUniqueOrHelpId(), (comm_USHORT)(M_Click|M_RET_NUM_CONTROL), static_cast<comm_ULONG>(pTB->GetHelpId( pTB->GetCurItemId() )) ); // GetHelpId() ULONG != comm_ULONG on 64bit
552 bSendData = TRUE;
554 /* not needed if ( m_bLog )
558 break;
559 case VCLEVENT_TOOLBOX_CLICK: /// ATTENTION this is called during initialisation of toolbox. whoever 'invented' this
560 pActionParent = pTB;
561 break;
562 // case VCLEVENT_WINDOW_SHOW: // not usable ATM. see above
563 // if ( pActionParent )
564 // { // a new toolbox opens up, might be a tearoff
565 // if ( pActionParent != pWin )
566 // { // it IS a tearoff not an undock
567 // // compare to 1 for floating ToolBoxes
568 // if ( m_bRecord )
569 // {
570 // if ( !pWin->GetSmartUniqueOrHelpId().HasAny() || pWin->GetSmartUniqueOrHelpId().Matches( 1 ) )
571 // // generate direct Button access
572 // StatementList::pRet->GenReturn( RET_MacroRecorder, SmartId( pActionParent->GetHelpId( pActionParent->GetCurItemId() ) ), (comm_USHORT)(M_TearOff) );
573 // else
574 // // access via Toolbox
575 // StatementList::pRet->GenReturn( RET_MacroRecorder, pActionParent->GetSmartUniqueOrHelpId(), (comm_USHORT)(M_TearOff|M_RET_NUM_CONTROL), static_cast<comm_ULONG>(pActionParent->GetHelpId( pActionParent->GetCurItemId() )) ); // GetHelpId() ULONG != comm_ULONG on 64bit
576 // bSendData = TRUE;
577 // }
578 // if ( m_bLog )
579 // {
580 // LogVCL( pActionParent->GetSmartUniqueOrHelpId(), pWin->GetType(), SmartId( pActionParent->GetHelpId( pActionParent->GetCurItemId() ) ), CUniString("TearOff") );
581 // }
582 // }
583 // pActionParent = NULL;
584 // }
585 // break;
586 case VCLEVENT_TOOLBOX_DEACTIVATE:
587 pActionParent = NULL;
588 break;
591 break;
592 /* ToolBox *pTB = ((ToolBox*)pControl);
593 if ( pTB->GetUniqueOrHelpId() != nUId ) // Also Button auf der ToolBox gefunden
595 if ( nParams == PARAM_NONE )
596 { // Wir fälschen einen Parameter
597 nParams = PARAM_USHORT_1;
598 nNr1 = nUId;
600 else
601 ReportError( nUId, GEN_RES_STR1( S_INTERNAL_ERROR, MethodString( nMethodId ) ) );
604 #define FIND_HELP\
606 if( nParams == PARAM_USHORT_1 )\
607 nLNr1 = nNr1;\
608 for ( nNr1 = 0; nNr1 < pTB->GetItemCount() && nLNr1 != pTB->GetHelpId(pTB->GetItemId(nNr1)) ; nNr1++ ) {}\
609 bBool1 = nLNr1 == pTB->GetHelpId(pTB->GetItemId(nNr1));\
610 if ( !bBool1 )\
611 ReportError( nUId, GEN_RES_STR1( S_HELPID_ON_TOOLBOX_NOT_FOUND, MethodString( nMethodId ) ) );\
612 else\
614 if ( !pTB->IsItemEnabled( pTB->GetItemId(nNr1) ) && nMethodId != _M_IsEnabled )\
616 ReportError( nUId, GEN_RES_STR1( S_BUTTON_DISABLED_ON_TOOLBOX, MethodString( nMethodId ) ) );\
617 bBool1 = FALSE;\
619 else if ( !pTB->IsItemVisible( pTB->GetItemId(nNr1) ) )\
621 ReportError( nUId, GEN_RES_STR1( S_BUTTON_HIDDEN_ON_TOOLBOX, MethodString( nMethodId ) ) );\
622 bBool1 = FALSE;\
624 else\
626 if ( pTB->GetItemRect(pTB->GetItemId(nNr1)).IsEmpty() )\
628 USHORT nLine = pTB->GetCurLine();\
631 pTB->ShowLine( FALSE );\
632 for ( int i = 1 ; i < 30 ; i++ )\
633 SafeReschedule();\
635 while ( pTB->GetCurLine() != nLine && pTB->GetItemRect(pTB->GetItemId(nNr1)).IsEmpty() );\
636 pTB->Invalidate( pTB->GetScrollRect() );\
638 if ( pTB->GetItemRect(pTB->GetItemId(nNr1)).IsEmpty() )\
640 ReportError( nUId, GEN_RES_STR1( S_CANNOT_MAKE_BUTTON_VISIBLE_IN_TOOLBOX, MethodString( nMethodId ) ) );\
641 bBool1 = FALSE;\
647 switch( nEventID )
649 case M_SetNextToolBox :
650 if ( (nParams & PARAM_STR_1) )
651 pTB->SetNextToolBox( aString1 );
652 else
653 pTB->SetNextToolBox( pTB->GetNextToolBox() );
654 pTB->NextToolBox();
655 break;
656 case M_GetNextToolBox :
657 pRet->GenReturn ( RET_Value, nUId, (String)pTB->GetNextToolBox());
658 break;
659 default:
660 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "ToolBox" ) );
661 break;
664 break;
666 case WINDOW_CONTROL:
667 case WINDOW_WINDOW:
668 switch( nEventID )
670 case VCLEVENT_WINDOW_COMMAND:
671 break;
672 case VCLEVENT_WINDOW_KEYINPUT:
674 const KeyEvent *pKeyEvent = ((KeyEvent*)pWinEvent->GetData());
675 const KeyCode aKeyCode = pKeyEvent->GetKeyCode();
676 if ( pKeyEvent )
678 pKeyWin = pWin;
679 Window *pIdWin = GetParentWithID( pWin );
680 if ( pIdWin != pWin )
681 bKeyFollowFocus = TRUE;
682 aKeyUniqueID = pIdWin->GetSmartUniqueOrHelpId();
683 if ( m_bLog )
685 // HACK Too many KeyEvents generated if ( aKeyString.Len() == 0 )
686 // HACK Too many KeyEvents generated LogVCL( SmartId(), 0, aKeyUniqueID, CUniString("TypeKeysStart") );
688 if ( ( !aKeyCode.IsMod1() && !aKeyCode.IsMod2() ) &&
689 (( aKeyCode.GetGroup() == KEYGROUP_NUM) ||
690 ( aKeyCode.GetGroup() == KEYGROUP_ALPHA) ||
691 ( aKeyCode.GetCode() == KEY_SPACE) ||
692 ( aKeyCode.GetCode() == KEY_ADD) ||
693 ( aKeyCode.GetCode() == KEY_SUBTRACT) ||
694 ( aKeyCode.GetCode() == KEY_MULTIPLY) ||
695 ( aKeyCode.GetCode() == KEY_DIVIDE) ||
696 ( aKeyCode.GetCode() == KEY_POINT) ||
697 ( aKeyCode.GetCode() == KEY_COMMA) ||
698 ( aKeyCode.GetCode() == KEY_EQUAL) ||
699 ( aKeyCode.GetCode() == 0) ) )
701 DBG_ASSERT( pKeyEvent->GetCharCode(), "no charcode found" );
702 aKeyString += pKeyEvent->GetCharCode();
704 else
705 { // not a regular key, transfer KeyCode
706 aKeyString += sal_Unicode(1); // mask it
707 // extra for '>' which is coded as <SHIFT GREATER>
708 if ( pKeyEvent->GetCharCode() == '>' )
709 aKeyString += sal_Unicode( KEY_GREATER | (aKeyCode.GetAllModifier() & ~KEY_SHIFT) );
710 else
711 aKeyString += sal_Unicode( aKeyCode.GetCode() | aKeyCode.GetAllModifier() );
715 break;
717 case VCLEVENT_WINDOW_MOUSEMOVE:
718 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
719 case VCLEVENT_WINDOW_MOUSEBUTTONUP:
722 break;
726 break;
727 case WINDOW_DOCKINGWINDOW:
728 // switch( nEventID )
730 // case 1 .. 0xffff:
731 DBG_TRACE3( "TT_VCLMessage %u %u %X",nEventID, pWin->GetType(), pWin );
732 // BOOL bx = ((DockingWindow*)pWin)->IsFloatingMode();
733 // break;
734 /* case M_Dock :
735 if ( ((DockingWindow*)pControl)->IsFloatingMode() )
736 ((DockingWindow*)pControl)->SetFloatingMode(FALSE);
737 else
738 ReportError( nUId, GEN_RES_STR1( S_ALLOWED_ONLY_IN_FLOATING_MODE, MethodString( nMethodId ) ) );
739 break;
740 case M_Undock :
741 if ( !((DockingWindow*)pControl)->IsFloatingMode() )
742 ((DockingWindow*)pControl)->SetFloatingMode(TRUE);
743 else
744 ReportError( nUId, GEN_RES_STR1( S_ALLOWED_ONLY_IN_FLOATING_MODE, MethodString( nMethodId ) ) );
745 break;
746 case M_IsDocked :
747 pRet->GenReturn ( RET_Value, nUId, (comm_BOOL) !((DockingWindow*)pControl)->IsFloatingMode());
748 break;
749 case M_Close:
750 //nWindowWaitUId = nUId;
751 DBG_ASSERT( nUId == pControl->GetUniqueOrHelpId(), "nUID != UniqueOrHelpId");
752 SET_WINP_CLOSING(pControl);
753 ((DockingWindow*)pControl)->Close();
754 break;
755 case M_Size:
756 case M_Move:
757 case M_IsMax :
758 case M_Minimize :
759 case M_Maximize :
760 if ( ((DockingWindow*)pControl)->IsFloatingMode() )
762 pControl = ((DockingWindow*)pControl)->GetFloatingWindow();
763 goto FloatWin;
765 else
766 ReportError( nUId, GEN_RES_STR1( S_ALLOWED_ONLY_IN_DOCKING_MODE, MethodString( nMethodId ) ) );
767 break;
768 case M_Help: // Alles was unten weiterbehandelt werden soll
769 goto MoreDialog;
771 default:
772 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "DockingWindow" ) );
773 break;*/
775 break;
782 case WINDOW_FLOATINGWINDOW:
784 DBG_TRACE3( "TT_VCLMessage %u %u %X",nEventID, pWin->GetType(), pWin );
785 // FloatingWindow *pFW = ((FloatingWindow*)pWin);
786 /* switch( nEventID )
789 // M_OpenMenu an einem ToolboxButton
790 case VCLEVENT_WINDOW_SHOW:
791 if ( pActionParent )
792 { // a new FloatingWindow opens up, so we assume an OpenMenu
793 // compare to 1 for floating ToolBoxes
794 if ( ( pActionParent->GetUniqueOrHelpId() == 0 || pActionParent->GetUniqueOrHelpId() == 1 ) )
795 // generate direct Button access
796 StatementList::pRet->GenReturn( RET_MacroRecorder, pActionParent->GetHelpId( pActionParent->GetCurItemId() ), (comm_USHORT)(M_OpenMenu) );
797 else
798 // access via Toolbox
799 StatementList::pRet->GenReturn( RET_MacroRecorder, pActionParent->GetUniqueOrHelpId(), (comm_USHORT)(M_OpenMenu|M_RET_NUM_CONTROL), pActionParent->GetHelpId( pActionParent->GetCurItemId() ) );
800 bSendData = TRUE;
802 break;
805 */ }
806 break;
808 case M_AnimateMouse :
809 AnimateMouse( pControl, MitteOben);
810 break;
811 case M_IsMax :
812 pRet->GenReturn ( RET_Value, nUId, (comm_BOOL)!((FloatingWindow*)pControl)->IsRollUp());
813 break;
814 case M_Minimize :
815 ((FloatingWindow*)pControl)->RollUp();
816 break;
817 case M_Maximize :
818 ((FloatingWindow*)pControl)->RollDown();
819 break;
820 case M_Size:
822 if ( pControl->GetStyle() & WB_SIZEABLE )
824 pControl->SetSizePixel(Size(nNr1,nNr2));
825 pControl->Resize();
827 else
828 ReportError( nUId, GEN_RES_STR1( S_SIZE_NOT_CHANGEABLE, MethodString( nMethodId ) ) );
829 break;
831 case M_Close:
832 DBG_ASSERT( nUId == pControl->GetUniqueOrHelpId(), "nUID != UniqueOrHelpId");
833 SET_WINP_CLOSING(pControl);
834 ((FloatingWindow*)pControl)->Close();
835 break;
836 case M_Help: // Alles was unten weiterbehandelt werden soll
837 case M_Move:
838 goto MoreDialog;
839 default:
840 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "FloatingWin" ) );
841 break;
843 break;*/
853 case C_ModelessDlg:
854 case C_Dlg:
855 case C_TabDlg:
856 MoreDialog:
857 switch( nEventID )
860 // (Rect GetRect)
862 case M_AnimateMouse :
863 AnimateMouse( pControl, MitteOben);
864 break;
865 case M_Close:
866 DBG_ASSERT( nUId == pControl->GetUniqueOrHelpId(), "nUID != UniqueOrHelpId");
867 SET_WINP_CLOSING(pControl);
868 ((SystemWindow*)pControl)->Close();
869 break;
870 case M_Move:
872 pControl->SetPosPixel(Point(nNr1,nNr2));
873 break;
875 default:
876 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "Dialog" ) );
877 break;
879 break;*/
894 case C_WorkWin:
895 switch( nEventID )
897 case M_Close:
898 DBG_ASSERT( nUId == pControl->GetUniqueOrHelpId(), "nUID != UniqueOrHelpId");
899 SET_WINP_CLOSING(pControl);
900 ((WorkWindow*)pControl)->Close();
901 break;
902 case M_Size:
903 case M_Move:
904 goto FloatWin;
905 break;
906 case M_Help: // Alles was unten weiterbehandelt werden soll
907 goto MoreDialog;
908 default:
909 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "WorkWindow" ) );
910 break;
912 break;
916 /* case C_TabPage:
917 switch( nEventID )
920 break;*/
935 case C_MessBox:
936 case C_InfoBox:
937 case C_WarningBox:
938 case C_ErrorBox:
939 case C_QueryBox:
941 BOOL bDone = TRUE;
942 MessBox* pMB = (MessBox*)pControl;
943 switch( nEventID )
945 case M_GetCheckBoxText:
946 pRet->GenReturn ( RET_Value, nUId, pMB->GetCheckBoxText() );
947 break;
948 case M_IsChecked :
949 pRet->GenReturn ( RET_Value, nUId, comm_BOOL( pMB->GetCheckBoxState() == STATE_CHECK) );
950 break;
951 case M_GetState :
952 pRet->GenReturn ( RET_Value, nUId, comm_ULONG( pMB->GetCheckBoxState() ));
953 break;
954 case M_Check :
955 pMB->SetCheckBoxState( STATE_CHECK );
956 break;
957 case M_UnCheck :
958 pMB->SetCheckBoxState( STATE_NOCHECK );
959 break;
960 case M_GetText :
961 pRet->GenReturn ( RET_Value, nUId, pMB->GetMessText());
962 break;
964 default:
965 bDone = FALSE;
966 break;
968 if ( bDone )
969 break; // break the case here else continue at C_ButtonDialog
971 case C_ButtonDialog:
973 ButtonDialog* pBD = (ButtonDialog*)pControl;
974 #if OSL_DEBUG_LEVEL > 1
975 m_pDbgWin->AddText( "Working MessBox: " );
976 if (pControl->IsVisible())
977 m_pDbgWin->AddText("*(Visible)\n");
978 else
979 m_pDbgWin->AddText("*(nicht Visible)\n");
980 #endif
981 switch( nEventID )
983 case M_GetText :
984 pRet->GenReturn ( RET_Value, nUId, pControl->GetText());
985 break;
986 case M_Click:
987 if ( nParams & PARAM_USHORT_1 )
989 if ( pBD->GetPushButton( nNr1 ) )
991 if ( nNr1 != BUTTONID_HELP )
993 SET_WINP_CLOSING(pControl);
995 pBD->GetPushButton( nNr1 )->Click();
997 else
998 ReportError( nUId, GEN_RES_STR2( S_NO_DEFAULT_BUTTON, UniString::CreateFromInt32( nNr1 ), MethodString( nMethodId ) ) );
1000 else
1001 ReportError( nUId, GEN_RES_STR1( S_BUTTONID_REQUIRED, MethodString( nMethodId ) ) );
1002 break;
1003 case M_GetButtonCount :
1004 pRet->GenReturn ( RET_Value, nUId, comm_ULONG(pBD->GetButtonCount()));
1005 break;
1006 case M_GetButtonId :
1007 if ( ValueOK(nUId, MethodString( nMethodId ),nNr1,pBD->GetButtonCount()) )
1008 pRet->GenReturn ( RET_Value, nUId, comm_ULONG(pBD->GetButtonId(nNr1-1)));
1009 break;
1010 default:
1011 ReportError( nUId, GEN_RES_STR2c2( S_UNKNOWN_METHOD, MethodString(nMethodId), "MessageBox" ) );
1012 break;
1014 break;
1023 switch( nEventID )
1025 case VCLEVENT_CONTROL_LOSEFOCUS:
1026 if ( pEditModify == pWin )
1028 if ( m_bRecord )
1030 StatementList::pRet->GenReturn( RET_MacroRecorder, pWin->GetSmartUniqueOrHelpId(), M_SetText, aEditModifyString );
1031 bSendData = TRUE;
1033 if ( m_bLog )
1035 LogVCL( GetParentID( pWin ), pWin->GetType(), pWin->GetSmartUniqueOrHelpId(), CUniString("Modify") );
1037 pEditModify = NULL;
1038 aEditModifyString.Erase(); //could be somewhat lengthy
1040 break;
1043 pLastWin = pWin;
1045 } // if
1046 else if ( pEvent->ISA( VclMenuEvent ) )
1048 // VclMenuEvent* pMenuEvent = ( VclMenuEvent* ) pEvent;
1052 if ( bSendData )
1053 new StatementFlow( NULL, F_EndCommandBlock ); // Kommando zum Senden erzeugen und in que eintragen
1055 return 0;
1060 static ::osl::Mutex * getRecorderMutex()
1062 static ::osl::Mutex * pMutex = NULL;
1063 if(pMutex==NULL)
1065 ::osl::MutexGuard aGuard(::osl::Mutex::getGlobalMutex());
1066 if(pMutex==NULL)
1067 pMutex = new ::osl::Mutex();
1069 return pMutex;
1073 void MacroRecorder::CheckDelete()
1075 ::osl::MutexGuard aGuard( getRecorderMutex() );
1076 if ( !m_bRecord && !m_bLog )
1078 pMacroRecorder = NULL;
1079 delete this;
1084 MacroRecorder* MacroRecorder::GetMacroRecorder()
1086 ::osl::MutexGuard aGuard( getRecorderMutex() );
1087 if ( !pMacroRecorder )
1088 pMacroRecorder = new MacroRecorder;
1090 return pMacroRecorder;
1093 BOOL MacroRecorder::HasMacroRecorder()
1095 ::osl::MutexGuard aGuard( getRecorderMutex() );
1096 return pMacroRecorder != NULL;