Fixes all wince menu bugs, except setting caption of subitems in atKeyPadDevice mode

git-svn-id: trunk@26798 -
This commit is contained in:
sekelsenmat 2010-07-24 09:57:58 +00:00
parent 62be1c21cc
commit 714834cb9c
3 changed files with 66 additions and 51 deletions

View File

@ -1104,7 +1104,7 @@ begin
if Hi(WParam) < 2 then //1 for accelerator 0 for menu
begin
TargetObject := GetMenuItemObject
TargetObject := GetMenuItemObject();
end
else // menuitem or shortcut
begin

View File

@ -1,19 +1,36 @@
//*****************************************************
// Resource file necessary for menu support
//*****************************************************
//
// The MENU resource data has the following format:
//
// TOOLBAR_ID MENU DISCARDABLE
// BEGIN
// MENUITEM Caption, MENU_ID
// END
//
// POPUP menus in this structure can't have a MENU_ID
//
// The RCDATA after that is the Toolbar information:
//
// TOOLBAR_ID, Number of menu items,
// Image, MENU_ID, Toolbar state, Toolbar Style, ?, 0, either NOMENU (popup) or 0 (menuitem)
//
// NOMENU = 0xFFFF
//
// 2 simple menu items
20000 MENU DISCARDABLE
BEGIN
MENUITEM " ", 1
MENUITEM " ", 2
MENUITEM " ", 1001
MENUITEM " ", 1002
END
20000 RCDATA DISCARDABLE
BEGIN
20000, 2,
-2, 1, 8, 0x10, 0, 0, 0xFFFF,
-2, 2, 8, 0x10, 0, 0, 0xFFFF
-2, 1001, 8, 0x10, 0, 0, 0xFFFF,
-2, 1002, 8, 0x10, 0, 0, 0xFFFF
END
// popup and simple menu item
@ -21,33 +38,33 @@ END
BEGIN
POPUP " "
BEGIN
MENUITEM " ", 1
MENUITEM " ", 1001
END
MENUITEM " ", 2
MENUITEM " ", 1002
END
20001 RCDATA DISCARDABLE
BEGIN
20001, 2,
-2, 1, 4, 0x18, 0, 0, 0,
-2, 2, 4, 0x10, 0, 0, 0xFFFF
-2, 1001, 4, 0x18, 0, 0, 0,
-2, 1002, 4, 0x10, 0, 0, 0xFFFF
END
// simple item and popup menu
20002 MENU DISCARDABLE
BEGIN
MENUITEM " ", 1
MENUITEM " ", 1001
POPUP " "
BEGIN
MENUITEM " ", 2
MENUITEM " ", 1002
END
END
20002 RCDATA DISCARDABLE
BEGIN
20002, 2,
-2, 1, 4, 0x10, 0, 0, 0xFFFF,
-2, 2, 4, 0x18, 0, 0, 1
-2, 1001, 4, 0x10, 0, 0, 0xFFFF,
-2, 1002, 4, 0x18, 0, 0, 1
END
// 2 popup menus
@ -55,31 +72,31 @@ END
BEGIN
POPUP "POPUP1"
BEGIN
MENUITEM "SUB1", 1
MENUITEM "SUB1", 1001
END
POPUP "POPUP2"
BEGIN
MENUITEM "SUB2", 2
MENUITEM "SUB2", 1002
END
END
20003 RCDATA DISCARDABLE
BEGIN
20003, 2,
-2, 1, 4, 0x18, 0, 0, 0,
-2, 2, 4, 0x18, 0, 0, 1
-2, 1001, 4, 0x18, 0, 0, 0,
-2, 1002, 4, 0x18, 0, 0, 1
END
// only 1 top-level item
20004 MENU DISCARDABLE
BEGIN
MENUITEM " ", 1
MENUITEM " ", 1001
END
20004 RCDATA DISCARDABLE
BEGIN
20004, 2,
-2, 1, 8, 0x10, 0, 0, 0xFFFF
20004, 1,
-2, 1001, 8, 0x10, 0, 0, 0xFFFF
END
// only 1 popup
@ -87,14 +104,14 @@ END
BEGIN
POPUP "POPUP1"
BEGIN
MENUITEM "SUB1", 1
MENUITEM "SUB1", 1001
END
END
20005 RCDATA DISCARDABLE
BEGIN
20005, 2,
-2, 1, 4, 0x18, 0, 0, 0
20005, 1,
-2, 1001, 4, 0x18, 0, 0, 0
END
// no menu
@ -104,7 +121,7 @@ END
20006 RCDATA DISCARDABLE
BEGIN
20006, 2
20006, 0
END
//*****************************************************

View File

@ -43,6 +43,7 @@ type
TWinCEWSMenuItem = class(TWSMenuItem)
public
class procedure UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
class procedure AttachMenuEx(const AMenuItem: TMenuItem; const AParentHandle: HMENU);
class procedure CopyMenuToHandle(const AMenuItem: TMenuItem; const ADest: HMENU);
published
@ -89,8 +90,8 @@ const
MenuBarID_1_Item = 20004;
MenuBarID_1_Popup = 20005;
MenuBarID_Empty = 20006;
MenuBarID_L = 1;
MenuBarID_R = 2;
MenuBarID_L = 1001;
MenuBarID_R = 1002;
StartMenuItem = 200;
var
MenuItemsList: TStringList;
@ -237,10 +238,10 @@ begin
// Clear any previously set menu items
while SendMessage(mbi.hwndMB, TB_DELETEBUTTON, 0, 0) <> 0 do
{$ifdef VerboseWinCEMenu}
DebugLn('[CeSetMenu] TB_DELETEBUTTON')
{$endif}
;
{$ifdef VerboseWinCEMenu}
DebugLn('[CeSetMenu] TB_DELETEBUTTON')
{$endif}
;
// Now we will add the buttons in the menu
//
@ -281,16 +282,10 @@ begin
tbbi.dwMask := TBIF_TEXT or TBIF_COMMAND or TBIF_STATE;
// Without setting idCommand the top-level items don't respond to clicks
case mbi.nToolBarId of
MenuBarID_Popups: tbbi.idCommand := MenuBarRLID;
MenuBarID_PopUp_Item: tbbi.idCommand := MenuBarRLID;
MenuBarID_Item_Popup: tbbi.idCommand := MenuBarRLID;
MenuBarID_Items: tbbi.idCommand := StartMenuItem + MenuBarRLID;
MenuBarID_1_Popup: tbbi.idCommand := MenuBarRLID;
MenuBarID_1_Item: tbbi.idCommand := StartMenuItem + MenuBarRLID;
end;
// Update the MenuItem Command to use latter
TMenuItemAccess(LCLMenu.Items.Items[j]).FCommand := MenuBarRLID;
tbbi.idCommand := MenuBarRLID;
// And we also need to update the MenuItem Command
TMenuItemAccess(LCLMenu.Items.Items[j]).FCommand := tbbi.idCommand - StartMenuItem;
{$ifdef VerboseWinCEMenu}
DebugLn('[CeSetMenu] atKeyPadDevice Set FCommand from ', LCLMenu.Items.Items[j].Name, ' to: ',
@ -298,15 +293,17 @@ begin
DebugLn('[CeSetMenu] atKeyPadDevice Message TB_SETBUTTONINFO with ButtonID: MenuBarRLID = ' + IntToStr(MenuBarRLID));
{$endif}
if SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi)) = 0 then
if SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, tbbi.idCommand, LPARAM(@tbbi)) = 0 then
DebugLn('[CeSetMenu] TB_SETBUTTONINFO failed');
MenuItemsList.AddObject(IntToStr(tbbi.idCommand), LCLMenu.Items.Items[j]);
// Adds subitems to a top-level item
{$ifdef VerboseWinCEMenu}
DebugLn('[CeSetMenu] atKeyPadDevice Message TB_GETBUTTONINFO with ButtonID: MenuBarRLID = ' + IntToStr(MenuBarRLID));
{$endif}
tbbi.dwMask := TBIF_LPARAM;
if SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi)) = - 1 then
if SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, tbbi.idCommand, LPARAM(@tbbi)) = - 1 then
DebugLn('[CeSetMenu] TB_GETBUTTONINFO failed');
// Remove any present buttons, for example the one from the .rc file
@ -320,12 +317,12 @@ begin
end;
end;
if i = 1 then
begin
tbbi.dwMask := TBIF_STATE;
tbbi.fsState:=0;
SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, 2, LPARAM(@tbbi));
end;
// if i = 1 then
// begin
// tbbi.dwMask := TBIF_STATE;
// tbbi.fsState:=0;
// SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, 2, LPARAM(@tbbi));
// end;
end;
end
else
@ -496,7 +493,7 @@ end;
{ TWinCEWSMenuItem }
procedure UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
class procedure TWinCEWSMenuItem.UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
var
MenuInfo: MENUITEMINFO;
wCaption: WideString;
@ -764,8 +761,9 @@ begin
if AMenu.Items.Items[j].Visible then Inc(i);
end;
if i = 0 then MenuBarRLID := StartMenuItem + MenuBarID_L
else MenuBarRLID := StartMenuItem + MenuBarID_R;
MenuBarRLID := StartMenuItem + AMenu.Items.Items[j].Command;
// if i = 0 then MenuBarRLID := StartMenuItem + MenuBarID_L
// else MenuBarRLID := StartMenuItem + MenuBarID_R;
{$ifdef VerboseWinCEMenu}
DebugLn('[TWinCEWSMenuItem.SetCaption] TB_SETBUTTONINFO with ButtonID: ' + IntToStr(MenuBarRLID));