View Issue Details

IDProjectCategoryView StatusLast Update
0029856LazarusRTLpublic2017-01-24 19:03
ReporterAlexey Tor.Assigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWinXP, RussianOSOS Version
Product Version1.7 (SVN)Product Build 
Target Version1.6.2Fixed in Version1.6.2 
Summary0029856: IDE Charmap don't show Rus chars in 128..255
Descriptionproblem visible in my app and in IDE too. char map don't show (from some build of Laz) Russian chars for Ansi codes 128..255.
Just open CharMap dialog. No Rus chars in it.

Other apps show Rus chars ok (Rus is default locale for non unicode)
Image
TagsNo tags attached.
Fixed in Revisionr52008
LazTarget1.6.2
Widgetset
Attached Files
  • charmap-laz.png (12,756 bytes)
    charmap-laz.png (12,756 bytes)
  • charmap_cp1252_laz144.png (31,505 bytes)
    charmap_cp1252_laz144.png (31,505 bytes)
  • charmap.diff (488 bytes)
    Index: ide/charactermapdlg.pas
    ===================================================================
    --- ide/charactermapdlg.pas	(revision 51837)
    +++ ide/charactermapdlg.pas	(working copy)
    @@ -285,7 +285,7 @@
         begin
           if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
           else
    -        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
    +        StringGrid1.Cells[C, R] := WinCPToUtf8(Chr(Succ(R) * 16 + Pred(C)));
         end;
       end;
     end;
    
    charmap.diff (488 bytes)
  • ide-charmap.patch (10,478 bytes)
    Index: ide/charactermapdlg.lfm
    ===================================================================
    --- ide/charactermapdlg.lfm	(revision 51943)
    +++ ide/charactermapdlg.lfm	(working copy)
    @@ -2,11 +2,11 @@
       Left = 370
       Height = 477
       Top = 128
    -  Width = 593
    +  Width = 590
       BorderStyle = bsSizeToolWin
       Caption = 'CharacterMapDialog'
       ClientHeight = 477
    -  ClientWidth = 593
    +  ClientWidth = 590
       FormStyle = fsStayOnTop
       KeyPreview = True
       OnCreate = FormCreate
    @@ -16,9 +16,9 @@
       LCLVersion = '1.7'
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 36
    -    Top = 435
    -    Width = 581
    +    Height = 26
    +    Top = 445
    +    Width = 578
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
         OKButton.Enabled = False
    @@ -41,83 +41,40 @@
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = ButtonPanel
         Left = 6
    -    Height = 423
    +    Height = 433
         Top = 6
    -    Width = 581
    -    ActivePage = TabSheet1
    +    Width = 578
    +    ActivePage = pgUnicode
         Anchors = [akTop, akLeft, akRight, akBottom]
         BorderSpacing.Around = 6
         TabIndex = 0
         TabOrder = 0
    -    object TabSheet1: TTabSheet
    -      Caption = 'ANSI'
    -      ClientHeight = 390
    -      ClientWidth = 577
    -      object CharInfoLabel: TLabel
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Side = asrBottom
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet1
    -        AnchorSideBottom.Side = asrBottom
    -        Left = 6
    -        Height = 17
    -        Top = 367
    -        Width = 565
    -        Anchors = [akLeft, akRight, akBottom]
    -        BorderSpacing.Around = 6
    -        Caption = 'CharInfoLabel'
    -        ParentColor = False
    -      end
    -      object StringGrid1: TStringGrid
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Control = TabSheet1
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = CharInfoLabel
    -        Left = 0
    -        Height = 361
    -        Top = 0
    -        Width = 577
    -        Anchors = [akTop, akLeft, akRight, akBottom]
    -        ColCount = 17
    -        DefaultColWidth = 16
    -        DefaultDrawing = False
    -        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    -        RowCount = 15
    -        TabOrder = 0
    -        OnKeyPress = StringGridKeyPress
    -        OnMouseDown = StringGridMouseDown
    -        OnMouseMove = StringGrid1MouseMove
    -        OnSelectCell = StringGrid1SelectCell
    -      end
    -    end
    -    object TabSheet2: TTabSheet
    +    object pgUnicode: TTabSheet
           Caption = 'Unicode'
    -      ClientHeight = 390
    -      ClientWidth = 577
    +      ClientHeight = 405
    +      ClientWidth = 570
           object UnicodeCharInfoLabel: TLabel
             AnchorSideLeft.Control = Owner
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             Left = 6
    -        Height = 17
    -        Top = 362
    -        Width = 147
    +        Height = 15
    +        Top = 380
    +        Width = 118
             BorderSpacing.Around = 6
             Caption = 'UnicodeCharInfoLabel'
             ParentColor = False
           end
           object StringGrid2: TStringGrid
    -        AnchorSideLeft.Control = TabSheet2
    -        AnchorSideTop.Control = TabSheet2
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideLeft.Control = pgUnicode
    +        AnchorSideTop.Control = pgUnicode
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
             AnchorSideBottom.Control = cbUniRange
             Left = 0
    -        Height = 351
    +        Height = 370
             Top = 0
    -        Width = 577
    +        Width = 570
             Anchors = [akTop, akLeft, akRight, akBottom]
             ColCount = 16
             DefaultColWidth = 16
    @@ -133,18 +90,18 @@
             OnSelectCell = StringGrid2SelectCell
           end
           object cbUniRange: TComboBox
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet2
    +        AnchorSideBottom.Control = pgUnicode
             AnchorSideBottom.Side = asrBottom
    -        Left = 280
    -        Height = 27
    -        Top = 357
    +        Left = 273
    +        Height = 23
    +        Top = 376
             Width = 291
             Anchors = [akRight, akBottom]
             BorderSpacing.Around = 6
             DropDownCount = 25
    -        ItemHeight = 23
    +        ItemHeight = 15
             OnSelect = cbUniRangeSelect
             Style = csDropDownList
             TabOrder = 1
    @@ -153,14 +110,116 @@
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             AnchorSideRight.Control = cbUniRange
    -        Left = 231
    -        Height = 17
    -        Top = 362
    -        Width = 43
    +        Left = 234
    +        Height = 15
    +        Top = 380
    +        Width = 33
             Anchors = [akTop, akRight]
             Caption = 'Range'
             ParentColor = False
           end
         end
    +    object pgAnsi: TTabSheet
    +      Caption = 'ANSI'
    +      ClientHeight = 405
    +      ClientWidth = 570
    +      object CharInfoLabel: TLabel
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 6
    +        Height = 15
    +        Top = 380
    +        Width = 74
    +        BorderSpacing.Around = 6
    +        Caption = 'CharInfoLabel'
    +        ParentColor = False
    +      end
    +      object StringGrid1: TStringGrid
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = pgAnsi
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = cbCodePage
    +        Left = 0
    +        Height = 370
    +        Top = 0
    +        Width = 570
    +        Anchors = [akTop, akLeft, akRight, akBottom]
    +        ColCount = 17
    +        DefaultColWidth = 16
    +        DefaultDrawing = False
    +        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    +        RowCount = 15
    +        TabOrder = 0
    +        OnKeyPress = StringGridKeyPress
    +        OnMouseDown = StringGridMouseDown
    +        OnMouseMove = StringGrid1MouseMove
    +        OnSelectCell = StringGrid1SelectCell
    +      end
    +      object cbCodePage: TComboBox
    +        AnchorSideTop.Control = StringGrid1
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 245
    +        Height = 23
    +        Top = 376
    +        Width = 319
    +        Anchors = [akRight, akBottom]
    +        BorderSpacing.Around = 6
    +        DropDownCount = 25
    +        ItemHeight = 15
    +        ItemIndex = 0
    +        Items.Strings = (
    +          'cp1250 - Central and East European Latin'
    +          'cp1251 - Cyrillic'
    +          'cp1252 - West European Latin'
    +          'cp1253 - Greek'
    +          'cp1254 - Turkish'
    +          'cp1255 - Hebrew'
    +          'cp1256 - Arabic'
    +          'cp1257 - Baltic'
    +          'cp1258 - Vietnamese'
    +          'cp437 - Original IBM PC hardware'
    +          'cp850 - Latin-1'
    +          'cp852 - Latin-2'
    +          'cp866 - Belarusian, Russian, Ukrainian'
    +          'cp874 - Thai'
    +          'cp932 - Japanese'
    +          'cp936 - ANSI/OEM Simplified Chinese'
    +          'cp949 - Korean'
    +          'cp950 - Traditional Chinese'
    +          'macintosh'
    +          'koi8'
    +          'iso88591 - ISO Latin-1 (Western Europe)'
    +          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
    +          'iso885915 - ISO Latin-9 (Western Europe)'
    +        )
    +        OnSelect = cbCodePageSelect
    +        Style = csDropDownList
    +        TabOrder = 1
    +        Text = 'cp1250 - Central and East European Latin'
    +      end
    +      object Label1: TLabel
    +        AnchorSideLeft.Control = CharInfoLabel
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = cbCodePage
    +        Left = 182
    +        Height = 15
    +        Top = 380
    +        Width = 57
    +        Anchors = [akTop, akRight]
    +        Caption = 'Code page'
    +        ParentColor = False
    +      end
    +    end
       end
     end
    Index: ide/charactermapdlg.pas
    ===================================================================
    --- ide/charactermapdlg.pas	(revision 51943)
    +++ ide/charactermapdlg.pas	(working copy)
    @@ -49,15 +49,18 @@
     
       TCharacterMapDialog = class(TForm)
         ButtonPanel: TButtonPanel;
    +    cbCodePage: TComboBox;
         CharInfoLabel: TLabel;
         cbUniRange: TComboBox;
    +    Label1: TLabel;
         RangeLabel: TLabel;
         UnicodeCharInfoLabel: TLabel;
         PageControl1: TPageControl;
         StringGrid1: TStringGrid;
         StringGrid2: TStringGrid;
    -    TabSheet1: TTabSheet;
    -    TabSheet2: TTabSheet;
    +    pgAnsi: TTabSheet;
    +    pgUnicode: TTabSheet;
    +    procedure cbCodePageSelect(Sender: TObject);
         procedure cbUniRangeSelect(Sender: TObject);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    @@ -93,6 +96,9 @@
     
     {$R *.lfm}
     
    +uses
    +  lconvencoding;
    +
     procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
     begin
       if CharacterMapDialog = nil then
    @@ -129,6 +135,11 @@
        Result:=(Value div Divi)+1;
     end;
     
    +procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
    +begin
    +  FillCharMap;
    +end;
    +
     procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
     var cnt, x, y :integer;
     S,E:Integer;
    @@ -276,8 +287,12 @@
     
     procedure TCharacterMapDialog.FillCharMap;
     var
    -  R, C: Integer;
    +  R, C, p: Integer;
    +  cp: String;
     begin
    +  cp := cbCodePage.Items[cbCodePage.ItemIndex];
    +  p := pos(' ', cp);
    +  if p > 0 then SetLength(cp, p-1);
       for R := 0 to Pred(StringGrid1.RowCount) do
       begin
         if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
    @@ -285,7 +300,7 @@
         begin
           if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
           else
    -        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
    +        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
         end;
       end;
     end;
    
    ide-charmap.patch (10,478 bytes)
  • ide-charmap-v2.patch (12,070 bytes)
    Index: ide/charactermapdlg.lfm
    ===================================================================
    --- ide/charactermapdlg.lfm	(revision 51943)
    +++ ide/charactermapdlg.lfm	(working copy)
    @@ -2,11 +2,11 @@
       Left = 370
       Height = 477
       Top = 128
    -  Width = 593
    +  Width = 590
       BorderStyle = bsSizeToolWin
       Caption = 'CharacterMapDialog'
       ClientHeight = 477
    -  ClientWidth = 593
    +  ClientWidth = 590
       FormStyle = fsStayOnTop
       KeyPreview = True
       OnCreate = FormCreate
    @@ -16,9 +16,9 @@
       LCLVersion = '1.7'
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 36
    -    Top = 435
    -    Width = 581
    +    Height = 26
    +    Top = 445
    +    Width = 578
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
         OKButton.Enabled = False
    @@ -41,83 +41,40 @@
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = ButtonPanel
         Left = 6
    -    Height = 423
    +    Height = 433
         Top = 6
    -    Width = 581
    -    ActivePage = TabSheet1
    +    Width = 578
    +    ActivePage = pgAnsi
         Anchors = [akTop, akLeft, akRight, akBottom]
         BorderSpacing.Around = 6
    -    TabIndex = 0
    +    TabIndex = 1
         TabOrder = 0
    -    object TabSheet1: TTabSheet
    -      Caption = 'ANSI'
    -      ClientHeight = 390
    -      ClientWidth = 577
    -      object CharInfoLabel: TLabel
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Side = asrBottom
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet1
    -        AnchorSideBottom.Side = asrBottom
    -        Left = 6
    -        Height = 17
    -        Top = 367
    -        Width = 565
    -        Anchors = [akLeft, akRight, akBottom]
    -        BorderSpacing.Around = 6
    -        Caption = 'CharInfoLabel'
    -        ParentColor = False
    -      end
    -      object StringGrid1: TStringGrid
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Control = TabSheet1
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = CharInfoLabel
    -        Left = 0
    -        Height = 361
    -        Top = 0
    -        Width = 577
    -        Anchors = [akTop, akLeft, akRight, akBottom]
    -        ColCount = 17
    -        DefaultColWidth = 16
    -        DefaultDrawing = False
    -        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    -        RowCount = 15
    -        TabOrder = 0
    -        OnKeyPress = StringGridKeyPress
    -        OnMouseDown = StringGridMouseDown
    -        OnMouseMove = StringGrid1MouseMove
    -        OnSelectCell = StringGrid1SelectCell
    -      end
    -    end
    -    object TabSheet2: TTabSheet
    +    object pgUnicode: TTabSheet
           Caption = 'Unicode'
    -      ClientHeight = 390
    -      ClientWidth = 577
    +      ClientHeight = 405
    +      ClientWidth = 570
           object UnicodeCharInfoLabel: TLabel
             AnchorSideLeft.Control = Owner
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             Left = 6
    -        Height = 17
    -        Top = 362
    -        Width = 147
    +        Height = 15
    +        Top = 380
    +        Width = 118
             BorderSpacing.Around = 6
             Caption = 'UnicodeCharInfoLabel'
             ParentColor = False
           end
           object StringGrid2: TStringGrid
    -        AnchorSideLeft.Control = TabSheet2
    -        AnchorSideTop.Control = TabSheet2
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideLeft.Control = pgUnicode
    +        AnchorSideTop.Control = pgUnicode
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
             AnchorSideBottom.Control = cbUniRange
             Left = 0
    -        Height = 351
    +        Height = 370
             Top = 0
    -        Width = 577
    +        Width = 570
             Anchors = [akTop, akLeft, akRight, akBottom]
             ColCount = 16
             DefaultColWidth = 16
    @@ -133,18 +90,18 @@
             OnSelectCell = StringGrid2SelectCell
           end
           object cbUniRange: TComboBox
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet2
    +        AnchorSideBottom.Control = pgUnicode
             AnchorSideBottom.Side = asrBottom
    -        Left = 280
    -        Height = 27
    -        Top = 357
    +        Left = 273
    +        Height = 23
    +        Top = 376
             Width = 291
             Anchors = [akRight, akBottom]
             BorderSpacing.Around = 6
             DropDownCount = 25
    -        ItemHeight = 23
    +        ItemHeight = 15
             OnSelect = cbUniRangeSelect
             Style = csDropDownList
             TabOrder = 1
    @@ -153,14 +110,114 @@
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             AnchorSideRight.Control = cbUniRange
    -        Left = 231
    -        Height = 17
    -        Top = 362
    -        Width = 43
    +        Left = 234
    +        Height = 15
    +        Top = 380
    +        Width = 33
             Anchors = [akTop, akRight]
             Caption = 'Range'
             ParentColor = False
           end
         end
    +    object pgAnsi: TTabSheet
    +      Caption = 'ANSI'
    +      ClientHeight = 405
    +      ClientWidth = 570
    +      object CharInfoLabel: TLabel
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 6
    +        Height = 15
    +        Top = 380
    +        Width = 74
    +        BorderSpacing.Around = 6
    +        Caption = 'CharInfoLabel'
    +        ParentColor = False
    +      end
    +      object StringGrid1: TStringGrid
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = pgAnsi
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = cbCodePage
    +        Left = 0
    +        Height = 370
    +        Top = 0
    +        Width = 570
    +        Anchors = [akTop, akLeft, akRight, akBottom]
    +        ColCount = 17
    +        DefaultColWidth = 16
    +        DefaultDrawing = False
    +        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    +        RowCount = 15
    +        TabOrder = 0
    +        OnKeyPress = StringGridKeyPress
    +        OnMouseDown = StringGridMouseDown
    +        OnMouseMove = StringGrid1MouseMove
    +        OnSelectCell = StringGrid1SelectCell
    +      end
    +      object cbCodePage: TComboBox
    +        AnchorSideTop.Control = StringGrid1
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 245
    +        Height = 23
    +        Top = 376
    +        Width = 319
    +        Anchors = [akRight, akBottom]
    +        BorderSpacing.Around = 6
    +        DropDownCount = 25
    +        ItemHeight = 15
    +        Items.Strings = (
    +          'cp1250 - Central and East European Latin'
    +          'cp1251 - Cyrillic'
    +          'cp1252 - West European Latin'
    +          'cp1253 - Greek'
    +          'cp1254 - Turkish'
    +          'cp1255 - Hebrew'
    +          'cp1256 - Arabic'
    +          'cp1257 - Baltic'
    +          'cp1258 - Vietnamese'
    +          'cp437 - Original IBM PC hardware'
    +          'cp850 - Latin-1'
    +          'cp852 - Latin-2'
    +          'cp866 - Belarusian, Russian, Ukrainian'
    +          'cp874 - Thai'
    +          'cp932 - Japanese'
    +          'cp936 - ANSI/OEM Simplified Chinese'
    +          'cp949 - Korean'
    +          'cp950 - Traditional Chinese'
    +          'macintosh'
    +          'koi8 - Ukrainean, Cyrillic'
    +          'iso88591 - ISO Latin-1 (Western Europe)'
    +          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
    +          'iso885915 - ISO Latin-9 (Western Europe)'
    +        )
    +        OnSelect = cbCodePageSelect
    +        Style = csDropDownList
    +        TabOrder = 1
    +      end
    +      object Label1: TLabel
    +        AnchorSideLeft.Control = CharInfoLabel
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = cbCodePage
    +        Left = 182
    +        Height = 15
    +        Top = 380
    +        Width = 57
    +        Anchors = [akTop, akRight]
    +        Caption = 'Code page'
    +        ParentColor = False
    +      end
    +    end
       end
     end
    Index: ide/charactermapdlg.pas
    ===================================================================
    --- ide/charactermapdlg.pas	(revision 51943)
    +++ ide/charactermapdlg.pas	(working copy)
    @@ -49,15 +49,18 @@
     
       TCharacterMapDialog = class(TForm)
         ButtonPanel: TButtonPanel;
    +    cbCodePage: TComboBox;
         CharInfoLabel: TLabel;
         cbUniRange: TComboBox;
    +    Label1: TLabel;
         RangeLabel: TLabel;
         UnicodeCharInfoLabel: TLabel;
         PageControl1: TPageControl;
         StringGrid1: TStringGrid;
         StringGrid2: TStringGrid;
    -    TabSheet1: TTabSheet;
    -    TabSheet2: TTabSheet;
    +    pgAnsi: TTabSheet;
    +    pgUnicode: TTabSheet;
    +    procedure cbCodePageSelect(Sender: TObject);
         procedure cbUniRangeSelect(Sender: TObject);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    @@ -79,6 +82,7 @@
         procedure DoStatusGrid1(ACol, ARow: integer);
         procedure DoStatusGrid2(ACol, ARow: integer);
         procedure FillCharMap;
    +    procedure SelectSystemCP;
       public
         property OnInsertCharacter: TOnInsertCharacterEvent read FOnInsertCharacter
                                                             write FOnInsertCharacter;
    @@ -93,6 +97,10 @@
     
     {$R *.lfm}
     
    +uses
    + {$ifdef WINDOWS}Windows,{$endif}
    +  lconvencoding;
    +
     procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
     begin
       if CharacterMapDialog = nil then
    @@ -112,11 +120,43 @@
       ButtonPanel.CloseButton.Caption:=lisBtnClose;
     
       //EnvironmentOptions.IDEWindowLayoutList.Apply(Self, Name);
    +  PageControl1.ActivePageIndex := 0;
       CharInfoLabel.Caption := '-';
       UnicodeCharInfoLabel.Caption := '-';
    +  SelectSystemCP;
       FillCharMap;
     end;
     
    +procedure TCharacterMapDialog.SelectSystemCP;
    +var
    +  i: Integer;
    +  cp: Word;
    +  cpStr: String;
    +begin
    + {$ifdef Windows}
    +  // Find system code page on Windows...
    +  // see: msdn.microsoft.com/library/windows/desktop/dd317756%28v=vs.85%29.aspx
    +  cp := Windows.GetACP;
    +  case cp of
    +    437..1258: cpStr := 'cp' + IntToStr(cp) + ' ';
    +    10000    : cpStr := 'macintosh ';
    +    20866    : cpStr := 'koi8 ';
    +    28591    : cpStr := 'iso88591 ';
    +    28592    : cpStr := 'iso88592 ';
    +    28605    : cpStr := 'iso885915 ';
    +    else       cpStr := '';
    +  end;
    +  for i := 0 to cbCodePage.Items.Count-1 do
    +    if pos(cpStr, cbCodePage.Items[i]) = 1 then
    +    begin
    +      cbCodePage.ItemIndex := i;
    +      exit;
    +    end;
    + {$endif}
    +  // ... if not found, or non-Windows, just pick the first item.
    +  cbCodePage.ItemIndex := 0;
    +end;
    +
     procedure TCharacterMapDialog.HelpButtonClick(Sender: TObject);
     begin
       LazarusHelp.ShowHelpForIDEControl(Self);
    @@ -129,6 +169,11 @@
        Result:=(Value div Divi)+1;
     end;
     
    +procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
    +begin
    +  FillCharMap;
    +end;
    +
     procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
     var cnt, x, y :integer;
     S,E:Integer;
    @@ -276,8 +321,12 @@
     
     procedure TCharacterMapDialog.FillCharMap;
     var
    -  R, C: Integer;
    +  R, C, p: Integer;
    +  cp: String;
     begin
    +  cp := cbCodePage.Items[cbCodePage.ItemIndex];
    +  p := pos(' ', cp);
    +  if p > 0 then SetLength(cp, p-1);
       for R := 0 to Pred(StringGrid1.RowCount) do
       begin
         if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
    @@ -285,7 +334,7 @@
         begin
           if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
           else
    -        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
    +        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
         end;
       end;
     end;
    
    ide-charmap-v2.patch (12,070 bytes)
  • ide-charmap-v3.patch (12,148 bytes)
    Index: ide/charactermapdlg.lfm
    ===================================================================
    --- ide/charactermapdlg.lfm	(revision 51943)
    +++ ide/charactermapdlg.lfm	(working copy)
    @@ -2,11 +2,11 @@
       Left = 370
       Height = 477
       Top = 128
    -  Width = 593
    +  Width = 590
       BorderStyle = bsSizeToolWin
       Caption = 'CharacterMapDialog'
       ClientHeight = 477
    -  ClientWidth = 593
    +  ClientWidth = 590
       FormStyle = fsStayOnTop
       KeyPreview = True
       OnCreate = FormCreate
    @@ -16,9 +16,9 @@
       LCLVersion = '1.7'
       object ButtonPanel: TButtonPanel
         Left = 6
    -    Height = 36
    -    Top = 435
    -    Width = 581
    +    Height = 26
    +    Top = 445
    +    Width = 578
         OKButton.Name = 'OKButton'
         OKButton.DefaultCaption = True
         OKButton.Enabled = False
    @@ -41,83 +41,40 @@
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = ButtonPanel
         Left = 6
    -    Height = 423
    +    Height = 433
         Top = 6
    -    Width = 581
    -    ActivePage = TabSheet1
    +    Width = 578
    +    ActivePage = pgUnicode
         Anchors = [akTop, akLeft, akRight, akBottom]
         BorderSpacing.Around = 6
         TabIndex = 0
         TabOrder = 0
    -    object TabSheet1: TTabSheet
    -      Caption = 'ANSI'
    -      ClientHeight = 390
    -      ClientWidth = 577
    -      object CharInfoLabel: TLabel
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Side = asrBottom
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet1
    -        AnchorSideBottom.Side = asrBottom
    -        Left = 6
    -        Height = 17
    -        Top = 367
    -        Width = 565
    -        Anchors = [akLeft, akRight, akBottom]
    -        BorderSpacing.Around = 6
    -        Caption = 'CharInfoLabel'
    -        ParentColor = False
    -      end
    -      object StringGrid1: TStringGrid
    -        AnchorSideLeft.Control = TabSheet1
    -        AnchorSideTop.Control = TabSheet1
    -        AnchorSideRight.Control = TabSheet1
    -        AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = CharInfoLabel
    -        Left = 0
    -        Height = 361
    -        Top = 0
    -        Width = 577
    -        Anchors = [akTop, akLeft, akRight, akBottom]
    -        ColCount = 17
    -        DefaultColWidth = 16
    -        DefaultDrawing = False
    -        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    -        RowCount = 15
    -        TabOrder = 0
    -        OnKeyPress = StringGridKeyPress
    -        OnMouseDown = StringGridMouseDown
    -        OnMouseMove = StringGrid1MouseMove
    -        OnSelectCell = StringGrid1SelectCell
    -      end
    -    end
    -    object TabSheet2: TTabSheet
    +    object pgUnicode: TTabSheet
           Caption = 'Unicode'
    -      ClientHeight = 390
    -      ClientWidth = 577
    +      ClientHeight = 405
    +      ClientWidth = 570
           object UnicodeCharInfoLabel: TLabel
             AnchorSideLeft.Control = Owner
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             Left = 6
    -        Height = 17
    -        Top = 362
    -        Width = 147
    +        Height = 15
    +        Top = 380
    +        Width = 118
             BorderSpacing.Around = 6
             Caption = 'UnicodeCharInfoLabel'
             ParentColor = False
           end
           object StringGrid2: TStringGrid
    -        AnchorSideLeft.Control = TabSheet2
    -        AnchorSideTop.Control = TabSheet2
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideLeft.Control = pgUnicode
    +        AnchorSideTop.Control = pgUnicode
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
             AnchorSideBottom.Control = cbUniRange
             Left = 0
    -        Height = 351
    +        Height = 370
             Top = 0
    -        Width = 577
    +        Width = 570
             Anchors = [akTop, akLeft, akRight, akBottom]
             ColCount = 16
             DefaultColWidth = 16
    @@ -133,18 +90,18 @@
             OnSelectCell = StringGrid2SelectCell
           end
           object cbUniRange: TComboBox
    -        AnchorSideRight.Control = TabSheet2
    +        AnchorSideRight.Control = pgUnicode
             AnchorSideRight.Side = asrBottom
    -        AnchorSideBottom.Control = TabSheet2
    +        AnchorSideBottom.Control = pgUnicode
             AnchorSideBottom.Side = asrBottom
    -        Left = 280
    -        Height = 27
    -        Top = 357
    +        Left = 273
    +        Height = 23
    +        Top = 376
             Width = 291
             Anchors = [akRight, akBottom]
             BorderSpacing.Around = 6
             DropDownCount = 25
    -        ItemHeight = 23
    +        ItemHeight = 15
             OnSelect = cbUniRangeSelect
             Style = csDropDownList
             TabOrder = 1
    @@ -153,14 +110,114 @@
             AnchorSideTop.Control = cbUniRange
             AnchorSideTop.Side = asrCenter
             AnchorSideRight.Control = cbUniRange
    -        Left = 231
    -        Height = 17
    -        Top = 362
    -        Width = 43
    +        Left = 234
    +        Height = 15
    +        Top = 380
    +        Width = 33
             Anchors = [akTop, akRight]
             Caption = 'Range'
             ParentColor = False
           end
         end
    +    object pgAnsi: TTabSheet
    +      Caption = 'ANSI'
    +      ClientHeight = 405
    +      ClientWidth = 570
    +      object CharInfoLabel: TLabel
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 6
    +        Height = 15
    +        Top = 380
    +        Width = 74
    +        BorderSpacing.Around = 6
    +        Caption = 'CharInfoLabel'
    +        ParentColor = False
    +      end
    +      object StringGrid1: TStringGrid
    +        AnchorSideLeft.Control = pgAnsi
    +        AnchorSideTop.Control = pgAnsi
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = cbCodePage
    +        Left = 0
    +        Height = 370
    +        Top = 0
    +        Width = 570
    +        Anchors = [akTop, akLeft, akRight, akBottom]
    +        ColCount = 17
    +        DefaultColWidth = 16
    +        DefaultDrawing = False
    +        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
    +        RowCount = 15
    +        TabOrder = 0
    +        OnKeyPress = StringGridKeyPress
    +        OnMouseDown = StringGridMouseDown
    +        OnMouseMove = StringGrid1MouseMove
    +        OnSelectCell = StringGrid1SelectCell
    +      end
    +      object cbCodePage: TComboBox
    +        AnchorSideTop.Control = StringGrid1
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = pgAnsi
    +        AnchorSideRight.Side = asrBottom
    +        AnchorSideBottom.Control = pgAnsi
    +        AnchorSideBottom.Side = asrBottom
    +        Left = 245
    +        Height = 23
    +        Top = 376
    +        Width = 319
    +        Anchors = [akRight, akBottom]
    +        BorderSpacing.Around = 6
    +        DropDownCount = 25
    +        ItemHeight = 15
    +        Items.Strings = (
    +          'cp1250 - Central and East European Latin'
    +          'cp1251 - Cyrillic'
    +          'cp1252 - West European Latin'
    +          'cp1253 - Greek'
    +          'cp1254 - Turkish'
    +          'cp1255 - Hebrew'
    +          'cp1256 - Arabic'
    +          'cp1257 - Baltic'
    +          'cp1258 - Vietnamese'
    +          'cp437 - Original IBM PC hardware'
    +          'cp850 - Latin-1'
    +          'cp852 - Latin-2'
    +          'cp866 - Belarusian, Russian, Ukrainian'
    +          'cp874 - Thai'
    +          'cp932 - Japanese'
    +          'cp936 - ANSI/OEM Simplified Chinese'
    +          'cp949 - Korean'
    +          'cp950 - Traditional Chinese'
    +          'macintosh - MAC Roman (Western Europe)'
    +          'koi8 - Ukrainean, Cyrillic'
    +          'iso88591 - ISO Latin-1 (Western Europe)'
    +          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
    +          'iso885915 - ISO Latin-9 (Western Europe)'
    +        )
    +        OnSelect = cbCodePageSelect
    +        Style = csDropDownList
    +        TabOrder = 1
    +      end
    +      object Label1: TLabel
    +        AnchorSideLeft.Control = CharInfoLabel
    +        AnchorSideTop.Control = cbCodePage
    +        AnchorSideTop.Side = asrCenter
    +        AnchorSideRight.Control = cbCodePage
    +        Left = 182
    +        Height = 15
    +        Top = 380
    +        Width = 57
    +        Anchors = [akTop, akRight]
    +        Caption = 'Code page'
    +        ParentColor = False
    +      end
    +    end
       end
     end
    Index: ide/charactermapdlg.pas
    ===================================================================
    --- ide/charactermapdlg.pas	(revision 51943)
    +++ ide/charactermapdlg.pas	(working copy)
    @@ -49,15 +49,18 @@
     
       TCharacterMapDialog = class(TForm)
         ButtonPanel: TButtonPanel;
    +    cbCodePage: TComboBox;
         CharInfoLabel: TLabel;
         cbUniRange: TComboBox;
    +    Label1: TLabel;
         RangeLabel: TLabel;
         UnicodeCharInfoLabel: TLabel;
         PageControl1: TPageControl;
         StringGrid1: TStringGrid;
         StringGrid2: TStringGrid;
    -    TabSheet1: TTabSheet;
    -    TabSheet2: TTabSheet;
    +    pgAnsi: TTabSheet;
    +    pgUnicode: TTabSheet;
    +    procedure cbCodePageSelect(Sender: TObject);
         procedure cbUniRangeSelect(Sender: TObject);
         procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
         procedure HelpButtonClick(Sender: TObject);
    @@ -79,6 +82,7 @@
         procedure DoStatusGrid1(ACol, ARow: integer);
         procedure DoStatusGrid2(ACol, ARow: integer);
         procedure FillCharMap;
    +    procedure SelectSystemCP;
       public
         property OnInsertCharacter: TOnInsertCharacterEvent read FOnInsertCharacter
                                                             write FOnInsertCharacter;
    @@ -93,6 +97,10 @@
     
     {$R *.lfm}
     
    +uses
    + {$ifdef WINDOWS}Windows,{$endif}
    +  lconvencoding;
    +
     procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
     begin
       if CharacterMapDialog = nil then
    @@ -112,11 +120,43 @@
       ButtonPanel.CloseButton.Caption:=lisBtnClose;
     
       //EnvironmentOptions.IDEWindowLayoutList.Apply(Self, Name);
    +  PageControl1.ActivePageIndex := 0;
       CharInfoLabel.Caption := '-';
       UnicodeCharInfoLabel.Caption := '-';
    +  SelectSystemCP;
       FillCharMap;
     end;
     
    +procedure TCharacterMapDialog.SelectSystemCP;
    +var
    +  i: Integer;
    +  cp: Word;
    +  cpStr: String;
    +begin
    + {$ifdef Windows}
    +  // Find system code page on Windows...
    +  // see: msdn.microsoft.com/library/windows/desktop/dd317756%28v=vs.85%29.aspx
    +  cp := Windows.GetACP;
    +  case cp of  // add spaces to be sure of unique names found in the combobox
    +    437..1258: cpStr := 'cp' + IntToStr(cp) + ' ';
    +    10000    : cpStr := 'macintosh ';
    +    20866    : cpStr := 'koi8 ';
    +    28591    : cpStr := 'iso88591 ';
    +    28592    : cpStr := 'iso88592 ';
    +    28605    : cpStr := 'iso885915 ';
    +    else       cpStr := '';
    +  end;
    +  for i := 0 to cbCodePage.Items.Count-1 do
    +    if pos(cpStr, cbCodePage.Items[i]) = 1 then
    +    begin
    +      cbCodePage.ItemIndex := i;
    +      exit;
    +    end;
    + {$endif}
    +  // ... if not found, or non-Windows, just pick the first item.
    +  cbCodePage.ItemIndex := 0;
    +end;
    +
     procedure TCharacterMapDialog.HelpButtonClick(Sender: TObject);
     begin
       LazarusHelp.ShowHelpForIDEControl(Self);
    @@ -129,6 +169,11 @@
        Result:=(Value div Divi)+1;
     end;
     
    +procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
    +begin
    +  FillCharMap;
    +end;
    +
     procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
     var cnt, x, y :integer;
     S,E:Integer;
    @@ -276,8 +321,12 @@
     
     procedure TCharacterMapDialog.FillCharMap;
     var
    -  R, C: Integer;
    +  R, C, p: Integer;
    +  cp: String;
     begin
    +  cp := cbCodePage.Items[cbCodePage.ItemIndex];
    +  p := pos(' ', cp);
    +  if p > 0 then SetLength(cp, p-1);
       for R := 0 to Pred(StringGrid1.RowCount) do
       begin
         if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
    @@ -285,7 +334,7 @@
         begin
           if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
           else
    -        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
    +        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
         end;
       end;
     end;
    
    ide-charmap-v3.patch (12,148 bytes)

Relationships

related to 0029078 resolvedJuha Manninen Patches CharMap improve 
related to 0031269 resolvedwp Lazarus Combo box for language selection on Unicode page of Chachcter map window is too small 

Activities

Alexey Tor.

2016-03-18 19:38

reporter  

charmap-laz.png (12,756 bytes)
charmap-laz.png (12,756 bytes)

FTurtle

2016-03-18 20:10

reporter   ~0091184

Try see 0029078, r50710

Alexey Tor.

2016-03-18 23:06

reporter   ~0091188

Last edited: 2016-03-18 23:09

View 3 revisions

Not shown - reason: AnsiToUtf8 (If i correct it's called for ansi mode) gets none for codes 128..255. Not my patch cozes it. Some RTL code cozes it.

characterMapDlg.pas
    begin
      if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
      else
        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
    end;

FTurtle

2016-03-18 23:59

reporter   ~0091189

At least this works:

procedure TCharacterMapDialog.FillCharMap;
type
  OneByteString = type AnsiString(1252); // any 1-byte cp
var
  R, C: Integer;
  s: OneByteString;
begin
  SetLength(s, 1);
  for R := 0 to Pred(StringGrid1.RowCount) do
  begin
    if R <> 0 then StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
    for C := 1 to Pred(StringGrid1.ColCount) do
    begin
      if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
      else
      begin
        s[1] := Chr(Succ(R) * 16 + Pred(C));
        SetCodePage(RawByteString(s), 1251, False);
        StringGrid1.Cells[C, R] := s;
      end;
    end;
  end;
end;

FTurtle

2016-03-19 00:17

reporter   ~0091190

You're right, it looks like the problem arose after transition to FPC 3.0

FTurtle

2016-03-19 08:49

reporter   ~0091192

Last edited: 2016-03-19 09:18

View 2 revisions

I think the cause is:

1. At some place single byte with value of 128..255 treated as UTF-8 string.
2. Byte with such value may be only a part of multibyte sequence.
3. This byte treated as wrong UTF-8 symbol and silently removed.
4. Grid cell gets empty string.

I think that silent removing of wrong UTF-8 symbol is highly dangerous behaviour.

FTurtle

2016-03-19 09:01

reporter   ~0091193

Also I think that the behaviour of TRawString is highly wrong now.
In code above I should be able write:

procedure TCharacterMapDialog.FillCharMap;
var
  R, C: Integer;
  s: RawByteString;

instead:

procedure TCharacterMapDialog.FillCharMap;
type
  OneByteString = type AnsiString(1252); // any 1-byte cp
var
  R, C: Integer;
  s: OneByteString;

Bart Broersma

2016-03-19 13:33

developer   ~0091200

Another way to look at this: since Lazarus/LCL is entirely UTF8 based, we should not show any Char above Chr(127), since this has no meaning in UTF8.
So, rename "ANSI" to "ASCII" and use "Unicode" Tab for all other codepoints.

wp

2016-03-19 17:06

developer   ~0091202

Last edited: 2016-03-19 17:27

View 2 revisions

> rename "ANSI" to "ASCII"

I think this is a step back. When dealing with ANSI files it is good to have an ANSI character map quickly at hand, and I would even appreciate to see all the other code pages in the char map - Lazarus has everything which is needed.

I am attaching screen shots of the charmap of Laz144 and Laz16.

wp

2016-03-19 17:08

developer  

charmap_cp1252_laz144.png (31,505 bytes)
charmap_cp1252_laz144.png (31,505 bytes)

wp

2016-03-19 17:08

developer  

Bart Broersma

2016-03-19 17:47

developer   ~0091203

Playing devils advocate:
1. The Unicode Tab has (almost) all you want.
2. The CharMap is meant for inserting characters, not as a lookup-table
3. How many Windows codepages do you want to support?

But seriously. I think we should move our designer away from ANSI relicts, and fuly focus on being Unicode compatible.

Bart Broersma

2016-03-19 17:50

developer   ~0091204

> 3. This byte treated as wrong UTF-8 symbol and silently removed.
No: see screenshot from wp: the strings are not empty, just not proper UTF8.

Bart Broersma

2016-03-19 18:06

developer   ~0091205

Does replacing AnsiToUTF8 with WinCPToUTF8 change anything?

Bart Broersma

2016-03-19 18:24

developer  

Bart Broersma

2016-03-19 18:26

developer   ~0091206

> Does replacing AnsiToUTF8 with WinCPToUTF8 change anything?

See: charmap-laz-1.7-fpc-3-0-0-wincptoutf8.png
I replaced AnsiToUTF8 with WinCPToUTF8.

Patch attached (charmap.diff).
@All: Please test with attached patch.

Bart Broersma

2016-03-19 18:27

developer  

charmap.diff (488 bytes)
Index: ide/charactermapdlg.pas
===================================================================
--- ide/charactermapdlg.pas	(revision 51837)
+++ ide/charactermapdlg.pas	(working copy)
@@ -285,7 +285,7 @@
     begin
       if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
       else
-        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
+        StringGrid1.Cells[C, R] := WinCPToUtf8(Chr(Succ(R) * 16 + Pred(C)));
     end;
   end;
 end;
charmap.diff (488 bytes)

FTurtle

2016-03-19 18:39

reporter   ~0091207

> No: see screenshot from wp: the strings are not empty, just not proper UTF8.

Really length=0.

Tested with:
fpc 3.0.0
Lazarus 1.7
Russian Windows XP

> Does replacing AnsiToUTF8 with WinCPToUTF8 change anything?

Yes, it works properly:

      else
        // StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
        StringGrid1.Cells[C, R] := WinCPToUTF8(Chr(Succ(R) * 16 + Pred(C)));

wp

2016-03-19 18:45

developer  

ide-charmap.patch (10,478 bytes)
Index: ide/charactermapdlg.lfm
===================================================================
--- ide/charactermapdlg.lfm	(revision 51943)
+++ ide/charactermapdlg.lfm	(working copy)
@@ -2,11 +2,11 @@
   Left = 370
   Height = 477
   Top = 128
-  Width = 593
+  Width = 590
   BorderStyle = bsSizeToolWin
   Caption = 'CharacterMapDialog'
   ClientHeight = 477
-  ClientWidth = 593
+  ClientWidth = 590
   FormStyle = fsStayOnTop
   KeyPreview = True
   OnCreate = FormCreate
@@ -16,9 +16,9 @@
   LCLVersion = '1.7'
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 36
-    Top = 435
-    Width = 581
+    Height = 26
+    Top = 445
+    Width = 578
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
     OKButton.Enabled = False
@@ -41,83 +41,40 @@
     AnchorSideRight.Side = asrBottom
     AnchorSideBottom.Control = ButtonPanel
     Left = 6
-    Height = 423
+    Height = 433
     Top = 6
-    Width = 581
-    ActivePage = TabSheet1
+    Width = 578
+    ActivePage = pgUnicode
     Anchors = [akTop, akLeft, akRight, akBottom]
     BorderSpacing.Around = 6
     TabIndex = 0
     TabOrder = 0
-    object TabSheet1: TTabSheet
-      Caption = 'ANSI'
-      ClientHeight = 390
-      ClientWidth = 577
-      object CharInfoLabel: TLabel
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Side = asrBottom
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet1
-        AnchorSideBottom.Side = asrBottom
-        Left = 6
-        Height = 17
-        Top = 367
-        Width = 565
-        Anchors = [akLeft, akRight, akBottom]
-        BorderSpacing.Around = 6
-        Caption = 'CharInfoLabel'
-        ParentColor = False
-      end
-      object StringGrid1: TStringGrid
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Control = TabSheet1
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = CharInfoLabel
-        Left = 0
-        Height = 361
-        Top = 0
-        Width = 577
-        Anchors = [akTop, akLeft, akRight, akBottom]
-        ColCount = 17
-        DefaultColWidth = 16
-        DefaultDrawing = False
-        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
-        RowCount = 15
-        TabOrder = 0
-        OnKeyPress = StringGridKeyPress
-        OnMouseDown = StringGridMouseDown
-        OnMouseMove = StringGrid1MouseMove
-        OnSelectCell = StringGrid1SelectCell
-      end
-    end
-    object TabSheet2: TTabSheet
+    object pgUnicode: TTabSheet
       Caption = 'Unicode'
-      ClientHeight = 390
-      ClientWidth = 577
+      ClientHeight = 405
+      ClientWidth = 570
       object UnicodeCharInfoLabel: TLabel
         AnchorSideLeft.Control = Owner
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         Left = 6
-        Height = 17
-        Top = 362
-        Width = 147
+        Height = 15
+        Top = 380
+        Width = 118
         BorderSpacing.Around = 6
         Caption = 'UnicodeCharInfoLabel'
         ParentColor = False
       end
       object StringGrid2: TStringGrid
-        AnchorSideLeft.Control = TabSheet2
-        AnchorSideTop.Control = TabSheet2
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideLeft.Control = pgUnicode
+        AnchorSideTop.Control = pgUnicode
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = cbUniRange
         Left = 0
-        Height = 351
+        Height = 370
         Top = 0
-        Width = 577
+        Width = 570
         Anchors = [akTop, akLeft, akRight, akBottom]
         ColCount = 16
         DefaultColWidth = 16
@@ -133,18 +90,18 @@
         OnSelectCell = StringGrid2SelectCell
       end
       object cbUniRange: TComboBox
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet2
+        AnchorSideBottom.Control = pgUnicode
         AnchorSideBottom.Side = asrBottom
-        Left = 280
-        Height = 27
-        Top = 357
+        Left = 273
+        Height = 23
+        Top = 376
         Width = 291
         Anchors = [akRight, akBottom]
         BorderSpacing.Around = 6
         DropDownCount = 25
-        ItemHeight = 23
+        ItemHeight = 15
         OnSelect = cbUniRangeSelect
         Style = csDropDownList
         TabOrder = 1
@@ -153,14 +110,116 @@
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         AnchorSideRight.Control = cbUniRange
-        Left = 231
-        Height = 17
-        Top = 362
-        Width = 43
+        Left = 234
+        Height = 15
+        Top = 380
+        Width = 33
         Anchors = [akTop, akRight]
         Caption = 'Range'
         ParentColor = False
       end
     end
+    object pgAnsi: TTabSheet
+      Caption = 'ANSI'
+      ClientHeight = 405
+      ClientWidth = 570
+      object CharInfoLabel: TLabel
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 6
+        Height = 15
+        Top = 380
+        Width = 74
+        BorderSpacing.Around = 6
+        Caption = 'CharInfoLabel'
+        ParentColor = False
+      end
+      object StringGrid1: TStringGrid
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = pgAnsi
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = cbCodePage
+        Left = 0
+        Height = 370
+        Top = 0
+        Width = 570
+        Anchors = [akTop, akLeft, akRight, akBottom]
+        ColCount = 17
+        DefaultColWidth = 16
+        DefaultDrawing = False
+        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
+        RowCount = 15
+        TabOrder = 0
+        OnKeyPress = StringGridKeyPress
+        OnMouseDown = StringGridMouseDown
+        OnMouseMove = StringGrid1MouseMove
+        OnSelectCell = StringGrid1SelectCell
+      end
+      object cbCodePage: TComboBox
+        AnchorSideTop.Control = StringGrid1
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 245
+        Height = 23
+        Top = 376
+        Width = 319
+        Anchors = [akRight, akBottom]
+        BorderSpacing.Around = 6
+        DropDownCount = 25
+        ItemHeight = 15
+        ItemIndex = 0
+        Items.Strings = (
+          'cp1250 - Central and East European Latin'
+          'cp1251 - Cyrillic'
+          'cp1252 - West European Latin'
+          'cp1253 - Greek'
+          'cp1254 - Turkish'
+          'cp1255 - Hebrew'
+          'cp1256 - Arabic'
+          'cp1257 - Baltic'
+          'cp1258 - Vietnamese'
+          'cp437 - Original IBM PC hardware'
+          'cp850 - Latin-1'
+          'cp852 - Latin-2'
+          'cp866 - Belarusian, Russian, Ukrainian'
+          'cp874 - Thai'
+          'cp932 - Japanese'
+          'cp936 - ANSI/OEM Simplified Chinese'
+          'cp949 - Korean'
+          'cp950 - Traditional Chinese'
+          'macintosh'
+          'koi8'
+          'iso88591 - ISO Latin-1 (Western Europe)'
+          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
+          'iso885915 - ISO Latin-9 (Western Europe)'
+        )
+        OnSelect = cbCodePageSelect
+        Style = csDropDownList
+        TabOrder = 1
+        Text = 'cp1250 - Central and East European Latin'
+      end
+      object Label1: TLabel
+        AnchorSideLeft.Control = CharInfoLabel
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = cbCodePage
+        Left = 182
+        Height = 15
+        Top = 380
+        Width = 57
+        Anchors = [akTop, akRight]
+        Caption = 'Code page'
+        ParentColor = False
+      end
+    end
   end
 end
Index: ide/charactermapdlg.pas
===================================================================
--- ide/charactermapdlg.pas	(revision 51943)
+++ ide/charactermapdlg.pas	(working copy)
@@ -49,15 +49,18 @@
 
   TCharacterMapDialog = class(TForm)
     ButtonPanel: TButtonPanel;
+    cbCodePage: TComboBox;
     CharInfoLabel: TLabel;
     cbUniRange: TComboBox;
+    Label1: TLabel;
     RangeLabel: TLabel;
     UnicodeCharInfoLabel: TLabel;
     PageControl1: TPageControl;
     StringGrid1: TStringGrid;
     StringGrid2: TStringGrid;
-    TabSheet1: TTabSheet;
-    TabSheet2: TTabSheet;
+    pgAnsi: TTabSheet;
+    pgUnicode: TTabSheet;
+    procedure cbCodePageSelect(Sender: TObject);
     procedure cbUniRangeSelect(Sender: TObject);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
@@ -93,6 +96,9 @@
 
 {$R *.lfm}
 
+uses
+  lconvencoding;
+
 procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
 begin
   if CharacterMapDialog = nil then
@@ -129,6 +135,11 @@
    Result:=(Value div Divi)+1;
 end;
 
+procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
+begin
+  FillCharMap;
+end;
+
 procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
 var cnt, x, y :integer;
 S,E:Integer;
@@ -276,8 +287,12 @@
 
 procedure TCharacterMapDialog.FillCharMap;
 var
-  R, C: Integer;
+  R, C, p: Integer;
+  cp: String;
 begin
+  cp := cbCodePage.Items[cbCodePage.ItemIndex];
+  p := pos(' ', cp);
+  if p > 0 then SetLength(cp, p-1);
   for R := 0 to Pred(StringGrid1.RowCount) do
   begin
     if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
@@ -285,7 +300,7 @@
     begin
       if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
       else
-        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
+        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
     end;
   end;
 end;
ide-charmap.patch (10,478 bytes)

wp

2016-03-19 18:48

developer   ~0091208

I added another patch which extends the ANSI charmap such that all code pages available in lconvencoding can be displayed. Works fine for me (Win 7/CP1252, I just don't see the Asian characters of the DOS code pages - maybe the Courier font used by the editor doesn't contain them?

Since ANSI is less important now, I moved the Unicode page to the top.

Bart Broersma

2016-03-19 18:53

developer   ~0091209

Last edited: 2016-03-19 18:58

View 2 revisions

@WP Looks nice!
Q: Does your new ANSI page (combobox) default to the current OS's codepage?

wp

2016-03-19 19:06

developer   ~0091211

Not at the moment. How do I get that? Once I know the number, I just have to find the item in the combobox and preselect it.

Bart Broersma

2016-03-19 19:18

developer   ~0091213

Last edited: 2016-03-19 19:24

View 3 revisions

On Windows: Windows.GetACP()
Not sure if there is an fpc cross-platform function for that.

[Edit] See the remarks here: http://wiki.lazarus.freepascal.org/FPC_Unicode_support#DefaultSystemCodePage

So, maybe just bother on Windows?

Bart Broersma

2016-03-19 19:26

developer   ~0091214

You might need this table to translate the returnvalue into one of the strings used in te combobox: https://msdn.microsoft.com/nl-nl/library/windows/desktop/dd317756%28v=vs.85%29.aspx

wp

2016-03-19 20:05

developer   ~0091215

The new patch (-v2) selects the combobox item for the system code page on windows, or the first item if not found or on other OS. Could test only for cp1252 which works.

wp

2016-03-19 20:05

developer  

ide-charmap-v2.patch (12,070 bytes)
Index: ide/charactermapdlg.lfm
===================================================================
--- ide/charactermapdlg.lfm	(revision 51943)
+++ ide/charactermapdlg.lfm	(working copy)
@@ -2,11 +2,11 @@
   Left = 370
   Height = 477
   Top = 128
-  Width = 593
+  Width = 590
   BorderStyle = bsSizeToolWin
   Caption = 'CharacterMapDialog'
   ClientHeight = 477
-  ClientWidth = 593
+  ClientWidth = 590
   FormStyle = fsStayOnTop
   KeyPreview = True
   OnCreate = FormCreate
@@ -16,9 +16,9 @@
   LCLVersion = '1.7'
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 36
-    Top = 435
-    Width = 581
+    Height = 26
+    Top = 445
+    Width = 578
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
     OKButton.Enabled = False
@@ -41,83 +41,40 @@
     AnchorSideRight.Side = asrBottom
     AnchorSideBottom.Control = ButtonPanel
     Left = 6
-    Height = 423
+    Height = 433
     Top = 6
-    Width = 581
-    ActivePage = TabSheet1
+    Width = 578
+    ActivePage = pgAnsi
     Anchors = [akTop, akLeft, akRight, akBottom]
     BorderSpacing.Around = 6
-    TabIndex = 0
+    TabIndex = 1
     TabOrder = 0
-    object TabSheet1: TTabSheet
-      Caption = 'ANSI'
-      ClientHeight = 390
-      ClientWidth = 577
-      object CharInfoLabel: TLabel
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Side = asrBottom
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet1
-        AnchorSideBottom.Side = asrBottom
-        Left = 6
-        Height = 17
-        Top = 367
-        Width = 565
-        Anchors = [akLeft, akRight, akBottom]
-        BorderSpacing.Around = 6
-        Caption = 'CharInfoLabel'
-        ParentColor = False
-      end
-      object StringGrid1: TStringGrid
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Control = TabSheet1
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = CharInfoLabel
-        Left = 0
-        Height = 361
-        Top = 0
-        Width = 577
-        Anchors = [akTop, akLeft, akRight, akBottom]
-        ColCount = 17
-        DefaultColWidth = 16
-        DefaultDrawing = False
-        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
-        RowCount = 15
-        TabOrder = 0
-        OnKeyPress = StringGridKeyPress
-        OnMouseDown = StringGridMouseDown
-        OnMouseMove = StringGrid1MouseMove
-        OnSelectCell = StringGrid1SelectCell
-      end
-    end
-    object TabSheet2: TTabSheet
+    object pgUnicode: TTabSheet
       Caption = 'Unicode'
-      ClientHeight = 390
-      ClientWidth = 577
+      ClientHeight = 405
+      ClientWidth = 570
       object UnicodeCharInfoLabel: TLabel
         AnchorSideLeft.Control = Owner
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         Left = 6
-        Height = 17
-        Top = 362
-        Width = 147
+        Height = 15
+        Top = 380
+        Width = 118
         BorderSpacing.Around = 6
         Caption = 'UnicodeCharInfoLabel'
         ParentColor = False
       end
       object StringGrid2: TStringGrid
-        AnchorSideLeft.Control = TabSheet2
-        AnchorSideTop.Control = TabSheet2
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideLeft.Control = pgUnicode
+        AnchorSideTop.Control = pgUnicode
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = cbUniRange
         Left = 0
-        Height = 351
+        Height = 370
         Top = 0
-        Width = 577
+        Width = 570
         Anchors = [akTop, akLeft, akRight, akBottom]
         ColCount = 16
         DefaultColWidth = 16
@@ -133,18 +90,18 @@
         OnSelectCell = StringGrid2SelectCell
       end
       object cbUniRange: TComboBox
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet2
+        AnchorSideBottom.Control = pgUnicode
         AnchorSideBottom.Side = asrBottom
-        Left = 280
-        Height = 27
-        Top = 357
+        Left = 273
+        Height = 23
+        Top = 376
         Width = 291
         Anchors = [akRight, akBottom]
         BorderSpacing.Around = 6
         DropDownCount = 25
-        ItemHeight = 23
+        ItemHeight = 15
         OnSelect = cbUniRangeSelect
         Style = csDropDownList
         TabOrder = 1
@@ -153,14 +110,114 @@
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         AnchorSideRight.Control = cbUniRange
-        Left = 231
-        Height = 17
-        Top = 362
-        Width = 43
+        Left = 234
+        Height = 15
+        Top = 380
+        Width = 33
         Anchors = [akTop, akRight]
         Caption = 'Range'
         ParentColor = False
       end
     end
+    object pgAnsi: TTabSheet
+      Caption = 'ANSI'
+      ClientHeight = 405
+      ClientWidth = 570
+      object CharInfoLabel: TLabel
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 6
+        Height = 15
+        Top = 380
+        Width = 74
+        BorderSpacing.Around = 6
+        Caption = 'CharInfoLabel'
+        ParentColor = False
+      end
+      object StringGrid1: TStringGrid
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = pgAnsi
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = cbCodePage
+        Left = 0
+        Height = 370
+        Top = 0
+        Width = 570
+        Anchors = [akTop, akLeft, akRight, akBottom]
+        ColCount = 17
+        DefaultColWidth = 16
+        DefaultDrawing = False
+        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
+        RowCount = 15
+        TabOrder = 0
+        OnKeyPress = StringGridKeyPress
+        OnMouseDown = StringGridMouseDown
+        OnMouseMove = StringGrid1MouseMove
+        OnSelectCell = StringGrid1SelectCell
+      end
+      object cbCodePage: TComboBox
+        AnchorSideTop.Control = StringGrid1
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 245
+        Height = 23
+        Top = 376
+        Width = 319
+        Anchors = [akRight, akBottom]
+        BorderSpacing.Around = 6
+        DropDownCount = 25
+        ItemHeight = 15
+        Items.Strings = (
+          'cp1250 - Central and East European Latin'
+          'cp1251 - Cyrillic'
+          'cp1252 - West European Latin'
+          'cp1253 - Greek'
+          'cp1254 - Turkish'
+          'cp1255 - Hebrew'
+          'cp1256 - Arabic'
+          'cp1257 - Baltic'
+          'cp1258 - Vietnamese'
+          'cp437 - Original IBM PC hardware'
+          'cp850 - Latin-1'
+          'cp852 - Latin-2'
+          'cp866 - Belarusian, Russian, Ukrainian'
+          'cp874 - Thai'
+          'cp932 - Japanese'
+          'cp936 - ANSI/OEM Simplified Chinese'
+          'cp949 - Korean'
+          'cp950 - Traditional Chinese'
+          'macintosh'
+          'koi8 - Ukrainean, Cyrillic'
+          'iso88591 - ISO Latin-1 (Western Europe)'
+          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
+          'iso885915 - ISO Latin-9 (Western Europe)'
+        )
+        OnSelect = cbCodePageSelect
+        Style = csDropDownList
+        TabOrder = 1
+      end
+      object Label1: TLabel
+        AnchorSideLeft.Control = CharInfoLabel
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = cbCodePage
+        Left = 182
+        Height = 15
+        Top = 380
+        Width = 57
+        Anchors = [akTop, akRight]
+        Caption = 'Code page'
+        ParentColor = False
+      end
+    end
   end
 end
Index: ide/charactermapdlg.pas
===================================================================
--- ide/charactermapdlg.pas	(revision 51943)
+++ ide/charactermapdlg.pas	(working copy)
@@ -49,15 +49,18 @@
 
   TCharacterMapDialog = class(TForm)
     ButtonPanel: TButtonPanel;
+    cbCodePage: TComboBox;
     CharInfoLabel: TLabel;
     cbUniRange: TComboBox;
+    Label1: TLabel;
     RangeLabel: TLabel;
     UnicodeCharInfoLabel: TLabel;
     PageControl1: TPageControl;
     StringGrid1: TStringGrid;
     StringGrid2: TStringGrid;
-    TabSheet1: TTabSheet;
-    TabSheet2: TTabSheet;
+    pgAnsi: TTabSheet;
+    pgUnicode: TTabSheet;
+    procedure cbCodePageSelect(Sender: TObject);
     procedure cbUniRangeSelect(Sender: TObject);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
@@ -79,6 +82,7 @@
     procedure DoStatusGrid1(ACol, ARow: integer);
     procedure DoStatusGrid2(ACol, ARow: integer);
     procedure FillCharMap;
+    procedure SelectSystemCP;
   public
     property OnInsertCharacter: TOnInsertCharacterEvent read FOnInsertCharacter
                                                         write FOnInsertCharacter;
@@ -93,6 +97,10 @@
 
 {$R *.lfm}
 
+uses
+ {$ifdef WINDOWS}Windows,{$endif}
+  lconvencoding;
+
 procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
 begin
   if CharacterMapDialog = nil then
@@ -112,11 +120,43 @@
   ButtonPanel.CloseButton.Caption:=lisBtnClose;
 
   //EnvironmentOptions.IDEWindowLayoutList.Apply(Self, Name);
+  PageControl1.ActivePageIndex := 0;
   CharInfoLabel.Caption := '-';
   UnicodeCharInfoLabel.Caption := '-';
+  SelectSystemCP;
   FillCharMap;
 end;
 
+procedure TCharacterMapDialog.SelectSystemCP;
+var
+  i: Integer;
+  cp: Word;
+  cpStr: String;
+begin
+ {$ifdef Windows}
+  // Find system code page on Windows...
+  // see: msdn.microsoft.com/library/windows/desktop/dd317756%28v=vs.85%29.aspx
+  cp := Windows.GetACP;
+  case cp of
+    437..1258: cpStr := 'cp' + IntToStr(cp) + ' ';
+    10000    : cpStr := 'macintosh ';
+    20866    : cpStr := 'koi8 ';
+    28591    : cpStr := 'iso88591 ';
+    28592    : cpStr := 'iso88592 ';
+    28605    : cpStr := 'iso885915 ';
+    else       cpStr := '';
+  end;
+  for i := 0 to cbCodePage.Items.Count-1 do
+    if pos(cpStr, cbCodePage.Items[i]) = 1 then
+    begin
+      cbCodePage.ItemIndex := i;
+      exit;
+    end;
+ {$endif}
+  // ... if not found, or non-Windows, just pick the first item.
+  cbCodePage.ItemIndex := 0;
+end;
+
 procedure TCharacterMapDialog.HelpButtonClick(Sender: TObject);
 begin
   LazarusHelp.ShowHelpForIDEControl(Self);
@@ -129,6 +169,11 @@
    Result:=(Value div Divi)+1;
 end;
 
+procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
+begin
+  FillCharMap;
+end;
+
 procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
 var cnt, x, y :integer;
 S,E:Integer;
@@ -276,8 +321,12 @@
 
 procedure TCharacterMapDialog.FillCharMap;
 var
-  R, C: Integer;
+  R, C, p: Integer;
+  cp: String;
 begin
+  cp := cbCodePage.Items[cbCodePage.ItemIndex];
+  p := pos(' ', cp);
+  if p > 0 then SetLength(cp, p-1);
   for R := 0 to Pred(StringGrid1.RowCount) do
   begin
     if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
@@ -285,7 +334,7 @@
     begin
       if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
       else
-        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
+        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
     end;
   end;
 end;
ide-charmap-v2.patch (12,070 bytes)

Anton

2016-03-19 21:03

reporter   ~0091217

You have "macintosh" without space at the end. Not sure Windows.GetACP will return such value...

wp

2016-03-19 22:16

developer   ~0091219

Patch -v3 should fix this.

No, Windows.GetACP does not return such a value, it just returns numbers. In the case instruction the number is converted to a string with which the corresponding combobox item begins.

wp

2016-03-19 22:16

developer  

ide-charmap-v3.patch (12,148 bytes)
Index: ide/charactermapdlg.lfm
===================================================================
--- ide/charactermapdlg.lfm	(revision 51943)
+++ ide/charactermapdlg.lfm	(working copy)
@@ -2,11 +2,11 @@
   Left = 370
   Height = 477
   Top = 128
-  Width = 593
+  Width = 590
   BorderStyle = bsSizeToolWin
   Caption = 'CharacterMapDialog'
   ClientHeight = 477
-  ClientWidth = 593
+  ClientWidth = 590
   FormStyle = fsStayOnTop
   KeyPreview = True
   OnCreate = FormCreate
@@ -16,9 +16,9 @@
   LCLVersion = '1.7'
   object ButtonPanel: TButtonPanel
     Left = 6
-    Height = 36
-    Top = 435
-    Width = 581
+    Height = 26
+    Top = 445
+    Width = 578
     OKButton.Name = 'OKButton'
     OKButton.DefaultCaption = True
     OKButton.Enabled = False
@@ -41,83 +41,40 @@
     AnchorSideRight.Side = asrBottom
     AnchorSideBottom.Control = ButtonPanel
     Left = 6
-    Height = 423
+    Height = 433
     Top = 6
-    Width = 581
-    ActivePage = TabSheet1
+    Width = 578
+    ActivePage = pgUnicode
     Anchors = [akTop, akLeft, akRight, akBottom]
     BorderSpacing.Around = 6
     TabIndex = 0
     TabOrder = 0
-    object TabSheet1: TTabSheet
-      Caption = 'ANSI'
-      ClientHeight = 390
-      ClientWidth = 577
-      object CharInfoLabel: TLabel
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Side = asrBottom
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet1
-        AnchorSideBottom.Side = asrBottom
-        Left = 6
-        Height = 17
-        Top = 367
-        Width = 565
-        Anchors = [akLeft, akRight, akBottom]
-        BorderSpacing.Around = 6
-        Caption = 'CharInfoLabel'
-        ParentColor = False
-      end
-      object StringGrid1: TStringGrid
-        AnchorSideLeft.Control = TabSheet1
-        AnchorSideTop.Control = TabSheet1
-        AnchorSideRight.Control = TabSheet1
-        AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = CharInfoLabel
-        Left = 0
-        Height = 361
-        Top = 0
-        Width = 577
-        Anchors = [akTop, akLeft, akRight, akBottom]
-        ColCount = 17
-        DefaultColWidth = 16
-        DefaultDrawing = False
-        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
-        RowCount = 15
-        TabOrder = 0
-        OnKeyPress = StringGridKeyPress
-        OnMouseDown = StringGridMouseDown
-        OnMouseMove = StringGrid1MouseMove
-        OnSelectCell = StringGrid1SelectCell
-      end
-    end
-    object TabSheet2: TTabSheet
+    object pgUnicode: TTabSheet
       Caption = 'Unicode'
-      ClientHeight = 390
-      ClientWidth = 577
+      ClientHeight = 405
+      ClientWidth = 570
       object UnicodeCharInfoLabel: TLabel
         AnchorSideLeft.Control = Owner
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         Left = 6
-        Height = 17
-        Top = 362
-        Width = 147
+        Height = 15
+        Top = 380
+        Width = 118
         BorderSpacing.Around = 6
         Caption = 'UnicodeCharInfoLabel'
         ParentColor = False
       end
       object StringGrid2: TStringGrid
-        AnchorSideLeft.Control = TabSheet2
-        AnchorSideTop.Control = TabSheet2
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideLeft.Control = pgUnicode
+        AnchorSideTop.Control = pgUnicode
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
         AnchorSideBottom.Control = cbUniRange
         Left = 0
-        Height = 351
+        Height = 370
         Top = 0
-        Width = 577
+        Width = 570
         Anchors = [akTop, akLeft, akRight, akBottom]
         ColCount = 16
         DefaultColWidth = 16
@@ -133,18 +90,18 @@
         OnSelectCell = StringGrid2SelectCell
       end
       object cbUniRange: TComboBox
-        AnchorSideRight.Control = TabSheet2
+        AnchorSideRight.Control = pgUnicode
         AnchorSideRight.Side = asrBottom
-        AnchorSideBottom.Control = TabSheet2
+        AnchorSideBottom.Control = pgUnicode
         AnchorSideBottom.Side = asrBottom
-        Left = 280
-        Height = 27
-        Top = 357
+        Left = 273
+        Height = 23
+        Top = 376
         Width = 291
         Anchors = [akRight, akBottom]
         BorderSpacing.Around = 6
         DropDownCount = 25
-        ItemHeight = 23
+        ItemHeight = 15
         OnSelect = cbUniRangeSelect
         Style = csDropDownList
         TabOrder = 1
@@ -153,14 +110,114 @@
         AnchorSideTop.Control = cbUniRange
         AnchorSideTop.Side = asrCenter
         AnchorSideRight.Control = cbUniRange
-        Left = 231
-        Height = 17
-        Top = 362
-        Width = 43
+        Left = 234
+        Height = 15
+        Top = 380
+        Width = 33
         Anchors = [akTop, akRight]
         Caption = 'Range'
         ParentColor = False
       end
     end
+    object pgAnsi: TTabSheet
+      Caption = 'ANSI'
+      ClientHeight = 405
+      ClientWidth = 570
+      object CharInfoLabel: TLabel
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 6
+        Height = 15
+        Top = 380
+        Width = 74
+        BorderSpacing.Around = 6
+        Caption = 'CharInfoLabel'
+        ParentColor = False
+      end
+      object StringGrid1: TStringGrid
+        AnchorSideLeft.Control = pgAnsi
+        AnchorSideTop.Control = pgAnsi
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = cbCodePage
+        Left = 0
+        Height = 370
+        Top = 0
+        Width = 570
+        Anchors = [akTop, akLeft, akRight, akBottom]
+        ColCount = 17
+        DefaultColWidth = 16
+        DefaultDrawing = False
+        Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goDrawFocusSelected, goSmoothScroll]
+        RowCount = 15
+        TabOrder = 0
+        OnKeyPress = StringGridKeyPress
+        OnMouseDown = StringGridMouseDown
+        OnMouseMove = StringGrid1MouseMove
+        OnSelectCell = StringGrid1SelectCell
+      end
+      object cbCodePage: TComboBox
+        AnchorSideTop.Control = StringGrid1
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = pgAnsi
+        AnchorSideRight.Side = asrBottom
+        AnchorSideBottom.Control = pgAnsi
+        AnchorSideBottom.Side = asrBottom
+        Left = 245
+        Height = 23
+        Top = 376
+        Width = 319
+        Anchors = [akRight, akBottom]
+        BorderSpacing.Around = 6
+        DropDownCount = 25
+        ItemHeight = 15
+        Items.Strings = (
+          'cp1250 - Central and East European Latin'
+          'cp1251 - Cyrillic'
+          'cp1252 - West European Latin'
+          'cp1253 - Greek'
+          'cp1254 - Turkish'
+          'cp1255 - Hebrew'
+          'cp1256 - Arabic'
+          'cp1257 - Baltic'
+          'cp1258 - Vietnamese'
+          'cp437 - Original IBM PC hardware'
+          'cp850 - Latin-1'
+          'cp852 - Latin-2'
+          'cp866 - Belarusian, Russian, Ukrainian'
+          'cp874 - Thai'
+          'cp932 - Japanese'
+          'cp936 - ANSI/OEM Simplified Chinese'
+          'cp949 - Korean'
+          'cp950 - Traditional Chinese'
+          'macintosh - MAC Roman (Western Europe)'
+          'koi8 - Ukrainean, Cyrillic'
+          'iso88591 - ISO Latin-1 (Western Europe)'
+          'iso88592 - ISO Latin-2 (Central and Eastern Europe)'
+          'iso885915 - ISO Latin-9 (Western Europe)'
+        )
+        OnSelect = cbCodePageSelect
+        Style = csDropDownList
+        TabOrder = 1
+      end
+      object Label1: TLabel
+        AnchorSideLeft.Control = CharInfoLabel
+        AnchorSideTop.Control = cbCodePage
+        AnchorSideTop.Side = asrCenter
+        AnchorSideRight.Control = cbCodePage
+        Left = 182
+        Height = 15
+        Top = 380
+        Width = 57
+        Anchors = [akTop, akRight]
+        Caption = 'Code page'
+        ParentColor = False
+      end
+    end
   end
 end
Index: ide/charactermapdlg.pas
===================================================================
--- ide/charactermapdlg.pas	(revision 51943)
+++ ide/charactermapdlg.pas	(working copy)
@@ -49,15 +49,18 @@
 
   TCharacterMapDialog = class(TForm)
     ButtonPanel: TButtonPanel;
+    cbCodePage: TComboBox;
     CharInfoLabel: TLabel;
     cbUniRange: TComboBox;
+    Label1: TLabel;
     RangeLabel: TLabel;
     UnicodeCharInfoLabel: TLabel;
     PageControl1: TPageControl;
     StringGrid1: TStringGrid;
     StringGrid2: TStringGrid;
-    TabSheet1: TTabSheet;
-    TabSheet2: TTabSheet;
+    pgAnsi: TTabSheet;
+    pgUnicode: TTabSheet;
+    procedure cbCodePageSelect(Sender: TObject);
     procedure cbUniRangeSelect(Sender: TObject);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
     procedure HelpButtonClick(Sender: TObject);
@@ -79,6 +82,7 @@
     procedure DoStatusGrid1(ACol, ARow: integer);
     procedure DoStatusGrid2(ACol, ARow: integer);
     procedure FillCharMap;
+    procedure SelectSystemCP;
   public
     property OnInsertCharacter: TOnInsertCharacterEvent read FOnInsertCharacter
                                                         write FOnInsertCharacter;
@@ -93,6 +97,10 @@
 
 {$R *.lfm}
 
+uses
+ {$ifdef WINDOWS}Windows,{$endif}
+  lconvencoding;
+
 procedure ShowCharacterMap(AOnInsertChar: TOnInsertCharacterEvent);
 begin
   if CharacterMapDialog = nil then
@@ -112,11 +120,43 @@
   ButtonPanel.CloseButton.Caption:=lisBtnClose;
 
   //EnvironmentOptions.IDEWindowLayoutList.Apply(Self, Name);
+  PageControl1.ActivePageIndex := 0;
   CharInfoLabel.Caption := '-';
   UnicodeCharInfoLabel.Caption := '-';
+  SelectSystemCP;
   FillCharMap;
 end;
 
+procedure TCharacterMapDialog.SelectSystemCP;
+var
+  i: Integer;
+  cp: Word;
+  cpStr: String;
+begin
+ {$ifdef Windows}
+  // Find system code page on Windows...
+  // see: msdn.microsoft.com/library/windows/desktop/dd317756%28v=vs.85%29.aspx
+  cp := Windows.GetACP;
+  case cp of  // add spaces to be sure of unique names found in the combobox
+    437..1258: cpStr := 'cp' + IntToStr(cp) + ' ';
+    10000    : cpStr := 'macintosh ';
+    20866    : cpStr := 'koi8 ';
+    28591    : cpStr := 'iso88591 ';
+    28592    : cpStr := 'iso88592 ';
+    28605    : cpStr := 'iso885915 ';
+    else       cpStr := '';
+  end;
+  for i := 0 to cbCodePage.Items.Count-1 do
+    if pos(cpStr, cbCodePage.Items[i]) = 1 then
+    begin
+      cbCodePage.ItemIndex := i;
+      exit;
+    end;
+ {$endif}
+  // ... if not found, or non-Windows, just pick the first item.
+  cbCodePage.ItemIndex := 0;
+end;
+
 procedure TCharacterMapDialog.HelpButtonClick(Sender: TObject);
 begin
   LazarusHelp.ShowHelpForIDEControl(Self);
@@ -129,6 +169,11 @@
    Result:=(Value div Divi)+1;
 end;
 
+procedure TCharacterMapDialog.cbCodePageSelect(Sender: TObject);
+begin
+  FillCharMap;
+end;
+
 procedure TCharacterMapDialog.cbUniRangeSelect(Sender: TObject);
 var cnt, x, y :integer;
 S,E:Integer;
@@ -276,8 +321,12 @@
 
 procedure TCharacterMapDialog.FillCharMap;
 var
-  R, C: Integer;
+  R, C, p: Integer;
+  cp: String;
 begin
+  cp := cbCodePage.Items[cbCodePage.ItemIndex];
+  p := pos(' ', cp);
+  if p > 0 then SetLength(cp, p-1);
   for R := 0 to Pred(StringGrid1.RowCount) do
   begin
     if R <> 0 then  StringGrid1.Cells[0, R] := Format('%.3d +', [Succ(R) * 16]);
@@ -285,7 +334,7 @@
     begin
       if R = 0 then StringGrid1.Cells[C, R] := Format('%.2d', [Pred(C)])
       else
-        StringGrid1.Cells[C, R] := AnsiToUTF8(Chr(Succ(R) * 16 + Pred(C)));
+        StringGrid1.Cells[C, R] := ConvertEncoding(Chr(Succ(R) * 16 + Pred(C)), cp, 'utf8');
     end;
   end;
 end;
ide-charmap-v3.patch (12,148 bytes)

Bart Broersma

2016-03-21 16:44

developer   ~0091261

Applied patch nr 3 by wp (with minor modification).
My initial patch (replacing AnsiToUtf8 with WinCPToUtf8 did not work on Linux with UTF8 as default encoding).

Please test and close if OK.

Issue History

Date Modified Username Field Change
2016-03-18 19:38 Alexey Tor. New Issue
2016-03-18 19:38 Alexey Tor. File Added: charmap-laz.png
2016-03-18 20:10 FTurtle Note Added: 0091184
2016-03-18 22:26 Juha Manninen Relationship added related to 0029078
2016-03-18 23:06 Alexey Tor. Note Added: 0091188
2016-03-18 23:08 Alexey Tor. Note Edited: 0091188 View Revisions
2016-03-18 23:09 Alexey Tor. Note Edited: 0091188 View Revisions
2016-03-18 23:59 FTurtle Note Added: 0091189
2016-03-19 00:17 FTurtle Note Added: 0091190
2016-03-19 08:49 FTurtle Note Added: 0091192
2016-03-19 09:01 FTurtle Note Added: 0091193
2016-03-19 09:18 FTurtle Note Edited: 0091192 View Revisions
2016-03-19 13:33 Bart Broersma Note Added: 0091200
2016-03-19 17:06 wp Note Added: 0091202
2016-03-19 17:08 wp File Added: charmap_cp1252_laz144.png
2016-03-19 17:08 wp File Added: charmap_cp1252_laz16-trunk.png
2016-03-19 17:27 wp Note Edited: 0091202 View Revisions
2016-03-19 17:47 Bart Broersma Note Added: 0091203
2016-03-19 17:50 Bart Broersma Note Added: 0091204
2016-03-19 18:06 Bart Broersma Note Added: 0091205
2016-03-19 18:24 Bart Broersma File Added: charmap-laz-1.7-fpc-3-0-0-wincptoutf8.png
2016-03-19 18:26 Bart Broersma Note Added: 0091206
2016-03-19 18:27 Bart Broersma File Added: charmap.diff
2016-03-19 18:39 FTurtle Note Added: 0091207
2016-03-19 18:45 wp File Added: ide-charmap.patch
2016-03-19 18:48 wp Note Added: 0091208
2016-03-19 18:53 Bart Broersma Note Added: 0091209
2016-03-19 18:58 Bart Broersma Note Edited: 0091209 View Revisions
2016-03-19 19:06 wp Note Added: 0091211
2016-03-19 19:18 Bart Broersma Note Added: 0091213
2016-03-19 19:22 Bart Broersma Note Edited: 0091213 View Revisions
2016-03-19 19:24 Bart Broersma Note Edited: 0091213 View Revisions
2016-03-19 19:26 Bart Broersma Note Added: 0091214
2016-03-19 20:05 wp Note Added: 0091215
2016-03-19 20:05 wp File Added: ide-charmap-v2.patch
2016-03-19 21:03 Anton Note Added: 0091217
2016-03-19 22:16 wp Note Added: 0091219
2016-03-19 22:16 wp File Added: ide-charmap-v3.patch
2016-03-20 17:20 Bart Broersma Assigned To => Bart Broersma
2016-03-20 17:20 Bart Broersma Status new => assigned
2016-03-21 16:44 Bart Broersma Fixed in Revision => r52008
2016-03-21 16:44 Bart Broersma LazTarget => 1.6.2
2016-03-21 16:44 Bart Broersma Note Added: 0091261
2016-03-21 16:44 Bart Broersma Status assigned => resolved
2016-03-21 16:44 Bart Broersma Fixed in Version => 1.6.2
2016-03-21 16:44 Bart Broersma Resolution open => fixed
2016-03-21 16:44 Bart Broersma Target Version => 1.6.2
2017-01-24 19:03 wp Relationship added related to 0031269