home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / MESSAGEB.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.3 KB  |  139 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Implementation of class TMessageBar.
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_MESSAGEB_H)
  11. # include <owl/messageb.h>
  12. #endif
  13. #if !defined(OWL_TEXTGADG_H)
  14. # include <owl/textgadg.h>
  15. #endif
  16. #if !defined(WINSYS_UIMETRIC_H)
  17. # include <winsys/uimetric.h>
  18. #endif
  19.  
  20. OWL_DIAGINFO;
  21.  
  22. IMPLEMENT_CASTABLE1(TMessageBar, TGadgetWindow);
  23.  
  24. //
  25. // Construct a message bar with a given font.
  26. //
  27. TMessageBar::TMessageBar(TWindow*   parent,
  28.                          TFont*     font,
  29.                          TModule*   module)
  30. :
  31.   TGadgetWindow(parent, Horizontal, font, module)
  32. {
  33.   TTextGadget*  textGadget = new TTextGadget(IDG_MESSAGE, TTextGadget::Recessed,
  34.                              TTextGadget::Left, 10, 0, 0);
  35.  
  36.   Attr.Id = IDW_STATUSBAR;
  37.  
  38.   // 3d UI will bevel the client's inner edge, so we dont need the hilight
  39.   //
  40.   HighlightLine = !(TSystem::Has3dUI());
  41.  
  42.   HintText = 0;
  43.   textGadget->WideAsPossible = true;
  44.   Insert(*textGadget);
  45. }
  46.  
  47. //
  48. // Destruct this message bar and cleanup text allocated
  49. //
  50. TMessageBar::~TMessageBar()
  51. {
  52.   delete[] HintText;
  53. }
  54.  
  55. //
  56. // Paint the gadgets in this messagebar. Paints highlight line if enabled, and
  57. // handles painting hint text over the gadgets if text is currently set.
  58. //
  59. void
  60. TMessageBar::PaintGadgets(TDC& dc, bool erase, TRect& rect)
  61. {
  62.   if (HighlightLine && rect.top == 0)
  63.     dc.TextRect(0, 0, rect.right, TUIMetric::CyBorder, TColor::Sys3dHilight);
  64.  
  65.   if (HintText) {
  66.     TRect  clientRect = GetClientRect();
  67.     int    y = (clientRect.bottom - GetFontHeight()) / 2;
  68.  
  69.     if (HighlightLine)
  70.       clientRect.top += TUIMetric::CyBorder;
  71.     dc.SelectObject(GetFont());
  72.     dc.SetBkColor(TColor::Sys3dFace);
  73.     dc.ExtTextOut(5, y, ETO_OPAQUE, &clientRect, HintText, strlen(HintText));
  74.   }
  75.   else {
  76.     TGadgetWindow::PaintGadgets(dc, erase, rect);
  77.   }
  78. }
  79.  
  80. //
  81. // Get the inner rect for this message bar. Adjust for the top highlight line
  82. // if one is set.
  83. //
  84. void
  85. TMessageBar::GetInnerRect(TRect& innerRect)
  86. {
  87.   TGadgetWindow::GetInnerRect(innerRect);
  88.  
  89.   if (HighlightLine)
  90.     innerRect.top += TUIMetric::CyBorder;
  91. }
  92.  
  93. //
  94. // Get the desired size for this message bar. Adjust for the top highlight line
  95. // if one is set.
  96. //
  97. void
  98. TMessageBar::GetDesiredSize(TSize& size)
  99. {
  100.   TGadgetWindow::GetDesiredSize(size);
  101.  
  102.   if (HighlightLine)
  103.     size.cy++;
  104. }
  105.  
  106. //
  107. // Set the text for the message bar by puting it in the message text gadget
  108. //
  109. void
  110. TMessageBar::SetText(const char* text)
  111. {
  112.   SetMessageText(IDG_MESSAGE, text);
  113. }
  114.  
  115. //
  116. // Set the text for the text gadget with a given ID
  117. //
  118. void
  119. TMessageBar::SetMessageText(int id, const char* text)
  120. {
  121.   TTextGadget* tg = TYPESAFE_DOWNCAST(GadgetWithId(id), TTextGadget);
  122.   if (tg)
  123.     tg->SetText(text);
  124. }
  125.  
  126. //
  127. // Sets or clears menu/command hint text that is displayed over all the gadgets
  128. // Pass 0 to clear the text. Causes a repaint.
  129. //
  130. void
  131. TMessageBar::SetHintText(const char* text)
  132. {
  133.   if (text != HintText) {
  134.     delete[] HintText;
  135.     HintText = text ? strnewdup(text) : 0;
  136.     Invalidate();
  137.   }
  138. }
  139.