forked from geraldholdsworth/DiscImageManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomDialogueUnit.pas
184 lines (159 loc) · 5.87 KB
/
CustomDialogueUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
unit CustomDialogueUnit;
{
Copyright (C) 2018-2023 Gerald Holdsworth [email protected]
This source is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public Licence as published by the Free
Software Foundation; either version 3 of the Licence, or (at your option)
any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more
details.
A copy of the GNU General Public Licence is available on the World Wide Web
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1335, USA.
}
{$mode objfpc}{$H+}
interface
uses
Classes,SysUtils,Forms,Controls,Graphics,Dialogs,ExtCtrls,StdCtrls,
GJHCustomComponents;
type
{ TCustomDialogue }
TCustomDialogue = class(TForm)
MainBevel: TBevel;
ErrorImg: TImage;
MessageLabel: TLabel;
MessagePanel: TPanel;
QuestionImg: TImage;
InfoImg: TImage;
IgnoreButton,
CancelButton,
OKButton: TGJHButton;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure ShowError(msg,BtnTxt: String);
procedure ShowConfirm(msg,OKBtnTxt,CancelBtnTxt,IgnoreBtnTxt: String);
procedure ShowInfo(msg,BtnTxt: String);
procedure ShowDialogue(msg,OKBtnTxt,CancelBtnTxt,IgnoreBtnTxt: String;style: Byte);
private
public
end;
var
CustomDialogue: TCustomDialogue;
implementation
{$R *.lfm}
uses MainUnit;
{ TCustomDialogue }
{------------------------------------------------------------------------------}
//Tile the window
{------------------------------------------------------------------------------}
procedure TCustomDialogue.FormPaint(Sender: TObject);
begin
MainForm.FileInfoPanelPaint(Sender);
end;
{------------------------------------------------------------------------------}
//Create the buttons and move things around for scaling
{------------------------------------------------------------------------------}
procedure TCustomDialogue.FormCreate(Sender: TObject);
var
ratio: Real;
begin
ratio:=PixelsPerInch/DesignTimePPI;
//Set width: buttons width + gap either side + gap between buttons
Width:=Round((120*3+8*4)*ratio);
MainBevel.Width:=Width;
MessagePanel.Width:=Width-MessagePanel.Left-Round(8*ratio);
//Create the buttons
IgnoreButton:=MainForm.CreateButton(CustomDialogue as TControl,'Ignore',False,
Round(8*ratio),
MainBevel.Top+MainBevel.Height+Round(12*ratio),
mrIgnore);
CancelButton:=MainForm.CreateButton(CustomDialogue as TControl,'Cancel',False,
0,MainBevel.Top+MainBevel.Height+Round(12*ratio),
mrCancel);
CancelButton.Left:=(Width-CancelButton.Width)div 2;
OKButton:=MainForm.CreateButton(CustomDialogue as TControl,'OK',True,0,
MainBevel.Top+MainBevel.Height+Round(8*ratio),
mrOK);
OKButton.Left:=Width-OKButton.Width-Round(8*ratio);
//Adjust the form height
Height:=OKButton.Top+OKButton.Height+Round(8*ratio);
end;
{------------------------------------------------------------------------------}
//Show an error message
{------------------------------------------------------------------------------}
procedure TCustomDialogue.ShowError(msg,BtnTxt: String);
begin
ShowDialogue(msg,BtnTxt,'','',0);
end;
{------------------------------------------------------------------------------}
//Ask the user for a confirmation
{------------------------------------------------------------------------------}
procedure TCustomDialogue.ShowConfirm(msg,OKBtnTxt,CancelBtnTxt,IgnoreBtnTxt: String);
begin
ShowDialogue(msg,OKBtnTxt,CancelBtnTxt,IgnoreBtnTxt,2);
end;
{------------------------------------------------------------------------------}
//Show information
{------------------------------------------------------------------------------}
procedure TCustomDialogue.ShowInfo(msg,BtnTxt: String);
begin
ShowDialogue(msg,BtnTxt,'','',1);
end;
{------------------------------------------------------------------------------}
//General display procedure
{------------------------------------------------------------------------------}
procedure TCustomDialogue.ShowDialogue(msg,OKBtnTxt,CancelBtnTxt,IgnoreBtnTxt: String
;style: Byte);
begin
if style>2 then exit;
//We need to briefly show the form so the controls resize
Show;
//Hide all the graphics
ErrorImg.Visible :=False;
InfoImg.Visible :=False;
QuestionImg.Visible:=False;
//Now show the appropriate one
case style of
0: ErrorImg.Visible :=True;
1: InfoImg.Visible :=True;
2: QuestionImg.Visible:=True;
end;
MessageLabel.Caption:='';
MessageLabel.Constraints.MaxWidth:=MessagePanel.ClientWidth;
MessageLabel.Constraints.MaxHeight:=MessagePanel.ClientHeight;
//Display the message
MessageLabel.Caption:=msg;
//And reposition it
MessageLabel.Left:=(MessagePanel.Width-MessageLabel.Width)div 2;
MessageLabel.Top:=(MessagePanel.Height-MessageLabel.Height)div 2;
//Label the default button
if OKBtnTxt='' then OKBtnTxt:='OK';
OKButton.Caption:=OKBtnTxt;
//Label the cancel button, and then show or hide it
if CancelBtnTxt='' then CancelButton.Visible:=False
else
begin
CancelButton.Visible:=True;
CancelButton.Caption:=CancelBtnTxt;
end;
//Label the ignore button, and then show or hide it
if IgnoreBtnTxt='' then IgnoreButton.Visible:=False
else
begin
IgnoreButton.Visible:=True;
IgnoreButton.Caption:=IgnoreBtnTxt;
end;
//Change the title
case style of
0: Caption:='Error';
1: Caption:='Information';
2: Caption:='Confirmation';
end;
//Now hide it before we show it as a modal
Hide;
ShowModal;
end;
end.