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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OFrame.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.  
  32. // $Header: W:/Projects/OCL/Source/rcs/OFrame.cpp 1.50 1996/08/11 23:49:16 B.STEIN Release $
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <OFrame.hpp>
  41. #include <OPMException.hpp>
  42.  
  43. OFrame::OFrame(const ULONG id,
  44.                const ULONG Style,
  45.                const ULONG winbits)
  46.  : OWindow(id, Style, winbits),
  47.    frame(NULLHANDLE),
  48.    client(NULLHANDLE)
  49.  {}
  50.  
  51.  
  52. OFrame::~OFrame()
  53.  if (frame)
  54.    WinDestroyWindow(frame); 
  55. }
  56.  
  57.  
  58. PSZ OFrame::isOfType() const
  59.  return("OFrame"); 
  60. }
  61.  
  62.  
  63. OFrame& OFrame::createFrame(PSZ className)
  64. {
  65.  FRAMECDATA fcdata;
  66.  
  67.  fcdata.cb            = sizeof(FRAMECDATA);
  68.  fcdata.flCreateFlags = style;
  69.  fcdata.hmodResources = (HMODULE)NULL;
  70.  fcdata.idResources   = res;
  71.  
  72.  if (!WinRegisterClass(OApp::current().anchor(), 
  73.                        className, 
  74.                        OWinDefWindowProc,
  75.                        bits,
  76.                        sizeof(PVOID)))
  77.    throw OPMException(OCL::error(132), 0);
  78.  
  79.  
  80.  if ((frame = WinCreateWindow(parent, WC_FRAME,  "",
  81.                               0, 0, 0, 0, 0,
  82.                               owner, HWND_TOP, res, &fcdata, NULL)) == NULLHANDLE)
  83.    throw OPMException(OCL::error(133), 0);
  84.  
  85.  if ((client = WinCreateWindow(frame, className, "", 0, 0, 0, 0, 0, frame,
  86.                                HWND_TOP, FID_CLIENT, this, NULL)) == NULLHANDLE)
  87.    throw OPMException(OCL::error(134), 0);
  88.  
  89.  if (!winText)
  90.    winText << className;
  91.  
  92.  WinSetWindowText(frame, winText);
  93.  
  94.  return(*this);
  95. }
  96.  
  97.  
  98. OFrame& OFrame::centerFrame()
  99. {
  100.  SWP swpScreen;
  101.  
  102.  swpScreen.cx=WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  103.  swpScreen.cy=WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  104.  
  105.  WinSetWindowPos(frame, NULLHANDLE, (swpScreen.cx-sizepos.cx)/2,
  106.                         (swpScreen.cy-sizepos.cy)/2, sizepos.cx, sizepos.cy,
  107.                         SWP_SIZE | SWP_MOVE | SWP_RESTORE | SWP_ACTIVATE);
  108.  return(*this);
  109. }
  110.  
  111.  
  112. OFrame& OFrame::setSizePosFrame(const HWND behind, SWP dimensions, const ULONG flag)
  113. {
  114.  if (frame) {
  115.    WinSetWindowPos(frame, behind, dimensions.x, dimensions.y, dimensions.cx, dimensions.cy, flag);
  116.    WinQueryWindowPos(frame, &sizepos); }
  117.  
  118.  return(*this);
  119. }
  120.  
  121.  
  122. OFrame& OFrame::trackFrame()
  123. {
  124.  TRACKINFO         TrackInfo;
  125.  
  126.  WinQueryWindowPos(frame, &sizepos);
  127.  memset (&TrackInfo, 0, sizeof(TrackInfo));  // init the trackinfo struct
  128.  
  129.  TrackInfo.cxBorder = 1;
  130.  TrackInfo.cyBorder = 1;
  131.  TrackInfo.cxGrid = 1;
  132.  TrackInfo.cyGrid = 1;
  133.  TrackInfo.cxKeyboard = 8;
  134.  TrackInfo.cyKeyboard = 8;
  135.  TrackInfo.rclTrack.xLeft   = sizepos.x;
  136.  TrackInfo.rclTrack.xRight  = sizepos.x + sizepos.cx;
  137.  TrackInfo.rclTrack.yBottom = sizepos.y;
  138.  TrackInfo.rclTrack.yTop = sizepos.y + sizepos.cy;
  139.  WinQueryWindowPos(HWND_DESKTOP, &sizepos);
  140.  TrackInfo.rclBoundary.xLeft   = sizepos.x;
  141.  TrackInfo.rclBoundary.xRight  = sizepos.x + sizepos.cx;
  142.  TrackInfo.rclBoundary.yBottom = sizepos.y;
  143.  TrackInfo.rclBoundary.yTop = sizepos.y + sizepos.cy;
  144.  TrackInfo.ptlMinTrackSize.x = 0;
  145.  TrackInfo.ptlMinTrackSize.y = 0;
  146.  TrackInfo.ptlMaxTrackSize.x = sizepos.cx;
  147.  TrackInfo.ptlMaxTrackSize.y = sizepos.cy;
  148.  TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
  149.  
  150.  if (WinTrackRect(HWND_DESKTOP, 0, &TrackInfo))   // now we move ourselves
  151.     WinSetWindowPos(frame, 0, (SHORT) TrackInfo.rclTrack.xLeft,
  152.                               (SHORT) TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
  153.  WinSetWindowPos(frame, 0, 0, 0, 0, 0, SWP_SHOW | SWP_ACTIVATE);
  154.  
  155.  return(*this);
  156. }
  157.  
  158.  
  159. OFrame& OFrame::showFrame() 
  160. {
  161.  if (frame)
  162.     WinShowWindow(frame, TRUE);
  163.  
  164.  return(*this);
  165. }
  166.  
  167.  
  168. OFrame& OFrame::hideFrame() 
  169. {
  170.  if (frame)
  171.    WinShowWindow(frame, FALSE);
  172.  
  173.  return(*this);
  174. }
  175.  
  176.  
  177. OFrame& OFrame::destroyFrame() 
  178. {
  179.  if (frame) {
  180.     termFlag = TRUE;
  181.     WinDestroyWindow(frame); }
  182.  
  183.  return(*this);
  184. }
  185.  
  186. OFrame& OFrame::postQuit()
  187. {
  188.  if (frame) {
  189.     termFlag = TRUE;
  190.     WinPostMsg(frame, WM_QUIT, NULL, NULL); }
  191.  
  192.  return(*this);
  193. }
  194.  
  195.  
  196. OFrame& OFrame::setWindowText(PCSZ text) 
  197. {
  198.   if (text) {
  199.      winText << (PSZ) text;
  200.      WinSetWindowText(frame, winText); }
  201.  
  202.  return(*this);
  203. }
  204.  
  205.  
  206.  
  207. BOOL OFrame::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  208. {
  209.  switch(msg)
  210.    {
  211.     case WM_PRESPARAMCHANGED:
  212.       switch(LONGFROMMP(mp1))
  213.        {
  214.         case PP_FONTNAMESIZE:
  215.           getFont();
  216.           WinInvalidateRect(hwnd, 0, TRUE);
  217.           WinQueryWindowPos(parent, &sizepos);
  218.           WinSendMsg(parent, WM_SIZE, NULL, MPFROM2SHORT(sizepos.cx, sizepos.cy));
  219.           break;
  220.  
  221.         case PP_FOREGROUNDCOLOR:
  222.           getForeColor();
  223.           WinInvalidateRect(hwnd, 0, TRUE);
  224.           break;
  225.  
  226.         case PP_BACKGROUNDCOLOR:
  227.           getBackColor();
  228.           WinInvalidateRect(hwnd, 0, TRUE);
  229.           break;
  230.        }
  231.       break;
  232.  
  233.     default:
  234.       return(FALSE);
  235.    }
  236.  return(TRUE);
  237. #ifdef __BCPLUSPLUS__
  238.   #pragma warn -par
  239. #endif
  240. }
  241. #ifdef __BCPLUSPLUS__
  242.   #pragma warn .par
  243. #endif
  244.  
  245.  
  246. // end of source  
  247.