home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xdialog.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  5KB  |  205 lines

  1. #include "xmodlg.h"
  2. #include "xmodal.h"
  3. #include "xres.h"
  4. #include "xreslib.h"
  5. #include "xexcept.h"
  6.  
  7. extern LONG MAXX;
  8. extern LONG MAXY;
  9. extern SHORT cxDlgFrame;
  10. extern SHORT cyDlgFrame;
  11. extern SHORT cxBorder;
  12. extern SHORT cyBorder;
  13. extern SHORT cxSizeBorder;
  14. extern SHORT cySizeBorder;
  15.  
  16. void BuildChilds(HWND dlgHandle);
  17. MRESULT HandleDefault(XWindow * w, ULONG msg, MPARAM mp1, MPARAM mp2, BOOL & handled);
  18.  
  19.  
  20. void SetCentered( HWND winhandle)
  21. {
  22.       if (MAXX == 0)
  23.     {
  24.         MAXX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  25.         MAXY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  26.         cxDlgFrame = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME);
  27.         cyDlgFrame = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME);
  28.         cxBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
  29.         cyBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
  30.         cxSizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  31.         cySizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  32.     }
  33.     SWP swp;
  34.     WinQueryWindowPos(winhandle, &swp);
  35.     WinSetWindowPos( winhandle, HWND_TOP, MAXX / 2 - swp.cx / 2, MAXY / 2 - swp.cy / 2, swp.cx, swp.cy, SWP_MOVE);
  36. }
  37.  
  38.  
  39. MRESULT EXPENTRY ModelessDProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  40. {
  41.     XModelessDialog *w = (XModelessDialog *) WinQueryWindowPtr(hwnd, 0);
  42.  
  43.     if (w)
  44.     {
  45.         BOOL handeld = FALSE;
  46.         MRESULT mr = HandleDefault(w, msg, mp1, mp2, handeld);
  47.  
  48.         if (handeld)
  49.             return mr;
  50.     }
  51.     return WinDefDlgProc(hwnd, msg, mp1, mp2);
  52. }
  53.  
  54.  
  55. /*@
  56. @class XModelesDialog
  57. @parent XDialog
  58. @type overview
  59. @symbol _
  60. */
  61.  
  62.  
  63. /*@ XModelessDialog :: XModelessDialog( const XResource * id, const XWindow * owner)
  64. @group constructors/destructors
  65. @remarks Construct a modeless dialog.
  66. @parameters 
  67. <t '°' c=2>
  68. °XResource * id        °a resource which describes the dialog template<BR>
  69. °XWindow * owner        °a pointer to the owner-window (can be NULL)
  70. </t>
  71. */
  72. XModelessDialog :: XModelessDialog( const XResource * id, const XWindow * owner, BOOL center)
  73. {
  74.    HWND hwnd = HWND_DESKTOP;
  75.     if(owner)
  76.         hwnd = owner->GetHandle();
  77.     winhandle = WinLoadDlg( HWND_DESKTOP, hwnd, (PFNWP) ModelessDProc, id->GetResourceLibrary()->GetModuleHandle(), id->GetID(), NULL);
  78.     if (winhandle == 0)
  79.     {
  80.         OOLThrow("could not create dialog from resources!", 0);
  81.         return;
  82.     }
  83.     WinSetWindowPtr(winhandle, 0, this);
  84.  
  85.     if(center)
  86.         SetCentered( winhandle );
  87.  
  88.     BuildChilds(winhandle);
  89.     process = id->GetResourceLibrary()->GetProcess();
  90.     process->AddWindow(this);
  91. }
  92.  
  93.  
  94. MRESULT EXPENTRY ModalDProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  95. {
  96.     XModalDialog *w = (XModalDialog *) WinQueryWindowPtr(hwnd, 0);
  97.  
  98.     if (w)
  99.     {
  100.  
  101.         if(msg == WM_COMMAND )
  102.         {
  103.             if( w->QueryForClose( SHORT1FROMMP(mp1) ) == TRUE)
  104.             {
  105.               w->command = SHORT1FROMMP(mp1);
  106.                 WinDismissDlg( w->winhandle, SHORT1FROMMP(mp1) );
  107.                 delete w;
  108.                 return (MRESULT) TRUE;
  109.             }
  110.             else
  111.                 return (MRESULT) FALSE;
  112.         }
  113.         BOOL handeld = FALSE;
  114.         MRESULT mr = HandleDefault(w, msg, mp1, mp2, handeld);
  115.  
  116.         if (handeld)
  117.             return (MRESULT) FALSE;// mr;
  118.         
  119.     }
  120.     return WinDefDlgProc(hwnd, msg, mp1, mp2);
  121. }
  122.  
  123.  
  124. /*@
  125. @class XModalDialog
  126. @parent XDialog
  127. @type overview
  128. @symbol _
  129. */
  130.  
  131. /*@ XModalDialog :: XModalDialog( const XResource * id, const XWindow * owner)
  132. @group constructors/destructors
  133. @remarks Construct a modal dialog. You must call XModalDialog::Start() after 
  134. constructing an instance to make the dialog work. When constructing the dialog you can initialize
  135. the dialog controls.
  136. @parameters 
  137. <t '°' c=2>
  138. °XResource * id        °A resource which describes the dialog template<BR>
  139. °XWindow * owner        °A pointer to the owner-window. If now owner is given an error occures.<BR>
  140. °BOOL center            °Display the dialog centered.
  141. </t>
  142. */
  143. XModalDialog :: XModalDialog( const XResource * id, const XWindow * owner, BOOL center)
  144. {
  145.    HWND hwnd = HWND_DESKTOP;
  146.     if(owner)
  147.         hwnd = owner->GetHandle();
  148.     else
  149.         OOLThrow("XModalDialog need a parent window!", 0);
  150.  
  151.     winhandle = WinLoadDlg( HWND_DESKTOP, hwnd, (PFNWP) ModalDProc, id->GetResourceLibrary()->GetModuleHandle(), id->GetID(), NULL);
  152.     if (winhandle == 0)
  153.     {
  154.         OOLThrow("could not create dialog from resources!", 0);
  155.         return;
  156.     }
  157.     WinSetWindowPtr(winhandle, 0, this);
  158.  
  159.     if( center )
  160.         SetCentered(winhandle);
  161.  
  162.     BuildChilds(winhandle);
  163.     process = id->GetResourceLibrary()->GetProcess();
  164.     process->AddWindow(this);
  165. }
  166.  
  167.  
  168.  
  169. /*@ XModalDialog :: Start( void )
  170. @group misc
  171. @remarks To make a modal dialog work you must call Start().
  172. */
  173. void XModalDialog :: Start( void )
  174. {
  175.     WinProcessDlg( winhandle);
  176. }
  177.  
  178.  
  179. //Docs only
  180. /*@ 
  181. @class XDialog
  182. @type overview
  183. @symbol _
  184. @remarks XDialog is the base class for XModalDialog and XModelessDialog.
  185. You cannot construct an instance of XDialog directly, you have to chose
  186. one of the child-classes.
  187. */
  188.  
  189.  
  190. /*@ XDialog::GetCommand()
  191. @remarks If a command was received by the dialog, eg. from a button the value is
  192. stored and can be get by the application with this function.
  193. @returns SHORT command
  194. */
  195.  
  196.  
  197. /*@ XModalDialog::QueryForClose()
  198. @remarks If a command was received by the modal dialog, eg. from a button, you must
  199. decide if the modal dialog can be destroyed or not. Override this function, return TRUE if the dialog
  200. can be destroyed, otherwise return FALSE.
  201. @parameters SHORT command    the command received from a dialog-control
  202. @returns BOOL canDestroy
  203. */
  204.  
  205.