1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxControl class
4 // Author: Julian Smart
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"
26 #include "wx/dcclient.h"
29 #include "wx/control.h"
31 #include "wx/msw/private.h"
33 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_ABSTRACT_CLASS(wxControl
, wxWindow
)
40 BEGIN_EVENT_TABLE(wxControl
, wxWindow
)
41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground
)
46 wxControl::wxControl()
48 m_backgroundColour
= *wxWHITE
;
49 m_foregroundColour
= *wxBLACK
;
51 #if WXWIN_COMPATIBILITY
53 #endif // WXWIN_COMPATIBILITY
56 wxControl::~wxControl()
58 m_isBeingDeleted
= TRUE
;
61 bool wxControl::MSWCreateControl(const wxChar
*classname
, WXDWORD style
)
63 // VZ: if someone could put a comment here explaining what exactly this is
64 // needed for, it would be nice...
67 // all controls have these childs (wxWindows creates all controls visible
69 style
|= WS_CHILD
| WS_VISIBLE
;
71 m_hWnd
= (WXHWND
)::CreateWindowEx
73 GetExStyle(style
, &want3D
), // extended style
74 classname
, // the kind of control to create
75 NULL
, // the window name
76 style
, // the window style
77 0, 0, 0, 0, // the window position and size
78 GetHwndOf(GetParent()), // parent
79 (HMENU
)GetId(), // child id
80 wxGetInstance(), // app instance
81 NULL
// creation parameters
87 wxLogError(wxT("Failed to create a control of class '%s'"), classname
);
96 Ctl3dSubclassCtl(GetHwnd());
101 // subclass again for purposes of dialog editing mode
104 // controls use the same font and colours as their parent dialog by default
110 wxSize
wxControl::DoGetBestSize()
112 return wxSize(DEFAULT_ITEM_WIDTH
, DEFAULT_ITEM_HEIGHT
);
115 bool wxControl::ProcessCommand(wxCommandEvent
& event
)
117 #if WXWIN_COMPATIBILITY
120 (void)(*m_callback
)(this, event
);
125 #endif // WXWIN_COMPATIBILITY
127 return GetEventHandler()->ProcessEvent(event
);
131 bool wxControl::MSWOnNotify(int idCtrl
,
135 wxCommandEvent
event(wxEVT_NULL
, m_windowId
);
136 wxEventType eventType
= wxEVT_NULL
;
137 NMHDR
*hdr1
= (NMHDR
*) lParam
;
138 switch ( hdr1
->code
)
141 eventType
= wxEVT_COMMAND_LEFT_CLICK
;
145 eventType
= wxEVT_COMMAND_LEFT_DCLICK
;
149 eventType
= wxEVT_COMMAND_RIGHT_CLICK
;
153 eventType
= wxEVT_COMMAND_RIGHT_DCLICK
;
157 eventType
= wxEVT_COMMAND_SET_FOCUS
;
161 eventType
= wxEVT_COMMAND_KILL_FOCUS
;
165 eventType
= wxEVT_COMMAND_ENTER
;
169 return wxWindow::MSWOnNotify(idCtrl
, lParam
, result
);
172 event
.SetEventType(eventType
);
173 event
.SetEventObject(this);
175 return GetEventHandler()->ProcessEvent(event
);
179 void wxControl::OnEraseBackground(wxEraseEvent
& event
)
181 // In general, you don't want to erase the background of a control,
182 // or you'll get a flicker.
183 // TODO: move this 'null' function into each control that
187 ::GetClientRect(GetHwnd(), &rect
);
189 HBRUSH hBrush
= ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
191 HDC hdc
= GetHdcOf((*event
.GetDC()));
192 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
194 ::FillRect(hdc
, &rect
, hBrush
);
195 ::DeleteObject(hBrush
);
196 ::SetMapMode(hdc
, mode
);
199 WXDWORD
wxControl::GetExStyle(WXDWORD
& style
, bool *want3D
) const
201 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, want3D
);
203 // Even with extended styles, need to combine with WS_BORDER for them to
205 if ( *want3D
|| wxStyleHasBorder(m_windowStyle
) )
211 // ---------------------------------------------------------------------------
213 // ---------------------------------------------------------------------------
215 // Call this repeatedly for several wnds to find the overall size
217 // Call it initially with -1 for all values in rect.
218 // Keep calling for other widgets, and rect will be modified
219 // to calculate largest bounding rectangle.
220 void wxFindMaxSize(WXHWND wnd
, RECT
*rect
)
222 int left
= rect
->left
;
223 int right
= rect
->right
;
225 int bottom
= rect
->bottom
;
227 GetWindowRect((HWND
) wnd
, rect
);
232 if (left
< rect
->left
)
235 if (right
> rect
->right
)
241 if (bottom
> rect
->bottom
)
242 rect
->bottom
= bottom
;