]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/screenshotgen/src/customcombo.cpp
Include <fcntl.h> from a header using fcntl().
[wxWidgets.git] / utils / screenshotgen / src / customcombo.cpp
... / ...
CommitLineData
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 licence
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// ----------------------------------------------------------------------------
47// PenStyleComboBox
48// ----------------------------------------------------------------------------
49
50void PenStyleComboBox::OnDrawItem( wxDC& dc,
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
106void PenStyleComboBox::OnDrawBackground( wxDC& dc, const wxRect& rect,
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
125inline wxCoord PenStyleComboBox::OnMeasureItem( size_t item ) const
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
134inline wxCoord PenStyleComboBox::OnMeasureItemWidth( size_t WXUNUSED(item) ) const
135{
136 return -1; // default - will be measured from text width
137}
138
139PenStyleComboBox * PenStyleComboBox::CreateSample(wxWindow* parent)
140{
141 PenStyleComboBox* odc;
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).
164 odc = new PenStyleComboBox();
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
175 wxImage imgNormal(wxT("bitmaps/dropbutn.png"));
176 wxImage imgPressed(wxT("bitmaps/dropbutp.png"));
177 wxImage imgHover(wxT("bitmaps/dropbuth.png"));
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