]>
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)
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
8 // For compilers that support precompilation, includes "wx/wx.h".
15 // for all others, include the necessary headers
21 #error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
24 #include "customcombo.h"
27 BEGIN_EVENT_TABLE(ListViewComboPopup
, wxListView
)
28 EVT_MOTION(ListViewComboPopup::OnMouseMove
)
29 // NOTE: Left down event is used instead of left up right now
30 // since MSW wxListCtrl doesn't seem to emit left ups
32 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick
)
35 BEGIN_EVENT_TABLE(TreeCtrlComboPopup
, wxTreeCtrl
)
36 EVT_MOTION(TreeCtrlComboPopup::OnMouseMove
)
37 // NOTE: Left down event is used instead of left up right now
38 // since MSW wxTreeCtrl doesn't seem to emit left ups
40 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick
)
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 void PenStyleComboBox::OnDrawItem( wxDC
& dc
,
54 if ( item
== wxNOT_FOUND
)
61 int penStyle
= wxSOLID
;
63 // penStyle = wxTRANSPARENT;
64 // else if ( item == 2 )
66 // else if ( item == 3 )
67 // penStyle = wxLONG_DASH;
68 // else if ( item == 4 )
69 // penStyle = wxSHORT_DASH;
71 penStyle
= wxDOT_DASH
;
73 penStyle
= wxBDIAGONAL_HATCH
;
75 penStyle
= wxCROSSDIAG_HATCH
;
76 // else if ( item == 8 )
77 // penStyle = wxFDIAGONAL_HATCH;
78 // else if ( item == 9 )
79 // penStyle = wxCROSS_HATCH;
80 // else if ( item == 10 )
81 // penStyle = wxHORIZONTAL_HATCH;
82 // else if ( item == 11 )
83 // penStyle = wxVERTICAL_HATCH;
85 wxPen
pen( dc
.GetTextForeground(), 3, penStyle
);
87 // Get text colour as pen colour
90 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
92 dc
.DrawText(GetString( item
),
94 (r
.y
+ 0) + ( (r
.height
/2) - dc
.GetCharHeight() )/2
97 dc
.DrawLine( r
.x
+5, r
.y
+((r
.height
/4)*3), r
.x
+r
.width
- 5, r
.y
+((r
.height
/4)*3) );
101 dc
.DrawLine( r
.x
+5, r
.y
+r
.height
/2, r
.x
+r
.width
- 5, r
.y
+r
.height
/2 );
105 void PenStyleComboBox::OnDrawBackground( wxDC
& dc
, const wxRect
& rect
,
106 int item
, int flags
) const
108 // If item is selected or even, or we are painting the
109 // combo control itself, use the default rendering.
110 if ( (flags
& (wxODCB_PAINTING_CONTROL
|wxODCB_PAINTING_SELECTED
)) ||
113 wxOwnerDrawnComboBox::OnDrawBackground(dc
,rect
,item
,flags
);
117 // Otherwise, draw every other background with different colour.
118 wxColour
bgCol(240,240,250);
119 dc
.SetBrush(wxBrush(bgCol
));
120 dc
.SetPen(wxPen(bgCol
));
121 dc
.DrawRectangle(rect
);
124 inline wxCoord
PenStyleComboBox::OnMeasureItem( size_t item
) const
126 // Simply demonstrate the ability to have variable-height items
133 inline wxCoord
PenStyleComboBox::OnMeasureItemWidth( size_t WXUNUSED(item
) ) const
135 return -1; // default - will be measured from text width
138 PenStyleComboBox
* PenStyleComboBox::CreateSample(wxWindow
* parent
)
140 PenStyleComboBox
* odc
;
142 // Common list of items for all dialogs.
143 wxArrayString arrItems
;
145 // Create common strings array
146 // arrItems.Add( wxT("Solid") );
147 // arrItems.Add( wxT("Transparent") );
148 // arrItems.Add( wxT("Dot") );
149 // arrItems.Add( wxT("Long Dash") );
150 // arrItems.Add( wxT("Short Dash") );
151 // Comment the following since we don't need too long a drop list
152 arrItems
.Add( wxT("Dot Dash") );
153 arrItems
.Add( wxT("Backward Diagonal Hatch") );
154 arrItems
.Add( wxT("Cross-diagonal Hatch") );
155 // arrItems.Add( wxT("Forward Diagonal Hatch") );
156 // arrItems.Add( wxT("Cross Hatch") );
157 // arrItems.Add( wxT("Horizontal Hatch") );
158 // arrItems.Add( wxT("Vertical Hatch") );
160 // When defining derivative class for callbacks, we need
161 // to use two-stage creation (or redefine the common wx
163 odc
= new PenStyleComboBox();
164 odc
->Create(parent
,wxID_ANY
,wxEmptyString
,
165 wxDefaultPosition
, wxDefaultSize
,
167 wxCB_READONLY
//wxNO_BORDER | wxCB_READONLY
171 odc
->SetSelection(0);
173 // Load images from disk
174 wxImage
imgNormal(wxT("bitmaps/dropbutn.png"));
175 wxImage
imgPressed(wxT("bitmaps/dropbutp.png"));
176 wxImage
imgHover(wxT("bitmaps/dropbuth.png"));
178 if ( imgNormal
.IsOk() && imgPressed
.IsOk() && imgHover
.IsOk() )
180 wxBitmap
bmpNormal(imgNormal
);
181 wxBitmap
bmpPressed(imgPressed
);
182 wxBitmap
bmpHover(imgHover
);
183 odc
->SetButtonBitmaps(bmpNormal
,false,bmpPressed
,bmpHover
);
186 wxLogError(wxT("Dropbutton images not found"));