Implements changing top-level menu caption under WinCE for atKeyPadDevice

git-svn-id: trunk@25813 -
This commit is contained in:
sekelsenmat 2010-06-01 07:48:53 +00:00
parent d8eb7e42ca
commit 987771a01f

View File

@ -256,8 +256,10 @@ begin
begin begin
if (Menu <> 0) and (LCLMenu <> nil) then if (Menu <> 0) and (LCLMenu <> nil) then
begin begin
i:=0; i:=0; // j = counts all top-level menu items;
// i = counts only visible ones;
for j:=0 to LCLMenu.Items.Count - 1 do for j:=0 to LCLMenu.Items.Count - 1 do
begin
if LCLMenu.Items.Items[j].Visible then if LCLMenu.Items.Items[j].Visible then
begin begin
if LCLMenu.Items.Items[j].Enabled then if LCLMenu.Items.Items[j].Enabled then
@ -267,47 +269,34 @@ begin
if LCLMenu.Items.Items[j].Checked then if LCLMenu.Items.Items[j].Checked then
tbbi.fsState:=tbbi.fsState or TBSTATE_CHECKED; tbbi.fsState:=tbbi.fsState or TBSTATE_CHECKED;
if (Application.ApplicationType = atKeyPadDevice) then // Adds a top-level item (We cant really add it, so we find
begin // and modify the existing top-level item)
// Adds a top-level item (We cant really add it, so we find if i = 2 then Break; // smartphones have maximum 2 top level menu items.
// and modify the existing top-level item)
if i = 2 then Break; // smartphones have maximum 2 top level menu items.
tbbi.cbSize := sizeof(tbbi);
tbbi.pszText := PWideChar(UTF8Decode(LCLMenu.Items.Items[j].Caption));
// tbbi.idCommand := FID;
tbbi.dwMask := TBIF_TEXT {or TBIF_COMMAND} or TBIF_STATE;
SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, i + 1, LPARAM(@tbbi));
// Adds subitems to a top-level item if i = 0 then MenuBarRLID := MenuBarID_L
tbbi.dwMask := TBIF_LPARAM; else MenuBarRLID := MenuBarID_R;
SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, i + 1 {FID}, LPARAM(@tbbi));
// Remove any present buttons, for example the one from the .rc file tbbi.cbSize := sizeof(tbbi);
// Careful that using TB_DELETEBUTTON doesnt work here tbbi.pszText := PWideChar(UTF8Decode(LCLMenu.Items.Items[j].Caption));
while RemoveMenu(HMENU(tbbi.lParam), 0, MF_BYPOSITION) do ; tbbi.dwMask := TBIF_TEXT {or TBIF_COMMAND} or TBIF_STATE;
SendMessage(mbi.hwndMB, TB_SETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi));
for k := 0 to LCLMenu.Items.Items[j].Count - 1 do // Adds subitems to a top-level item
TWinCEWSMenuItem.AttachMenuEx( tbbi.dwMask := TBIF_LPARAM;
LCLMenu.Items.Items[j].Items[k], HMENU(tbbi.lParam)); SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi));
end
else // Remove any present buttons, for example the one from the .rc file
begin // Careful that using TB_DELETEBUTTON doesnt work here
{ FillChar(tb, SizeOf(tb), 0); while RemoveMenu(HMENU(tbbi.lParam), 0, MF_BYPOSITION) do ;
tb.iBitmap:=I_IMAGENONE;
tb.idCommand:=fID; for k := 0 to LCLMenu.Items.Items[j].Count - 1 do
tb.iString:=longint(PKOLChar(Caption)); TWinCEWSMenuItem.AttachMenuEx(
tb.fsState:=st; LCLMenu.Items.Items[j].Items[k], HMENU(tbbi.lParam));
if SubMenu <> 0 then
tb.fsStyle:=TBSTYLE_DROPDOWN or $0080 or TBSTYLE_AUTOSIZE
else
tb.fsStyle:=TBSTYLE_BUTTON or TBSTYLE_AUTOSIZE;
tb.dwData:=SubMenu;
SendMessage(mbi.hwndMB, TB_INSERTBUTTON, i, LPARAM(@tb));}
end;
Inc(i); Inc(i);
end; end;
end;
if (Application.ApplicationType = atKeyPadDevice) and (i = 1) then if i = 1 then
begin begin
tbbi.dwMask := TBIF_STATE; tbbi.dwMask := TBIF_STATE;
tbbi.fsState:=0; tbbi.fsState:=0;
@ -318,17 +307,15 @@ begin
else else
begin begin
// Now we will add the buttons in the menu // Now we will add the buttons in the menu
// DbgAppendToFile(ExtractFilePath(ParamStr(0)) + '1.log', // DebugLn('Menu: ' + IntToStr(Menu) + ' LCLMenu: ' + IntToStr(PtrInt(LCLMenu)));
// 'Menu: ' + IntToStr(Menu) + ' LCLMenu: ' + IntToStr(PtrInt(LCLMenu)));
if (Menu <> 0) then if (Menu <> 0) then
begin begin
// DbgAppendToFile(ExtractFilePath(ParamStr(0)) + '1.log', 'if (Menu <> 0) and (LCLMenu <> nil) then'); // DebugLn('if (Menu <> 0) and (LCLMenu <> nil) then');
i:=0; i:=0;
while True do while True do
begin begin
mi.cch:=SizeOf(buf); mi.cch:=SizeOf(buf);
if not GetMenuItemInfo(Menu, i, True, @mi) then if not GetMenuItemInfo(Menu, i, True, @mi) then Break;
break;
buf[mi.cch]:=#0; buf[mi.cch]:=#0;
FillChar(tb, SizeOf(tb), 0); FillChar(tb, SizeOf(tb), 0);
tb.iBitmap:=I_IMAGENONE; tb.iBitmap:=I_IMAGENONE;
@ -347,7 +334,7 @@ begin
SendMessage(mbi.hwndMB, TB_INSERTBUTTON, i, LPARAM(@tb)); SendMessage(mbi.hwndMB, TB_INSERTBUTTON, i, LPARAM(@tb));
//MsgBox('i = ' + int2str(i),0); //MsgBox('i = ' + int2str(i),0);
if (Application.ApplicationType = atKeyPadDevice) and (i < 2) then{KeyPadDevices can have only 2 buttons!} { if (Application.ApplicationType = atKeyPadDevice) and (i < 2) then{KeyPadDevices can have only 2 buttons!}
begin begin
case i of case i of
0: MenuBarRLID := MenuBarID_L; 0: MenuBarRLID := MenuBarID_L;
@ -360,7 +347,7 @@ begin
tbbi.dwMask := TBIF_LPARAM; tbbi.dwMask := TBIF_LPARAM;
SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi)); SendMessage(mbi.hwndMB, TB_GETBUTTONINFO, MenuBarRLID, LPARAM(@tbbi));
CeMakeMenuesSame(mi.hSubMenu, HMENU(tbbi.lParam)); CeMakeMenuesSame(mi.hSubMenu, HMENU(tbbi.lParam));
end; end;}
Inc(i); Inc(i);
end; end;
@ -644,7 +631,7 @@ var
bi: TBBUTTONINFO; bi: TBBUTTONINFO;
w: WideString; w: WideString;
h: THandle; h: THandle;
i: Integer; i, j, MenuBarRLID: Integer;
FormFound: Boolean; FormFound: Boolean;
AMenu: TMenu; AMenu: TMenu;
{$endif} {$endif}
@ -654,6 +641,8 @@ begin
AMenu := AMenuItem.GetParentMenu; AMenu := AMenuItem.GetParentMenu;
// DebugLn(Format('[TWinCEWSMenuItem.SetCaption] A AItem.Menu:%d', // DebugLn(Format('[TWinCEWSMenuItem.SetCaption] A AItem.Menu:%d',
// [PtrInt(AMenu)])); // [PtrInt(AMenu)]));
// Top-Level menu items for PDA systems
if (Application.ApplicationType in [atPDA, atKeyPadDevice]) and if (Application.ApplicationType in [atPDA, atKeyPadDevice]) and
(AMenu <> nil) and (AMenu is TMainMenu) and (AMenu <> nil) and (AMenu is TMainMenu) and
(AMenuItem.Parent = AMenu.Items) then (AMenuItem.Parent = AMenu.Items) then
@ -679,7 +668,26 @@ begin
bi.dwMask := TBIF_TEXT; bi.dwMask := TBIF_TEXT;
w := UTF8Decode(ACaption); w := UTF8Decode(ACaption);
bi.pszText := PWideChar(w); bi.pszText := PWideChar(w);
SendMessageW(h, TB_SETBUTTONINFO, AMenuItem.Command + StartMenuItem, LPARAM(@bi));
// Under Windows the Command numbering is different
// Here we need to find the position of the button
// in the list of visible buttons and use MenuBarID_L or _R
if (Application.ApplicationType = atKeyPadDevice) then
begin
i := 0; // Counts only really visible menus
for j := 0 to AMenu.Items.Count - 1 do
begin
if AMenuItem = AMenu.Items.Items[j] then Break;
if AMenu.Items.Items[j].Visible then Inc(i);
end;
if i = 0 then MenuBarRLID := MenuBarID_L
else MenuBarRLID := MenuBarID_R;
SendMessageW(h, TB_SETBUTTONINFO, MenuBarRLID, LPARAM(@bi));
end
else
SendMessageW(h, TB_SETBUTTONINFO, AMenuItem.Command + StartMenuItem, LPARAM(@bi));
end end
else else
{$endif} {$endif}