]> git.saurik.com Git - wxWidgets.git/blame - src/os2/app.cpp
TransferFrom/ToWindow() were reverted, fixed
[wxWidgets.git] / src / os2 / app.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
d88de032 4// Author: David Webster
0e320a79 5// Modified by:
d88de032 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
d88de032
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
272ebf16
SN
12#ifdef __GNUG__
13 #pragma implementation "app.h"
14#endif
15
d88de032
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/frame.h"
21 #include "wx/app.h"
22 #include "wx/utils.h"
23 #include "wx/gdicmn.h"
24 #include "wx/pen.h"
25 #include "wx/brush.h"
26 #include "wx/cursor.h"
27 #include "wx/icon.h"
28 #include "wx/palette.h"
29 #include "wx/dc.h"
30 #include "wx/dialog.h"
31 #include "wx/msgdlg.h"
32 #include "wx/intl.h"
33 #include "wx/dynarray.h"
cb21bd1b
SN
34 #include "wx/wxchar.h"
35 #include "wx/icon.h"
0e320a79
DW
36#endif
37
0e320a79
DW
38#include "wx/log.h"
39#include "wx/module.h"
d88de032
DW
40
41#include "wx/os2/private.h"
42
29d83fc1
DW
43#ifdef __EMX__
44
19193a2c
KB
45#include <sys/ioctl.h>
46#include <sys/select.h>
29d83fc1
DW
47
48#else
49
65b851bb 50#include <nerrno.h>
19193a2c
KB
51#include <sys/ioctl.h>
52#include <sys/select.h>
53#include <sys/time.h>
29d83fc1 54
19193a2c 55#endif //
29d83fc1 56
3958ae62 57#ifndef __EMX__
29d83fc1 58
3958ae62 59#define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
19193a2c
KB
60extern "C" int _System bsdselect(int,
61 struct fd_set *,
62 struct fd_set *,
63 struct fd_set *,
64 struct timeval *);
3958ae62
SN
65#endif
66
d88de032
DW
67#if wxUSE_THREADS
68 #include "wx/thread.h"
d88de032 69#endif // wxUSE_THREADS
0e320a79 70
8df85a61
DW
71#if wxUSE_TOOLTIPS
72 #include "wx/tooltip.h"
73#endif // wxUSE_TOOLTIPS
74
0e320a79 75#include <string.h>
d88de032
DW
76#include <ctype.h>
77
78// ---------------------------------------------------------------------------
79// global variables
80// ---------------------------------------------------------------------------
81
9ed0fac8 82extern wxChar* wxBuffer;
9ed0fac8
DW
83extern wxList* wxWinHandleList;
84extern wxList WXDLLEXPORT wxPendingDelete;
9ed0fac8 85extern wxCursor* g_globalCursor;
0e320a79 86
8df85a61 87HAB vHabmain = NULLHANDLE;
d88de032 88
d88de032 89
9ed0fac8
DW
90HICON wxSTD_FRAME_ICON = (HICON) NULL;
91HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
d88de032
DW
92HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
93
9ed0fac8
DW
94HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
95HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
96HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
d88de032
DW
97
98HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
99
51c1d535
DW
100MRESULT EXPENTRY wxWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2);
101MRESULT EXPENTRY wxFrameWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2);
102
d88de032
DW
103// ===========================================================================
104// implementation
105// ===========================================================================
106
3958ae62
SN
107// ---------------------------------------------------------------------------
108// helper struct and functions for socket handling
109// ---------------------------------------------------------------------------
110
111struct GsocketCallbackInfo{
112 void (*proc)(void *);
113 int type;
114 int handle;
115 void* gsock;
116};
117
118// These defines and wrapper functions are used here and in gsockpm.c
119#define wxSockReadMask 0x01
120#define wxSockWriteMask 0x02
121
29d83fc1 122#ifdef __EMX__
3958ae62
SN
123extern "C"
124int wxAppAddSocketHandler(int handle, int mask,
29d83fc1 125 void (*callback)(void*), void * gsock)
3958ae62
SN
126{
127 return wxTheApp->AddSocketHandler(handle, mask, callback, gsock);
128}
3958ae62
SN
129extern "C"
130void wxAppRemoveSocketHandler(int handle)
131{
132 wxTheApp->RemoveSocketHandler(handle);
133}
29d83fc1
DW
134#else
135// Linkage mode problems using callbacks with extern C in a .cpp module
136int wxAppAddSocketHandler(int handle, int mask,
137 void (*callback)(void*), void * gsock)
138{
139 return wxTheApp->AddSocketHandler(handle, mask, callback, gsock);
140}
141void wxAppRemoveSocketHandler(int handle)
142{
143 wxTheApp->RemoveSocketHandler(handle);
144}
145#endif
3958ae62
SN
146
147void wxApp::HandleSockets()
148{
29d83fc1 149 bool pendingEvent = FALSE;
3958ae62
SN
150
151 // Check whether it's time for Gsocket operation
152 if (m_maxSocketHandles > 0 && m_maxSocketNr > 0)
153 {
154 fd_set readfds = m_readfds;
155 fd_set writefds = m_writefds;
156 struct timeval timeout;
157 int i;
158 struct GsocketCallbackInfo
159 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
3958ae62
SN
160 timeout.tv_sec = 0;
161 timeout.tv_usec = 0;
162 if ( select(m_maxSocketNr, &readfds, &writefds, 0, &timeout) > 0)
163 {
5c9ee6dd
SN
164 for (i = m_lastUsedHandle + 1; i != m_lastUsedHandle;
165 (i < m_maxSocketNr - 1) ? i++ : (i = 0))
3958ae62 166 {
3958ae62
SN
167 if (FD_ISSET(i, &readfds))
168 {
169 int r;
170 for (r = 0; r < m_maxSocketHandles; r++){
171 if(CallbackInfo[r].handle == i &&
172 CallbackInfo[r].type == wxSockReadMask)
173 break;
174 }
175 if (r < m_maxSocketHandles)
176 {
177 CallbackInfo[r].proc(CallbackInfo[r].gsock);
29d83fc1 178 pendingEvent = TRUE;
3958ae62
SN
179 }
180 }
181 if (FD_ISSET(i, &writefds))
182 {
183 int r;
184 for (r = 0; r < m_maxSocketHandles; r++)
185 if(CallbackInfo[r].handle == i &&
186 CallbackInfo[r].type == wxSockWriteMask)
187 break;
188 if (r < m_maxSocketHandles)
189 {
190 CallbackInfo[r].proc(CallbackInfo[r].gsock);
29d83fc1 191 pendingEvent = TRUE;
3958ae62
SN
192 }
193 }
194 }
195 m_lastUsedHandle = i;
196 }
197 if (pendingEvent)
5c9ee6dd 198 ProcessPendingEvents();
3958ae62
SN
199 }
200}
d88de032
DW
201// ---------------------------------------------------------------------------
202// wxApp
203// ---------------------------------------------------------------------------
204
d88de032 205 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
0e320a79 206
d88de032
DW
207 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
208 EVT_IDLE(wxApp::OnIdle)
209 EVT_END_SESSION(wxApp::OnEndSession)
210 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
211 END_EVENT_TABLE()
0e320a79 212
8df85a61
DW
213//
214// Initialize
215//
05e2b077 216bool wxApp::Initialize(int& argc, wxChar **argv)
0e320a79 217{
94826170
VZ
218 if ( !wxAppBase::Initialize(argc, argv) )
219 return false;
220
7e99520b
DW
221#if defined(wxUSE_CONSOLEDEBUG)
222 #if wxUSE_CONSOLEDEBUG
223/***********************************************/
224/* Code for using stdout debug */
225/* To use it you mast link app as "Window" - EK*/
226/***********************************************/
227 {
228 PPIB pib;
229 PTIB tib;
230
231 printf("In console\n");
232
233 DosGetInfoBlocks(&tib, &pib);
234/* Try morphing into a PM application. */
235// if(pib->pib_ultype == 2) /* VIO */
236 pib->pib_ultype = 3;
237 }
238/**********************************************/
239/**********************************************/
240 #endif //wxUSE_CONSOLEDEBUG
241#endif
242
54ffa107
DW
243 //
244 // OS2 has to have an anchorblock
245 //
94826170
VZ
246 vHabmain = WinInitialize(0);
247
248 if (!vHabmain)
249 {
250 // TODO: at least give some error message here...
251 wxAppBase::CleanUp();
54ffa107 252
54ffa107 253 return FALSE;
94826170
VZ
254 }
255
256 wxBuffer = new wxChar[1500]; // FIXME; why?
54ffa107
DW
257
258 // Some people may wish to use this, but
259 // probably it shouldn't be here by default.
260#ifdef __WXDEBUG__
261 // wxRedirectIOToConsole();
262#endif
263
d88de032
DW
264 wxWinHandleList = new wxList(wxKEY_INTEGER);
265
266 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
267 // PLEASE DO NOT ALTER THIS.
1b3d5e55 268#if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
d88de032
DW
269 extern char wxDummyChar;
270 if (wxDummyChar) wxDummyChar++;
271#endif
272
61243a51 273 // wxSetKeyboardHook(TRUE);
d88de032 274
459073a9 275 RegisterWindowClasses(vHabmain);
94826170 276
d88de032 277 return TRUE;
8df85a61 278} // end of wxApp::Initialize
d88de032 279
7e99520b 280const char* CANTREGISTERCLASS = " Can't register Class ";
d88de032
DW
281// ---------------------------------------------------------------------------
282// RegisterWindowClasses
283// ---------------------------------------------------------------------------
284
9ed0fac8
DW
285bool wxApp::RegisterWindowClasses(
286 HAB vHab
287)
d88de032 288{
914589c2
DW
289 ERRORID vError = 0L;
290 wxString sError;
3b9e3455 291
f23208ca
DW
292 if (!::WinRegisterClass( vHab
293 ,wxFrameClassName
51c1d535 294 ,wxFrameWndProc
f9efbe3a 295 ,CS_SIZEREDRAW | CS_SYNCPAINT
a0606634 296 ,sizeof(ULONG)
f23208ca 297 ))
d88de032 298 {
914589c2
DW
299 vError = ::WinGetLastError(vHab);
300 sError = wxPMErrorToStr(vError);
301 wxLogLastError(sError);
d88de032
DW
302 return FALSE;
303 }
304
f23208ca
DW
305 if (!::WinRegisterClass( vHab
306 ,wxFrameClassNameNoRedraw
51c1d535 307 ,wxWndProc
f23208ca 308 ,0
51c1d535 309 ,sizeof(ULONG)
f23208ca 310 ))
d88de032 311 {
914589c2
DW
312 vError = ::WinGetLastError(vHab);
313 sError = wxPMErrorToStr(vError);
314 wxLogLastError(sError);
d88de032
DW
315 return FALSE;
316 }
317
f23208ca
DW
318 if (!::WinRegisterClass( vHab
319 ,wxMDIFrameClassName
51c1d535 320 ,wxWndProc
f6bcfd97 321 ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT
51c1d535 322 ,sizeof(ULONG)
f23208ca 323 ))
d88de032 324 {
914589c2
DW
325 vError = ::WinGetLastError(vHab);
326 sError = wxPMErrorToStr(vError);
327 wxLogLastError(sError);
d88de032
DW
328 return FALSE;
329 }
0e320a79 330
f23208ca
DW
331 if (!::WinRegisterClass( vHab
332 ,wxMDIFrameClassNameNoRedraw
51c1d535 333 ,wxWndProc
f23208ca 334 ,0
51c1d535 335 ,sizeof(ULONG)
f23208ca 336 ))
d88de032 337 {
914589c2
DW
338 vError = ::WinGetLastError(vHab);
339 sError = wxPMErrorToStr(vError);
340 wxLogLastError(sError);
d88de032
DW
341 return FALSE;
342 }
343
f23208ca
DW
344 if (!::WinRegisterClass( vHab
345 ,wxMDIChildFrameClassName
51c1d535 346 ,wxWndProc
f23208ca 347 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST
51c1d535 348 ,sizeof(ULONG)
f23208ca 349 ))
d88de032 350 {
914589c2
DW
351 vError = ::WinGetLastError(vHab);
352 sError = wxPMErrorToStr(vError);
353 wxLogLastError(sError);
d88de032
DW
354 return FALSE;
355 }
356
f23208ca
DW
357 if (!::WinRegisterClass( vHab
358 ,wxMDIChildFrameClassNameNoRedraw
51c1d535 359 ,wxWndProc
f23208ca 360 ,CS_HITTEST
51c1d535 361 ,sizeof(ULONG)
f23208ca 362 ))
d88de032 363 {
914589c2
DW
364 vError = ::WinGetLastError(vHab);
365 sError = wxPMErrorToStr(vError);
366 wxLogLastError(sError);
d88de032
DW
367 return FALSE;
368 }
369
f23208ca
DW
370 if (!::WinRegisterClass( vHab
371 ,wxPanelClassName
51c1d535 372 ,wxWndProc
f23208ca 373 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT
51c1d535 374 ,sizeof(ULONG)
f23208ca 375 ))
d88de032 376 {
914589c2
DW
377 vError = ::WinGetLastError(vHab);
378 sError = wxPMErrorToStr(vError);
379 wxLogLastError(sError);
d88de032
DW
380 return FALSE;
381 }
382
f23208ca
DW
383 if (!::WinRegisterClass( vHab
384 ,wxCanvasClassName
51c1d535 385 ,wxWndProc
54ffa107 386 ,CS_SIZEREDRAW | CS_HITTEST | CS_SYNCPAINT
51c1d535 387 ,sizeof(ULONG)
f23208ca 388 ))
d88de032 389 {
914589c2
DW
390 vError = ::WinGetLastError(vHab);
391 sError = wxPMErrorToStr(vError);
392 wxLogLastError(sError);
d88de032
DW
393 return FALSE;
394 }
0256cfeb
DW
395 if (!::WinRegisterClass( vHab
396 ,wxCanvasClassNameNR
397 ,wxWndProc
398 ,CS_HITTEST | CS_SYNCPAINT
399 ,sizeof(ULONG)
400 ))
401 {
402 vError = ::WinGetLastError(vHab);
403 sError = wxPMErrorToStr(vError);
404 wxLogLastError(sError);
405 return FALSE;
406 }
d88de032 407 return TRUE;
8df85a61 408} // end of wxApp::RegisterWindowClasses
d88de032 409
8df85a61
DW
410//
411// Cleans up any wxWindows internal structures left lying around
412//
0e320a79
DW
413void wxApp::CleanUp()
414{
d88de032
DW
415 delete[] wxBuffer;
416 wxBuffer = NULL;
0e320a79 417
8df85a61
DW
418 //
419 // PM-SPECIFIC CLEANUP
420 //
0e320a79 421
61243a51 422 // wxSetKeyboardHook(FALSE);
9ed0fac8 423
d88de032 424 if (wxSTD_FRAME_ICON)
9ed0fac8 425 ::WinFreeFileIcon(wxSTD_FRAME_ICON);
d88de032 426 if (wxSTD_MDICHILDFRAME_ICON)
9ed0fac8 427 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON);
d88de032 428 if (wxSTD_MDIPARENTFRAME_ICON)
9ed0fac8 429 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON);
d88de032
DW
430
431 if (wxDEFAULT_FRAME_ICON)
9ed0fac8 432 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON);
d88de032 433 if (wxDEFAULT_MDICHILDFRAME_ICON)
9ed0fac8 434 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON);
d88de032 435 if (wxDEFAULT_MDIPARENTFRAME_ICON)
9ed0fac8
DW
436 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
437
d88de032
DW
438 if ( wxDisableButtonBrush )
439 {
440// TODO: ::DeleteObject( wxDisableButtonBrush );
441 }
442
443 if (wxWinHandleList)
444 delete wxWinHandleList;
445
468e327a
SN
446 // Delete Message queue
447 if (wxTheApp->m_hMq)
448 ::WinDestroyMsgQueue(wxTheApp->m_hMq);
449
94826170 450 wxAppBase::CleanUp();
8df85a61 451} // end of wxApp::CleanUp
0e320a79 452
9ed0fac8 453bool wxApp::OnInitGui()
d88de032 454{
914589c2
DW
455 ERRORID vError;
456 wxString sError;
77cd51c3 457
19193a2c
KB
458 if (!wxAppBase::OnInitGui())
459 return FALSE;
460
f23208ca 461 m_hMq = ::WinCreateMsgQueue(vHabmain, 0);
914589c2
DW
462 if (!m_hMq)
463 {
464 vError = ::WinGetLastError(vHabmain);
465 sError = wxPMErrorToStr(vError);
466 wxLogDebug(sError);
467 return FALSE;
468 }
19193a2c 469
9ed0fac8 470 return TRUE;
8df85a61 471} // end of wxApp::OnInitGui
0e320a79 472
0e320a79
DW
473wxApp::wxApp()
474{
d88de032
DW
475 argc = 0;
476 argv = NULL;
9ed0fac8 477 m_nPrintMode = wxPRINT_WINDOWS;
468e327a 478 m_hMq = 0;
3958ae62
SN
479 m_maxSocketHandles = 0;
480 m_maxSocketNr = 0;
481 m_sockCallbackInfo = 0;
8df85a61 482} // end of wxApp::wxApp
d88de032
DW
483
484wxApp::~wxApp()
485{
8df85a61 486 //
d88de032 487 // Delete command-line args
8df85a61 488 //
039bec17 489#if wxUSE_UNICODE
8df85a61
DW
490 int i;
491
d88de032
DW
492 for (i = 0; i < argc; i++)
493 {
494 delete[] argv[i];
495 }
496 delete[] argv;
039bec17 497#endif
8df85a61 498} // end of wxApp::~wxApp
0e320a79
DW
499
500bool wxApp::Initialized()
501{
d88de032
DW
502 if (GetTopWindow())
503 return TRUE;
504 else
505 return FALSE;
8df85a61 506} // end of wxApp::Initialized
0e320a79 507
2b5f62a0
VZ
508bool gbInOnIdle = FALSE;
509
9ed0fac8
DW
510void wxApp::OnIdle(
511 wxIdleEvent& rEvent
512)
d88de032 513{
d88de032 514
9ed0fac8 515 //
d88de032 516 // Avoid recursion (via ProcessEvent default case)
9ed0fac8 517 //
2b5f62a0 518 if (gbInOnIdle)
d88de032 519 return;
0e320a79 520
2b5f62a0 521 gbInOnIdle = TRUE;
955a9197 522
459073a9 523 wxAppBase::OnIdle(rEvent);
0e320a79 524
893758d5
DW
525#if wxUSE_DC_CACHEING
526 // automated DC cache management: clear the cached DCs and bitmap
527 // if it's likely that the app has finished with them, that is, we
528 // get an idle event and we're not dragging anything.
19193a2c
KB
529 if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) &&
530 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) &&
531 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
893758d5
DW
532 wxDC::ClearCache();
533#endif // wxUSE_DC_CACHEING
534
2b5f62a0 535 gbInOnIdle = FALSE;
8df85a61 536} // end of wxApp::OnIdle
9779893b 537
9ed0fac8
DW
538void wxApp::OnEndSession(
539 wxCloseEvent& WXUNUSED(rEvent))
0e320a79 540{
d88de032
DW
541 if (GetTopWindow())
542 GetTopWindow()->Close(TRUE);
8df85a61 543} // end of wxApp::OnEndSession
0e320a79 544
9ed0fac8 545//
d88de032
DW
546// Default behaviour: close the application with prompts. The
547// user can veto the close, and therefore the end session.
9ed0fac8
DW
548//
549void wxApp::OnQueryEndSession(
550 wxCloseEvent& rEvent
551)
0e320a79 552{
d88de032
DW
553 if (GetTopWindow())
554 {
9ed0fac8
DW
555 if (!GetTopWindow()->Close(!rEvent.CanVeto()))
556 rEvent.Veto(TRUE);
d88de032 557 }
8df85a61 558} // end of wxApp::OnQueryEndSession
0e320a79 559
8df85a61 560//
d88de032 561// Yield to incoming messages
8df85a61 562//
8461e4c2 563bool wxApp::Yield(bool onlyIfNeeded)
0e320a79 564{
8461e4c2
VZ
565 static bool s_inYield = FALSE;
566
567 if ( s_inYield )
568 {
569 if ( !onlyIfNeeded )
570 {
571 wxFAIL_MSG( _T("wxYield() called recursively") );
572 }
573
574 return FALSE;
575 }
576
9dea36ef 577 HAB vHab = 0;
dde11e60 578 QMSG vMsg;
ee453a16 579
8df85a61
DW
580 //
581 // Disable log flushing from here because a call to wxYield() shouldn't
582 // normally result in message boxes popping up &c
583 //
584 wxLog::Suspend();
585
8461e4c2 586 s_inYield = TRUE;
8b63ae37 587
8df85a61 588 //
d88de032
DW
589 // We want to go back to the main message loop
590 // if we see a WM_QUIT. (?)
8df85a61 591 //
dde11e60 592 while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT)
d88de032 593 {
8df85a61
DW
594#if wxUSE_THREADS
595 wxMutexGuiLeaveOrEnter();
596#endif // wxUSE_THREADS
598dc9b7 597 if (!wxTheApp->Dispatch())
d88de032
DW
598 break;
599 }
8df85a61 600 //
d88de032 601 // If they are pending events, we must process them.
8df85a61
DW
602 //
603 if (wxTheApp)
604 wxTheApp->ProcessPendingEvents();
605
5c9ee6dd 606 HandleSockets();
8df85a61
DW
607 //
608 // Let the logs be flashed again
609 //
610 wxLog::Resume();
8461e4c2 611 s_inYield = FALSE;
d88de032 612 return TRUE;
8df85a61 613} // end of wxYield
d88de032 614
3958ae62
SN
615int wxApp::AddSocketHandler(int handle, int mask,
616 void (*callback)(void*), void * gsock)
617{
618 int find;
619 struct GsocketCallbackInfo
620 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
621
622 for (find = 0; find < m_maxSocketHandles; find++)
623 if (CallbackInfo[find].handle == -1)
624 break;
625 if (find == m_maxSocketHandles)
626 {
627 // Allocate new memory
628 m_sockCallbackInfo = realloc(m_sockCallbackInfo,
629 (m_maxSocketHandles+=10)*
630 sizeof(struct GsocketCallbackInfo));
631 CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
632 for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++)
633 CallbackInfo[find].handle = -1;
634 find = m_maxSocketHandles - 10;
635 }
636 CallbackInfo[find].proc = callback;
637 CallbackInfo[find].type = mask;
638 CallbackInfo[find].handle = handle;
639 CallbackInfo[find].gsock = gsock;
640 if (mask & wxSockReadMask)
641 FD_SET(handle, &m_readfds);
642 if (mask & wxSockWriteMask)
643 FD_SET(handle, &m_writefds);
644 if (handle >= m_maxSocketNr)
645 m_maxSocketNr = handle + 1;
646 return find;
647}
648
649void wxApp::RemoveSocketHandler(int handle)
650{
651 struct GsocketCallbackInfo
652 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
653 if (handle < m_maxSocketHandles)
654 {
655 if (CallbackInfo[handle].type & wxSockReadMask)
656 FD_CLR(CallbackInfo[handle].handle, &m_readfds);
657 if (CallbackInfo[handle].type & wxSockWriteMask)
658 FD_CLR(CallbackInfo[handle].handle, &m_writefds);
659 CallbackInfo[handle].handle = -1;
660 }
661}
662
8df85a61
DW
663//-----------------------------------------------------------------------------
664// wxWakeUpIdle
665//-----------------------------------------------------------------------------
666
e2478fde 667void wxApp::WakeUpIdle()
8df85a61
DW
668{
669 //
670 // Send the top window a dummy message so idle handler processing will
671 // start up again. Doing it this way ensures that the idle handler
672 // wakes up in the right thread (see also wxWakeUpMainThread() which does
673 // the same for the main app thread only)
674 //
675 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
676
677 if (pTopWindow)
678 {
679 if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0))
680 {
681 //
682 // Should never happen
683 //
684 wxLogLastError("PostMessage(WM_NULL)");
685 }
686 }
687} // end of wxWakeUpIdle
d88de032 688
76990f63 689HAB wxGetInstance()
d88de032 690{
76990f63 691 return vHabmain;
d88de032
DW
692}
693
76990f63
DW
694void wxSetInstance(
695 HAB vHab
696)
d88de032 697{
76990f63 698 vHabmain = vHab;
0e320a79
DW
699}
700