home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / FLOATFRA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  5.2 KB  |  183 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of class TFloatingFrame.
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl/owlpch.h>
  9. #include <owl/floatfra.h>
  10. #include <owl/dc.h>
  11.  
  12. #if !defined(SECTION) || SECTION == 1
  13.  
  14. //
  15. // Order is very important.  Must make sure that TTinyCaption gets 1st crack
  16. // after us
  17. //
  18. DEFINE_RESPONSE_TABLE2(TFloatingFrame, TTinyCaption, TFrameWindow)
  19.   EV_WM_SYSCOMMAND,
  20.   EV_WM_NCCALCSIZE,
  21.   EV_WM_NCPAINT,
  22.   EV_WM_NCHITTEST,
  23. END_RESPONSE_TABLE;
  24.  
  25. TFloatingFrame::TFloatingFrame(TWindow* owner, char* title, TWindow* client, 
  26.                                bool shrinkToClient, int captionHeight,
  27.                                bool popupPalette, TModule* module)
  28. :
  29.   TFrameWindow(owner, title, client, shrinkToClient, module),
  30.   TTinyCaption(),
  31.   Margin(2, 2)
  32. {
  33.   FloatingPaletteEnabled = popupPalette;
  34.   if (FloatingPaletteEnabled) {
  35.     Attr.Style = WS_POPUP | WS_BORDER | WS_VISIBLE;
  36.  
  37.     //
  38.     // Use close box (true) for palettes, & calc dimensions w/ new styles
  39.     //
  40.     EnableTinyCaption(captionHeight, true);
  41.  
  42.     //
  43.     // Windows with a popup style ignore CW_USEDEFAULT style
  44.     // So we will specify a default size
  45.     // Normal use will be to specify a client and allow frame to sizeToClient
  46.     // so this will rarely be used.
  47.     //
  48.     Attr.X = Attr.Y = 0;
  49.     Attr.W = 100;
  50.     Attr.H = 50;
  51.   }
  52.   else
  53.     EnableTinyCaption(captionHeight, false);
  54. }
  55.  
  56. //
  57. // Resolving ambiguous mixin reference
  58. //
  59. LRESULT
  60. TFloatingFrame::EvCommand(uint id, HWND hWndCtl, uint notifyCode)
  61. {
  62.   LRESULT er;
  63.   if (TTinyCaption::DoCommand(id, hWndCtl, notifyCode, er) == esComplete)
  64.     return er;
  65.   if (Parent)
  66.     return Parent->EvCommand(id, hWndCtl, notifyCode);
  67.   return TFrameWindow::EvCommand(id, hWndCtl, notifyCode);
  68. }
  69.  
  70. //
  71. // This is an example of a mix-in that does partial event handling
  72. // We need to call the 'do' function for the mixin instead of the 'Ev'
  73. // function to avoid duplicate default processing
  74. //
  75. void
  76. TFloatingFrame::EvSysCommand(uint cmdType, TPoint& p)
  77. {
  78.   if (TTinyCaption::DoSysCommand(cmdType, p) == esComplete)
  79.     return;
  80.   TFrameWindow::EvSysCommand(cmdType,p);
  81. }
  82.  
  83. uint
  84. TFloatingFrame::EvNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS far& calcSize)
  85. {
  86.   // Adjust margins for extra edge around palette
  87.   //
  88.   if (FloatingPaletteEnabled && !IsIconic()) {
  89.     calcSize.rgrc[0].left +=   Margin.cx * GetSystemMetrics(SM_CXBORDER);
  90.     calcSize.rgrc[0].top +=    Margin.cy * GetSystemMetrics(SM_CYBORDER);
  91.     calcSize.rgrc[0].right -=  Margin.cx * GetSystemMetrics(SM_CXBORDER);
  92.     calcSize.rgrc[0].bottom -= Margin.cy * GetSystemMetrics(SM_CYBORDER);
  93.   }
  94.  
  95.   uint er;
  96.   if (DoNCCalcSize(calcValidRects, calcSize, er) == esComplete)
  97.     return er;
  98.   return TFrameWindow::EvNCCalcSize(calcValidRects, calcSize);
  99. }
  100.  
  101. //
  102. // We only need to paint the margins. TWindow (via DefWindowProc) will paint
  103. // the borders, & TTinyCaption will paint the caption
  104. //
  105. void
  106. TFloatingFrame::EvNCPaint()
  107. {
  108.   TWindow::EvNCPaint();       // Default border painting
  109.   TTinyCaption::DoNCPaint();  // Tiny caption painting
  110.  
  111.   if (FloatingPaletteEnabled) {
  112.     //
  113.     // Paint margins in button face color
  114.     //
  115.     TWindowDC dc(*this);
  116.     TRect     wr = GetWindowRect().InflatedBy(-Frame);
  117.     wr -= wr.TopLeft();
  118.     wr += Border;
  119.     wr.top = GetCaptionRect().bottom;
  120.     int mx = Margin.cx * Border.cx;
  121.     int my = Margin.cy * Border.cy;
  122.     dc.SetBkColor(GetSysColor(COLOR_BTNFACE));
  123.     dc.TextRect(wr.left, wr.top, wr.left+mx, wr.bottom);           // left
  124.     dc.TextRect(wr.left+mx, wr.top, wr.right-mx, wr.top+my);       // top
  125.     dc.TextRect(wr.right-mx, wr.top, wr.right, wr.bottom);         // right
  126.     dc.TextRect(wr.left+mx, wr.bottom-my, wr.right-mx, wr.bottom); // bottom
  127.   }
  128. }
  129.  
  130. //
  131. // Return where in the non client area we are.  We only handle caption
  132. // bar area
  133. //
  134. uint
  135. TFloatingFrame::EvNCHitTest(TPoint& screenPt)
  136. {
  137.   uint er;
  138.   if (TTinyCaption::DoNCHitTest(screenPt, er) == esComplete ||
  139.       DoNCHitTest(screenPt, er) == esComplete)
  140.     return er;
  141.   return TWindow::EvNCHitTest(screenPt);
  142. }
  143.  
  144. TEventStatus
  145. TFloatingFrame::DoNCHitTest(TPoint& screenPt, uint& evRes)
  146. {
  147.   if (FloatingPaletteEnabled) {
  148.     TPoint clientOffs(0,0);
  149.     ClientToScreen(clientOffs);
  150.     if (!GetClientRect().Contains(screenPt-clientOffs)) {
  151.       evRes = HTCAPTION;
  152.       return esComplete;
  153.     }
  154.   }
  155.   return esPartial;
  156. }
  157.  
  158. #endif
  159. #if !defined(SECTION) || SECTION == 2
  160.  
  161. IMPLEMENT_STREAMABLE2(TFloatingFrame, TTinyCaption, TFrameWindow);
  162.  
  163. void*
  164. TFloatingFrame::Streamer::Read(ipstream& is, uint32 /*version*/) const
  165. {
  166.   TFloatingFrame* o = GetObject();
  167.   ReadBaseObject((TFrameWindow*)o, is);
  168.   ReadBaseObject((TTinyCaption*)o, is);
  169.   is >> o->Margin;
  170.   return o;
  171. }
  172.  
  173. void
  174. TFloatingFrame::Streamer::Write(opstream& os) const
  175. {
  176.   TFloatingFrame* o = GetObject();
  177.   WriteBaseObject((TFrameWindow*)o, os);
  178.   WriteBaseObject((TTinyCaption*)o, os);
  179.   os << o->Margin;
  180. }
  181.  
  182. #endif
  183.