unit custom_base; //{$DEFINE DEBUG} interface uses Windows, ActnList, Buttons, Classes, ComCtrls, Controls, ExtCtrls, Forms, Menus, Messages, StdCtrls, SysUtils, Graphics, Dialogs, myFileDialog, Grids, myEdit, myListBox, myShape; type T_ResetData = record bDisp_InfoPanel, bDisp_TimeVerbose: Boolean; bOpt_OpenOriginalSize, bOpt_Random, bOpt_Resume, bOpt_AllowDuplication, bOpt_AllowScreenSaver: Boolean; end; TApp_CustomBaseForm = class(TForm) PageControl1: TPageControl; tabOpt: TTabSheet; tabMenu: TTabSheet; tabToolBar: TTabSheet; tabShortCut: TTabSheet; tabHelp: TTabSheet; dlgAllowExt: TMyOpenFileDialog; mnuAllowExt: TPopupMenu; mniAllowExt_Sel: TMenuItem; mniAllowExt_Add: TMenuItem; mniAllowExt_Del: TMenuItem; mniAllowExt_Line1: TMenuItem; mniAllowExt_Reset: TMenuItem; grpOption: TGroupBox; chkOpt_OpenOriginaSize: TCheckBox; chkOpt_Random: TCheckBox; chkOpt_Resume: TCheckBox; chkOpt_AllowDuplication: TCheckBox; chkOpt_AllowScreenSaver: TCheckBox; grpAllowExt: TGroupBox; shpAllowExt: TMyShape; chkOpt_AllowExt: TCheckBox; btnAllowExt_Add: TButton; btnAllowExt_Del: TButton; btnAllowExt_Reset: TButton; lstAllowExt: TMyListBox; edtAllowExt: TMyEdit; btnAllowExt_Sel: TButton; pnlCmd: TPanel; btnClose: TButton; btnReset: TButton; chkDisp_InfoPanel: TCheckBox; chkDisp_TimeVerbose: TCheckBox; ActionList1: TActionList; actFile_Close: TAction; actSetting_Reset: TAction; actAllowExt_Sel: TAction; actAllowExt_Add: TAction; actAllowExt_Del: TAction; actAllowExt_Reset: TAction; 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 PageControl1Changing(Sender: TObject; var AllowChange: Boolean); procedure actDisp_ResetAllExecute(Sender: TObject); procedure actOpt_ResetAllExecute(Sender: TObject); procedure actAllowExt_SelExecute(Sender: TObject); procedure actAllowExt_AddExecute(Sender: TObject); procedure actAllowExt_DelExecute(Sender: TObject); procedure actAllowExt_ResetExecute(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private 宣言 } F_InitData: T_ResetData; F_slResetExt: TStrings; public { Public 宣言 } procedure SetTabSheet(ATabSheet: TTabSheet); end; //------------------------------------------------------------------------------ procedure gpcCreateCustomBaseForm(AOwner: TComponent); procedure gpcSetTabSheet(sTabSheet: String); var App_CustomBaseForm: TApp_CustomBaseForm; G_CustomForm: TApp_CustomBaseForm; //============================================================================== implementation uses {$IFDEF DEBUG} myDebug, {$ENDIF} myControl, myFile, myList, myMessageBox, myMonitor, // myMultiMonitor, mySearch, myString, myWindow, main, custom_menu, custom_toolbar, custom_shortcut, custom_help; {$R *.dfm} //============================================================================== procedure gpcCreateCustomBaseForm(AOwner: TComponent); var i: Integer; begin if (App_CustomBaseForm = nil) then begin App_CustomBaseForm := TApp_CustomBaseForm.Create(AOwner); end else begin for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] = App_CustomBaseForm) then begin Exit; end; end; App_CustomBaseForm := TApp_CustomBaseForm.Create(AOwner); end; end; procedure gpcSetTabSheet(sTabSheet: String); begin gpcCreateCustomBaseForm(G_MainForm); sTabSheet := UpperCase(sTabSheet); if (sTabSheet = 'OPTION') then begin App_CustomBaseForm.SetTabSheet(App_CustomBaseForm.tabOpt); end else if (sTabSheet = 'MENU') then begin App_CustomBaseForm.SetTabSheet(App_CustomBaseForm.tabMenu); end else if (sTabSheet = 'TOOLBAR') then begin App_CustomBaseForm.SetTabSheet(App_CustomBaseForm.tabToolBar); end else if (sTabSheet = 'SHORTCUT') then begin App_CustomBaseForm.SetTabSheet(App_CustomBaseForm.tabShortCut); end else if (sTabSheet = 'HELP') then begin App_CustomBaseForm.SetTabSheet(App_CustomBaseForm.tabHelp); end; end; //============================================================================== procedure TApp_CustomBaseForm.FormCreate(Sender: TObject); procedure _CaptionTrim(Sender: TWinControl); //Captionのアクセラレータ以降を取り除く //+メニューアイコンのImageへのセット var i: Integer; l_Control : TControl; l_RadioButton : TRadioButton; l_CheckBox : TCheckBox; begin for i := 0 to Sender.ControlCount -1 do begin if (Sender.Controls[i] is TWinControl) then begin l_Control := TControl(Sender.Controls[i]); if (l_Control is TRadioButton) or (l_Control is TCheckBox) then begin if (l_Control is TRadioButton) then begin l_RadioButton := TRadioButton(l_Control); l_RadioButton.Caption := StripHotKey(l_RadioButton.Caption); end else if (l_Control is TCheckBox) then begin l_CheckBox := TCheckBox(l_Control); l_CheckBox.Caption := StripHotKey(l_CheckBox.Caption); end; end; end; end; end; var lh_Menu : hMenu; begin G_CustomForm := Self; Self.Icon := Application.Icon; //デフォルトはマウスカーソルのあるモニターの真ん中に gpcMonitorCenterPosSet(Self); //メニュー 最大化、最小化は必要ないので消去 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); PageControl1.Align := alClient; PageControl1.ActivePage := tabOpt; F_slResetExt := TStringList.Create; F_slResetExt.Assign(G_MainForm.plyMedia.AllowExt); lstAllowExt.Items.Assign(F_slResetExt); with G_MainForm do begin //表示 F_InitData.bDisp_InfoPanel := actDisp_InfoPanel.Checked; F_InitData.bDisp_TimeVerbose := actDisp_TimeVerbose.Checked; //オプション F_InitData.bOpt_OpenOriginalSize := actOpt_OpenOriginalSize.Checked; F_InitData.bOpt_Random := actOpt_Random.Checked; F_InitData.bOpt_Resume := actOpt_Resume.Checked; F_InitData.bOpt_AllowDuplication := actOpt_AllowDuplication.Checked; F_InitData.bOpt_AllowScreenSaver := actOpt_AllowScreenSaver.Checked; end; _CaptionTrim(grpOption); _CaptionTrim(grpAllowExt); // _CaptionTrim(grpSearchSite); Tag := 1; end; procedure TApp_CustomBaseForm.FormDestroy(Sender: TObject); begin F_slResetExt.Free; end; procedure TApp_CustomBaseForm.actFile_CloseExecute(Sender: TObject); begin Close; end; procedure TApp_CustomBaseForm.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_CustomBaseForm.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); begin gpcCreateMenuForm; gpcCreateToolBarForm(Self); gpcCreateShortCutForm; gpcCreateHelpForm; end; procedure TApp_CustomBaseForm.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 = tabToolBar) then begin l_Form := App_CustomToolBar; end else if (ActivePage = tabShortCut) then begin l_Form := App_CustomShortCut; 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_CustomBaseForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var l_Form: TForm; begin // l_Form := nil; with (PageControl1) do begin if (ActivePage = tabToolBar) then begin l_Form := App_CustomToolBar; end else if (ActivePage = tabShortCut) then begin l_Form := App_CustomShortCut; 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; procedure TApp_CustomBaseForm.actDisp_ResetAllExecute(Sender: TObject); begin //表示設定の初期化 if (gfniMessageBoxYesNo('表示設定の設定値をリセットします。よろしいですか', G_csAPPTITLE + ' - 確認') = ID_YES) then begin with G_MainForm do begin //表示 actDisp_InfoPanel.Checked := F_InitData.bDisp_InfoPanel; actDisp_InfoPanel.OnExecute(nil); actDisp_TimeVerbose.Checked := F_InitData.bDisp_TimeVerbose; actDisp_TimeVerbose.OnExecute(nil); end; end; end; procedure TApp_CustomBaseForm.actOpt_ResetAllExecute(Sender: TObject); begin //オプション設定の初期化 if (gfniMessageBoxYesNo('オプション設定の設定値をリセットします。よろしいですか', G_csAPPTITLE + ' - 確認') = ID_YES) then begin with G_MainForm do begin //オプション actOpt_OpenOriginalSize.Checked := F_InitData.bOpt_OpenOriginalSize; actOpt_Random.Checked := F_InitData.bOpt_Random; actOpt_Random.OnExecute(nil); actOpt_Resume.Checked := F_InitData.bOpt_Resume; actOpt_AllowDuplication.Checked := F_InitData.bOpt_AllowDuplication; actOpt_AllowDuplication.OnExecute(nil); actOpt_AllowScreenSaver.Checked := F_InitData.bOpt_AllowScreenSaver; end; end; end; procedure TApp_CustomBaseForm.actAllowExt_SelExecute(Sender: TObject); //選択 var ls_Ext : String; begin if (dlgAllowExt.Execute) then begin dlgAllowExt.InitialDir := gfnsFilePathGet(dlgAllowExt.FileName); ls_Ext := gfnsFileExtGet(dlgAllowExt.FileName); if (gfnbIsIncludeList(ls_Ext, G_MainForm.DefDisallowExtList)) then begin gpcShowMessage('この拡張子は追加できません'); Exit; end; lstAllowExt.Items.Add(ls_Ext); G_MainForm.actOpt_AllowExtExecute(nil); end; end; procedure TApp_CustomBaseForm.actAllowExt_AddExecute(Sender: TObject); //追加 var ls_Ext : String; begin if (edtAllowExt.Text <> '') then begin ls_Ext := gfnsStrHeadFit(edtAllowExt.Text, '.'); if (gfnbIsIncludeList(ls_Ext, G_MainForm.DefDisAllowExtList)) then begin gpcShowMessage('この拡張子は追加できません'); Exit; end; lstAllowExt.Items.Add(ls_Ext); G_MainForm.actOpt_AllowExtExecute(nil); end; end; procedure TApp_CustomBaseForm.actAllowExt_DelExecute(Sender: TObject); //削除 var i: Integer; begin if (gfnbIsIncludeList(lstAllowExt.Items[lstAllowExt.ItemIndex], G_MainForm.DefAllowExtList)) then begin gpcShowMessage('この拡張子は削除できません'); Exit; end; if not(gfniMessageBoxYesNo(WideFormat('%sを拡張子限定リストから削除します'#13'よろしいですか', [lstAllowExt.Items[lstAllowExt.ItemIndex]])) = ID_YES) then begin Exit; end; if (lstAllowExt.ItemIndex >= 0) then begin lstAllowExt.Items.BeginUpdate; try for i := lstAllowExt.Items.Count-1 downto 0 do begin if (lstAllowExt.Selected[i]) then begin lstAllowExt.Items.Delete(lstAllowExt.ItemIndex); end; end; finally lstAllowExt.Items.EndUpdate; end; G_MainForm.actOpt_AllowExtExecute(nil); end; end; procedure TApp_CustomBaseForm.actAllowExt_ResetExecute(Sender: TObject); //リセット begin //拡張子の初期化 if (gfniMessageBoxYesNo('拡張子のリストをリセットします。よろしいですか', G_csAPPTITLE) = ID_YES) then begin lstAllowExt.Items.Assign(F_slResetExt); G_MainForm.actOpt_AllowExtExecute(nil); end; end; end.