home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / FLOATFRA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.5 KB  |  151 lines

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