List Info

Thread: Bug in C++ UNO binding of awt::KeyEvent ?




Bug in C++ UNO binding of awt::KeyEvent ?
user name
2006-10-19 12:25:28
Le 19 oct. 06, à 14:00, Stephan Bergmann a écrit :

> I very much doubt that this is directly a problem of
the UNO C++  
> language binding.  com.sun.star.awt.KeyEvent is a UNO
struct that has  
> members KeyChar and KeyCode.  Maybe you can post the
failing C++ code  
> here (if it is not too long) and somebody with awt
knowledge can spot  
> the real problem.
>

Hi Stephan,

The test code for this bug is simple, and is similar to the
Basic code  
snippet:

____________________________________________________________
____________

// Let 'm_serviceMgr' be the service manager
<XMultiServiceFactory>  
interface.
//
Reference<XModuleUIConfigurationManagerSupplier>
	xUICfgSupp(m_serviceMgr->createInstance(OUString:: 
createFromAscii("com.sun.star.ui.ModuleUIConfigurationM
anagerSupplier")) 
, UNO_QUERY_THROW);

Reference<XUIConfigurationManager> xUICfgMgr
	=  
xUICfgSupp->getUIConfigurationManager(OUString:: 
createFromAscii("com.sun.star.text.TextDocument"))
;

Reference<XAcceleratorConfiguration>  
shortcutMgr(xUICfgMgr->getShortCutManager(),
UNO_QUERY_THROW);

awt::KeyEvent keyEvent;

/ 
/-----------------------------------------------------------
------------ 
---------------------------------
// BUG (of binding ?) : Use KeyEvent.KeyChar, and not
KeyEvent.KeyCode  
!!
//
// Note:
// The same bug appears when retrieving a KeyEvent, such as
//
XAcceleratorConfiguration.getKeyEventsByCommand(".uno:A
ddDirect").
// => the returned KeyEvents have KeyChar filled by what
should be in  
KeyCode.
/ 
/-----------------------------------------------------------
------------ 
---------------------------------
//
keyEvent.KeyChar = awt::Key::F11;
keyEvent.Modifiers = awt::KeyModifier::MOD1; // Ctrl+F11

OUString commandURL =
OUString::createFromAscii(".uno:AddDirect"); //  
this command is just as a test

try {
	shortcutMgr->removeKeyEvent(keyEvent);
}
catch (NoSuchElementException &) {}

shortcutMgr->setKeyEvent(keyEvent, commandURL);
shortcutMgr->store();

____________________________________________________________
____________


I first suspected a struct alignment problem, but it doesn't
seem to be  
so.

I use OO 2.0.3.

Julien Galand

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

Bug in C++ UNO binding of awt::KeyEvent ?
user name
2006-10-20 08:54:18
Julien Galand wrote:

> // BUG (of binding ?) : Use KeyEvent.KeyChar, and not
KeyEvent.KeyCode  
> !!
> //
> // Note:
> // The same bug appears when retrieving a KeyEvent,
such as
> //
XAcceleratorConfiguration.getKeyEventsByCommand(".uno:A
ddDirect").
> // => the returned KeyEvents have KeyChar filled by
what should be in  
> KeyCode.

I think it didn't work because you already have added
something before
you used that call. And the remove/setKeyEvent calls have a
bug or at
least a special behavior (see below).

> //
> keyEvent.KeyChar = awt::Key::F11;
> keyEvent.Modifiers = awt::KeyModifier::MOD1; //
Ctrl+F11
> 
> OUString commandURL =
OUString::createFromAscii(".uno:AddDirect"); //  
> this command is just as a test
> 
> try {
> 	shortcutMgr->removeKeyEvent(keyEvent);
> }
> catch (NoSuchElementException &) {}
> 
> shortcutMgr->setKeyEvent(keyEvent, commandURL);
> shortcutMgr->store();

There is a bug(or an unspecified feature?) in the
accelerator
configuration: searching for a configuration by Event
ignores KeyChar
and KeyFunc, it only uses KeyCode. This can lead to the
strangest
effects. Especially your code will force the Accelerator
Configuration
to grab the first binding that has "MOD1" set and
no KeyCode assigned,
whatever that means.

I recommend to do the following:
Make sure that you have the default configuration and use
"getKeyEventsByCommand" to see what you get. It
should yield the same
result as in Basic.

If setKeyEvent still doesn't work with a correctly assigned
KeyCode we
must debug it. This could be accelerated if you could
deliver your C++
code as an installable and executable extension.

Best regards,
Mathias

-- 
Mathias Bauer - OpenOffice.org Application Framework Project
Lead
Please reply to the list only, nospamforMBAgmx.de is
a spam sink.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

Bug in C++ UNO binding of awt::KeyEvent ?
user name
2006-10-20 16:11:57
Le 20 oct. 06, à 10:54, Mathias Bauer a écrit :

> Julien Galand wrote:
>
>> // BUG (of binding ?) : Use KeyEvent.KeyChar, and
not KeyEvent.KeyCode
>> !!
>> //
>> // Note:
>> // The same bug appears when retrieving a KeyEvent,
such as
>> //
XAcceleratorConfiguration.getKeyEventsByCommand(".uno:A
ddDirect").
>> // => the returned KeyEvents have KeyChar filled
by what should be in
>> KeyCode.
>
>> //
>> keyEvent.KeyChar = awt::Key::F11;
>> keyEvent.Modifiers = awt::KeyModifier::MOD1; //
Ctrl+F11
>>
>> OUString commandURL =
OUString::createFromAscii(".uno:AddDirect"); //
>> this command is just as a test
>>
>> try {
>> 	shortcutMgr->removeKeyEvent(keyEvent);
>> }
>> catch (NoSuchElementException &) {}
>>
>> shortcutMgr->setKeyEvent(keyEvent, commandURL);
>> shortcutMgr->store();
>
> I recommend to do the following:
> Make sure that you have the default configuration and
use
> "getKeyEventsByCommand" to see what you get.
It should yield the same
> result as in Basic.
>

Hi Mathias,

I have followed your advice. Doing so enabled me to
investigate 
further, and I have concluded that there is definitely an
alignment 
weakness in the UNO C++ headers.

The point is that I compile my add-on with alignment 2. I
thought there 
would be no problem since all UNO structures are wrapped
with :
#pragma pack(8)
struct { ... }
#pragma pack()

But there is a subtlety. Nothing is better than an example,
the one I 
have coped with :

________________________________________________
#pragma pack(push, 8)

struct EventObject {
     Reference<XInterface> Source;
};

struct myEventObject {
     void *Source;
};

#pragma pack(pop)

==> sizeof(EventObject)==4 &&
sizeof(myEventObject)==4

#pragma pack(push, 8)

struct myInputEvent: public myEventObject {
     short Modifiers;
};

struct InputEvent: public EventObject {
     short Modifiers;
};

#pragma pack(pop)

________________________________________________

The size of myInputEvent is 8 (at least with Visual C++),
because the 
'myEventObject' type has requested to be aligned on 8-bytes
boundary, 
and therefore its 'Source' field must be aligned on 4-bytes
boundary.
The compiler adjusts the size of the structure so that an
array of 
myInputEvent makes the Source field fall on 4-bytes
boundaries.

But if the default alignment compiler option is set to 2,
the size of 
InputEvent is 6, even though EventObject and my EventObject
look 
equivalent at first sight.

Why ? Because the Reference<> template is itself a
structure, not a 
basic type, and NOT wrapped with  #pragma pack(8). So the
compiler 
doesn't bother to keep it aligned on 8-bytes or even 4-bytes
boundary.

Consequence :
The awt::KeyEvent structure doesn't match the one of UNO in
a C++ 
component compiled with such an option.

As a conclusion :
- Either compile a C++ UNO component with the alignment
compiler option 
set to 8 (or at least all SDK/UNO headers).
- Or the Reference<> template structure definition
should be wrapped 
with #pragma align(8).

But the latter option is a fix in the SDK. Should I report
this to 
someone ?
Or should I forward this mail to another dedicated list ?

Julien Galand

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

Bug in C++ UNO binding of awt::KeyEvent ?
user name
2006-10-20 17:50:24
Hi Julien,

Julien Galand wrote:

> As a conclusion :
> - Either compile a C++ UNO component with the alignment
compiler option 
> set to 8 (or at least all SDK/UNO headers).
> - Or the Reference<> template structure
definition should be wrapped 
> with #pragma align(8).
> 
> But the latter option is a fix in the SDK. Should I
report this to 
> someone ?
> Or should I forward this mail to another dedicated list
?

As Stephan Bergmann is our expert for stuff like this and he
already
replied to one of your last mails I assume that he also will
have
something to say about your findings.

Stephan currently is just drowned in mails after some days
of vacation. 

Best regards (and thanks for your efforts),
Mathias

-- 
Mathias Bauer - OpenOffice.org Application Framework Project
Lead
Please reply to the list only, nospamforMBAgmx.de is
a spam sink.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )