convert line ends
[canaan.git] / prj / tech / libsrc / appcore / wappcore.cpp
blob1874abb2079dab430c8fa0127d38ce8798cab3d8
1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/appcore/RCS/wappcore.cpp $
3 // $Author: TOML $
4 // $Date: 1997/10/16 13:18:53 $
5 // $Revision: 1.27 $
6 //
8 #ifdef _WIN32
10 #include <windows.h>
11 #include <lg.h>
12 #include <aggmemb.h>
13 #include <wappcore.h>
14 #include <appagg.h>
16 #ifndef NO_DB_MEM
17 // Must be last header
18 #include <memall.h>
19 #include <dbmem.h>
20 #endif
22 #if defined(__WATCOMC__)
23 #pragma off (unreferenced)
24 #endif
26 ///////////////////////////////////////////////////////////////////////////////
28 EXTERN tResult LGAPI _GenericApplicationCreate(REFIID,
29 IApplication ** ppApplication,
30 IUnknown * pOuterUnknown,
31 int argc, const char *argv[],
32 const char * pszName,
33 const char * pszDefaultPath)
35 USE_EXTENDED_START_UP();
36 // Create the application. Instance adds self to pOuterUnknown
37 return (new cWindowsApplication(argc, argv, pszName, pOuterUnknown) != 0);
40 ///////////////////////////////////////////////////////////////////////////////
42 // CLASS: cWindowsApplication
46 // Pre-fab COM implementations
48 IMPLEMENT_SIMPLE_AGGREGATE_CONTROL_DELETE_CLIENT(cWindowsApplication);
50 ///////////////////////////////////////
52 // Create an instance...
55 cWindowsApplication::cWindowsApplication(int argc, const char *argv[],
56 const char * pszName,
57 IUnknown * pOuterUnknown)
58 : m_argc(argc), m_argv(argv),
59 m_NameStr(pszName),
60 m_WinAppOperations(this, pOuterUnknown),
61 m_ApplicationOperations(this, pOuterUnknown)
63 // Add internal components to outer aggregate...
64 ADD_TO_AGGREGATE_2( pOuterUnknown,
65 IID_IWinApp, &m_WinAppOperations,
66 IID_IApplication, &m_ApplicationOperations,
67 kPriorityReserved,
68 NULL );
71 ///////////////////////////////////////////////////////////////////////////////
73 // CLASS: cWindowsApplication::cWinAppOperations
77 // Pre-fab COM implementations
80 IMPLEMENT_DELEGATION(cWindowsApplication::cWinAppOperations);
81 IMPLEMENT_CONNECTION_POINT(cWindowsApplication::cWinAppOperations, IWinAppAdviseSink);
83 ///////////////////////////////////////
85 // Get the main window
88 STDMETHODIMP_(HWND) cWindowsApplication::cWinAppOperations::GetMainWnd()
90 return m_hMainWnd;
93 ///////////////////////////////////////
95 // Set the main window
98 STDMETHODIMP_(HWND) cWindowsApplication::cWinAppOperations::SetMainWnd(HWND hNewMainWnd)
100 HWND hOldMainWnd = m_hMainWnd;
101 m_hMainWnd = hNewMainWnd;
102 return hOldMainWnd;
105 ///////////////////////////////////////
107 // Get the current instance handle
110 STDMETHODIMP_(HINSTANCE) cWindowsApplication::cWinAppOperations::GetInstance()
112 return GetModuleHandle(NULL);
115 ///////////////////////////////////////
117 // Get the handle for Windows resources
120 STDMETHODIMP_(HINSTANCE) cWindowsApplication::cWinAppOperations::GetResourceInstance()
122 return GetModuleHandle(NULL);
125 ///////////////////////////////////////
127 // Get the command line
130 STDMETHODIMP_(const char *) cWindowsApplication::cWinAppOperations::GetCommandLine()
132 CriticalMsg("Unimplemented call");
133 return 0;
136 ///////////////////////////////////////
138 // Get the intially requested "show state"
141 STDMETHODIMP_(int) cWindowsApplication::cWinAppOperations::GetCommandShow()
143 CriticalMsg("Unimplemented call");
144 return 0;
147 ///////////////////////////////////////
149 // Set the application registry key
152 STDMETHODIMP_(void) cWindowsApplication::cWinAppOperations::SetRegistryKey(const char *)
154 CriticalMsg("Unimplemented call");
157 ///////////////////////////////////////
159 // Get the application registry key
162 STDMETHODIMP_(const char *) cWindowsApplication::cWinAppOperations::GetRegistryKey()
164 CriticalMsg("Unimplemented call");
165 return 0;
168 ///////////////////////////////////////
170 // Set the application .ini file name
173 STDMETHODIMP_(void) cWindowsApplication::cWinAppOperations::SetProfileName(const char *)
175 CriticalMsg("Unimplemented call");
178 ///////////////////////////////////////
180 // Get the application .ini file name
183 STDMETHODIMP_(const char *) cWindowsApplication::cWinAppOperations::GetProfileName()
185 CriticalMsg("Unimplemented call");
186 return 0;
189 ///////////////////////////////////////
191 // Set the default background color of application's dialogs
194 STDMETHODIMP_(void) cWindowsApplication::cWinAppOperations::SetDialogBkColor(COLORREF clrCtlBk, COLORREF clrCtlText)
196 CriticalMsg("Unimplemented call");
199 ///////////////////////////////////////
201 // Message pumping
204 eWinPumpResult cWindowsApplication::cWinAppOperations::DispatchOneMessage(MSG * pMsg, unsigned nFilterMin, unsigned nFilterMax)
206 const int fGetResult = GetMessage(pMsg, NULL, nFilterMin, nFilterMax);
208 AssertMsg(fGetResult >= 0, "Error calling GetMessage()");
209 DebugMsgTrue(retVal == 0, "Recevied WM_QUIT");
211 if (fGetResult && !PreTranslateMessage(pMsg))
213 TranslateMessage(pMsg);
214 DispatchMessage(pMsg);
216 return (fGetResult > 0) ? kPumpedOk : kPumpedQuit;
219 STDMETHODIMP_(eWinPumpResult) cWindowsApplication::cWinAppOperations::PumpEvents(int fPumpKind, eWinPumpDuration fDuration)
221 // If we're not in the midst of exiting...
222 if (!(m_fFlags & kReceivedQuit))
224 MSG msg;
225 unsigned nFilterMin;
226 unsigned nFilterMax;
228 // If want to pump until quit, must choose kPumpAll...
229 AssertMsg(fDuration != kPumpUntilQuit || fPumpKind == kPumpAll, "PumpEvents() parameters too dangerous");
231 // First pick filtering based on kind of pump desired...
232 switch (fPumpKind)
234 case kPumpAll:
235 nFilterMin = 0;
236 nFilterMax = 0;
237 break;
239 case kPumpKeyboard:
240 nFilterMin = WM_KEYFIRST;
241 nFilterMax = WM_KEYLAST;
242 break;
244 case kPumpMouse:
245 nFilterMin = WM_MOUSEFIRST;
246 nFilterMax = WM_MOUSELAST;
247 break;
249 case kPumpPaint:
250 nFilterMin = WM_PAINT;
251 nFilterMax = WM_PAINT;
252 break;
254 default:
255 CriticalMsg2("Don't know how to handle requested pump kind in PumpEvents(%x, %d)", fPumpKind, fDuration);
258 // Now start pumping according to desired duration...
259 eWinPumpResult retVal;
261 switch (fDuration)
263 case kPumpOne:
264 if (PeekMessage(&msg, NULL, nFilterMin, nFilterMax, PM_NOREMOVE))
265 retVal = DispatchOneMessage(&msg, nFilterMin, nFilterMax);
266 else
267 retVal = kPumpedNothing;
269 break;
271 case kPumpUntilEmpty:
272 retVal = kPumpedNothing;
273 while (PeekMessage(&msg, NULL, nFilterMin, nFilterMax, PM_NOREMOVE))
274 retVal = DispatchOneMessage(&msg, nFilterMin, nFilterMax);
276 break;
278 case kPumpUntilQuit:
279 while (DispatchOneMessage(&msg, nFilterMin, nFilterMax) == kPumpedOk)
281 retVal = kPumpedQuit;
283 default:
284 CriticalMsg2("Don't know how to handle requested pump duration in PumpEvents(%x, %d)", fPumpKind, fDuration);
287 // If we received quit, set flag to shut down all subsequent PumpMessage() calls
288 if (retVal == kPumpedQuit)
289 m_fFlags |= kReceivedQuit;
290 return retVal;
292 return kPumpedPastQuit;
295 ///////////////////////////////////////
297 // Give clients a chance to handle our message
300 int cWindowsApplication::cWinAppOperations::PreTranslateMessage(MSG * pMsg)
302 CONNECTION_POINT_ITERATE()
304 if (pSink->PreTranslateMessage(pMsg))
305 return TRUE;
307 return FALSE;
310 ///////////////////////////////////////
312 // Show a modal dialog box
315 STDMETHODIMP cWindowsApplication::cWinAppOperations::ModalDialogBox(LPCTSTR lpTemplate, DLGPROC lpDialogFunc)
317 CriticalMsg("Unimplemented call");
318 return 0;
321 ///////////////////////////////////////////////////////////////////////////////
323 // CLASS: cWindowsApplication::cApplicationOperations
327 // Pre-fab COM implementations
329 IMPLEMENT_DELEGATION(cWindowsApplication::cApplicationOperations);
330 IMPLEMENT_CONNECTION_POINT(cWindowsApplication::cApplicationOperations, IAppAdviseSink);
332 ///////////////////////////////////////
334 STDMETHODIMP cWindowsApplication::cApplicationOperations::QueryQuit()
336 CONNECTION_POINT_ITERATE()
338 if (pSink->OnQueryQuit() != S_OK)
340 return S_FALSE;
344 Quit();
346 return S_OK; // This will never execute
349 ///////////////////////////////////////
351 STDMETHODIMP_(void) cWindowsApplication::cApplicationOperations::Quit()
353 CONNECTION_POINT_ITERATE()
355 pSink->OnQuit();
357 exit(0); // This may never execute
360 ///////////////////////////////////////
362 STDMETHODIMP_(void) cWindowsApplication::cApplicationOperations::Abort(const char * pszReason)
364 CriticalMsg("Unimplemented call");
367 ///////////////////////////////////////
369 STDMETHODIMP_(void) cWindowsApplication::cApplicationOperations::SetCaption(const char *)
371 CriticalMsg("Unimplemented call");
374 ///////////////////////////////////////
376 STDMETHODIMP_(const char *) cWindowsApplication::cApplicationOperations::GetCaption()
378 return m_pWindowsApplication->m_NameStr;
381 ///////////////////////////////////////
383 STDMETHODIMP_(void) cWindowsApplication::cApplicationOperations::SetDefaultFilePath(const char *)
385 CriticalMsg("Unimplemented call");
388 ///////////////////////////////////////
390 STDMETHODIMP_(const char *) cWindowsApplication::cApplicationOperations::GetDefaultFilePath()
392 CriticalMsg("Unimplemented call");
393 return 0;
396 ///////////////////////////////////////
398 STDMETHODIMP_(const char *) cWindowsApplication::cApplicationOperations::GetFullName()
400 CriticalMsg("Unimplemented call");
401 return 0;
404 ///////////////////////////////////////
406 STDMETHODIMP_(const char *) cWindowsApplication::cApplicationOperations::GetPath()
408 CriticalMsg("Unimplemented call");
409 return 0;
412 ///////////////////////////////////////
414 STDMETHODIMP_(int) cWindowsApplication::cApplicationOperations::MessageBox(const char * pszMessage, const char * pszCaption, int fFlags)
416 CriticalMsg("Unimplemented call");
417 return 0;
420 ///////////////////////////////////////
422 STDMETHODIMP_(int) cWindowsApplication::cApplicationOperations::CriticalMessageBox(const char * pszMessage, const char * pszCaption, int errorCode)
424 CriticalMsg("Unimplemented call");
425 return 0;
428 ///////////////////////////////////////
430 STDMETHODIMP_(void) cWindowsApplication::cApplicationOperations::AppCommand(unsigned nCmdId)
432 CONNECTION_POINT_ITERATE()
434 if (pSink->GetVersion() >= kVerAppAdvise_CommandSupport)
436 pSink->OnCommand(nCmdId);
441 ///////////////////////////////////////////////////////////////////////////////
443 #endif /* _WIN32 */