From a29c6d9deca8bdaaee01c1ca0d154f8e8359bfdf Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sat, 13 Jul 2013 05:12:09 +0000 Subject: [PATCH] Applies patch from bug #17519 to fix regression in WinCE menus git-svn-id: trunk@42069 - --- lcl/include/menuitem.inc | 4 ++-- lcl/interfaces/wince/wincewsmenus.pp | 19 +++++++++++++++++-- lcl/menus.pp | 16 ---------------- lcl/widgetset/wsmenus.pp | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc index 97da4caffa..f1625e5409 100644 --- a/lcl/include/menuitem.inc +++ b/lcl/include/menuitem.inc @@ -111,7 +111,7 @@ begin FChecked := False; FVisible := True; FEnabled := True; - FCommand := UniqueCommand; + FCommand := TWSMenuItemClass(WidgetSetClass).OpenCommand; FImageIndex := -1; FBitmapIsValid := True; FRightJustify := False; @@ -210,7 +210,7 @@ begin FreeAndNil(FMenuItemHandlers[HandlerType]); if FParent <> nil then FParent.FItems.Remove(Self); - if FCommand <> 0 then CommandPool[FCommand] := False; + if FCommand <> 0 then TWSMenuItemClass(WidgetSetClass).CloseCommand(FCommand); //debugln('TMenuItem.Destroy B ',dbgsName(Self)); inherited Destroy; end; diff --git a/lcl/interfaces/wince/wincewsmenus.pp b/lcl/interfaces/wince/wincewsmenus.pp index e16465bc9b..c702042225 100644 --- a/lcl/interfaces/wince/wincewsmenus.pp +++ b/lcl/interfaces/wince/wincewsmenus.pp @@ -45,6 +45,8 @@ type var AForm: TForm): Boolean; {$endif} published + class function OpenCommand: LongInt; override; + class procedure CloseCommand(ACommand: LongInt); override; class procedure AttachMenu(const AMenuItem: TMenuItem); override; class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; @@ -80,7 +82,7 @@ type end; const - // IDs corresponding to the file winceres.rc + // IDs corresponding to the file wincemenures.rc MenuBarID_Items = 20000; MenuBarID_PopUp_Item = 20001; MenuBarID_Item_Popup = 20002; @@ -90,6 +92,7 @@ const MenuBarID_Empty = 20006; MenuBarID_L = 1001; MenuBarID_R = 1002; + MenuBarID_BASE = 1003; var MenuItemsList: TStringList; MenuHandleList, MenuLCLObjectList: TFPList; @@ -573,7 +576,6 @@ begin begin GetWindowRect(mbi.hwndMB, R); Windows.SystemParametersInfo(SPI_GETWORKAREA, 0, @WR, 0); - if WR.Bottom > R.Top then SetWindowPos(wnd, 0, 0, 0, WR.Right - WR.Left, R.Top - WR.Top, SWP_NOZORDER or SWP_NOREPOSITION or SWP_NOMOVE); end; @@ -887,6 +889,19 @@ begin Break; end; end; + +class function TWinCEWSMenuItem.OpenCommand: LongInt; +begin + Result := inherited OpenCommand; + Result := Result + MenuBarID_BASE; +end; + +class procedure TWinCEWSMenuItem.CloseCommand(ACommand: LongInt); +begin + ACommand := ACommand - MenuBarID_BASE; + inherited CloseCommand(ACommand); +end; + {$endif} class procedure TWinCEWSMenuItem.AttachMenu(const AMenuItem: TMenuItem); diff --git a/lcl/menus.pp b/lcl/menus.pp index 0c3e97665e..5eb11d8f1b 100644 --- a/lcl/menus.pp +++ b/lcl/menus.pp @@ -450,19 +450,6 @@ uses WSMenus, Forms {KeyDataToShiftState}; -{ Menu command management } - -var - CommandPool: TBits = nil; - -function UniqueCommand: LongInt; -begin - if CommandPool = nil then - CommandPool := TBits.Create(16); - Result := CommandPool.OpenBit; - CommandPool[Result] := True; -end; - { Easy Menu building } procedure AddMenuItems(AMenu: TMenu; const Items: array of TMenuItem); @@ -589,7 +576,4 @@ begin Result := FPosition < FMenuItem.Count; end; -finalization - FreeThenNil(CommandPool); - end. diff --git a/lcl/widgetset/wsmenus.pp b/lcl/widgetset/wsmenus.pp index d800236df2..5fb2d048ef 100644 --- a/lcl/widgetset/wsmenus.pp +++ b/lcl/widgetset/wsmenus.pp @@ -49,6 +49,8 @@ type TWSMenuItem = class(TWSLCLComponent) published + class function OpenCommand: LongInt; virtual; + class procedure CloseCommand(ACommand: LongInt); virtual; class procedure AttachMenu(const AMenuItem: TMenuItem); virtual; class function CreateHandle(const AMenuItem: TMenuItem): HMENU; virtual; class procedure DestroyHandle(const AMenuItem: TMenuItem); virtual; @@ -99,8 +101,31 @@ function WSCheckMenuItem(const AMenuItem: TMenuItem; implementation +{ Menu command management } + +var + CommandPool: TBits = nil; + +function UniqueCommand: LongInt; +begin + if CommandPool = nil then + CommandPool := TBits.Create(16); + Result := CommandPool.OpenBit; + CommandPool[Result] := True; +end; + { TWSMenuItem } +class function TWSMenuItem.OpenCommand: LongInt; +begin + Result := UniqueCommand; +end; + +class procedure TWSMenuItem.CloseCommand(ACommand: LongInt); +begin + CommandPool[ACommand] := False; +end; + class procedure TWSMenuItem.AttachMenu(const AMenuItem: TMenuItem); begin end; @@ -232,4 +257,6 @@ begin Done := True; end; +finalization + FreeThenNil(CommandPool); end.