home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 3.ddi / OWLINC.ZIP / APPLICAT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  5.2 KB  |  144 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2.  
  3. #ifndef __APPLICAT_H
  4. #define __APPLICAT_H
  5.  
  6. #ifndef __OWL_H
  7. #include <owl.h>
  8. #endif
  9.  
  10. #ifndef __MODULE_H
  11. #include <module.h>
  12. #endif
  13.  
  14. #pragma option -Vo-
  15. #if     defined(__BCOPT__) && !defined(_ALLOW_po)
  16. #pragma option -po-
  17. #endif
  18.  
  19. // Application Class
  20.  
  21. _CLASSDEF(TApplication)
  22.  
  23. class _EXPORT TApplication : public TModule {
  24. public:
  25.  
  26.     // WinMain arguments
  27.     HINSTANCE         hPrevInstance;
  28.     int            nCmdShow;
  29.  
  30.     PTWindowsObject MainWindow;
  31.     HACCEL HAccTable;
  32.     PTWindowsObject KBHandlerWnd;
  33.  
  34. #if defined(WIN31)
  35.     // windows 3.1 interface
  36.     TApplication(LPSTR AName, HINSTANCE AnInstance,
  37.               HINSTANCE APrevInstance, LPSTR ACmdLine, int ACmdShow);
  38. #endif
  39. #if defined(WIN30)
  40.     // windows 3.0 interface
  41.     TApplication(LPSTR AName, HINSTANCE_30 AnInstance,
  42.               HINSTANCE_30 APrevInstance, LPSTR ACmdLine, int ACmdShow);
  43. #endif
  44.  
  45.     ~TApplication();
  46.     virtual void Run();
  47.     virtual BOOL CanClose();
  48.     void SetKBHandler(PTWindowsObject AWindowsObject);
  49.  
  50.     // define pure virtual functions derived from Object class
  51.     virtual classType        isA() const
  52.          { return applicationClass; }
  53.     virtual Pchar nameOf() const
  54.          {return "TApplication";}
  55. protected:
  56.     virtual void InitApplication();  // "first"-instance initialization
  57.     virtual void InitInstance();     // each-instance initialization
  58.     virtual void InitMainWindow();   // init application main window
  59.  
  60.     virtual void MessageLoop();
  61.     /* IdleAction may be redefined in derived classes to do some action when
  62.        there are no messages pending. */
  63.     virtual void IdleAction() {}
  64.     virtual BOOL ProcessAppMsg(LPMSG PMessage);
  65.     virtual BOOL ProcessDlgMsg(LPMSG PMessage);
  66.     virtual BOOL ProcessAccels(LPMSG PMessage);
  67.     virtual BOOL ProcessMDIAccels(LPMSG PMessage);
  68.  
  69. private:
  70.  
  71.     void __TApplication(LPSTR AName, HINSTANCE AnInstance,
  72.                     HINSTANCE APrevInstance, LPSTR ACmdLine, int ACmdShow);
  73.  
  74. };    // end of Application class
  75.  
  76. /* Performs special handling for the message last retrieved.
  77.    Translates keyboard input messages into control selections or
  78.    command messages, when appropriate.  Dispatches message, if
  79.    translated. */
  80. inline BOOL TApplication::ProcessAppMsg(LPMSG PMessage)
  81.        { if ( KBHandlerWnd )
  82.            if ( KBHandlerWnd->IsFlagSet(WB_MDICHILD) )
  83.              return ProcessMDIAccels(PMessage) ||
  84.                     ProcessDlgMsg(PMessage) ||
  85.                     ProcessAccels(PMessage);
  86.            else
  87.             return ProcessDlgMsg(PMessage) ||
  88.                    ProcessMDIAccels(PMessage) ||
  89.                    ProcessAccels(PMessage);
  90.          else
  91.            return ProcessMDIAccels(PMessage) ||
  92.                   ProcessAccels(PMessage); }
  93.  
  94. /* Attempts to translate a message into a control selection if the
  95.    currently active OWL window has requested "keyboard handling".
  96.    (Some keyboard input messages are translated into control
  97.    selection messages). Dispatches message, if translated. */
  98. inline BOOL TApplication::ProcessDlgMsg(LPMSG PMessage)
  99.     { if (KBHandlerWnd && KBHandlerWnd->HWindow)
  100.            return IsDialogMessage(KBHandlerWnd->HWindow, PMessage);
  101.          else
  102.            return FALSE; }
  103.  
  104. /* Attempts to translate a message into a command message if the
  105.    TApplication has loaded an accelerator table. (Keyboard input
  106.    messages for which an entry exists in the accelerator table are
  107.    translated into command messages.)  Dispatches message, if
  108.    translated.  (Translation of MDI accelerator messages is performed
  109.    in ProcessMDIAccels function.) */
  110. inline BOOL TApplication::ProcessAccels(LPMSG PMessage)
  111.        { return HAccTable &&
  112.          TranslateAccelerator(
  113.                  MainWindow->HWindow, HAccTable, PMessage); }
  114.  
  115. /* Attempts to translate a message into a system command message
  116.    for MDI TApplications (whose main window is a TMDIFrame). (Some
  117.    keyboard input messages are translated into system commands for
  118.    MDI applications). Dispatches message, if translated. */
  119. inline BOOL TApplication::ProcessMDIAccels(LPMSG PMessage)
  120.        { return (PTWindowsObject)(MainWindow->GetClient()) &&
  121.            TranslateMDISysAccel(
  122.             ((PTWindowsObject)(MainWindow->GetClient()))->HWindow, PMessage); }
  123.  
  124. /* Activates and deactivates "keyboard handling" (translation of
  125.    keyboard input into control selections) for the currently active
  126.    TWindowsObject by setting the KBHandlerWnd to the parameter passed.
  127.    This function is called internally by the OWL whenever a OWL window
  128.    is activated.  If "keyboard handling" has been requested for the
  129.    TWindowsObject, the parameter passed is non-NULL, else NULL is
  130.    passed.  "Keyboard handling" is requested, by default, for all
  131.    modeless dialogs and may be requested for a TWindow via a call to
  132.    its EnableKBHandler function. */
  133. inline void TApplication::SetKBHandler(PTWindowsObject AWindowsObject)
  134.        { KBHandlerWnd = AWindowsObject; }
  135.  
  136. extern PTApplication _EXPFUNC GetApplicationObject();
  137.  
  138. #pragma option -Vo.
  139. #if     defined(__BCOPT__) && !defined(_ALLOW_po)
  140. #pragma option -po.
  141. #endif
  142.  
  143. #endif // ifndef _APPLICAT_H
  144.