source: 2.19_branch/NewView/OptionsForm.pas@ 376

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

+ i18n debug messages

  • Property svn:eol-style set to native
File size: 15.6 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 DebugUnit,
144 StringUtilsUnit;
145
146Procedure TOptionsForm.OptionsFormOnSetupShow (Sender: TObject);
147Begin
148 ScaleForm( self, 11, 16 );
149End;
150
151Procedure TOptionsForm.ApplicationFontButtonOnClick (Sender: TObject);
152Begin
153 FontDialog.EditFont := ApplicationFontPanel.Font;
154 if FontDialog.Execute then
155 begin
156 ApplicationFontPanel.Font := Screen.CreateCompatibleFont( FontDialog.EditFont );
157 ApplicationFontCustomised := true;
158 SetFontCaptions;
159 end;
160End;
161
162function TOptionsForm.GetFontString( Font: TFont ): string;
163begin
164 Result := Font.FaceName
165 + ' '
166 + IntToStr( Font.PointSize );
167 if faBold in Font.Attributes then
168 Result := Result + BoldFontSuffix;
169 if faItalic in Font.Attributes then
170 Result := Result + ItalicFontSuffix;
171end;
172
173Procedure TOptionsForm.ColorItemsListBoxOnClick (Sender: TObject);
174Begin
175
176End;
177
178const
179 DefaultColorItemNames: array[ 0 .. NumColorSettings - 1 ] of string =
180 (
181 'Contents Background',
182 ' Text',
183 ' Lines',
184 'Index Background',
185 ' Text',
186 'Search Background',
187 ' Text',
188 'Notes Background',
189 ' Text',
190 'Topic Background',
191 ' Notes Text',
192 'Search Highlight'
193 );
194
195Procedure TOptionsForm.OnLanguageEvent( Language: TLanguageFile;
196 const Apply: boolean );
197var
198 i: longint;
199 ColorItemName: string;
200begin
201 LogEvent(LogI18n, 'TOptionsForm.OnLanguageEvent apply: "' + BoolToStr(Apply) + '"');
202 Language.LoadComponentLanguage( self, Apply );
203
204 if Apply then
205 begin
206 ColorItemsListBox.Items.BeginUpdate;
207 ColorItemsListBox.Items.Clear;
208 end;
209
210 for i := 0 to NumColorSettings - 1 do
211 begin
212 Language.LL( Apply,
213 ColorItemName,
214 'ColorItemName' + IntToStr( i ),
215 DefaultColorItemNames[ i ] );
216 if Apply then
217 ColorItemsListBox.Items.Add( ColorItemName );
218 end;
219
220 if Apply then
221 ColorItemsListBox.EndUpdate;
222
223 Language.LL( Apply, SelectBitmapTitle, 'SelectBitmapTitle', 'Select Bitmap File' );
224 Language.LL( Apply, BitmapFilesDesc, 'BitmapFilesDesc', 'Bitmaps (*.bmp)' );
225 Language.LL( Apply, BoldFontSuffix, 'BoldFontSuffix', ' Bold' );
226 Language.LL( Apply, ItalicFontSuffix, 'ItalicFontSuffix', ' Italic' );
227end;
228
229Procedure TOptionsForm.DefaultFontsButtonOnClick (Sender: TObject);
230Begin
231 NormalFontPanel.Font := Screen.GetFontFromPointSize( DefaultTopicFontName,
232 DefaultTopicFontSize );
233 FixedFontPanel.Font := Screen.GetFontFromPointSize( DefaultTopicFixedFontName,
234 DefaultTopicFixedFontSize );
235 ApplicationFontCustomised := false;
236 ApplicationFontPanel.Font := GetNiceDefaultFont;
237
238 SetFontCaptions;
239End;
240
241Procedure TOptionsForm.DefaultColorsButtonOnClick (Sender: TObject);
242var
243 i: longint;
244Begin
245 // restore default colors
246 for i := 0 to NumColorSettings - 1 do
247 begin
248 Colors[ i ] := DefaultColors[ i ];
249 end;
250 DisplayColorItem( nil );
251End;
252
253Procedure TOptionsForm.SetSelectedColor( bit: longword;
254 value: longint;
255 ExcludeControl: TComponent );
256var
257 mask: longword;
258begin
259 if UpdatingColor then
260 exit;
261
262 if value < 0 then
263 value := 0;
264 if value > 255 then
265 value := 255;
266
267 UpdatingColor := true;
268
269 Mask := $ffffff and not ( $ff shl bit );
270
271 Colors[ ColorItemsListBox.ItemIndex ] :=
272 Colors[ ColorItemsListBox.ItemIndex ]
273 and Mask
274 or ( Value shl bit );
275
276 DisplayColorItem( ExcludeControl );
277
278 UpdatingColor := false;
279
280end;
281
282Procedure TOptionsForm.RedUpDownOnChanging (Sender: TComponent;
283 Var AllowChange: Boolean);
284Begin
285 SetSelectedColor( 16, RedUpDown.Position, RedUpDown );
286End;
287
288Procedure TOptionsForm.GreenUpDownOnChanging (Sender: TComponent;
289 Var AllowChange: Boolean);
290Begin
291 SetSelectedColor( 8, GreenUpDown.Position, GreenUpDown );
292End;
293
294Procedure TOptionsForm.BlueUpDownOnChanging (Sender: TComponent;
295 Var AllowChange: Boolean);
296Begin
297 SetSelectedColor( 0, BlueUpDown.Position, BlueUpDown );
298End;
299
300Procedure TOptionsForm.RedTrackBarOnChange (Sender: TObject);
301Begin
302 SetSelectedColor( 16, RedTrackBar.Position, RedTrackBar );
303End;
304
305Procedure TOptionsForm.GreenTrackBarOnChange (Sender: TObject);
306Begin
307 SetSelectedColor( 8, GreenTrackBar.Position, GreenTrackBar );
308End;
309
310Procedure TOptionsForm.BlueTrackBarOnChange (Sender: TObject);
311Begin
312 SetSelectedColor( 0, BlueTrackBar.Position, BlueTrackBar );
313End;
314
315Procedure TOptionsForm.RedEditOnChange (Sender: TObject);
316Begin
317 try
318 SetSelectedColor( 16, StrToInt( RedEdit.Text ), RedEdit );
319 except
320 end;
321End;
322
323Procedure TOptionsForm.GreenEditOnChange (Sender: TObject);
324Begin
325 try
326 SetSelectedColor( 8, StrToInt( GreenEdit.Text ), GreenEdit );
327 except
328 end;
329End;
330
331Procedure TOptionsForm.BlueEditOnChange (Sender: TObject);
332Begin
333 try
334 SetSelectedColor( 0, StrToInt( BlueEdit.Text ), BlueEdit );
335 except
336 end;
337End;
338
339Procedure TOptionsForm.ClearBackgroundBitmapButtonOnClick (Sender: TObject);
340Begin
341 BackgroundImageFilenameEdit.Text := '';
342End;
343
344Procedure TOptionsForm.OpenBackgroundImageButtonOnClick (Sender: TObject);
345var
346 Filename: string;
347Begin
348 if DoOpenFileDialog( SelectBitmapTitle,
349 BitmapFilesDesc + '|*.bmp',
350 '*.bmp',
351 ImageDirectory,
352 Filename ) then
353 begin
354 BackgroundImageFilenameEdit.Text := Filename;
355 end;
356End;
357
358Procedure TOptionsForm.OptionsFormOnCreate (Sender: TObject);
359Begin
360 RegisterForLanguages( OnLanguageEvent );
361
362 TabbedNoteBook.ShowPageHint := false;
363 TabbedNoteBook.NotebookMargin := 2;
364 TabbedNoteBook.PageIndex := 0;
365
366 // Select the first colour item
367 ColorItemsListBox.ItemIndex := 0;
368 RedTrackBar.Frequency := 32;
369 GreenTrackBar.Frequency := 32;
370 BlueTrackBar.Frequency := 32;
371
372 ImageDirectory := GetApplicationDir;
373End;
374
375Procedure TOptionsForm.ValueBarOnChange (Sender: TObject);
376Begin
377 if UpdatingColor then
378 exit;
379
380 UpdatingColor := true;
381
382 Colors[ ColorItemsListBox.ItemIndex ] := ValueBar.SelectedColor;
383
384 DisplayColorItem( ColorWheel );
385
386 UpdatingColor := false;
387End;
388
389Procedure TOptionsForm.ColorItemsListBoxOnItemFocus (Sender: TObject;
390 Index: LongInt);
391begin
392 DisplayColorItem( nil );
393end;
394
395Procedure TOptionsForm.DisplayColorItem( ExcludeControl: TComponent );
396Var
397 c: longint;
398 r: longint;
399 g: longint;
400 b: longint;
401Begin
402 c := Colors[ ColorItemsListBox.ItemIndex ];
403 c := SysColorToRGB( c );
404 r := ( c shr 16 ) and 255;
405 g := ( c shr 8 ) and 255;
406 b := ( c ) and 255;
407
408 if ExcludeControl <> ColorWheel then
409 ColorWheel.SetSelectedColor( c );
410
411 if ExcludeControl <> RedEdit then
412 RedEdit.Text := IntToStr( r );
413 if ExcludeControl <> GreenEdit then
414 GreenEdit.Text := IntToStr( g );
415 if ExcludeControl <> BlueEdit then
416 BlueEdit.Text := IntToStr( b );
417
418 if ExcludeControl <> RedTrackBar then
419 RedTrackBar.Position := r;
420 if ExcludeControl <> GreenTrackBar then
421 GreenTrackBar.Position := g;
422 if ExcludeControl <> BlueTrackBar then
423 BlueTrackBar.Position := b;
424
425 if ExcludeControl <> RedUpDown then
426 RedUpDown.Position := r;
427 if ExcludeControl <> GreenUpDown then
428 GreenUpDown.Position := g;
429 if ExcludeControl <> BlueUpDown then
430 BlueUpDown.Position := b;
431End;
432
433Procedure TOptionsForm.OKButtonOnClick (Sender: TObject);
434var
435 ColorIndex: integer;
436Begin
437 // Save settings from controls
438 Settings.ShowLeftPanel_Help := ShowLeftPanel_HelpCheckBox.Checked;
439 Settings.ShowLeftPanel_StandAlone := ShowLeftPanel_StandaloneCheckBox.Checked;
440
441 Settings.NormalFont := NormalFontPanel.Font;
442 Settings.FixedFont := FixedFontPanel.Font;
443
444 Settings.FixedFontSubstitution := FixedFontSubstitutionCheckBox.Checked;
445 Settings.FixedFontSubstitutes := FixedFontSubstitutesEdit.Text;
446
447 Settings.StartupHelp := StartupHelpCheckBox.Checked;
448
449 Settings.IndexStyle := TIndexStyle( IndexStyleRadioGroup.ItemIndex );
450 Settings.SmoothScrolling := SmoothScrollingCheckbox.Checked;
451 Settings.UseOriginalDialogs := UseOriginalDialogsCheckBox.Checked;
452 Settings.OpenWithExpandedContents := OpenWithExpandedContentsCheckBox.Checked;
453
454 for ColorIndex := 0 to High( Settings.Colors ) do
455 Settings.Colors[ ColorIndex ] := Colors[ ColorIndex ];
456
457 Settings.ToolbarBackgroundImageFilename := BackgroundImageFilenameEdit.Text;
458
459 Settings.ToolbarStyle := TToolbarStyle( ToolbarStyleRadioGroup.ItemIndex );
460
461 if ApplicationFontCustomised then
462 Settings.Fonts[ ApplicationFontIndex ] := ApplicationFontPanel.Font
463 else
464 Settings.Fonts[ ApplicationFontIndex ] := nil;
465
466 Settings.ConfirmWinHelp := ConfirmWinHelpCheckBox.Checked;
467End;
468
469Procedure TOptionsForm.FixedFontButtonOnClick (Sender: TObject);
470Begin
471 FontDialog.EditFont := FixedFontPanel.Font;
472 if FontDialog.Execute then
473 begin
474 FixedFontPanel.Font := Screen.CreateCompatibleFont( FontDialog.EditFont );
475 SetFontCaptions;
476 end;
477
478End;
479
480Procedure TOptionsForm.NormalFontButtonOnClick (Sender: TObject);
481Begin
482 FontDialog.EditFont := NormalFontPanel.Font;
483 if FontDialog.Execute then
484 begin
485 NormalFontPanel.Font := FontDialog.EditFont;
486 SetFontCaptions;
487 end;
488End;
489
490Procedure TOptionsForm.OptionsFormOnShow (Sender: TObject);
491var
492 ColorIndex: integer;
493Begin
494
495 // Load settings into controls.
496 ShowLeftPanel_HelpCheckBox.Checked := Settings.ShowLeftPanel_Help;
497 ShowLeftPanel_StandaloneCheckBox.Checked := Settings.ShowLeftPanel_StandAlone;
498
499 NormalFontPanel.Font := Settings.NormalFont;
500 FixedFontPanel.Font := Settings.FixedFont;
501
502 ApplicationFontCustomised := Settings.Fonts[ ApplicationFontIndex ] <> nil;
503 if ApplicationFontCustomised then
504 ApplicationFontPanel.Font := Settings.Fonts[ ApplicationFontIndex ]
505 else
506 ApplicationFontPanel.Font := GetNiceDefaultFont;
507
508 SetFontCaptions;
509
510 FixedFontSubstitutionCheckBox.Checked := Settings.FixedFontSubstitution;
511 FixedFontSubstitutesEdit.Text := Settings.FixedFontSubstitutes;
512
513 StartupHelpCheckBox.Checked := Settings.StartupHelp;
514
515 SmoothScrollingCheckbox.Checked := Settings.SmoothScrolling;
516 IndexStyleRadioGroup.ItemIndex := integer( Settings.IndexStyle );
517 UseOriginalDialogsCheckBox.Checked := Settings.UseOriginalDialogs;
518 OpenWithExpandedContentsCheckBox.Checked := Settings.OpenWithExpandedContents;
519
520 for ColorIndex := 0 to High( Settings.Colors ) do
521 Colors[ ColorIndex ] := Settings.Colors[ ColorIndex ];
522
523 DisplayColorItem( nil );
524
525 FontDialog.Font := Font;
526
527 BackgroundImageFilenameEdit.Text := Settings.ToolbarBackgroundImageFilename;
528
529 ToolbarStyleRadioGroup.ItemIndex := Ord( Settings.ToolbarStyle );
530
531 ConfirmWinHelpCheckBox.Checked := Settings.ConfirmWinHelp;
532
533 UpdatingColor := false;
534
535 SmoothScrollingCheckBox.Focus; // TNotebook should do this for us, but doesn't (a bug)
536
537 OKButton.Default := true;
538End;
539
540Procedure TOptionsForm.SetFontCaptions;
541begin
542 NormalFontPanel.Caption := GetFontString( NormalFontPanel.Font );
543 FixedFontPanel.Caption := GetFontString( FixedFontPanel.Font );
544 if ApplicationFontCustomised then
545 ApplicationFontPanel.Caption := GetFontString( ApplicationFontPanel.Font )
546 else
547 ApplicationFontPanel.Caption := '(Default)';
548end;
549
550procedure EnsureOptionsFormLoaded;
551begin
552 if OptionsForm = nil then
553 OptionsForm := TOptionsForm.Create( nil );
554end;
555
556Initialization
557 RegisterClasses ([TOptionsForm,
558 TLabel, TTabbedNotebook
559 , TCheckBox, TPanel, TListBox, TGroupBox,
560 TCustomFontDialog, TEdit, TColorWheel, TValueBar, TTrackBar, TUpDown
561 , TRadioGroup, TButton]);
562
563 RegisterUpdateProcForLanguages( EnsureOptionsFormLoaded );
564End.
Note: See TracBrowser for help on using the repository browser.