diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-10-05 12:59:49 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-10-05 12:59:49 +0000 |
commit | 6c72999051b20a306d7e40a55f5df5a48253799f (patch) | |
tree | 8afe8d755d2017bd662aa0c54bcf261cd53f4314 | |
parent | 433fbe8a1810882eda822e4cf4ccdefdbd8de959 (diff) | |
download | fpGUI-6c72999051b20a306d7e40a55f5df5a48253799f.tar.xz |
* Implemented a UTF8Insert() and UTF8Delete() procedures
* Fixed up TfpgEdit to now use the UTF-8 versions of Insert() and Delete()
which fixes some of the keyboard input issue.
* Removed stacks of compiler warnings all over the place.
* Fixed up the TfpgMemo to now use the UTF-8 versions of Insert() and Delete()
which fixes some of the keyboard input issues.
-rw-r--r-- | prototypes/fpgui2/tests/edittest.dpr | 9 | ||||
-rw-r--r-- | src/corelib/gfx_utf8utils.pas | 56 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 7 | ||||
-rw-r--r-- | src/corelib/x11/_netlayer.pas | 6 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 15 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 25 | ||||
-rw-r--r-- | src/gui/gui_listbox.pas | 6 | ||||
-rw-r--r-- | src/gui/gui_memo.pas | 10 | ||||
-rw-r--r-- | src/gui/gui_menu.pas | 1 |
9 files changed, 80 insertions, 55 deletions
diff --git a/prototypes/fpgui2/tests/edittest.dpr b/prototypes/fpgui2/tests/edittest.dpr index 35b3a4ce..e4107d50 100644 --- a/prototypes/fpgui2/tests/edittest.dpr +++ b/prototypes/fpgui2/tests/edittest.dpr @@ -9,6 +9,7 @@ uses fpgfx, gfx_widget, gfx_imgfmt_bmp, + gfx_UTF8utils, gui_form, gui_label, gui_button, @@ -360,7 +361,7 @@ var bmp: TfpgImage; begin SetPosition(200, 200, 500, 350); - WindowTitle := 'Test Russian text -> Òåñò'; + WindowTitle := 'UTF-8 Title -> Òåñò'; label1 := CreateLabel(self, 5, 5, 'Hello world!'); label2 := CreateLabel(self, 5, 20, 'Hello world in Bold!'); @@ -373,7 +374,11 @@ begin edit1 := CreateEdit(self, 10, 40, 120, 22); edit1.Text := 'Hello world. Hello world. Hello world.'; edit2 := CreateEdit(self, 10, 70, 200, 22); - edit2.Text := 'Test Russian text -> Òåñò'; + edit2.Text := 'UTF-8 text -> Òåñò'; +// writeln(UTF8Length(edit2.text)); +// writeln(Length(edit2.text)); + UTF8Insert('ö', edit2.Text, 15); + // left to right and right to left text in one // fpGUI doesn't handle this correctly yet. // See http://www.catch22.net/tuts/editor18.asp for how it needs to display and work diff --git a/src/corelib/gfx_utf8utils.pas b/src/corelib/gfx_utf8utils.pas index 6734a9d5..297eb069 100644 --- a/src/corelib/gfx_utf8utils.pas +++ b/src/corelib/gfx_utf8utils.pas @@ -1,6 +1,6 @@ { - Some handly UTF8 function copied from the Lazarus LCL. Surely we can move - this into FPC? + Some handly UTF8 function copied from the Lazarus LCL. Comes from the LCLProc + unit.Surely we can move this into FPC? } unit gfx_UTF8utils; @@ -12,14 +12,14 @@ uses Classes, SysUtils; -function UTF8Pos(const SearchForText, SearchInText: string): integer; -function UTF8Copy(const s: string; StartCharIndex, CharCount: integer): string; -function UTF8Length(const s: string): integer; -function UTF8Length(p: PChar; ByteCount: integer): integer; -function UTF8CharStart(UTF8Str: PChar; Len, Index: integer): PChar; -function UTF8CharacterLength(p: PChar): integer; - -{$Note I believe we need a UTF8Delete and UTF8Insert as well. } +function UTF8Pos(const SearchForText, SearchInText: string): integer; +function UTF8Copy(const s: string; StartCharIndex, CharCount: integer): string; +function UTF8Length(const s: string): integer; +function UTF8Length(p: PChar; ByteCount: integer): integer; +function UTF8CharStart(UTF8Str: PChar; Len, Index: integer): PChar; +function UTF8CharacterLength(p: PChar): integer; +procedure UTF8Insert(const Source: string; var S: string; Index: integer); +procedure UTF8Delete(var S: string; Index, Size: integer); implementation @@ -29,11 +29,11 @@ function UTF8Pos(const SearchForText, SearchInText: string): integer; var p: LongInt; begin - p:=System.Pos(SearchForText,SearchInText); - if p>0 then - Result:=UTF8Length(PChar(SearchInText),p-1)+1 - else - Result:=0; + p := System.Pos(SearchForText, SearchInText); + if p > 0 then + Result := UTF8Length(PChar(SearchInText), p-1) + 1 + else + Result := 0; end; // returns substring @@ -138,5 +138,31 @@ begin Result:=0; end; +procedure UTF8Insert(const Source: string; var S: string; Index: integer); +var + b: string; + e: string; +begin + if UTF8Length(Source) = 0 then + Exit; //==> + b := UTF8Copy(S, 1, Index-1); // beginning string + e := UTF8Copy(S, Index, UTF8Length(S)-Index+1); // ending string + S := b + Source + e; +end; + +procedure UTF8Delete(var S: string; Index, Size: integer); +var + ls: integer; + b: string; + e: string; +begin + ls := UTF8Length(S); + if (Index > ls) or (Index <= 0) or (Size <= 0) then + Exit; //==> + b := UTF8Copy(S, 1, Index-1); // beginning string + e := UTF8Copy(S, Index+Size, UTF8Length(S)-(Index+Size-1)); // ending string + S := b + e; +end; + end. diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 7b7eec6d..3669ca94 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -847,7 +847,6 @@ end; procedure TfpgCanvasBase.StretchDraw(x, y, w, h: TfpgCoord; ASource: TfpgImageBase); var - i: TfpgCustomInterpolation; FreeInterpolation: boolean; IP: TfpgCustomInterpolation; begin @@ -1278,8 +1277,8 @@ end; procedure TfpgBaseInterpolation.Execute(x, y, w, h: integer); begin - tempimage := TfpgImageBase.Create; - tempimage.AllocateImage(image.ColorDepth, w, image.Height); +// tempimage := TfpgImageBase.Create; +// tempimage.AllocateImage(image.ColorDepth, w, image.Height); xfactor := image.Width / w; yfactor := image.Height / h; @@ -1297,7 +1296,7 @@ end; destructor TfpgBaseInterpolation.Destroy; begin - tempimage.Free; +// tempimage.Free; inherited Destroy; end; diff --git a/src/corelib/x11/_netlayer.pas b/src/corelib/x11/_netlayer.pas index 724b6e4b..3eb5f326 100644 --- a/src/corelib/x11/_netlayer.pas +++ b/src/corelib/x11/_netlayer.pas @@ -284,7 +284,6 @@ procedure TNETWindowLayer.UpdateSupportedAtoms; var AtomCount: Integer; Atoms: PNetAtom; - Data: Pointer; I: Integer; NetAtom: TNetAtomEnum; begin @@ -306,6 +305,7 @@ end; function TNETWindowLayer.WindowSetName(const AWindow: TWindow; AName: PChar ): Boolean; begin + Result := True; //???? WindowSetPropertyUTF8(AWindow, FNetAtoms[naWM_NAME], Length(AName), AName); end; @@ -623,7 +623,7 @@ end; function TNETWindowLayer.ManagerIsValid: Boolean; begin - + Result := False; // ????? Todo end; procedure TNETWindowLayer.SendRootWindowMessage(AMessage: PXEvent); @@ -791,9 +791,7 @@ function TNETWindowLayer.WindowGetState(const AWindow: TWindow; out var AtomCount: Integer; StateAtoms: PAtom; - Data: Pointer; I: Integer; - State: TNetWindowState; begin Result := FAtomSupported[naWM_STATE]; if Result = False then Exit; diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 23df9cbb..a03523b6 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -230,6 +230,7 @@ procedure XRenderSetPictureClipRectangles(disp: PXDisplay; pic: TPicture; xorigi // redefines: function XmbLookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar; len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external; +function Xutf8LookupString(p1: PXIC; ev: PXKeyPressedEvent; str: PChar; len: longword; ks: PKeySym; stat: PStatus): longint; cdecl; external; // Double buffer functions function XdbeQueryExtension(ADisplay: PXDisplay; AMajor, AMinor: PInt): PStatus; cdecl; external; @@ -539,13 +540,13 @@ begin DefaultColorMap := XDefaultColorMap(FDisplay, DefaultScreen); // Initialize atoms - xia_clipboard := XInternAtom(FDisplay, 'CLIPBOARD', longbool(0)); - xia_targets := XInternAtom(FDisplay, 'TARGETS', longbool(0)); - xia_motif_wm_hints := XInternAtom(FDisplay, '_MOTIF_WM_HINTS', longbool(0)); - xia_wm_protocols := XInternAtom(FDisplay, 'WM_PROTOCOLS', longbool(0)); - xia_wm_delete_window := XInternAtom(FDisplay, 'WM_DELETE_WINDOW', longbool(0)); - xia_wm_state := XInternAtom(FDisplay, '_NET_WM_STATE', longbool(0)); - xia_wm_state_modal := XInternAtom(FDisplay, '_NET_WM_STATE_MODAL', longbool(0)); + xia_clipboard := XInternAtom(FDisplay, 'CLIPBOARD', longbool(0)); + xia_targets := XInternAtom(FDisplay, 'TARGETS', longbool(0)); + xia_motif_wm_hints := XInternAtom(FDisplay, '_MOTIF_WM_HINTS', longbool(0)); + xia_wm_protocols := XInternAtom(FDisplay, 'WM_PROTOCOLS', longbool(0)); + xia_wm_delete_window := XInternAtom(FDisplay, 'WM_DELETE_WINDOW', longbool(0)); + xia_wm_state := XInternAtom(FDisplay, '_NET_WM_STATE', longbool(0)); + xia_wm_state_modal := XInternAtom(FDisplay, '_NET_WM_STATE_MODAL', longbool(0)); // for correct keyboard handling InputMethod := XOpenIM(FDisplay, nil, nil, nil); diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index 1d11b6c4..018ecc38 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -176,8 +176,9 @@ end; procedure TfpgEdit.SetPasswordMode(const AValue: boolean); begin - if FPasswordMode=AValue then exit; - FPasswordMode:=AValue; + if FPasswordMode = AValue then + Exit; //==> + FPasswordMode := AValue; end; procedure TfpgEdit.DeleteSelection; @@ -186,12 +187,12 @@ begin begin if FSelOffset < 0 then begin - Delete(FText, 1 + FSelStart + FSelOffset, -FSelOffset); + UTF8Delete(FText, 1 + FSelStart + FSelOffset, -FSelOffset); FCurSorPos := FSelStart + FSelOffset; end else begin - Delete(FText, 1 + FSelStart, FSelOffset); + UTF8Delete(FText, 1 + FSelStart, FSelOffset); FCurSorPos := FSelStart; end; FSelOffset := 0; @@ -202,7 +203,7 @@ end; procedure TfpgEdit.DoCopy; begin if FSelOffset = 0 then - Exit; + Exit; //==> fpgClipboard.Text := SelectionText; end; @@ -219,8 +220,8 @@ begin if UTF8Length(s) < 1 then Exit; //==> - {$Note Is Insert() UTF-8 safe? } - Insert(s, FText, FCursorPos + 1); + + UTF8Insert(s, FText, FCursorPos + 1); FCursorPos := FCursorPos + UTF8Length(s); AdjustCursor; Repaint; @@ -323,7 +324,7 @@ begin if (FMaxLength <= 0) or (UTF8Length(FText) < FMaxLength) then begin DeleteSelection; - Insert(s, FText, FCursorPos + 1); + UTF8Insert(s, FText, FCursorPos + 1); Inc(FCursorPos); FSelStart := FCursorPos; AdjustCursor; @@ -453,7 +454,7 @@ begin begin if FCursorPos > 0 then begin - Delete(FText, FCursorPos, 1); + UTF8Delete(FText, FCursorPos, 1); Dec(FCursorPos); hasChanged := True; end;// backspace @@ -465,7 +466,7 @@ begin if FSelOffset <> 0 then DeleteSelection else if FCursorPos < UTF8Length(FText) then - Delete(FText, FCursorPos + 1, 1); + UTF8Delete(FText, FCursorPos + 1, 1); hasChanged := True; end; else @@ -491,7 +492,6 @@ end; procedure TfpgEdit.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); var - s: string; n: integer; cpx: integer; cp: integer; @@ -504,7 +504,6 @@ begin dtext := GetDrawText; cpx := FFont.TextWidth(UTF8Copy(dtext, 1, FCursorPos)) - FDrawOffset + FSideMargin; cp := FCursorPos; - s := ''; for n := 0 to UTF8Length(dtext) do begin @@ -531,7 +530,6 @@ end; procedure TfpgEdit.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var - s: string; n: integer; cpx: integer; cp: integer; @@ -545,7 +543,6 @@ begin dtext := GetDrawText; cpx := FFont.TextWidth(UTF8Copy(dtext, 1, FCursorPos)) - FDrawOffset + FSideMargin; cp := FCursorPos; - s := ''; for n := 0 to UTF8Length(dtext) do begin diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas index c4bbd0b6..c35be4bf 100644 --- a/src/gui/gui_listbox.pas +++ b/src/gui/gui_listbox.pas @@ -150,13 +150,13 @@ begin end; function TfpgListBoxStrings.Add(const s: String): Integer; -var - ItemWidth: Integer; +//var +// ItemWidth: Integer; begin Result := inherited Add(s); if Assigned(ListBox) and (ListBox.HasHandle) then begin - ItemWidth := ListBox.Font.TextWidth(s) + 4; +// ItemWidth := ListBox.Font.TextWidth(s) + 4; // if ItemWidth > ListBox.FMaxItemWidth then // ListBox.FMaxItemWidth := ItemWidth; ListBox.UpdateScrollBar; diff --git a/src/gui/gui_memo.pas b/src/gui/gui_memo.pas index 75cc4965..f151203e 100644 --- a/src/gui/gui_memo.pas +++ b/src/gui/gui_memo.pas @@ -302,7 +302,7 @@ begin else len := selep - st; - Delete(ls, st + 1, len); + UTF8Delete(ls, st + 1, len); SetLineText(n, ls); end; @@ -798,7 +798,7 @@ begin begin DeleteSelection; ls := GetLineText(FCursorLine); - insert(s, ls, FCursorPos + 1); + UTF8Insert(s, ls, FCursorPos + 1); SetLineText(FCursorLine, ls); Inc(FCursorPos); FSelStartPos := FCursorPos; @@ -991,7 +991,7 @@ begin if FCursorPos > 0 then begin ls := GetLineText(FCursorLine); - Delete(ls, FCursorPos, 1); + UTF8Delete(ls, FCursorPos, 1); SetLineText(FCursorLine, ls); Dec(FCursorPos); end @@ -1013,7 +1013,7 @@ begin DeleteSelection else if FCursorPos < UTF8Length(ls) then begin - Delete(ls, FCursorPos + 1, 1); + UTF8Delete(ls, FCursorPos + 1, 1); SetLineText(FCursorLine, ls); end else if FCursorLine < LineCount then @@ -1033,7 +1033,7 @@ begin DeleteSelection else} if FCursorPos < UTF8Length(ls) then begin - Insert(#9, ls, FCursorPos); + UTF8Insert(#9, ls, FCursorPos); SetLineText(FCursorLine, ls); end; { diff --git a/src/gui/gui_menu.pas b/src/gui/gui_menu.pas index 2aad7394..58aacda6 100644 --- a/src/gui/gui_menu.pas +++ b/src/gui/gui_menu.pas @@ -458,7 +458,6 @@ var n: integer; r: TfpgRect; mi: TfpgMenuItem; - r2: TfpgRect; begin Canvas.BeginDraw; r.SetRect(2, 1, 1, fpgStyle.MenuFont.Height+1); |