Difference between revisions of "User:Ismael"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
Line 25: Line 25:
 
=== Short introduction: presenting the basis ===
 
=== Short introduction: presenting the basis ===
  
The function which interests us is <pre>void AquaSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& rKeyName ) <pre>
+
The function which interests us is <pre>void AquaSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& rKeyName ) </pre>
  
 
* nPos is the menu item index, but nPos is 0 to n based whereas the carbon API we use for ooo macport is from 1 to n+1 e.g. for the first element nPos=0, and his carbon index will be 1  
 
* nPos is the menu item index, but nPos is 0 to n based whereas the carbon API we use for ooo macport is from 1 to n+1 e.g. for the first element nPos=0, and his carbon index will be 1  
Line 39: Line 39:
 
We will use the ''SetMenuItemModifiers'' function to chose the modifier(s) of the key accelerator like cmd, shift, alt... and we'll set the key accelerator with two different function depending of the situation: the ''SetMenuItemCommandKey'' function for visible key accelerator (like for the N of Cmd+N) and the ''SetMenuItemKeyGlyph'' function for non visible characters (like for F1, F2,... or space).
 
We will use the ''SetMenuItemModifiers'' function to chose the modifier(s) of the key accelerator like cmd, shift, alt... and we'll set the key accelerator with two different function depending of the situation: the ''SetMenuItemCommandKey'' function for visible key accelerator (like for the N of Cmd+N) and the ''SetMenuItemKeyGlyph'' function for non visible characters (like for F1, F2,... or space).
  
==== Setting the key accelerator ====
+
=== Setting the key accelerator ===
 
The difficulty is that the OOo keycodes are different of the ASCII keycodes used in Carbon.
 
The difficulty is that the OOo keycodes are different of the ASCII keycodes used in Carbon.
 
For example: A is 65 in ASCII but in OOo it's 512 (defined in Key.hdl)
 
For example: A is 65 in ASCII but in OOo it's 512 (defined in Key.hdl)

Revision as of 18:04, 4 November 2006

Developper infos

Name: Ismael MERZAQ

IRC Nickname: Ismael


Current work

I'm working in implementing the key accelerators in the native menus (like Cmd+N for new document instead of ctrl+N in the X11 version).


Introduction

The purpose of this page is to present my work. As I have been contribuiting for few time, i have only worked on the key accelerators in the native menu.


Apple Documentation and References

Apple carbon reference about menus: [1]

Key accelerators

Short introduction: presenting the basis

The function which interests us is
void AquaSalMenu::SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const KeyCode& rKeyCode, const XubString& rKeyName ) 
  • nPos is the menu item index, but nPos is 0 to n based whereas the carbon API we use for ooo macport is from 1 to n+1 e.g. for the first element nPos=0, and his carbon index will be 1
  • SalMenuItem* pSalMenuItem is a pointer to the menu item we want to add key accelerator
  • const KeyCode& rKeyCode is the keycode of the accelerator. We can get the keycode with rKeyCode.GetCode() and the key modifier(s) (like cmd, shift, ... for Mac OS) with rKeyCode.GetAllModifier()
  • const XubString& rKeyName is not used for the MacOs port

Implementation

We will use the SetMenuItemModifiers function to chose the modifier(s) of the key accelerator like cmd, shift, alt... and we'll set the key accelerator with two different function depending of the situation: the SetMenuItemCommandKey function for visible key accelerator (like for the N of Cmd+N) and the SetMenuItemKeyGlyph function for non visible characters (like for F1, F2,... or space).

Setting the key accelerator

The difficulty is that the OOo keycodes are different of the ASCII keycodes used in Carbon. For example: A is 65 in ASCII but in OOo it's 512 (defined in Key.hdl) So we have to translate from ooo codes to ascii, but the order of the characters are not exactly the same as ASCII so we translate only by intervals. We obtain this code:

if ((ncode>=KEY_A) && (ncode<=KEY_Z)) {
    nresultcode=ncode-KEY_A+'A';
}
else if ((ncode>=KEY_0) && (ncode<=KEY_9)) {
    nresultcode=ncode-KEY_0+'0';
}

We do the same thing for non visible characters but instead of using the ascii code of the given character we use its carbon value.

else if((ncode>=KEY_F1) && (ncode<=KEY_F12)) {
    nresultcode=kMenuF1Glyph+ncode-KEY_F1; // kMenuFnGlyph=kMenuF1Glyph+n only for n<13 then it should be processed for each case
}
else if((ncode>=KEY_F13) && (ncode<=KEY_F15)) {
    nresultcode=kMenuF13Glyph+ncode-KEY_F13; //kMenuF13Glyph=0x87 and kMenuF12Glyph=0x7A
}
else if(ncode==KEY_SPACE) {
    nresultcode=kMenuSpaceGlyph; 
}

Then we only have to add the accelator to the menu:

  • For the non visible characters: The syntax of SetMenuItemKeyGlyph is:
OSErr SetMenuItemKeyGlyph (
   MenuRef inMenu,
   SInt16 inItem,
   SInt16 inGlyph
);

so we use it like this:

SetMenuItemKeyGlyph (
    mrMenuRef, //is the reference to the menu
    nPos+1, // for the reason of using nPos+1 instead of nPos see the short intro
    nresultcode
    );
  • For visible characters: The syntax of SetMenuItemCommandKey is:
OSStatus SetMenuItemCommandKey (
   MenuRef inMenu,
   MenuItemIndex inItem,
   Boolean inSetVirtualKey,
   UInt16 inKey
);

so we use it like this:

SetMenuItemCommandKey (
    mrMenuRef,
    nPos+1,
    0,
    nresultcode
    );


Problems and know bugs

Personal tools