home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / ownerdra.pak / OWNERDRA.CPP < prev    next >
C/C++ Source or Header  |  1997-07-23  |  4KB  |  142 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\button.h>
  7. #include <owl\framewin.h>
  8. #include <owl\dialog.h>
  9. #include <owl\dc.h>
  10. #include "ownerdra.h"
  11. #include <stdio.h>
  12.  
  13. class TDrawableButton : public TButton {
  14.   public:
  15.     TDrawableButton(TWindow* parent, int resId) : TButton(parent, resId) {}
  16.    ~TDrawableButton() {}
  17.  
  18.     void ODADrawEntire(DRAWITEMSTRUCT far& drawInfo);
  19.     void ODAFocus(DRAWITEMSTRUCT far& drawInfo);
  20.     void ODASelect(DRAWITEMSTRUCT far& drawInfo);
  21. };
  22.  
  23. //
  24. // Function called when button needs to be drawn
  25. //
  26. void
  27. TDrawableButton::ODADrawEntire(DRAWITEMSTRUCT far& drawInfo)
  28. {
  29.   TDC drawDC(drawInfo.hDC);
  30.   TRect itemRect(drawInfo.rcItem.left, drawInfo.rcItem.top,
  31.                  drawInfo.rcItem.right, drawInfo.rcItem.bottom);
  32.   drawDC.Rectangle(itemRect);
  33.   if (IsCurrentDefPB)
  34.     drawDC.Rectangle(itemRect.InflatedBy(-1,-1));
  35.  
  36.   itemRect.Inflate(-4,-6);
  37.   drawDC.DrawText("DRAWN", -1, itemRect, DT_CENTER | DT_VCENTER);
  38.   if (drawInfo.itemState & ODS_FOCUS)
  39.     drawDC.DrawFocusRect(itemRect);
  40. }
  41.  
  42. //
  43. // Function called when button gains or loses focus
  44. //
  45. void
  46. TDrawableButton::ODAFocus(DRAWITEMSTRUCT far& drawInfo)
  47. {
  48.   TDC drawDC(drawInfo.hDC);
  49.   TRect itemRect(drawInfo.rcItem.left+4, drawInfo.rcItem.top+6,
  50.                  drawInfo.rcItem.right-4, drawInfo.rcItem.bottom-6);
  51.   drawDC.DrawFocusRect(itemRect);
  52. }
  53.  
  54. //
  55. // Function called when button's selection status changes
  56. //
  57. void
  58. TDrawableButton::ODASelect(DRAWITEMSTRUCT far& drawInfo)
  59. {
  60.   TDC drawDC(drawInfo.hDC);
  61.   TRect itemRect(drawInfo.rcItem.left, drawInfo.rcItem.top,
  62.                  drawInfo.rcItem.right, drawInfo.rcItem.bottom);
  63.   drawDC.Rectangle(itemRect);
  64.   if (IsCurrentDefPB)
  65.     drawDC.Rectangle(itemRect.InflatedBy(-1,-1));
  66.  
  67.   itemRect.Inflate(-4,-6);
  68.   if (drawInfo.itemState & ODS_SELECTED)
  69.     drawDC.DrawText("SELECTED", -1, itemRect, DT_CENTER | DT_VCENTER);
  70.   else
  71.     drawDC.DrawText("DESELECTED", -1, itemRect, DT_CENTER | DT_VCENTER);
  72.   if (drawInfo.itemState & ODS_FOCUS)
  73.     drawDC.DrawFocusRect(itemRect);
  74. }
  75.  
  76. //----------------------------------------------------------------------------
  77.  
  78. class TTestDialog : public TDialog {
  79.   public:
  80.     TDrawableButton* Button1;
  81.     TDrawableButton* Button2;
  82.  
  83.     TTestDialog(TWindow* parent);
  84.     void CmButton1() {MessageBeep(0);}
  85.  
  86.   DECLARE_RESPONSE_TABLE(TTestDialog);
  87. };
  88.  
  89. DEFINE_RESPONSE_TABLE1(TTestDialog,TDialog)
  90.   EV_COMMAND(ID_BUTTON1,CmButton1),
  91. END_RESPONSE_TABLE;
  92.  
  93.  
  94. TTestDialog::TTestDialog(TWindow* parent)
  95.   : TDialog(parent, "TESTDIALOG"),
  96.     TWindow(parent)
  97. {
  98.   Button1 = new TDrawableButton(this, ID_BUTTON1);
  99.   Button2 = new TDrawableButton(this, ID_BUTTON2);
  100. }
  101.  
  102. class TTestWindow : public TWindow {
  103.   public:
  104.     TTestWindow();
  105.     void CmTest();
  106.  
  107.   DECLARE_RESPONSE_TABLE(TTestWindow);
  108. };
  109.  
  110. DEFINE_RESPONSE_TABLE1(TTestWindow,TWindow)
  111.   EV_COMMAND(CM_TEST,CmTest),
  112. END_RESPONSE_TABLE;
  113.  
  114. TTestWindow::TTestWindow()
  115.   : TWindow(0, 0, 0)
  116. {
  117. }
  118.  
  119. void
  120. TTestWindow::CmTest()
  121. {
  122.   TTestDialog(this).Execute();
  123. }
  124.  
  125. //----------------------------------------------------------------------------
  126.  
  127. class TTestApp : public TApplication {
  128.   public:
  129.     TTestApp() : TApplication() {}
  130.     void InitMainWindow()
  131.     {
  132.         MainWindow = new TFrameWindow(0, "Drawable Button Tester", new TTestWindow);
  133.         MainWindow->AssignMenu("COMMANDS");
  134.     }
  135. };
  136.  
  137. int
  138. OwlMain(int /*argc*/, char* /*argv*/ [])
  139. {
  140.   return TTestApp().Run();
  141. }
  142.