From 774aa2e4f9f2eb68532e49c9060ed105b0acdf86 Mon Sep 17 00:00:00 2001 From: alexs75 Date: Thu, 23 Aug 2012 17:03:53 +0000 Subject: [PATCH] in rxdbgridCollumn add property EditButtons - collection of custom buttons for edit cell. See RxDBGrid demo - collumn price git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2489 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi | 203 +++++++++++++-- .../rx/Demos/RxDBGrid/rxdbgridmainunit.lfm | 91 ++++++- .../rx/Demos/RxDBGrid/rxdbgridmainunit.pas | 30 ++- components/rx/rxdbgrid.pas | 242 +++++++++++++++++- 4 files changed, 521 insertions(+), 45 deletions(-) diff --git a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi index acb7cb195..ecb6aedc8 100644 --- a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -54,30 +54,31 @@ - + - + - + + - - - + + + @@ -170,8 +171,8 @@ - + @@ -431,9 +432,7 @@ - - @@ -441,9 +440,7 @@ - - @@ -451,18 +448,15 @@ - - - + - - - + + @@ -502,24 +496,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -574,4 +724,5 @@ + diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm index 5d38dad5b..7fe917a5f 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -1,19 +1,19 @@ object RxDBGridMainForm: TRxDBGridMainForm - Left = 151 - Height = 786 - Top = 48 + Left = 296 + Height = 721 + Top = 115 Width = 1187 ActiveControl = Panel1 Caption = 'RxDBGrid Demo' - ClientHeight = 763 + ClientHeight = 698 ClientWidth = 1187 Menu = MainMenu1 OnCreate = FormCreate ShowHint = True - LCLVersion = '0.9.31' + LCLVersion = '1.1' object RxDBGrid1: TRxDBGrid Left = 0 - Height = 699 + Height = 634 Top = 64 Width = 1187 TitleButtons = True @@ -38,6 +38,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item Title.Alignment = taCenter @@ -56,6 +57,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item Title.Alignment = taCenter @@ -71,6 +73,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item Title.Alignment = taCenter @@ -86,6 +89,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item Title.Alignment = taCenter @@ -106,6 +110,20 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = < + item + Glyph.Data = { + CE000000424DCE0000000000000076000000280000000B0000000B0000000100 + 0400000000005800000000000000000000000000000000000000000000000000 + 8000008000000080800080000000800080008080000080808000C0C0C0000000 + FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00EEEEEEEEEEE0 + 0000EEEEEEEEEEE00000EE00EEEE00E00000EEE00EE00EE00000EEEE0000EEE0 + 0000EEEEE00EEEE00000EEEE0000EEE00000EEE00EE00EE00000EE00EEEE00E0 + 0000EEEEEEEEEEE00000EEEEEEEEEEE00000 + } + Hint = 'Clear value' + OnClick = TRxColumnEditButtons2Click + end> end item Title.Alignment = taCenter @@ -120,6 +138,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item Title.Alignment = taCenter @@ -134,6 +153,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyValue = '(Нет)' Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 + EditButtons = <> end item ButtonStyle = cbsPickList @@ -152,6 +172,43 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 DirectInput = False + EditButtons = < + item + Glyph.Data = { + F6000000424DF600000000000000760000002800000010000000100000000100 + 0400000000008000000000000000000000000000000000000000000000000000 + 8000008000000080800080000000800080008080000080808000C0C0C0000000 + FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00666666006666 + 666666666077066666666666077B06666666600077B0700F766607777B0770FF + 007607BBB070000FFF067B0BB0077770F0060BBB70077700FF07607000077770 + FFF76660007777770F06666000077070000766600007770B00B0666000000007 + BB06666600000000006666666000066666666666666666666666 + } + Hint = 'Первая кнопка' + Width = 16 + OnClick = TRxColumnEditButtons0Click + end + item + Glyph.Data = { + C6010000424DC60100000000000036000000280000000A0000000A0000000100 + 2000000000009001000064000000640000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000808080FFFFFF + FFFF000000000000000000000000000000000000000000000000000000008080 + 80FF0000000000000000FFFFFFFF000000000000000000000000000000000000 + 000000000000808080FF0000000000000000FFFFFFFF00000000000000000000 + 00000000000000000000808080FF00000000000000000000000000000000FFFF + FFFF00000000000000000000000000000000808080FF00000000000000000000 + 000000000000FFFFFFFF000000000000000000000000808080FF000000000000 + 000000000000000000000000000000000000FFFFFFFF00000000000000008080 + 80FF808080FF808080FF808080FF808080FF808080FF808080FFFFFFFFFF0000 + 0000000000000000000000000000000000000000000000000000000000000000 + 00000000000000000000 + } + Hint = 'Вторая кнопка' + OnClick = TRxColumnEditButtons1Click + end> end> KeyStrokes = < item @@ -223,9 +280,9 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 Left = 270 - Height = 16 + Height = 15 Top = 7 - Width = 36 + Width = 35 BorderSpacing.Around = 6 Caption = 'Mode' ParentColor = False @@ -276,7 +333,7 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideTop.Side = asrBottom Left = 276 Height = 25 - Top = 29 + Top = 28 Width = 217 BorderSpacing.Around = 6 ItemHeight = 0 @@ -336,6 +393,12 @@ object RxDBGridMainForm: TRxDBGridMainForm TabOrder = 6 end end + object SpeedButton1: TSpeedButton + Left = 596 + Height = 22 + Top = 443 + Width = 23 + end object RxMemoryData1: TRxMemoryData AutoCalcFields = False FieldDefs = < @@ -383,6 +446,7 @@ object RxDBGridMainForm: TRxDBGridMainForm end> OnFilterRecord = RxMemoryData1FilterRecordEx OnFilterRecordEx = RxMemoryData1FilterRecordEx + PacketRecords = 0 left = 152 top = 264 object RxMemoryData1ID1: TLongintField @@ -556,7 +620,8 @@ object RxDBGridMainForm: TRxDBGridMainForm Precision = 0 Size = 130 end> - left = 240 + PacketRecords = 0 + left = 248 top = 264 object RxMemoryData2DEVELOPER_ID1: TLongintField DisplayWidth = 10 @@ -582,7 +647,7 @@ object RxDBGridMainForm: TRxDBGridMainForm end object XMLPropStorage1: TXMLPropStorage StoredValues = <> - left = 241 + left = 272 top = 128 end object ImageList1: TImageList @@ -1239,7 +1304,7 @@ object RxDBGridMainForm: TRxDBGridMainForm 050505050505050505050505050505050505C3C3BFF84F17C91A5A01F4000000 0049454E44AE426082 } - left = 858 - top = 28 + left = 856 + top = 48 end end diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas index ca34425bd..04881659c 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas @@ -21,6 +21,7 @@ type MenuItem9: TMenuItem; RxAboutDialog1: TRxAboutDialog; RxMemoryData1RAIT: TStringField; + SpeedButton1: TSpeedButton; sysExit: TAction; hlpAbout: TAction; CheckBox2: TCheckBox; @@ -77,6 +78,9 @@ type procedure showColumnsDialogExecute(Sender: TObject); procedure showFindDialogExecute(Sender: TObject); procedure sysExitExecute(Sender: TObject); + procedure TRxColumnEditButtons0Click(Sender: TObject); + procedure TRxColumnEditButtons1Click(Sender: TObject); + procedure TRxColumnEditButtons2Click(Sender: TObject); private procedure DoFillFilters; public @@ -129,9 +133,9 @@ begin RxMemoryData1.AppendRecord([14, 'Бух. комплекс "45-я Параллель"', 180, 'ООО "Boot"', EncodeDate(2007, 2, 1), 3]); RxMemoryData1.AppendRecord([15, 'Консультант+', 380, 'Консультант+', EncodeDate(2007, 2, 1), 3]); RxMemoryData1.AppendRecord([16, 'Гарант', 480, 'Гарант', EncodeDate(2007, 2, 1), 3]); -// DoFillFilters; + RxMemoryData1.First; - RxDBGrid1.CalcStatTotals; //fix error in GotoBookmark +// RxDBGrid1.CalcStatTotals; //fix error in GotoBookmark end; @@ -179,6 +183,24 @@ begin Close; end; +procedure TRxDBGridMainForm.TRxColumnEditButtons0Click(Sender: TObject); +begin + ShowMessage('Click first button'); +end; + +procedure TRxDBGridMainForm.TRxColumnEditButtons1Click(Sender: TObject); +begin + ShowMessage('Click next button'); +end; + +procedure TRxDBGridMainForm.TRxColumnEditButtons2Click(Sender: TObject); +begin + if RxMemoryData1.State <> dsEdit then + RxMemoryData1.Edit; + RxMemoryData1PRICE1.Clear; + RxMemoryData1.Post; +end; + procedure TRxDBGridMainForm.DoFillFilters; var C:TRxColumn; @@ -206,7 +228,7 @@ end; procedure TRxDBGridMainForm.actCalcTotalExecute(Sender: TObject); begin - RxDBGrid1.CalcStatTotals; //fix error in GotoBookmark + RxDBGrid1.CalcStatTotals; end; procedure TRxDBGridMainForm.actOptimizeColumnsWidthAllExecute(Sender: TObject); @@ -254,7 +276,5 @@ begin RxDBGrid1.ReadOnly:=ComboBox1.ItemIndex <> 0; end; -//TRxAboutDialog - end. diff --git a/components/rx/rxdbgrid.pas b/components/rx/rxdbgrid.pas index bd8508ab8..25445f1a5 100644 --- a/components/rx/rxdbgrid.pas +++ b/components/rx/rxdbgrid.pas @@ -37,7 +37,7 @@ unit rxdbgrid; interface uses - Classes, SysUtils, LResources, LCLType, LCLIntf, Forms, Controls, + Classes, SysUtils, LResources, LCLType, LCLIntf, Forms, Controls, Buttons, Graphics, Dialogs, Grids, dbutils, DBGrids, DB, PropertyStorage, vclutils, LMessages, types, StdCtrls, Menus; @@ -70,6 +70,9 @@ type TRxDBGridAllowedOperation = (aoInsert, aoUpdate, aoDelete, aoAppend); TRxDBGridAllowedOperations = set of TRxDBGridAllowedOperation; + TRxColumnEditButtonStyle = (ebsDropDownRx, ebsEllipsisRx, ebsGlyphRx, ebsUpDownRx, + ebsPlusRx, ebsMinusRx); + TFooterValueType = (fvtNon, fvtSum, fvtAvg, fvtCount, fvtFieldValue, fvtStaticText, fvtMax, fvtMin, fvtRecNo); @@ -294,11 +297,64 @@ type property ItemIndex: integer read GetItemIndex write SetItemIndex; end; + { TRxColumnEditButton } + + TRxColumnEditButton = class(TCollectionItem) + private + FShortCut: TShortCut; + FStyle: TRxColumnEditButtonStyle; + FButton:TSpeedButton; + FVisible: Boolean; + function GetGlyph: TBitmap; + function GetHint: String; + function GetNumGlyphs: Integer; + function GetOnButtonClick: TNotifyEvent; + function GetWidth: Integer; + procedure SetGlyph(AValue: TBitmap); + procedure SetHint(AValue: String); + procedure SetNumGlyphs(AValue: Integer); + procedure SetOnButtonClick(AValue: TNotifyEvent); + procedure SetStyle(AValue: TRxColumnEditButtonStyle); + procedure SetVisible(AValue: Boolean); + procedure SetWidth(AValue: Integer); + protected + function GetDisplayName: string; override; + public + constructor Create(ACollection: TCollection); override; + destructor Destroy; override; + published + //property DropdownMenu: TPopupMenu read FDropdownMenu write FDropdownMenu; :TODO: + property Glyph: TBitmap read GetGlyph write SetGlyph; + property Hint: String read GetHint write SetHint; + property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1; + property ShortCut: TShortCut read FShortCut write FShortCut default scNone; + property Style: TRxColumnEditButtonStyle read FStyle write SetStyle default ebsDropDownRx; + property Visible: Boolean read FVisible write SetVisible default true; + property Width: Integer read GetWidth write SetWidth default 15; + property OnClick: TNotifyEvent read GetOnButtonClick write SetOnButtonClick; + //property OnDown: TNotifyEvent read FOnButtonDown write FOnButtonDown; + end; + + TRxColumnEditButtons = class(TCollection) + private + FOwner: TPersistent; + function GetItem(Index: integer): TRxColumnEditButton; + procedure SetItem(Index: integer; AValue: TRxColumnEditButton); + protected + procedure Update(Item: TCollectionItem); override; + public + constructor Create(AOwner: TPersistent); + function Add: TRxColumnEditButton; + public + property Items[Index: integer]: TRxColumnEditButton read GetItem write SetItem; default; + end; + { TRxColumn } TRxColumn = class(TColumn) private FDirectInput: boolean; + FEditButtons: TRxColumnEditButtons; FFooter: TRxColumnFooter; FFilter: TRxColumnFilter; FImageList: TImageList; @@ -306,6 +362,7 @@ type FNotInKeyListIndex: integer; function GetFooter: TRxColumnFooter; function GetKeyList: TStrings; + procedure SetEditButtons(AValue: TRxColumnEditButtons); procedure SetFilter(const AValue: TRxColumnFilter); procedure SetFooter(const AValue: TRxColumnFooter); procedure SetImageList(const AValue: TImageList); @@ -325,6 +382,7 @@ type write SetNotInKeyListIndex default -1; property Filter: TRxColumnFilter read FFilter write SetFilter; property DirectInput : boolean read FDirectInput write FDirectInput default true; + property EditButtons:TRxColumnEditButtons read FEditButtons write SetEditButtons; end; { TRxDbGridColumns } @@ -469,6 +527,7 @@ type override; procedure LinkActive(Value: boolean); override; procedure DrawFooterRows; virtual; + procedure DoTitleClick(ACol: longint; AField: TField); virtual; procedure MouseMove(Shift: TShiftState; X, Y: integer); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; @@ -508,6 +567,10 @@ type procedure OnChooseVisibleFields(Sender: TObject); procedure Loaded; override; procedure UpdateFooterRowOnUpdateActive; + + procedure DoEditorHide; override; + procedure DoEditorShow; override; + public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -743,6 +806,125 @@ type procedure EditingDone; override; end; +{ TRxColumnEditButton } + +function TRxColumnEditButton.GetGlyph: TBitmap; +begin + Result:=FButton.Glyph; +end; + +function TRxColumnEditButton.GetHint: String; +begin + Result:=FButton.Hint; +end; + +function TRxColumnEditButton.GetNumGlyphs: Integer; +begin + Result:=FButton.NumGlyphs; +end; + +function TRxColumnEditButton.GetOnButtonClick: TNotifyEvent; +begin + Result:=FButton.OnClick; +end; + +function TRxColumnEditButton.GetWidth: Integer; +begin + Result:=FButton.Width; +end; + +procedure TRxColumnEditButton.SetGlyph(AValue: TBitmap); +begin + FButton.Glyph.Assign(AValue); + if not (csLoading in TRxDBGrid(TRxColumnEditButtons(Collection).Owner).ComponentState) then + FStyle:=ebsGlyphRx; +end; + +procedure TRxColumnEditButton.SetHint(AValue: String); +begin + FButton.Hint:=AValue; +end; + +procedure TRxColumnEditButton.SetNumGlyphs(AValue: Integer); +begin + FButton.NumGlyphs:=AValue; +end; + +procedure TRxColumnEditButton.SetOnButtonClick(AValue: TNotifyEvent); +begin + FButton.OnClick:=AValue; +end; + +procedure TRxColumnEditButton.SetStyle(AValue: TRxColumnEditButtonStyle); +begin + if FStyle=AValue then Exit; + FStyle:=AValue; +end; + +procedure TRxColumnEditButton.SetVisible(AValue: Boolean); +begin + if FVisible=AValue then Exit; + FVisible:=AValue; + FButton.Visible:=AValue; +end; + +procedure TRxColumnEditButton.SetWidth(AValue: Integer); +begin + FButton.Width:=AValue; +end; + +function TRxColumnEditButton.GetDisplayName: string; +begin + if Hint<>'' then + Result:=Hint + else + Result:='TRxColumnEditButton'; +end; + +constructor TRxColumnEditButton.Create(ACollection: TCollection); +begin + inherited Create(ACollection); + FButton:=TSpeedButton.Create(nil); + FButton.Glyph:=LoadLazResBitmapImage('rx_markerdown'); + FVisible:=true; + Width:=15; +end; + +destructor TRxColumnEditButton.Destroy; +begin + FreeAndNil(FButton); + inherited Destroy; +end; + +{ TRxColumnEditButtons } + +function TRxColumnEditButtons.GetItem(Index: integer): TRxColumnEditButton; +begin + Result:= TRxColumnEditButton(inherited Items[Index]); +end; + +procedure TRxColumnEditButtons.SetItem(Index: integer; + AValue: TRxColumnEditButton); +begin + inherited SetItem(Index, AValue); +end; + +procedure TRxColumnEditButtons.Update(Item: TCollectionItem); +begin + inherited Update(Item); +end; + +constructor TRxColumnEditButtons.Create(AOwner: TPersistent); +begin + inherited Create(TRxColumnEditButton); + FOwner:=AOwner; +end; + +function TRxColumnEditButtons.Add: TRxColumnEditButton; +begin + Result := TRxColumnEditButton(inherited Add); +end; + { TRxDBGridFooterOptions } procedure TRxDBGridFooterOptions.SetActive(AValue: boolean); @@ -3335,6 +3517,57 @@ begin FOldDataSetState:=dsInactive; end; +procedure TRxDBGrid.DoEditorHide; +var + R:TRxColumn; + i, w:integer; +begin + inherited DoEditorHide; + R:=SelectedColumn as TRxColumn; + + if Assigned(Editor) then + for i:=0 to R.EditButtons.Count-1 do + R.EditButtons[i].FButton.Visible:=false; +end; + +procedure TRxDBGrid.DoEditorShow; +var + R:TRxColumn; + i, w:integer; +begin + inherited DoEditorShow; + + R:=SelectedColumn as TRxColumn; + + if Assigned(Editor) then + begin + W:=0; + for i:=0 to R.EditButtons.Count-1 do + begin + if R.EditButtons[i].Visible then + W:=W+R.EditButtons[i].Width; + end; + + if W>0 then + begin + Editor.Width:=Editor.Width - W; + W:=Editor.Width + Editor.Left; + + for i:=0 to R.EditButtons.Count-1 do + if R.EditButtons[i].Visible then + begin + R.EditButtons[i].FButton.Parent:=Self; + R.EditButtons[i].FButton.Left:=W; + R.EditButtons[i].FButton.Top:=Editor.Top; + R.EditButtons[i].FButton.Height:=Editor.Height; + R.EditButtons[i].FButton.Visible:=true; + + W:=W+R.EditButtons[i].FButton.Width; + end; + end; + end; +end; + procedure TRxDBGrid.GetOnCreateLookup; begin if Assigned(F_CreateLookup) then @@ -3490,6 +3723,11 @@ begin Result := FKeyList; end; +procedure TRxColumn.SetEditButtons(AValue: TRxColumnEditButtons); +begin + FEditButtons.Assign(AValue); +end; + procedure TRxColumn.SetFilter(const AValue: TRxColumnFilter); begin FFilter.Assign(AValue); @@ -3546,10 +3784,12 @@ begin FFooter := TRxColumnFooter.Create(Self); FFilter := TRxColumnFilter.Create(Self); FDirectInput := true; + FEditButtons:=TRxColumnEditButtons.Create(Self); end; destructor TRxColumn.Destroy; begin + FreeAndNil(FEditButtons); if FKeyList <> nil then begin FKeyList.Free;