* Add definition of column type 'groups' to mysql_structures.

* Enhance the TComboBox used in fieldeditor to support option groups via owner drawing.
 * Add some ridiculously dumb functions to translate between the dropdown's index and (non-group) item index.
 * Accomplishes rfe #577.
This commit is contained in:
rosenfield.albert
2008-06-23 15:39:36 +00:00
parent 72586d0791
commit eb94d80223
3 changed files with 174 additions and 9 deletions

View File

@@ -107,11 +107,12 @@ object FieldEditForm: TFieldEditForm
Left = 88
Top = 61
Width = 165
Height = 21
Style = csDropDownList
Height = 19
Style = csOwnerDrawFixed
ItemHeight = 13
TabOrder = 2
OnChange = ComboBoxTypeChange
OnDrawItem = ComboBoxTypeDrawItem
end
object EditFieldname: TEdit
Left = 88

View File

@@ -79,6 +79,8 @@ type
procedure btnDeleteAllColumnsFromIndexClick(Sender: TObject);
procedure CheckBoxUnsignedClick(Sender: TObject);
procedure CheckBoxZerofillClick(Sender: TObject);
procedure ComboBoxTypeDrawItem(Control: TWinControl; Index: Integer; Rect:
TRect; State: TOwnerDrawState);
procedure listClick(Sender: TObject);
private
{ Private declarations }
@@ -87,6 +89,9 @@ type
FModeWhenCalled : TFieldEditorMode;
FFieldName : String;
procedure ValidateControls;
function IsCategory(index: Integer): Boolean;
function IndexToType(index: Integer): Integer;
function TypeToIndex(t: Integer): Integer;
public
{ Public declarations }
end;
@@ -145,7 +150,7 @@ end;
procedure TFieldEditForm.InitFieldEditor(Sender: TObject);
var
strtype : String;
i : Integer;
i, j : Integer;
ListColumns : TVirtualStringTree;
NodeData : PVTreeData;
begin
@@ -167,9 +172,13 @@ begin
// re-fill datatypes-combobox
ComboBoxType.Items.Clear;
for i := Low(MySqlDataTypeArray) to High(MySqlDataTypeArray) do
begin
ComboBoxType.Items.Add( MySqlDataTypeArray[i].Name );
for j := Low(MySqlDataTypeCategories) to High(MySqlDataTypeCategories) do begin
ComboBoxType.Items.Add(' ' + MySqlDataTypeCategories[j].Name);
for i := Low(MySqlDataTypeArray) to High(MySqlDataTypeArray) do begin
if MySqlDataTypeArray[i].Category = MySqlDataTypeCategories[j].Index then begin
ComboBoxType.Items.Add(MySqlDataTypeArray[i].Name);
end;
end;
end;
CheckBoxAutoIncrement.Enabled := true;
@@ -184,7 +193,7 @@ begin
begin
CheckBoxAutoIncrement.Enabled := false;
EditFieldName.Text := 'FieldName';
ComboBoxType.ItemIndex := 0;
ComboBoxType.ItemIndex := 1;
EditLength.Text := '';
EditDefault.Text := '';
EditComment.Text := '';
@@ -218,7 +227,7 @@ begin
// enable / disable length field
// get default length ..
end;
ComboBoxType.ItemIndex := MySqlDataTypeArray[i].Index;
ComboBoxType.ItemIndex := TypeToIndex(MySqlDataTypeArray[i].Index);
Break;
end;
end;
@@ -304,7 +313,36 @@ begin
ValidateControls;
end;
function TFieldEditForm.IsCategory(index: Integer): Boolean;
begin
Result := Copy(ComboBoxType.Items[index], 1, 2) = ' ';
end;
function TFieldEditForm.IndexToType(index: Integer): Integer;
var
i: Integer;
begin
for i := Low(MySqlDataTypeArray) to High(MySqlDataTypeArray) do begin
if ComboBoxType.Items[index] = MySqlDataTypeArray[i].Name then begin
Result := MySqlDataTypeArray[i].Index;
Exit;
end;
end;
raise Exception.Create('Internal error: invalid index ' + IntToStr(index) + '.');
end;
function TFieldEditForm.TypeToIndex(t: Integer): Integer;
var
i: Integer;
begin
for i := 0 to ComboBoxType.Items.Count - 1 do begin
if ComboBoxType.Items[i] = MySqlDataTypeArray[t].Name then begin
Result := i;
Exit;
end;
end;
raise Exception.Create('Internal error: invalid type ' + IntToStr(t) + '.');
end;
{***
User selected a new datatype for the selected field.
@@ -317,8 +355,13 @@ var
begin
// Attributes
// Skip column type categories
if IsCategory(ComboBoxType.ItemIndex) then begin
ComboBoxType.ItemIndex := ComboBoxType.ItemIndex + 1;
end;
// Detect column-type
FieldType := MySqlDataTypeArray[ComboBoxType.ItemIndex];
FieldType := MySqlDataTypeArray[IndexToType(ComboBoxType.ItemIndex)];
// BINARY
CheckBoxBinary.Enabled := FieldType.HasBinary;
@@ -1049,6 +1092,32 @@ begin
end;
procedure TFieldEditForm.ComboBoxTypeDrawItem(Control: TWinControl; Index:
Integer; Rect: TRect; State: TOwnerDrawState);
var
s: string;
begin
with Control as TComboBox,Canvas do begin
// decide colors
Brush.Color := clWhite;
Font.Color := clBlack;
if IsCategory(Index) or (odSelected in State) then begin
Font.Color := clWhite;
if IsCategory(Index) then Brush.Color := clBlack
else if odSelected in State then Brush.Color := clBlue
end;
// fill the rectangle first
FillRect(Rect);
// categories start with spaces to avoid hotkeys hitting them, reverse that
s := Items[Index];
if IsCategory(Index) then s := Copy(s, 4)
else s := ' ' + s;
// then print text
TextOut(Rect.Left, Rect.Top, s);
end;
end;
end.

View File

@@ -33,6 +33,13 @@ type
HasBinary: Boolean; // Can be binary?
HasDefault: Boolean; // Can have a default value?
DefLengthSet: String; // Should be set for types which require a length/set
Category: Integer;
end;
// MySQL Data Type category structure
TMysqlDataTypeCategory = record
Index: Integer;
Name: String[18];
end;
// MySQL Field structure
@@ -101,7 +108,59 @@ const
tpMULTIPOLYGON = 34;
tpGEOMETRYCOLLECTION = 35;
// MySQL field type categorization
const
catInteger = 0;
catReal = 1;
catTemporal = 2;
catText = 3;
catBinary = 4;
catIntegerNamed = 5;
catSet = 6;
catSetNamed = 7;
catSpatial = 8;
var
// MySQL data type categories
MySqlDataTypeCategories: array[0..8] of TMysqlDataTypeCategory = (
(
Index: catInteger;
Name: 'Integer'
),
(
Index: catReal;
Name: 'Real'
),
(
Index: catText;
Name: 'Text'
),
(
Index: catBinary;
Name: 'Binary'
),
(
Index: catTemporal;
Name: 'Temporal (time)'
),
(
Index: catSpatial;
Name: 'Spatial (geometry)'
),
(
Index: catIntegerNamed;
Name: 'Integer, Named'
),
(
Index: catSet;
Name: 'Set of Bits'
),
(
Index: catSetNamed;
Name: 'Set of Bits, Named'
)
);
// MySQL Data Type List and Properties
MySqlDataTypeArray: array [0..35] of TMysqlDataTypeRecord =
(
@@ -114,6 +173,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catInteger;
),
(
Index: tpSMALLINT;
@@ -124,6 +184,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catInteger;
),
(
Index: tpMEDIUMINT;
@@ -134,6 +195,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catInteger;
),
(
Index: tpINT;
@@ -144,6 +206,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catInteger;
),
(
Index: tpBIGINT;
@@ -154,6 +217,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catInteger;
),
(
Index: tpFLOAT;
@@ -164,6 +228,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catReal;
),
(
Index: tpDOUBLE;
@@ -174,6 +239,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catReal;
),
(
Index: tpDECIMAL;
@@ -184,6 +250,7 @@ var
HasZerofill: True;
HasBinary: False;
HasDefault: True;
Category: catReal;
),
(
Index: tpDATE;
@@ -194,6 +261,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catTemporal;
),
(
Index: tpTIME;
@@ -204,6 +272,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catTemporal;
),
(
Index: tpYEAR;
@@ -214,6 +283,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catTemporal;
),
(
Index: tpDATETIME;
@@ -224,6 +294,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catTemporal;
),
(
Index: tpTIMESTAMP;
@@ -234,6 +305,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catTemporal;
),
(
Index: tpCHAR;
@@ -245,6 +317,7 @@ var
HasBinary: True;
HasDefault: True;
DefLengthSet: '50';
Category: catText;
),
(
Index: tpVARCHAR;
@@ -256,6 +329,7 @@ var
HasBinary: True; // MySQL-Help says the opposite but it's valid for older versions at least.
HasDefault: True;
DefLengthSet: '50';
Category: catText;
),
(
Index: tpTINYTEXT;
@@ -266,6 +340,7 @@ var
HasZerofill: False;
HasBinary: True;
HasDefault: False;
Category: catText;
),
(
Index: tpMEDIUMTEXT;
@@ -276,6 +351,7 @@ var
HasZerofill: False;
HasBinary: True;
HasDefault: False;
Category: catText;
),
(
Index: tpTEXT;
@@ -286,6 +362,7 @@ var
HasZerofill: False;
HasBinary: True;
HasDefault: False;
Category: catText;
),
(
Index: tpLONGTEXT;
@@ -296,6 +373,7 @@ var
HasZerofill: False;
HasBinary: True;
HasDefault: False;
Category: catText;
),
(
Index: tpBINARY;
@@ -307,6 +385,7 @@ var
HasBinary: False;
HasDefault: True;
DefLengthSet: '50';
Category: catBinary;
),
(
Index: tpVARBINARY;
@@ -318,6 +397,7 @@ var
HasBinary: False;
HasDefault: True;
DefLengthSet: '50';
Category: catBinary;
),
(
Index: tpTINYBLOB;
@@ -328,6 +408,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catBinary;
),
(
Index: tpBLOB;
@@ -338,6 +419,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catBinary;
),
(
Index: tpMEDIUMBLOB;
@@ -348,6 +430,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catBinary;
),
(
Index: tpLONGBLOB;
@@ -358,6 +441,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catBinary;
),
(
Index: tpENUM;
@@ -369,6 +453,7 @@ var
HasBinary: False;
HasDefault: True;
DefLengthSet: '''Y'',''N''';
Category: catIntegerNamed;
),
(
Index: tpSET;
@@ -380,6 +465,7 @@ var
HasBinary: False;
HasDefault: True;
DefLengthSet: '''Value A'',''Value B''';
Category: catSetNamed;
),
(
Index: tpBIT;
@@ -390,6 +476,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: True;
Category: catSet;
),
(
Index: tpPOINT;
@@ -400,6 +487,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpLINESTRING;
@@ -410,6 +498,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpPOLYGON;
@@ -420,6 +509,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpGEOMETRY;
@@ -430,6 +520,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpMULTIPOINT;
@@ -440,6 +531,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpMULTILINESTRING;
@@ -450,6 +542,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpMULTIPOLYGON;
@@ -460,6 +553,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
),
(
Index: tpGEOMETRYCOLLECTION;
@@ -470,6 +564,7 @@ var
HasZerofill: False;
HasBinary: False;
HasDefault: False;
Category: catSpatial;
)
);