bartop

palmoswerks ARCHIVE
Palm OS programming tips from a (former) CodeWarrior insider

header

Navigation

Search
Home
About
Stories
Stuff I Like
Articles
PilRC
CodeWarrior
palmos.techwood.org
DevTools List
Palm OS Dev FAQ

 Permanent link to archive for 11/16/01.   Friday, November 16, 2001 daytail

Quick and Easy Edit Menus

Adding an "Edit" menu to your application is really easy, and it can be done just by adding a resource with no code needed. In the past, most Palm programming books have suggested making your own edit menu, and hooking all the commands up to the various Palm OS system calls, like FldCut and FldPaste. This isn't the best solution. Instead, you should take advantage of the edit menu already built into Palm OS.

To do this, you should define a new menu using Constructor (I'll talk about Rez and PilRC in a moment). In Constructor, you do this by going to the Menu group in your resource project, then choosing Edit/New Menu Resource. You should name this menu "Edit", and change its resource ID to "10000".

Now, open the new menu and add these items and keyboard shortcuts in this order: "Undo (U)", "Cut (X)", "Copy (C)", "Paste (P)", "Select All (S)", separator bar, "Keyboard (K)", and "Graffiti Help (G)".

You now have a menu that you can add to any of your menu bars. Since the menu items get IDs 10000-10007, they map automatically into edit commands that Palm OS will handle for you. If you arrange your menu in a different order, you'll have a mismatch between your label and the action. The separator bar is also needed, since it takes up an ID position which isn't used by Palm OS. You can see all of these special menu IDs in the UIResources.h header file; just search for "sysEditMenuUndoCmd".

There is another side effect to doing this. Palm OS on non-engligh devices recognizes this menu structure and can automatically add items that help with text entry. For example, on devices running Japanese versions of Palm OS, your menu will automatically have additional items to support text input and font size.

For Rez users, just define your menu like this:

resource 'MENU' (10000, "Edit") {
  10000, textMenuProc, 0x7FFFFFDF,
  enabled, "Edit",
  {
    "Undo", noIcon, "U", noMark, plain,
    "Cut", noIcon, "X", noMark, plain,
    "Copy", noIcon, "C", noMark, plain,
    "Paste", noIcon, "P", noMark, plain,
    "Select All", noIcon, "S", noMark, plain,
    "-", noIcon, noKey, noMark, plain,
    "Keyboard", noIcon, "K", noMark, plain,
    "Graffiti Help", noIcon, "G", noMark, plain
  }
};

For PilRC users, it is also pretty easy:

MENU ID 100
BEGIN
  PULLDOWN "Edit"
  BEGIN
    MENUITEM "Undo" ID 10000 "U"
    MENUITEM "Cut" ID 10001 "X"
    MENUITEM "Copy" ID 10002 "C"
    MENUITEM "Paste" ID 10003 "P"
    MENUITEM "Select All" ID 10004 "S"
    MENUITEM SEPARATOR
    MENUITEM "Keyboard" ID 10006 "K"
    MENUITEM "Graffiti Help" ID 10007 "G"
  END
END

Of course, you would need your other pulldown menus defined here too.

brought to you by weblogger.com

 
November 2001
Sun Mon Tue Wed Thu Fri Sat
  1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Oct   Jan


Send feedback to combee@techwood.org
Copyright © 2004 Benjamin L. Combee
Palm OS is a registered trademark of PalmSource, Inc.
Metrowerks and CodeWarrior are registered trademarks of Metrowerks Inc.

The views expressed on this website/weblog are those of mine alone and do not necessarily reflect the views of PalmSource or Metrowerks.

This is a Manila Site

qwertYAK / frobnovich