diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-23 22:41:38 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-03-23 22:41:38 +0000 |
commit | 5a9025391a90f6c66a38436c74e7de88efd68621 (patch) | |
tree | fc5e35a5530366ea269ae8dab38b97673f53dc9c /src/gui | |
parent | b3d0fa099f95a2ef19fc35ec24d4749c28e74974 (diff) | |
download | fpGUI-5a9025391a90f6c66a38436c74e7de88efd68621.tar.xz |
* Implemented a basic Color ListBox component. It is still incomplete and has no published properties yet.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui_combobox.pas | 2 | ||||
-rw-r--r-- | src/gui/gui_editcombo.pas | 1 | ||||
-rw-r--r-- | src/gui/gui_listbox.pas | 178 |
3 files changed, 179 insertions, 2 deletions
diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas index f0ebe833..c08b31a8 100644 --- a/src/gui/gui_combobox.pas +++ b/src/gui/gui_combobox.pas @@ -70,6 +70,7 @@ type procedure SetFocusItem(const AValue: integer); procedure SetFontDesc(const AValue: string); protected + FInternalBtnRect: TfpgRect; FFocusItem: integer; FItems: TStringList; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; @@ -92,7 +93,6 @@ type TfpgAbstractComboBox = class(TfpgBaseComboBox) private - FInternalBtnRect: TfpgRect; procedure InternalBtnClick(Sender: TObject); procedure SetFocusItem(const AValue: integer); procedure CalculateInternalButtonRect; diff --git a/src/gui/gui_editcombo.pas b/src/gui/gui_editcombo.pas index b6bfb6c3..7198a1ef 100644 --- a/src/gui/gui_editcombo.pas +++ b/src/gui/gui_editcombo.pas @@ -72,7 +72,6 @@ type FText: string; FSelectedItem: integer; FMaxLength: integer; - FInternalBtnRect: TfpgRect; FNewItem: boolean; procedure SetAllowNew(const AValue: TAllowNew); procedure InternalBtnClick(Sender: TObject); diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas index 219ced11..298b998f 100644 --- a/src/gui/gui_listbox.pas +++ b/src/gui/gui_listbox.pas @@ -130,6 +130,40 @@ type property TabOrder; property TextColor; end; + + + // simple data class containing color information + TColorItem = class(TObject) + public + constructor Create(const AColorName: string; const AColorValue: TfpgColor); + ColorName: string; + ColorValue: TfpgColor; + end; + + + TfpgColorPalette = (cpStandardColors, cpSystemColors, cpWebColors); + + + TfpgColorListBox = class(TfpgBaseListBox) + private + FColorBoxWidth: TfpgCoord; + FColorBoxHeight: TfpgCoord; + FColorPalette: TfpgColorPalette; + procedure SetColorPalette (const AValue: TfpgColorPalette ); + procedure SetupColorPalette; + procedure FreeAndClearColors; + protected + FItems: TList; + procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); override; +// procedure HandleKeyChar(var AText: TfpgChar; var shiftstate: TShiftState; var consumed: boolean); override; + property Items: TList read FItems; + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + function ItemCount: integer; override; + function Color: TfpgColor; + property ColorPalette: TfpgColorPalette read FColorPalette write SetColorPalette; + end; function CreateListBox(AOwner: TComponent; x, y, w, h: TfpgCoord): TfpgListBox; @@ -713,5 +747,149 @@ begin result := ''; end; +{ TColorItem } + +constructor TColorItem.Create (const AColorName: string; const AColorValue: TfpgColor); +begin + inherited Create; + ColorName := AColorName; + ColorValue := AColorValue; +end; + +{ TfpgColorListBox } + +procedure TfpgColorListBox.SetColorPalette (const AValue: TfpgColorPalette ); +begin + if FColorPalette = AValue then + exit; + FColorPalette := AValue; + SetupColorPalette; +// Repaint; +end; + +procedure TfpgColorListBox.SetupColorPalette; +begin + FreeAndClearColors; + + case FColorPalette of + cpStandardColors: + begin + FItems.Add(TColorItem.Create('clAqua', clAqua)); + FItems.Add(TColorItem.Create('clBlack', clBlack)); + FItems.Add(TColorItem.Create('clBlue', clBlue)); + FItems.Add(TColorItem.Create('clCream', clCream)); + FItems.Add(TColorItem.Create('clDkGray', clDkGray)); + FItems.Add(TColorItem.Create('clFuchsia', clFuchsia)); + FItems.Add(TColorItem.Create('clGray', clGray)); + FItems.Add(TColorItem.Create('clGreen', clGreen)); + FItems.Add(TColorItem.Create('clLime', clLime)); + FItems.Add(TColorItem.Create('clLtGray', clLtGray)); + FItems.Add(TColorItem.Create('clMaroon', clMaroon)); + FItems.Add(TColorItem.Create('clNavy', clNavy)); + FItems.Add(TColorItem.Create('clOlive', clOlive)); + FItems.Add(TColorItem.Create('clPurple', clPurple)); + FItems.Add(TColorItem.Create('clRed', clRed)); + FItems.Add(TColorItem.Create('clSilver', clSilver)); + FItems.Add(TColorItem.Create('clTeal', clTeal)); + FItems.Add(TColorItem.Create('clWhite', clWhite)); + FItems.Add(TColorItem.Create('clYellow', clYellow)); + FItems.Add(TColorItem.Create('clMoneyGreen', clMoneyGreen)); + FItems.Add(TColorItem.Create('clSkyBlue', clSkyBlue)); + FItems.Add(TColorItem.Create('clMedGray', clMedGray)); + end; + cpSystemColors: + begin + FItems.Add(TColorItem.Create('clWindowBackground', clWindowBackground)); + FItems.Add(TColorItem.Create('clBoxColor', clBoxColor)); + FItems.Add(TColorItem.Create('clButtonFace', clButtonFace)); + FItems.Add(TColorItem.Create('clShadow1', clShadow1)); + FItems.Add(TColorItem.Create('clShadow2', clShadow2)); + FItems.Add(TColorItem.Create('clHilite1', clHilite1)); + FItems.Add(TColorItem.Create('clHilite2', clHilite2)); + FItems.Add(TColorItem.Create('clText1', clText1)); + FItems.Add(TColorItem.Create('clText2', clText2)); + FItems.Add(TColorItem.Create('clText3', clText3)); + FItems.Add(TColorItem.Create('clText4', clText4)); + FItems.Add(TColorItem.Create('clSelection', clSelection)); + FItems.Add(TColorItem.Create('clSelectionText', clSelectionText)); + FItems.Add(TColorItem.Create('clInactiveSel', clInactiveSel)); + FItems.Add(TColorItem.Create('clInactiveSelText', clInactiveSelText)); + FItems.Add(TColorItem.Create('clScrollBar', clScrollBar)); + FItems.Add(TColorItem.Create('clListBox', clListBox)); + FItems.Add(TColorItem.Create('clGridLines', clGridLines)); + FItems.Add(TColorItem.Create('clGridHeader', clGridHeader)); + FItems.Add(TColorItem.Create('clWidgetFrame', clWidgetFrame)); + FItems.Add(TColorItem.Create('clInactiveWgFrame', clInactiveWgFrame)); + FItems.Add(TColorItem.Create('clTextCursor', clTextCursor)); + FItems.Add(TColorItem.Create('clChoiceListBox', clChoiceListBox)); + FItems.Add(TColorItem.Create('clUnset', clUnset)); + FItems.Add(TColorItem.Create('clMenuText', clMenuText)); + FItems.Add(TColorItem.Create('clMenuDisabled', clMenuDisabled)); + end; + cpWebColors: + begin + { TODO : Need to add the web colors } + FItems.Add(TColorItem.Create('clRed', clRed)); + FItems.Add(TColorItem.Create('clGreen', clGreen)); + FItems.Add(TColorItem.Create('clBlue', clBlue)); + FItems.Add(TColorItem.Create('clBlack', clBlack)); + end; + end; +end; + +procedure TfpgColorListBox.FreeAndClearColors; +var + i: integer; +begin + for i := 0 to FItems.Count-1 do + TColorItem(FItems.Items[i]).Free; + FItems.Clear; +end; + +procedure TfpgColorListBox.DrawItem (num: integer; rect: TfpgRect; flags: integer ); +var + itm: TColorItem; +begin + if num < 1 then + Exit; + itm := TColorItem(FItems.Items[num-1]); + // color box + Canvas.SetColor(itm.ColorValue); + Canvas.FillRectangle(rect.Left + 2, rect.Top + 4, FColorBoxWidth, FColorboxHeight); + Canvas.SetColor(clBlack); + Canvas.DrawRectangle(rect.Left + 2, rect.Top + 4, FColorBoxWidth, FColorboxHeight); + // color text + fpgStyle.DrawString(Canvas, FColorboxWidth + 8 + rect.left, rect.top+1, itm.ColorName, Enabled); +end; + +constructor TfpgColorListBox.Create (AOwner: TComponent ); +begin + inherited Create (AOwner ); + FColorBoxWidth := 35; + FColorBoxHeight := 10; + + FItems := TList.Create; + // default Delphi colors + FColorPalette := cpStandardColors; + SetupColorPalette; +end; + +destructor TfpgColorListBox.Destroy; +begin + FreeAndClearColors; + FItems.Free; + inherited Destroy; +end; + +function TfpgColorListBox.ItemCount: integer; +begin + result := FItems.Count; +end; + +function TfpgColorListBox.Color: TfpgColor; +begin + Result := TColorItem(FItems.Items[FocusItem]).ColorValue; +end; + end. |