]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/customcombo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: customcombo.cpp
3 // Purpose: Implement some custom wxComboCtrls
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx/wx.h".
10 #include "wx/wxprec.h"
16 // for all others, include the necessary headers
22 #error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
25 #include "customcombo.h"
28 BEGIN_EVENT_TABLE(ListViewComboPopup
, wxListView
)
29 EVT_MOTION(ListViewComboPopup::OnMouseMove
)
30 // NOTE: Left down event is used instead of left up right now
31 // since MSW wxListCtrl doesn't seem to emit left ups
33 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick
)
36 BEGIN_EVENT_TABLE(TreeCtrlComboPopup
, wxTreeCtrl
)
37 EVT_MOTION(TreeCtrlComboPopup::OnMouseMove
)
38 // NOTE: Left down event is used instead of left up right now
39 // since MSW wxTreeCtrl doesn't seem to emit left ups
41 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick
)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 void PenStyleComboBox::OnDrawItem( wxDC
& dc
,
55 if ( item
== wxNOT_FOUND
)
62 int penStyle
= wxSOLID
;
64 // penStyle = wxTRANSPARENT;
65 // else if ( item == 2 )
67 // else if ( item == 3 )
68 // penStyle = wxLONG_DASH;
69 // else if ( item == 4 )
70 // penStyle = wxSHORT_DASH;
72 penStyle
= wxDOT_DASH
;
74 penStyle
= wxBDIAGONAL_HATCH
;
76 penStyle
= wxCROSSDIAG_HATCH
;
77 // else if ( item == 8 )
78 // penStyle = wxFDIAGONAL_HATCH;
79 // else if ( item == 9 )
80 // penStyle = wxCROSS_HATCH;
81 // else if ( item == 10 )
82 // penStyle = wxHORIZONTAL_HATCH;
83 // else if ( item == 11 )
84 // penStyle = wxVERTICAL_HATCH;
86 wxPen
pen( dc
.GetTextForeground(), 3, penStyle
);
88 // Get text colour as pen colour
91 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
93 dc
.DrawText(GetString( item
),
95 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
98 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
102 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
106 void PenStyleComboBox::OnDrawBackground( wxDC
& dc
, const wxRect
& rect
,
107 int item
, int flags
) const
109 // If item is selected or even, or we are painting the
110 // combo control itself, use the default rendering.
111 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
114 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
118 // Otherwise, draw every other background with different colour.
119 wxColour
bgCol(240,240,250);
120 dc
.SetBrush(wxBrush(bgCol
));
121 dc
.SetPen(wxPen(bgCol
));
122 dc
.DrawRectangle(rect
);
125 inline wxCoord
PenStyleComboBox::OnMeasureItem( size_t item
) const
127 // Simply demonstrate the ability to have variable-height items
134 inline wxCoord
PenStyleComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
136 return -1; // default - will be measured from text width
139 PenStyleComboBox
* PenStyleComboBox::CreateSample(wxWindow
* parent
)
141 PenStyleComboBox
* odc
;
143 // Common list of items for all dialogs.
144 wxArrayString arrItems
;
146 // Create common strings array
147 // arrItems.Add( wxT("Solid") );
148 // arrItems.Add( wxT("Transparent") );
149 // arrItems.Add( wxT("Dot") );
150 // arrItems.Add( wxT("Long Dash") );
151 // arrItems.Add( wxT("Short Dash") );
152 // Comment the following since we don't need too long a drop list
153 arrItems
.Add( wxT("Dot Dash") );
154 arrItems
.Add( wxT("Backward Diagonal Hatch") );
155 arrItems
.Add( wxT("Cross-diagonal Hatch") );
156 // arrItems.Add( wxT("Forward Diagonal Hatch") );
157 // arrItems.Add( wxT("Cross Hatch") );
158 // arrItems.Add( wxT("Horizontal Hatch") );
159 // arrItems.Add( wxT("Vertical Hatch") );
161 // When defining derivative class for callbacks, we need
162 // to use two-stage creation (or redefine the common wx
164 odc
= new PenStyleComboBox();
165 odc
->Create(parent
,wxID_ANY
,wxEmptyString
,
166 wxDefaultPosition
, wxDefaultSize
,
168 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
172 odc
->SetSelection(0);
174 // Load images from disk
175 wxImage
imgNormal(wxT("bitmaps/dropbutn.png"));
176 wxImage
imgPressed(wxT("bitmaps/dropbutp.png"));
177 wxImage
imgHover(wxT("bitmaps/dropbuth.png"));
179 if ( imgNormal
.IsOk() && imgPressed
.IsOk() && imgHover
.IsOk() )
181 wxBitmap
bmpNormal(imgNormal
);
182 wxBitmap
bmpPressed(imgPressed
);
183 wxBitmap
bmpHover(imgHover
);
184 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
187 wxLogError(wxT("Dropbutton images not found"));