Menu

[r3166]: / trunk / Src / FrDisplayPrefs.pas  Maximize  Restore  History

Download this file

343 lines (308 with data), 11.4 kB

  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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2012-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a frame that allows user to set application display preferences.
* Designed for use as one of the tabs in the preferences dialog box.
}
unit FrDisplayPrefs;
interface
uses
// Delphi
Controls, StdCtrls, Classes,
// Project
FrPrefsBase, UColorBoxEx, UColorDialogEx, UPreferences;
type
TDisplayPrefsFrame = class(TPrefsBaseFrame)
lblOverviewTree: TLabel;
cbOverviewTree: TComboBox;
chkHideEmptySections: TCheckBox;
chkSnippetsInNewTab: TCheckBox;
lblMainColour: TLabel;
lblUserColour: TLabel;
btnDefColours: TButton;
lblSourceBGColour: TLabel;
procedure chkHideEmptySectionsClick(Sender: TObject);
procedure btnDefColoursClick(Sender: TObject);
strict private
var
/// <summary>Flag indicating if changes affect UI.</summary>
fUIChanged: Boolean;
fMainColourBox: TColorBoxEx;
fMainColourDlg: TColorDialogEx;
fUserColourBox: TColorBoxEx;
fUserColourDlg: TColorDialogEx;
fSourceBGColourBox: TColorBoxEx;
fSourceBGColourDlg: TColorDialogEx;
procedure SelectOverviewTreeState(const State: TOverviewStartState);
{Selects combo box item associated with a overview treeview startup state.
@param State [in] Startup state to be selected.
}
function OverviewTreeStateDesc(const State: TOverviewStartState): string;
{Gets description of an overview treeview startup state.
@param State [in] State for which description is required.
@return Required description.
}
function CreateCustomColourBox(const ColourDlg: TColorDialogEx):
TColorBoxEx;
procedure ColourBoxChangeHandler(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
{Class constructor. Sets up frame and populates controls.
@param AOwner [in] Component that owns frame.
}
procedure Activate(const Prefs: IPreferences); override;
{Called when page activated. Updates controls.
@param Prefs [in] Object that provides info used to update controls.
}
procedure Deactivate(const Prefs: IPreferences); override;
{Called when page is deactivated. Stores information entered by user.
@param Prefs [in] Object used to store information.
}
/// <summary>Checks if preference changes require that main window UI is
/// updated.</summary>
/// <remarks>Called when dialog box containing frame is closing.</remarks>
function UIUpdated: Boolean; override;
procedure ArrangeControls; override;
{Arranges controls on frame. Called after frame has been sized.
}
function DisplayName: string; override;
{Caption that is displayed in the tab sheet that contains this frame when
displayed in the preference dialog box.
@return Required display name.
}
class function Index: Byte; override;
{Index number that determines the location of the tab containing this
frame when displayed in the preferences dialog box.
@return Required index number.
}
end;
implementation
uses
// Delphi
Math, Graphics, ExtCtrls,
// Project
FmPreferencesDlg, UColours, UCtrlArranger, UGraphicUtils;
{$R *.dfm}
{ TDisplayPrefsFrame }
procedure TDisplayPrefsFrame.Activate(const Prefs: IPreferences);
{Called when page activated. Updates controls.
@param Prefs [in] Object that provides info used to update controls.
}
begin
SelectOverviewTreeState(Prefs.OverviewStartState);
chkHideEmptySections.OnClick := nil; // prevent OnClick when Checked set
chkHideEmptySections.Checked := not Prefs.ShowEmptySections;
chkHideEmptySections.OnClick := chkHideEmptySectionsClick;
chkSnippetsInNewTab.Checked := Prefs.ShowNewSnippetsInNewTabs;
fMainColourBox.Selected := Prefs.DBHeadingColours[False];
fUserColourBox.Selected := Prefs.DBHeadingColours[True];
fSourceBGColourBox.Selected := Prefs.SourceCodeBGcolour;
Prefs.DBHeadingCustomColours[False].CopyTo(fMainColourDlg.CustomColors, True);
Prefs.DBHeadingCustomColours[True].CopyTo(fUserColourDlg.CustomColors, True);
Prefs.SourceCodeBGCustomColours.CopyTo(fSourceBGColourDlg.CustomColors, True);
end;
procedure TDisplayPrefsFrame.ArrangeControls;
{Arranges controls on frame. Called after frame has been sized.
}
begin
TCtrlArranger.AlignLefts(
[
lblOverviewTree, chkHideEmptySections, chkSnippetsInNewTab,
lblMainColour, lblUserColour, lblSourceBGColour, btnDefColours
],
0
);
TCtrlArranger.AlignLefts(
[cbOverviewTree, fMainColourBox, fUserColourBox, fSourceBGColourBox],
TCtrlArranger.RightOf(
[lblOverviewTree, lblMainColour, lblUserColour, lblSourceBGColour],
8
)
);
TCtrlArranger.AlignVCentres(0, [lblOverviewTree, cbOverviewTree]);
TCtrlArranger.MoveBelow(
[lblOverviewTree, cbOverviewTree], chkSnippetsInNewTab, 24
);
TCtrlArranger.MoveBelow(chkSnippetsInNewTab, chkHideEmptySections, 8);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf(chkHideEmptySections, 24),
[lblMainColour, fMainColourBox]
);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf([lblMainColour, fMainColourBox], 8),
[lblUserColour, fUserColourBox]
);
TCtrlArranger.AlignVCentres(
TCtrlArranger.BottomOf([lblUserColour, fUserColourBox], 8),
[lblSourceBGColour, fSourceBGColourBox]
);
TCtrlArranger.MoveBelow(
[lblSourceBGColour, fSourceBGColourBox], btnDefColours, 12
);
chkHideEmptySections.Width := Self.Width - 16;
chkSnippetsInNewTab.Width := Self.Width - 16;
end;
procedure TDisplayPrefsFrame.btnDefColoursClick(Sender: TObject);
begin
// Restores default heading and source code background colours in colour
// combo boxes
fMainColourBox.Selected := clMainSnippet;
fUserColourBox.Selected := clUserSnippet;
fSourceBGColourBox.Selected := clSourceBg;
fUIChanged := True;
end;
procedure TDisplayPrefsFrame.chkHideEmptySectionsClick(Sender: TObject);
{Handles clicks on "Hide Empty Sections" check box. Flags UI preferences has
having changed.
@param Sender [in] Ignored.
}
begin
fUIChanged := True;
end;
procedure TDisplayPrefsFrame.ColourBoxChangeHandler(Sender: TObject);
begin
fUIChanged := True;
end;
constructor TDisplayPrefsFrame.Create(AOwner: TComponent);
{Class constructor. Sets up frame and populates controls.
@param AOwner [in] Component that owns frame.
}
resourcestring
sHeadingColourDlgTitle = 'Heading Colour';
sSourceBGColourDlgTitle = 'Source Code Background Colour';
var
OTStateIdx: TOverviewStartState; // loops thru each overview tree start state
begin
inherited;
HelpKeyword := 'DisplayPrefs';
// Populate overview tree start state
for OTStateIdx := Low(TOverviewStartState) to High(TOverviewStartState) do
cbOverviewTree.Items.AddObject(
OverviewTreeStateDesc(OTStateIdx), TObject(OTStateIdx)
);
// Create colour dialogue boxes
fMainColourDlg := TColorDialogEx.Create(Self);
fMainColourDlg.Title := sHeadingColourDlgTitle;
fUserColourDlg := TColorDialogEx.Create(Self);
fUserColourDlg.Title := sHeadingColourDlgTitle;
fSourceBGColourDlg := TColorDialogEx.Create(Self);
fSourceBGColourDlg.Title := sSourceBGColourDlgTitle;
// Create colour combo boxes
fMainColourBox := CreateCustomColourBox(fMainColourDlg);
fMainColourBox.TabOrder := 3;
lblMainColour.FocusControl := fMainColourBox;
fUserColourBox := CreateCustomColourBox(fUserColourDlg);
fUserColourBox.TabOrder := 4;
lblUserColour.FocusControl := fUserColourBox;
fSourceBGColourBox := CreateCustomColourBox(fSourceBGColourDlg);
fSourceBGColourBox.TabOrder := 5;
lblSourceBGColour.FocusControl := fSourceBGColourBox;
end;
function TDisplayPrefsFrame.CreateCustomColourBox(
const ColourDlg: TColorDialogEx): TColorBoxEx;
begin
// Create and initialise custom color combo box
Result := TColorBoxEx.Create(Self); // automatically freed
Result.Parent := Self;
Result.Width := 137;
Result.Height := 22;
// cbCustomColor not included in Style since assigning ColorDialog property
// sets this style
Result.Style := [cbStandardColors, cbExtendedColors, cbSystemColors,
cbPrettyNames];
Result.ItemHeight := 16;
if Assigned(ColourDlg) then
Result.ColorDialog := ColourDlg;
Result.OnChange := ColourBoxChangeHandler;
end;
procedure TDisplayPrefsFrame.Deactivate(const Prefs: IPreferences);
{Called when page is deactivated. Stores information entered by user.
@param Prefs [in] Object used to store information.
}
begin
Prefs.ShowNewSnippetsInNewTabs := chkSnippetsInNewTab.Checked;
Prefs.ShowEmptySections := not chkHideEmptySections.Checked;
Prefs.OverviewStartState := TOverviewStartState(
cbOverviewTree.Items.Objects[cbOverviewTree.ItemIndex]
);
Prefs.DBHeadingColours[False] := fMainColourBox.Selected;
Prefs.DBHeadingColours[True] := fUserColourBox.Selected;
Prefs.SourceCodeBGcolour := fSourceBGColourBox.Selected;
Prefs.DBHeadingCustomColours[False].CopyFrom(
fMainColourDlg.CustomColors, True
);
Prefs.DBHeadingCustomColours[True].CopyFrom(
fUserColourDlg.CustomColors, True
);
Prefs.SourceCodeBGCustomColours.CopyFrom(
fSourceBGColourDlg.CustomColors, True
);
end;
function TDisplayPrefsFrame.DisplayName: string;
{Caption that is displayed in the tab sheet that contains this frame when
displayed in the preference dialog box.
@return Required display name.
}
resourcestring
sDisplayName = 'Display'; // display name
begin
Result := sDisplayName;
end;
class function TDisplayPrefsFrame.Index: Byte;
{Index number that determines the location of the tab containing this frame
when displayed in the preferences dialog box.
@return Required index number.
}
begin
Result := 10;
end;
function TDisplayPrefsFrame.OverviewTreeStateDesc(
const State: TOverviewStartState): string;
{Gets description of an overview treeview startup state.
@param State [in] State for which description is required.
@return Required description.
}
resourcestring
// Startup state descriptions
sOTSExpanded = 'Fully expanded';
sOTSCollapsed = 'Fully collapsed';
const
// Map of overview tree start states to descriptions
cOTSStartStates: array[TOverviewStartState] of string = (
sOTSExpanded, sOTSCollapsed
);
begin
Result := cOTSStartStates[State];
end;
procedure TDisplayPrefsFrame.SelectOverviewTreeState(
const State: TOverviewStartState);
{Selects combo box item associated with a overview treeview startup state.
@param State [in] Startup state to be selected.
}
var
CBIdx: Integer; // loops through each entry in combo box
begin
for CBIdx := 0 to Pred(cbOverviewTree.Items.Count) do
begin
if State = TOverviewStartState(cbOverviewTree.Items.Objects[CBIdx]) then
begin
cbOverviewTree.ItemIndex := CBIdx;
Break;
end;
end;
end;
function TDisplayPrefsFrame.UIUpdated: Boolean;
begin
Result := fUIChanged;
end;
initialization
// Register frame with preferences dialog box
TPreferencesDlg.RegisterPage(TDisplayPrefsFrame);
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.