unit custom_shortcut; //{$DEFINE _DEBUG} {$DEFINE MEGALO_BUG} interface uses Windows, Messages, SysUtils, Graphics, Controls, Forms, ComCtrls, ExtCtrls, StdCtrls, Grids, ActnList, Menus, Classes, Buttons, lang; const G_ciKEYNUMFIRST = 0; G_ciKEYNUMEND = 9; G_ciKEYCHARFIRST = 10; G_ciKEYCHAREND = 36; G_ciKEYFUNCFIRST = 37; G_ciKEYFUNCEND = 48; G_ciKEYEXTFIRST = 49; G_ciKEYEXTEND = 61; G_ciKEYEND = G_ciKEYEXTEND; G_ciSHORTCUTTEXT = 0; G_ciSHORTCUTDISP = 1; //ショートカットキー G_csSHORTCUTKEY: array[0..G_ciKEYEND, G_ciSHORTCUTTEXT..G_ciSHORTCUTDISP] of String = ( ('0', '0'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('Space', G_csCustomShortCut_DispKeySpace), ('A', 'A'), ('B', 'B'), ('C', 'C'), ('D', 'D'), ('E', 'E'), ('F', 'F'), ('G', 'G'), ('H', 'H'), ('I', 'I'), ('J', 'J'), ('K', 'K'), ('L', 'L'), ('M', 'M'), ('N', 'N'), ('O', 'O'), ('P', 'P'), ('Q', 'Q'), ('R', 'R'), ('S', 'S'), ('T', 'T'), ('U', 'U'), ('V', 'V'), ('W', 'W'), ('X', 'X'), ('Y', 'Y'), ('Z', 'Z'), ('F1', 'F1'), ('F2', 'F2'), ('F3', 'F3'), ('F4', 'F4'), ('F5', 'F5'), ('F6', 'F6'), ('F7', 'F7'), ('F8', 'F8'), ('F9', 'F9'), ('F10', 'F10'), ('F11', 'F11'), ('F12', 'F12'), ('Enter', G_csCustomShortCut_DispKeyEnter), ('BkSp', G_csCustomShortCut_DispKeyBkSp), ('Del', G_csCustomShortCut_DispKeyDel), ('Ins', G_csCustomShortCut_DispKeyIns), ('Esc', G_csCustomShortCut_DispKeyEsc), ('PgUp', G_csCustomShortCut_DispKeyPgUp), ('PgDn', G_csCustomShortCut_DispKeyPgDn), ('Home', G_csCustomShortCut_DispKeyHome), ('End', G_csCustomShortCut_DispKeyEnd), ('Up', G_csCustomShortCut_DispKeyUp), ('Down', G_csCustomShortCut_DispKeyDonw), ('Left', G_csCustomShortCut_DispKeyLeft), ('Right', G_csCustomShortCut_DispKeyRight) ); const //マウスジェスチャ G_ciGESTUREUP = 0; G_ciGESTUREDOWN = 1; G_ciGESTURELEFT = 2; G_ciGESTURERIGHT = 3; G_csGESTURESTRING: array[G_ciGESTUREUP..G_ciGESTURERIGHT]of String = ( G_csCustomShortCut_DispGestureUp, G_csCustomShortCut_DispGestureDonw, G_csCustomShortCut_DispGestureLeft, G_csCustomShortCut_DispGestureRight ); type { T_MouseGesture = record //マウスジェスチャ GestureUp: TAction; GestureDown: TAction; GestureLeft: TAction; GestureRight: TAction; end; } T_ShortCutAction = class(TObject) private F_iKey: Word; F_Action: TAction; public constructor Create(iKey: Word; AAction: TAction); property Key: Word read F_iKey; property Action: TAction read F_Action; end; type TForm_Custom_ShortCut = class(TForm) ActionList1: TActionList; actFile_Close: TAction; actCommand_KeyAdd: TAction; actCommand_KeyDelete: TAction; actCommand_KeyResetAll: TAction; actShortCutKey_ResetAll: TAction; actShortCutKey_Set: TAction; actShortCutKey_Delete: TAction; actGesture_Set: TAction; actGesture_Delete: TAction; actGesture_ResetAll: TAction; actMenu_Popup: TAction; mnuCustomShortCut: TPopupMenu; mniMenu_Reset: TMenuItem; mniMenu_Line2: TMenuItem; mniFile_Close: TMenuItem; mnuCommand: TPopupMenu; mniCommand_KeyNumAdd: TMenuItem; mniCommand_KeyCharAdd: TMenuItem; mniCommand_KeyFuncAdd: TMenuItem; mniCommand_KeyExtAdd: TMenuItem; mniCommand_KeyGestureAdd: TMenuItem; mniCommand_KeyLine1: TMenuItem; mniCommand_KeyAdd: TMenuItem; mniCommand_KeyDelete: TMenuItem; mniCommand_KeyLine2: TMenuItem; mniCommand_KeyReset: TMenuItem; mnuCommand_Category: TPopupMenu; mnuShortCutKey: TPopupMenu; mniShortCutKey_Line1: TMenuItem; mniShortCutKey_Set: TMenuItem; mniShortCutKey_Delete: TMenuItem; mniShortCutKey_Line2: TMenuItem; mniShortCutKey_ResetAll: TMenuItem; mnuGesture: TPopupMenu; mniGesture_Line1: TMenuItem; mniGesture_Set: TMenuItem; mniGesture_Delete: TMenuItem; mniGesture_Line2: TMenuItem; mniGesture_ResetAll: TMenuItem; pnlCustomShortCut: TPanel; Panel_Command: TPanel; Label_Command: TLabel; StringGrid_Command: TStringGrid; Button_Command_KeyAdd: TButton; Button_Command_KeyDelete: TButton; Button_Command_KeyReset: TButton; Splitter1: TSplitter; pnlShortCut: TPanel; PageControl_ShortCut: TPageControl; TabSheet_ShortCutKey: TTabSheet; StringGrid_ShortCutKey: TStringGrid; Button_ShortCutKey_Set: TButton; Button_ShortCutKey_Delete: TButton; Button_ShortCutKey_Reset: TButton; TabSheet_Gesture: TTabSheet; StringGrid_Gesture: TStringGrid; Button_Gesture_Set: TButton; Button_Gesture_Delete: TButton; Button_Gesture_Reset: TButton; Panel_Cmd: TPanel; Button_Close: TButton; GroupBox_Hint: TGroupBox; Label_Hint: TLabel; ComboBox_CommandCategory: TComboBox; procedure FormCreate (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); procedure FormDestroy(Sender: TObject); procedure FormResize (Sender: TObject); procedure FormKeyUp (Sender: TObject; var Key: Word; Shift: TShiftState); procedure actFile_CloseExecute(Sender: TObject); procedure actMenu_PopupExecute(Sender: TObject); procedure mnuShortCutKeyPopup (Sender: TObject); procedure mnuGesturePopup (Sender: TObject); procedure mnuCommandPopup (Sender: TObject); //ショートカット // procedure pagShortCutChange (Sender: TObject); procedure actCommand_KeyResetAllExecute(Sender: TObject); //ショートカットキー procedure actShortCutKey_SetExecute (Sender: TObject); procedure actShortCutKey_DeleteExecute (Sender: TObject); procedure actShortCutKey_ResetAllExecute (Sender: TObject); procedure StringGrid_ShortCutKeyDragDrop (Sender, Source: TObject; X, Y: Integer); procedure StringGrid_ShortCutKeyDragOver (Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure StringGrid_ShortCutKeyDrawCell (Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure StringGrid_ShortCutKeyMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid_ShortCutKeyMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid_ShortCutKeyKeyUp (Sender: TObject; var Key: Word; Shift: TShiftState); procedure actGesture_ResetAllExecute (Sender: TObject); procedure actGesture_SetExecute (Sender: TObject); procedure actGesture_DeleteExecute (Sender: TObject); procedure actMouseGesture_ResetExecute(Sender: TObject); procedure actCommand_KeyAddExecute (Sender: TObject); procedure actCommand_KeyDeleteExecute(Sender: TObject); procedure StringGrid_CommandDragDrop (Sender, Source: TObject; X, Y: Integer); procedure StringGrid_CommandDragOver (Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure StringGrid_CommandDrawCell (Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure StringGrid_CommandMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid_CommandMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid_CommandSelectCell (Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure StringGrid_ShortCutKeySelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure StringGrid_GestureSelectCell (Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure ComboBox_CommandCategorySelect(Sender: TObject); procedure ComboBox_CommandCategoryDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private 宣言 } // F_slUndoBuff: TList; //キーカスタマイズのアンドゥバッファ F_Drag: TObject; procedure FSetHighDPIControlHeight; // function F_GetCmdHint(AAction: TAction): String; function F_GetShortCut(iIndex: Integer): TShortCut; procedure F_DispCommandKey(AAction: TAction); procedure F_DispShortCutKey; function F_GetKeyAction(iRow: Integer): TAction; procedure F_SetKeyAction(iRow: Integer; AAction: TAction); procedure F_SetAction (iRow: Integer; AAction: TAction); overload; procedure F_SetAction (iRow, iActionIndex: Integer); overload; procedure F_DelAction (iRow: Integer); function F_GetGestureAction(iRow: Integer): TAction; procedure F_SetGestureAction(iRow: Integer; AAction: TAction); procedure F_DelGestureAction(iRow: Integer); procedure F_ChangeSetting; //Help更新のため procedure F_CommandPopup (iIndex: Integer); procedure F_ShortCutPopup (iIndex: Integer); procedure F_MouseGesturePopup(iIndex: Integer); procedure F_SetCommand (Sender: TObject); procedure F_CmdAddKey (Sender: TObject); procedure F_CmdAddGesture(Sender: TObject); procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; public { Public 宣言 } end; //------------------------------------------------------------------------------ procedure G_pcCreateShortCutForm; procedure G_pcClearShortCut; procedure G_pcSetInitShortCut (AActionList: TActionList); procedure G_pcSetInitMouseGesture(GestureUp, GestureDown, GestureLeft, GestureRight: TAction); //procedure gpcReadIniShortCut (AIniFile: TMyIniFile; AActionList: TActionList); //procedure gpcWriteIniShortCut(AIniFile: TMyIniFile); function gfniTextToShortCut(Text: String): TShortCut; function gfnsShortCutToText(ShortCut: TShortCut): String; var G_iKeyLength, G_iGestureLength, G_iShortCutLength: Integer; G_InitShortCutList, G_ShortCutList: TList; G_InitGestureUp, G_InitGestureDown, G_InitGestureLeft, G_InitGestureRight: TAction; G_GestureUp, G_GestureDown, G_GestureLeft, G_GestureRight: TAction; var Form_Custom_ShortCut: TForm_Custom_ShortCut; implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} general, {$IFDEF MEGALO_BUG} custom_base, custom_help, {$ENDIF} main, common, highDPIUnit; {$R *.dfm} //============================================================================== procedure G_pcCreateShortCutForm; procedure _CreateForm; begin Form_Custom_ShortCut := TForm_Custom_ShortCut.Create(G_MainForm); end; var i: Integer; begin if (Form_Custom_ShortCut = nil) then begin _CreateForm; end else begin for i := 0 to Screen.FormCount -1 do begin if (Screen.Forms[i] = Form_Custom_ShortCut) then begin Exit; end; end; _CreateForm; end; end; procedure G_pcClearShortCut; var i: Integer; begin //初期設定をクリア for i := G_ShortCutList.Count-1 downto 0 do begin T_ShortCutAction(G_ShortCutList.Items[i]).Free; G_ShortCutList.Delete(i); end; end; procedure G_pcSetInitShortCut(AActionList: TActionList); //ショートカットの初期値をセット var i, k: Integer; li_Old, li_Key: Word; l_Shift: TShiftState; l_Action: TAction; begin for i := 0 to AActionList.ActionCount-1 do begin l_Action := TAction(AActionList.Actions[i]); if (l_Action.SecondaryShortCuts.Count > 0) then begin li_Old := 0; for k := 0 to l_Action.SecondaryShortCuts.Count-1 do begin ShortCutToKey(l_Action.SecondaryShortCuts.ShortCuts[k], li_Key, l_Shift); if (li_Key <> li_Old) then begin G_InitShortCutList.Add(T_ShortCutAction.Create(li_Key, l_Action)); G_ShortCutList.Add (T_ShortCutAction.Create(li_Key, l_Action)); li_Old := li_Key; end; end; l_Action.SecondaryShortCuts.Clear; end; end; end; procedure G_pcSetInitMouseGesture(GestureUp, GestureDown, GestureLeft, GestureRight: TAction); //マウスジェスチャの初期値をセット begin G_InitGestureUp := GestureUp; G_InitGestureDown := GestureDown; G_InitGestureLeft := GestureLeft; G_InitGestureRight := GestureRight; G_GestureUp := G_InitGestureUp; G_GestureDown := G_InitGestureDown; G_GestureLeft := G_InitGestureLeft; G_GestureRight := G_InitGestureRight; end; (* const lcsSECT_SHORTCUT = 'ShortCut'; lcsSECT_MOUSEGESTURE = 'MouseGesture'; procedure gpcReadIniShortCut(AIniFile: TMyIniFile; AActionList: TActionList); function lfns_GetActionName(AAction: TAction): String; begin if (AAction = nil) then begin Result := ''; end else begin Result := AAction.Name; end; end; function lfn_FindAction(sName: String; AActionList: TActionList): TAction; var i: Integer; ls_Name: String; l_Action: TAction; begin ls_Name := UpperCase(sName); Result := nil; for i := 0 to AActionList.ActionCount-1 do begin l_Action := TAction(AActionList.Actions[i]); if (ls_Name = UpperCase(l_Action.Name)) then begin Result := l_Action; Exit; end; end; end; var lsl_List: TStrings; i: Integer; li_ShortCut, li_Gesture: Integer; l_Action: TAction; li_Key: Word; l_Shift: TShiftState; begin lsl_List := TStringList.Create; try //[ShortCut] if (AIniFile.SectionExists(lcsSECT_SHORTCUT)) then begin //初期設定をクリア for i := G_ShortCutList.Count-1 downto 0 do begin T_ShortCutAction(G_ShortCutList.Items[i]).Free; G_ShortCutList.Delete(i); end; AIniFile.ReadSection(lcsSECT_SHORTCUT, lsl_List); //アクションがセットされている仮想キーコードすべてが列挙されている //仮想キーコード=Action.Name for i := 0 to lsl_List.Count -1 do begin li_ShortCut := gfniStrToInt(lsl_List[i]); if (li_ShortCut > 0) and (li_ShortCut <= High(TShortCut)) then begin // l_Action := lfn_FindAction(AIniFile.ReadString(lcsSECT_SHORTCUT, lsl_List[i], 'actNop'), AActionList); l_Action := G_MainForm.Get_CommandToAction(AIniFile.ReadInteger(lcsSECT_SHORTCUT, lsl_List[i], 0)); if (l_Action <> nil) then begin ShortCutToKey(li_ShortCut, li_Key, l_Shift); G_ShortCutList.Add(T_ShortCutAction.Create(li_Key, l_Action)); end; end; end; end; //[MouseGesture] if (AIniFile.SectionExists(lcsSECT_MOUSEGESTURE)) then begin AIniFile.ReadSection(lcsSECT_MOUSEGESTURE, lsl_List); //仮のジェスチャーコード=Action.Name for i := 0 to lsl_List.Count-1 do begin li_Gesture := gfniStrToInt(lsl_List[i]); case li_Gesture of G_ciGESTUREUP: begin // G_GestureUp := lfn_FindAction(AIniFile.ReadString(lcsSECT_MOUSEGESTURE, lsl_List[i], lfns_GetActionName(G_GestureUp)), AActionList); G_GestureUp := G_MainForm.Get_CommandToAction(AIniFile.ReadInteger(lcsSECT_MOUSEGESTURE, lsl_List[i], G_MainForm.Get_ActionToCommand(G_GestureUp))); end; G_ciGESTUREDOWN: begin // G_GestureDown := lfn_FindAction(AIniFile.ReadString(lcsSECT_MOUSEGESTURE, lsl_List[i], lfns_GetActionName(G_GestureDown)), AActionList); G_GestureDown := G_MainForm.Get_CommandToAction(AIniFile.ReadInteger(lcsSECT_MOUSEGESTURE, lsl_List[i], G_MainForm.Get_ActionToCommand(G_GestureDown))); end; G_ciGESTURELEFT: begin // G_GestureLeft := lfn_FindAction(AIniFile.ReadString(lcsSECT_MOUSEGESTURE, lsl_List[i], lfns_GetActionName(G_GestureLeft)), AActionList); G_GestureLeft := G_MainForm.Get_CommandToAction(AIniFile.ReadInteger(lcsSECT_MOUSEGESTURE, lsl_List[i], G_MainForm.Get_ActionToCommand(G_GestureLeft))); end; G_ciGESTURERIGHT: begin // G_GestureRight := lfn_FindAction(AIniFile.ReadString(lcsSECT_MOUSEGESTURE, lsl_List[i], lfns_GetActionName(G_GestureRight)), AActionList); G_GestureRight := G_MainForm.Get_CommandToAction(AIniFile.ReadInteger(lcsSECT_MOUSEGESTURE, lsl_List[i], G_MainForm.Get_ActionToCommand(G_GestureRight))); end; else begin Continue; end; end; end; end; finally lsl_List.Free; end; end; procedure gpcWriteIniShortCut(AIniFile: TMyIniFile); { function lfns_GetActionName(AAction: TAction): String; begin if (AAction = nil) then begin Result := ''; end else begin Result := AAction.Name; end; end; } var i: Integer; begin //[ShortCut] AIniFile.EraseSection(lcsSECT_SHORTCUT); for i := 0 to G_ShortCutList.Count-1 do begin // AIniFile.WriteString(lcsSECT_SHORTCUT, IntToStr(T_ShortCutAction(G_ShortCutList.Items[i]).Key), T_ShortCutAction(G_ShortCutList.Items[i]).Action.Name); AIniFile.WriteInteger(lcsSECT_SHORTCUT, IntToStr(T_ShortCutAction(G_ShortCutList.Items[i]).Key), G_MainForm.Get_ActionToCommand(T_ShortCutAction(G_ShortCutList.Items[i]).Action)); end; AIniFile.WriteSection(lcsSECT_SHORTCUT); //[MouseGesture] //デフォルトと同じでも必ず書き出す { AIniFile.EraseSection(lcsSECT_MOUSEGESTURE); AIniFile.WriteString(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTUREUP), lfns_GetActionName(G_GestureUp)); AIniFile.WriteString(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTUREDOWN), lfns_GetActionName(G_GestureDown)); AIniFile.WriteString(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTURELEFT), lfns_GetActionName(G_GestureLeft)); AIniFile.WriteString(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTURERIGHT), lfns_GetActionName(G_GestureRight)); } AIniFile.WriteInteger(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTUREUP), G_MainForm.Get_ActionToCommand(G_GestureUp)); AIniFile.WriteInteger(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTUREDOWN), G_MainForm.Get_ActionToCommand(G_GestureDown)); AIniFile.WriteInteger(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTURELEFT), G_MainForm.Get_ActionToCommand(G_GestureLeft)); AIniFile.WriteInteger(lcsSECT_MOUSEGESTURE, IntToStr(G_ciGESTURERIGHT), G_MainForm.Get_ActionToCommand(G_GestureRight)); end; *) constructor T_ShortCutAction.Create(iKey: Word; AAction: TAction); begin inherited Create; F_iKey := iKey; F_Action := AAction; end; const lciCOL_KEYDISP = 0; //キー lciCOL_KEYCMDHINT = 1; //ヒント const lciCOL_CMDCATEGORY = 0; lciCOL_CMDHINT = 1; lciCOL_CMDKEY = 2; //------------------------------------------------------------------------------ function gfniTextToShortCut(Text: string): TShortCut; //表示用のテキストからショートカット値を返す。 var i: Integer; begin for i := 0 to High(G_csSHORTCUTKEY) do begin if (Text = G_csSHORTCUTKEY[i, G_ciSHORTCUTDISP]) then begin Result := Menus.TextToShortCut(G_csSHORTCUTKEY[i, G_ciSHORTCUTTEXT]); Exit; end; end; Result := 0; end; function gfnsShortCutToText(ShortCut: TShortCut): string; var i: Integer; begin Result := Menus.ShortCutToText(ShortCut); for i := 0 to High(G_csSHORTCUTKEY) do begin if (Result = G_csSHORTCUTKEY[i, G_ciSHORTCUTTEXT]) then begin Result := G_csSHORTCUTKEY[i, G_ciSHORTCUTDISP]; Exit; end; end; end; //------------------------------------------------------------------------------ procedure TForm_Custom_ShortCut.WMSysCommand(var Msg: TWMSysCommand); begin case Msg.CmdType of 61587: begin //システムアイコンクリック actMenu_PopupExecute(nil); end; else begin inherited; end; end; end; procedure TForm_Custom_ShortCut.FSetHighDPIControlHeight; begin //コマンドリスト gpcLabelHeightSet(Label_Command); gpcItemHeightSet(ComboBox_CommandCategory); ComboBox_CommandCategory.Items.Add(''); //ダミー ComboBox_CommandCategory.Items.Delete(ComboBox_CommandCategory.Items.Count -1); //ComboBoxはItemHeightに値をセットした後にアイテムを追加しないと表示されるまで高さが変わらない。 //アイテム追加後にItemHeightをセットしたのではうまくいかない。 G_ControlWidthSet(ComboBox_CommandCategory); G_ControlLeftSet(ComboBox_CommandCategory); G_ControlTopSet([Label_Command, ComboBox_CommandCategory]); //ComboBox_CommandCategory.Top := Label_Command.BoundsRect.Bottom; gpcDefaultRowHeightSet(StringGrid_Command); G_ControlWidthSet(StringGrid_Command); G_ControlTopSet([ComboBox_CommandCategory, StringGrid_Command]); G_ControlLeftSet(StringGrid_Command); Button_Command_KeyAdd.Top := Panel_Command.ClientHeight - Button_Command_KeyAdd.Height - G_ciCONTROL_MARGIN; Button_Command_KeyDelete.Top := Button_Command_KeyAdd.Top; Button_Command_KeyReset.Top := Button_Command_KeyAdd.Top; G_ControlLeftSet(Button_Command_KeyAdd, [Button_Command_KeyDelete]); G_CloseButtonLeftSet(Button_Command_KeyReset); //ボタンのTopをセットした後にすること StringGrid_Command.Height := Button_Command_KeyAdd.Top - G_ciCONTROL_MARGIN - StringGrid_Command.Top; //ショートカットキー gpcDefaultRowHeightSet(StringGrid_ShortCutKey); Button_ShortCutKey_Set.Top := Button_ShortCutKey_Set.Parent.ClientHeight - Button_ShortCutKey_Set.Height - G_ciCONTROL_MARGIN; Button_ShortCutKey_Delete.Top := Button_ShortCutKey_Set.Top; Button_ShortCutKey_Reset.Top := Button_ShortCutKey_Set.Top; G_ControlLeftSet(Button_ShortCutKey_Set, [Button_ShortCutKey_Delete]); G_CloseButtonLeftSet(Button_ShortCutKey_Reset); StringGrid_ShortCutKey.Height := Button_ShortCutKey_Set.Top - G_ciCONTROL_MARGIN - StringGrid_ShortCutKey.Top; //マウスジェスチャ gpcDefaultRowHeightSet(StringGrid_Gesture); Button_Gesture_Set.Top := Button_Gesture_Set.Parent.ClientHeight - Button_Gesture_Set.Height - G_ciCONTROL_MARGIN; Button_Gesture_Delete.Top := Button_Gesture_Set.Top; Button_Gesture_Reset.Top := Button_Gesture_Set.Top; G_ControlLeftSet(Button_Gesture_Set, [Button_Gesture_Delete]); G_CloseButtonLeftSet(Button_Gesture_Reset); StringGrid_Gesture.Height := Button_Gesture_Set.Top - G_ciCONTROL_MARGIN - StringGrid_Gesture.Top; //ヒントボックスの高さ調整 G_HintBoxHeightSet(GroupBox_Hint); //下部のコマンドボタンの調整 gpcButtonHeightSet(Button_Close); G_PanelCmdHieghtSet(Panel_Cmd); G_ControlTopSet(Button_Close); G_CloseButtonLeftSet(Button_Close); end; procedure TForm_Custom_ShortCut.FormCreate(Sender: TObject); procedure _AddKeyMenu(AMenuItem: TMenuItem; iIndex: Integer); var l_MenuItem: TMenuItem; begin AMenuItem.Add( NewItem( // Format('[%s] を追加', [G_csSHORTCUTKEY[iIndex, G_ciSHORTCUTDISP]]), //Caption Format('[%s]', [G_csSHORTCUTKEY[iIndex, G_ciSHORTCUTDISP]]), //Caption 0, //ShortCut False, //Checked True, //Enabled F_CmdAddKey, //OnClickイベント 0, //HelpContext Format('%s_%d', [AMenuItem.Name, AMenuItem.Count]) //Name ) ); l_MenuItem := AMenuItem.Items[AMenuItem.Count-1]; l_MenuItem.Tag := iIndex; end; procedure _AddGestureMenu(AMenuItem: TMenuItem; iIndex: Integer); var l_MenuItem: TMenuItem; begin AMenuItem.Add( NewItem( // Format('[%s] を追加', [G_csGESTURESTRING[iIndex]]), //Caption Format('[%s]', [G_csGESTURESTRING[iIndex]]), //Caption 0, //ShortCut False, //Checked True, //Enabled F_CmdAddGesture, //OnClickイベント 0, //HelpContext Format('%s_%d', [AMenuItem.Name, AMenuItem.Count]) //Name ) ); l_MenuItem := AMenuItem.Items[AMenuItem.Count-1]; l_MenuItem.Tag := iIndex; end; var i, li_Count, li_Index, li_HeaderCount, li_Width: Integer; lh_Menu: HMENU; l_Action: TAction; ls_Category, ls_Name: String; l_ShortCutMenuItem, l_GestureMenuItem{, l_MenuItem}: TMenuItem; begin {$IFDEF MEGALO_BUG} G_pcCreateCustomBaseForm; Self.ManualDock(G_CustomForm.tabShortCut); Self.Align := alClient; Self.Visible := True; {$ELSE} Self.BorderStyle := bsSizeable; Self.BorderIcons := [biSystemMenu]; {$ENDIF} Self.Icon := Application.Icon; Label_Hint.Caption := ''; //システムメニュー lh_Menu := GetSystemMenu(Handle, False); DeleteMenu(lh_Menu, SC_RESTORE, MF_BYCOMMAND); //元のサイズに戻す DeleteMenu(lh_Menu, SC_MINIMIZE, MF_BYCOMMAND); //最小化 DeleteMenu(lh_Menu, SC_MAXIMIZE, MF_BYCOMMAND); //最大化 DrawMenuBar(lh_Menu); pnlCustomShortCut.Align := alClient; //ショートカット // F_slUndoBuff := TList.Create; PageControl_ShortCut.ActivePageIndex := 0; //キーリストの初期設定 with StringGrid_ShortCutKey do begin RowCount := Length(G_csSHORTCUTKEY) + StringGrid_ShortCutKey.FixedRows; //ヘッダーの分をプラス Cells[lciCOL_KEYDISP, 0] := G_csCustomShortCut_KeyListTitleKey; Cells[lciCOL_KEYCMDHINT, 0] := G_csCustomShortCut_KeyListTitleCommand; li_Count := gfniMax([G_iKeyLength, Length(StringGrid_ShortCutKey.Cells[lciCOL_KEYDISP, 0])]); ColWidths[lciCOL_KEYDISP] := (gfniCanvasTextWidthGet(StringGrid_ShortCutKey.Font, 'A') * li_Count) + (G_ciTEXT_MARGIN * 2); //左右のマージンでlciMARGIN * 2 for i := 0 to High(G_csSHORTCUTKEY) do begin li_Index := i + StringGrid_ShortCutKey.FixedRows; //ヘッダーの分をプラス StringGrid_ShortCutKey.Cells[lciCOL_KEYDISP, li_Index] := G_csSHORTCUTKEY[i, G_ciSHORTCUTDISP]; F_SetAction(li_Index, nil); if (i >= G_ciKEYNUMFIRST) and (i <= G_ciKEYNUMEND) then begin _AddKeyMenu(mniCommand_KeyNumAdd, i); end else if (i >= G_ciKEYCHARFIRST) and (i <= G_ciKEYCHAREND) then begin _AddKeyMenu(mniCommand_KeyCharAdd, i); end else if (i >= G_ciKEYFUNCFIRST) and (i <= G_ciKEYFUNCEND) then begin _AddKeyMenu(mniCommand_KeyFuncAdd, i); end else if (i >= G_ciKEYEXTFIRST) and (i <= G_ciKEYEXTEND) then begin _AddKeyMenu(mniCommand_KeyExtAdd, i); end; end; end; //マウスジェスチャ for i := 0 to High(G_csGESTURESTRING) do begin _AddGestureMenu(mniCommand_KeyGestureAdd, i); end; with StringGrid_Gesture do begin Cells[lciCOL_KEYDISP, 0] := G_csCustomShortCut_GestureListTitleGesture; Cells[lciCOL_KEYCMDHINT, 0] := G_csCustomShortCut_GestureListTitleCommand; li_Count := gfniMax([G_iGestureLength, Length(Cells[lciCOL_KEYDISP, 0])]); ColWidths[lciCOL_KEYDISP] := (gfniCanvasTextWidthGet(StringGrid_Gesture.Font, 'A') * li_Count) + (G_ciTEXT_MARGIN * 2); //左右のマージンでlciMARGIN * 2 for i := 0 to High(G_csGESTURESTRING) do begin Cells[lciCOL_KEYDISP, i + FixedRows] := G_csGESTURESTRING[i]; case i of G_ciGESTUREUP: l_Action := G_GestureUp; G_ciGESTUREDOWN: l_Action := G_GestureDown; G_ciGESTURELEFT: l_Action := G_GestureLeft; G_ciGESTURERIGHT: l_Action := G_GestureRight; else l_Action := nil; end; Cells[lciCOL_CMDHINT, i + FixedRows] := G_fnsCommandDescriptionGet(l_Action); end; end; //コマンドリスト初期設定 StringGrid_Command.RowCount := G_ActionList.ActionCount + (StringGrid_Command.FixedRows); //ヘッダー分をプラス StringGrid_Command.Cells[lciCOL_CMDCATEGORY, 0] := G_csCustomShortCut_CommandListTitleCategory; StringGrid_Command.Cells[lciCOL_CMDHINT, 0] := G_csCustomShortCut_CommandListTitleCommand; StringGrid_Command.Cells[lciCOL_CMDKEY, 0] := G_csCustomShortCut_CommandListTitleKey; li_HeaderCount := StringGrid_Command.FixedRows; //ヘッダー分を足す for i := 0 to G_ActionList.ActionCount-1 do begin l_Action := TAction(G_ActionList.Actions[i]); if (StringGrid_Command.Cells[lciCOL_CMDHINT, i + li_HeaderCount] = '') then begin StringGrid_Command.Cells[lciCOL_CMDCATEGORY, i + li_HeaderCount] := l_Action.Category; StringGrid_Command.Cells[lciCOL_CMDHINT, i + li_HeaderCount] := Trim(StripHotKey(l_Action.Caption)); end; end; //高DPI対応 FSetHighDPIControlHeight; //カテゴリメニュー構築 li_Width := 0; ls_Category := ''; li_Count := 0; l_ShortCutMenuItem := nil; l_GestureMenuItem := nil; for i := 0 to G_ActionList.ActionCount-1 do begin l_Action := TAction(G_ActionList.Actions[i]); if (l_Action.Category <> ls_Category) then begin ls_Category := l_Action.Category; //メニューに追加 //固定ピッチフォントではないので逐一幅を計算する li_Width := gfniMax([li_Width, gfniCanvasTextWidthGet(StringGrid_Command.Font, ls_Category)]); ls_Name := gfnsAvailableName('mniPShortCut_Category'); mnuCommand_Category.Items.Add( NewItem( // Format('%s へ移動', [ls_Category]), //Caption ls_Category, //Caption 0, //ShortCut False, //Checked True, //Enabled // F_CmdGoToCategory, //OnClickイベント ComboBox_CommandCategorySelect, //OnClickイベント 0, //HelpContext ls_Name //Name )); ComboBox_CommandCategory.Items.Add(ls_Category); ls_Name := gfnsAvailableName('mniShortCutKey'); mnuShortCutKey.Items.Insert(li_Count, NewItem( Format(G_csCustomShortCut_SetCommandFormat, [ls_Category]), //Caption 0, //ShortCut False, //Checked True, //Enabled nil, //OnClickイベント 0, //HelpContext ls_Name //Name )); l_ShortCutMenuItem := mnuShortCutKey.Items[li_Count]; ls_Name := gfnsAvailableName('mniGesture'); mnuGesture.Items.Insert(li_Count, NewItem( Format(G_csCustomShortCut_SetCommandFormat, [ls_Category]), //Caption 0, //ShortCut False, //Checked True, //Enabled nil, //OnClickイベント 0, //HelpContext ls_Name //Name )); l_GestureMenuItem := mnuGesture.Items[li_Count]; Inc(li_Count); end; ComboBox_CommandCategory.ItemIndex := 0; if (l_ShortCutMenuItem <> nil) then begin ls_Name := gfnsAvailableName(Format('%s___mniShortCut', [l_Action.Name])); l_ShortCutMenuItem.Add( NewItem( StripHotKey(l_Action.Caption), 0, //ShortCut False, //Checked True, //Enabled F_SetCommand, //OnClickイベント 0, //HelpContext ls_Name //Name )); end; if (l_GestureMenuItem <> nil) then begin ls_Name := gfnsAvailableName(Format('%s___mniGesture', [l_Action.Name])); l_GestureMenuItem.Add( NewItem( StripHotKey(l_Action.Caption), 0, //ShortCut False, //Checked True, //Enabled F_SetCommand, //OnClickイベント 0, //HelpContext ls_Name //Name )); end; end; StringGrid_Command.ColWidths[lciCOL_CMDCATEGORY] := li_Width + (G_ciTEXT_MARGIN * 2); Tag := 1; //ショートカット表示 F_DispShortCutKey; mnuShortCutKeyPopup(nil); mnuGesturePopup(nil); mnuCommandPopup(nil); FormResize(nil); end; procedure TForm_Custom_ShortCut.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; //破棄 procedure TForm_Custom_ShortCut.FormDestroy(Sender: TObject); begin // F_slUndoBuff.Free; end; procedure TForm_Custom_ShortCut.FormResize(Sender: TObject); begin with StringGrid_Command do begin ColWidths[lciCOL_CMDHINT] := ClientWidth - ColWidths[lciCOL_CMDCATEGORY] - ColWidths[lciCOL_CMDKEY] - (GridLineWidth * (ColCount +1)); end; with StringGrid_ShortCutKey do begin ColWidths[lciCOL_KEYCMDHINT] := ClientWidth - ColWidths[lciCOL_KEYDISP] - (GridLineWidth * (ColCount +1)); end; with StringGrid_Gesture do begin ColWidths[lciCOL_KEYCMDHINT] := ClientWidth - ColWidths[lciCOL_KEYDISP] - (GridLineWidth * (ColCount)); end; end; //閉じる procedure TForm_Custom_ShortCut.actFile_CloseExecute(Sender: TObject); begin {$IFDEF MEGALO_BUG} G_CustomForm.actFile_CloseExecute(nil); {$ELSE} Close; {$ENDIF} end; //------------------------------------------------------------------------------ procedure TForm_Custom_ShortCut.F_SetCommand(Sender: TObject); var ls_Name: String; l_MenuItem: TMenuItem; l_Action: TAction; i: Integer; begin if not(Sender is TMenuItem) then begin Exit; end; l_MenuItem := TMenuItem(Sender); ls_Name := Copy(l_MenuItem.Name, 1, Pos('___', l_MenuItem.Name) -1); l_Action := nil; for i := 0 to G_ActionList.ActionCount-1 do begin if (G_ActionList.Actions[i].Name = ls_Name) then begin l_Action := TAction(G_ActionList.Actions[i]); Break; end; end; if (l_Action <> nil) then begin if (PageControl_ShortCut.ActivePage = TabSheet_ShortCutKey) then begin F_SetKeyAction(StringGrid_ShortCutKey.Row, l_Action); end else if (PageControl_ShortCut.ActivePage = TabSheet_Gesture) then begin F_SetGestureAction(StringGrid_Gesture.Row, l_Action); end; end; end; procedure TForm_Custom_ShortCut.F_CmdAddKey(Sender: TObject); //コマンドにキーを追加 var l_MenuItem: TMenuItem; li_Ret, li_KeyRow, li_CmdIndex: Integer; l_NowAction, l_Action: TAction; begin l_MenuItem := TMenuItem(Sender); li_KeyRow := l_MenuItem.Tag + StringGrid_ShortCutKey.FixedRows; l_NowAction := F_GetKeyAction(li_KeyRow); li_CmdIndex := StringGrid_Command.Row - (StringGrid_Command.FixedRows); //ヘッダー分を引く。 l_Action := TAction(G_ActionList.Actions[li_CmdIndex]); if (l_NowAction = l_Action) then begin Exit end; li_Ret := ID_YES; if (l_NowAction <> nil) then begin li_Ret := gfniMessageBoxYesNo(Format(G_csCustomShortCut_ReplaceCommandMessage, [G_csSHORTCUTKEY[l_MenuItem.Tag, G_ciSHORTCUTDISP], G_fnsCommandDescriptionGet(l_NowAction)]), G_csAPPTITLE); end; if (li_Ret = ID_YES) then begin F_SetKeyAction(li_KeyRow, l_Action); end; end; procedure TForm_Custom_ShortCut.F_CmdAddGesture(Sender: TObject); //コマンドにジェスチャを追加 var l_MenuItem: TMenuItem; li_Ret, li_GestureRow, li_CmdIndex: Integer; l_NowAction, l_Action: TAction; begin l_MenuItem := TMenuItem(Sender); li_GestureRow := l_MenuItem.Tag + StringGrid_Gesture.FixedRows; l_NowAction := F_GetGestureAction(li_GestureRow); li_CmdIndex := StringGrid_Command.Row - (StringGrid_Command.FixedRows); //ヘッダー分を引く。 l_Action := TAction(G_ActionList.Actions[li_CmdIndex]); if (l_NowAction = l_Action) then begin Exit end; li_Ret := ID_YES; if (l_NowAction <> nil) then begin li_Ret := gfniMessageBoxYesNo(Format(G_csCustomShortCut_ReplaceCommandMessage, [G_csGESTURESTRING[l_MenuItem.Tag], G_fnsCommandDescriptionGet(l_NowAction)]), G_csAPPTITLE); end; if (li_Ret = ID_YES) then begin F_SetGestureAction(li_GestureRow, l_Action); end; end; { function TApp_CustomShortCut.F_GetCmdHint(AAction: TAction): String; begin if (AAction = nil) then begin Result := ''; end else begin Result := Format('%s/%s', [AAction.Category, StripHotKey(AAction.Caption)]); end; end; } { procedure TApp_CustomShortCut.pagShortCutChange(Sender: TObject); var ls_List, ls_Add: String; begin if (pagShortCut.ActivePage = tabGesture) then begin ls_List := 'マウスジェスチャ'; ls_Add := 'ジェスチャ'; end else begin ls_List := 'キーリスト'; ls_Add := 'キー'; end; celCommand.Hint := Format('左の%sからドラッグし、ドロップしてコマンドに%sを追加', [ls_List, ls_Add]); end; } procedure TForm_Custom_ShortCut.F_DispCommandKey(AAction: TAction); //コマンドリストのAActionに設定されているキーを表示用にセットする procedure lpc_SetDispKey(var sKey: String; sAdd: String); begin sKey := Format('%s [%s]', [sKey, sAdd]); end; var i, li_CmdListRow: Integer; ls_Key: String; begin if (AAction = nil) then begin Exit; end; li_CmdListRow := AAction.Index + (StringGrid_Command.FixedRows); //ヘッダー分を足す //キーリスト ls_Key := ''; for i := 0 to G_ShortCutList.Count-1 do begin if (T_ShortCutAction(G_ShortCutList.Items[i]).Action = AAction) then begin lpc_SetDispKey(ls_Key, gfnsShortCutToText(T_ShortCutAction(G_ShortCutList.Items[i]).Key)); end; end; //マウスジェスチャ //キーリストと違ってApp_BugsEyeのF_GestureAction構造体にそれぞれのActionを保持している if (AAction = G_GestureUp) then begin lpc_SetDispKey(ls_Key, StringGrid_Gesture.Cells[lciCOL_KEYDISP, G_ciGESTUREUP + StringGrid_Gesture.FixedRows]); end; if (AAction = G_GestureDown) then begin lpc_SetDispKey(ls_Key, StringGrid_Gesture.Cells[lciCOL_KEYDISP, G_ciGESTUREDOWN + StringGrid_Gesture.FixedRows]); end; if (AAction = G_GestureLeft) then begin lpc_SetDispKey(ls_Key, StringGrid_Gesture.Cells[lciCOL_KEYDISP, G_ciGESTURELEFT + StringGrid_Gesture.FixedRows]); end; if (AAction = G_GestureRight) then begin lpc_SetDispKey(ls_Key, StringGrid_Gesture.Cells[lciCOL_KEYDISP, G_ciGESTURERIGHT + StringGrid_Gesture.FixedRows]); end; StringGrid_Command.Cells[lciCOL_CMDKEY, li_CmdListRow] := Trim(ls_Key); end; procedure TForm_Custom_ShortCut.F_DispShortCutKey; var i, k: Integer; li_Key: Word; l_Shift: TShiftState; l_Action: TAction; begin //キーにセットされているコマンドを表示 for i := 1 to StringGrid_ShortCutKey.RowCount-1 do begin l_Action := nil; ShortCutToKey(gfniTextToShortCut(StringGrid_ShortCutKey.Cells[lciCOL_KEYDISP, i]), li_Key, l_Shift); for k := 0 to G_ShortCutList.Count-1 do begin if (T_ShortCutAction(G_ShortCutList.Items[k]).Key = li_Key) then begin l_Action := T_ShortCutAction(G_ShortCutList.Items[k]).Action; F_SetAction(i, l_Action); Break; end; end; F_SetAction(i, l_Action); end; //コマンドにセットされているキーを表示 for i := 0 to G_ActionList.ActionCount-1 do begin l_Action := TAction(G_ActionList.Actions[i]); F_DispCommandKey(l_Action); end; end; //コマンドリスト //描画 procedure TForm_Custom_ShortCut.StringGrid_CommandDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid_Command.Canvas do begin if (ACol = lciCOL_CMDKEY) then begin Font.Name := G_csCustom_FixedFontName; end else begin Font.Name := G_csCustom_FontName; end; if (gdFixed in State) then begin Brush.Color := StringGrid_Command.FixedColor; Font.Color := StringGrid_Command.Font.Color; end else begin if (gdSelected in State) then begin if (GetFocus = StringGrid_Command.Handle) then begin Brush.Color := clHighlight; Font.Color := clHighlightText; end else begin Brush.Color := clBtnFace; Font.Color := clBtnText; end; end else begin Brush.Color := StringGrid_Command.Color; Font.Color := StringGrid_Command.Font.Color; end; end; FillRect(Rect); if (ARow = 0) then begin DrawText(Handle, PChar(StringGrid_Command.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_NOPREFIX or DT_CENTER or DT_VCENTER); end else begin Inc(Rect.Left, G_ciTEXT_MARGIN); DrawText(Handle, PChar(StringGrid_Command.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_VCENTER); end; end; end; //ドラッグ procedure TForm_Custom_ShortCut.StringGrid_CommandMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); //ドラッグ開始 //オートにすると不都合があるのでマニュアルドラッグ var li_Col, li_Row: Integer; l_Rect: TGridRect; begin F_Drag := Sender; with StringGrid_Command do begin MouseToCell(X, Y, li_Col, li_Row); if (li_Row > 0) then begin if (Button = mbLeft) then begin BeginDrag(False, GetSystemMetrics(SM_CXDOUBLECLK)); end else if (Button = mbRight) then begin if (Row <> li_Row) then begin l_Rect.Left := 0; l_Rect.Top := li_Row; l_Rect.Right := ColCount-1; l_Rect.Bottom := li_Row; Selection := l_Rect; end; end; end; end; end; procedure TForm_Custom_ShortCut.StringGrid_CommandMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var lpt_Pos: TPoint; li_Col, li_Row: Integer; begin lpt_Pos := gfnptMousePosGet; StringGrid_Command.MouseToCell(X, Y, li_Col, li_Row); if (F_Drag = StringGrid_Command) and (li_Row = 0) then begin if (li_Col = lciCOL_CMDCATEGORY) or (Button = mbRight) then begin mnuCommand_Category.Popup(lpt_Pos.X, lpt_Pos.Y); end; end else if (Button = mbRight) then begin mnuCommand.Popup(lpt_Pos.X, lpt_Pos.Y); end else begin // mnuCommandPopup(nil); end; end; procedure TForm_Custom_ShortCut.StringGrid_CommandSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin F_CommandPopup(ARow); end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeySelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin F_ShortCutPopup(ARow); end; procedure TForm_Custom_ShortCut.StringGrid_GestureSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin F_MouseGesturePopup(ARow); end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var li_Col, li_Row: Integer; l_Rect: TGridRect; l_Grid: TStringGrid; begin if not(Sender is TStringGrid) then Exit; l_Grid := TStringGrid(Sender); F_Drag := Sender; if (Button = mbLeft) then begin l_Grid.BeginDrag(False, GetSystemMetrics(SM_CXDOUBLECLK)); end else if (Button = mbRight) then begin with l_Grid do begin MouseToCell(X, Y, li_Col, li_Row); if (li_Row > 0) and (li_Row <> Row) then begin l_Rect.Left := 0; l_Rect.Top := li_Row; l_Rect.Right := ColCount-1; l_Rect.Bottom := li_Row; Selection := l_Rect; end; end; end; end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var lpt_Pos: TPoint; li_Col, li_Row: Integer; l_Grid: TStringGrid; begin if not(Sender is TStringGrid) then Exit; l_Grid := TStringGrid(Sender); l_Grid.MouseToCell(X, Y, li_Col, li_Row); if ((F_Drag = StringGrid_ShortCutKey) or (F_Drag = StringGrid_Gesture)) and (li_Row > 0) and (Button = mbRight) then begin lpt_Pos := gfnptMousePosGet; l_Grid.PopupMenu.Popup(lpt_Pos.X, lpt_Pos.Y); end else begin l_Grid.PopupMenu.OnPopup(nil); end; end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var l_Grid: TStringGrid; begin if not(Sender is TStringGrid) then Exit; l_Grid := TStringGrid(Sender); case Key of VK_F10: begin if (ssShift in Shift) then begin l_Grid.PopupMenu.Popup(l_Grid.ClientOrigin.X, l_Grid.ClientOrigin.Y); end; Key := 0; end; VK_APPS: begin l_Grid.PopupMenu.Popup(l_Grid.ClientOrigin.X, l_Grid.ClientOrigin.Y); Key := 0; end; VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_HOME, VK_END: begin // l_Grid.PopupMenu.OnPopup(nil); end; end; end; procedure TForm_Custom_ShortCut.StringGrid_CommandDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); //ドラッグ中のcelCommandListのマウスカーソルをドラッグ状態にするために必要。 var li_Col, li_Row: Integer; begin if (F_Drag = StringGrid_ShortCutKey) or (F_Drag = StringGrid_Gesture) then begin //X,Yはグリッドのクライアント座標 with StringGrid_Command do begin MouseToCell(X, Y, li_Col, li_Row); Accept := {(li_Col = lciCOL_CMDHINT) and} (li_Row > 0); end; end else begin Accept := False; Exit; end; end; procedure TForm_Custom_ShortCut.StringGrid_CommandDragDrop(Sender, Source: TObject; X, Y: Integer); //キー&マウスジェスチャのリストからコマンドリストへドロップ var li_Col, li_Row: Integer; lr_GridRect: TGridRect; begin if (F_Drag = StringGrid_ShortCutKey) or (F_Drag = StringGrid_Gesture) then begin with StringGrid_Command do begin MouseToCell(X, Y, li_Col, li_Row); with lr_GridRect do begin Left := 0; Top := li_Row; Right := ColCount -1; Bottom := li_Row; end; Selection := lr_GridRect; end; if (F_Drag = StringGrid_ShortCutKey) then begin //コマンドリストへキーを追加 actShortCutKey_SetExecute(nil); end else if (F_Drag = StringGrid_Gesture) then begin //コマンドリストへマウスジェスチャを追加 actGesture_SetExecute(nil); end; end; end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); //ドラッグ中のマウスカーソルをドラッグ状態にするために必要。 var li_Col, li_Row: Integer; l_Grid: TStringGrid; begin if (F_Drag <> StringGrid_Command) or not(Sender is TStringGrid) then begin Accept := False; Exit; end; l_Grid := TStringGrid(Sender); //X,Yはグリッドのクライアント座標 with l_Grid do begin MouseToCell(X, Y, li_Col, li_Row); Accept := {(li_Col = lciCOL_KEYCMDHINT) and} (li_Row > 0); end; end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyDragDrop(Sender, Source: TObject; X, Y: Integer); //コマンドリストからキー&マウスジェスチャのリストへドロップ var li_Col, li_Row: Integer; lr_GridRect: TGridRect; l_Grid: TStringGrid; begin if not(Sender is TStringGrid) then Exit; if (F_Drag <> StringGrid_Command) then begin Exit; end; l_Grid := TStringGrid(Sender); with l_Grid do begin MouseToCell(X, Y, li_Col, li_Row); with lr_GridRect do begin Left := 0; Top := li_Row; Right := ColCount -1; Bottom := li_Row; end; Selection := lr_GridRect; end; if (Sender = StringGrid_ShortCutKey) then begin //キーリスト actShortCutKey_SetExecute(nil); end else if (Sender = StringGrid_Gesture) then begin //マウスジェスチャリスト actGesture_SetExecute(nil); end; end; procedure TForm_Custom_ShortCut.F_ShortCutPopup(iIndex: Integer); var ls_Key : String; ls_KeyCmdHint : String; ls_CmdHint : String; l_Action : TAction; begin ls_Key := StringGrid_ShortCutKey.Cells[lciCOL_KEYDISP, iIndex]; //対象となるキー ls_KeyCmdHint := StringGrid_ShortCutKey.Cells[lciCOL_KEYCMDHINT, iIndex]; //キーに設定済みのコマンドの説明 l_Action := F_GetKeyAction(iIndex); ls_CmdHint := G_fnsCommandDescriptionGet(l_Action); //設定しようとしているコマンドの説明 Label_Hint.Caption := G_fnsCommandHintGet(l_Action); // actShortCutKey_Set.Enabled := (ls_KeyCmdHint <> '') and (ls_KeyCmdHint <> ls_CmdHint); { actShortCutKey_Set.Caption := Format('[%s] に %s をセット(&S)', [ ls_Key, ls_CmdHint, '' ] ); } actShortCutKey_Delete.Enabled := (ls_KeyCmdHint <> ''); { if (actShortCutKey_Delete.Enabled) then begin actShortCutKey_Delete.Caption := Format('[%s] のコマンドを削除(&R)', [ ls_Key, '' ] ); end else begin actShortCutKey_Delete.Caption := 'キーのコマンドを削除(&R)'; end; } end; procedure TForm_Custom_ShortCut.mnuShortCutKeyPopup(Sender: TObject); //キーリストメニューをポップアップ begin F_ShortCutPopup(StringGrid_ShortCutKey.Row); end; procedure TForm_Custom_ShortCut.F_MouseGesturePopup(iIndex: Integer); var ls_Gesture : String; ls_GestureCmdHint : String; ls_CmdHint : String; l_Action : TAction; begin ls_Gesture := StringGrid_Gesture.Cells[lciCOL_KEYDISP, iIndex]; //対象となるジェスチャ ls_GestureCmdHint := StringGrid_Gesture.Cells[lciCOL_KEYCMDHINT, iIndex]; //ジェスチャに設定済みのコマンドの説明 l_Action := F_GetGestureAction(iIndex); ls_CmdHint := G_fnsCommandDescriptionGet(l_Action); //設定しようとしているコマンドの説明 Label_Hint.Caption := G_fnsCommandHintGet(l_Action); { actGesture_Set.Caption := Format('[%s] に %s をセット(&S)', [ ls_Gesture, ls_CmdHint, '' ] ); } actGesture_Delete.Enabled := (ls_GestureCmdHint <> ''); //マウスジェスチャのコマンドが空でなければTrue { if (actGesture_Delete.Enabled) then begin actGesture_Delete.Caption := Format('[%s] のコマンドを削除(&R)', [ ls_Gesture, '' ] ); end else begin actGesture_Delete.Caption := 'ジェスチャのコマンドを削除(&R)'; end; } end; procedure TForm_Custom_ShortCut.mnuGesturePopup(Sender: TObject); //マウスジェスチャメニューをポップアップ begin F_MouseGesturePopup(StringGrid_Gesture.Row); end; procedure TForm_Custom_ShortCut.F_CommandPopup(iIndex: Integer); var // l_StringGrid: TStringGrid; li_ActionIndex: Integer; l_Action: TAction; ls_CmdHint: String; begin if (PageControl_ShortCut.ActivePage = TabSheet_ShortCutKey) then begin // l_StringGrid := celShortCutKey; end else if (PageControl_ShortCut.ActivePage = TabSheet_Gesture) then begin // l_StringGrid := celGesture; end else begin // actCommand_KeyAdd.Caption := 'コマンドにキーを追加(&A)'; //例外 Exit; end; li_ActionIndex := iIndex - (StringGrid_Command.FixedRows); l_Action := TAction(G_ActionList.Actions[li_ActionIndex]); ls_CmdHint := G_fnsCommandDescriptionGet(l_Action); //対象となるコマンドの説明 // actCommand_KeyAdd.Enabled := F_GetKeyAction(l_StringGrid.Row) <> G_ActionList.Actions[li_ActionIndex]; { actCommand_KeyAdd.Caption := Format('%s のキーに [%s] を追加(&A)', [ ls_CmdHint, //コマンドの説明 l_StringGrid.Cells[lciCOL_KEYDISP, l_StringGrid.Row], '' ] ); } actCommand_KeyDelete.Enabled := (StringGrid_Command.Cells[lciCOL_CMDKEY, iIndex] <> ''); //コマンドのキー欄が空でなければTrue { if (actCommand_KeyDelete.Enabled) then begin actCommand_KeyDelete.Caption := Format('%s のキーとジェスチャを削除(&R)', [ ls_CmdHint, '' ] ); end else begin actCommand_KeyDelete.Caption := 'コマンドのキーとジェスチャを削除(&R)'; end; } Label_Hint.Caption := G_fnsCommandHintGet(l_Action); end; procedure TForm_Custom_ShortCut.mnuCommandPopup(Sender: TObject); //コマンドリストメニューをポップアップ begin F_CommandPopup(StringGrid_Command.Row); end; procedure TForm_Custom_ShortCut.F_ChangeSetting; {$IFDEF MEGALO_BUG} var i: Integer; {$ENDIF} begin // mnuCommandPopup(nil); // mnuShortCutKeyPopup(nil); // mnuGesturePopup(nil); {$IFDEF MEGALO_BUG} //ヘルプのショートカットリストを更新 for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] = G_HelpForm) then begin G_HelpForm.actHelp_UpdateExecute(nil); Break; end; end; {$ENDIF} end; //------------------------------------------------------------------------------ //コマンドキー procedure TForm_Custom_ShortCut.actCommand_KeyAddExecute(Sender: TObject); //コマンドにショートカットキーもしくはマウスジェスチャを追加 begin if (PageControl_ShortCut.ActivePage = TabSheet_ShortCutKey) then begin actShortCutKey_SetExecute(actShortCutKey_Set); end else if (PageControl_ShortCut.ActivePage = TabSheet_Gesture) then begin actGesture_SetExecute(actGesture_Set); end; end; procedure TForm_Custom_ShortCut.actCommand_KeyDeleteExecute(Sender: TObject); var i: Integer; l_Action: TAction; lb_Update: Boolean; begin //余計な更新をキャンセルするため lb_Update := False; l_Action := TAction(G_ActionList.Actions[StringGrid_Command.Row - StringGrid_Command.FixedRows]); if (StringGrid_Command.Cells[lciCOL_CMDKEY, StringGrid_Command.Row] <> '') then begin for i := StringGrid_ShortCutKey.FixedRows to StringGrid_ShortCutKey.RowCount-1 do begin if (F_GetKeyAction(i) = l_Action) then begin F_DelAction(i); F_SetAction(i, nil); lb_Update := True; end; end; end; if (G_GestureUp = l_Action) then begin; F_DelGestureAction(G_ciGESTUREUP + StringGrid_Gesture.FixedRows); lb_Update := True; end; if (G_GestureDown = l_Action) then begin; F_DelGestureAction(G_ciGESTUREDOWN + StringGrid_Gesture.FixedRows); lb_Update := True; end; if (G_GestureLeft = l_Action) then begin; F_DelGestureAction(G_ciGESTURELEFT + StringGrid_Gesture.FixedRows); lb_Update := True; end; if (G_GestureRight = l_Action) then begin; F_DelGestureAction(G_ciGESTURERIGHT + StringGrid_Gesture.FixedRows); lb_Update := True; end; if (lb_Update) then begin //ヘルプのショートカットリストも更新 F_ChangeSetting; end; end; //------------------------------------------------------------------------------ //ショートカットキー function TForm_Custom_ShortCut.F_GetShortCut(iIndex: Integer): TShortCut; //Objectsに格納されているShortCut値を返す begin Result := gfniTextToShortCut(StringGrid_ShortCutKey.Cells[lciCOL_KEYDISP, iIndex]); end; procedure TForm_Custom_ShortCut.F_SetAction(iRow: Integer; AAction: TAction); //キーリストのキーにセットするコマンドのカテゴリ/キャプションとコマンドのインデックスをセット var i: Integer; li_CellKey, li_Key: Word; begin //アクションのインデックスはコマンド列にセット if (AAction <> nil) then begin StringGrid_ShortCutKey.Cells[lciCOL_KEYCMDHINT, iRow] := G_fnsCommandDescriptionGet(AAction); StringGrid_ShortCutKey.Cols[lciCOL_KEYCMDHINT].Objects[iRow] := TObject(AAction.Index); li_CellKey := F_GetShortCut(iRow); for i := 0 to G_ShortCutList.Count-1 do begin li_Key := T_ShortCutAction(G_ShortCutList.Items[i]).Key; if (li_Key = li_CellKey) then begin Exit; end; end; G_ShortCutList.Add(T_ShortCutAction.Create(li_CellKey, AAction)); end else begin // F_DelAction(iIndex); NG; // //↑と順序を入れ替えてはいけない StringGrid_ShortCutKey.Cells[lciCOL_KEYCMDHINT, iRow] := ''; StringGrid_ShortCutKey.Cols[lciCOL_KEYCMDHINT].Objects[iRow] := TObject(-1); end; end; procedure TForm_Custom_ShortCut.F_SetAction(iRow, iActionIndex: Integer); var l_Action: TAction; begin if (iActionIndex >= 0) then begin l_Action := TAction(G_ActionList.Actions[iActionIndex]); F_SetAction(iRow, l_Action); end else begin F_SetAction(iRow, nil); end; end; function TForm_Custom_ShortCut.F_GetKeyAction(iRow: Integer): TAction; //キーにセットされているアクションを返す var li_Index: Integer; begin //コマンドのインデックスを取得 li_Index := Integer(StringGrid_ShortCutKey.Cols[lciCOL_KEYCMDHINT].Objects[iRow]); if (li_Index >= 0) then begin //0以上ならアクション Result := TAction(G_ActionList.Actions[li_Index]); end else begin Result := nil; end; end; procedure TForm_Custom_ShortCut.F_SetKeyAction(iRow: Integer; AAction: TAction); //キーにコマンドをセット var l_NowAction: TAction; begin l_NowAction := F_GetKeyAction(iRow); //コマンドリストの選択行 = コマンド if (l_NowAction <> nil) and (l_NowAction = AAction) then begin //現在の設定と同じなら新たな処理は必要ないので抜ける Exit; end; F_DelAction(iRow); F_SetAction(iRow, AAction); F_DispCommandKey(AAction); //ヘルプのショートカットリストも更新 F_ChangeSetting; end; procedure TForm_Custom_ShortCut.F_DelAction(iRow: Integer); //キーリストのiRow行のキーにセットされているコマンドを削除する var i, li_ActionIndex: Integer; li_Key: WORD; l_Action: TAction; begin //セットされているアクションのインデックス li_ActionIndex := Integer(StringGrid_ShortCutKey.Cols[lciCOL_KEYCMDHINT].Objects[iRow]); if (li_ActionIndex >= 0) then begin l_Action := TAction(G_ActionList.Actions[li_ActionIndex]); //セットされているショートカット値 li_Key := F_GetShortCut(iRow); for i := G_ShortCutList.Count-1 downto 0 do begin if (T_ShortCutAction(G_ShortCutList.Items[i]).Key = li_Key) then begin T_ShortCutAction(G_ShortCutList.Items[i]).Free; G_ShortCutList.Delete(i); end; end; F_DispCommandKey(l_Action); end; end; procedure TForm_Custom_ShortCut.actShortCutKey_SetExecute(Sender: TObject); //キーにコマンドをセット var li_KeyRow, li_CmdIndex: Integer; begin //キーリストの選択行 = キー li_KeyRow := StringGrid_ShortCutKey.Row; //コマンドリストの選択行 = コマンド li_CmdIndex := StringGrid_Command.Row - (StringGrid_Command.FixedRows); //ヘッダ分を引く F_SetKeyAction(li_KeyRow, TAction(G_ActionList.Actions[li_CmdIndex])); end; procedure TForm_Custom_ShortCut.actShortCutKey_DeleteExecute(Sender: TObject); //キーにセットされているコマンドを削除する var li_Row: Integer; l_Action: TAction; begin li_Row := StringGrid_ShortCutKey.Row; if (li_Row > 0) then begin l_Action := F_GetKeyAction(li_Row); F_DelAction(li_Row); F_SetAction(li_Row, -1); F_DispCommandKey(l_Action); //ヘルプのショートカットリストも更新 F_ChangeSetting; end; end; procedure TForm_Custom_ShortCut.actShortCutKey_ResetAllExecute(Sender: TObject); //ショートカット設定のリセット var i: Integer; begin //ショートカットキーの初期化 if (Sender = nil) or (gfniMessageBoxYesNo(G_csCusotmShortCut_ResetKeyMessage, G_csAPPTITLE) = ID_YES) then begin //初期設定をクリア G_pcClearShortCut; { for i := G_ShortCutList.Count-1 downto 0 do begin T_ShortCutAction(G_ShortCutList.Items[i]).Free; G_ShortCutList.Delete(i); end; } for i := 0 to G_InitShortCutList.Count-1 do begin G_ShortCutList.Add(T_ShortCutAction.Create( T_ShortCutAction(G_InitShortCutList.Items[i]).Key, T_ShortCutAction(G_InitShortCutList.Items[i]).Action )); end; if (Sender <> nil) then begin F_DispShortCutKey; end; //ヘルプのショートカットリストも更新 F_ChangeSetting; end; end; //------------------------------------------------------------------------------ //マウスジェスチャ function TForm_Custom_ShortCut.F_GetGestureAction(iRow: Integer): TAction; //ジェスチャにセットされているアクションを返す begin case iRow - StringGrid_Gesture.FixedRows of G_ciGESTUREUP : Result := G_GestureUp; G_ciGESTUREDOWN : Result := G_GestureDown; G_ciGESTURELEFT : Result := G_GestureLeft; G_ciGESTURERIGHT : Result := G_GestureRight; else Result := nil; end; end; procedure TForm_Custom_ShortCut.F_SetGestureAction(iRow: Integer; AAction: TAction); //マウスジェスチャにコマンドをセット。 begin F_DelGestureAction(iRow); case iRow - StringGrid_Gesture.FixedRows of G_ciGESTUREUP : G_GestureUp := AAction; G_ciGESTUREDOWN : G_GestureDown := AAction; G_ciGESTURELEFT : G_GestureLeft := AAction; G_ciGESTURERIGHT : G_GestureRight := AAction; else begin //後の処理を飛ばす Exit; end; end; StringGrid_Gesture.Cells[lciCOL_KEYCMDHINT, iRow] := G_fnsCommandDescriptionGet(AAction); F_DispCommandKey(AAction); //ヘルプのショートカットリストも更新 F_ChangeSetting; end; procedure TForm_Custom_ShortCut.F_DelGestureAction(iRow: Integer); //ジェスチャにセットされているコマンドを削除する var l_Action: TAction; begin l_Action := F_GetGestureAction(iRow); case iRow - StringGrid_Gesture.FixedRows of G_ciGESTUREUP : G_GestureUp := nil; G_ciGESTUREDOWN : G_GestureDown := nil; G_ciGESTURELEFT : G_GestureLeft := nil; G_ciGESTURERIGHT : G_GestureRight := nil; else begin //後の処理を飛ばす Exit; end; end; StringGrid_Gesture.Cells[lciCOL_CMDHINT, iRow] := ''; F_DispCommandKey(l_Action); end; procedure TForm_Custom_ShortCut.actGesture_SetExecute(Sender: TObject); //マウスジェスチャにコマンドをセット。 var li_CmdIndex, li_GestureRow: Integer; l_Action: TAction; begin li_CmdIndex := StringGrid_Command.Row - (StringGrid_Command.FixedRows); //ヘッダー分をマイナス l_Action := TAction(G_ActionList.Actions[li_CmdIndex]); li_GestureRow := StringGrid_Gesture.Row; F_SetGestureAction(li_GestureRow, l_Action); end; procedure TForm_Custom_ShortCut.actGesture_DeleteExecute(Sender: TObject); //マウスジェスチャにセットされているコマンドを削除する begin F_DelGestureAction(StringGrid_Gesture.Row); //ヘルプのショートカットリストも更新 F_ChangeSetting; end; procedure TForm_Custom_ShortCut.actMouseGesture_ResetExecute(Sender: TObject); var li_GestureRow: Integer; l_Action: TAction; begin li_GestureRow := StringGrid_Gesture.Row; case li_GestureRow - StringGrid_Gesture.FixedRows of G_ciGESTUREUP :begin G_GestureUp := G_InitGestureUp; l_Action := G_GestureUp; end; G_ciGESTUREDOWN :begin G_GestureDown := G_InitGestureDown; l_Action := G_GestureDown; end; G_ciGESTURELEFT :begin G_GestureLeft := G_InitGestureLeft; l_Action := G_GestureLeft; end; G_ciGESTURERIGHT :begin G_GestureRight := G_InitGestureRight; l_Action := G_GestureRight; end; else begin //後の処理を飛ばす Exit; end; end; StringGrid_Gesture.Cells[lciCOL_KEYCMDHINT, li_GestureRow] := G_fnsCommandDescriptionGet(l_Action); F_DispShortCutKey; //ヘルプのショートカットリストも更新 F_ChangeSetting; end; procedure TForm_Custom_ShortCut.actGesture_ResetAllExecute(Sender: TObject); //マウスジェスチャの初期化 begin if (Sender = nil) or (gfniMessageBoxYesNo(G_csCusotmShortCut_ResetGestureMessage, G_csAPPTITLE) = ID_YES) then begin G_GestureUp := G_InitGestureUp; G_GestureDown := G_InitGestureDown; G_GestureLeft := G_InitGestureLeft; G_GestureRight := G_InitGestureRight; StringGrid_Gesture.Cells[lciCOL_CMDHINT, G_ciGESTUREUP + StringGrid_Gesture.FixedRows] := G_fnsCommandDescriptionGet(G_GestureUp); StringGrid_Gesture.Cells[lciCOL_CMDHINT, G_ciGESTUREDOWN + StringGrid_Gesture.FixedRows] := G_fnsCommandDescriptionGet(G_GestureDown); StringGrid_Gesture.Cells[lciCOL_CMDHINT, G_ciGESTURELEFT + StringGrid_Gesture.FixedRows] := G_fnsCommandDescriptionGet(G_GestureLeft); StringGrid_Gesture.Cells[lciCOL_CMDHINT, G_ciGESTURERIGHT + StringGrid_Gesture.FixedRows] := G_fnsCommandDescriptionGet(G_GestureRight); if (Sender <> nil) then begin F_DispShortCutKey; end; //ヘルプのショートカットリストも更新 F_ChangeSetting; end; end; procedure TForm_Custom_ShortCut.actCommand_KeyResetAllExecute(Sender: TObject); begin if (gfniMessageBoxYesNo(G_csCusotmShortCut_ResetCommandMessage, G_csAPPTITLE) = ID_YES) then begin actShortCutKey_ResetAllExecute(nil); actGesture_ResetAllExecute(nil); F_DispShortCutKey; //ヘルプのショートカットリストも更新 F_ChangeSetting; end; end; procedure TForm_Custom_ShortCut.StringGrid_ShortCutKeyDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var // l_Action: TAction; l_Grid: TStringGrid; begin if not(Sender is TStringGrid) then begin Exit; end; l_Grid := TStringGrid(Sender); with l_Grid.Canvas do begin if (ACol = lciCOL_KEYDISP) then begin Font.Name := G_csCustom_FixedFontName; end else begin Font.Name := G_csCustom_FontName; end; if (gdFixed in State) then begin Brush.Color := l_Grid.FixedColor; Font.Color := l_Grid.Font.Color; end else begin if (gdSelected in State) then begin if (GetFocus = l_Grid.Handle) then begin Brush.Color := clHighlight; Font.Color := clHighlightText; end else begin Brush.Color := clBtnFace; Font.Color := clBtnText; end; end else begin Brush.Color := l_Grid.Color; Font.Color := l_Grid.Font.Color; end; end; FillRect(Rect); if (ARow = 0) then begin DrawText(Handle, PChar(l_Grid.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_NOPREFIX or DT_CENTER or DT_VCENTER); end else if (ACol = lciCOL_KEYDISP) then begin Inc(Rect.Left, G_ciTEXT_MARGIN); Dec(Rect.Right, G_ciTEXT_MARGIN); if (l_Grid = StringGrid_ShortCutKey) then begin //キーは右寄せ DrawText(Handle, PChar(l_Grid.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_NOPREFIX or DT_RIGHT or DT_VCENTER); end else begin //マウスジェスチャは左寄せ DrawText(Handle, PChar(l_Grid.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_NOPREFIX or DT_VCENTER); end; end else if (ACol = lciCOL_KEYCMDHINT) then begin if (l_Grid.Cells[ACol, ARow] <> '') then begin Inc(Rect.Left, G_ciTEXT_MARGIN); DrawText(Handle, PChar(l_Grid.Cells[ACol, ARow]), -1, Rect, DT_SINGLELINE or DT_VCENTER); end; end; end; end; procedure TForm_Custom_ShortCut.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var l_Grid: TStringGrid; begin case Key of VK_F10 :begin if (ssShift in Shift) then begin if (StringGrid_Command.Focused) then begin l_Grid := StringGrid_Command; end else if (StringGrid_ShortCutKey.Focused) then begin l_Grid := StringGrid_ShortCutKey; end else if (StringGrid_Gesture.Focused) then begin l_Grid := StringGrid_Gesture; end else begin l_Grid := nil; end; if (l_Grid <> nil) then begin l_Grid.PopupMenu.Popup(l_Grid.ClientOrigin.X, l_Grid.ClientOrigin.Y); end; Key := 0; end else if not(ssAlt in Shift) and not(ssCtrl in Shift) // and not(ssShift in Shift) then begin actMenu_PopupExecute(nil); Key := 0; end; end; VK_APPS :begin if not(StringGrid_Command.Focused) and not(StringGrid_ShortCutKey.Focused) and not(StringGrid_Gesture.Focused) then begin actMenu_PopupExecute(nil); Key := 0; end; end; end; end; procedure TForm_Custom_ShortCut.actMenu_PopupExecute(Sender: TObject); begin mnuCustomShortCut.Popup(Self.ClientOrigin.X, Self.ClientOrigin.Y); end; //============================================================================== procedure lpcMaxLengthSet; var i: Integer; begin G_iKeyLength := 1; G_iGestureLength := 1; G_iShortCutLength := 1; for i := 0 to High(G_csSHORTCUTKEY) do begin G_iKeyLength := gfniMax([G_iKeyLength, Length(G_csSHORTCUTKEY[i, G_ciSHORTCUTDISP])]); end; for i := 0 to High(G_csGESTURESTRING) do begin G_iGestureLength := gfniMax([G_iGestureLength, Length(G_csGESTURESTRING[i])]); end; G_iShortCutLength := gfniMax([G_iKeyLength, G_iGestureLength]); end; procedure lpcListFree(AList: TList); var i: Integer; begin for i := AList.Count-1 downto 0 do begin T_ShortCutAction(AList.Items[i]).Free; AList.Delete(i); end; AList.Free; end; procedure TForm_Custom_ShortCut.ComboBox_CommandCategorySelect(Sender: TObject); //カテゴリジャンプ var l_MenuItem : TMenuItem; l_ComboBox : TComboBox; i: Integer; l_Select : TGridRect; ls_Caption : String; begin if (Sender is TMenuItem) then begin l_MenuItem := TMenuItem(Sender); ls_Caption := l_MenuItem.Caption; end else if (Sender is TComboBox) then begin l_ComboBox := TComboBox(Sender); //AIU if (l_ComboBox.ItemIndex < 0) then begin Exit; end; ls_Caption := l_ComboBox.Items[l_ComboBox.ItemIndex]; end else begin Exit; end; for i := 1 to StringGrid_Command.RowCount-1 do begin if (ls_Caption = StringGrid_Command.Cells[lciCOL_CMDCATEGORY, i]) then begin StringGrid_Command.TopRow := i; l_Select.Left := 0; l_Select.Top := i; l_Select.Right := StringGrid_Command.ColCount-1; l_Select.Bottom := i; StringGrid_Command.Selection := l_Select; Exit; end; end; end; procedure TForm_Custom_ShortCut.ComboBox_CommandCategoryDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var l_Rect : TRect; begin with ComboBox_CommandCategory do begin Canvas.Font.Assign(Font); l_Rect := Rect; Inc(l_Rect.Left, G_ciTEXT_MARGIN); if (odSelected in State) and (DroppedDown) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else begin Canvas.Font.Color := clWindowText; Canvas.Brush.Color := clWindow; end; Canvas.FillRect(Rect); DrawText(Canvas.Handle, PChar(Items[Index]), -1, l_Rect, DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER); end; end; initialization lpcMaxLengthSet; //ショートカットリスト G_InitShortCutList := TList.Create; G_ShortCutList := TList.Create; //マウスジェスチャ G_InitGestureUp := nil; G_InitGestureDown := nil; G_InitGestureLeft := nil; G_InitGestureRight := nil; G_GestureUp := nil; G_GestureDown := nil; G_GestureLeft := nil; G_GestureRight := nil; finalization lpcListFree(G_InitShortCutList); lpcListFree(G_ShortCutList); end.