summaryrefslogtreecommitdiff
path: root/extras/tiopf/gui/tiDialogs.pas
blob: 04f4d89695bd2f24519cbf21aa85f3d7d4c85826 (plain)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
unit tiDialogs;

{$mode objfpc}{$H+}

{ TODO: Port tiProcessing and tiEndProcessing }

interface

uses
  Classes,
  SysUtils,
  Variants,
  fpg_base;

  
  // Call showMessage, but accepts a variant. Good for debugging.
  procedure tiShowMessage(const AArray: Array of Const); overload;
  procedure tiShowMessage(const AValue: variant); overload;

  
  // Show the contents of a TStringList - for debugging
  procedure tiShowStringList(const AStringList: TStringList; const AHeading: TfpgString = 'Show string list');
  // Show the contents of a TStrings - for debugging
  procedure tiShowStrings(const AStrings: TStrings; const AHeading: TfpgString = 'Show strings');
  // Show a long string - for debugging
  procedure tiShowString(const AStr: TfpgString; const AHeading: TfpgString = 'Show string');
  // Show a variant array of variants - for debugging
  procedure tiShowVariant(AValue: Variant; AHeading: TfpgString = 'Show variant');
  // Show the contents of a stream
  procedure tiShowStream(const AValue: TStream; const AHeading: TfpgString = 'Show stream');
  // Show a <Yes>, <No> dialog box, and return true if <Yes> was selected
  function tiAppConfirmation(const AMessage: TfpgString; ATitle: TfpgString = ''): boolean; overload;
  function tiAppConfirmation(const AMessage: TfpgString; const AValues: array of const): boolean; overload;
  // Show a message
  procedure tiAppMessage(const AMessage: TfpgString; ATitle: TfpgString = '');
  // Show a warning
  procedure tiAppWarning(const AMessage: TfpgString; ATitle: TfpgString = '');
  // Show a error message
  procedure tiAppError(const AMessage: TfpgString; ATitle: TfpgString = '');

  // A type of notification window that will disappear by it self
  procedure tiProcessing(const AMessage: TfpgString);
  procedure tiEndProcessing;

implementation

uses
  fpg_main,
  fpg_form,
  fpg_memo,
  fpg_label,
  fpg_dialogs,
  fpg_panel,
  tiGUIINI,
  tiUtils;

var
  pWorkingForm: TfpgForm;

type
  TProcessingForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: ProcessingForm}
    Bevel1: TfpgBevel;
    lblMessage: TfpgLabel;
    {@VFD_HEAD_END: ProcessingForm}
  public
    procedure AfterCreate; override;
  end;

{ TProcessingForm }

procedure TProcessingForm.AfterCreate;
begin
  {%region 'Auto-generated GUI code' -fold}
  {@VFD_BODY_BEGIN: ProcessingForm}
  Name := 'ProcessingForm';
  SetPosition(317, 177, 400, 150);
  WindowTitle := 'Processing...';
  WindowPosition := wpScreenCenter;
  BackgroundColor := clHilite1;
  WindowType := wtPopup;

  Bevel1 := TfpgBevel.Create(self);
  with Bevel1 do
  begin
    Name := 'Bevel1';
    SetPosition(8, 4, 232, 80);
    Align := alClient;
  end;

  lblMessage := TfpgLabel.Create(Bevel1);
  with lblMessage do
  begin
    Name := 'lblMessage';
    SetPosition(32, 28, 108, 32);
    Alignment := taCenter;
    FontDesc := '#Label1';
    Hint := '';
    Layout := tlCenter;
    Text := '...';
    WrapText := True;
    Align := alClient;
    MouseCursor := mcHourGlass;
  end;

  {@VFD_BODY_END: ProcessingForm}
  {%endregion}
end;



procedure tiShowMessage(const AArray: array of const);
const
  BoolChars: array[Boolean] of Char = ('F', 'T');
var
  i: Integer;
  lsLine: string;
begin
  lsLine := '';
  for I := 0 to High(AArray) do begin
    if lsLine <> '' then
      lsLine := lsLine + Cr;
    with AArray[i] do
      case VType of
        vtInteger:    lsLine := lsLine + IntToStr(VInteger);
        vtBoolean:    lsLine := lsLine + BoolChars[VBoolean];
        vtChar:       lsLine := lsLine + VChar;
        vtExtended:   lsLine := lsLine + FloatToStr(VExtended^);
        vtString:     lsLine := lsLine + VString^;
        vtPChar:      lsLine := lsLine + VPChar;
        vtObject:     lsLine := lsLine + VObject.ClassName;
        vtClass:      lsLine := lsLine + VClass.ClassName;
        vtAnsiString: lsLine := lsLine + string(VAnsiString);
        vtCurrency:   lsLine := lsLine + CurrToStr(VCurrency^);
        vtVariant:    lsLine := lsLine + string(VVariant^);
        vtInt64:      lsLine := lsLine + IntToStr(VInt64^);
    end;
  end;
  tiShowMessage(lsLine);
end;

procedure tiShowMessage(const AValue: variant);
begin
  ShowMessage(VarToStr(AValue));
end;

procedure tiShowStringList(const AStringList: TStringList; const AHeading: TfpgString);
begin
  tiShowStrings(AStringList, AHeading);
end;

procedure tiShowStrings(const AStrings: TStrings; const AHeading: TfpgString);
var
  lForm: TfpgForm;
  lMemo: TfpgMemo;
begin
  lForm := TfpgForm.Create(nil);
  lMemo := TfpgMemo.Create(lForm);
  try
    lForm.WindowTitle := AHeading;
    lForm.Width       := 300;
    lForm.Height      := 300;
    lForm.WindowPosition := wpScreenCenter;
    lForm.Name        := 'FormShowStrings';
    lMemo.Lines.Assign(AStrings);
    lMemo.FontDesc    := 'Courier New-10';
    gGUIINI.ReadFormState(lForm);
    lMemo.SetPosition(0, 0, lForm.Width, lForm.Height);
    lMemo.Align       := alClient;
    lForm.ShowModal;
    gGUIINI.WriteFormState(lForm);
  finally
    lForm.free;
  end;
end;

procedure tiShowString(const AStr: TfpgString; const AHeading: TfpgString);
var
  lSL: TStringList;
begin
  lSL := TStringList.Create;
  try
    lSL.Text := AStr;
    tiShowStringList(lSL, AHeading);
  finally
    lSL.Free;
  end;
end;

procedure tiShowVariant(AValue: Variant; AHeading: TfpgString);
var
  ls: string;
begin
  ls := tiVariantArrayToString(AValue);
  tiShowString(ls, AHeading);
end;

procedure tiShowStream(const AValue: TStream; const AHeading: TfpgString);
var
  lStringStream: TStringStream;
begin
  lStringStream := TStringStream.Create('');
  try
    AValue.Position := 0;
    lStringStream.CopyFrom(AValue, AValue.Size);
    tiShowString(lStringStream.DataString, AHeading);
  finally
    lStringStream.Free;
  end;
end;

function tiAppConfirmation(const AMessage: TfpgString; ATitle: TfpgString = ''): boolean;
begin
  Result := TfpgMessageDialog.Question(ATitle, AMessage) = mbYes
end;

function tiAppConfirmation(const AMessage: TfpgString;
  const AValues: array of const): boolean;
begin
  Result := tiAppConfirmation(Format(AMessage, AValues));
end;

procedure tiAppMessage(const AMessage: TfpgString; ATitle: TfpgString = '');
begin
  TfpgMessageDialog.Information(ATitle, AMessage);
end;

procedure tiAppWarning(const AMessage: TfpgString; ATitle: TfpgString = '');
begin
  TfpgMessageDialog.Warning(ATitle, AMessage);
end;

procedure tiAppError(const AMessage: TfpgString; ATitle: TfpgString = '');
begin
  TfpgMessageDialog.Critical(ATitle, AMessage);
end;

procedure tiProcessing(const AMessage: TfpgString);
begin
  if not Assigned(pWorkingForm) then
  begin
    pWorkingForm := TProcessingForm.Create(nil);
    TProcessingForm(pWorkingForm).lblMessage.Text := AMessage;
    pWorkingForm.Show;
  end
  else
    TProcessingForm(pWorkingForm).lblMessage.Text := AMessage;
  fpgApplication.ProcessMessages;
end;

procedure tiEndProcessing;
begin
  if Assigned(pWorkingForm) then
    pWorkingForm.Close;
  FreeAndNil(pWorkingForm);
end;

end.