diff --git a/components/synedit/syncompletion.pas b/components/synedit/syncompletion.pas index 083833ea23..cdf094dc4f 100644 --- a/components/synedit/syncompletion.pas +++ b/components/synedit/syncompletion.pas @@ -349,8 +349,7 @@ type function GetEditor(i: integer): TCustomSynEdit; protected procedure OnFormPaint(Sender: TObject); - procedure Notification(AComponent: TComponent; Operation: TOperation); - override; + procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure SetShortCut(Value: TShortCut); public constructor Create(AOwner: TComponent); override; @@ -1673,7 +1672,7 @@ begin FEndOfTokenChr := '()[].'; fEditors := TList.Create; fEditstuffs := TList.Create; - fShortCut := Menus.ShortCut(Ord(' '), [ssCtrl]); + fShortCut := Key2ShortCut(Ord(' '), [ssCtrl]); end; procedure TSynCompletion.SetShortCut(Value: TShortCut); @@ -1859,7 +1858,7 @@ begin fEditstuffs := TList.Create; FEndOfTokenChr := '()[].'; fAutoCompleteList := TStringList.Create; - fShortCut := Menus.ShortCut(Ord(' '), [ssShift]); + fShortCut := Key2ShortCut(Ord(' '), [ssShift]); end; procedure TSynAutoComplete.SetShortCut(Value: TShortCut); diff --git a/components/synedit/syneditkeycmds.pp b/components/synedit/syneditkeycmds.pp index baa3cf7a17..9f813e35a1 100644 --- a/components/synedit/syneditkeycmds.pp +++ b/components/synedit/syneditkeycmds.pp @@ -725,7 +725,7 @@ end; function TSynEditKeyStroke.GetShortCut: TShortCut; begin - Result := Menus.ShortCut(Key, Shift); + Result := Key2ShortCut(Key, Shift); end; function TSynEditKeyStroke.GetCommand: TSynEditorCommand; @@ -819,7 +819,7 @@ end; function TSynEditKeyStroke.GetShortCut2: TShortCut; begin - Result := Menus.ShortCut(Key2, Shift2); + Result := Key2ShortCut(Key2, Shift2); end; {begin} //ac 2000-07-05 diff --git a/components/synedit/synmacrorecorder.pas b/components/synedit/synmacrorecorder.pas index acfe6f2d66..627b6aada0 100644 --- a/components/synedit/synmacrorecorder.pas +++ b/components/synedit/synmacrorecorder.pas @@ -363,8 +363,8 @@ begin fShortCuts[mcRecord] := QMenus.ShortCut( Ord('R'), [ssCtrl, ssShift] ); fShortCuts[mcPlayback] := QMenus.ShortCut( Ord('P'), [ssCtrl, ssShift] ); {$ELSE} - fShortCuts[mcRecord] := Menus.ShortCut( Ord('R'), [ssCtrl, ssShift] ); - fShortCuts[mcPlayback] := Menus.ShortCut( Ord('P'), [ssCtrl, ssShift] ); + fShortCuts[mcRecord] := Key2ShortCut( Ord('R'), [ssCtrl, ssShift] ); + fShortCuts[mcPlayback] := Key2ShortCut( Ord('P'), [ssCtrl, ssShift] ); {$ENDIF} end; diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 6463f6e922..cee0bf96db 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -2034,7 +2034,7 @@ begin OnKeyPress:=@OnSynCompletionKeyPress; OnUTF8KeyPress:=@OnSynCompletionUTF8KeyPress; OnPositionChanged:=@OnSynCompletionPositionChanged; - ShortCut:=Menus.ShortCut(VK_UNKNOWN,[]); + ShortCut:=Key2ShortCut(VK_UNKNOWN,[]); TheForm.ShowSizeDrag := True; TheForm.Width := Max(50, EnvironmentOptions.CompletionWindowWidth); TheForm.NbLinesInWindow := Max(3, EnvironmentOptions.CompletionWindowHeight); diff --git a/ideintf/idecommands.pas b/ideintf/idecommands.pas index f832984620..bfd03c4665 100644 --- a/ideintf/idecommands.pas +++ b/ideintf/idecommands.pas @@ -508,8 +508,6 @@ procedure ExecuteIDEShortCut(Sender: TObject; var Key: word; Shift: TShiftState; procedure ExecuteIDEShortCut(Sender: TObject; var Key: word; Shift: TShiftState); function ExecuteIDECommand(Sender: TObject; Command: word): boolean; -function IDEShortCutToMenuShortCut(MenuItem: TMenuItem; const IDEShortCut: TIDEShortCut): TShortCut; - var // will be set by the IDE IDECommandList: TIDECommands; @@ -598,23 +596,6 @@ begin Result:=false; end; -function IDEShortCutToMenuShortCut(MenuItem: TMenuItem; const IDEShortCut: TIDEShortCut): TShortCut; -begin - if IDEShortCut.Key2=VK_UNKNOWN then - Result:=ShortCut(IDEShortCut.Key1,IDEShortCut.Shift1) - else begin - // This shows combination shortcuts. Normally shortcut string is generated - // in widgetset code but it supports only one key (modified by Shift state). - {$IFDEF CombinationShortcuts} - if (IDEShortCut.Key1<>VK_UNKNOWN) and (IDEShortCut.Key2<>VK_UNKNOWN) then - MenuItem.Caption:=MenuItem.Caption+#9+ - KeyAndShiftStateToKeyString(IDEShortCut.Key1,IDEShortCut.Shift1)+', '+ - KeyAndShiftStateToKeyString(IDEShortCut.Key2,IDEShortCut.Shift2); - {$ENDIF} - Result:=ShortCut(VK_UNKNOWN,[]); - end; -end; - procedure CreateStandardIDECommandScopes; begin IDECommandScopes:=TIDECommandScopes.Create; diff --git a/ideintf/menuintf.pas b/ideintf/menuintf.pas index 5e009b532d..b08bacd78a 100644 --- a/ideintf/menuintf.pas +++ b/ideintf/menuintf.pas @@ -24,7 +24,7 @@ unit MenuIntf; interface uses - Classes, SysUtils, LCLProc, Menus, ImgList, Graphics, LazHelpIntf, + Classes, SysUtils, LCLType, LCLProc, Menus, ImgList, Graphics, LazHelpIntf, IDECommands, IDEImagesIntf; type @@ -1621,10 +1621,14 @@ procedure TIDEMenuCommand.CommandChanged(Sender: TObject); begin //DebugLn('TIDEMenuCommand.CommandChanged ',Name); if MenuItem<>nil then - if FCommand<>nil then - MenuItem.ShortCut:=IDEShortCutToMenuShortCut(MenuItem, FCommand.ShortcutA) - else + if FCommand<>nil then begin + MenuItem.ShortCut:=KeyToShortCut(FCommand.ShortcutA.Key1,FCommand.ShortcutA.Shift1); + MenuItem.ShortCutKey2:=KeyToShortCut(FCommand.ShortcutA.Key2,FCommand.ShortcutA.Shift2); + end + else begin MenuItem.ShortCut:=0; + MenuItem.ShortCutKey2:=0; + end; end; procedure TIDEMenuCommand.MenuItemClick(Sender: TObject); @@ -1726,10 +1730,14 @@ begin MenuItem.RadioItem:=RadioItem; MenuItem.RightJustify:=RightJustify; MenuItem.ShowAlwaysCheckable:=ShowAlwaysCheckable; - if Command<>nil then - MenuItem.ShortCut:=IDEShortCutToMenuShortCut(MenuItem, Command.ShortcutA) - else - MenuItem.ShortCut:=ShortCut(0,[]); + if FCommand<>nil then begin + MenuItem.ShortCut:=KeyToShortCut(FCommand.ShortcutA.Key1,FCommand.ShortcutA.Shift1); + MenuItem.ShortCutKey2:=KeyToShortCut(FCommand.ShortcutA.Key2,FCommand.ShortcutA.Shift2); + end + else begin + MenuItem.ShortCut:=0; + MenuItem.ShortCutKey2:=0; + end; MenuItem.GroupIndex:=GroupIndex; end; end; diff --git a/ideintf/propedits.pp b/ideintf/propedits.pp index 6cba6f5a11..a12e34306d 100644 --- a/ideintf/propedits.pp +++ b/ideintf/propedits.pp @@ -4651,7 +4651,7 @@ begin Dlg.AutoSize:=true; if Dlg.ShowModal=mrOk then begin - NewValue:=ShortCut(Box.Key,Box.ShiftState); + NewValue:=Key2ShortCut(Box.Key,Box.ShiftState); if OldValue<>NewValue then SetOrdValue(NewValue); end; diff --git a/lcl/include/buttons.inc b/lcl/include/buttons.inc index 615d6ba279..6b3a64acfb 100644 --- a/lcl/include/buttons.inc +++ b/lcl/include/buttons.inc @@ -282,8 +282,8 @@ begin if AccelIndex > -1 then begin OldShortCut := FShortCut; - FShortCut := ShortCut(Char2VK(ParseStr[AccelIndex]), [ssCtrl]); - TWSButtonClass(WidgetSetClass).SetShortCut(Self, OldShortCut, FShortCut); + FShortCut := Key2ShortCut(Char2VK(ParseStr[AccelIndex]), [ssCtrl]); + TWSButtonClass(WidgetSetClass).SetShortCut(Self, OldShortCut); end; end; inherited WSSetText(AText); diff --git a/lcl/include/customcheckbox.inc b/lcl/include/customcheckbox.inc index aad6ceb1aa..dd27c260d8 100644 --- a/lcl/include/customcheckbox.inc +++ b/lcl/include/customcheckbox.inc @@ -217,8 +217,8 @@ begin if AccelIndex > -1 then begin OldShortCut := FShortCut; - FShortCut := ShortCut(Char2VK(ParseStr[AccelIndex]), [ssCtrl]); - TWSCustomCheckBoxClass(WidgetSetClass).SetShortCut(Self, OldShortCut, FShortCut); + FShortCut := Key2ShortCut(Char2VK(ParseStr[AccelIndex]), [ssCtrl]); + TWSCustomCheckBoxClass(WidgetSetClass).SetShortCut(Self, OldShortCut); end; end; inherited WSSetText(AText); diff --git a/lcl/include/menu.inc b/lcl/include/menu.inc index e5790c2c17..42ffb8a204 100644 --- a/lcl/include/menu.inc +++ b/lcl/include/menu.inc @@ -262,7 +262,7 @@ var ShiftState: TShiftState; begin ShiftState := KeyDataToShiftState(Message.KeyData); - Shortcut := Menus.Shortcut(Message.CharCode, ShiftState); + Shortcut := Key2ShortCut(Message.CharCode, ShiftState); Item := FindItem(Shortcut, fkShortcut); Result := not (csDesigning in ComponentState) and (Item <> nil); //DebugLn(['TMenu.IsShortcut ',dbgsName(Self),' Result=',Result,' Message.CharCode=',Message.CharCode,' ShiftState=',dbgs(ShiftState)]); diff --git a/lcl/include/menuitem.inc b/lcl/include/menuitem.inc index 669e385fb6..f8f09ce412 100644 --- a/lcl/include/menuitem.inc +++ b/lcl/include/menuitem.inc @@ -135,7 +135,8 @@ begin if HandleAllocated then begin - if ShortCut <> 0 then ShortCutChanged(0, Shortcut); + if ShortCut <> 0 then + ShortCutChanged(0); end; end; //DebugLn('TMenuItem.CreateHandle END ',Name,':',ClassName); @@ -540,7 +541,7 @@ end; {------------------------------------------------------------------------------ function TMenuItem.IsShortCutStored: boolean; - Checks if 'ShotCut' needs to be saved to stream + Checks if 'ShortCut' needs to be saved to stream ------------------------------------------------------------------------------} function TMenuItem.IsShortCutStored: boolean; begin @@ -1310,14 +1311,27 @@ end; Params: Value: TShortCut Returns: Nothing - Set the shortcut + Set the ShortCut ------------------------------------------------------------------------------} procedure TMenuItem.SetShortCut(const AValue : TShortCut); +var + OldShortCut: TShortCut; Begin if FShortCut <> AValue then begin - ShortCutChanged(FShortCut, AValue); + OldShortCut:=FShortCut; FShortCut := AValue; + ShortCutChanged(OldShortCut); + end; +end; + +procedure TMenuItem.SetShortCutKey2(const AValue: TShortCut); +begin + if FShortCutKey2 <> AValue then + begin + FShortCutKey2 := AValue; + // ToDo: Remove the unused OldValue parameter if possible. It gets wrong value here. + ShortCutChanged(FShortCut); end; end; @@ -1407,15 +1421,15 @@ end; {------------------------------------------------------------------------------ Method: TMenuItem.ShortcutChanged - Params: OldValue: Old shortcut, Value: New shortcut + Params: OldValue: Old Key2ShortCut, Value: New Key2ShortCut Returns: Nothing - Installs a new shortcut, removes an old one. + Installs a new Key2ShortCut, removes an old one. ------------------------------------------------------------------------------} -procedure TMenuItem.ShortcutChanged(const OldValue, Value: TShortcut); +procedure TMenuItem.ShortcutChanged(const OldValue: TShortcut); begin if HandleAllocated then - TWSMenuItemClass(WidgetSetClass).SetShortCut(Self, OldValue, Value); + TWSMenuItemClass(WidgetSetClass).SetShortCut(Self, OldValue); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/carbon/carbonwsmenus.pp b/lcl/interfaces/carbon/carbonwsmenus.pp index b92714b24c..148ac0a799 100644 --- a/lcl/interfaces/carbon/carbonwsmenus.pp +++ b/lcl/interfaces/carbon/carbonwsmenus.pp @@ -54,7 +54,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; @@ -200,17 +200,16 @@ end; Method: TCarbonWSMenuItem.SetShortCut Params: AMenuItem - LCL menu item OldShortCut - Old shortcut - NewShortCut - New shortcut Sets the shortcut of menu item in Carbon interface ------------------------------------------------------------------------------} class procedure TCarbonWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin if not CheckMenuItem(AMenuItem, 'SetShortCut') then Exit; if not CheckMenuItem(AMenuItem.Parent, 'SetShortCut', 'Parent') then Exit; - TCarbonMenu(AMenuItem.Handle).SetShortCut(NewShortCut); + TCarbonMenu(AMenuItem.Handle).SetShortCut(AMenuItem.ShortCut); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/cocoa/cocoawsmenus.pas b/lcl/interfaces/cocoa/cocoawsmenus.pas index d4ec4b459e..d3dbac0bb6 100644 --- a/lcl/interfaces/cocoa/cocoawsmenus.pas +++ b/lcl/interfaces/cocoa/cocoawsmenus.pas @@ -52,7 +52,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; @@ -217,12 +217,11 @@ end; Method: TCocoaWSMenuItem.SetShortCut Params: AMenuItem - LCL menu item OldShortCut - Old shortcut - NewShortCut - New shortcut Sets the shortcut of menu item in Cocoa interface ------------------------------------------------------------------------------} class procedure TCocoaWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin end; diff --git a/lcl/interfaces/gtk/gtkproc.inc b/lcl/interfaces/gtk/gtkproc.inc index 4c284ee429..506e252215 100644 --- a/lcl/interfaces/gtk/gtkproc.inc +++ b/lcl/interfaces/gtk/gtkproc.inc @@ -6048,7 +6048,7 @@ end; procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget); begin - UpdateInnerMenuItem(LCLMenuItem, MenuItemWidget, LCLMenuItem.ShortCut); + UpdateInnerMenuItem(LCLMenuItem, MenuItemWidget, LCLMenuItem.ShortCut, LCLMenuItem.ShortCutKey2); end; {------------------------------------------------------------------------------ @@ -6057,8 +6057,8 @@ end; Update the inner widgets of a menuitem widget. ------------------------------------------------------------------------------} -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget; NewShortCut: TShortCut); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget; + NewShortCut, ShortCutKey2: TShortCut); {$ifdef GTK2} const WidgetDirection : array[boolean] of longint = (GTK_TEXT_DIR_LTR, GTK_TEXT_DIR_RTL); @@ -6088,32 +6088,25 @@ var var LabelWidget: PGtkLabel; NeedShortCut: Boolean; - Key: Word; - Shift: TShiftState; + Key, Key2: Word; + Shift, Shift2: TShiftState; s: String; begin //DebugLn(['UpdateShortCutLabel ',dbgsName(LCLMenuItem),' ',ShortCutToText(NewShortCut)]); ShortCutToKey(NewShortCut, Key, Shift); + ShortCutToKey(ShortCutKey2, Key2, Shift2); - // check if shortcut is needed - NeedShortCut := Key <> 0; + // Check if shortcut is needed. No shortcut captions for items in menubar + NeedShortCut := (Key <> 0) and + not ( (LCLMenuItem.Parent <> nil) and LCLMenuItem.Parent.HandleAllocated and + GtkWidgetIsA(PGtkWidget(LCLMenuItem.Parent.Handle), GTK_TYPE_MENU_BAR) ); - if NeedShortCut and - (LCLMenuItem.Parent <> nil) and - LCLMenuItem.Parent.HandleAllocated and - GtkWidgetIsA(PGtkWidget(LCLMenuItem.Parent.Handle), GTK_TYPE_MENU_BAR) then - begin - // no shortcut captions for items in menubar - NeedShortCut := False; - end; - - LabelWidget := PGtkLabel(gtk_object_get_data(PGtkObject(MenuItemWidget), - 'LCLShortCutLabel')); - + LabelWidget := PGtkLabel(gtk_object_get_data(PGtkObject(MenuItemWidget),'LCLShortCutLabel')); if NeedShortCut then begin - ShortCutToKey(NewShortCut, Key, Shift); s := GetAcceleratorString(Key, Shift); + if Key2 <> 0 then + s := s + ', ' + GetAcceleratorString(Key2, Shift2); // ShortCutToText(NewShortCut); if LabelWidget = nil then begin diff --git a/lcl/interfaces/gtk/gtkproc.pp b/lcl/interfaces/gtk/gtkproc.pp index df0b0431f1..4b23d8af36 100644 --- a/lcl/interfaces/gtk/gtkproc.pp +++ b/lcl/interfaces/gtk/gtkproc.pp @@ -662,10 +662,9 @@ function MENU_ITEM_CLASS(widget: PGtkWidget): PGtkMenuItemClass; function CHECK_MENU_ITEM_CLASS(widget: PGtkWidget): PGtkCheckMenuItemClass; procedure LockRadioGroupOnChange(RadioGroup: PGSList; const ADelta: Integer); procedure UpdateRadioGroupChecks(RadioGroup: PGSList); -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget); -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget; NewShortCut: TShortCut); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget; + NewShortCut, ShortCutKey2: TShortCut); // statusbar function CreateStatusBarPanel(StatusBar: TObject; Index: integer): PGtkWidget; diff --git a/lcl/interfaces/gtk/gtkwsmenus.pp b/lcl/interfaces/gtk/gtkwsmenus.pp index 305ade3266..90fc37c2bb 100644 --- a/lcl/interfaces/gtk/gtkwsmenus.pp +++ b/lcl/interfaces/gtk/gtkwsmenus.pp @@ -46,7 +46,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; @@ -232,13 +232,12 @@ begin AMenuItem.Enabled and (ACaption <> cLineCaption)); end; -class procedure TGtkWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); +class procedure TGtkWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); begin if not WSCheckMenuItem(AMenuItem, 'SetShortCut') then Exit; //DebugLn(['TGtkWSMenuItem.SetShortCut ',dbgsName(AMenuItem),' ',ShortCutToText(NewShortCut)]); - UpdateInnerMenuItem(AMenuItem, PGTKWidget(AMenuItem.Handle), NewShortCut); + UpdateInnerMenuItem(AMenuItem, PGTKWidget(AMenuItem.Handle)); end; class procedure TGtkWSMenuItem.SetVisible(const AMenuItem: TMenuItem; diff --git a/lcl/interfaces/gtk/gtkwsstdctrls.pp b/lcl/interfaces/gtk/gtkwsstdctrls.pp index 6c0201590d..dcbba27899 100644 --- a/lcl/interfaces/gtk/gtkwsstdctrls.pp +++ b/lcl/interfaces/gtk/gtkwsstdctrls.pp @@ -260,7 +260,7 @@ type class procedure SetColor(const AWinControl: TWinControl); override; class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; - class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override; + class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut: TShortcut); override; class procedure SetText(const AWinControl: TWinControl; const AText: String); override; {$endif Gtk1} end; @@ -273,12 +273,9 @@ type published {$IFDEF GTK1} class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; - class function RetrieveState(const ACustomCheckBox: TCustomCheckBox - ): TCheckBoxState; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; - class procedure SetState(const ACB: TCustomCheckBox; - const ANewState: TCheckBoxState); override; + class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; + class procedure SetState(const ACB: TCustomCheckBox; const ANewState: TCheckBoxState); override; class procedure GetPreferredSize(const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; @@ -1698,14 +1695,13 @@ begin end; end; -class procedure TGtkWSButton.SetShortcut(const AButton: TCustomButton; - const OldShortcut, NewShortcut: TShortcut); +class procedure TGtkWSButton.SetShortcut(const AButton: TCustomButton; const OldShortcut: TShortcut); begin if not WSCheckHandleAllocated(AButton, 'SetShortcut') then Exit; {$IFDEF Gtk1} - Accelerate(AButton, PGtkWidget(AButton.Handle), NewShortcut, 'clicked'); + Accelerate(AButton, PGtkWidget(AButton.Handle), AButton.ShortCut, 'clicked'); {$ENDIF} // gtk2: shortcuts are handled by the LCL end; @@ -1825,10 +1821,9 @@ begin end; class procedure TGtkWSCustomCheckBox.SetShortCut( - const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); begin - Accelerate(ACustomCheckBox, PGtkWidget(ACustomCheckBox.Handle), NewShortcut, + Accelerate(ACustomCheckBox, PGtkWidget(ACustomCheckBox.Handle), ACustomCheckBox.Shortcut, 'activate_item'); end; diff --git a/lcl/interfaces/gtk2/gtk2proc.inc b/lcl/interfaces/gtk2/gtk2proc.inc index 5e442d0915..2c56f96e6b 100644 --- a/lcl/interfaces/gtk2/gtk2proc.inc +++ b/lcl/interfaces/gtk2/gtk2proc.inc @@ -5714,7 +5714,7 @@ end; procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget); begin - UpdateInnerMenuItem(LCLMenuItem, MenuItemWidget, LCLMenuItem.ShortCut); + UpdateInnerMenuItem(LCLMenuItem, MenuItemWidget, LCLMenuItem.ShortCut, LCLMenuItem.ShortCutKey2); end; {------------------------------------------------------------------------------ @@ -5723,8 +5723,8 @@ end; Update the inner widgets of a menuitem widget. ------------------------------------------------------------------------------} -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget; NewShortCut: TShortCut); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget; + NewShortCut, ShortCutKey2: TShortCut); const WidgetDirection : array[boolean] of longint = (GTK_TEXT_DIR_LTR, GTK_TEXT_DIR_RTL); @@ -5751,32 +5751,25 @@ var var LabelWidget: PGtkLabel; NeedShortCut: Boolean; - Key: Word; - Shift: TShiftState; + Key, Key2: Word; + Shift, Shift2: TShiftState; s: String; begin //DebugLn(['UpdateShortCutLabel ',dbgsName(LCLMenuItem),' ',ShortCutToText(NewShortCut)]); ShortCutToKey(NewShortCut, Key, Shift); + ShortCutToKey(ShortCutKey2, Key2, Shift2); - // check if shortcut is needed - NeedShortCut := Key <> 0; + // Check if shortcut is needed. No shortcut captions for items in menubar + NeedShortCut := (Key <> 0) and + not ( (LCLMenuItem.Parent <> nil) and LCLMenuItem.Parent.HandleAllocated and + GtkWidgetIsA(PGtkWidget(LCLMenuItem.Parent.Handle), GTK_TYPE_MENU_BAR) ); - if NeedShortCut and - (LCLMenuItem.Parent <> nil) and - LCLMenuItem.Parent.HandleAllocated and - GtkWidgetIsA(PGtkWidget(LCLMenuItem.Parent.Handle), GTK_TYPE_MENU_BAR) then - begin - // no shortcut captions for items in menubar - NeedShortCut := False; - end; - - LabelWidget := PGtkLabel(gtk_object_get_data(PGtkObject(MenuItemWidget), - 'LCLShortCutLabel')); - + LabelWidget := PGtkLabel(gtk_object_get_data(PGtkObject(MenuItemWidget),'LCLShortCutLabel')); if NeedShortCut then begin - ShortCutToKey(NewShortCut, Key, Shift); s := GetAcceleratorString(Key, Shift); + if Key2 <> 0 then + s := s + ', ' + GetAcceleratorString(Key2, Shift2); // ShortCutToText(NewShortCut); if LabelWidget = nil then begin diff --git a/lcl/interfaces/gtk2/gtk2proc.pp b/lcl/interfaces/gtk2/gtk2proc.pp index 7af1ed6ee3..7592fc6069 100644 --- a/lcl/interfaces/gtk2/gtk2proc.pp +++ b/lcl/interfaces/gtk2/gtk2proc.pp @@ -635,10 +635,9 @@ function MENU_ITEM_CLASS(widget: PGtkWidget): PGtkMenuItemClass; function CHECK_MENU_ITEM_CLASS(widget: PGtkWidget): PGtkCheckMenuItemClass; procedure LockRadioGroupOnChange(RadioGroup: PGSList; const ADelta: Integer); procedure UpdateRadioGroupChecks(RadioGroup: PGSList); -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget); -procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; - MenuItemWidget: PGtkWidget; NewShortCut: TShortCut); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget); +procedure UpdateInnerMenuItem(LCLMenuItem: TMenuItem; MenuItemWidget: PGtkWidget; + NewShortCut, ShortCutKey2: TShortCut); // statusbar function CreateStatusBarPanel(StatusBar: TObject; Index: integer): PGtkWidget; diff --git a/lcl/interfaces/gtk2/gtk2wsmenus.pp b/lcl/interfaces/gtk2/gtk2wsmenus.pp index 6d8af7f73e..10ac599d3d 100644 --- a/lcl/interfaces/gtk2/gtk2wsmenus.pp +++ b/lcl/interfaces/gtk2/gtk2wsmenus.pp @@ -44,7 +44,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; @@ -375,7 +375,7 @@ begin end; class procedure TGtk2WSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); //var //MenuWidget: PGtkMenuItem; //accel_path: String; @@ -385,22 +385,15 @@ begin if not WSCheckMenuItem(AMenuItem, 'SetShortCut') then Exit; // Temporary: At least it writes the names of the shortcuts - UpdateInnerMenuItem(AMenuItem, PGTKWidget(AMenuItem.Handle), NewShortCut); + UpdateInnerMenuItem(AMenuItem, PGTKWidget(AMenuItem.Handle)); { // Gets the inner widgets. They should already be created by now - MenuWidget := PGtkMenuItem(AMenuItem.Handle); - if (MenuWidget=nil) then Exit; - // Converts the shortcut to a gtk friendly format and sets it - ShortCutToKey(NewShortCut, CurKey, CurShift); - accel_path := 'LCLApp/Menu/' + GetAcceleratorString(CurKey, CurShift); - gtk_accel_map_add_entry(accel_path, CurKey, ShiftToGdkModifierType); - gtk_menu_item_set_accel_path(); } end; diff --git a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp index 1fc7e61cde..ff9e44b431 100644 --- a/lcl/interfaces/gtk2/gtk2wsstdctrls.pp +++ b/lcl/interfaces/gtk2/gtk2wsstdctrls.pp @@ -303,7 +303,7 @@ type class procedure SetColor(const AWinControl: TWinControl); override; class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; - class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override; + class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut: TShortcut); override; class procedure SetText(const AWinControl: TWinControl; const AText: String); override; end; @@ -318,10 +318,8 @@ type class procedure GetPreferredSize(const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; - class function RetrieveState(const ACustomCheckBox: TCustomCheckBox - ): TCheckBoxState; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override; @@ -917,12 +915,11 @@ begin Result := cbUnchecked; end; -class procedure TGtk2WSCustomCheckBox.SetShortCut( - const ACustomCheckBox: TCustomCheckBox; const OldShortCut, - NewShortCut: TShortCut); +class procedure TGtk2WSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; + const OldShortCut: TShortCut); begin //DebugLn(['TGtk2WSCustomCheckBox.SetShortCut ',NewShortCut]); - Accelerate(ACustomCheckBox, PGtkWidget(ACustomCheckBox.Handle), NewShortcut, + Accelerate(ACustomCheckBox, PGtkWidget(ACustomCheckBox.Handle), ACustomCheckBox.Shortcut, 'clicked' //'activate_item' ); @@ -2307,7 +2304,7 @@ begin end; class procedure TGtk2WSButton.SetShortcut(const AButton: TCustomButton; - const OldShortcut, NewShortcut: TShortcut); + const OldShortcut: TShortcut); begin if not WSCheckHandleAllocated(AButton, 'SetShortcut') then Exit; diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 1961aa4eee..89a472b521 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -471,7 +471,7 @@ type function getText: WideString; override; procedure setIcon(AIcon: QIconH); procedure setIconSize(Size: PSize); - procedure setShortcut(AShortcut: TShortcut); + procedure setShortcut(AShortcut, AShortCutKey2: TShortcut); procedure setText(const W: WideString); override; procedure Toggle; function isChecked: Boolean; @@ -1361,7 +1361,7 @@ type procedure setIcon(AIcon: QIconH); procedure setImage(AImage: TQtImage); procedure setSeparator(AValue: Boolean); - procedure setShortcut(AShortcut: TShortcut); + procedure setShortcut(AShortcut, AShortCutKey2: TShortcut); procedure setText(const W: WideString); override; procedure setVisible(AVisible: Boolean); override; property trackButton: QtMouseButton read FTrackButton write FTrackButton; @@ -4497,21 +4497,26 @@ begin QAbstractButton_setIconSize(QAbstractButtonH(Widget), Size); end; -procedure TQtAbstractButton.setShortcut(AShortcut: TShortcut); +procedure TQtAbstractButton.setShortcut(AShortcut, AShortCutKey2: TShortcut); var Key: Word; Shift: TShiftState; - Modifiers: QtModifier; + QtK1, QtK2: integer; KeySequence: QKeySequenceH; begin + QtK1 := 0; + QtK2 := 0; if AShortCut <> 0 then begin ShortCutToKey(AShortCut, Key, Shift); - Modifiers := ShiftStateToQtModifiers(Shift); - KeySequence := QKeySequence_create(LCLKeyToQtKey(Key) or Modifiers); - end - else - KeySequence := QKeySequence_create(); + QtK1 := LCLKeyToQtKey(Key) or ShiftStateToQtModifiers(Shift); + if AShortCutKey2 <> 0 then + begin + ShortCutToKey(AShortCutKey2, Key, Shift); + QtK2 := LCLKeyToQtKey(Key) or ShiftStateToQtModifiers(Shift); + end; + end; + KeySequence := QKeySequence_create(QtK1, QtK2); QAbstractButton_setShortcut(QAbstractButtonH(Widget), KeySequence); QKeySequence_destroy(KeySequence); end; @@ -11046,22 +11051,27 @@ begin QAction_setSeparator(ActionHandle, AValue); end; -procedure TQtMenu.setShortcut(AShortcut: TShortcut); +procedure TQtMenu.setShortcut(AShortcut, AShortCutKey2: TShortcut); var Key: Word; - KeySequence: QKeySequenceH; Shift: TShiftState; - Modifiers: QtModifier; + QtK1, QtK2: integer; + KeySequence: QKeySequenceH; begin + QtK1 := 0; + QtK2 := 0; if AShortCut <> 0 then begin ShortCutToKey(AShortCut, Key, Shift); - Modifiers := ShiftStateToQtModifiers(Shift); - // there is no need in destroying QKeySequnce - KeySequence := QKeySequence_create(LCLKeyToQtKey(Key) or Modifiers); - end - else - KeySequence := QKeySequence_create(); + QtK1 := LCLKeyToQtKey(Key) or ShiftStateToQtModifiers(Shift); + if AShortCutKey2 <> 0 then + begin + ShortCutToKey(AShortCutKey2, Key, Shift); + QtK2 := LCLKeyToQtKey(Key) or ShiftStateToQtModifiers(Shift); + end; + end; + // there is no need in destroying QKeySequnce + KeySequence := QKeySequence_create(QtK1, QtK2); QAction_setShortcut(ActionHandle, KeySequence); QKeySequence_destroy(KeySequence); end; diff --git a/lcl/interfaces/qt/qtwsmenus.pp b/lcl/interfaces/qt/qtwsmenus.pp index 4cc53c28a5..ed2843281b 100644 --- a/lcl/interfaces/qt/qtwsmenus.pp +++ b/lcl/interfaces/qt/qtwsmenus.pp @@ -49,7 +49,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; override; class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; @@ -120,7 +120,7 @@ begin Result.BeginUpdate; Result.setChecked(AMenuItem.Checked); Result.EndUpdate; - Result.setShortcut(AMenuItem.ShortCut); + Result.setShortcut(AMenuItem.ShortCut, AMenuItem.ShortCutKey2); if AMenuItem.HasIcon then Result.setImage(TQtImage(AMenuItem.Bitmap.Handle)); end; @@ -253,7 +253,8 @@ end; Params: None Returns: Nothing ------------------------------------------------------------------------------} -class procedure TQtWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); +class procedure TQtWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; + const OldShortCut: TShortCut); var Widget: TQtWidget; begin @@ -266,7 +267,7 @@ begin Widget := TQtWidget(AMenuItem.Handle); if Widget is TQtMenu then - TQtMenu(Widget).setShortcut(NewShortCut); + TQtMenu(Widget).setShortcut(AMenuItem.ShortCut, AMenuItem.ShortCutKey2); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/qt/qtwsstdctrls.pp b/lcl/interfaces/qt/qtwsstdctrls.pp index 422ff708d0..d76bdfae4a 100644 --- a/lcl/interfaces/qt/qtwsstdctrls.pp +++ b/lcl/interfaces/qt/qtwsstdctrls.pp @@ -198,7 +198,7 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; - class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override; + class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut: TShortcut); override; end; { TQtWSCustomCheckBox } @@ -208,8 +208,7 @@ type class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; @@ -228,8 +227,7 @@ type class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; @@ -242,8 +240,7 @@ type class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; @@ -1044,11 +1041,11 @@ begin end; class procedure TQtWSButton.SetShortcut(const AButton: TCustomButton; - const OldShortcut, NewShortcut: TShortcut); + const OldShortcut: TShortcut); begin if not WSCheckHandleAllocated(AButton, 'SetShortcut') then Exit; - TQtPushButton(AButton.Handle).setShortcut(NewShortcut); + TQtPushButton(AButton.Handle).setShortcut(AButton.Shortcut, AButton.ShortCutKey2); end; { TQtWSCustomCheckBox } @@ -1074,11 +1071,12 @@ end; Returns: Nothing ------------------------------------------------------------------------------} class procedure TQtWSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin if not WSCheckHandleAllocated(ACustomCheckBox, 'SetShortcut') then Exit; - TQtCheckBox(ACustomCheckBox.Handle).setShortcut(NewShortcut); + TQtCheckBox(ACustomCheckBox.Handle).setShortcut(ACustomCheckBox.ShortCut, + ACustomCheckBox.ShortCutKey2); end; {------------------------------------------------------------------------------ @@ -1140,9 +1138,10 @@ end; Returns: Nothing ------------------------------------------------------------------------------} class procedure TQtWSRadioButton.SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin - TQtRadioButton(ACustomCheckBox.Handle).setShortcut(NewShortCut); + TQtRadioButton(ACustomCheckBox.Handle).setShortcut(ACustomCheckBox.ShortCut, + ACustomCheckBox.ShortCutKey2); end; {------------------------------------------------------------------------------ @@ -1504,11 +1503,12 @@ end; Returns: Nothing ------------------------------------------------------------------------------} class procedure TQtWSToggleBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin if not WSCheckHandleAllocated(ACustomCheckBox, 'SetShortCut') then Exit; - TQtToggleBox(ACustomCheckBox.Handle).setShortcut(NewShortCut); + TQtToggleBox(ACustomCheckBox.Handle).setShortcut(ACustomCheckBox.ShortCut, + ACustomCheckBox.ShortCutKey2); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/win32/win32wsmenus.pp b/lcl/interfaces/win32/win32wsmenus.pp index 03dbcfc0f1..2e1458ae13 100644 --- a/lcl/interfaces/win32/win32wsmenus.pp +++ b/lcl/interfaces/win32/win32wsmenus.pp @@ -52,7 +52,7 @@ type class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; class function SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean; override; class procedure UpdateMenuIcon(const AMenuItem: TMenuItem; const HasIcon: Boolean; const AIcon: Graphics.TBitmap); override; @@ -239,12 +239,20 @@ begin Result := CreateFontIndirect(@lf); end; +(* Get the menu item shortcut text *) +function MenuItemShortCut(const AMenuItem: TMenuItem): string; +begin + Result := ShortCutToText(AMenuItem.ShortCut); + if AMenuItem.ShortCutKey2 <> scNone then + Result := Result + ', ' + ShortCutToText(AMenuItem.ShortCutKey2); +end; + (* Get the menu item caption including shortcut *) function CompleteMenuItemCaption(const AMenuItem: TMenuItem; Spacing: String): string; begin Result := AMenuItem.Caption; if AMenuItem.ShortCut <> scNone then - Result := Result + Spacing + ShortCutToText(AMenuItem.ShortCut); + Result := Result + Spacing + MenuItemShortCut(AMenuItem); end; (* Get the maximum length of the given string in pixels *) @@ -364,6 +372,7 @@ var Theme: HTHEME; TextRect: TRect; W: WideString; + S: string; AFont, OldFont: HFONT; begin Theme := TWin32ThemeServices(ThemeServices).Theme[teMenu]; @@ -401,7 +410,7 @@ begin if AMenuItem.ShortCut <> scNone then begin; - W := UTF8ToUTF16(ShortCutToText(AMenuItem.ShortCut)); + W := UTF8ToUTF16(MenuItemShortCut(AMenuItem)); GetThemeTextExtent(Theme, DC, MENU_POPUPITEM, 0, PWideChar(W), Length(W), DT_SINGLELINE or DT_LEFT, nil, TextRect); Result.ShortCustSize.cx := TextRect.Right - TextRect.Left; @@ -762,8 +771,7 @@ begin TextRect.Left := TextRect.Right - Metrics.ShortCustSize.cx; TextFlags := TextFlags xor DT_LEFT or DT_RIGHT; end; - - ThemeDrawText(AHDC, Details, ShortCutToText(AMenuItem.ShortCut), TextRect, TextFlags, 0); + ThemeDrawText(AHDC, Details, MenuItemShortCut(AMenuItem), TextRect, TextFlags, 0); end; // exlude menu item rectangle to prevent drawing by windows after us if AMenuItem.Count > 0 then @@ -1008,7 +1016,7 @@ begin if AMenuItem.ShortCut <> scNone then begin - shortCutText := ShortCutToText(AMenuItem.ShortCut); + shortCutText := MenuItemShortCut(AMenuItem); if IsRightToLeft then begin Inc(ARect.Left, GetSystemMetrics(SM_CXMENUCHECK)); @@ -1369,15 +1377,13 @@ begin UpdateCaption(AMenuItem, aCaption); end; -class function TWin32WSMenuItem.SetCheck(const AMenuItem: TMenuItem; - const Checked: boolean): boolean; +class function TWin32WSMenuItem.SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; begin UpdateCaption(AMenuItem, aMenuItem.Caption); Result := Checked; end; -class procedure TWin32WSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); +class procedure TWin32WSMenuItem.SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); begin UpdateCaption(AMenuItem, aMenuItem.Caption); end; diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp index 9f62926ba5..2f4caf3ef7 100644 --- a/lcl/interfaces/win32/win32wsstdctrls.pp +++ b/lcl/interfaces/win32/win32wsstdctrls.pp @@ -248,7 +248,7 @@ type class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override; class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; - class procedure SetShortCut(const AButton: TCustomButton; const OldKey, NewKey: word); override; + class procedure SetShortCut(const AButton: TCustomButton; const OldKey: word); override; end; { TWin32WSCustomCheckBox } @@ -261,8 +261,7 @@ type var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetBiDiMode(const AWinControl: TWinControl; UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; @@ -1594,7 +1593,7 @@ begin Windows.SendMessage(AButton.Handle, BM_SETSTYLE, WindowStyle, 1); end; -class procedure TWin32WSButton.SetShortCut(const AButton: TCustomButton; const OldKey, NewKey: word); +class procedure TWin32WSButton.SetShortCut(const AButton: TCustomButton; const OldKey: word); begin if not WSCheckHandleAllocated(AButton, 'SetShortcut') then Exit; // TODO: implement me! @@ -1655,7 +1654,7 @@ begin end; class procedure TWin32WSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin // TODO: implement me! end; diff --git a/lcl/interfaces/wince/wincewsmenus.pp b/lcl/interfaces/wince/wincewsmenus.pp index 4859c2ba7f..ab7fe37c48 100644 --- a/lcl/interfaces/wince/wincewsmenus.pp +++ b/lcl/interfaces/wince/wincewsmenus.pp @@ -56,7 +56,7 @@ type class procedure DestroyHandle(const AMenuItem: TMenuItem); override; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); override; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; override; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); override; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override; class function SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean; override; class procedure UpdateMenuIcon(const AMenuItem: TMenuItem; const HasIcon: Boolean; const AIcon: Graphics.TBitmap); override; @@ -1008,8 +1008,7 @@ begin UpdateCaption(AMenuItem, ACaption); end; -class function TWinCEWSMenuItem.SetCheck(const AMenuItem: TMenuItem; - const Checked: boolean): boolean; +class function TWinCEWSMenuItem.SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; var uCheck: UINT; begin @@ -1020,8 +1019,7 @@ begin Result := Boolean(Windows.CheckMenuItem(AMenuItem.Parent.Handle, AMenuItem.Command, uCheck)); end; -class procedure TWinCEWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); +class procedure TWinCEWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); begin TWinCEWSMenuItem.SetCaption(AMenuItem, aMenuItem.Caption); end; diff --git a/lcl/interfaces/wince/wincewsstdctrls.pp b/lcl/interfaces/wince/wincewsstdctrls.pp index 18e416e8fe..cc7963b13f 100644 --- a/lcl/interfaces/wince/wincewsstdctrls.pp +++ b/lcl/interfaces/wince/wincewsstdctrls.pp @@ -239,7 +239,7 @@ type published class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override; // class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); override; -// class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override; +// class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut: TShortcut); override; class procedure GetPreferredSize(const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; @@ -255,8 +255,7 @@ type var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); override; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); override; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override; end; @@ -1315,7 +1314,7 @@ begin end; class procedure TWinCEWSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); + const OldShortCut: TShortCut); begin // TODO: implement me! end; diff --git a/lcl/menus.pp b/lcl/menus.pp index 873d3a6393..2480ae4e9f 100644 --- a/lcl/menus.pp +++ b/lcl/menus.pp @@ -134,6 +134,7 @@ type FMenuItemHandlers: array[TMenuItemHandlerType] of TMethodList; FSubMenuImages: TCustomImageList; FShortCut: TShortCut; + FShortCutKey2: TShortCut; FGroupIndex: Byte; FRadioItem: Boolean; FRightJustify: boolean; @@ -173,9 +174,8 @@ type procedure SetRightJustify(const AValue: boolean); procedure SetShowAlwaysCheckable(const AValue: boolean); procedure SetSubMenuImages(const AValue: TCustomImageList); - procedure ShortcutChanged(const OldValue, Value : TShortcut); - procedure SubItemChanged(Sender: TObject; Source: TMenuItem; - Rebuild: Boolean); + procedure ShortcutChanged(const OldValue: TShortcut); + procedure SubItemChanged(Sender: TObject; Source: TMenuItem; Rebuild: Boolean); procedure TurnSiblingsOff; procedure DoActionChange(Sender: TObject); protected @@ -192,8 +192,7 @@ type procedure CreateHandle; virtual; procedure DestroyHandle; virtual; procedure Loaded; override; - procedure Notification(AComponent: TComponent; - Operation: TOperation); override; + procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override; procedure InitiateActions; procedure MenuChanged(Rebuild : Boolean); @@ -203,6 +202,7 @@ type procedure SetImageIndex(AValue : TImageIndex); procedure SetParentComponent(AValue : TComponent); override; procedure SetShortCut(const AValue : TShortCut); + procedure SetShortCutKey2(const AValue : TShortCut); procedure SetVisible(AValue: Boolean); procedure UpdateImage; procedure UpdateImages; @@ -279,15 +279,14 @@ type property Hint: TTranslateString read FHint write FHint stored IsHintStored; property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1; - property RadioItem: Boolean read FRadioItem write SetRadioItem - default False; + property RadioItem: Boolean read FRadioItem write SetRadioItem default False; property RightJustify: boolean read FRightJustify write SetRightJustify default False; property ShortCut: TShortCut read FShortCut write SetShortCut stored IsShortCutStored default 0; + property ShortCutKey2: TShortCut read FShortCutKey2 write SetShortCutKey2 default 0; property ShowAlwaysCheckable: boolean read FShowAlwaysCheckable write SetShowAlwaysCheckable default False; - property SubMenuImages: TCustomImageList read FSubMenuImages - write SetSubMenuImages; + property SubMenuImages: TCustomImageList read FSubMenuImages write SetSubMenuImages; property Visible: Boolean read FVisible write SetVisible stored IsVisibleStored default True; property OnClick: TNotifyEvent read FOnClick write FOnClick @@ -417,7 +416,7 @@ type property OnClose: TNotifyEvent read FOnClose write FOnClose; end; -function ShortCut(const Key: Word; const Shift : TShiftState) : TShortCut; +function Key2ShortCut(const Key: Word; const Shift : TShiftState) : TShortCut; procedure ShortCutToKey(const ShortCut : TShortCut; var Key: Word; var Shift : TShiftState); @@ -559,7 +558,7 @@ end; {$I popupmenu.inc} {$I menuactionlink.inc} -function ShortCut(const Key: Word; const Shift : TShiftState) : TShortCut; +function Key2ShortCut(const Key: Word; const Shift : TShiftState) : TShortCut; begin Result := LCLType.KeyToShortCut(Key,Shift); end; diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 0349682eb9..e1fbb90b18 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -1080,6 +1080,7 @@ type private FModalResult: TModalResult; FShortCut: TShortcut; + FShortCutKey2: TShortcut; FCancel: Boolean; FDefault: Boolean; FActive: boolean; @@ -1117,6 +1118,8 @@ type property Active: boolean read FActive stored false; property Default: Boolean read FDefault write SetDefault default false; property ModalResult: TModalResult read FModalResult write SetModalResult default mrNone; + property ShortCut: TShortcut read FShortCut; + property ShortCutKey2: TShortcut read FShortCutKey2; property Cancel: Boolean read FCancel write SetCancel default false; property Color default {$ifdef UseCLDefault}clDefault{$else}clBtnFace{$endif}; property TabStop default true; @@ -1186,6 +1189,7 @@ type FAllowGrayed: Boolean; FState: TCheckBoxState; FShortCut: TShortcut; + FShortCutKey2: TShortcut; procedure SetState(Value: TCheckBoxState); function GetState: TCheckBoxState; procedure DoChange(var Msg); message LM_CHANGED; @@ -1211,6 +1215,8 @@ type public property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default false; property State: TCheckBoxState read GetState write SetState default cbUnchecked; + property ShortCut: TShortcut read FShortCut; + property ShortCutKey2: TShortcut read FShortCutKey2; property OnChange; end; diff --git a/lcl/widgetset/wsmenus.pp b/lcl/widgetset/wsmenus.pp index e7be74d115..c52d947483 100644 --- a/lcl/widgetset/wsmenus.pp +++ b/lcl/widgetset/wsmenus.pp @@ -58,7 +58,7 @@ type class function CreateHandle(const AMenuItem: TMenuItem): HMENU; virtual; class procedure DestroyHandle(const AMenuItem: TMenuItem); virtual; class procedure SetCaption(const AMenuItem: TMenuItem; const ACaption: string); virtual; - class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); virtual; + class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); virtual; class procedure SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); virtual; class function SetCheck(const AMenuItem: TMenuItem; const Checked: boolean): boolean; virtual; class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; virtual; @@ -123,13 +123,11 @@ class procedure TWSMenuItem.SetCaption(const AMenuItem: TMenuItem; const ACaptio begin end; -class procedure TWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; - const OldShortCut, NewShortCut: TShortCut); +class procedure TWSMenuItem.SetShortCut(const AMenuItem: TMenuItem; const OldShortCut: TShortCut); begin end; -class procedure TWSMenuItem.SetVisible(const AMenuItem: TMenuItem; - const Visible: boolean); +class procedure TWSMenuItem.SetVisible(const AMenuItem: TMenuItem; const Visible: boolean); begin end; @@ -143,8 +141,7 @@ begin Result := false; end; -class function TWSMenuItem.SetRadioItem(const AMenuItem: TMenuItem; - const RadioItem: boolean): boolean; +class function TWSMenuItem.SetRadioItem(const AMenuItem: TMenuItem; const RadioItem: boolean): boolean; begin Result := false; end; diff --git a/lcl/widgetset/wsstdctrls.pp b/lcl/widgetset/wsstdctrls.pp index b5a00c1782..5ac5c63130 100644 --- a/lcl/widgetset/wsstdctrls.pp +++ b/lcl/widgetset/wsstdctrls.pp @@ -217,7 +217,7 @@ type TWSButton = class(TWSButtonControl) published class procedure SetDefault(const AButton: TCustomButton; ADefault: Boolean); virtual; - class procedure SetShortCut(const AButton: TCustomButton; const OldShortCut, NewShortCut: TShortCut); virtual; + class procedure SetShortCut(const AButton: TCustomButton; const OldShortCut: TShortCut); virtual; end; TWSButtonClass = class of TWSButton; @@ -226,8 +226,7 @@ type TWSCustomCheckBox = class(TWSButtonControl) published class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; virtual; - class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; - const OldShortCut, NewShortCut: TShortCut); virtual; + class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); virtual; class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); virtual; end; TWSCustomCheckBoxClass = class of TWSCustomCheckBox; @@ -603,8 +602,8 @@ class procedure TWSButton.SetDefault(const AButton: TCustomButton; ADefault: Boo begin end; -class procedure TWSButton.SetShortCut(const AButton: TCustomButton; const OldShortCut, NewShortCut: TShortCut); -begin +class procedure TWSButton.SetShortCut(const AButton: TCustomButton; const OldShortCut: TShortCut); +begin; end; { TWSCustomCheckBox } @@ -614,7 +613,7 @@ begin Result := cbUnchecked; end; -class procedure TWSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut, NewShortCut: TShortCut); +class procedure TWSCustomCheckBox.SetShortCut(const ACustomCheckBox: TCustomCheckBox; const OldShortCut: TShortCut); begin end;