source: trunk/NewView/OptionsForm.pas@ 33

Last change on this file since 33 was 33, checked in by RBRi, 19 years ago

more uses cleanup

  • Property svn:eol-style set to native
File size: 15.5 KB
Line 
1Unit OptionsForm;
2
3// NewView - a new OS/2 Help Viewer
4// Copyright 2003 Aaron Lawrence (aaronl at consultant dot com)
5// This software is released under the Gnu Public License - see readme.txt
6
7Interface
8
9Uses
10 Classes,
11 Forms,
12 Buttons,
13 ExtCtrls,
14 StdCtrls,
15 TabCtrls,
16 ComCtrls,
17 ColorWheel,
18 CustomFontDialog,
19 ACLLanguageUnit,
20 SettingsUnit;
21
22// The correct sizes are:
23// Form: 479x378
24// Notebook: 471x306
25
26Type
27 TOptionsForm = Class (TForm)
28 TabbedNotebook: TTabbedNotebook;
29 SmoothScrollingCheckBox: TCheckBox;
30 UseOriginalDialogsCheckBox: TCheckBox;
31 Label1: TLabel;
32 NormalFontPanel: TPanel;
33 Label2: TLabel;
34 FixedFontPanel: TPanel;
35 Label5: TLabel;
36 ColorItemsListBox: TListBox;
37 GroupBox1: TGroupBox;
38 FontDialog: TCustomFontDialog;
39 NormalFontButton: TButton;
40 FixedFontButton: TButton;
41 DefaultFontsButton: TButton;
42 OpenBackgroundImageButton: TButton;
43 ClearBackgroundBitmapButton: TButton;
44 CancelButton: TButton;
45 OKButton: TButton;
46 FixedFontSubstitutionCheckBox: TCheckBox;
47 FixedFontSubstitutesEdit: TEdit;
48 CheckBox1: TCheckBox;
49 CheckBox2: TCheckBox;
50 ConfirmWinHelpCheckBox: TCheckBox;
51 CheckBox3: TCheckBox;
52 GroupBox2: TGroupBox;
53 ShowLeftPanel_HelpCheckBox: TCheckBox;
54 ShowLeftPanel_StandaloneCheckBox: TCheckBox;
55 DefaultColorsButton: TButton;
56 ToolbarStyleRadioGroup: TRadioGroup;
57 ApplicationFontPanel: TPanel;
58 ApplicationFontButton: TButton;
59 ApplicationFontLabel: TLabel;
60 IndexStyleRadioGroup: TRadioGroup;
61 StartupHelpCheckBox: TCheckBox;
62 RedTrackBar: TTrackBar;
63 RedEdit: TEdit;
64 GreenTrackBar: TTrackBar;
65 GreenEdit: TEdit;
66 BlueTrackBar: TTrackBar;
67 BlueEdit: TEdit;
68 RedLabel: TLabel;
69 Label8: TLabel;
70 Label9: TLabel;
71 RedUpDown: TUpDown;
72 GreenUpDown: TUpDown;
73 BlueUpDown: TUpDown;
74 OpenWithExpandedContentsCheckBox: TCheckBox;
75 ColorWheel: TColorWheel;
76 ValueBar: TValueBar;
77 BackgroundImageFilenameEdit: TEdit;
78 Label6: TLabel;
79 Procedure OptionsFormOnSetupShow (Sender: TObject);
80 Procedure ApplicationFontButtonOnClick (Sender: TObject);
81 Procedure ColorItemsListBoxOnClick (Sender: TObject);
82 Procedure DefaultFontsButtonOnClick (Sender: TObject);
83 Procedure DefaultColorsButtonOnClick (Sender: TObject);
84 Procedure BlueUpDownOnChanging (Sender: TComponent;
85 Var AllowChange: Boolean);
86 Procedure GreenUpDownOnChanging (Sender: TComponent;
87 Var AllowChange: Boolean);
88 Procedure RedUpDownOnChanging (Sender: TComponent;
89 Var AllowChange: Boolean);
90 Procedure RedTrackBarOnChange (Sender: TObject);
91 Procedure GreenTrackBarOnChange (Sender: TObject);
92 Procedure BlueTrackBarOnChange (Sender: TObject);
93 Procedure BlueEditOnChange (Sender: TObject);
94 Procedure GreenEditOnChange (Sender: TObject);
95 Procedure RedEditOnChange (Sender: TObject);
96 Procedure ClearBackgroundBitmapButtonOnClick (Sender: TObject);
97 Procedure OpenBackgroundImageButtonOnClick (Sender: TObject);
98 Procedure OptionsFormOnCreate (Sender: TObject);
99 Procedure ValueBarOnChange (Sender: TObject);
100 Procedure ColorItemsListBoxOnItemFocus (Sender: TObject; Index: LongInt);
101 Procedure OKButtonOnClick (Sender: TObject);
102 Procedure FixedFontButtonOnClick (Sender: TObject);
103 Procedure NormalFontButtonOnClick (Sender: TObject);
104 Procedure OptionsFormOnShow (Sender: TObject);
105 Protected
106 Colors: Array[ 0..NumColorSettings - 1 ] of TColor;
107 UpdatingColor: boolean;
108 ImageDirectory: string;
109 ApplicationFontCustomised: boolean;
110 Procedure SetSelectedColor( bit: longword;
111 value: longint;
112 ExcludeControl: TComponent );
113 Procedure SetFontCaptions;
114 Procedure DisplayColorItem( ExcludeControl: TComponent );
115
116 function GetFontString( Font: TFont ): string;
117
118 Protected
119 Procedure OnLanguageEvent( Language: TLanguageFile;
120 const Apply: boolean );
121
122 SelectBitmapTitle: string;
123 BitmapFilesDesc: string;
124 BoldFontSuffix: string;
125 ItalicFontSuffix: string;
126
127 Public
128 MyParent: TForm;
129 End;
130
131Var
132 OptionsForm: TOptionsForm;
133
134procedure EnsureOptionsFormLoaded;
135
136Implementation
137
138uses
139 SysUtils,
140 ACLUtility,
141 ControlsUtility,
142 FileDialogForm;
143
144Procedure TOptionsForm.OptionsFormOnSetupShow (Sender: TObject);
145Begin
146 ScaleForm( self, 11, 16 );
147End;
148
149Procedure TOptionsForm.ApplicationFontButtonOnClick (Sender: TObject);
150Begin
151 FontDialog.EditFont := ApplicationFontPanel.Font;
152 if FontDialog.Execute then
153 begin
154 ApplicationFontPanel.Font := Screen.CreateCompatibleFont( FontDialog.EditFont );
155 ApplicationFontCustomised := true;
156 SetFontCaptions;
157 end;
158End;
159
160function TOptionsForm.GetFontString( Font: TFont ): string;
161begin
162 Result := Font.FaceName
163 + ' '
164 + IntToStr( Font.PointSize );
165 if faBold in Font.Attributes then
166 Result := Result + BoldFontSuffix;
167 if faItalic in Font.Attributes then
168 Result := Result + ItalicFontSuffix;
169end;
170
171Procedure TOptionsForm.ColorItemsListBoxOnClick (Sender: TObject);
172Begin
173
174End;
175
176const
177 DefaultColorItemNames: array[ 0 .. NumColorSettings - 1 ] of string =
178 (
179 'Contents Background',
180 ' Text',
181 ' Lines',
182 'Index Background',
183 ' Text',
184 'Search Background',
185 ' Text',
186 'Notes Background',
187 ' Text',
188 'Topic Background',
189 ' Notes Text',
190 'Search Highlight'
191 );
192
193Procedure TOptionsForm.OnLanguageEvent( Language: TLanguageFile;
194 const Apply: boolean );
195var
196 i: longint;
197 ColorItemName: string;
198begin
199 Language.LoadComponentLanguage( self, Apply );
200
201 if Apply then
202 begin
203 ColorItemsListBox.Items.BeginUpdate;
204 ColorItemsListBox.Items.Clear;
205 end;
206
207 for i := 0 to NumColorSettings - 1 do
208 begin
209 Language.LL( Apply,
210 ColorItemName,
211 'ColorItemName' + IntToStr( i ),
212 DefaultColorItemNames[ i ] );
213 if Apply then
214 ColorItemsListBox.Items.Add( ColorItemName );
215 end;
216
217 if Apply then
218 ColorItemsListBox.EndUpdate;
219
220 Language.LL( Apply, SelectBitmapTitle, 'SelectBitmapTitle', 'Select Bitmap File' );
221 Language.LL( Apply, BitmapFilesDesc, 'BitmapFilesDesc', 'Bitmaps (*.bmp)' );
222 Language.LL( Apply, BoldFontSuffix, 'BoldFontSuffix', ' Bold' );
223 Language.LL( Apply, ItalicFontSuffix, 'ItalicFontSuffix', ' Italic' );
224end;
225
226Procedure TOptionsForm.DefaultFontsButtonOnClick (Sender: TObject);
227Begin
228 NormalFontPanel.Font := Screen.GetFontFromPointSize( DefaultTopicFontName,
229 DefaultTopicFontSize );
230 FixedFontPanel.Font := Screen.GetFontFromPointSize( DefaultTopicFixedFontName,
231 DefaultTopicFixedFontSize );
232 ApplicationFontCustomised := false;
233 ApplicationFontPanel.Font := GetNiceDefaultFont;
234
235 SetFontCaptions;
236End;
237
238Procedure TOptionsForm.DefaultColorsButtonOnClick (Sender: TObject);
239var
240 i: longint;
241Begin
242 // restore default colors
243 for i := 0 to NumColorSettings - 1 do
244 begin
245 Colors[ i ] := DefaultColors[ i ];
246 end;
247 DisplayColorItem( nil );
248End;
249
250Procedure TOptionsForm.SetSelectedColor( bit: longword;
251 value: longint;
252 ExcludeControl: TComponent );
253var
254 mask: longword;
255begin
256 if UpdatingColor then
257 exit;
258
259 if value < 0 then
260 value := 0;
261 if value > 255 then
262 value := 255;
263
264 UpdatingColor := true;
265
266 Mask := $ffffff and not ( $ff shl bit );
267
268 Colors[ ColorItemsListBox.ItemIndex ] :=
269 Colors[ ColorItemsListBox.ItemIndex ]
270 and Mask
271 or ( Value shl bit );
272
273 DisplayColorItem( ExcludeControl );
274
275 UpdatingColor := false;
276
277end;
278
279Procedure TOptionsForm.RedUpDownOnChanging (Sender: TComponent;
280 Var AllowChange: Boolean);
281Begin
282 SetSelectedColor( 16, RedUpDown.Position, RedUpDown );
283End;
284
285Procedure TOptionsForm.GreenUpDownOnChanging (Sender: TComponent;
286 Var AllowChange: Boolean);
287Begin
288 SetSelectedColor( 8, GreenUpDown.Position, GreenUpDown );
289End;
290
291Procedure TOptionsForm.BlueUpDownOnChanging (Sender: TComponent;
292 Var AllowChange: Boolean);
293Begin
294 SetSelectedColor( 0, BlueUpDown.Position, BlueUpDown );
295End;
296
297Procedure TOptionsForm.RedTrackBarOnChange (Sender: TObject);
298Begin
299 SetSelectedColor( 16, RedTrackBar.Position, RedTrackBar );
300End;
301
302Procedure TOptionsForm.GreenTrackBarOnChange (Sender: TObject);
303Begin
304 SetSelectedColor( 8, GreenTrackBar.Position, GreenTrackBar );
305End;
306
307Procedure TOptionsForm.BlueTrackBarOnChange (Sender: TObject);
308Begin
309 SetSelectedColor( 0, BlueTrackBar.Position, BlueTrackBar );
310End;
311
312Procedure TOptionsForm.RedEditOnChange (Sender: TObject);
313Begin
314 try
315 SetSelectedColor( 16, StrToInt( RedEdit.Text ), RedEdit );
316 except
317 end;
318End;
319
320Procedure TOptionsForm.GreenEditOnChange (Sender: TObject);
321Begin
322 try
323 SetSelectedColor( 8, StrToInt( GreenEdit.Text ), GreenEdit );
324 except
325 end;
326End;
327
328Procedure TOptionsForm.BlueEditOnChange (Sender: TObject);
329Begin
330 try
331 SetSelectedColor( 0, StrToInt( BlueEdit.Text ), BlueEdit );
332 except
333 end;
334End;
335
336Procedure TOptionsForm.ClearBackgroundBitmapButtonOnClick (Sender: TObject);
337Begin
338 BackgroundImageFilenameEdit.Text := '';
339End;
340
341Procedure TOptionsForm.OpenBackgroundImageButtonOnClick (Sender: TObject);
342var
343 Filename: string;
344Begin
345 if DoOpenFileDialog( SelectBitmapTitle,
346 BitmapFilesDesc + '|*.bmp',
347 '*.bmp',
348 ImageDirectory,
349 Filename ) then
350 begin
351 BackgroundImageFilenameEdit.Text := Filename;
352 end;
353End;
354
355Procedure TOptionsForm.OptionsFormOnCreate (Sender: TObject);
356Begin
357 RegisterForLanguages( OnLanguageEvent );
358
359 TabbedNoteBook.ShowPageHint := false;
360 TabbedNoteBook.NotebookMargin := 2;
361 TabbedNoteBook.PageIndex := 0;
362
363 // Select the first colour item
364 ColorItemsListBox.ItemIndex := 0;
365 RedTrackBar.Frequency := 32;
366 GreenTrackBar.Frequency := 32;
367 BlueTrackBar.Frequency := 32;
368
369 ImageDirectory := GetApplicationDir;
370End;
371
372Procedure TOptionsForm.ValueBarOnChange (Sender: TObject);
373Begin
374 if UpdatingColor then
375 exit;
376
377 UpdatingColor := true;
378
379 Colors[ ColorItemsListBox.ItemIndex ] := ValueBar.SelectedColor;
380
381 DisplayColorItem( ColorWheel );
382
383 UpdatingColor := false;
384End;
385
386Procedure TOptionsForm.ColorItemsListBoxOnItemFocus (Sender: TObject;
387 Index: LongInt);
388begin
389 DisplayColorItem( nil );
390end;
391
392Procedure TOptionsForm.DisplayColorItem( ExcludeControl: TComponent );
393Var
394 c: longint;
395 r: longint;
396 g: longint;
397 b: longint;
398Begin
399 c := Colors[ ColorItemsListBox.ItemIndex ];
400 c := SysColorToRGB( c );
401 r := ( c shr 16 ) and 255;
402 g := ( c shr 8 ) and 255;
403 b := ( c ) and 255;
404
405 if ExcludeControl <> ColorWheel then
406 ColorWheel.SetSelectedColor( c );
407
408 if ExcludeControl <> RedEdit then
409 RedEdit.Text := IntToStr( r );
410 if ExcludeControl <> GreenEdit then
411 GreenEdit.Text := IntToStr( g );
412 if ExcludeControl <> BlueEdit then
413 BlueEdit.Text := IntToStr( b );
414
415 if ExcludeControl <> RedTrackBar then
416 RedTrackBar.Position := r;
417 if ExcludeControl <> GreenTrackBar then
418 GreenTrackBar.Position := g;
419 if ExcludeControl <> BlueTrackBar then
420 BlueTrackBar.Position := b;
421
422 if ExcludeControl <> RedUpDown then
423 RedUpDown.Position := r;
424 if ExcludeControl <> GreenUpDown then
425 GreenUpDown.Position := g;
426 if ExcludeControl <> BlueUpDown then
427 BlueUpDown.Position := b;
428End;
429
430Procedure TOptionsForm.OKButtonOnClick (Sender: TObject);
431var
432 ColorIndex: integer;
433Begin
434 // Save settings from controls
435 Settings.ShowLeftPanel_Help := ShowLeftPanel_HelpCheckBox.Checked;
436 Settings.ShowLeftPanel_StandAlone := ShowLeftPanel_StandaloneCheckBox.Checked;
437
438 Settings.NormalFont := NormalFontPanel.Font;
439 Settings.FixedFont := FixedFontPanel.Font;
440
441 Settings.FixedFontSubstitution := FixedFontSubstitutionCheckBox.Checked;
442 Settings.FixedFontSubstitutes := FixedFontSubstitutesEdit.Text;
443
444 Settings.StartupHelp := StartupHelpCheckBox.Checked;
445
446 Settings.IndexStyle := TIndexStyle( IndexStyleRadioGroup.ItemIndex );
447 Settings.SmoothScrolling := SmoothScrollingCheckbox.Checked;
448 Settings.UseOriginalDialogs := UseOriginalDialogsCheckBox.Checked;
449 Settings.OpenWithExpandedContents := OpenWithExpandedContentsCheckBox.Checked;
450
451 for ColorIndex := 0 to High( Settings.Colors ) do
452 Settings.Colors[ ColorIndex ] := Colors[ ColorIndex ];
453
454 Settings.ToolbarBackgroundImageFilename := BackgroundImageFilenameEdit.Text;
455
456 Settings.ToolbarStyle := TToolbarStyle( ToolbarStyleRadioGroup.ItemIndex );
457
458 if ApplicationFontCustomised then
459 Settings.Fonts[ ApplicationFontIndex ] := ApplicationFontPanel.Font
460 else
461 Settings.Fonts[ ApplicationFontIndex ] := nil;
462
463 Settings.ConfirmWinHelp := ConfirmWinHelpCheckBox.Checked;
464End;
465
466Procedure TOptionsForm.FixedFontButtonOnClick (Sender: TObject);
467Begin
468 FontDialog.EditFont := FixedFontPanel.Font;
469 if FontDialog.Execute then
470 begin
471 FixedFontPanel.Font := Screen.CreateCompatibleFont( FontDialog.EditFont );
472 SetFontCaptions;
473 end;
474
475End;
476
477Procedure TOptionsForm.NormalFontButtonOnClick (Sender: TObject);
478Begin
479 FontDialog.EditFont := NormalFontPanel.Font;
480 if FontDialog.Execute then
481 begin
482 NormalFontPanel.Font := FontDialog.EditFont;
483 SetFontCaptions;
484 end;
485End;
486
487Procedure TOptionsForm.OptionsFormOnShow (Sender: TObject);
488var
489 ColorIndex: integer;
490Begin
491
492 // Load settings into controls.
493 ShowLeftPanel_HelpCheckBox.Checked := Settings.ShowLeftPanel_Help;
494 ShowLeftPanel_StandaloneCheckBox.Checked := Settings.ShowLeftPanel_StandAlone;
495
496 NormalFontPanel.Font := Settings.NormalFont;
497 FixedFontPanel.Font := Settings.FixedFont;
498
499 ApplicationFontCustomised := Settings.Fonts[ ApplicationFontIndex ] <> nil;
500 if ApplicationFontCustomised then
501 ApplicationFontPanel.Font := Settings.Fonts[ ApplicationFontIndex ]
502 else
503 ApplicationFontPanel.Font := GetNiceDefaultFont;
504
505 SetFontCaptions;
506
507 FixedFontSubstitutionCheckBox.Checked := Settings.FixedFontSubstitution;
508 FixedFontSubstitutesEdit.Text := Settings.FixedFontSubstitutes;
509
510 StartupHelpCheckBox.Checked := Settings.StartupHelp;
511
512 SmoothScrollingCheckbox.Checked := Settings.SmoothScrolling;
513 IndexStyleRadioGroup.ItemIndex := integer( Settings.IndexStyle );
514 UseOriginalDialogsCheckBox.Checked := Settings.UseOriginalDialogs;
515 OpenWithExpandedContentsCheckBox.Checked := Settings.OpenWithExpandedContents;
516
517 for ColorIndex := 0 to High( Settings.Colors ) do
518 Colors[ ColorIndex ] := Settings.Colors[ ColorIndex ];
519
520 DisplayColorItem( nil );
521
522 FontDialog.Font := Font;
523
524 BackgroundImageFilenameEdit.Text := Settings.ToolbarBackgroundImageFilename;
525
526 ToolbarStyleRadioGroup.ItemIndex := Ord( Settings.ToolbarStyle );
527
528 ConfirmWinHelpCheckBox.Checked := Settings.ConfirmWinHelp;
529
530 UpdatingColor := false;
531
532 SmoothScrollingCheckBox.Focus; // TNotebook should do this for us, but doesn't (a bug)
533
534 OKButton.Default := true;
535End;
536
537Procedure TOptionsForm.SetFontCaptions;
538begin
539 NormalFontPanel.Caption := GetFontString( NormalFontPanel.Font );
540 FixedFontPanel.Caption := GetFontString( FixedFontPanel.Font );
541 if ApplicationFontCustomised then
542 ApplicationFontPanel.Caption := GetFontString( ApplicationFontPanel.Font )
543 else
544 ApplicationFontPanel.Caption := '(Default)';
545end;
546
547procedure EnsureOptionsFormLoaded;
548begin
549 if OptionsForm = nil then
550 OptionsForm := TOptionsForm.Create( nil );
551end;
552
553Initialization
554 RegisterClasses ([TOptionsForm,
555 TLabel, TTabbedNotebook
556 , TCheckBox, TPanel, TListBox, TGroupBox,
557 TCustomFontDialog, TEdit, TColorWheel, TValueBar, TTrackBar, TUpDown
558 , TRadioGroup, TButton]);
559
560 RegisterUpdateProcForLanguages( EnsureOptionsFormLoaded );
561End.
Note: See TracBrowser for help on using the repository browser.