diff options
-rw-r--r-- | extras/tiopf/tiOPFfpGUI.lpk | 8 | ||||
-rw-r--r-- | src/corelib/gfx_widget.pas | 4 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 4 | ||||
-rw-r--r-- | src/gui/fpgui_package.lpk | 8 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 106 |
5 files changed, 115 insertions, 15 deletions
diff --git a/extras/tiopf/tiOPFfpGUI.lpk b/extras/tiopf/tiOPFfpGUI.lpk index 860ec462..663bee3b 100644 --- a/extras/tiopf/tiOPFfpGUI.lpk +++ b/extras/tiopf/tiOPFfpGUI.lpk @@ -53,16 +53,16 @@ </Files> <RequiredPkgs Count="3"> <Item1> - <PackageName Value="fpgui_package"/> - <MinVersion Minor="5" Valid="True"/> + <PackageName Value="FCL"/> + <MinVersion Major="1" Valid="True"/> </Item1> <Item2> <PackageName Value="tiOPF"/> <MinVersion Major="2" Release="3" Valid="True"/> </Item2> <Item3> - <PackageName Value="FCL"/> - <MinVersion Major="1" Valid="True"/> + <PackageName Value="fpgui_package"/> + <MinVersion Minor="5" Valid="True"/> </Item3> </RequiredPkgs> <UsageOptions> diff --git a/src/corelib/gfx_widget.pas b/src/corelib/gfx_widget.pas index 8aafe95c..7ee14ca9 100644 --- a/src/corelib/gfx_widget.pas +++ b/src/corelib/gfx_widget.pas @@ -333,14 +333,14 @@ var begin if FFormDesigner <> nil then begin -// writeln('dispatching message to designer...'); + // dispatching message to designer FFormDesigner.Dispatch(msg); Exit; end; if not FEnabled then exit; // Do we want this here? - + case msg.Params.mouse.Buttons of MOUSE_LEFT: begin diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 12522b61..07b8fe7b 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -34,8 +34,8 @@ type const MOUSE_LEFT = 1; - MOUSE_RIGHT = 2; - MOUSE_MIDDLE = 4; + MOUSE_RIGHT = 3; + MOUSE_MIDDLE = 2; // Platform independent messages used by fpGUI (TfpgWidget) FPGM_PAINT = 1; diff --git a/src/gui/fpgui_package.lpk b/src/gui/fpgui_package.lpk index 2c957e1e..a9716935 100644 --- a/src/gui/fpgui_package.lpk +++ b/src/gui/fpgui_package.lpk @@ -143,12 +143,12 @@ <LazDoc Paths="../../docs/xml/gui/"/> <RequiredPkgs Count="2"> <Item1> - <PackageName Value="fpgfx_package"/> - <MinVersion Minor="5" Valid="True"/> - </Item1> - <Item2> <PackageName Value="FCL"/> <MinVersion Major="1" Valid="True"/> + </Item1> + <Item2> + <PackageName Value="fpgfx_package"/> + <MinVersion Minor="5" Valid="True"/> </Item2> </RequiredPkgs> <UsageOptions> diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index 133def39..369379ba 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -26,7 +26,8 @@ uses SysUtils, gfxbase, fpgfx, - gfx_widget; + gfx_widget, + gui_menu; type TfpgEditBorderStyle = (bsNone, bsDefault, bsSingle); @@ -36,6 +37,8 @@ type private FAutoSelect: Boolean; FHideSelection: Boolean; + FPopupMenu: TfpgPopupMenu; + FDefaultPopupMenu: TfpgPopupMenu; FText: string; FBackgroundColor: TfpgColor; FFont: TfpgFont; @@ -56,6 +59,11 @@ type function GetFontDesc: string; procedure SetFontDesc(const AValue: string); procedure SetText(const AValue: string); + procedure DefaultPopupCut(Sender: TObject); + procedure DefaultPopupCopy(Sender: TObject); + procedure DefaultPopupPaste(Sender: TObject); + procedure DefaultPopupClearAll(Sender: TObject); + procedure SetDefaultPopupMenuItemsState; protected FMouseDragPos: integer; FDrawOffset: integer; @@ -63,10 +71,12 @@ type FSelStart: integer; FSelOffset: integer; FCursorPos: integer; + procedure ShowDefaultPopupMenu(const x, y: integer; const shiftstate: TShiftState); virtual; 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; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleRMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); override; procedure HandleMouseEnter; override; @@ -76,13 +86,14 @@ type function GetDrawText: String; property AutoSelect: Boolean read FAutoSelect write SetAutoSelect default True; property BackgroundColor: TfpgColor read FBackgroundColor write SetBackgroundColor default clBoxColor; + property BorderStyle: TfpgEditBorderStyle read FBorderStyle write SetBorderStyle default bsDefault; property Font: TfpgFont read FFont; property FontDesc: String read GetFontDesc write SetFontDesc; property HideSelection: Boolean read FHideSelection write SetHideSelection default True; + property MaxLength: Integer read FMaxLength write FMaxLength; property PasswordMode: Boolean read FPasswordMode write SetPasswordMode default False; - property BorderStyle: TfpgEditBorderStyle read FBorderStyle write SetBorderStyle default bsDefault; + property PopupMenu: TfpgPopupMenu read FPopupMenu write FPopupMenu; 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; @@ -98,6 +109,8 @@ type TfpgEdit = class(TfpgCustomEdit) + public + property PopupMenu; // UI Designer doesn't fully support it yet published property AutoSelect; property BackgroundColor; @@ -125,6 +138,14 @@ implementation uses gfx_UTF8utils, gfx_clipboard; + +const + // internal popupmenu item names + ipmCut = 'miDefaultCut'; + ipmCopy = 'miDefaultCopy'; + ipmPaste = 'miDefaultPaste'; + ipmClearAll = 'miDefaultClearAll'; + function CreateEdit(AOwner: TComponent; x, y, w, h: TfpgCoord): TfpgEdit; begin @@ -483,6 +504,15 @@ begin Repaint; end; +procedure TfpgCustomEdit.HandleRMouseDown(x, y: integer; shiftstate: TShiftState); +begin + inherited HandleRMouseDown(x, y, shiftstate); + if Assigned(PopupMenu) then + PopupMenu.ShowAt(self, x, y) + else + ShowDefaultPopupMenu(x, y, ShiftState); +end; + procedure TfpgCustomEdit.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var n: integer; @@ -586,11 +616,15 @@ begin FDrawOffset := 0; FPasswordMode := False; FBorderStyle := bsDefault; + FPopupMenu := nil; + FDefaultPopupMenu := nil; FOnChange := nil; end; destructor TfpgCustomEdit.Destroy; begin + if Assigned(FDefaultPopupMenu) then + FDefaultPopupMenu.Free; FFont.Free; inherited Destroy; end; @@ -657,6 +691,72 @@ begin RePaint; end; +procedure TfpgCustomEdit.DefaultPopupCut(Sender: TObject); +begin + CutToClipboard; +end; + +procedure TfpgCustomEdit.DefaultPopupCopy(Sender: TObject); +begin + CopyToClipboard; +end; + +procedure TfpgCustomEdit.DefaultPopupPaste(Sender: TObject); +begin + PasteFromClipboard +end; + +procedure TfpgCustomEdit.DefaultPopupClearAll(Sender: TObject); +begin + Clear; +end; + +procedure TfpgCustomEdit.SetDefaultPopupMenuItemsState; +var + i: integer; + itm: TfpgMenuItem; +begin + for i := 0 to FDefaultPopupMenu.ComponentCount-1 do + begin + if FDefaultPopupMenu.Components[i] is TfpgMenuItem then + begin + itm := TfpgMenuItem(FDefaultPopupMenu.Components[i]); + // enabled/disable menu items + if itm.Name = ipmCut then + itm.Enabled := FSelOffset <> 0 + else if itm.Name = ipmCopy then + itm.Enabled := FSelOffset <> 0 + else if itm.Name = ipmPaste then + itm.Enabled := fpgClipboard.Text <> '' + else if itm.Name = ipmClearAll then + itm.Enabled := Text <> ''; + end; + end; +end; + +procedure TfpgCustomEdit.ShowDefaultPopupMenu(const x, y: integer; + const shiftstate: TShiftState); +var + itm: TfpgMenuItem; +begin + if not Assigned(FDefaultPopupMenu) then + begin + { todo: This text needs to be localized } + FDefaultPopupMenu := TfpgPopupMenu.Create(nil); + itm := FDefaultPopupMenu.AddMenuItem('Cut', '', @DefaultPopupCut); + itm.Name := ipmCut; + itm := FDefaultPopupMenu.AddMenuItem('Copy', '', @DefaultPopupCopy); + itm.Name := ipmCopy; + itm := FDefaultPopupMenu.AddMenuItem('Paste', '', @DefaultPopupPaste); + itm.Name := ipmPaste; + itm := FDefaultPopupMenu.AddMenuItem('Clear all text', '', @DefaultPopupClearAll); + itm.Name := ipmClearAll; + end; + + SetDefaultPopupMenuItemsState; + FDefaultPopupMenu.ShowAt(self, x, y); +end; + procedure TfpgCustomEdit.DeleteSelection; begin if FSelOffset <> 0 then |