]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl class
4 // Author: David Webster
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "control.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
22 #include "wx/dcclient.h"
24 #include "wx/os2/private.h"
25 #include "wx/control.h"
27 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
29 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
30 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
34 wxControl::wxControl()
36 m_backgroundColour
= *wxWHITE
;
37 m_foregroundColour
= *wxBLACK
;
39 #if WXWIN_COMPATIBILITY
41 #endif // WXWIN_COMPATIBILITY
44 bool wxControl::Create(wxWindow
*parent
, wxWindowID id
,
46 const wxSize
& size
, long style
,
48 const wxValidator
& validator
,
52 bool rval
= wxWindow::Create(parent
, id
, pos
, size
, style
, name
);
55 SetValidator(validator
);
61 wxControl::~wxControl()
63 m_isBeingDeleted
= TRUE
;
66 bool wxControl::OS2CreateControl(const wxChar
*classname
,
70 const wxString
& label
,
73 // VZ: if someone could put a comment here explaining what exactly this is
74 // needed for, it would be nice...
77 // if no extended style given, determine it ourselves
78 if ( exstyle
== (WXDWORD
)-1 )
80 exstyle
= GetExStyle(style
);
85 // all controls have these childs (wxWindows creates all controls visible
87 style |= WS_CHILD | WS_VISIBLE;
89 m_hWnd = (WXHWND)::CreateWindowEx
91 exstyle, // extended style
92 classname, // the kind of control to create
93 label, // the window name
94 style, // the window style
95 pos.x, pos.y, // the window position
96 size.x, size.y, // and size
97 GetHwndOf(GetParent()), // parent
98 (HMENU)GetId(), // child id
99 wxGetInstance(), // app instance
100 NULL // creation parameters
106 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
115 Ctl3dSubclassCtl(GetHwnd());
118 #endif // wxUSE_CTL3D
120 // subclass again for purposes of dialog editing mode
123 // controls use the same font and colours as their parent dialog by default
129 wxSize
wxControl::DoGetBestSize() const
131 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
134 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
136 #if WXWIN_COMPATIBILITY
139 (void)(*m_callback
)(this, event
);
144 #endif // WXWIN_COMPATIBILITY
146 return GetEventHandler()->ProcessEvent(event
);
149 bool wxControl::OS2OnNotify(int idCtrl
,
153 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
154 wxEventType eventType
= wxEVT_NULL
;
156 NMHDR *hdr1 = (NMHDR*) lParam;
157 switch ( hdr1->code )
160 eventType = wxEVT_COMMAND_LEFT_CLICK;
164 eventType = wxEVT_COMMAND_LEFT_DCLICK;
168 eventType = wxEVT_COMMAND_RIGHT_CLICK;
172 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
176 eventType = wxEVT_COMMAND_SET_FOCUS;
180 eventType = wxEVT_COMMAND_KILL_FOCUS;
184 eventType = wxEVT_COMMAND_ENTER;
188 return wxWindow::OS2OnNotify(idCtrl, lParam, result);
191 event
.SetEventType(eventType
);
192 event
.SetEventObject(this);
194 return GetEventHandler()->ProcessEvent(event
);
197 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
199 // In general, you don't want to erase the background of a control,
200 // or you'll get a flicker.
201 // TODO: move this 'null' function into each control that
207 * TODO: convert to PM Code
208 * ::GetClientRect((HWND) GetHWND(), &rect);
210 * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
211 * GetBackgroundColour().Green(),
212 * GetBackgroundColour().Blue()));
213 * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
215 * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
216 * ::DeleteObject(hBrush);
217 * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
221 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
) const
224 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
226 // Even with extended styles, need to combine with FS_BORDER
227 // for them to look right. Check it out later, base window style does
228 // not designate BORDERS. Down in Frame and And controls.
230 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
236 // ---------------------------------------------------------------------------
238 // ---------------------------------------------------------------------------
240 // Call this repeatedly for several wnds to find the overall size
242 // Call it initially with -1 for all values in rect.
243 // Keep calling for other widgets, and rect will be modified
244 // to calculate largest bounding rectangle.
245 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
247 int left
= rect
->xLeft
;
248 int right
= rect
->xRight
;
249 int top
= rect
->yTop
;
250 int bottom
= rect
->yBottom
;
252 ::WinQueryWindowRect((HWND
) wnd
, rect
);
257 if (left
< rect
->xLeft
)
260 if (right
> rect
->xRight
)
261 rect
->xRight
= right
;
263 if (top
< rect
->yTop
)
266 if (bottom
> rect
->yBottom
)
267 rect
->yBottom
= bottom
;