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:AddDirect").
// => 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to