]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
wxBitmap::LoadFile and SaveFile now uses wxImage's methods in case there is no wxBitm...
[wxWidgets.git] / src / os2 / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: David Webster
5 // Modified by:
6 // Created: 09/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/event.h"
21 #include "wx/app.h"
22 #include "wx/dcclient.h"
23 #endif
24 #include "wx/os2/private.h"
25 #include "wx/control.h"
26
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30 BEGIN_EVENT_TABLE(wxControl, wxWindow)
31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
32 END_EVENT_TABLE()
33 #endif
34
35 // Item members
36 wxControl::wxControl()
37 {
38 m_backgroundColour = *wxWHITE;
39 m_foregroundColour = *wxBLACK;
40
41 #if WXWIN_COMPATIBILITY
42 m_callback = 0;
43 #endif // WXWIN_COMPATIBILITY
44 }
45
46 wxControl::~wxControl()
47 {
48 m_isBeingDeleted = TRUE;
49 }
50
51 bool wxControl::OS2CreateControl(const wxChar *classname, WXDWORD style)
52 {
53 m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(GetParent())
54 ,classname
55 ,NULL
56 ,style
57 ,0,0,0,0
58 ,NULLHANDLE
59 ,HWND_TOP
60 ,(HMENU)GetId()
61 ,NULL
62 ,NULL
63 );
64
65
66 if ( !m_hWnd )
67 {
68 #ifdef __WXDEBUG__
69 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
70 #endif // DEBUG
71
72 return FALSE;
73 }
74
75 // subclass again for purposes of dialog editing mode
76 SubclassWin(m_hWnd);
77
78 // controls use the same font and colours as their parent dialog by default
79 InheritAttributes();
80
81 return TRUE;
82 }
83
84 wxSize wxControl::DoGetBestSize()
85 {
86 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
87 }
88
89 bool wxControl::ProcessCommand(wxCommandEvent& event)
90 {
91 #if WXWIN_COMPATIBILITY
92 if ( m_callback )
93 {
94 (void)(*m_callback)(this, event);
95
96 return TRUE;
97 }
98 else
99 #endif // WXWIN_COMPATIBILITY
100
101 return GetEventHandler()->ProcessEvent(event);
102 }
103
104 bool wxControl::OS2OnNotify(int idCtrl,
105 WXLPARAM lParam,
106 WXLPARAM* result)
107 {
108 wxCommandEvent event(wxEVT_NULL, m_windowId);
109 wxEventType eventType = wxEVT_NULL;
110 /* TODO:
111 NMHDR *hdr1 = (NMHDR*) lParam;
112 switch ( hdr1->code )
113 {
114 case NM_CLICK:
115 eventType = wxEVT_COMMAND_LEFT_CLICK;
116 break;
117
118 case NM_DBLCLK:
119 eventType = wxEVT_COMMAND_LEFT_DCLICK;
120 break;
121
122 case NM_RCLICK:
123 eventType = wxEVT_COMMAND_RIGHT_CLICK;
124 break;
125
126 case NM_RDBLCLK:
127 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
128 break;
129
130 case NM_SETFOCUS:
131 eventType = wxEVT_COMMAND_SET_FOCUS;
132 break;
133
134 case NM_KILLFOCUS:
135 eventType = wxEVT_COMMAND_KILL_FOCUS;
136 break;
137
138 case NM_RETURN:
139 eventType = wxEVT_COMMAND_ENTER;
140 break;
141
142 default:
143 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
144 }
145 */
146 event.SetEventType(eventType);
147 event.SetEventObject(this);
148
149 return GetEventHandler()->ProcessEvent(event);
150 }
151
152 void wxControl::OnEraseBackground(wxEraseEvent& event)
153 {
154 // In general, you don't want to erase the background of a control,
155 // or you'll get a flicker.
156 // TODO: move this 'null' function into each control that
157 // might flicker.
158
159 RECT rect;
160 /*
161 * below is msw code.
162 * TODO: convert to PM Code
163 * ::GetClientRect((HWND) GetHWND(), &rect);
164 *
165 * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
166 * GetBackgroundColour().Green(),
167 * GetBackgroundColour().Blue()));
168 * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
169 *
170 * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
171 * ::DeleteObject(hBrush);
172 * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
173 */
174 }
175
176 WXDWORD wxControl::GetExStyle(WXDWORD& style) const
177 {
178 bool want3D;
179 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
180
181 // Even with extended styles, need to combine with FS_BORDER
182 // for them to look right. Check it out later, base window style does
183 // not designate BORDERS. Down in Frame and And controls.
184
185 if ( want3D || wxStyleHasBorder(m_windowStyle) )
186 style |= FS_BORDER;
187
188 return exStyle;
189 }
190
191 // ---------------------------------------------------------------------------
192 // global functions
193 // ---------------------------------------------------------------------------
194
195 // Call this repeatedly for several wnds to find the overall size
196 // of the widget.
197 // Call it initially with -1 for all values in rect.
198 // Keep calling for other widgets, and rect will be modified
199 // to calculate largest bounding rectangle.
200 void wxFindMaxSize(WXHWND wnd, RECT *rect)
201 {
202 int left = rect->xLeft;
203 int right = rect->xRight;
204 int top = rect->yTop;
205 int bottom = rect->yBottom;
206
207 ::WinQueryWindowRect((HWND) wnd, rect);
208
209 if (left < 0)
210 return;
211
212 if (left < rect->xLeft)
213 rect->xLeft = left;
214
215 if (right > rect->xRight)
216 rect->xRight = right;
217
218 if (top < rect->yTop)
219 rect->yTop = top;
220
221 if (bottom > rect->yBottom)
222 rect->yBottom = bottom;
223 }
224