home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / TOOLBOX.PAK / TOOLBOXX.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.2 KB  |  145 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/floatfra.h>
  8. #include <owl/toolbox.h>
  9. #include <owl/buttonga.h>
  10. #include <owl/bitmapga.h>
  11. #include "toolbox.rh"
  12.  
  13. //
  14. // class TClientWindow
  15. // ~~~~~ ~~~~~~~~~~~~~
  16. class TClientWindow : public TWindow {
  17.   public:
  18.     TClientWindow();
  19.  
  20.   protected:
  21.     void    ButtonHandler(uint id);
  22.     bool    EvSetCursor(HWND hWndCursor, uint hitTest, uint mouseMsg);
  23.     void    EvSize(uint,TSize&);
  24.  
  25.     void    Paint(TDC& dc, bool repaint, TRect& rect);
  26.     TPointer<TCursor> Cursor;
  27.  
  28.   DECLARE_RESPONSE_TABLE(TClientWindow);
  29. };
  30.  
  31.  
  32. //
  33. // class TToolBoxApp
  34. // ~~~~~ ~~~~~~~~~~~
  35. class TToolBoxApp : public TApplication {
  36.   public:
  37.     void InitMainWindow();
  38. };
  39.  
  40.  
  41. //
  42. // Response table for ToolBoxWindow
  43. //
  44. DEFINE_RESPONSE_TABLE1(TClientWindow, TWindow)
  45.   EV_WM_SETCURSOR,
  46.   EV_WM_SIZE,
  47.   EV_COMMAND_AND_ID(CM_CMD1,   ButtonHandler),
  48.   EV_COMMAND_AND_ID(CM_CMD2,   ButtonHandler),
  49.   EV_COMMAND_AND_ID(CM_CMD3,   ButtonHandler),
  50.   EV_COMMAND_AND_ID(CM_CMD4,   ButtonHandler),
  51.   EV_COMMAND_AND_ID(CM_CMD5,   ButtonHandler),
  52.   EV_COMMAND_AND_ID(CM_CMD6,   ButtonHandler),
  53.   EV_COMMAND_AND_ID(CM_CMD7,   ButtonHandler),
  54.   EV_COMMAND_AND_ID(CM_CMD8,   ButtonHandler),
  55.   EV_COMMAND_AND_ID(CM_CMD9,   ButtonHandler),
  56. END_RESPONSE_TABLE;
  57.  
  58. TClientWindow::TClientWindow() : TWindow(0, "Toolbox Sample")
  59. {}
  60.  
  61. //
  62. //
  63. //
  64. void
  65. TClientWindow::ButtonHandler(uint id)
  66. {
  67.   if (id >= CM_CMD1 && id <= CM_CMD9)
  68.     Cursor = new TCursor(*GetModule(), TResId(id));
  69. }
  70.  
  71. //
  72. //
  73. //
  74. void  
  75. TClientWindow::Paint(TDC& dc, bool /*repaint*/, TRect& /*rect*/)
  76. {
  77.   TRect rect;
  78.   GetClientRect(rect);
  79.  
  80.   const char msg[]="This window's cursor matches the button "
  81.                    "gadget selected on it's toolbox";
  82.   dc.DrawText(msg, sizeof(msg)-1, rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  83. }
  84.  
  85. //
  86. //
  87. //
  88. bool    
  89. TClientWindow::EvSetCursor(HWND /*hWndCursor*/, uint /*hitTest*/, 
  90.                            uint /*mouseMsg*/)
  91. {
  92.   TCursor* cursor = Cursor;
  93.   if (cursor && cursor->GetHandle()) {
  94.     ::SetCursor(*cursor);
  95.     return true;
  96.   }
  97.   return false;
  98. }
  99.  
  100. //
  101. //
  102. //
  103. void
  104. TClientWindow::EvSize(uint,TSize&)
  105. {
  106.   Invalidate();
  107.   UpdateWindow();
  108. }
  109.  
  110. //
  111. // InitMainWindow
  112. //
  113. void
  114. TToolBoxApp::InitMainWindow()
  115. {
  116.   // Main window: frame + client
  117.   //
  118.   TClientWindow* client = new TClientWindow;
  119.   TFrameWindow* frame = new TFrameWindow(0, "ToolBox application", client);
  120.  
  121.   // Palette: Floating frame + toolbox
  122.   //
  123.   TToolBox* tb = new TToolBox(0, 3);
  124.   for (int i=CM_CMD1; i<=CM_CMD9; i++)
  125.    tb->Insert(*new TButtonGadget(i, i, TButtonGadget::Exclusive));
  126.  
  127.   TFloatingFrame* ff = new TFloatingFrame(frame, "Sample toolbox", tb, true,
  128.                                  TFloatingFrame::DefaultCaptionHeight, true);
  129.   ff->Attr.ExStyle |= WS_EX_PALETTEWINDOW;
  130.  
  131.   SetMainWindow(frame);
  132. }
  133.  
  134.  
  135. //
  136. // OwlMain
  137. //
  138. int
  139. OwlMain(int /*argc*/, char* /*argv*/ [])
  140. {
  141.   TToolBoxApp app;
  142.   return app.Run();
  143. }
  144.  
  145.