diff options
-rw-r--r-- | examples/gui/colorlistbox/colorlistboxtest.lpi | 4 | ||||
-rw-r--r-- | examples/gui/fontselect/fontselect.lpi | 5 | ||||
-rw-r--r-- | prototypes/textedit/demo_textedit.lpi | 13 | ||||
-rw-r--r-- | prototypes/textedit/demo_textedit.lpr | 3 | ||||
-rw-r--r-- | prototypes/textedit/fpg_textedit.pas | 97 |
5 files changed, 105 insertions, 17 deletions
diff --git a/examples/gui/colorlistbox/colorlistboxtest.lpi b/examples/gui/colorlistbox/colorlistboxtest.lpi index b5129898..b74ec22a 100644 --- a/examples/gui/colorlistbox/colorlistboxtest.lpi +++ b/examples/gui/colorlistbox/colorlistboxtest.lpi @@ -1,11 +1,11 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="/"/> - <Version Value="6"/> + <Version Value="7"/> <General> <Flags> <SaveOnlyProjectUnits Value="True"/> + <LRSInOutputDirectory Value="False"/> </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> diff --git a/examples/gui/fontselect/fontselect.lpi b/examples/gui/fontselect/fontselect.lpi index 7e9fd4a0..74eb6b4d 100644 --- a/examples/gui/fontselect/fontselect.lpi +++ b/examples/gui/fontselect/fontselect.lpi @@ -1,15 +1,14 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="/"/> - <Version Value="6"/> + <Version Value="7"/> <General> <Flags> <SaveOnlyProjectUnits Value="True"/> + <LRSInOutputDirectory Value="False"/> </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> diff --git a/prototypes/textedit/demo_textedit.lpi b/prototypes/textedit/demo_textedit.lpi index 3e74aa03..6b541e19 100644 --- a/prototypes/textedit/demo_textedit.lpi +++ b/prototypes/textedit/demo_textedit.lpi @@ -5,12 +5,13 @@ <General> <Flags> <SaveOnlyProjectUnits Value="True"/> - <LRSInOutputDirectory Value="False"/> </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> + <AutoCreateForms Value="False"/> <TargetFileExt Value=""/> <Title Value="demo_textedit"/> + <UseAppBundle Value="False"/> </General> <VersionInfo> <ProjectVersion Value=""/> @@ -47,6 +48,9 @@ </ProjectOptions> <CompilerOptions> <Version Value="8"/> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)/"/> + </SearchPaths> <Parsing> <SyntaxOptions> <CStyleOperator Value="False"/> @@ -63,6 +67,13 @@ <CustomOptions Value="-FUunits "/> <CompilerPath Value="$(CompPath)"/> + <ExecuteBefore> + <CompileReasons Compile="False" Build="False" Run="False"/> + </ExecuteBefore> + <ExecuteAfter> + <CompileReasons Compile="False" Build="False" Run="False"/> + </ExecuteAfter> </Other> + <CompileReasons Compile="False" Build="False" Run="False"/> </CompilerOptions> </CONFIG> diff --git a/prototypes/textedit/demo_textedit.lpr b/prototypes/textedit/demo_textedit.lpr index 0af5e4ec..6211cc7f 100644 --- a/prototypes/textedit/demo_textedit.lpr +++ b/prototypes/textedit/demo_textedit.lpr @@ -117,8 +117,7 @@ begin if rbRight.Checked or rbBoth.Checked then begin t := fpgGetTickCount; - TextEdit.Lines.LoadFromFile(s); - TextEdit.Invalidate; + TextEdit.LoadFromFile(s); Label2.Text := Format('%d ticks', [fpgGetTickCount - t]); end; end; diff --git a/prototypes/textedit/fpg_textedit.pas b/prototypes/textedit/fpg_textedit.pas index 862aff24..78b91083 100644 --- a/prototypes/textedit/fpg_textedit.pas +++ b/prototypes/textedit/fpg_textedit.pas @@ -26,15 +26,16 @@ unit fpg_textedit; interface uses - Classes, SysUtils, fpg_base, fpg_main, fpg_widget, fpg_panel, + Classes, SysUtils, fpg_base, fpg_main, fpg_widget, fpg_scrollbar; type // forward declaration TfpgBaseTextEdit = class; - TfpgGutter = class(TfpgBevel) + TfpgGutter = class(TfpgWidget) private + FOwner: TfpgBaseTextEdit; // convenience reference variable FDigits: Integer; FShowNum: Boolean; FSpace: Integer; @@ -48,6 +49,7 @@ type procedure SetZeroStart(const AValue: Boolean); protected procedure HandlePaint; override; + procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; public constructor CreateGutter(AOwner: TfpgBaseTextEdit); function GetClientRect: TfpgRect; override; @@ -114,6 +116,7 @@ type procedure HandleMouseEnter; override; procedure HandleMouseExit; override; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; procedure HandleKeyChar(var AText: TfpgChar; var shiftstate: TShiftState; var consumed: boolean); override; { -- local widget functions -- } @@ -139,6 +142,8 @@ type procedure Clear; procedure ScrollTo(X, Y: Integer); procedure DeleteSelection; + procedure SaveToFile(const AFileName: TfpgString); + procedure LoadFromFile(const AFileName: TfpgString); property ScrollPos_H: Integer read GetHScrollPos write SetHScrollPos; property ScrollPos_V: Integer read GetVScrollPos write SetVScrollPos; property TopLine: Integer read FTopLine; @@ -162,7 +167,7 @@ type implementation uses - fpg_dialogs{, fpg_constants}, fpg_stringutils; + fpg_dialogs{, fpg_constants}, fpg_stringutils, fpg_utils; { TfpgGutter } @@ -200,11 +205,11 @@ var begin if not FShowNum then Exit; //==> - w := GetClientRect.Width - FSpace - 1; - H := TfpgBaseTextEdit(Owner).FChrH; - MaxI := TfpgBaseTextEdit(Owner).FVisLines; + w := GetClientRect.Width - FSpace - 1; + H := FOwner.FChrH; + MaxI := FOwner.FVisLines; ltxtflags := [txtRight, txtVCenter]; - Canvas.SetFont(TfpgBaseTextEdit(Owner).FFont); + Canvas.SetFont(FOwner.FFont); r.SetRect(2, 0, W, H); for i := 0 to MaxI do @@ -230,25 +235,45 @@ end; procedure TfpgGutter.HandlePaint; begin inherited HandlePaint; + Canvas.Clear(clWindowBackground); + // Gutter right border + Canvas.SetColor(clHilite2); + Canvas.DrawLine(Width - 2, 0, Width - 2, Height - 1); + Canvas.SetColor(clShadow1); + Canvas.DrawLine(Width - 1, 0, Width - 1, Height - 1); DrawLineNums; end; +procedure TfpgGutter.HandleMouseScroll(x, y: integer; shiftstate: TShiftState; + delta: smallint); +var + msg: TfpgMessageParams; +begin + inherited HandleMouseScroll(x, y, shiftstate, delta); + fillchar(msg, sizeof(msg), 0); // zero out the record - initialize it + msg.mouse.x := x; + msg.mouse.y := y; + msg.mouse.shiftstate := shiftstate; + msg.mouse.delta := delta; + fpgPostMessage(self, FOwner.FVScrollBar, FPGM_SCROLL, msg); +end; + constructor TfpgGutter.CreateGutter(AOwner: TfpgBaseTextEdit); begin inherited Create(AOwner); + FOwner := AOwner; FDigits := 0; FShowNum := True; FSpace := 2; FStartNum := 1; FZeroStart := False; Width := 35; - Shape := bsRightLine; end; function TfpgGutter.GetClientRect: TfpgRect; begin Result := inherited GetClientRect; - Result.Width := Result.Width - 2; // bsRightLine takes up two pixels + Result.Width := Result.Width - 2; // border right line takes up two pixels end; { TfpgBaseTextEdit } @@ -797,6 +822,20 @@ writeln(' shiftstate not detected'); Invalidate; end; +procedure TfpgBaseTextEdit.HandleMouseScroll(x, y: integer; shiftstate: TShiftState; + delta: smallint); +var + msg: TfpgMessageParams; +begin + inherited HandleMouseScroll(x, y, shiftstate, delta); + fillchar(msg, sizeof(msg), 0); // zero out the record - initialize it + msg.mouse.x := x; + msg.mouse.y := y; + msg.mouse.shiftstate := shiftstate; + msg.mouse.delta := delta; + fpgPostMessage(self, FVScrollBar, FPGM_SCROLL, msg); +end; + procedure TfpgBaseTextEdit.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var @@ -1263,6 +1302,46 @@ begin { TODO : Implement DeleteSelection } end; +procedure TfpgBaseTextEdit.SaveToFile(const AFileName: TfpgString); +var + BuffList: TStringList; + SLine: TfpgString; + I, P: Integer; + Replace: Boolean; +begin + BuffList := TStringList.Create; + try + BuffList.Assign(FLines); + for I := 0 to pred(BuffList.Count) do + begin + SLine := BuffList[I]; + P := UTF8Length(SLine); + Replace := (P > 0) and (SLine <> ''); + if Replace then + begin + while (fpgCharAt(SLine, P) = ' ') do + begin + UTF8Delete(SLine, P, 1); + P := UTF8Length(SLine); + end; + BuffList[I] := SLine; + end; + end; + BuffList.SaveToFile(AFileName); + finally + BuffList.Free; + end; +end; + +procedure TfpgBaseTextEdit.LoadFromFile(const AFileName: TfpgString); +begin + if not fpgFileExists(AFileName) then + Exit; //==> + Clear; + FLines.LoadFromFile(AFileName); + Invalidate; +end; + end. |