00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_WXICONBOX_H
00023 #define MECHSYS_WXICONBOX_H
00024
00025 #include <wx/vlbox.h>
00026 #include <wx/icon.h>
00027 #include <wx/imaglist.h>
00028
00029 class WxIconBox : public wxVListBox
00030 {
00031 public:
00032 WxIconBox(wxWindow * parent, wxWindowID id=wxID_ANY, const wxPoint & pos=wxDefaultPosition, int Width=-1, int nLines=1);
00033
00034
00035
00036
00037
00038
00039 void OnDrawItem (wxDC & dc, const wxRect & rect, size_t n) const;
00040 wxCoord OnMeasureItem (size_t n) const;
00041
00042 void Add(wxIcon const & anIcon);
00043 void Add(wxIcon const & anIcon, wxString const & Text);
00044 private:
00045
00046 int _width;
00047 int _n_lines;
00048 mutable wxImageList _icons;
00049 mutable wxArrayString _text;
00050
00051 void _draw_button(wxDC & dc, wxRect const & BtnRect) const;
00052 };
00053
00054
00056
00057 inline WxIconBox::WxIconBox(wxWindow * parent, wxWindowID id, const wxPoint & pos, int Width, int nLines)
00058 : wxVListBox (parent, id, pos, wxDefaultSize, wxSUNKEN_BORDER),
00059 _width (Width),
00060 _n_lines (nLines)
00061 {
00062 }
00063
00064 inline void WxIconBox::OnDrawItem (wxDC & dc, const wxRect & rect, size_t n) const
00065 {
00066 int x=rect.GetX();
00067 int y=rect.GetY();
00068 int w,h;
00069 _icons.GetSize(0, w, h);
00070 _icons.Draw(n,dc,x,y);
00071 if (_text.size()>0)
00072 {
00073
00074 wxFont font(12,wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
00075 dc.SetFont(font);
00076 dc.SetBackgroundMode(wxTRANSPARENT);
00077 dc.SetTextForeground(*wxBLACK);
00078 dc.SetTextBackground(*wxWHITE);
00079 wxCoord wtxt,htxt;
00080 GetTextExtent(_text[n], &wtxt, &htxt);
00081 dc.DrawText(_text[n],wxPoint(x+w,y+(h-htxt)/2));
00082 }
00083
00084
00085
00086
00087 }
00088
00089 inline wxCoord WxIconBox::OnMeasureItem (size_t n) const
00090 {
00091 int w,h;
00092 _icons.GetSize(0, w, h);
00093 return h;
00094 }
00095
00096 inline void WxIconBox::Add(wxIcon const & anIcon)
00097 {
00098 _icons.Add(anIcon);
00099 SetItemCount(GetItemCount()+1);
00100 if (_width==-1) _width=anIcon.GetWidth();
00101 SetClientSize(_width,anIcon.GetHeight()*_n_lines);
00102 }
00103
00104 inline void WxIconBox::Add(wxIcon const & anIcon, wxString const & Text)
00105 {
00106 _icons.Add(anIcon);
00107 _text.Add(Text);
00108 SetItemCount(GetItemCount()+1);
00109 if (_width==-1) _width=wxDefaultSize.GetWidth();
00110 SetClientSize(_width,anIcon.GetHeight()*_n_lines);
00111 }
00112
00113 inline void WxIconBox::_draw_button(wxDC & dc, wxRect const & BtnRect) const
00114 {
00115
00116 wxColour bg_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
00117 wxColour fg_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
00118 wxColour sh_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
00119 wxColour hi_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
00120 dc.SetBrush(wxBrush(bg_clr, wxSOLID));
00121 dc.SetPen(wxPen(bg_clr, 1, wxSOLID));
00122 dc.DrawRectangle(BtnRect);
00123 dc.SetPen(wxPen(fg_clr, 1, wxSOLID));
00124 dc.DrawLine(BtnRect.GetLeft() , BtnRect.GetBottom(), BtnRect.GetRight(), BtnRect.GetBottom());
00125 dc.DrawLine(BtnRect.GetRight(), BtnRect.GetBottom(), BtnRect.GetRight(), BtnRect.GetTop()-1);
00126 dc.SetPen(wxPen(sh_clr, 1, wxSOLID));
00127 dc.DrawLine(BtnRect.GetLeft()+1 , BtnRect.GetBottom()-1, BtnRect.GetRight()-1, BtnRect.GetBottom()-1);
00128 dc.DrawLine(BtnRect.GetRight()-1, BtnRect.GetBottom()-1, BtnRect.GetRight()-1, BtnRect.GetTop());
00129 dc.SetPen(wxPen(hi_clr, 1, wxSOLID));
00130 dc.DrawLine(BtnRect.GetRight()-2, BtnRect.GetTop()+1, BtnRect.GetLeft()+1, BtnRect.GetTop()+1);
00131 dc.DrawLine(BtnRect.GetLeft()+1 , BtnRect.GetTop()+1, BtnRect.GetLeft()+1, BtnRect.GetBottom()-1);
00132
00133 int W = BtnRect.GetWidth();
00134 int H = BtnRect.GetHeight();
00135 int w = H/3;
00136 int h = H/6;
00137 wxPoint point[3];
00138 point[0] = wxPoint(BtnRect.GetX()+(W-w)/2,BtnRect.GetY()+(H-h)/2);
00139 point[1] = wxPoint(point[0].x+w,point[0].y);
00140 point[2] = wxPoint(point[0].x+w/2,point[0].y+h);
00141 dc.SetBrush(wxBrush(fg_clr, wxSOLID));
00142 dc.SetPen(wxPen(fg_clr, 1, wxSOLID));
00143 dc.DrawPolygon(3, point);
00144 }
00145
00146 #endif // MECHSYS_WXICONBOX_H
00147
00148