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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OWindow.cpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OWindow.cpp 1.50 1996/08/11 23:49:36 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OWindow.hpp>
  40.  
  41.  
  42. OWindow::OWindow(const ULONG id, const ULONG winstyle, const ULONG winbits)
  43.    : termFlag(FALSE),
  44.      parent(HWND_DESKTOP),
  45.      owner(HWND_DESKTOP),
  46.      res(id),
  47.      style(winstyle),
  48.      bits(winbits),
  49.      hps(0)
  50. {
  51.  memset(&sizepos, 0, sizeof(SWP));
  52. }
  53.  
  54.  
  55.  
  56.  
  57. OWindow& OWindow::inherit(const HWND hwndDlg)
  58. {
  59.  if ((hwnd = WinWindowFromID(hwndDlg, res)) == NULLHANDLE)
  60.    throw OPMException(OCL::error(138), 0);
  61.  
  62.  parent = hwndDlg;
  63.  owner = hwndDlg;
  64.  
  65.  return(*this);
  66. }
  67.  
  68.  
  69. OWindow::~OWindow() 
  70.  destroy(); 
  71. #ifdef __IBMCPP__ 
  72.    _heapmin();  // return all unused memory to OS/2
  73. #endif
  74. }
  75.  
  76.  
  77. PSZ OWindow::isOfType() const
  78.  return("OWindow"); 
  79.  
  80.  
  81. OWindow& OWindow::show()
  82. {
  83.  if (hwnd)
  84.     WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ACTIVATE);
  85.  return(*this);
  86. }
  87.  
  88. OWindow& OWindow::hide()
  89. {
  90.  if (hwnd)
  91.     WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_HIDE | SWP_DEACTIVATE);
  92.  return(*this);
  93. }
  94.  
  95. OWindow& OWindow::activate()
  96. {
  97.  if (hwnd)
  98.     WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_ACTIVATE);
  99.  return(*this);
  100. }
  101.  
  102.  
  103. OWindow& OWindow::enable()
  104. {
  105.  if (hwnd)
  106.     WinEnableWindow(hwnd, TRUE);
  107.  return(*this);
  108. }
  109.  
  110.  
  111. OWindow& OWindow::disable()
  112. {
  113.  if (hwnd)
  114.     WinEnableWindow(hwnd, FALSE);
  115.  return(*this);
  116. }
  117.  
  118.  
  119. OWindow& OWindow::destroy()
  120. {
  121.  if (hwnd)
  122.     WinDestroyWindow(hwnd);
  123.  return(*this);
  124. }
  125.  
  126. OWindow& OWindow::setFocus()
  127. {
  128.  if (hwnd)
  129.     WinSetFocus(HWND_DESKTOP, hwnd);
  130.  return(*this);
  131. }
  132.  
  133.  
  134. OWindow& OWindow::setParent(const HWND handle)
  135. {
  136.  parent = handle; 
  137.  WinSetParent(hwnd, parent, TRUE);
  138.  return(*this);
  139. }
  140.  
  141.  
  142. OWindow& OWindow::setOwner(const HWND handle)
  143. {
  144.  owner = handle;
  145.  WinSetOwner(hwnd, owner);
  146.  return(*this);
  147. }
  148.  
  149. OWindow& OWindow::setForeColor(COLOR color)
  150. {
  151.  pparms.Fore = color;
  152.  WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, sizeof(COLOR), &pparms.Fore);
  153.  WinUpdateWindow(hwnd);
  154.  return(*this);
  155. }
  156.  
  157.  
  158. OWindow& OWindow::setBackColor(COLOR color)
  159. {
  160.  pparms.Back = color;
  161.  WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, sizeof(COLOR), &pparms.Back);
  162.  WinUpdateWindow(hwnd);
  163.  return(*this);
  164. }
  165.  
  166.  
  167. OWindow& OWindow::setFont(PSZ fontnamesize)
  168. {
  169.  strcpy(pparms.Font, fontnamesize);
  170.  WinSetPresParam(hwnd, PP_FONTNAMESIZE, strlen(pparms.Font)+1, pparms.Font);
  171.  WinUpdateWindow(hwnd);
  172.  return(*this);
  173. }
  174.  
  175.  
  176.  
  177. OWindow& OWindow::setPresentation(pPresParms presentation)
  178. {
  179.  pparms.Fore = presentation->Fore;
  180.  pparms.Back = presentation->Back;
  181.  WinSetPresParam(hwnd, PP_FOREGROUNDCOLOR, sizeof(COLOR), &pparms.Fore);
  182.  WinSetPresParam(hwnd, PP_BACKGROUNDCOLOR, sizeof(COLOR), &pparms.Back);
  183.  setFont(presentation->Font);
  184.  return(*this);
  185. }
  186.  
  187.  
  188. COLOR OWindow::getForeColor()
  189. {
  190.  ULONG ppid;
  191.  
  192.  WinQueryPresParam(hwnd, PP_FOREGROUNDCOLOR, 0, &ppid,
  193.                    sizeof(COLOR), &pparms.Fore, 0);
  194.  return(pparms.Fore);
  195. }
  196.  
  197.  
  198.  
  199. COLOR OWindow::getBackColor()
  200. {
  201.  ULONG ppid;
  202.  
  203.  WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &ppid,
  204.                    sizeof(COLOR), &pparms.Back, 0);
  205.  return(pparms.Back);
  206. }
  207.  
  208.  
  209. PSZ OWindow::getFont()
  210. {
  211.  ULONG ppid;
  212.  
  213.  WinQueryPresParam(hwnd, PP_FONTNAMESIZE, 0, &ppid, sizeof(pparms.Font), &pparms.Font, 0);
  214.  return(pparms.Font);
  215. }
  216.  
  217. OWindow& OWindow::getPresentation(pPresParms presentation)
  218. {
  219.  presentation->Fore = getForeColor();
  220.  presentation->Back = getBackColor();
  221.  strcpy(presentation->Font, getFont());
  222.  return(*this);
  223. }
  224.  
  225.  
  226. OWindow& OWindow::initReplace(const ULONG id, SWP& swp)
  227. {
  228.  HWND _hwnd = WinWindowFromID(parent, id);
  229.  
  230.  if (!_hwnd)
  231.    throw OPMException(OCL::error(137), 0);
  232.  
  233.  WinQueryWindowPos(_hwnd, &swp);
  234.  WinDestroyWindow(_hwnd);
  235.  
  236.  return(*this);
  237. }
  238.  
  239. OWindow& OWindow::cancelClose()
  240. {
  241.  WinSetWindowULong(hwnd, QWL_USER, (ULONG)this);
  242.  return(*this);
  243. }
  244.  
  245.  
  246. // end of source
  247.