unit custom_base; //{$DEFINE _DEBUG} interface uses Windows, ActnList, Buttons, Classes, ComCtrls, Controls, ExtCtrls, Forms, Menus, Messages, StdCtrls, SysUtils, Graphics; type TApp_BugsEyeCustom = class(TForm) ActionList1: TActionList; actFile_Close: TAction; PageControl1: TPageControl; TabSheet_Option: TTabSheet; tabCopy: TTabSheet; tabToolBar: TTabSheet; tabShortCut: TTabSheet; tabHelp: TTabSheet; tabMenu: TTabSheet; StatusBar1: TStatusBar; procedure actFile_CloseExecute(Sender: TObject); procedure FormCreate (Sender: TObject); procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure FormKeyUp (Sender: TObject; var Key: Word; Shift: TShiftState); procedure PageControl1Change(Sender: TObject); private { Private 宣言 } procedure FSetHighDPIControlHeight; public { Public 宣言 } procedure SetTabSheet(ATabSheet: TTabSheet); end; //------------------------------------------------------------------------------ procedure G_pcCreateCustomBaseForm; procedure G_pcSetTabSheet(ATabSheet: TTabSheet); procedure G_pcControlFontSet(AFont: TFont; AMenuItem: TMenuItem); //procedure G_pcControlFontSet(ACheckBox: TCheckBox; AMenuItem: TMenuItem); procedure G_TrimCaption(Sender: TWinControl); var App_BugsEyeCustom :TApp_BugsEyeCustom; G_CustomForm :TApp_BugsEyeCustom; //============================================================================== implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} {$IFDEF MYLIB} myControl, myMonitor, myMultiMonitor, myWindow, {$ELSE} my_monitor, general, {$ENDIF} main, highDPIUnit, common, custom_setting, custom_menu, custom_toolbar, custom_shortcut, custom_copy, custom_help; {$R *.dfm} //============================================================================== procedure G_pcCreateCustomBaseForm; procedure _CreateForm; begin App_BugsEyeCustom := TApp_BugsEyeCustom.Create(G_MainForm); end; var i: Integer; begin if (App_BugsEyeCustom = nil) then begin _CreateForm; end else begin for i := 0 to Screen.FormCount -1 do begin if (Screen.Forms[i] = App_BugsEyeCustom) then begin Exit; end; end; _CreateForm; end; end; procedure G_pcSetTabSheet(ATabSheet: TTabSheet); begin G_pcCreateCustomBaseForm; App_BugsEyeCustom.SetTabSheet(ATabSheet); end; procedure G_pcControlFontSet(AFont: TFont; AMenuItem: TMenuItem); begin if (AMenuItem <> nil) then begin if (AMenuItem.Visible) then begin // AFont.Color := clWindowText; // AFont.Style := AFont.Style - [fsUnderLine]; // AFont.Style := AFont.Style - [fsItalic]; end else begin // AFont.Color := clGrayText; // AFont.Style := AFont.Style + [fsUnderLine]; // AFont.Style := AFont.Style + [fsItalic]; end; end; end; procedure G_TrimCaption(Sender: TWinControl); //Captionのアクセラレータ以降を取り除く。 //プラス、チェックボックスのアクション関連の問題点へ対処。 function _GetAction(AControl: TControl): TAction; begin Result := TAction(G_MainForm.FindComponent(gfnsFindComponentNameGet('Action', AControl.Name))); end; procedure _SetAction(AControl: TControl; AAction: TAction); begin if (AAction <> nil) and (AControl <> nil) and (AControl.Action = nil) then begin { if (AAction = nil) then begin myDebug.gpcDebug(AControl.Name); end; } //チェックボックスのアクション関連の問題点へ対処。 //アクションをセットする前にチェック状態をセットすること。 if (AControl is TRadioButton) then begin TRadioButton(AControl).Checked := AAction.Checked; end else if (AControl is TCheckBox) then begin TCheckBox(AControl).Checked := AAction.Checked; end; AControl.Action := AAction; end; end; function _GetMenuItem(AControl: TControl): TMenuItem; begin Result := TMenuItem(G_MainForm.FindComponent(gfnsFindComponentNameGet('MenuItem', AControl.Name))); { if (Result = nil) then begin myDebug.gpcDebug(AControl.Name); end; } end; var i: Integer; l_Control : TControl; l_RadioButton : TRadioButton; l_CheckBox : TCheckBox; l_Button : TButton; l_Action : TAction; l_MenuItem : TMenuItem; begin for i := 0 to Sender.ComponentCount -1 do begin if (Sender.Components[i] is TWinControl) then begin l_Control := TControl(Sender.Components[i]); if (l_Control is TRadioButton) or (l_Control is TCheckBox) or (l_Control is TButton) then begin l_MenuItem := _GetMenuItem(l_Control); l_Action := _GetAction(l_Control); _SetAction(l_Control, l_Action); if (l_Control is TRadioButton) then begin l_RadioButton := TRadioButton(l_Control); G_pcControlFontSet(l_RadioButton.Font, l_MenuItem); l_RadioButton.Caption := StripHotKey(l_RadioButton.Caption); end else if (l_Control is TCheckBox) then begin l_CheckBox := TCheckBox(l_Control); G_pcControlFontSet(l_CheckBox.Font, l_MenuItem); l_CheckBox.Caption := StripHotKey(l_CheckBox.Caption); end else if (l_Control is TButton) then begin l_Button := TButton(l_Control); G_pcControlFontSet(l_Button.Font, l_MenuItem); l_Button.Caption := StripHotKey(l_Button.Caption); end; end; end; end; end; //============================================================================== procedure TApp_BugsEyeCustom.FSetHighDPIControlHeight; begin //高DPI対応 gpcStatusBarHeightSet(StatusBar1); end; procedure TApp_BugsEyeCustom.FormCreate(Sender: TObject); var lh_Menu : hMenu; lrc_Rect : TRect; begin G_CustomForm := Self; Self.ClientWidth := PageControl1.Width; Self.ClientHeight := PageControl1.Height + StatusBar1.Height; //デフォルトは真ん中に lrc_Rect := gfnrcMonitorRectGet(gfnptMousePosGet); SetBounds((gfniRectWidth(lrc_Rect) - Width) div 2, (gfniRectHeight(lrc_Rect) - Height) div 2, Width, Height); //メニュー 最大化、最小化は必要ないので消去 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); //最大化 DeleteMenu(lh_Menu, 2, MF_BYPOSITION); //区切り線 DrawMenuBar(lh_Menu); //高DPI環境対応 FSetHighDPIControlHeight; PageControl1.Align := alClient; PageControl1.ActivePage := TabSheet_Option; end; procedure TApp_BugsEyeCustom.actFile_CloseExecute(Sender: TObject); begin Close; end; procedure TApp_BugsEyeCustom.SetTabSheet(ATabSheet: TTabSheet); begin if (ATabSheet = nil) then begin Exit; end; PageControl1.ActivePage := ATabSheet; if (Self.Visible) and (Self.Enabled) and (Self.CanFocus) then begin Self.SetFocus; end else begin Self.Show; end; end; procedure TApp_BugsEyeCustom.PageControl1Change(Sender: TObject); begin case PageControl1.TabIndex of 0: G_pcCreateSettingForm; // 0: G_MainForm.Action_Custom_SettingExecute(nil); 1: G_pcCreateMenuForm; 2: G_pcCreateToolBarForm; 3: G_pcCreateShortCutForm; 4: G_pcCreateCopyForm; 5: G_pcCreateHelpForm; end; end; procedure TApp_BugsEyeCustom.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); var l_Form: TForm; begin l_Form := nil; with (PageControl1) do begin if (ActivePage = tabCopy) then begin l_Form := Form_Custom_Copy; end else if (ActivePage = tabToolBar) then begin l_Form := Form_Custom_ToolBar; end else if (ActivePage = tabShortCut) then begin l_Form := Form_Custom_ShortCut; end else if (ActivePage = tabHelp) then begin l_Form := G_HelpForm; end; end; if (l_Form <> nil) and (@l_Form.OnMouseWheel <> nil) then begin l_Form.OnMouseWheel(Sender, Shift, WheelDelta, MousePos, Handled); end; end; procedure TApp_BugsEyeCustom.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var l_Form: TForm; begin // l_Form := nil; with (PageControl1) do begin if (ActivePage = tabCopy) then begin l_Form := Form_Custom_Copy; end else if (ActivePage = tabToolBar) then begin l_Form := Form_Custom_ToolBar; end else if (ActivePage = tabShortCut) then begin l_Form := Form_Custom_ShortCut; end else if (ActivePage = tabHelp) then begin l_Form := G_HelpForm; end; end; if (l_Form <> nil) and (@l_Form.OnKeyUp <> nil) then begin l_Form.OnKeyUp(Sender, Key, Shift); end; end; end.