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"
25 #include "wx/control.h"
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
30 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
36 wxControl::wxControl()
38 m_backgroundColour
= *wxWHITE
;
39 m_foregroundColour
= *wxBLACK
;
41 #if WXWIN_COMPATIBILITY
43 #endif // WXWIN_COMPATIBILITY
46 wxControl::~wxControl()
48 m_isBeingDeleted
= TRUE
;
51 bool wxControl::OS2CreateControl(const wxChar
*classname
, WXDWORD style
)
53 m_hWnd
= (WXHWND
)::CreateWindowEx
55 GetExStyle(style
), // extended style
56 classname
, // the kind of control to create
57 NULL
, // the window name
58 style
, // the window style
59 0, 0, 0, 0, // the window position and size
60 GetHwndOf(GetParent()), // parent
61 (HMENU
)GetId(), // child id
62 wxGetInstance(), // app instance
63 NULL
// creation parameters
69 wxLogError(_T("Failed to create a control of class '%s'"), classname
);
75 // subclass again for purposes of dialog editing mode
78 // controls use the same font and colours as their parent dialog by default
84 wxSize
wxControl::DoGetBestSize()
86 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
89 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
91 #if WXWIN_COMPATIBILITY
94 (void)(*m_callback
)(this, event
);
99 #endif // WXWIN_COMPATIBILITY
101 return GetEventHandler()->ProcessEvent(event
);
104 bool wxControl::OS2OnNotify(int idCtrl
,
108 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
109 wxEventType eventType
= wxEVT_NULL
;
110 NMHDR
*hdr1
= (NMHDR
*) lParam
;
111 switch ( hdr1
->code
)
114 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
118 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
122 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
126 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
130 eventType
= wxEVT_COMMAND_SET_FOCUS
;
134 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
138 eventType
= wxEVT_COMMAND_ENTER
;
142 return wxWindow::OS2OnNotify(idCtrl
, lParam
, result
);
145 event
.SetEventType(eventType
);
146 event
.SetEventObject(this);
148 return GetEventHandler()->ProcessEvent(event
);
151 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
153 // In general, you don't want to erase the background of a control,
154 // or you'll get a flicker.
155 // TODO: move this 'null' function into each control that
161 * TODO: convert to PM Code
162 * ::GetClientRect((HWND) GetHWND(), &rect);
164 * HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
165 * GetBackgroundColour().Green(),
166 * GetBackgroundColour().Blue()));
167 * int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
169 * ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
170 * ::DeleteObject(hBrush);
171 * ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
175 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
) const
178 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
180 // Even with extended styles, need to combine with WS_BORDER
181 // for them to look right.
182 if ( want3D
|| wxStyleHasBorder(m_windowStyle
) )
188 // ---------------------------------------------------------------------------
190 // ---------------------------------------------------------------------------
192 // Call this repeatedly for several wnds to find the overall size
194 // Call it initially with -1 for all values in rect.
195 // Keep calling for other widgets, and rect will be modified
196 // to calculate largest bounding rectangle.
197 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
199 int left
= rect
->left
;
200 int right
= rect
->right
;
202 int bottom
= rect
->bottom
;
204 GetWindowRect((HWND
) wnd
, rect
);
209 if (left
< rect
->left
)
212 if (right
> rect
->right
)
218 if (bottom
> rect
->bottom
)
219 rect
->bottom
= bottom
;