home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / igpb1.zip / igpbrdr.hpp < prev    next >
Text File  |  1994-03-11  |  2KB  |  49 lines

  1. #include <isizehdr.hpp>
  2. #include <igraphbt.hpp>
  3. #include <iiconctl.hpp>
  4.  
  5. /***********************************************************************/
  6. /* Here is the windowResize function for implementing a IGPBorderSizer */
  7. /* that inherits from IResizeHander.  Attach this to your graphic      */
  8. /* push buttons.                                                       */
  9. /* To use this all you need to is include this file in any .cpp that   */
  10. /* uses IGraphicPushButton, instatiate an IGPBorderSizer object, then  */
  11. /* have it handleEventsFor() the IGraphicPushButtons that you wish to  */
  12. /* change border size for.                                             */
  13. /* The default border size used is 3, you can change this by passing   */
  14. /* a value on the constructor                                          */
  15. /* This handler only affect buttons that DO NOT have the sizeToGraphic */
  16. /* style.                                                              */
  17. /***********************************************************************/
  18. class IGPBorderSizer : public IResizeHandler {
  19.  
  20. public:
  21.   IGPBorderSizer(long size = 3) :
  22.      IResizeHandler(),
  23.      borderSize(size)
  24.   {}
  25.  
  26. protected:
  27.   Boolean IGPBorderSizer :: windowResize( IResizeEvent& evt )
  28.   {
  29.     IGraphicPushButton* button = (IGraphicPushButton*)evt.window();
  30.     if (evt.oldSize() != evt.newSize() && !(button->isSizeToGraphic()))
  31.     {
  32.        long inith  = borderSize, 
  33.             initw  = borderSize,
  34.             width  = -initw,
  35.             height = -inith;
  36.        if ((width += evt.newSize().width() ) < 0)
  37.           width = 0;
  38.        if ((height+= evt.newSize().height()) < 0)
  39.           height = 0;
  40.        button->graphicWindow().moveSizeTo(IRectangle(initw,inith,width,height));
  41.     }                               // End size change occurred
  42.     return true;
  43.   }
  44.  
  45. private:
  46.   long borderSize;
  47.  
  48. };
  49.