home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / ODialog.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  174 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // ODialog.cpp
  5.  
  6. // member functions of ODialog
  7.  
  8. /*
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  15.  *    endorse or promote products derived from this software
  16.  *    without specific prior written permission.
  17.  * 3. See OCL.INF for a detailed copyright notice.
  18.  *
  19.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  */
  31.  
  32.  
  33. // $Header: W:/Projects/OCL/Source/rcs/ODialog.cpp 1.50 1996/08/11 23:49:13 B.STEIN Release $
  34.  
  35. #define __OCL_SOURCE__
  36.  
  37. #define OINCL_OSTRING
  38. #define OINCL_BASE
  39.  
  40. #include <ocl.hpp>
  41. #include <ODialog.hpp>
  42.  
  43.  
  44. ODialog::ODialog(const ULONG idDlg)
  45.   : OWindow(idDlg, 0, 0),
  46.     module(NULLHANDLE)
  47. {
  48.  parent = HWND_DESKTOP;
  49.  owner = HWND_DESKTOP;
  50. }
  51.  
  52.  
  53. ODialog::ODialog(const HWND Parent, const HWND Owner, const ULONG idDlg)
  54.   : OWindow(idDlg, 0, 0),
  55.     module(NULLHANDLE)
  56. {
  57.  parent = Parent;
  58.  owner = Owner;
  59. }
  60.  
  61.  
  62. ODialog::ODialog(const HWND Parent, const HWND Owner, const HMODULE resource, const ULONG idDlg)
  63.   : OWindow(idDlg, 0, 0),
  64.     module(resource)
  65. {
  66.  parent = Parent;
  67.  owner = Owner;
  68. }
  69.  
  70.  
  71. ODialog::~ODialog()
  72. {
  73.  destroyDlg();
  74. }
  75.  
  76.  
  77. PSZ ODialog::isOfType() const
  78.  return("ODialog"); 
  79. }
  80.  
  81.  
  82. ODialog& ODialog::createDlg()
  83. {
  84.  if (!WinLoadDlg(parent, owner, OWinDefDlgProc, module, res, this))
  85.    throw OPMException(OCL::error(160), 0);
  86.  return(*this);
  87. }
  88.  
  89.  
  90.  
  91. ODialog& ODialog::showDlg()
  92. {
  93.  WinSetWindowPos(hwnd, 0, 0, 0, 0, HWND_TOP, SWP_ACTIVATE | SWP_SHOW);
  94.  return(*this);
  95. }
  96.  
  97.  
  98. BOOL ODialog::showDlgModal()
  99. {
  100.  return((BOOL)WinDlgBox(parent, owner, OWinDefDlgProc, module, res, this));
  101. }
  102.  
  103.  
  104. ODialog& ODialog::dismissDlg(BOOL success)
  105. {
  106.  WinDismissDlg(hwnd, success);
  107.  return(*this);
  108. }
  109.  
  110. ODialog& ODialog::hideDlg()
  111. {
  112.  WinShowWindow(hwnd, FALSE);
  113.  return(*this);
  114. }
  115.  
  116.  
  117. ODialog& ODialog::destroyDlg()
  118. {
  119.  WinDestroyWindow(hwnd);
  120.  return(*this);
  121. }
  122.  
  123.  
  124. ODialog& ODialog::centerDlg(const ULONG parentWindow)
  125. {
  126.  SWP swpParent;
  127.  SWP swp;
  128.  
  129.  switch(parentWindow)
  130.    {
  131.     case CENTER_ONSCREEN:
  132.       swpParent.cx=WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  133.       swpParent.cy=WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  134.       WinQueryWindowPos(hwnd, &swp);
  135.       WinSetWindowPos(hwnd, HWND_TOP,
  136.                      (swpParent.cx-swp.cx)/2,
  137.                      (swpParent.cy-swp.cy)/2, 0, 0, SWP_MOVE);
  138.       break;
  139.  
  140.     case CENTER_ONPARENT: {
  141.       LONG ScreenWidth, ScreenHeight;
  142.       LONG PosX, PosY;
  143.  
  144.       /* Bildschirmabmessungen holen */
  145.       ScreenWidth  = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  146.       ScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  147.       /* Fensterabmessungen holen */
  148.       WinQueryWindowPos(parent, &swpParent);
  149.       WinQueryWindowPos(hwnd, &swp);
  150.  
  151.       PosX = (swpParent.cx - swp.cx) / 2;
  152.       PosY = (swpParent.cy - swp.cy) / 2;
  153.  
  154.       /* Korrektur, falls Teile des Fensters aus dem sichtbaren Bereich
  155.        * des Fensters herausfallen würden: */
  156.       if (PosX < 0)
  157.          PosX = 0;
  158.       else if (PosX + swp.cx > ScreenWidth)
  159.          PosX = ScreenWidth - swp.cx;
  160.  
  161.       if (PosY < 0)
  162.          PosY = 0;
  163.       else if (PosY + swp.cy > ScreenHeight)
  164.          PosY = ScreenHeight - swp.cy;
  165.  
  166.       WinSetWindowPos(hwnd, HWND_TOP, PosX, PosY, 0, 0, SWP_MOVE);
  167.       break; }
  168.    }
  169.  return(*this);
  170. }
  171.  
  172. // end of source
  173.