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