]> git.saurik.com Git - wxWidgets.git/blob - src/msw/control.cpp
wxGetFullHostName() implemented - it doesn't work though (and won't even
[wxWidgets.git] / src / msw / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: control.cpp
3 // Purpose: wxControl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
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 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/event.h"
25 #include "wx/app.h"
26 #include "wx/dcclient.h"
27 #endif
28
29 #include "wx/control.h"
30
31 #include "wx/msw/private.h"
32
33 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
34 #include <commctrl.h>
35 #endif
36
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
39
40 BEGIN_EVENT_TABLE(wxControl, wxWindow)
41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
42 END_EVENT_TABLE()
43 #endif
44
45 // Item members
46 wxControl::wxControl()
47 {
48 m_backgroundColour = *wxWHITE;
49 m_foregroundColour = *wxBLACK;
50
51 #if WXWIN_COMPATIBILITY
52 m_callback = 0;
53 #endif // WXWIN_COMPATIBILITY
54 }
55
56 wxControl::~wxControl()
57 {
58 m_isBeingDeleted = TRUE;
59
60 // If we delete an item, we should initialize the parent panel,
61 // because it could now be invalid.
62 wxWindow *parent = (wxWindow *)GetParent();
63 if (parent)
64 {
65 if (parent->GetDefaultItem() == (wxButton*) this)
66 parent->SetDefaultItem(NULL);
67 }
68 }
69
70 bool wxControl::ProcessCommand(wxCommandEvent& event)
71 {
72 #if WXWIN_COMPATIBILITY
73 if ( m_callback )
74 {
75 (void)(*m_callback)(this, event);
76
77 return TRUE;
78 }
79 else
80 #endif // WXWIN_COMPATIBILITY
81
82 return GetEventHandler()->ProcessEvent(event);
83 }
84
85 #ifdef __WIN95__
86 bool wxControl::MSWOnNotify(int idCtrl,
87 WXLPARAM lParam,
88 WXLPARAM* result)
89 {
90 wxCommandEvent event(wxEVT_NULL, m_windowId);
91 wxEventType eventType = wxEVT_NULL;
92 NMHDR *hdr1 = (NMHDR*) lParam;
93 switch ( hdr1->code )
94 {
95 case NM_CLICK:
96 eventType = wxEVT_COMMAND_LEFT_CLICK;
97 break;
98
99 case NM_DBLCLK:
100 eventType = wxEVT_COMMAND_LEFT_DCLICK;
101 break;
102
103 case NM_RCLICK:
104 eventType = wxEVT_COMMAND_RIGHT_CLICK;
105 break;
106
107 case NM_RDBLCLK:
108 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
109 break;
110
111 case NM_SETFOCUS:
112 eventType = wxEVT_COMMAND_SET_FOCUS;
113 break;
114
115 case NM_KILLFOCUS:
116 eventType = wxEVT_COMMAND_KILL_FOCUS;
117 break;
118
119 case NM_RETURN:
120 eventType = wxEVT_COMMAND_ENTER;
121 break;
122
123 default:
124 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
125 }
126
127 event.SetEventType(eventType);
128 event.SetEventObject(this);
129
130 return GetEventHandler()->ProcessEvent(event);
131 }
132 #endif // Win95
133
134 void wxControl::OnEraseBackground(wxEraseEvent& event)
135 {
136 // In general, you don't want to erase the background of a control,
137 // or you'll get a flicker.
138 // TODO: move this 'null' function into each control that
139 // might flicker.
140
141 RECT rect;
142 ::GetClientRect((HWND) GetHWND(), &rect);
143
144 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(),
145 GetBackgroundColour().Green(),
146 GetBackgroundColour().Blue()));
147 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
148
149 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
150 ::DeleteObject(hBrush);
151 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
152 }
153
154 // ---------------------------------------------------------------------------
155 // global functions
156 // ---------------------------------------------------------------------------
157
158 // Call this repeatedly for several wnds to find the overall size
159 // of the widget.
160 // Call it initially with -1 for all values in rect.
161 // Keep calling for other widgets, and rect will be modified
162 // to calculate largest bounding rectangle.
163 void wxFindMaxSize(WXHWND wnd, RECT *rect)
164 {
165 int left = rect->left;
166 int right = rect->right;
167 int top = rect->top;
168 int bottom = rect->bottom;
169
170 GetWindowRect((HWND) wnd, rect);
171
172 if (left < 0)
173 return;
174
175 if (left < rect->left)
176 rect->left = left;
177
178 if (right > rect->right)
179 rect->right = right;
180
181 if (top < rect->top)
182 rect->top = top;
183
184 if (bottom > rect->bottom)
185 rect->bottom = bottom;
186 }
187