diff --git a/components/charactermap/charactermapfrm.lfm b/components/charactermap/charactermapfrm.lfm index d0e7ff8cfa..5a6a6a31a1 100644 --- a/components/charactermap/charactermapfrm.lfm +++ b/components/charactermap/charactermapfrm.lfm @@ -2636,8 +2636,7 @@ object CharacterMapForm: TCharacterMapForm OnCreate = FormCreate OnKeyDown = FormKeyDown OnShow = FormShow - Position = poScreenCenter - LCLVersion = '2.3.0.0' + LCLVersion = '3.99.0.0' object ButtonPanel: TButtonPanel Left = 6 Height = 26 @@ -2648,7 +2647,6 @@ object CharacterMapForm: TCharacterMapForm OKButton.Enabled = False HelpButton.Name = 'HelpButton' HelpButton.DefaultCaption = True - HelpButton.OnClick = HelpButtonClick CloseButton.Name = 'CloseButton' CloseButton.DefaultCaption = True CancelButton.Name = 'CancelButton' @@ -2668,10 +2666,10 @@ object CharacterMapForm: TCharacterMapForm Height = 433 Top = 6 Width = 578 - ActivePage = pgAnsi + ActivePage = pgUnicode Anchors = [akTop, akLeft, akRight, akBottom] BorderSpacing.Around = 6 - TabIndex = 1 + TabIndex = 0 TabOrder = 0 object pgUnicode: TTabSheet Caption = 'Unicode' diff --git a/components/charactermap/charactermapfrm.pas b/components/charactermap/charactermapfrm.pas index 18d261c617..b74d63429a 100644 --- a/components/charactermap/charactermapfrm.pas +++ b/components/charactermap/charactermapfrm.pas @@ -46,6 +46,7 @@ uses GraphType, LazUTF8, LConvEncoding; type + TCharMapPage = (cmpUnicode, cmpAnsi); TOnInsertCharacterEvent = procedure (const C: TUTF8Char) of object; { TCharacterMapForm } @@ -73,7 +74,6 @@ type procedure cbCodePageSelect(Sender: TObject); procedure cbUniRangeSelect(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState); - procedure HelpButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure seAnsiSizeChange(Sender: TObject); @@ -99,11 +99,23 @@ type procedure FillAnsiGrid; procedure FillUnicodeGrid; procedure FillUniRangeList(ASorted: Boolean); + function GetActivePage: TCharMapPage; + function GetAlphaSort: Boolean; + function GetDropDownCount: Integer; + function GetFontSize: Integer; function UnicodeBlockIndexByName(AName: String): Integer; function UnicodeBlockSelected: Boolean; procedure SelectSystemCP; + procedure SetActivePage(AValue: TCharMapPage); + procedure SetAlphaSort(AValue: Boolean); + procedure SetDropDownCount(AValue: Integer); + procedure SetFontSize(AValue: Integer); procedure SetOnShowHelp(AValue: TNotifyEvent); public + property ActivePage: TCharMapPage read GetActivePage write SetActivePage; + property AlphaSort: Boolean read GetAlphaSort write SetAlphaSort; + property DropDownCount: Integer read GetDropDownCount write SetDropDownCount; + property FontSize: Integer read GetFontSize write SetFontSize; property OnInsertCharacter: TOnInsertCharacterEvent read FOnInsertCharacter write FOnInsertCharacter; property OnShowHelp: TNotifyEvent @@ -210,11 +222,6 @@ begin cbCodePage.ItemIndex := 0; end; -procedure TCharacterMapForm.HelpButtonClick(Sender: TObject); -begin - //LazarusHelp.ShowHelpForIDEControl(Self); -end; - function RoundUp(Value, Divi:integer):integer; begin if Value mod Divi = 0 then @@ -247,13 +254,6 @@ procedure TCharacterMapForm.FormShow(Sender: TObject); var savedFontSize: Integer; begin - (* wp - AnsiGrid.Font.Name := EditorOpts.EditorFont; - UnicodeGrid.Font.Name := EditorOpts.EditorFont; - AnsiGrid.Font.Size := seAnsiSize.Value; - UnicodeGrid.Font.Size := seUniSize.Value; - *) - // Auto-adjust the width of the AnsiGrid's fixed column. Note that // the font defined in PrepareCanvas is ignored by AutoSizeColumn. savedfontSize := AnsiGrid.Font.Size; @@ -266,9 +266,6 @@ begin FUnicodeBlockIndex:=NOT_SELECTED; FillUniRangeList(SortUniRangeListButton.Down); FillUnicodeGrid; - // wp - //cbCodePage.DropDownCount := Math.max(EnvironmentOptions.DropDownCount, 25); - //cbUniRange.DropDownCount := Math.max(EnvironmentOptions.DropDownCount, 25); end; procedure TCharacterMapForm.seAnsiSizeChange(Sender: TObject); @@ -455,6 +452,51 @@ begin cbUniRange.Text:=UnicodeBlocks[FUnicodeBlockIndex].PG; end; +function TCharacterMapForm.GetActivePage: TCharMapPage; +begin + Result := TCharMapPage(PageControl1.ActivePageIndex); +end; + +function TCharacterMapForm.GetAlphaSort: Boolean; +begin + Result := SortUniRangeListButton.Down; +end; + +function TCharacterMapForm.GetDropDownCount: Integer; +begin + Result := CbUniRange.DropDownCount; +end; + +function TCharacterMapForm.GetFontSize: Integer; +begin + Result := seUniSize.Value; +end; + +procedure TCharacterMapForm.SetActivePage(AValue: TCharMapPage); +begin + PageControl1.ActivePageIndex := ord(AValue); +end; + +procedure TCharacterMapForm.SetAlphaSort(AValue: Boolean); +begin + SortUniRangeListButton.Down := AValue; +end; + +procedure TCharacterMapForm.SetDropDownCount(AValue: Integer); +begin + CbUniRange.DropDownCount := AValue; + CbCodePage.DropDownCount := AValue; +end; + +procedure TCharacterMapForm.SetFontSize(AValue: Integer); +begin + seUniSize.Value := AValue; + seAnsiSize.Value := AValue; + + UnicodeGrid.Font.Size := AValue; + AnsiGrid.Font.Size := AValue; +end; + function TCharacterMapForm.UnicodeBlockIndexByName(AName: String): Integer; var BlockIdx: Integer; diff --git a/components/charactermap/design/charactermap_reg.pas b/components/charactermap/design/charactermap_reg.pas index 61b80eaba1..fd511cbc31 100644 --- a/components/charactermap/design/charactermap_reg.pas +++ b/components/charactermap/design/charactermap_reg.pas @@ -5,8 +5,8 @@ unit charactermap_reg; interface uses - Classes, SysUtils, LCLType, Forms, SynEdit, - MenuIntf, IDECommands, IDEHelpIntf, SrcEditorIntf, + Classes, SysUtils, LCLIntf, LCLType, Forms, SynEdit, Laz2_XMLCfg, + MenuIntf, IDECommands, IDEHelpIntf, SrcEditorIntf, EnvironmentOpts, CharacterMapFrm; type @@ -15,12 +15,17 @@ type TCharacterMapDialog = class(TCharacterMapForm) private + FXMLCfg: TXMLConfig; procedure HelpButtonClick(Sender: TObject); procedure InsertCharacter(const C: TUTF8Char); + procedure CloseQueryHandler(Sender: TObject; var CanClose: Boolean); + procedure LoadConfig; + procedure SaveConfig; protected procedure Activate; override; public constructor Create(AOwner: TComponent); override; + destructor Destroy; override; end; procedure Register; @@ -35,15 +40,27 @@ procedure ShowCharacterMapProc({%H-}ASender: TObject); begin if CharacterMapDialog = nil then Application.CreateForm(TCharacterMapDialog, CharacterMapDialog); + CharacterMapDialog.LoadConfig; CharacterMapDialog.Show; end; { TCharacterMapDialog } +const + Path = 'CharacterMap/'; + constructor TCharacterMapDialog.Create(AOwner: TComponent); begin inherited; OnInsertCharacter := @InsertCharacter; + OnCloseQuery := @CloseQueryHandler; + FXMLCfg := TXMLConfig.Create(ExtractFilePath(EnvironmentOptions.FileName) + 'charactermap.xml'); +end; + +destructor TCharacterMapDialog.Destroy; +begin + FXMLCfg.Free; + inherited; end; procedure TCharacterMapDialog.Activate; @@ -51,6 +68,13 @@ begin OnShowHelp := @HelpButtonClick; end; +procedure TCharacterMapDialog.CloseQueryHandler(Sender: TObject; + var CanClose: Boolean); +begin + if CanClose then + SaveConfig; +end; + procedure TCharacterMapDialog.HelpButtonClick(Sender: TObject); begin LazarusHelp.ShowHelpForIDEControl(Self); @@ -69,6 +93,45 @@ begin end; end; +procedure TCharacterMapDialog.LoadConfig; +var + L, T, W, H: Integer; + R: TRect; +begin + L := FXMLCfg.GetValue(Path + 'Position/Left', Left); + T := FXMLCfg.GetValue(Path + 'Position/Top', Top); + W := FXMLCfg.GetValue(Path + 'Position/Width', Width); + H := FXMLCfg.GetValue(Path + 'Position/Height', Height); + R := Screen.WorkAreaRect; + if W > R.Width then W := R.Width; + if H > R.Height then H := R.Height; + if L < R.Left then L := R.Left; + if T < R.Top then T := R.Top; + if L + W > R.Right then L := R.Right - W - GetSystemMetrics(SM_CXSIZEFRAME); + if T + H > R.Bottom then T := R.Bottom - H - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYSIZEFRAME); + SetBounds(L, T, W, H); + WindowState := TWindowState(FXMLCfg.GetValue(Path + 'Position/WindowState', 0)); + FontSize := FXMLCfg.GetValue(Path + 'FontSize', 12); + ActivePage := TCharMapPage(FXMLCfg.GetValue(Path + 'ActivePage', Integer(ActivePage))); + AlphaSort := FXMLCfg.GetValue(Path + 'SortedUnicodeRangeList', AlphaSort); + + DropDownCount := EnvironmentOptions.DropDownCount; +end; + +procedure TCharacterMapDialog.SaveConfig; +begin + FXMLCfg.SetValue(Path + 'Position/Top', RestoredTop); + FXMLCfg.SetValue(Path + 'Position/Left', RestoredLeft); + FXMLCfg.SetValue(Path + 'Position/Width', RestoredWidth); + FXMLCfg.SetValue(Path + 'Position/Height', RestoredHeight); + FXMLCfg.SetValue(Path + 'Position/WindowState', Integer(WindowState)); + FXMLCfg.SetValue(Path + 'FontSize', FontSize); + FXMLCfg.SetValue(Path + 'ActivePage', ord(ActivePage)); + FXMLCfg.SetValue(Path + 'SortedUnicodeRangeList', AlphaSort); + + EnvironmentOptions.DropDownCount := DropDownCount; +end; + { Registration }