unit custom_toolbar; //{$DEFINE _DEBUG} //{$DEFINE MYLIB} interface uses Windows, Messages, SysUtils, Graphics, Controls, Forms, ComCtrls, ExtCtrls, StdCtrls, ActnList, Menus, Classes, CheckLst, Buttons; // my_IniFile; type T_MyToolButton = class(TToolButton) protected procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; procedure MouseUp (Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; end; type TForm_Custom_ToolBar = class(TForm) ActionList_ToolBar: TActionList; Action_File_Close: TAction; Action_ToolBar_Add: TAction; Action_ToolBar_Delete: TAction; Action_ToolBar_ResetAll: TAction; Action_ToolBar_MoveUp: TAction; Action_ToolBar_MoveDown: TAction; Action_ToolBar_Insert: TAction; mnuCommandCategory: TPopupMenu; mnuCommandList: TPopupMenu; mniToolBar_Add: TMenuItem; mnuNowSetting: TPopupMenu; mniToolBar_Delete: TMenuItem; mniToolBar_NowSettingLine1: TMenuItem; mniToolBar_Reset: TMenuItem; pnlToolBar: TPanel; Panel_Command: TPanel; Label_Command: TLabel; CheckListBox_Command: TCheckListBox; Panel_NowSetting: TPanel; Label_NowSetting: TLabel; CheckListBox_NowSetting: TCheckListBox; Panel_Cmd: TPanel; Button_Close: TButton; Button_Reset: TButton; GroupBox_Hint: TGroupBox; Label_Hint: TLabel; ComboBox_CommandCategory: TComboBox; Panel_Button: TPanel; Button_ToolBar_Add: TButton; Button_ToolBar_Delete: TButton; Button_ToolBar_MoveUp: TButton; Button_ToolBar_MoveDown: TButton; procedure Action_File_CloseExecute (Sender: TObject); procedure Action_ToolBar_AddExecute (Sender: TObject); procedure Action_ToolBar_DeleteExecute (Sender: TObject); procedure Action_ToolBar_ResetAllExecute(Sender: TObject); procedure Action_ToolBar_MoveUpExecute (Sender: TObject); procedure Action_ToolBar_MoveDownExecute(Sender: TObject); procedure Action_ToolBar_InsertExecute (Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); procedure FormResize(Sender: TObject); procedure mnuCommandListPopup (Sender: TObject); procedure mnuNowSettingPopup (Sender: TObject); procedure CheckListBox_CommandDragDrop (Sender, Source: TObject; X, Y: Integer); procedure CheckListBox_CommandDragOver (Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure CheckListBox_CommandDrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure CheckListBox_CommandMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure CheckListBox_CommandEnter (Sender: TObject); procedure CheckListBox_CommandMouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure CheckListBox_CommandClickCheck(Sender: TObject); procedure CheckListBox_NowSettingDragDrop (Sender, Source: TObject; X, Y: Integer); procedure CheckListBox_NowSettingDragOver (Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure CheckListBox_NowSettingDrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure CheckListBox_NowSettingKeyUp (Sender: TObject; var Key: Word; Shift: TShiftState); procedure CheckListBox_NowSettingEnter (Sender: TObject); procedure CheckListBox_NowSettingClickCheck (Sender: TObject); procedure CheckListBox_CommandClick(Sender: TObject); procedure CheckListBox_NowSettingClick(Sender: TObject); procedure ComboBox_CommandCategorySelect(Sender: TObject); procedure ComboBox_CommandCategoryDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private 宣言 } function F_GetDescription (AToolButton: TToolButton): String; // procedure F_CmdGoToCategory(Sender: TObject); procedure FSetHighDPIControlHeight; public { Public 宣言 } // procedure ToolBarButton_MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); // procedure ToolBarButton_MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); end; //------------------------------------------------------------------------------ procedure ClearToolBar; function AppendToolButton(sName: String): Boolean; overload; function AppendToolButton(AAction: TAction): Boolean; overload; function InsertToolButton(iIndex: Integer; AAction: TAction): Boolean; function DeleteToolButton(iIndex: Integer): Boolean; overload; function DeleteToolButton(AAction: TAction): Boolean; overload; procedure G_pcCreateToolBarForm; procedure G_pcSetInitToolBar(AToolBar: TToolBar); //procedure G_pcReadIniToolBar (AIniFile: TMyIniFile); //procedure G_pcWriteIniToolBar(AIniFile: TMyIniFile; AToolBar: TToolBar); procedure G_pcSetReadBinToolBar; function G_fniWriteBinToolBar(hHandle: THandle): DWORD; var G_InitToolBar: TList; G_ToolBar: TToolBar; Form_Custom_ToolBar: TForm_Custom_ToolBar; //============================================================================== implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} CommCtrl, general, custom_base, custom_shortcut, my_settingfile, lang, main, highDPIUnit, common; {$R *.dfm} //============================================================================== procedure ClearToolBar; var i:Integer; begin for i := G_ToolBar.ButtonCount-1 downto 0 do begin DeleteToolButton(i); end; end; function AppendToolButton(sName: String): Boolean; //sNameのNameプロパティを持つActionをツールボタンに追加する var i: Integer; begin sName := UpperCase(sName); for i := 0 to G_ActionList.ActionCount-1 do begin if (UpperCase(G_ActionList.Actions[i].Name) = sName) then begin Result := AppendToolButton(TAction(G_ActionList.Actions[i])); Exit; end; end; Result := AppendToolButton(nil); end; function AppendToolButton(AAction: TAction): Boolean; begin Result := InsertToolButton(G_ToolBar.ButtonCount, AAction); end; function InsertToolButton(iIndex: Integer; AAction: TAction): Boolean; var li_Left: Integer; ls_Name: String; l_InsertPos, l_ToolButton: TToolButton; begin Result := False; if (AAction = nil) then begin Exit; end else begin ls_Name := gfnsAvailableName(Format('ToolButton_%s', [Copy(AAction.Name, 8, MaxInt)])); end; if (G_ToolBar.ButtonCount <= 0) or (iIndex = 0) then begin li_Left := 0; end else begin iIndex := gfniNumLimit(iIndex, 1, G_ToolBar.ButtonCount); l_InsertPos := G_ToolBar.Buttons[iIndex -1]; //一つ前のボタンから計算するため-1 li_Left := l_InsertPos.Left + l_InsertPos.Width; end; l_ToolButton := TToolButton.Create(G_ToolBar); with l_ToolButton do begin if (li_Left > 0) then begin Left := li_Left; end; Name := ls_Name; Parent := G_ToolBar; Action := AAction; if (AAction.AutoCheck) or (AAction.GroupIndex > 0) then begin Style := tbsCheck; end; G_MainForm.SetToolButtonMenu(l_ToolButton, AAction); end; Result := True; end; function DeleteToolButton(iIndex: Integer): Boolean; begin Result := False; if (iIndex >= 0) and (iIndex < G_ToolBar.ButtonCount) then begin G_ToolBar.Buttons[iIndex].Free; Result := True; end; end; function DeleteToolButton(AAction: TAction): Boolean; var i:Integer; begin Result := False; for i := G_ToolBar.ButtonCount-1 downto 0 do begin if (G_ToolBar.Buttons[i].Action = AAction) then begin DeleteToolButton(i); Result := True; //Break; end; end; end; procedure G_pcCreateToolBarForm; procedure _CreateForm; begin Form_Custom_ToolBar := TForm_Custom_ToolBar.Create(G_MainForm); end; var i: Integer; begin if (Form_Custom_ToolBar = nil) then begin _CreateForm; end else begin for i := 0 to Screen.FormCount -1 do begin if (Screen.Forms[i] = Form_Custom_ToolBar) then begin Exit; end; end; _CreateForm; end; end; procedure G_pcSetInitToolBar(AToolBar: TToolBar); var i: Integer; begin for i := 0 to AToolBar.ButtonCount-1 do begin G_InitToolBar.Add(AToolBar.Buttons[i].Action); end; end; (* const lcsSECT_TOOLBAR = 'ToolBar'; procedure G_pcReadIniToolBar(AIniFile: TMyIniFile); var lsl_List: TStrings; i: Integer; begin lsl_List := TStringList.Create; try //[ToolBar] if (AIniFile.SectionExists(lcsSECT_TOOLBAR)) then begin //初期設定をクリア ClearToolBar; AIniFile.ReadSectionText(lcsSECT_TOOLBAR, lsl_List); //Action.Nameを順番に列挙しているだけ for i := 0 to lsl_List.Count-1 do begin // AppendToolButton(lsl_List[i]); AppendToolButton(G_MainForm.Get_CommandToAction(gfniStrToInt(lsl_List[i]))); end; end; finally lsl_List.Free; end; end; procedure G_pcWriteIniToolBar(AIniFile: TMyIniFile; AToolBar: TToolBar); var lsl_List: TStrings; i: Integer; begin lsl_List := TStringList.Create; try //[ToolButton] AIniFile.EraseSection(lcsSECT_TOOLBAR); for i := 0 to AToolBar.ButtonCount-1 do begin if (AToolBar.Buttons[i].Action <> nil) then begin // lsl_List.Add(AToolBar.Buttons[i].Action.Name); lsl_List.Add(IntToStr(G_MainForm.Get_ActionToCommand(TAction(AToolBar.Buttons[i].Action)))); end; end; AIniFile.WriteSectionText(lcsSECT_TOOLBAR, lsl_List); finally lsl_List.Free; end; end; *) procedure G_pcSetReadBinToolBar; var i: Integer; begin //[ToolBar] //初期設定をクリア ClearToolBar; if (High(G_ToolBarAction) >= 0) then begin //Action.Nameを順番に列挙しているだけ for i := 0 to High(G_ToolBarAction) do begin AppendToolButton(G_MainForm.Get_CommandToAction(G_ToolBarAction[i])); end; end; end; function G_fniWriteBinToolBar(hHandle: THandle): DWORD; var i: Integer; li_Count: Word; li_Write: DWORD; begin // Result := 0; li_Count := G_MainForm.ToolBar_Main.ButtonCount; SetLength(G_ToolBarAction, li_Count); for i := 0 to High(G_ToolBarAction) do begin if (G_MainForm.ToolBar_Main.Buttons[i].Action <> nil) then begin G_ToolBarAction[i] := G_MainForm.Get_ActionToCommand(TAction(G_MainForm.ToolBar_Main.Buttons[i].Action)); end; end; WriteFile(hHandle, li_Count, SizeOf(li_Count), li_Write, nil); Result := SizeOf(li_Count); if (li_Count > 0) then begin WriteFile(hHandle, G_ToolBarAction[0], SizeOf(Word) * li_Count, li_Write, nil); Inc(Result, SizeOf(Word) * li_Count); end; end; //============================================================================== procedure T_MyToolButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Assigned(OnMouseDown) then OnMouseDown(Self, Button, Shift, X, Y); end; procedure T_MyToolButton.MouseMove(Shift: TShiftState; X, Y: Integer); begin if Assigned(OnMouseMove) then OnMouseMove(Self, Shift, X, Y); end; procedure T_MyToolButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Assigned(OnMouseUp) then OnMouseUp(Self, Button, Shift, X, Y); end; //============================================================================== procedure TForm_Custom_ToolBar.ComboBox_CommandCategorySelect(Sender: TObject); //カテゴリジャンプ var i: Integer; l_MenuItem : TMenuItem; l_ComboBox : TComboBox; 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 CheckListBox_Command.Items.Count -1 do begin if (ls_Caption = TAction(CheckListBox_Command.Items.Objects[i]).Category) then begin CheckListBox_Command.TopIndex := i; Exit; end; end; end; procedure TForm_Custom_ToolBar.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; function TForm_Custom_ToolBar.F_GetDescription(AToolButton: TToolButton): String; var l_Action: TAction; begin l_Action := TAction(AToolButton.Action); if (l_Action = nil) then begin if (AToolButton.Style = tbsSeparator) or (AToolButton.Style = tbsDivider) then begin Result := G_MainForm.actSpc.Caption; //'区切り'; end else begin Result := StripHotKey(AToolButton.Caption); end; end else begin Result := G_fnsCommandDescriptionGet(l_Action); end; end; procedure TForm_Custom_ToolBar.FSetHighDPIControlHeight; var li_Width : Integer; 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); //ComboBox_CommandCategory.Top := Label_Command.BoundsRect.Bottom; G_ControlTopSet([Label_Command, ComboBox_CommandCategory]); G_ControlLeftSet(ComboBox_CommandCategory); gpcItemHeightSet(CheckListBox_Command, G_ActionList.Images.Height); G_ControlWidthSet(CheckListBox_Command); G_ControlTopSet([ComboBox_CommandCategory, CheckListBox_Command]); G_ControlLeftSet(CheckListBox_Command); //CheckListBox_Command.Top := ComboBox_CommandCategory.BoundsRect.Bottom; CheckListBox_Command.Height := CheckListBox_Command.Parent.ClientHeight - CheckListBox_Command.Top - G_ciCONTROL_MARGIN; //Panel_Button gpcButtonHeightSet(Button_ToolBar_Add); gpcButtonHeightSet(Button_ToolBar_Delete); gpcButtonHeightSet(Button_ToolBar_MoveUp); gpcButtonHeightSet(Button_ToolBar_MoveDown); Button_ToolBar_Add.Top := CheckListBox_Command.Top; G_ControlTopSet([Button_ToolBar_Add, Button_ToolBar_Delete]); G_ControlTopSet([Button_ToolBar_MoveUp, Button_ToolBar_MoveDown]); li_Width := gfniMax([ gfniCanvasTextWidthGet(Button_ToolBar_Add.Font, Button_ToolBar_Add.Caption), gfniCanvasTextWidthGet(Button_ToolBar_Delete.Font, Button_ToolBar_Delete.Caption), gfniCanvasTextWidthGet(Button_ToolBar_MoveUp.Font, Button_ToolBar_MoveUp.Caption), gfniCanvasTextWidthGet(Button_ToolBar_MoveDown.Font, Button_ToolBar_MoveDown.Caption) ]) + (G_ciCONTROL_MARGIN * 2); Button_ToolBar_Add.Width := li_Width; Button_ToolBar_Delete.Width := li_Width; Button_ToolBar_MoveUp.Width := li_Width; Button_ToolBar_MoveDown.Width := li_Width; Panel_Button.ClientWidth := li_Width; //現在設定されているコマンド gpcLabelHeightSet(Label_NowSetting); gpcItemHeightSet(CheckListBox_NowSetting, G_ActionList.Images.Height); G_ControlWidthSet(CheckListBox_NowSetting); G_ControlTopSet([Label_NowSetting, CheckListBox_NowSetting]); G_ControlLeftSet(CheckListBox_NowSetting); CheckListBox_NowSetting.Height := CheckListBox_NowSetting.Parent.ClientHeight - CheckListBox_NowSetting.Top - G_ciCONTROL_MARGIN; //ヒントボックスの高さ調整 G_HintBoxHeightSet(GroupBox_Hint); //下部のコマンドボタンの調整 gpcButtonHeightSet(Button_Reset); gpcButtonHeightSet(Button_Close); G_PanelCmdHieghtSet(Panel_Cmd); G_ControlTopSet(Button_Reset); G_ControlTopSet(Button_Close); G_ControlLeftSet(Button_Reset); G_CloseButtonLeftSet(Button_Close); end; procedure TForm_Custom_ToolBar.FormCreate(Sender: TObject); var i, k: Integer; lh_Menu: HMENU; l_Action: TAction; ls_Category: String; begin G_pcCreateCustomBaseForm; Self.ManualDock(G_CustomForm.tabToolBar); Self.Align := alClient; pnlToolBar.Align := alClient; Panel_Command.Align := alClient; Self.Icon := Application.Icon; Self.Visible := True; 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); //高DPI対応 FSetHighDPIControlHeight; //コマンドリスト for i := 0 to G_ActionList.ActionCount-1 do begin l_Action := TAction(G_ActionList.Actions[i]); if (l_Action.ImageIndex < 0) then begin //イメージの割り当てられていないアクションは除外 Continue; end; CheckListBox_Command.Items.AddObject(l_Action.Caption, l_Action); for k := 0 to G_ToolBar.ButtonCount-1 do begin if (G_ToolBar.Buttons[k].Action = l_Action) then begin CheckListBox_Command.Checked[CheckListBox_Command.Count -1] := True; Break; end; end; end; CheckListBox_Command.ItemIndex := 0; //カテゴリメニュー構築 ls_Category := ''; 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; //カテゴリ選択リストに追加 ComboBox_CommandCategory.Items.Add(ls_Category); //メニューに追加 mnuCommandCategory.Items.Add( NewItem( // Format('%s へ移動', [ls_Category]), ls_Category, 0, False, True, ComboBox_CommandCategorySelect, 0, Format('mniPShortCut_Category_%d', [i]) ) ); end; end; ComboBox_CommandCategory.ItemIndex := 0; //現在の設定 for i := 0 to G_ToolBar.ButtonCount-1 do begin CheckListBox_NowSetting.Items.Add(''); CheckListBox_NowSetting.Checked[i] := True; end; if (CheckListBox_NowSetting.Items.Count > 0) then begin CheckListBox_NowSetting.ItemIndex := 0; end; Tag := 1; end; procedure TForm_Custom_ToolBar.FormClose(Sender: TObject; var Action: TCloseAction); begin Action := caFree; end; procedure TForm_Custom_ToolBar.FormResize(Sender: TObject); begin Panel_NowSetting.Width := (Self.ClientWidth - Panel_Button.Width) div 2; end; //閉じる procedure TForm_Custom_ToolBar.Action_File_CloseExecute(Sender: TObject); begin G_CustomForm.actFile_CloseExecute(nil); end; //コマンドリスト //描画 procedure TForm_Custom_ToolBar.CheckListBox_CommandDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var l_Action: TAction; begin with CheckListBox_Command.Canvas do begin if (odSelected in State) then begin if (GetFocus = CheckListBox_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 := CheckListBox_Command.Color; Font.Color := CheckListBox_Command.Font.Color; end; // Font.Name := 'MS UI Gothic'; l_Action := TAction(CheckListBox_Command.Items.Objects[Index]); if (l_Action.Name = 'actSpc') then begin FillRect(Classes.Rect(0, Rect.Top, Rect.Right, Rect.Bottom)); end else begin FillRect(Rect); end; if (G_ActionList.Images <> nil) then begin if (l_Action.ImageIndex > -1) then begin G_ActionList.Images.Draw(CheckListBox_Command.Canvas, Rect.Left, Rect.Top + gfniMax([0, (CheckListBox_Command.ItemHeight - G_ActionList.Images.Height) div 2]), l_Action.ImageIndex); end; Inc(Rect.Left, G_ActionList.Images.Width + G_ciTEXT_MARGIN); end; DrawText(Handle, PChar(G_fnsCommandDescriptionGet(l_Action)), -1, Rect, DT_SINGLELINE or DT_VCENTER); end; end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var l_ToolButton : TToolButton; l_Action : TAction; begin with CheckListBox_NowSetting.Canvas do begin if (odSelected in State) then begin if (GetFocus = CheckListBox_NowSetting.Handle) then begin Brush.Color := clHighlight; Font.Color := clHighlightText; end else begin Brush.Color := clBtnFace; Font.Color := clBtnText; end; end else begin Brush.Color := CheckListBox_NowSetting.Color; Font.Color := CheckListBox_NowSetting.Font.Color; end; FillRect(Rect); l_ToolButton := G_ToolBar.Buttons[Index]; l_Action := TAction(l_ToolButton.Action); if (l_Action <> nil) and (l_Action.ImageIndex <> -1) then begin G_ActionList.Images.Draw(CheckListBox_NowSetting.Canvas, Rect.Left, Rect.Top + gfniMax([0, (CheckListBox_NowSetting.ItemHeight - G_ActionList.Images.Height) div 2]), l_Action.ImageIndex); Inc(Rect.Left, G_ActionList.Images.Width + G_ciTEXT_MARGIN); end; DrawText(Handle, PChar(F_GetDescription(l_ToolButton)), -1, Rect, DT_SINGLELINE or DT_VCENTER); end; end; //ドラッグ procedure TForm_Custom_ToolBar.CheckListBox_CommandMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); //ドラッグ開始 //オートにすると不都合があるのでマニュアルドラッグ var l_Control: TControl; l_CheckListBox: TCheckListBox; li_Index: Integer; begin if not(Sender is TControl) then Exit; l_Control := TControl(Sender); if (Button = mbLeft) then begin l_Control.BeginDrag(False, GetSystemMetrics(SM_CXDOUBLECLK)); end else if (Button = mbRight) then begin if not(Sender is TCheckListBox) then Exit; l_CheckListBox := TCheckListBox(Sender); if (l_CheckListBox.CanFocus) then begin l_CheckListBox.SetFocus; end; li_Index := l_CheckListBox.ItemAtPos(Point(X, Y), True); if (li_Index >= 0) then begin l_CheckListBox.Selected[li_Index] := True; end; end; end; procedure TForm_Custom_ToolBar.CheckListBox_CommandMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var l_CheckListBox: TCheckListBox; begin if not(Sender is TCheckListBox) then Exit; if (Button <> mbRight) then begin l_CheckListBox := TCheckListBox(Sender); l_CheckListBox.PopupMenu.OnPopup(nil); end; end; procedure TForm_Custom_ToolBar.CheckListBox_CommandDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); //ドラッグ中のマウスカーソルをドラッグ状態にするために必要。 begin Accept := (Source = CheckListBox_NowSetting); end; procedure TForm_Custom_ToolBar.CheckListBox_CommandDragDrop(Sender, Source: TObject; X, Y: Integer); //現在の設定からコマンドリストへドロップ begin if not(Source = CheckListBox_NowSetting) then Exit; //コマンドリストへドロップ = 削除 Action_ToolBar_DeleteExecute(nil); end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); //ドラッグ中のマウスカーソルをドラッグ状態にするために必要。 begin Accept := (Source = CheckListBox_Command) and (Action_ToolBar_Add.Enabled); end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingDragDrop(Sender, Source: TObject; X, Y: Integer); //コマンドリストから現在の設定へドロップ begin if not(Source = CheckListBox_Command) then begin Exit; end; //現在の設定へドロップ = ドロップ位置へ挿入 Action_ToolBar_InsertExecute(nil); end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var l_CheckListBox: TCheckListBox; begin if not(Sender is TCheckListBox) then Exit; l_CheckListBox := TCheckListBox(Sender); case Key of VK_F10: begin if (ssShift in Shift) then begin l_CheckListBox.PopupMenu.Popup(l_CheckListBox.ClientOrigin.X, l_CheckListBox.ClientOrigin.Y); end; Key := 0; end; VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_HOME, VK_END: begin l_CheckListBox.PopupMenu.OnPopup(nil); end; end; end; procedure TForm_Custom_ToolBar.mnuNowSettingPopup(Sender: TObject); //現在の設定メニューをポップアップ //var // l_ToolButton: TToolButton; begin CheckListBox_NowSettingEnter(nil); { if (actToolBar_Delete.Enabled) then begin l_ToolButton := G_MainForm.ToolBar_Main.Buttons[lstNowSetting.ItemIndex]; mniToolBar_Delete.Caption := Format('[%s] をツールバーから削除(&R)', [F_GetDescription(l_ToolButton)]); end else begin mniToolBar_Delete.Caption := '削除(&R)'; end; } end; procedure TForm_Custom_ToolBar.mnuCommandListPopup(Sender: TObject); //コマンドリストメニューをポップアップ begin CheckListBox_CommandEnter(nil); { if (actToolBar_Add.Enabled) then begin mniToolBar_Add.Caption := Format('[%s] をツールバーに追加(&A)', [gfnsCommandDescriptGet(TAction(G_ActionList.Actions[lstCommand.ItemIndex]))]); end else begin mniToolBar_Add.Caption := '追加(&A)'; end; } end; procedure TForm_Custom_ToolBar.CheckListBox_CommandClick(Sender: TObject); var l_Action: TAction; begin if (CheckListBox_Command.ItemIndex >= 0) then begin // l_Action := TAction(G_ActionList.Actions[CheckListBox_Command.ItemIndex]); l_Action := TAction(CheckListBox_Command.Items.Objects[CheckListBox_Command.ItemIndex]); Label_Hint.Caption := G_fnsCommandHintGet(l_Action); end else begin Label_Hint.Caption := ''; end; end; procedure TForm_Custom_ToolBar.CheckListBox_CommandClickCheck(Sender: TObject); var l_Action: TAction; i: Integer; begin // l_Action := TAction(G_ActionList.Actions[CheckListBox_Command.ItemIndex]); l_Action := TAction(CheckListBox_Command.Items.Objects[CheckListBox_Command.ItemIndex]); if (CheckListBox_Command.Checked[CheckListBox_Command.ItemIndex]) or (l_Action.Name = 'actSpc') then begin if (l_Action.Name = 'actSpc') then begin CheckListBox_Command.Checked[l_Action.Index] := False; end; Action_ToolBar_AddExecute(nil); end else begin for i := 0 to G_ToolBar.ButtonCount-1 do begin if (G_ToolBar.Buttons[i].Action = l_Action) then begin G_ToolBar.Buttons[i].Free; CheckListBox_NowSetting.Items.Delete(i); Break; end; end; end; end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingClick(Sender: TObject); var l_ToolButton: TToolButton; begin if (CheckListBox_NowSetting.ItemIndex >= 0) then begin l_ToolButton := G_ToolBar.Buttons[CheckListBox_NowSetting.ItemIndex]; Label_Hint.Caption := F_GetDescription(l_ToolButton); end else begin Label_Hint.Caption := ''; end; end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingClickCheck(Sender: TObject); //現在の設定 begin Action_ToolBar_DeleteExecute(nil); end; //------------------------------------------------------------------------------ procedure TForm_Custom_ToolBar.Action_ToolBar_AddExecute(Sender: TObject); var li_Index: Integer; begin if (CheckListBox_Command.ItemIndex < 0) then begin Exit; end; li_Index := CheckListBox_Command.ItemIndex; if (AppendToolButton(TAction(CheckListBox_Command.Items.Objects[li_Index]))) then begin CheckListBox_NowSetting.Items.Add(''); CheckListBox_NowSetting.Checked[G_ToolBar.ButtonCount-1] := True; CheckListBox_CommandEnter(nil); CheckListBox_Command.Checked[CheckListBox_Command.ItemIndex] := True; end; end; procedure TForm_Custom_ToolBar.Action_ToolBar_InsertExecute(Sender: TObject); var li_Index, li_Insert: Integer; lpt_Pos: TPoint; begin if (CheckListBox_Command.ItemIndex < 0) then Exit; li_Index := CheckListBox_Command.ItemIndex; lpt_Pos := gfnptMousePosGet; li_Insert := CheckListBox_NowSetting.ItemAtPos(CheckListBox_NowSetting.ScreenToClient(lpt_Pos), False); if (li_Insert > -1) then begin if (InsertToolButton(li_Insert, TAction(CheckListBox_Command.Items.Objects[li_Index]))) then begin CheckListBox_NowSetting.Items.Insert(li_Insert, ''); CheckListBox_NowSetting.Checked[li_Insert] := True; CheckListBox_NowSettingEnter(nil); CheckListBox_Command.Checked[CheckListBox_Command.ItemIndex] := True; end; end; end; procedure TForm_Custom_ToolBar.Action_ToolBar_DeleteExecute(Sender: TObject); var i : Integer; li_Index : Integer; l_Action : TAction; begin if (CheckListBox_NowSetting.ItemIndex < 0) then begin Exit; end; li_Index := CheckListBox_NowSetting.ItemIndex; l_Action := TAction(G_MainForm.ToolBar_Main.Buttons[li_Index].Action); if (l_Action <> nil) then begin for i := 0 to CheckListBox_Command.Count -1 do begin if (CheckListBox_Command.Items.Objects[i] = l_Action) then begin CheckListBox_Command.Checked[i] := False; Break; end; end; end; DeleteToolButton(li_Index); CheckListBox_NowSetting.Items.Delete(li_Index); CheckListBox_NowSettingEnter(nil); end; procedure TForm_Custom_ToolBar.Action_ToolBar_ResetAllExecute(Sender: TObject); var i: Integer; l_Action: TAction; begin if (gfniMessageBoxYesNo(G_csCustomToolBar_ResetMessage, G_csAPPTITLE) = ID_YES) then begin ClearToolBar; CheckListBox_NowSetting.Items.Clear; for i := 0 to CheckListBox_Command.Items.Count-1 do begin CheckListBox_Command.Checked[i] := False; end; for i := 0 to G_InitToolBar.Count-1 do begin l_Action := TAction(G_InitToolBar.Items[i]); if (AppendToolButton(l_Action)) then begin CheckListBox_NowSetting.Items.Add(''); CheckListBox_NowSetting.Checked[CheckListBox_NowSetting.Count-1] := True; if (l_Action <> nil) then begin CheckListBox_Command.Checked[l_Action.Index] := True; end; end; end; CheckListBox_NowSettingEnter(nil); end; end; procedure TForm_Custom_ToolBar.Action_ToolBar_MoveUpExecute(Sender: TObject); //上へ移動 var li_FromIndex, li_ToIndex: Integer; l_Action: TAction; begin if (CheckListBox_NowSetting.ItemIndex <= 0) then begin Exit; end; li_FromIndex := CheckListBox_NowSetting.ItemIndex; li_ToIndex := li_FromIndex -1; l_Action := TAction(G_MainForm.ToolBar_Main.Buttons[li_FromIndex].Action); DeleteToolButton(li_FromIndex); InsertToolButton(li_ToIndex, l_Action); CheckListBox_NowSetting.ItemIndex := li_ToIndex; CheckListBox_NowSettingEnter(nil); end; procedure TForm_Custom_ToolBar.Action_ToolBar_MoveDownExecute(Sender: TObject); //下へ移動 var li_FromIndex, li_ToIndex: Integer; l_Action: TAction; begin if (CheckListBox_NowSetting.ItemIndex >= CheckListBox_NowSetting.Items.Count-1) then begin Exit; end; li_FromIndex := CheckListBox_NowSetting.ItemIndex; li_ToIndex := li_FromIndex +1; l_Action := TAction(G_MainForm.ToolBar_Main.Buttons[li_FromIndex].Action); DeleteToolButton(li_FromIndex); InsertToolButton(li_ToIndex, l_Action); CheckListBox_NowSetting.ItemIndex := li_ToIndex; CheckListBox_NowSettingEnter(nil); end; procedure TForm_Custom_ToolBar.CheckListBox_CommandEnter(Sender: TObject); begin //区切りはいつでもTrue Action_ToolBar_Add.Enabled := (CheckListBox_Command.ItemIndex = 0) or ((CheckListBox_Command.ItemIndex > 0) and (CheckListBox_Command.Checked[CheckListBox_Command.ItemIndex] = False)); Action_ToolBar_Delete.Enabled := False; Action_ToolBar_MoveUp.Enabled := False; Action_ToolBar_MoveDown.Enabled := False; end; procedure TForm_Custom_ToolBar.CheckListBox_NowSettingEnter(Sender: TObject); begin Action_ToolBar_Add.Enabled := False; Action_ToolBar_Delete.Enabled := (CheckListBox_NowSetting.ItemIndex >= 0); Action_ToolBar_MoveUp.Enabled := (CheckListBox_NowSetting.ItemIndex >= 1); Action_ToolBar_MoveDown.Enabled := (CheckListBox_NowSetting.ItemIndex >= 0) and (CheckListBox_NowSetting.ItemIndex < CheckListBox_NowSetting.Count-1); end; //============================================================================== procedure F_ListFree(AList: TList); var i: Integer; begin for i := AList.Count-1 downto 0 do begin AList.Delete(i); end; AList.Free; end; initialization G_InitToolBar := TList.Create; finalization F_ListFree(G_InitToolBar); end.