home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / buttons / titlebut / titlebut.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.9 KB  |  115 lines

  1. //************************************************************
  2. // Button Controls - Title Bar Bitmap Example                 
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <iapp.hpp>
  9. #include <iframe.hpp>
  10. #include <igraphbt.hpp>
  11. #include <istattxt.hpp>
  12. #include <isizehdr.hpp>
  13. #include <iiconctl.hpp>
  14. #include <icmdhdr.hpp>
  15. #include "titlebut.h"
  16.  
  17.  
  18. // Command handler to capture button commands
  19. class CommandHandler : public ICommandHandler
  20. {
  21. public:
  22.   CommandHandler ( IStaticText& status)
  23.             : _status(status) {}
  24.  
  25. protected:
  26. virtual Boolean
  27.   command              ( ICommandEvent& event );
  28.  
  29. private:
  30. IStaticText
  31.  &_status;
  32. CommandHandler& operator=(const CommandHandler&);
  33. };
  34.  
  35. // Create a Resize Handler for the Graphic Push Button
  36. class GraphicResizeHandler : public IResizeHandler {
  37.  
  38. protected:
  39. virtual Boolean
  40.   windowResize         ( IResizeEvent& event );
  41. }; 
  42.  
  43.  
  44. void main()
  45. {
  46. IFrameWindow
  47.   frame ("Title Bar Bitmap Example");
  48.  
  49. // Titlebar Bitmaps using Buttons
  50. IGraphicPushButton
  51.   ringBefore(ID_RINGBEFORE, &frame, &frame, ID_RINGBEFORE),
  52.   ringAfter(ID_RINGAFTER, &frame, &frame, ID_RINGAFTER);
  53.  
  54. // Create the resize handler and energize
  55. // it for both bitmap buttons
  56. GraphicResizeHandler resizeHandler;
  57. resizeHandler
  58.   .handleEventsFor(&ringBefore)
  59.   .handleEventsFor(&ringAfter);
  60.  
  61. // Add the buttons as frame extensions
  62. frame
  63.   .addExtension(&ringAfter,  IFrameWindow::rightOfTitleBar, 22)
  64.   .addExtension(&ringBefore, IFrameWindow::rightOfTitleBar, 22);
  65.  
  66. // Create a Status Area and
  67. // a command handler to write in it
  68. IStaticText statusArea(ID_STATUS, &frame, &frame);
  69. CommandHandler commandHandler(statusArea);
  70. commandHandler.handleEventsFor(&frame);
  71.  
  72. // Put the status area in the client, 
  73. // set the focus, and show the app
  74. frame
  75.   .setClient(&statusArea)
  76.   .setFocus()
  77.   .show();
  78. IApplication::current().run();
  79.  
  80. }
  81.  
  82. // A Command handler just to be sure the buttons work
  83. Boolean CommandHandler::command( ICommandEvent& event )
  84. {
  85.   switch(event.commandId())
  86.   {
  87.     case ID_RINGBEFORE :
  88.     {
  89.        _status.setText("Ring before button pressed");
  90.        return true;
  91.     }
  92.  
  93.     case ID_RINGAFTER :
  94.     {
  95.        _status.setText("Ring after button pressed");
  96.        return true;
  97.     }
  98.   }
  99. return false;
  100. }
  101.  
  102. // Resize the IIconControl child of the IGraphicPushButton 
  103. // - this is needed because too much padding is around the 
  104. // IIconControl by default
  105. Boolean GraphicResizeHandler :: windowResize( IResizeEvent& evt )
  106. {
  107.   IGraphicPushButton* button = (IGraphicPushButton*)evt.window();
  108.   if (evt.oldSize() != evt.newSize() &&
  109.              !(button->isSizeToGraphic()))
  110.   {
  111.      button->graphicWindow().moveSizeTo(IRectangle(2,2,22,22));
  112.   }
  113.   return true;
  114. }
  115.