Lines 58-63
Link Here
|
58 |
#include <com/sun/star/awt/XDialog.hpp> |
58 |
#include <com/sun/star/awt/XDialog.hpp> |
59 |
#include <com/sun/star/awt/KeyEvent.hpp> |
59 |
#include <com/sun/star/awt/KeyEvent.hpp> |
60 |
#include <com/sun/star/awt/MouseEvent.hpp> |
60 |
#include <com/sun/star/awt/MouseEvent.hpp> |
|
|
61 |
#include <com/sun/star/awt/XFixedText.hpp> //liuchen 2009-6-5 |
62 |
#include <com/sun/star/awt/XTextComponent.hpp> //liuchen 2009-6-5 |
63 |
#include <com/sun/star/awt/XComboBox.hpp> //liuchen 2009-6-18 |
64 |
#include <com/sun/star/awt/XRadioButton.hpp> //liuchen 2009-7-30 |
61 |
|
65 |
|
62 |
#include <msforms/ReturnInteger.hpp> |
66 |
#include <msforms/ReturnInteger.hpp> |
63 |
|
67 |
|
Lines 90-95
using namespace ::com::sun::star::script;
Link Here
|
90 |
using namespace ::com::sun::star::uno; |
94 |
using namespace ::com::sun::star::uno; |
91 |
using namespace ::ooo::vba; |
95 |
using namespace ::ooo::vba; |
92 |
|
96 |
|
|
|
97 |
#define MAP_CHAR_LEN(x) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(x))//liuchen 2009-6-8 |
98 |
#define GET_TYPE(x) ::getCppuType((uno::Reference< x > *)0); |
93 |
|
99 |
|
94 |
// Some constants |
100 |
// Some constants |
95 |
const static rtl::OUString DELIM = rtl::OUString::createFromAscii( "::" ); |
101 |
const static rtl::OUString DELIM = rtl::OUString::createFromAscii( "::" ); |
Lines 254-263
Sequence< Any > ooKeyPressedToVBAKeyUpDown( const Sequence< Any >& params )
Link Here
|
254 |
|
260 |
|
255 |
typedef Sequence< Any > (*Translator)(const Sequence< Any >&); |
261 |
typedef Sequence< Any > (*Translator)(const Sequence< Any >&); |
256 |
|
262 |
|
|
|
263 |
//liuchen 2009-6-23 |
264 |
//expand the "TranslateInfo" struct to support more kinds of events |
257 |
struct TranslateInfo |
265 |
struct TranslateInfo |
258 |
{ |
266 |
{ |
259 |
rtl::OUString sVBAName; |
267 |
rtl::OUString sVBAName; //vba event name |
260 |
Translator toVBA; |
268 |
Translator toVBA; //the method to convert OO event parameters to VBA event parameters |
|
|
269 |
bool (*ApproveRule)(const ScriptEvent& evt, void* pPara); //this method is used to determine which types of controls should execute the event |
270 |
void *pPara; //Parameters for the above approve method |
261 |
}; |
271 |
}; |
262 |
|
272 |
|
263 |
|
273 |
|
Lines 266-271
std::list< TranslateInfo >,
Link Here
|
266 |
::rtl::OUStringHash, |
276 |
::rtl::OUStringHash, |
267 |
::std::equal_to< ::rtl::OUString > > EventInfoHash; |
277 |
::std::equal_to< ::rtl::OUString > > EventInfoHash; |
268 |
|
278 |
|
|
|
279 |
//liuchen 2009-6-23 |
280 |
struct TranslatePropMap |
281 |
{ |
282 |
rtl::OUString sEventInfo; //OO event name |
283 |
TranslateInfo aTransInfo; |
284 |
}; |
285 |
|
286 |
bool ApproveAll(const ScriptEvent& evt, void* pPara); //allow all types of controls to execute the event |
287 |
bool ApproveType(const ScriptEvent& evt, void* pPara); //certain types of controls should execute the event, those types are given by pPara |
288 |
bool DenyType(const ScriptEvent& evt, void* pPara); //certain types of controls should not execute the event, those types are given by pPara |
289 |
bool DenyMouseDrag(const ScriptEvent& evt, void* pPara); //used for VBA MouseMove event when "Shift" key is pressed |
290 |
|
291 |
struct TypeList |
292 |
{ |
293 |
uno::Type* pTypeList; |
294 |
int nListLength; |
295 |
}; |
296 |
|
297 |
Type typeXFixedText = GET_TYPE(awt::XFixedText); |
298 |
Type typeXTextComponent = GET_TYPE(awt::XTextComponent); |
299 |
Type typeXComboBox = GET_TYPE(awt::XComboBox); |
300 |
Type typeXRadioButton = GET_TYPE(awt::XRadioButton); |
301 |
|
302 |
|
303 |
TypeList fixedTextList = {&typeXFixedText, 1}; |
304 |
TypeList textCompList = {&typeXTextComponent, 1}; |
305 |
TypeList radioButtonList = {&typeXRadioButton, 1}; |
306 |
TypeList comboBoxList = {&typeXComboBox, 1}; |
307 |
|
308 |
//this array stores the OO event to VBA event translation info |
309 |
static TranslatePropMap aTranslatePropMap_Impl[] = |
310 |
{ |
311 |
// actionPerformed ooo event |
312 |
{ MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Click"), NULL, ApproveAll, NULL } }, |
313 |
{ MAP_CHAR_LEN("actionPerformed"), { MAP_CHAR_LEN("_Change"), NULL, DenyType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event is not the same as OptionalButton_Click event |
314 |
|
315 |
// itemStateChanged ooo event |
316 |
{ MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Click"), NULL, ApproveType, (void*)(&comboBoxList) } }, //liuchen, add to support VBA ComboBox_Click event |
317 |
{ MAP_CHAR_LEN("itemStateChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveType, (void*)(&radioButtonList) } }, //liuchen 2009-7-30, OptionalButton_Change event should be triggered when the button state is changed |
318 |
|
319 |
// changed ooo event |
320 |
{ MAP_CHAR_LEN("changed"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } }, |
321 |
|
322 |
// focusGained ooo event |
323 |
{ MAP_CHAR_LEN("focusGained"), { MAP_CHAR_LEN("_GotFocus"), NULL, ApproveAll, NULL } }, |
324 |
|
325 |
// focusLost ooo event |
326 |
{ MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_LostFocus"), NULL, ApproveAll, NULL } }, |
327 |
{ MAP_CHAR_LEN("focusLost"), { MAP_CHAR_LEN("_Exit"), NULL, ApproveType, (void*)(&textCompList) } }, //liuchen, add to support VBA TextBox_Exit event |
328 |
|
329 |
// adjustmentValueChanged ooo event |
330 |
{ MAP_CHAR_LEN("adjustmentValueChanged"), { MAP_CHAR_LEN("_Scroll"), NULL, ApproveAll, NULL } }, |
331 |
{ MAP_CHAR_LEN("adjustmentValueChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } }, |
332 |
|
333 |
// textChanged ooo event |
334 |
{ MAP_CHAR_LEN("textChanged"), { MAP_CHAR_LEN("_Change"), NULL, ApproveAll, NULL } }, |
335 |
|
336 |
// keyReleased ooo event |
337 |
{ MAP_CHAR_LEN("keyReleased"), { MAP_CHAR_LEN("_KeyUp"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } }, |
338 |
|
339 |
// mouseReleased ooo event |
340 |
{ MAP_CHAR_LEN("mouseReleased"), { MAP_CHAR_LEN("_Click"), ooMouseEvtToVBAMouseEvt, ApproveType, (void*)(&fixedTextList) } }, //liuchen, add to support VBA Label_Click event |
341 |
{ MAP_CHAR_LEN("mouseReleased"), { MAP_CHAR_LEN("_MouseUp"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } }, |
342 |
|
343 |
// mousePressed ooo event |
344 |
{ MAP_CHAR_LEN("mousePressed"), { MAP_CHAR_LEN("_MouseDown"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } }, |
345 |
{ MAP_CHAR_LEN("mousePressed"), { MAP_CHAR_LEN("_DblClick"), ooMouseEvtToVBADblClick, ApproveAll, NULL } }, |
346 |
|
347 |
// mouseMoved ooo event |
348 |
{ MAP_CHAR_LEN("mouseMoved"), { MAP_CHAR_LEN("_MouseMove"), ooMouseEvtToVBAMouseEvt, ApproveAll, NULL } }, |
349 |
{ MAP_CHAR_LEN("mouseDragged"), { MAP_CHAR_LEN("_MouseMove"), ooMouseEvtToVBAMouseEvt, DenyMouseDrag, NULL } }, //liuchen, add to support VBA MouseMove event when the "Shift" key is pressed |
350 |
|
351 |
// keyPressed ooo event |
352 |
{ MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyDown"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } }, |
353 |
{ MAP_CHAR_LEN("keyPressed"), { MAP_CHAR_LEN("_KeyPress"), ooKeyPressedToVBAKeyUpDown, ApproveAll, NULL } } |
354 |
}; |
269 |
|
355 |
|
270 |
EventInfoHash& getEventTransInfo() |
356 |
EventInfoHash& getEventTransInfo() |
271 |
{ |
357 |
{ |
Lines 273-363
EventInfoHash& getEventTransInfo()
Link Here
|
273 |
static EventInfoHash eventTransInfo; |
359 |
static EventInfoHash eventTransInfo; |
274 |
if ( !initialised ) |
360 |
if ( !initialised ) |
275 |
{ |
361 |
{ |
276 |
TranslateInfo info; |
362 |
rtl::OUString sEventInfo = MAP_CHAR_LEN(""); |
277 |
// actionPerformed ooo event |
363 |
TranslatePropMap* pTransProp = aTranslatePropMap_Impl; |
278 |
std::list< TranslateInfo > actionInfos; |
364 |
int nCount = sizeof(aTranslatePropMap_Impl) / sizeof(aTranslatePropMap_Impl[0]); |
279 |
info.sVBAName = rtl::OUString::createFromAscii("_Click"); |
365 |
|
280 |
info.toVBA = NULL; |
366 |
int i = 0; |
281 |
actionInfos.push_back( info ); |
367 |
while (i < nCount) |
282 |
info.sVBAName = rtl::OUString::createFromAscii("_Change"); |
368 |
{ |
283 |
info.toVBA = NULL; |
369 |
sEventInfo = pTransProp->sEventInfo; |
284 |
actionInfos.push_back( info ); |
370 |
std::list< TranslateInfo > infoList; |
285 |
eventTransInfo[ rtl::OUString::createFromAscii("actionPerformed") ] = actionInfos; |
371 |
do |
286 |
// changed ooo event |
372 |
{ |
287 |
std::list< TranslateInfo > changeInfos; |
373 |
infoList.push_back( pTransProp->aTransInfo ); |
288 |
info.sVBAName = rtl::OUString::createFromAscii("_Change"); |
374 |
pTransProp++; |
289 |
info.toVBA = NULL; |
375 |
i++; |
290 |
changeInfos.push_back( info ); |
376 |
}while(i < nCount && sEventInfo == pTransProp->sEventInfo); |
291 |
eventTransInfo[ rtl::OUString::createFromAscii("changed") ] = changeInfos; |
377 |
eventTransInfo[sEventInfo] = infoList; |
292 |
// focusGained ooo event |
378 |
} |
293 |
std::list< TranslateInfo > focusGainedInfos; |
|
|
294 |
info.sVBAName = rtl::OUString::createFromAscii("_GotFocus"); |
295 |
info.toVBA = NULL; |
296 |
focusGainedInfos.push_back( info ); |
297 |
eventTransInfo[ rtl::OUString::createFromAscii("focusGained") ] = focusGainedInfos; |
298 |
// focusLost ooo event |
299 |
std::list< TranslateInfo > focusLostInfos; |
300 |
info.sVBAName = rtl::OUString::createFromAscii("_LostFocus"); |
301 |
info.toVBA = NULL; |
302 |
focusLostInfos.push_back( info ); |
303 |
eventTransInfo[ rtl::OUString::createFromAscii("focusGained") ] = focusLostInfos; |
304 |
// adjustmentValueChanged ooo event |
305 |
std::list< TranslateInfo > adjustInfos; |
306 |
info.sVBAName = rtl::OUString::createFromAscii("_Scroll"); |
307 |
info.toVBA = NULL; |
308 |
adjustInfos.push_back( info ); |
309 |
info.sVBAName = rtl::OUString::createFromAscii("_Change"); |
310 |
info.toVBA = NULL; |
311 |
adjustInfos.push_back( info ); |
312 |
eventTransInfo[ rtl::OUString::createFromAscii("adjustmentValueChanged") ] = adjustInfos; |
313 |
// textChanged ooo event |
314 |
std::list< TranslateInfo > txtChangedInfos; |
315 |
info.sVBAName = rtl::OUString::createFromAscii("_Change"); |
316 |
info.toVBA = NULL; |
317 |
txtChangedInfos.push_back( info ); |
318 |
eventTransInfo[ rtl::OUString::createFromAscii("textChanged") ] = txtChangedInfos; |
319 |
|
320 |
// keyReleased ooo event |
321 |
std::list< TranslateInfo > keyReleasedInfos; |
322 |
info.sVBAName = rtl::OUString::createFromAscii("_KeyUp"); |
323 |
info.toVBA = ooKeyPressedToVBAKeyUpDown; |
324 |
keyReleasedInfos.push_back( info ); |
325 |
eventTransInfo[ rtl::OUString::createFromAscii("keyReleased") ] = keyReleasedInfos; |
326 |
// mouseReleased ooo event |
327 |
std::list< TranslateInfo > mouseReleasedInfos; |
328 |
info.sVBAName = rtl::OUString::createFromAscii("_MouseUp"); |
329 |
info.toVBA = ooMouseEvtToVBAMouseEvt; |
330 |
mouseReleasedInfos.push_back( info ); |
331 |
eventTransInfo[ rtl::OUString::createFromAscii("mouseReleased") ] = mouseReleasedInfos; |
332 |
// mousePressed ooo event |
333 |
std::list< TranslateInfo > mousePressedInfos; |
334 |
info.sVBAName = rtl::OUString::createFromAscii("_MouseDown"); |
335 |
info.toVBA = ooMouseEvtToVBAMouseEvt; |
336 |
mousePressedInfos.push_back( info ); |
337 |
info.sVBAName = rtl::OUString::createFromAscii("_DblClick"); |
338 |
// emulate double click event |
339 |
info.toVBA = ooMouseEvtToVBADblClick; |
340 |
mousePressedInfos.push_back( info ); |
341 |
eventTransInfo[ rtl::OUString::createFromAscii("mousePressed") ] = mousePressedInfos; |
342 |
// mouseMoved ooo event |
343 |
std::list< TranslateInfo > mouseMovedInfos; |
344 |
info.sVBAName = rtl::OUString::createFromAscii("_MouseMove"); |
345 |
info.toVBA = ooMouseEvtToVBAMouseEvt; |
346 |
mouseMovedInfos.push_back( info ); |
347 |
eventTransInfo[ rtl::OUString::createFromAscii("mouseMoved") ] = mouseMovedInfos; |
348 |
// keyPressed ooo event |
349 |
std::list< TranslateInfo > keyPressedInfos; |
350 |
info.sVBAName = rtl::OUString::createFromAscii("_KeyDown"); |
351 |
info.toVBA = ooKeyPressedToVBAKeyUpDown; |
352 |
keyPressedInfos.push_back( info ); |
353 |
info.sVBAName = rtl::OUString::createFromAscii("_KeyPress"); |
354 |
info.toVBA = ooKeyPressedToVBAKeyPressed; |
355 |
keyPressedInfos.push_back( info ); |
356 |
eventTransInfo[ rtl::OUString::createFromAscii("keyPressed") ] = keyPressedInfos; |
357 |
initialised = true; |
379 |
initialised = true; |
358 |
} |
380 |
} |
359 |
return eventTransInfo; |
381 |
return eventTransInfo; |
360 |
} |
382 |
} |
|
|
383 |
//liuchen 2009-6-23 end |
361 |
|
384 |
|
362 |
// Helper class |
385 |
// Helper class |
363 |
|
386 |
|
Lines 752-758
EventListener::getPropertySetInfo( ) throw (RuntimeException)
Link Here
|
752 |
return xInfo; |
775 |
return xInfo; |
753 |
} |
776 |
} |
754 |
|
777 |
|
|
|
778 |
//liuchen 2009-6-23 |
779 |
//decide if the control should execute the event |
780 |
bool ApproveAll(const ScriptEvent&, void* ) |
781 |
{ |
782 |
return true; |
783 |
} |
784 |
|
785 |
//for the given control type in evt.Arguments[0], look for if it appears in the type list in pPara |
786 |
bool FindControl(const ScriptEvent& evt, void* pPara) |
787 |
{ |
788 |
lang::EventObject aEvent; |
789 |
evt.Arguments[ 0 ] >>= aEvent; |
790 |
uno::Reference< uno::XInterface > xInterface( aEvent.Source, uno::UNO_QUERY ); |
791 |
|
792 |
TypeList* pTypeListInfo = static_cast<TypeList*>(pPara); |
793 |
Type* pType = pTypeListInfo->pTypeList; |
794 |
int nLen = pTypeListInfo->nListLength; |
795 |
|
796 |
for (int i = 0; i < nLen; i++) |
797 |
{ |
798 |
if ( xInterface->queryInterface( *pType ).hasValue() ) |
799 |
{ |
800 |
return true; |
801 |
} |
802 |
pType++; |
803 |
} |
804 |
|
805 |
return false; |
806 |
} |
807 |
|
808 |
//if the the given control type in evt.Arguments[0] appears in the type list in pPara, then approve the execution |
809 |
bool ApproveType(const ScriptEvent& evt, void* pPara) |
810 |
{ |
811 |
return FindControl(evt, pPara); |
812 |
} |
813 |
|
814 |
//if the the given control type in evt.Arguments[0] appears in the type list in pPara, then deny the execution |
815 |
bool DenyType(const ScriptEvent& evt, void* pPara) |
816 |
{ |
817 |
return !FindControl(evt, pPara); |
818 |
} |
819 |
|
820 |
//when mouse is moving, either the mouse button is pressed or some key is pressed can trigger the OO mouseDragged event, |
821 |
//the former should be denyed, and the latter allowed, only by doing so can the VBA MouseMove event when the "Shift" key is |
822 |
//pressed can be correctly triggered |
823 |
bool DenyMouseDrag(const ScriptEvent& evt, void* ) |
824 |
{ |
825 |
awt::MouseEvent aEvent; |
826 |
evt.Arguments[ 0 ] >>= aEvent; |
827 |
if (aEvent.Buttons == 0 ) |
828 |
{ |
829 |
return true; |
830 |
} |
831 |
else |
832 |
{ |
833 |
return false; |
834 |
} |
835 |
} |
836 |
|
837 |
|
755 |
|
838 |
|
|
|
839 |
//liuchen 2009-6-23 |
756 |
// EventListener |
840 |
// EventListener |
757 |
|
841 |
|
758 |
void |
842 |
void |
Lines 815-820
EventListener::firing_Impl(const ScriptEvent& evt, Any* /*pRet*/ ) throw(Runtime
Link Here
|
815 |
SbMethod* pMeth = static_cast< SbMethod* >( pModule->Find( sTemp, SbxCLASS_METHOD ) ); |
899 |
SbMethod* pMeth = static_cast< SbMethod* >( pModule->Find( sTemp, SbxCLASS_METHOD ) ); |
816 |
if ( pMeth ) |
900 |
if ( pMeth ) |
817 |
{ |
901 |
{ |
|
|
902 |
//liuchen 2009-6-8 |
903 |
if (! txInfo->ApproveRule(evt, txInfo->pPara) ) |
904 |
{ |
905 |
continue; |
906 |
} |
907 |
//liuchen 2009-6-8 |
818 |
// !! translate arguments & emulate events where necessary |
908 |
// !! translate arguments & emulate events where necessary |
819 |
Sequence< Any > aArguments; |
909 |
Sequence< Any > aArguments; |
820 |
if ( (*txInfo).toVBA ) |
910 |
if ( (*txInfo).toVBA ) |