home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vmodald.cpp < prev    next >
C/C++ Source or Header  |  1999-01-26  |  5KB  |  124 lines

  1. //===============================================================
  2. // vdialog.cxx - vdialog class functions - X11R5
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>           // for OS/2 stuff
  12. #include <v/vmodald.h>          // our header
  13. #include <v/vapp.h>
  14. // Define static data of the class
  15. // ... none ...
  16. //=================>>> vModalDialog::vModalDialog <<<=====================
  17.   vModalDialog::vModalDialog(vBaseWindow* creator, VCONST char* title) :
  18.     vDialog(creator, 1, title)          // constructor
  19.   {
  20.     SysDebug(Constructor,"vModalDialog::vModalDialog(vBaseWindow) constructor\n")
  21.   }
  22. //=================>>> vModalDialog::vModalDialog <<<=====================
  23.   vModalDialog::vModalDialog(vApp* creator, VCONST char* title) :
  24.     vDialog(creator, 1, title)          // constructor
  25.   {
  26.     SysDebug(Constructor,"vModalDialog::vModalDialog(vApp) constructor\n")
  27.   }
  28. //===============>>> vModalDialog::~vModalDialog <<<=======================
  29.   vModalDialog::~vModalDialog()
  30.   {
  31.     SysDebug(Destructor,"vModalDialog::~vModalDialog() destructor\n")
  32.   }
  33. //==================>>> vModalDialog::CloseDialog <<<=======================
  34.   void vModalDialog::CloseDialog(void)
  35.   {
  36.     vDialog::CloseDialog();
  37.     _curModal = _oldModal;              // V:1.13
  38.     WinDismissDlg(_wDialog,1);
  39.  
  40.   }
  41. //=================>>> vModalDialog::DialogCommand <<<======================
  42.   void vModalDialog::DialogCommand(ItemVal id, ItemVal retval, CmdType ctype)
  43.   {
  44.     // After the user has selected a command from the dialog,
  45.     // this routine is called with the value
  46.     vDialog::DialogCommand(id, retval, ctype);
  47.     _mdItemVal = retval;                // for full modal return
  48.     _mdItemID = id;                     // must go after above call
  49.     _mdCmdType = ctype;
  50.   }
  51. //================>>> vModalDialog::ShowModalDialog <<<======================
  52.   ItemVal vModalDialog::ShowModalDialog(VCONST char* msg, ItemVal& retval)
  53.   {
  54.     // This is a fully modal version that will allow the user a simple
  55.     // wait for an answer without needing the DialogCommand method
  56.     // V:1.13 - Windows doesn't seem to handle nested modals very well...
  57.     // I don't know why. So I've added the logic with _oldModal and _curModal
  58.     // to handle nested modals correctly, I hope...
  59.     _oldModal = _curModal;              // V:1.13
  60.     _curModal = this;
  61.     ShowDialog(msg);                    // Display the dialog
  62.     retval = _mdItemVal;
  63.     return _mdItemID;                   // return the value
  64.   }
  65.  
  66. // JBH Feb98
  67. // Added DialogDisplayed to handle the centering of the dialog in the app.
  68. // for some reason this was left out of V1.17 (except for the OS/2 version :-)
  69. //==================>>> vNoticeDialog::DialogDisplayed <<<=====================
  70.   void vModalDialog::DialogDisplayed()
  71.   {
  72.     // we want to keep the dialog 'margin' units away from the screen edges
  73.     const int margin = 25;
  74.     // center the dialog in the app window, the usual nightmare of
  75.     // os/2 and V coord transforms applies as always!
  76.     const LONG DisplayHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  77.     const LONG DisplayWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  78.     SWP swpApp, swpDlg;
  79.  
  80.     HWND ClientHwnd = WinQueryWindow(_wDialog, QW_OWNER);
  81.     if (ClientHwnd)
  82.       WinQueryWindowPos(ClientHwnd, &swpApp);
  83.     else // it seems modal-modals don't have an owner, so put in the middle!
  84.     {
  85.       swpApp.x=0;
  86.       swpApp.y=0;
  87.       swpApp.cx=0;
  88.       swpApp.cy=0;
  89.     }
  90.     WinQueryWindowPos(_wDialog, &swpDlg);
  91.  
  92.     int left, top;            // new dialog posn upper-left corner
  93.     if ( swpApp.cx > swpDlg.cx )
  94.       left = swpApp.x + (swpApp.cx - swpDlg.cx)/2;
  95.     else
  96.       left = swpApp.x;
  97.  
  98.     if ( swpApp.cy > swpDlg.cy )
  99.       top = (DisplayHeight - swpApp.y - swpApp.cy) + (swpApp.cy - swpDlg.cy)/2;
  100.     else
  101.       top = DisplayHeight - swpApp.y - swpApp.cy;
  102.  
  103.     // special case of no visible parent window, so center on screen instead
  104.     if ( swpApp.cx ==0 && swpApp.cy==0)
  105.     {
  106.       top = (DisplayHeight - swpDlg.cy)/2;
  107.       left = (DisplayWidth - swpDlg.cx)/2;
  108.     }
  109.     // sanity checks!  Make sure dialog fits on the screen!
  110.     if ((top+swpDlg.cy+ margin) >  DisplayHeight)
  111.        top = DisplayHeight - swpDlg.cy - margin;
  112.     if ((left+swpDlg.cx+margin) >  DisplayWidth)
  113.        left = DisplayWidth - swpDlg.cx - margin;
  114.     // but don't overcorrect! If its bigger than the screen do the best you can
  115.     if (top < 0 )
  116.       top = 0;
  117.     if (left < 0 )
  118.       left = 0;
  119.     // for this function, the position coords are relative to the screen, not the app
  120.     // and origin is upper left corner of screen (V coords)
  121.     SetDialogPosition (left, top);
  122.   }
  123.  
  124.