From 6c2178c4d639f6cbe75303794bd23f065a1b7aae Mon Sep 17 00:00:00 2001 From: vincents Date: Wed, 29 Nov 2006 12:22:26 +0000 Subject: [PATCH] =?UTF-8?q?added=20TColorListBox=20from=20Diogo=20Pi=C3=A7?= =?UTF-8?q?arra?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: trunk@10255 - --- .gitattributes | 1 + docs/Contributors.txt | 1 + docs/xml/lcl/controls.xml | 6 +- docs/xml/lcl/dialogs.xml | 8 +- images/components/tcolorlistbox.xpm | 197 ++++++++++++++++++++++ lcl/colorbox.pas | 248 +++++++++++++++++++++++++++- lcl/editbtn.pas | 2 +- 7 files changed, 457 insertions(+), 6 deletions(-) create mode 100644 images/components/tcolorlistbox.xpm diff --git a/.gitattributes b/.gitattributes index ff4094cd39..609e086f1a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1703,6 +1703,7 @@ images/components/tcolorbutton.xpm -text svneol=native#image/x-xpixmap images/components/tcolorcombobox.xpm svneol=native#text/plain images/components/tcolordialog.ico -text svneol=unset#image/x-icon images/components/tcolordialog.xpm -text svneol=native#image/x-xpixmap +images/components/tcolorlistbox.xpm -text svneol=native#image/x-xpixmap images/components/tcombobox.ico -text svneol=unset#image/x-icon images/components/tcombobox.xpm -text svneol=native#image/x-xpixmap images/components/tcomboedit.xpm -text svneol=native#image/x-xpixmap diff --git a/docs/Contributors.txt b/docs/Contributors.txt index 6f4026b60f..6b7e8e1c00 100644 --- a/docs/Contributors.txt +++ b/docs/Contributors.txt @@ -21,6 +21,7 @@ Curtis White Darek Mazur Darius Blaszijk Dean Zobec +Diogo Piçarra Ere Maijala Eric Chapman Erivelton Silva diff --git a/docs/xml/lcl/controls.xml b/docs/xml/lcl/controls.xml index 92eacdc488..25839d62d6 100644 --- a/docs/xml/lcl/controls.xml +++ b/docs/xml/lcl/controls.xml @@ -6971,9 +6971,9 @@ Used to align the control in one of four directions. - - - + + + diff --git a/docs/xml/lcl/dialogs.xml b/docs/xml/lcl/dialogs.xml index 95b0d5982e..2c598eaf70 100644 --- a/docs/xml/lcl/dialogs.xml +++ b/docs/xml/lcl/dialogs.xml @@ -1464,7 +1464,13 @@ The MessageDlgPos function does not enable you to choose the caption of the dial Show a question to the user and get a response - QuestionDlg has the same functionality as MessageDlg except for the parameter Buttons which is of a different type. You can define your own captions and return values of this function. + QuestionDlg has the same functionality as MessageDlg except for the parameter Buttons which is of a different type. You can define your own captions and return values of this function.<br/> +Buttons is a list of TModalResult and strings. For each TModalResult a button is + created. To set a custom caption, add a string after a button. + +The default TModalResults defined in controls.pp (mrNone..mrLast) don't need + + caption. The default captions will be used. diff --git a/images/components/tcolorlistbox.xpm b/images/components/tcolorlistbox.xpm new file mode 100644 index 0000000000..293bbecd3e --- /dev/null +++ b/images/components/tcolorlistbox.xpm @@ -0,0 +1,197 @@ +/* XPM */ +static char *tlistbox[]={ +"20 19 175 2", +".H c #000000", +".p c #000002", +"#Q c #000004", +".q c #000005", +"aI c #000007", +"aR c #000009", +"#j c #00000b", +"aM c #00000c", +"aS c #00000e", +"aK c #00000f", +"aO c #000014", +"#w c #000019", +"#M c #00001e", +"#E c #000023", +"#L c #000080", +".Z c #0000ff", +".n c #000100", +"a. c #000200", +".5 c #000207", +"aL c #00020f", +"ap c #000300", +".z c #00ff00", +".2 c #010000", +".L c #010002", +".1 c #010100", +"#u c #010101", +"ad c #01010b", +".F c #020005", +".R c #020202", +"#T c #02020c", +"#J c #030207", +"#q c #030416", +"#9 c #030500", +".m c #040500", +"aN c #040519", +".I c #050400", +"aG c #05040c", +".A c #050503", +".W c #060405", +".J c #060503", +"aP c #060513", +"a# c #060702", +"aJ c #070614", +"aj c #070705", +"#Y c #070709", +"aQ c #070904", +"aB c #080c00", +".o c #090907", +".r c #0a0911", +"#K c #6d6b92", +"#n c #777992", +"Qt c #79797b", +"al c #797a7c", +".a c #7a797f", +".y c #7a7981", +".h c #7a7987", +"#B c #7a79a1", +".i c #7a7a86", +".C c #7c7b77", +".e c #7c7c84", +"ah c #7c7d7f", +"aH c #7d7c82", +".f c #7d7d89", +"#v c #7d7da1", +"aq c #7e7d83", +"aa c #7e7f84", +".3 c #7e8387", +".d c #808183", +".G c #817f8a", +".# c #818085", +"#Z c #818090", +".k c #828284", +".j c #82828a", +".X c #82828c", +".M c #83818e", +".b c #848388", +".c c #848587", +".l c #858583", +"#. c #858994", +"as c #86858a", +".D c #878586", +".g c #898795", +"#R c #8a8aa4", +".s c #908f94", +"#p c #ab172f", +".U c #b7b6b2", +"#r c #b7b8bd", +"#k c #b9bcc5", +"#l c #babcb7", +"#N c #babcc9", +".K c #bbb9bc", +"aE c #bbb9c6", +"#X c #bbbbb9", +"ag c #bbbcb7", +"aC c #bbbeb5", +".9 c #bdbeb8", +".E c #bebcc1", +".7 c #bec0bb", +"ac c #c0c000", +"#t c #c0c0c0", +"#O c #c0c1c6", +"aF c #c1bfca", +".S c #c1c2bc", +".V c #c2c0c1", +"#G c #c2c1d1", +"#V c #c2c3bb", +".x c #c3c2c8", +"ar c #c4c3c9", +"#I c #c5c4cc", +"ak c #c5c5c3", +"aD c #c7c6cc", +"#z c #c8c8d0", +".T c #c9c8c3", +"#x c #c9ccd5", +"ay c #f0efff", +"#h c #f1f3ff", +"au c #f2ecff", +"#5 c #f2f1ff", +"#d c #f2f4ff", +"#0 c #f3f3ff", +"#c c #f3f5ff", +"#a c #f3f6ff", +"ai c #f3f8f4", +"ax c #f4f2ff", +"#y c #f4f4fe", +"#e c #f4f6ff", +"#o c #f6f8ff", +"aA c #f6fbe5", +"#C c #f7f4ff", +"#1 c #f7f6ff", +"#f c #f7f7ff", +"#b c #f7f9ff", +"#D c #f8f1ff", +"#g c #f8f5ff", +"#4 c #f8f7ff", +"#3 c #f8f8ff", +"## c #f8fcff", +"#6 c #f9f7ff", +".Y c #f9f8ff", +".P c #f9f9ff", +"#W c #f9faf2", +"an c #f9fcf5", +".Q c #fafaff", +"#U c #fafcf9", +"#8 c #fafdff", +"av c #fbf5ff", +"aw c #fbf9ff", +"#2 c #fbfaff", +"#H c #fbfbff", +"#F c #fbfcff", +".4 c #fbfeff", +"#i c #fbffff", +".O c #fcf9ff", +"#P c #fcfbff", +"#S c #fcfcff", +"af c #fcfdf5", +"#7 c #fcfdff", +"ab c #fcfeff", +".0 c #fcffff", +"am c #fdfdff", +".u c #fdfef8", +"#s c #fdfeff", +"at c #fefbff", +".w c #fefeff", +"ao c #feffef", +"az c #fefff6", +"ae c #fefffa", +".6 c #feffff", +".N c #fffdff", +"#A c #fffeff", +".8 c #fffff8", +".B c #fffffa", +"#m c #fffffb", +".v c #fffffd", +".t c #ffffff", +"Qt.#.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r", +".s.t.t.t.t.t.t.t.t.t.t.t.t.t.n.u.v.w.x.q", +".y.t.z.z.z.z.z.z.z.z.z.z.z.t.A.B.C.D.E.F", +".G.t.z.z.z.z.z.z.z.z.z.z.z.t.H.u.I.J.K.L", +".M.N.O.t.t.t.t.t.t.t.t.t.P.Q.R.S.T.U.V.W", +".X.Y.Z.Z.Z.Z.Z.Z.Z.Z.Z.Z.Z.0.p.1.n.I.2.H", +".3.4.Z.Z.Z.Z.Z.Z.Z.Z.Z.Z.Z.0.5.6.7.8.9.H", +"#.###a#b#c#d#e#e#d#f#g#f#h#i#j#k.6#l#m.A", +"#n#o#p#p#p#p#p#p#p#p#p#p#p.t#q.0#r#s#t#u", +"#v.t#p#p#p#p#p#p#p#p#p#p#p.t#w#x#y#z#A.p", +"#B.t.t.t.t.t.t#C#D.t.t.t.t.t#E#F#G#H#I#J", +"#K.t#L#L#L#L#L#L#L#L#L#L#L.t#M#N.w#O#P#Q", +"#R#H#L#L#L#L#L#L#L#L#L#L#L#S#T#U#V#W#X#Y", +"#Z#0#1#2#c#3#4#5.Y#f#6#H#7#8.p.n#9a.a#.H", +"aaabacacacacacacacacacacac.0ad.6aeafag.A", +"ah.wacacacacacacacacacacacai.q.6.Hajak.H", +"alam.t.t.t.t.t.t.t.t.t#Sanaoapan.kaqar#Q", +"as.w.watauav#gawaxay#P#eazaAaBaCaDaEaFaG", +"aHaI#jaJaKaL#jaMaNaOaPaI.naQ.najaRaSaSaR"}; diff --git a/lcl/colorbox.pas b/lcl/colorbox.pas index abe7f6af7a..f1e42ff6bf 100644 --- a/lcl/colorbox.pas +++ b/lcl/colorbox.pas @@ -1,5 +1,6 @@ { TColorBox is component that displays colors in a combobox + TColorListBox is component that displays colors in a listbox Copyright (C) 2005 Darius Blaszijk @@ -47,6 +48,10 @@ type published property Align; property Anchors; + property ArrowKeysTraverseList; + property AutoComplete; + property AutoCompleteText; + property AutoDropDown; property BorderSpacing; property Color; property Ctl3D; @@ -56,7 +61,9 @@ type property Enabled; property Font; property ItemHeight; + property ItemIndex; property Items; + property ItemWidth; property MaxLength; property Palette: TColorPalette read FPalette write SetPalette; property ParentColor; @@ -64,6 +71,7 @@ type property ParentFont; property ParentShowHint; property PopupMenu; + property ReadOnly; property ShowHint; property Sorted; property TabOrder; @@ -71,12 +79,15 @@ type property Text; property Visible; property OnChange; + property OnChangeBounds; property OnClick; + property OnCloseUp; property OnDblClick; property OnDragDrop; property OnDragOver; property OnDrawItem; property OnDropDown; + property OnEditingDone; property OnEndDrag; property OnEnter; property OnExit; @@ -84,7 +95,72 @@ type property OnKeyPress; property OnKeyUp; property OnMeasureItem; + property OnMouseDown; + property OnMouseMove; + property OnMouseUp; property OnStartDrag; + property OnSelect; + end; + + TColorListBox = class(TCustomListBox) + private + FPalette: TColorPalette; + function GetSelection: TColor; + procedure SetSelection(Value: TColor); + procedure SetPalette(Value: TColorPalette); + protected + procedure SetStyle(Value: TListBoxStyle); override; + procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override; + public + constructor Create(AOwner: TComponent); override; + procedure SetColorList; + property Selection: TColor read GetSelection write SetSelection; + published + property Align; + property Anchors; + property BorderSpacing; + property BorderStyle; + property ClickOnSelChange; + property Color; + property Constraints; + property Enabled; + property ExtendedSelect; + property Font; + property IntegralHeight; + property ItemHeight; + property Items; + property MultiSelect; + property Palette: TColorPalette read FPalette write SetPalette; + property ParentColor; + property ParentFont; + property ParentShowHint; + property PopupMenu; + property ShowHint; + property Sorted; + property TabOrder; + property TabStop; + property TopIndex; + property Visible; + property OnChangeBounds; + property OnClick; + property OnDblClick; + property OnDrawItem; + property OnEnter; + property OnExit; + property OnKeyDown; + property OnKeyPress; + property OnKeyUp; + property OnMouseDown; + property OnMouseEnter; + property OnMouseLeave; + property OnMouseMove; + property OnMouseUp; + property OnMouseWheel; + property OnMouseWheelDown; + property OnMouseWheelUp; + property OnResize; + property OnSelectionChange; + property OnShowHint; end; procedure Register; @@ -102,7 +178,7 @@ const {------------------------------------------------------------------------------} procedure Register; begin - RegisterComponents('Additional', [TColorBox]); + RegisterComponents('Additional', [TColorBox, TColorListBox]); end; {------------------------------------------------------------------------------ Method: TColorBox.Create @@ -274,4 +350,174 @@ begin end; end; {------------------------------------------------------------------------------} +{------------------------------------------------------------------------------ + Method: TColorListBox.Create + Params: AOwner + Returns: Nothing + + Use Create to create an instance of TColorListBox and initialize all properties + and variables. + + ------------------------------------------------------------------------------} +constructor TColorListBox.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + + FPalette := cpDefault; + + SetColorList; + + Style := lbOwnerDrawFixed; +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.GetSelection + Params: None + Returns: TColor + + Use GetSelection to convert the item selected into a system color. + + ------------------------------------------------------------------------------} +function TColorListBox.GetSelection: TColor; +begin + Result := 0; + if ItemIndex >= 0 then + if not IdentToColor(Items[ItemIndex], LongInt(Result)) then + Result := 0; +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.SetSelection + Params: Value + Returns: Nothing + + Use SetSelection to set the item in the ColorListBox when appointed a color + from code. + + ------------------------------------------------------------------------------} +procedure TColorListBox.SetSelection(Value: TColor); +var + c: integer; + i: Longint; +begin + ItemIndex := -1; + + for c := 0 to Pred(Items.Count) do + if IdentToColor(Items[c], i) then + if i = Value then + ItemIndex := c; +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.SetPalette + Params: Value + Returns: Nothing + + Use SetPalette to determine wether to reset the colorlist in the ColorListBox + based on the type of palette. + + ------------------------------------------------------------------------------} +procedure TColorListBox.SetPalette(Value: TColorPalette); +begin + if Value <> FPalette then + begin + FPalette := Value; + SetColorList; + end; +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.SetStyle + Params: Value + Returns: Nothing + + Use SetStyle to prevent the style to be changed to anything else than + lbOwnerDrawFixed. + + ------------------------------------------------------------------------------} +procedure TColorListBox.SetStyle(Value: TListBoxStyle); +begin + inherited SetStyle(lbOwnerDrawFixed); +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.DrawItem + Params: Index, Rect, State + Returns: Nothing + + Use DrawItem to customdraw an item in the ColorListBox. A color preview is drawn + and the item rectangle is made smaller and given to the inherited method to + draw the corresponding text. The Brush color and Pen color where changed and + reset to their original values. + + ------------------------------------------------------------------------------} +procedure TColorListBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); +var + r: TRect; + ItemColor: TColor; + BrushColor: TColor; + PenColor: TColor; +begin + if Index<0 then + exit; + r.top := Rect.top + 3; + r.bottom := Rect.bottom - 3; + r.left := Rect.left + 3; + r.right := r.left + 14; + Exclude(State,odPainted); + with Canvas do begin + FillRect(Rect); + + BrushColor := Brush.Color; + PenColor := Pen.Color; + + if IdentToColor(Items[Index], LongInt(ItemColor)) then + Brush.Color := ItemColor; + + Pen.Color := clBlack; + + Rectangle(r); + + Brush.Color := BrushColor; + Pen.Color := PenColor; + end; + r := Rect; + r.left := r.left + 20; + + //DebugLn('TColorListBox.DrawItem ',dbgs(Index),' ',dbgs(r),' ',dbgs(odPainted in State),' ',dbgs(Assigned(OndrawItem))); + inherited DrawItem(Index, r, State); +end; +{------------------------------------------------------------------------------ + Method: TColorListBox.SetColorList + Params: None + Returns: Nothing + + Use SetColorList to fill the itemlist in the ColorListBox with the right color + entries. Based on the value of the Palette property. + + ------------------------------------------------------------------------------} +procedure TColorListBox.SetColorList; +var + c: Longint; + s: ANSIString; + m: TIdentMapEntry; +begin + with Items do + begin + Clear; + + //add palettes as desired + case Palette of + cpFull : begin + c := 0; + while IdentEntry(c, m) do + begin + Add(m.Name); + Inc(c); + end; + end; + else + begin + for c := 0 to High(ColorDefault) do + if ColorToIdent(ColorDefault[c], s) then Add(s); + end; + end; + end; +end; +{------------------------------------------------------------------------------} end. \ No newline at end of file diff --git a/lcl/editbtn.pas b/lcl/editbtn.pas index c9ccd42c29..bfb1ffdbea 100644 --- a/lcl/editbtn.pas +++ b/lcl/editbtn.pas @@ -1,6 +1,6 @@ { /*************************************************************************** - edirbtn.pas + editbtn.pas ----------- Component Library Extended dialogs Controls