diff options
Diffstat (limited to 'extras/contributed')
-rw-r--r-- | extras/contributed/editgrid/u_demo.pas | 96 | ||||
-rw-r--r-- | extras/contributed/editgrid/u_editgrid.pas | 145 |
2 files changed, 212 insertions, 29 deletions
diff --git a/extras/contributed/editgrid/u_demo.pas b/extras/contributed/editgrid/u_demo.pas index 0513970e..fc22f668 100644 --- a/extras/contributed/editgrid/u_demo.pas +++ b/extras/contributed/editgrid/u_demo.pas @@ -24,6 +24,7 @@ type Rb_Comma: TfpgRadioButton; Ckb_Space: TfpgCheckBox; Ckb_Thousand: TfpgCheckBox; + Ckb_NegativeColor: TfpgCheckBox; P_EditCombo: TfpgPanel; Ckb_AutoComplete: TfpgCheckBox; Rb_No: TfpgRadioButton; @@ -35,6 +36,7 @@ type procedure Bt_AddOneClick(Sender: TObject); procedure Ckb_LimitsChange(Sender: TObject); procedure Ckb_ThousandChange(Sender: TObject); + procedure Ckb_NegativeColorChange(Sender: TObject); procedure Rb_Change(Sender: TObject); procedure Ckb_SpaceChange(Sender: TObject); procedure Ckb_FloatDecChange(Sender: TObject); @@ -65,6 +67,11 @@ ComboBoxListe.Add('two'); ComboBoxListe.Add('three'); ComboBoxListe.Add('four'); ComboBoxListe.Add('five'); +ComboBoxListe.Add('six'); +ComboBoxListe.Add('seven'); +ComboBoxListe.Add('eight'); +ComboBoxListe.Add('nine'); +ComboBoxListe.Add('ten'); end; procedure TF_Demo.EG_GridKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; @@ -145,17 +152,48 @@ var Cpt: Integer; begin with EG_Grid do + begin for Cpt:= 0 to Pred(ColumnCount) do if Ckb_Thousand.Checked then case ColumnEditType[Cpt] of etInteger, etFloat, etCurrency: + begin NumericShowThousand[Cpt]:= True; + Ckb_Space.Enabled:= False; + end; end else case ColumnEditType[Cpt] of etInteger, etFloat, etCurrency: + begin NumericShowThousand[Cpt]:= False; + Ckb_Space.Enabled:= True; + end; end; + Invalidate; + end; +end; + +procedure TF_Demo.Ckb_NegativeColorChange(Sender: TObject); +var + Cpt: Integer; +begin + with EG_Grid do + begin + for Cpt:= 0 to Pred(ColumnCount) do + if Ckb_NegativeColor.Checked then + case ColumnEditType[Cpt] of + etInteger, etFloat, etCurrency: + NumericNegativeColor[Cpt]:= clRed; + + end + else + case ColumnEditType[Cpt] of + etInteger, etFloat, etCurrency: + NumericNegativeColor[Cpt]:= clBlack; + end; + Invalidate; + end; end; procedure TF_Demo.Rb_Change(Sender: TObject); @@ -163,6 +201,7 @@ var Cpt: Integer; begin with EG_Grid do + begin for Cpt:= 0 to Pred(ColumnCount) do if Sender is TfpgRadioButton then case (Sender as TfpgRadioButton).tag of @@ -194,6 +233,8 @@ begin end; end; end; + Invalidate; + end; end; procedure TF_Demo.Ckb_SpaceChange(Sender: TObject); @@ -329,35 +370,31 @@ with EG_Grid do begin AddColumn('None',50,taCenter); AddColumn('Text',100,etText); + TextColor[Pred(ColumnCount)] := clBlue; AddColumn('Integer',90,etInteger,taRightJustify); - //AddColumn('Float',90,etFloat,taRightJustify); - //FloatFixedDecimals[Pred(ColumnCount)]:= 3; - //NumericDecimals[Pred(ColumnCount)]:= 3; - //AddColumn('Currency',90,etCurrency,taRightJustify); - //AddColumn('ComboBox',120,etComboBox); - //for Cpt:= 0 to Pred(ComboBoxListe.Count) do - // AddComboItem(Pred(ColumnCount),ComboBoxListe[Cpt]); - //AddColumn('EditCombo',120,etEditCombo); - //AddEditcomboItem(Pred(ColumnCount),'un'); - //AddEditcomboItem(Pred(ColumnCount),'deux'); - //AddEditcomboItem(Pred(ColumnCount),'trois'); - //AddEditcomboItem(Pred(ColumnCount),'quatre'); - //AddEditcomboItem(Pred(ColumnCount),'cinq'); - //AutoComplete[Pred(ColumnCount)] := True; - //AllowNew[Pred(ColumnCount)] := anAsk; - //AddColumn('CheckBox',100,etCheckBox,taCenter); - //BoxCheckedText[Pred(ColumnCount)] := 'True'; - //BoxUncheckedText[Pred(ColumnCount)] := 'False'; - //BoxDisplayText[Pred(ColumnCount)] := 'CheckBox'; - //AddColumn('Calendar',120,etCalendar,taCenter); - //GridDateFormat[Pred(ColumnCount)] := LongDateFormat; - //CalendarDateFormat[Pred(ColumnCount)] := ShortDateFormat; - //DateValue[Pred(ColumnCount)] := Now; - //WeekStartDay[Pred(ColumnCount)] := 1; - //WeeklyHoliday[Pred(ColumnCount)] := 7; - //DayColor[Pred(ColumnCount)] := clBlue; - //HoliDayColor[Pred(ColumnCount)] := clRed; - //SingleClickSelect[Pred(ColumnCount)] := True; + AddColumn('Float',90,etFloat,taRightJustify); + AddColumn('Currency',90,etCurrency,taRightJustify); + AddColumn('ComboBox',120,etComboBox); + for Cpt:= 0 to Pred(ComboBoxListe.Count) do + AddComboItem(Pred(ColumnCount),ComboBoxListe[Cpt]); + ComboBoxDropDownCount[Pred(ColumnCount)] := 6; + AddColumn('EditCombo',120,etEditCombo); + AutoComplete[Pred(ColumnCount)] := True; + AllowNew[Pred(ColumnCount)] := anAsk; + EditComboDropDownCount[Pred(ColumnCount)] := 4; + AddColumn('CheckBox',100,etCheckBox,taCenter); + BoxCheckedText[Pred(ColumnCount)] := 'True'; + BoxUncheckedText[Pred(ColumnCount)] := 'False'; + BoxDisplayText[Pred(ColumnCount)] := 'CheckBox'; + AddColumn('Calendar',120,etCalendar,taCenter); + GridDateFormat[Pred(ColumnCount)] := LongDateFormat; + CalendarDateFormat[Pred(ColumnCount)] := ShortDateFormat; + DateValue[Pred(ColumnCount)] := Now; + WeekStartDay[Pred(ColumnCount)] := 1; + WeeklyHoliday[Pred(ColumnCount)] := 7; + DayColor[Pred(ColumnCount)] := clBlue; + HoliDayColor[Pred(ColumnCount)] := clRed; + SingleClickSelect[Pred(ColumnCount)] := True; DefaultRowHeight:= 20; HeaderFontDesc:= 'bitstream vera sans-10:bold'; // Options:= [go_HideFocusRect]; @@ -386,6 +423,9 @@ Ckb_Space.OnChange:= @Ckb_SpaceChange; Ckb_Thousand:= CreateCheckBox(Self,400,Height-40,'Show thousand separator'); Ckb_Thousand.OnChange:= @Ckb_ThousandChange; Ckb_Thousand.Checked:= True; +Ckb_NegativeColor:= CreateCheckBox(Self,400,Height-20,'Negative values in red'); +Ckb_NegativeColor.OnChange:= @Ckb_NegativeColorChange; +Ckb_NegativeColor.Checked:= True; P_EditCombo:= CreatePanel(Self,650,Height-110,170,100,'EditCombo',bsFlat,taCenter,tlTop); Ckb_AutoComplete:= CreateCheckBox(P_EditCombo,10,20,'Auto Completion'); Ckb_AutoComplete.OnChange:= @Ckb_AutoCompleteChange; diff --git a/extras/contributed/editgrid/u_editgrid.pas b/extras/contributed/editgrid/u_editgrid.pas index 70b0d52d..17446fa6 100644 --- a/extras/contributed/editgrid/u_editgrid.pas +++ b/extras/contributed/editgrid/u_editgrid.pas @@ -26,7 +26,7 @@ type TfpgColumnData = class(TObject) private FMaxSet: boolean; - FminSet: boolean; + FMinSet: boolean; public constructor Create; destructor Destroy; override; @@ -42,6 +42,7 @@ type FDecimalSeparator: TfpgChar; FThousandSeparator: TfpgChar; FShowThousand: boolean; + FNegativeColor: TfpgColor; public constructor Create; destructor Destroy; override; @@ -51,6 +52,7 @@ type property DecimalSeparator: TfpgChar read FDecimalSeparator write FDecimalSeparator; property ThousandSeparator: TfpgChar read FThousandSeparator write FThousandSeparator; property ShowThousand: boolean read FShowThousand write FShowThousand; + property NegativeColor: TfpgColor read FNegativeColor write FNegativeColor; end; TfpgIntegerColumn = class(TfpgNumericColumn) @@ -91,10 +93,12 @@ type TfpgComboBoxColumn = class(TfpgColumnData) private FItems: TStringList; + FDropDownCount: integer; public constructor Create; destructor Destroy; override; property Items: TStringList read FItems write FItems; + property DropDownCount: integer read FDropDownCount write FDropDownCount; end; TfpgEditComboColumn = class(TfpgColumnData) @@ -102,12 +106,14 @@ type FItems: TStringList; FAutoComplete: boolean; FAllowNew: TAllowNew; + FDropDownCount: integer; public constructor Create; destructor Destroy; override; property Items: TStringList read FItems write FItems; property AutoComplete: boolean read FAutoComplete write FAutoComplete; property AllowNew: TAllowNew read FAllowNew write FAllowNew; + property DropDownCount: integer read FDropDownCount write FDropDownCount; end; TfpgCheckBoxColumn = class(TfpgColumnData) @@ -184,7 +190,11 @@ type const AMousePos: TPoint); procedure EditGridMouseDown(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); + procedure EditGridDrawCell(Sender: TObject; const ARow, ACol: Integer; const ARect: TfpgRect; + const AFlags: TfpgGridDrawState; var ADefaultDrawing: boolean); function GetColumnEditType(AIndex: integer): TEditType; + function GetTextColor(AIndex: integer): TfpgColor; + procedure SetTextColor(AIndex: integer; const AValue: TfpgColor); procedure SetEditCell; procedure CloseEditCell; procedure SetReturnWay; @@ -204,6 +214,8 @@ type procedure SetNumericThousandSeparator(AIndex: integer; const AValue: TfpgChar); function GetNumericShowThousand(AIndex: integer): boolean; procedure SetNumericShowThousand(AIndex: integer; const AValue: boolean); + function GetNumericNegativeColor(AIndex: integer): TfpgColor; + procedure SetNumericNegativeColor(AIndex: integer; const AValue: TfpgColor); procedure IniIntegerCell; procedure FCellEditIntegerKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); @@ -230,6 +242,8 @@ type procedure IniComboBoxCell; procedure FCellComboBoxKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); + function GetComboBoxDropDownCount(AIndex: integer): integer; + procedure SetComboBoxDropDownCount(AIndex: integer; AValue: integer); procedure IniEditComboCell; procedure FCellEditComboKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); @@ -237,6 +251,8 @@ type procedure SetAutoComplete(AIndex: integer; const AValue: boolean); function GetAllowNew(AIndex: integer): TAllowNew; procedure SetAllowNew(AIndex: integer; AValue: TAllowNew); + function GetEditComboDropDownCount(AIndex: integer): integer; + procedure SetEditComboDropDownCount(AIndex: integer; AValue: integer); procedure IniCheckBoxCell; procedure FCellCheckBoxKeyPress(Sender: TObject; var KeyCode: word; var ShiftState: TShiftState; var Consumed: boolean); @@ -285,12 +301,14 @@ type function AddColumn(ATitle: string; AWidth: integer; AEditType: TEditType = etNone; AAlignment: TAlignment = taLeftJustify; AbackgroundColor: TfpgColor = clDefault; ATextColor: TfpgColor = clDefault): TfpgEditColumn; overload; property ColumnEditType[AIndex: integer]: TEditType read GetColumnEditType; + property TextColor[AIndex: integer]: TfpgColor read GetTextColor write SetTextColor; property NumericMaxLimit[AIndex: integer]: boolean read GetNumericMaxLimit write SetNumericMaxLimit; property NumericMinLimit[AIndex: integer]: boolean read GetNumericMinLimit write SetNumericMinLimit; property NumericDecimals[AIndex: integer]: integer read GetNumericDecimals write SetNumericDecimals; property NumericDecimalSeparator[AIndex: integer]: TfpgChar read GetNumericDecimalSeparator write SetNumericDecimalSeparator; property NumericThousandSeparator[AIndex: integer]: TfpgChar read GetNumericThousandSeparator write SetNumericThousandSeparator; property NumericShowThousand[AIndex: integer]: boolean read GetNumericShowThousand write SetNumericShowThousand; + property NumericNegativeColor[AIndex: integer]: Tfpgcolor read GetNumericNegativeColor write SetNumericNegativeColor; property MaxIntValue[AIndex: integer]: integer read GetMaxIntValue write SetMaxIntValue; property MinIntValue[AIndex: integer]: integer read GetMinIntValue write SetMinIntValue; property MaxFloatValue[AIndex: integer]: extended read GetMaxFloatValue write SetMaxFloatValue; @@ -299,9 +317,11 @@ type property MaxCurrValue[AIndex: integer]: currency read GetMaxCurrValue write SetMaxCurrValue; property MinCurrValue[AIndex: integer]: currency read GetMinCurrValue write SetMinCurrValue; procedure AddComboItem(AIndex: integer; const AValue: string); + property ComboBoxDropDownCount[AIndex: integer]: integer read GetComboBoxDropDownCount write SetComboBoxDropDownCount; procedure AddEditComboItem(AIndex: integer; const AValue: string); property AutoComplete[AIndex: integer]: boolean read GetAutoComplete write SetAutoComplete; property AllowNew[AIndex: integer]: TAllowNew read GetAllowNew write SetAllowNew; + property EditComboDropDownCount[AIndex: integer]: integer read GetEditComboDropDownCount write SetEditComboDropDownCount; property BoxCheckedText[AIndex: integer]: string read GetBoxCheckedText write SetBoxCheckedText; property BoxUncheckedText[AIndex: integer]: string read GetBoxUncheckedText write SetBoxUncheckedText; property BoxDisplayText[AIndex: integer]: string read GetBoxDisplayText write SetBoxDisplayText; @@ -539,11 +559,100 @@ begin CloseEditCell; end; +procedure TfpgCustomEditGrid.EditGridDrawCell(Sender: TObject; const ARow, ACol: Integer; const ARect: TfpgRect; + const AFlags: TfpgGridDrawState; var ADefaultDrawing: boolean); +var + Txt, Deci: string; + tSeparator,dseparator: TfpgChar; +begin + case Columns[Acol].EditType of + etInteger: + begin + if Copy(Cells[ACol, ARow],1,1) = '-' then + begin + Txt:= UTF8Copy(Cells[ACol, ARow],2,Pred(UTF8Length(Cells[ACol, ARow]))); + Canvas.TextColor:= TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).NegativeColor; + end + else + Txt:= Cells[ACol, ARow]; + if UTF8Length(Txt)> 3 then + begin + tSeparator:= TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).ThousandSeparator; + if TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).ShowThousand then + begin + if UTF8Pos(tSeparator,Txt) = 0 then + begin + Txt:= UTF8Copy(Txt, 1, UTF8Length(txt) - 3) + tSeparator + UTF8Copy(Txt, UTF8Length(Txt) - 2, 3); + while UTF8Pos(tSeparator,Txt) > 3 do + Txt:= UTF8Copy(Txt, 1, UTF8Pos(tSeparator,Txt) - 4) + tSeparator + + UTF8Copy(Txt, UTF8Pos(tSeparator,Txt) - 3, UTF8Length(txt) - UTF8Pos(tSeparator,Txt) + 4); + end; + end + else + if UTF8Pos(tSeparator,Txt) > 0 then + while UTF8Pos(tSeparator,Txt) > 0 do + Txt:= UTF8Copy(txt, 1, Pred(UTF8Pos(tSeparator, txt))) + +UTF8Copy(txt, Succ(UTF8Pos(tSeparator, txt)), UTF8Length(txt) - UTF8Pos(tSeparator, txt)); + if Copy(Cells[ACol, ARow],1,1) = '-' then + Cells[ACol, ARow] := '-' + Txt + else + Cells[ACol, ARow] := Txt; + end; + end; + etFloat, etCurrency: + begin + if Copy(Cells[ACol, ARow],1,1) = '-' then + begin + Txt:= UTF8Copy(Cells[ACol, ARow],2,Pred(UTF8Length(Cells[ACol, ARow]))); + Canvas.TextColor:= TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).NegativeColor; + end + else + Txt:= Cells[ACol, ARow]; + dSeparator:= TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).DecimalSeparator; + if UTF8Pos(dSeparator,Txt) > 0 then + Deci:= Copy(Cells[ACol, ARow], UTF8Pos(dSeparator,Txt), UTF8Length(Cells[ACol, ARow]) - Pred(UTF8Pos(dSeparator,Txt))); + if (UTF8Length(Txt) - UTF8Length(Deci)) > 3 then + begin + tSeparator:= TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).ThousandSeparator; + if TfpgNumericColumn(TfpgEditColumn(Columns[ACol]).Data).ShowThousand then + begin + if UTF8Pos(tSeparator,Txt) = 0 then + begin + Txt:= UTF8Copy(Txt, 1, UTF8Length(txt) - UTF8Length(Deci) - 3) + tSeparator + UTF8Copy(Txt, UTF8Length(Txt) - UTF8Length(Deci) - 2, 3) + Deci; + while UTF8Pos(tSeparator,Txt) > 3 do + Txt:= UTF8Copy(Txt, 1, UTF8Pos(tSeparator,Txt) - 4) + tSeparator + + UTF8Copy(Txt, UTF8Pos(tSeparator,Txt) - 3, UTF8Length(txt) - UTF8Length(Deci) - UTF8Pos(tSeparator,Txt) + 4) + Deci; + end; + end + else + if UTF8Pos(tSeparator,Txt) > 0 then + while UTF8Pos(tSeparator,Txt) > 0 do + Txt:= UTF8Copy(txt, 1, Pred(UTF8Pos(tSeparator, txt))) + +UTF8Copy(txt, Succ(UTF8Pos(tSeparator, txt)), UTF8Length(txt) - UTF8Length(Deci) - UTF8Pos(tSeparator, txt)) + Deci; + if Copy(Cells[ACol, ARow],1,1) = '-' then + Cells[ACol, ARow] := '-' + Txt + else + Cells[ACol, ARow] := Txt; + end; + end; + end; +end; + function TfpgCustomEditGrid.GetColumnEditType(AIndex: integer): TEditType; begin Result := TfpgEditColumn(Columns[AIndex]).EditType; end; +function TfpgCustomEditGrid.GetTextColor(AIndex: integer): TfpgColor; +begin + Result := TfpgEditColumn(Columns[AIndex]).TextColor; +end; + +procedure TfpgCustomEditGrid.SetTextColor(AIndex: integer; const AValue: TfpgColor); +begin + TfpgEditColumn(Columns[AIndex]).TextColor := AValue; +end; + procedure TfpgCustomEditGrid.SetEditCell; begin case Columns[FocusCol].EditType of @@ -767,6 +876,16 @@ begin TfpgNumericColumn(TfpgEditColumn(Columns[AIndex]).Data).ShowThousand := AValue; end; +function TfpgCustomEditGrid.GetNumericNegativeColor(AIndex: integer): TfpgColor; +begin + Result := TfpgNumericColumn(TfpgEditColumn(Columns[AIndex]).Data).NegativeColor; +end; + +procedure TfpgCustomEditGrid.SetNumericNegativeColor(AIndex: integer; const AValue: TfpgColor); +begin + TfpgNumericColumn(TfpgEditColumn(Columns[AIndex]).Data).NegativeColor := AValue; +end; + procedure TfpgCustomEditGrid.IniIntegerCell; var Pt: TPoint; @@ -789,6 +908,7 @@ begin MinValue := MinIntValue[FocusCol]; CustomThousandSeparator := TfpgNumericColumn(TfpgEditColumn(Columns[FocusCol]).Data).ThousandSeparator; ShowThousand := TfpgNumericColumn(TfpgEditColumn(Columns[FocusCol]).Data).ShowThousand; + NegativeColor := TfpgNumericColumn(TfpgEditColumn(Columns[FocusCol]).Data).NegativeColor; OnKeyPress := @FCellEditIntegerKeyPress; SetFocus; end; @@ -1090,6 +1210,7 @@ begin for i := 0 to Pred(Items.Count) do if Items[i] = Cells[FocusCol, FocusRow] then Text := Items[i]; + DropDownCount := TfpgComboBoxColumn(TfpgEditColumn(Columns[FocusCol]).Data).DropDownCount; OnKeyPress := @FCellComboBoxKeyPress; SetFocus; end; @@ -1123,6 +1244,16 @@ begin end; end; +function TfpgCustomEditGrid.GetComboBoxDropDownCount(AIndex: integer): integer; +begin + Result := TfpgComboBoxColumn(TfpgEditColumn(Columns[AIndex]).Data).DropDownCount; +end; + +procedure TfpgCustomEditGrid.SetComboBoxDropDownCount(AIndex: integer; AValue: integer); +begin + TfpgComboBoxColumn(TfpgEditColumn(Columns[AIndex]).Data).DropDownCount := AValue; +end; + procedure TfpgCustomEditGrid.IniEditComboCell; var Pt: TPoint; @@ -1145,6 +1276,7 @@ begin Text := Items[i]; AutoCompletion := TfpgEditComboColumn(TfpgEditColumn(Columns[FocusCol]).Data).AutoComplete; AllowNew := TfpgEditComboColumn(TfpgEditColumn(Columns[FocusCol]).Data).AllowNew; + DropDownCount := TfpgEditComboColumn(TfpgEditColumn(Columns[FocusCol]).Data).DropDownCount; OnKeyPress := @FCellEditComboKeyPress; SetFocus; end; @@ -1200,6 +1332,16 @@ begin TfpgEditComboColumn(TfpgEditColumn(Columns[AIndex]).Data).AllowNew := AValue; end; +function TfpgCustomEditGrid.GetEditComboDropDownCount(AIndex: integer): integer; +begin + Result := TfpgEditComboColumn(TfpgEditColumn(Columns[AIndex]).Data).DropDownCount; +end; + +procedure TfpgCustomEditGrid.SetEditComboDropDownCount(AIndex: integer; AValue: integer); +begin + TfpgEditComboColumn(TfpgEditColumn(Columns[AIndex]).Data).DropDownCount := AValue; +end; + procedure TfpgCustomEditGrid.IniCheckBoxCell; var Pt: TPoint; @@ -1554,6 +1696,7 @@ begin OnDoubleClick := @EditGridDoubleClick; OnFocusChange := @EditGridFocusChange; OnMouseDown := @EditGridMouseDown; + OnDrawCell := @EditGridDrawCell; FEditing := False; FEditWay := edNone; end; |