]> git.saurik.com Git - wxWidgets.git/blame - utils/screenshotgen/src/customcombo.cpp
No changes, just fix a typo in a comment in docview event handling code.
[wxWidgets.git] / utils / screenshotgen / src / customcombo.cpp
CommitLineData
0d5eda9c
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: customcombo.cpp
3// Purpose: Implement some custom wxComboCtrls
4// Author: Utensil Candel (UtensilCandel@@gmail.com)
526954c5 5// Licence: wxWindows licence
0d5eda9c
FM
6/////////////////////////////////////////////////////////////////////////////
7
8// For compilers that support precompilation, includes "wx/wx.h".
9#include "wx/wxprec.h"
10
11#ifdef __BORLANDC__
12 #pragma hdrstop
13#endif
14
15// for all others, include the necessary headers
16#ifndef WX_PRECOMP
17 #include "wx/wx.h"
18#endif
19
20#if !wxUSE_COMBOCTRL
21 #error "Please set wxUSE_COMBOCTRL to 1 and rebuild the library."
22#endif
23
24#include "customcombo.h"
25
26
27BEGIN_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
31 // consistently.
32 EVT_LEFT_DOWN(ListViewComboPopup::OnMouseClick)
33END_EVENT_TABLE()
34
35BEGIN_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
39 // consistently.
40 EVT_LEFT_DOWN(TreeCtrlComboPopup::OnMouseClick)
41END_EVENT_TABLE()
42
43
44
45// ----------------------------------------------------------------------------
4bae10bd 46// PenStyleComboBox
0d5eda9c
FM
47// ----------------------------------------------------------------------------
48
4bae10bd 49void PenStyleComboBox::OnDrawItem( wxDC& dc,
0d5eda9c
FM
50 const wxRect& rect,
51 int item,
52 int flags ) const
53{
54 if ( item == wxNOT_FOUND )
55 return;
56
57 wxRect r(rect);
58 r.Deflate(3);
59 r.height -= 2;
60
61 int penStyle = wxSOLID;
62// if ( item == 1 )
63// penStyle = wxTRANSPARENT;
64// else if ( item == 2 )
65// penStyle = wxDOT;
66// else if ( item == 3 )
67// penStyle = wxLONG_DASH;
68// else if ( item == 4 )
69// penStyle = wxSHORT_DASH;
70 if ( item == 0 )
71 penStyle = wxDOT_DASH;
72 else if ( item == 1 )
73 penStyle = wxBDIAGONAL_HATCH;
74 else if ( item == 2 )
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;
84
85 wxPen pen( dc.GetTextForeground(), 3, penStyle );
86
87 // Get text colour as pen colour
88 dc.SetPen( pen );
89
90 if ( !(flags & wxODCB_PAINTING_CONTROL) )
91 {
92 dc.DrawText(GetString( item ),
93 r.x + 3,
94 (r.y + 0) + ( (r.height/2) - dc.GetCharHeight() )/2
95 );
96
97 dc.DrawLine( r.x+5, r.y+((r.height/4)*3), r.x+r.width - 5, r.y+((r.height/4)*3) );
98 }
99 else
100 {
101 dc.DrawLine( r.x+5, r.y+r.height/2, r.x+r.width - 5, r.y+r.height/2 );
102 }
103}
104
4bae10bd 105void PenStyleComboBox::OnDrawBackground( wxDC& dc, const wxRect& rect,
0d5eda9c
FM
106 int item, int flags ) const
107{
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)) ||
111 (item & 1) == 0 )
112 {
113 wxOwnerDrawnComboBox::OnDrawBackground(dc,rect,item,flags);
114 return;
115 }
116
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);
122}
123
4bae10bd 124inline wxCoord PenStyleComboBox::OnMeasureItem( size_t item ) const
0d5eda9c
FM
125{
126 // Simply demonstrate the ability to have variable-height items
127 if ( item & 1 )
128 return 36;
129 else
130 return 24;
131}
132
4bae10bd 133inline wxCoord PenStyleComboBox::OnMeasureItemWidth( size_t WXUNUSED(item) ) const
0d5eda9c
FM
134{
135 return -1; // default - will be measured from text width
136}
137
4bae10bd 138PenStyleComboBox * PenStyleComboBox::CreateSample(wxWindow* parent)
0d5eda9c 139{
4bae10bd 140 PenStyleComboBox* odc;
0d5eda9c
FM
141
142 // Common list of items for all dialogs.
143 wxArrayString arrItems;
144
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") );
159
160 // When defining derivative class for callbacks, we need
161 // to use two-stage creation (or redefine the common wx
162 // constructor).
4bae10bd 163 odc = new PenStyleComboBox();
0d5eda9c
FM
164 odc->Create(parent,wxID_ANY,wxEmptyString,
165 wxDefaultPosition, wxDefaultSize,
166 arrItems,
167 wxCB_READONLY //wxNO_BORDER | wxCB_READONLY
168 );
169
170
171 odc->SetSelection(0);
172
173 // Load images from disk
4bae10bd
FM
174 wxImage imgNormal(wxT("bitmaps/dropbutn.png"));
175 wxImage imgPressed(wxT("bitmaps/dropbutp.png"));
176 wxImage imgHover(wxT("bitmaps/dropbuth.png"));
0d5eda9c
FM
177
178 if ( imgNormal.IsOk() && imgPressed.IsOk() && imgHover.IsOk() )
179 {
180 wxBitmap bmpNormal(imgNormal);
181 wxBitmap bmpPressed(imgPressed);
182 wxBitmap bmpHover(imgHover);
183 odc->SetButtonBitmaps(bmpNormal,false,bmpPressed,bmpHover);
184 }
185 else
186 wxLogError(wxT("Dropbutton images not found"));
187
188 return odc;
189}
190