diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-11-05 15:05:56 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-11-05 15:05:56 +0000 |
commit | a86c82aa5b3aea8a4cb40a9fa1121427bf320bfd (patch) | |
tree | 97bc07cf0e2fa17546f4b352a3587df7ee7feeb9 | |
parent | 2da5c00abfea780c0f375d6f1646f4d15ca98256 (diff) | |
download | fpGUI-a86c82aa5b3aea8a4cb40a9fa1121427bf320bfd.tar.xz |
* More improvements to Calendar component.
* Lots of refactoring in the text Edit component.
* Added a new property BorderStyle to the Edit component.
-rw-r--r-- | examples/gui/calendar/calendartest.lpi | 207 | ||||
-rw-r--r-- | examples/gui/calendar/calendartest.lpr | 20 | ||||
-rw-r--r-- | src/corelib/gfx_popupwindow.pas | 4 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 399 | ||||
-rw-r--r-- | src/gui/gui_popupcalendar.pas | 48 |
5 files changed, 269 insertions, 409 deletions
diff --git a/examples/gui/calendar/calendartest.lpi b/examples/gui/calendar/calendartest.lpi index d0f6fd90..431c61ee 100644 --- a/examples/gui/calendar/calendartest.lpi +++ b/examples/gui/calendar/calendartest.lpi @@ -4,19 +4,19 @@ <PathDelim Value="/"/> <Version Value="6"/> <General> + <Flags> + <SaveOnlyProjectUnits Value="True"/> + </Flags> + <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> <IconPath Value="./"/> <TargetFileExt Value=""/> - <ActiveEditorIndexAtStart Value="1"/> </General> <VersionInfo> <ProjectVersion Value=""/> - <Language Value=""/> - <CharSet Value=""/> </VersionInfo> <PublishOptions> <Version Value="2"/> - <IgnoreBinaries Value="False"/> <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> </PublishOptions> @@ -32,210 +32,13 @@ <MinVersion Minor="5" Release="1" Valid="True"/> </Item1> </RequiredPackages> - <Units Count="21"> + <Units Count="1"> <Unit0> <Filename Value="calendartest.lpr"/> <IsPartOfProject Value="True"/> <UnitName Value="calendartest"/> - <CursorPos X="29" Y="19"/> - <TopLine Value="1"/> - <EditorIndex Value="0"/> - <UsageCount Value="21"/> - <Loaded Value="True"/> </Unit0> - <Unit1> - <Filename Value="../../../src/gui/gui_popupcalendar.pas"/> - <UnitName Value="gui_popupcalendar"/> - <CursorPos X="1" Y="217"/> - <TopLine Value="199"/> - <EditorIndex Value="1"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit1> - <Unit2> - <Filename Value="../../../src/gui/gui_grid.pas"/> - <UnitName Value="gui_grid"/> - <CursorPos X="13" Y="741"/> - <TopLine Value="725"/> - <EditorIndex Value="5"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit2> - <Unit3> - <Filename Value="../../../src/gui/gui_customgrid.pas"/> - <UnitName Value="gui_customgrid"/> - <CursorPos X="32" Y="54"/> - <TopLine Value="48"/> - <EditorIndex Value="7"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit3> - <Unit4> - <Filename Value="../../../src/gui/gui_basegrid.pas"/> - <UnitName Value="gui_basegrid"/> - <CursorPos X="1" Y="1039"/> - <TopLine Value="1026"/> - <EditorIndex Value="8"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit4> - <Unit5> - <Filename Value="../../../src/corelib/gfx_popupwindow.pas"/> - <UnitName Value="gfx_popupwindow"/> - <CursorPos X="35" Y="238"/> - <TopLine Value="166"/> - <UsageCount Value="10"/> - </Unit5> - <Unit6> - <Filename Value="../../../src/gui/gui_form.pas"/> - <UnitName Value="gui_form"/> - <CursorPos X="1" Y="12"/> - <TopLine Value="1"/> - <UsageCount Value="10"/> - </Unit6> - <Unit7> - <Filename Value="../../../src/gui/gui_combobox.pas"/> - <UnitName Value="gui_combobox"/> - <CursorPos X="16" Y="188"/> - <TopLine Value="171"/> - <UsageCount Value="10"/> - </Unit7> - <Unit8> - <Filename Value="../../../src/gui/gui_button.pas"/> - <UnitName Value="gui_button"/> - <CursorPos X="25" Y="91"/> - <TopLine Value="54"/> - <UsageCount Value="10"/> - </Unit8> - <Unit9> - <Filename Value="../../../src/gui/gui_listbox.pas"/> - <UnitName Value="gui_listbox"/> - <CursorPos X="1" Y="491"/> - <TopLine Value="475"/> - <UsageCount Value="10"/> - </Unit9> - <Unit10> - <Filename Value="../../../src/corelib/gfxbase.pas"/> - <UnitName Value="gfxbase"/> - <CursorPos X="3" Y="839"/> - <TopLine Value="837"/> - <UsageCount Value="10"/> - </Unit10> - <Unit11> - <Filename Value="../../../src/corelib/gfx_widget.pas"/> - <UnitName Value="gfx_widget"/> - <CursorPos X="3" Y="795"/> - <TopLine Value="790"/> - <UsageCount Value="10"/> - </Unit11> - <Unit12> - <Filename Value="../../../src/gui/gui_scrollbar.pas"/> - <UnitName Value="gui_scrollbar"/> - <CursorPos X="66" Y="42"/> - <TopLine Value="36"/> - <UsageCount Value="10"/> - </Unit12> - <Unit13> - <Filename Value="/opt/fpc-2.2.0/src/rtl/objpas/sysutils/sysinth.inc"/> - <CursorPos X="18" Y="107"/> - <TopLine Value="86"/> - <UsageCount Value="10"/> - </Unit13> - <Unit14> - <Filename Value="/opt/fpc-2.2.0/src/rtl/objpas/sysutils/datih.inc"/> - <CursorPos X="14" Y="115"/> - <TopLine Value="91"/> - <UsageCount Value="10"/> - </Unit14> - <Unit15> - <Filename Value="../../../src/gui/gui_memo.pas"/> - <UnitName Value="gui_memo"/> - <CursorPos X="1" Y="22"/> - <TopLine Value="1"/> - <UsageCount Value="10"/> - </Unit15> - <Unit16> - <Filename Value="../../../src/corelib/fpgfx.pas"/> - <UnitName Value="fpgfx"/> - <CursorPos X="42" Y="14"/> - <TopLine Value="1"/> - <EditorIndex Value="2"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit16> - <Unit17> - <Filename Value="../../../src/corelib/x11/gfx_x11.pas"/> - <UnitName Value="gfx_x11"/> - <CursorPos X="17" Y="300"/> - <TopLine Value="271"/> - <EditorIndex Value="3"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit17> - <Unit18> - <Filename Value="/opt/lazarus/lcl/grids.pas"/> - <UnitName Value="Grids"/> - <CursorPos X="3" Y="5574"/> - <TopLine Value="5558"/> - <EditorIndex Value="4"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit18> - <Unit19> - <Filename Value="../../../../../kylix3/source/clx/QGrids.pas"/> - <UnitName Value="QGrids"/> - <CursorPos X="1" Y="916"/> - <TopLine Value="899"/> - <UsageCount Value="10"/> - </Unit19> - <Unit20> - <Filename Value="../../../../3rdParty/tiOPF2/Source/Core/tiObject.pas"/> - <UnitName Value="tiObject"/> - <CursorPos X="1" Y="3722"/> - <TopLine Value="3714"/> - <EditorIndex Value="6"/> - <UsageCount Value="10"/> - <Loaded Value="True"/> - </Unit20> </Units> - <JumpHistory Count="9" HistoryIndex="8"> - <Position1> - <Filename Value="/opt/lazarus/lcl/grids.pas"/> - <Caret Line="37" Column="45" TopLine="19"/> - </Position1> - <Position2> - <Filename Value="../../../src/gui/gui_basegrid.pas"/> - <Caret Line="1048" Column="5" TopLine="1009"/> - </Position2> - <Position3> - <Filename Value="../../../../3rdParty/tiOPF2/Source/Core/tiObject.pas"/> - <Caret Line="20" Column="16" TopLine="1"/> - </Position3> - <Position4> - <Filename Value="../../../src/gui/gui_grid.pas"/> - <Caret Line="180" Column="76" TopLine="167"/> - </Position4> - <Position5> - <Filename Value="../../../src/gui/gui_grid.pas"/> - <Caret Line="671" Column="1" TopLine="653"/> - </Position5> - <Position6> - <Filename Value="../../../src/gui/gui_popupcalendar.pas"/> - <Caret Line="211" Column="5" TopLine="204"/> - </Position6> - <Position7> - <Filename Value="../../../src/gui/gui_popupcalendar.pas"/> - <Caret Line="78" Column="73" TopLine="63"/> - </Position7> - <Position8> - <Filename Value="../../../src/gui/gui_popupcalendar.pas"/> - <Caret Line="181" Column="11" TopLine="168"/> - </Position8> - <Position9> - <Filename Value="../../../src/gui/gui_popupcalendar.pas"/> - <Caret Line="196" Column="12" TopLine="193"/> - </Position9> - </JumpHistory> </ProjectOptions> <CompilerOptions> <Version Value="5"/> diff --git a/examples/gui/calendar/calendartest.lpr b/examples/gui/calendar/calendartest.lpr index 163961fa..6a16d853 100644 --- a/examples/gui/calendar/calendartest.lpr +++ b/examples/gui/calendar/calendartest.lpr @@ -11,7 +11,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Classes, SysUtils, fpgfx, gui_form, gui_popupcalendar, gui_edit, - gui_button, gui_label, gfx_popupwindow; + gui_button, gui_label, gfx_popupwindow, gui_combobox; type TMainForm = class(TfpgForm) @@ -24,6 +24,7 @@ type btnName1: TfpgButton; lblName1: TfpgLabel; lblName2: TfpgLabel; + cbName1: TfpgComboBox; {@VFD_HEAD_END: MainForm} FDropDown: TfpgPopupCalendar; procedure AfterCreate; override; @@ -45,6 +46,7 @@ begin FDropDown := TfpgPopupCalendar.Create(nil); FDropDown.ShowAt(self, edtName1.Left, edtName1.Top+edtName1.Height); FDropDown.PopupFrame:= True; + FDropDown.grdName1.SetFocus; end else begin @@ -58,7 +60,7 @@ begin inherited AfterCreate; {@VFD_BODY_BEGIN: MainForm} Name := 'MainForm'; - SetPosition(100, 100, 417, 270); + SetPosition(286, 234, 417, 270); WindowTitle := 'fpGUI Calendar Test'; WindowPosition := wpUser; @@ -100,6 +102,20 @@ begin FontDesc := '#Label2'; end; + cbName1 := TfpgComboBox.Create(self); + with cbName1 do + begin + Name := 'cbName1'; + SetPosition(124, 184, 120, 23); + Items.Add('line1'); + Items.Add('line2'); + Items.Add('line3'); + Items.Add('line4'); + Items.Add('line5'); + Items.Add('line6'); + FontDesc := '#List'; + end; + {@VFD_BODY_END: MainForm} end; diff --git a/src/corelib/gfx_popupwindow.pas b/src/corelib/gfx_popupwindow.pas index 3450b63d..64713c27 100644 --- a/src/corelib/gfx_popupwindow.pas +++ b/src/corelib/gfx_popupwindow.pas @@ -227,7 +227,7 @@ begin // Width := Width + 1; // Height := Height + 1; // UpdateWindowPosition; - HandleResize(Width+1, Height+1); + HandleResize(Width+2, Height+2); UpdateWindowPosition; for i := 0 to ComponentCount-1 do @@ -235,7 +235,7 @@ begin if Components[i] is TfpgWidget then TfpgWidget(Components[i]).Anchors := [anLeft, anTop]; end; - HandleResize(Width+1, Height+1); + HandleResize(Width+2, Height+2); UpdateWindowPosition; Canvas.BeginDraw; diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index 19cca8cd..04725c3b 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -29,11 +29,29 @@ uses gfx_widget; type + TfpgEditBorderStyle = (bsNone, bsDefault, bsSingle); + + TfpgCustomEdit = class(TfpgWidget) private FText: string; + FBackgroundColor: TfpgColor; FFont: TfpgFont; FPasswordMode: boolean; + FBorderStyle: TfpgEditBorderStyle; + FOnChange: TNotifyEvent; + FMaxLength: integer; + FSelecting: boolean; + procedure AdjustCursor; + procedure DeleteSelection; + procedure DoCopy; + procedure DoPaste; + procedure SetBackgroundColor(const AValue: TfpgColor); + procedure SetBorderStyle(const AValue: TfpgEditBorderStyle); + procedure SetPasswordMode(const AValue: boolean); + function GetFontDesc: string; + procedure SetFontDesc(const AValue: string); + procedure SetText(const AValue: string); protected FMouseDragPos: integer; FDrawOffset: integer; @@ -41,27 +59,6 @@ type FSelStart: integer; FSelOffset: integer; FCursorPos: integer; - function GetDrawText: string; - procedure SetPasswordMode(const AValue: boolean); - property Font: TfpgFont read FFont; - property PasswordMode: boolean read FPasswordMode write SetPasswordMode; - end; - - - TfpgEdit = class(TfpgCustomEdit) - private - FOnChange: TNotifyEvent; - FMaxLength: integer; - FBackgroundColor: TfpgColor; - FSelecting: boolean; - function GetFontDesc: string; - procedure SetBackgroundColor(const AValue: TfpgColor); - procedure SetFontDesc(const AValue: string); - procedure SetText(const AValue: string); - procedure DeleteSelection; - procedure DoCopy; - procedure DoPaste; - procedure AdjustCursor; procedure HandlePaint; override; procedure HandleKeyChar(var AText: string; var shiftstate: TShiftState; var consumed: boolean); override; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; @@ -69,17 +66,35 @@ type procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; procedure HandleMouseEnter; override; procedure HandleMouseExit; override; + function GetDrawText: string; + property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor default clBoxColor; + property Font: TfpgFont read FFont; + property FontDesc: string read GetFontDesc write SetFontDesc; + property PasswordMode: boolean read FPasswordMode write SetPasswordMode default False; + property BorderStyle: TfpgEditBorderStyle read FBorderStyle write SetBorderStyle default bsDefault; + property Text: string read FText write SetText; + property MaxLength: integer read FMaxLength write FMaxLength; + property OnChange: TNotifyEvent read FOnChange write FOnChange; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; function SelectionText: string; - property OnChange: TNotifyEvent read FOnChange write FOnChange; + end; + + + TfpgEdit = class(TfpgCustomEdit) + private published - property Text: string read FText write SetText; - property FontDesc: string read GetFontDesc write SetFontDesc; - property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor; - property MaxLength: integer read FMaxLength write FMaxLength; + property Text; + property FontDesc; + property BackgroundColor; + property MaxLength; property PasswordMode; + property BorderStyle; + property OnChange; + property OnPaint; + property OnMouseExit; + property OnMouseEnter; end; @@ -105,148 +120,7 @@ end; { TfpgCustomEdit } -function TfpgCustomEdit.GetDrawText: string; -begin - if not PassWordMode then - Result := FText - else - Result := StringOfChar('*', UTF8Length(FText)); -end; - -procedure TfpgCustomEdit.SetPasswordMode (const AValue: boolean ); -begin - if FPasswordMode = AValue then - Exit; //==> - FPasswordMode := AValue; -end; - - -{ TfpgEdit } - -constructor TfpgEdit.Create(AOwner: TComponent); -begin - inherited; - Focusable := True; - - FFont := fpgGetFont('#Edit1'); // owned object ! - - FHeight := FFont.Height + 6; - FWidth := 120; - FBackgroundColor := clBoxColor; - FSelecting := False; - FSideMargin := 3; - FMaxLength := 0; // no limit - FText := ''; - FCursorPos := UTF8Length(FText); - FSelStart := FCursorPos; - FSelOffset := 0; - FDrawOffset := 0; - FPasswordMode := False; - - FOnChange := nil; -end; - -destructor TfpgEdit.Destroy; -begin - FFont.Free; - inherited Destroy; -end; - -procedure TfpgEdit.SetText(const AValue: string); -var - s: string; -begin - if FText = AValue then - Exit; - - if FMaxLength <> 0 then - begin - if UTF8Length(FText) > FMaxLength then - s := UTF8Copy(AValue, 1, FMaxLength) - else - s := AValue; - end - else - s := AValue; - - FText := s; - FCursorPos := UTF8Length(FText); - FSelStart := FCursorPos; - FSelOffset := 0; - FDrawOffset := 0; - - AdjustCursor; - RePaint; -end; - -function TfpgEdit.GetFontDesc: string; -begin - Result := FFont.FontDesc; -end; - -procedure TfpgEdit.SetBackgroundColor(const AValue: TfpgColor); -begin - if FBackgroundColor <> AValue then - begin - FBackgroundColor := AValue; - Repaint; - end; -end; - -procedure TfpgEdit.SetFontDesc(const AValue: string); -begin - FFont.Free; - FFont := fpgGetFont(AValue); - RePaint; -end; - -procedure TfpgEdit.DeleteSelection; -begin - if FSelOffset <> 0 then - begin - if FSelOffset < 0 then - begin - UTF8Delete(FText, 1 + FSelStart + FSelOffset, -FSelOffset); - FCurSorPos := FSelStart + FSelOffset; - end - else - begin - UTF8Delete(FText, 1 + FSelStart, FSelOffset); - FCurSorPos := FSelStart; - end; - FSelOffset := 0; - FSelStart := FCursorPos; - end; -end; - -procedure TfpgEdit.DoCopy; -begin - if FSelOffset = 0 then - Exit; //==> - fpgClipboard.Text := SelectionText; -end; - -procedure TfpgEdit.DoPaste; -var - s: string; -begin - DeleteSelection; - s := fpgClipboard.Text; - - if (FMaxLength > 0) then - if UTF8Length(FText) + UTF8Length(s) > FMaxLength then - s := UTF8Copy(s, 1, FMaxLength - UTF8Length(FText)); // trim the clipboard text if needed - - if UTF8Length(s) < 1 then - Exit; //==> - - UTF8Insert(s, FText, FCursorPos + 1); - FCursorPos := FCursorPos + UTF8Length(s); - AdjustCursor; - Repaint; -end; - -procedure TfpgEdit.AdjustCursor; +procedure TfpgCustomEdit.AdjustCursor; var tw: integer; VisibleWidth: integer; @@ -264,26 +138,58 @@ begin end; end; -procedure TfpgEdit.HandlePaint; +procedure TfpgCustomEdit.SetBackgroundColor(const AValue: TfpgColor); +begin + if FBackgroundColor <> AValue then + begin + FBackgroundColor := AValue; + Repaint; + end; +end; + +procedure TfpgCustomEdit.SetBorderStyle(const AValue: TfpgEditBorderStyle); +begin + if FBorderStyle = AValue then + Exit; //==> + FBorderStyle := AValue; + RePaint; +end; + +procedure TfpgCustomEdit.HandlePaint; var r: TfpgRect; tw, tw2, st, len: integer; dtext: string; begin Canvas.BeginDraw; + Canvas.ClearClipRect; r.SetRect(0, 0, Width, Height); - Canvas.DrawControlFrame(r); - - InflateRect(r, -2, -2); + case BorderStyle of + bsNone: + begin + // do nothing + end; + bsDefault: + begin + Canvas.DrawControlFrame(r); + InflateRect(r, -2, -2); + end; + bsSingle: + begin + Canvas.SetColor(clShadow2); + Canvas.DrawRectangle(r); + InflateRect(r, -1, -1); + end; + end; Canvas.SetClipRect(r); if Enabled then Canvas.SetColor(FBackgroundColor) else Canvas.SetColor(clWindowBackground); - Canvas.FillRectAngle(r); + Canvas.FillRectAngle(r); dtext := GetDrawText; Canvas.SetTextColor(clText1); Canvas.SetFont(FFont); @@ -301,7 +207,6 @@ begin st := st + len; len := -len; end; - tw := FFont.TextWidth(UTF8copy(dtext, 1, st)); tw2 := FFont.TextWidth(UTF8copy(dtext, 1, st + len)); Canvas.XORFillRectangle(fpgColorToRGB(clSelection) xor $FFFFFF, -FDrawOffset + @@ -318,7 +223,7 @@ begin Canvas.EndDraw; end; -procedure TfpgEdit.HandleKeyChar(var AText: string; +procedure TfpgCustomEdit.HandleKeyChar(var AText: string; var shiftstate: TShiftState; var consumed: boolean); var s: string; @@ -327,7 +232,7 @@ begin prevval := Text; s := AText; consumed := False; - + // Handle only printable characters // Note: This is not UTF-8 compliant! if (Ord(AText[1]) > 31) and (Ord(AText[1]) < 127) then @@ -353,7 +258,7 @@ begin inherited HandleKeyChar(AText, shiftstate, consumed); end; -procedure TfpgEdit.HandleKeyPress(var keycode: word; +procedure TfpgCustomEdit.HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); var lpos: integer; @@ -495,13 +400,13 @@ begin RePaint else inherited; - + if hasChanged then if Assigned(FOnChange) then FOnChange(self); end; -procedure TfpgEdit.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); +procedure TfpgCustomEdit.HandleLMouseDown(x, y: integer; shiftstate: TShiftState); var n: integer; cpx: integer; @@ -539,7 +444,7 @@ begin Repaint; end; -procedure TfpgEdit.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); +procedure TfpgCustomEdit.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var n: integer; cpx: integer; @@ -574,7 +479,7 @@ begin end; end; -procedure TfpgEdit.HandleMouseEnter; +procedure TfpgCustomEdit.HandleMouseEnter; begin inherited HandleMouseEnter; if (csDesigning in ComponentState) then @@ -583,7 +488,7 @@ begin MouseCursor := mcIBeam; end; -procedure TfpgEdit.HandleMouseExit; +procedure TfpgCustomEdit.HandleMouseExit; begin inherited HandleMouseExit; if (csDesigning in ComponentState) then @@ -591,7 +496,42 @@ begin MouseCursor := mcDefault; end; -function TfpgEdit.SelectionText: string; +function TfpgCustomEdit.GetDrawText: string; +begin + if not PassWordMode then + Result := FText + else + Result := StringOfChar('*', UTF8Length(FText)); +end; + +constructor TfpgCustomEdit.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FFont := fpgGetFont('#Edit1'); // owned object ! + Focusable := True; + FHeight := FFont.Height + 6; + FWidth := 120; + FBackgroundColor := clBoxColor; + FSelecting := False; + FSideMargin := 3; + FMaxLength := 0; // no limit + FText := ''; + FCursorPos := UTF8Length(FText); + FSelStart := FCursorPos; + FSelOffset := 0; + FDrawOffset := 0; + FPasswordMode := False; + FBorderStyle := bsDefault; + FOnChange := nil; +end; + +destructor TfpgCustomEdit.Destroy; +begin + FFont.Free; + inherited Destroy; +end; + +function TfpgCustomEdit.SelectionText: string; begin if FSelOffset <> 0 then begin @@ -606,6 +546,99 @@ begin Result := ''; end; +procedure TfpgCustomEdit.SetPasswordMode (const AValue: boolean ); +begin + if FPasswordMode = AValue then + Exit; //==> + FPasswordMode := AValue; + RePaint; +end; + +function TfpgCustomEdit.GetFontDesc: string; +begin + Result := FFont.FontDesc; +end; + +procedure TfpgCustomEdit.SetFontDesc(const AValue: string); +begin + FFont.Free; + FFont := fpgGetFont(AValue); + RePaint; +end; + +procedure TfpgCustomEdit.SetText(const AValue: string); +var + s: string; +begin + if FText = AValue then + Exit; + + if FMaxLength <> 0 then + begin + if UTF8Length(FText) > FMaxLength then + s := UTF8Copy(AValue, 1, FMaxLength) + else + s := AValue; + end + else + s := AValue; + + FText := s; + FCursorPos := UTF8Length(FText); + FSelStart := FCursorPos; + FSelOffset := 0; + FDrawOffset := 0; + + AdjustCursor; + RePaint; +end; + +procedure TfpgCustomEdit.DeleteSelection; +begin + if FSelOffset <> 0 then + begin + if FSelOffset < 0 then + begin + UTF8Delete(FText, 1 + FSelStart + FSelOffset, -FSelOffset); + FCurSorPos := FSelStart + FSelOffset; + end + else + begin + UTF8Delete(FText, 1 + FSelStart, FSelOffset); + FCurSorPos := FSelStart; + end; + FSelOffset := 0; + FSelStart := FCursorPos; + end; +end; + +procedure TfpgCustomEdit.DoCopy; +begin + if FSelOffset = 0 then + Exit; //==> + fpgClipboard.Text := SelectionText; +end; + +procedure TfpgCustomEdit.DoPaste; +var + s: string; +begin + DeleteSelection; + s := fpgClipboard.Text; + + if (FMaxLength > 0) then + if UTF8Length(FText) + UTF8Length(s) > FMaxLength then + s := UTF8Copy(s, 1, FMaxLength - UTF8Length(FText)); // trim the clipboard text if needed + + if UTF8Length(s) < 1 then + Exit; //==> + + UTF8Insert(s, FText, FCursorPos + 1); + FCursorPos := FCursorPos + UTF8Length(s); + AdjustCursor; + Repaint; +end; + end. diff --git a/src/gui/gui_popupcalendar.pas b/src/gui/gui_popupcalendar.pas index 0be547df..462feace 100644 --- a/src/gui/gui_popupcalendar.pas +++ b/src/gui/gui_popupcalendar.pas @@ -148,12 +148,9 @@ var lD, lM, lY: Word; lTheFirst: TDateTime; begin - if FDate > 0 then - begin - DecodeDate(FDate, lY, lM, lD); - lTheFirst := EncodeDate(lY, lM, 1); - FMonthOffset := 2 - DayOfWeek(lTheFirst); - end; + DecodeDate(FDate, lY, lM, lD); + lTheFirst := EncodeDate(lY, lM, 1); + FMonthOffset := 2 - DayOfWeek(lTheFirst); end; function TfpgPopupCalendar.CalculateCellDay(const ACol, ARow: LongWord): Word; @@ -189,11 +186,20 @@ begin end; procedure TfpgPopupCalendar.UpdateCalendar; +var + lD, lM, lY: Word; begin - CalculateMonthOffset; - PopulateDays; - edtYear.Text := IntToStr(Year); - edtMonth.Text := LongMonthNames[Month]; + if FDate > 0 then + begin + CalculateMonthOffset; + PopulateDays; + edtYear.Text := IntToStr(Year); + edtMonth.Text := LongMonthNames[Month]; + DecodeDate(FDate, lY, lM, lD); + writeln(' lD: ', lD); + grdName1.FocusCol := (lD - FMonthOffset) mod 7 + 1; + grdName1.FocusRow := (lD - FMonthOffset) div 7 + 1; + end; end; procedure TfpgPopupCalendar.btnYearUpClicked(Sender: TObject); @@ -240,10 +246,10 @@ procedure TfpgPopupCalendar.AfterCreate; begin {@VFD_BODY_BEGIN: fpgPopupCalendar} Name := 'fpgPopupCalendar'; - SetPosition(100, 268, 233, 179); -// WindowTitle := 'fpgPopupCalendar'; -// WindowPosition := wpUser; -// Sizeable := False; + SetPosition(100, 268, 233, 138); + // WindowTitle := 'fpgPopupCalendar'; + // WindowPosition := wpUser; + // Sizeable := False; edtYear := TfpgEdit.Create(self); with edtYear do @@ -253,6 +259,7 @@ begin Text := ''; FontDesc := '#Edit1'; Focusable := False; + BorderStyle := bsSingle; end; btnYearUp := TfpgButton.Create(self); @@ -261,10 +268,10 @@ begin Name := 'btnYearUp'; SetPosition(72, 0, 13, 11); Text := ''; + Embedded := True; FontDesc := '#Label1'; ImageMargin := 0; ImageName := 'sys.sb.up'; - Embedded := True; OnClick := @btnYearUpClicked; end; @@ -274,10 +281,10 @@ begin Name := 'btnYearDown'; SetPosition(72, 11, 13, 11); Text := ''; + Embedded := True; FontDesc := '#Label1'; ImageMargin := 0; ImageName := 'sys.sb.down'; - Embedded := True; OnClick := @btnYearDownClicked; end; @@ -285,10 +292,11 @@ begin with edtMonth do begin Name := 'edtMonth'; - SetPosition(85, 0, 136, 22); + SetPosition(85, 0, 135, 22); Text := ''; FontDesc := '#Edit1'; Focusable := False; + BorderStyle := bsSingle; end; btnMonthUp := TfpgButton.Create(self); @@ -297,10 +305,10 @@ begin Name := 'btnMonthUp'; SetPosition(220, 0, 13, 11); Text := ''; + Embedded := True; FontDesc := '#Label1'; ImageMargin := 0; ImageName := 'sys.sb.up'; - Embedded := True; OnClick := @btnMonthUpClicked; end; @@ -310,10 +318,10 @@ begin Name := 'btnMonthDown'; SetPosition(220, 11, 13, 11); Text := ''; + Embedded := True; FontDesc := '#Label1'; ImageMargin := 0; ImageName := 'sys.sb.down'; - Embedded := True; OnClick := @btnMonthDownClicked; end; @@ -321,7 +329,7 @@ begin with grdName1 do begin Name := 'grdName1'; - SetPosition(0, 23, 233, 156); + SetPosition(0, 23, 233, 114); AddColumn('Mon', 33, taLeftJustify); AddColumn('Tue', 32, taLeftJustify); AddColumn('Wed', 33, taLeftJustify); |