source: trunk/NewView/OptionsForm.pas@ 18

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

+ newview source

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