home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Conic Sections 0.9.2 / Sources / DismissButton.cpp < prev    next >
Encoding:
Text File  |  1997-07-20  |  1.6 KB  |  72 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "DismissButton.h"
  5. #include "CLEventDispatcher.h"
  6. #include "CLKeyboardHandler.h"
  7. #include "CLBaseWindow.h"
  8. #include <QuickDrawText.h>
  9. #include <Fonts.h>
  10.  
  11. TDismissButton::TDismissButton( TLayoutBranch *super, unsigned char *message ):
  12.     TControl( super ),
  13.     mString( message )
  14. {
  15. }
  16.  
  17. void TDismissButton::AttachedToWindow( TBaseWindow *win, Rect r )
  18. {
  19.     TControl::AttachedToWindow( win, r );
  20.     TKeyboardHandler::GetKeyboard()->SetListener( this );
  21. }
  22.  
  23. void TDismissButton::DrawSelf( TDrawSlate *gr )
  24. {
  25.     Rect drawRect= mContentRect;
  26.     FontInfo metric;
  27.  
  28.     ::FrameRoundRect( &drawRect, 8, 8 );
  29.     ::TextFont( ::GetSysFont() );
  30.     ::GetFontInfo( &metric );
  31.     ::MoveTo( (drawRect.left+drawRect.right-StringWidth( mString ))/2,
  32.       (drawRect.top+drawRect.bottom+metric.ascent-metric.descent)/2 );
  33.     ::DrawString( mString );
  34. }
  35.  
  36. void TDismissButton::TrackMouseDown( TMouseEvent *ev )
  37. {
  38.     TrackMouseChange( ev, true );
  39. }
  40.  
  41. void TDismissButton::TrackMouseChange( TMouseEvent *ev, BOOLEAN in )
  42. {
  43.     Rect drawRect= mContentRect;
  44.  
  45.     ::InsetRect( &drawRect, 1, 1 );
  46.     ::InvertRoundRect( &drawRect, 6, 6 );
  47. }
  48.  
  49. void TDismissButton::TrackMouseUp( TMouseEvent *ev )
  50. {
  51.     MEventDispatcher::GetDispatcher()->Quit();
  52. }
  53.  
  54. Rect TDismissButton::GetLargestSize()
  55. {
  56.     return( mContentRect );
  57. }
  58.  
  59. void TDismissButton::RespondKeyboard( const TKeyEvent *ev )
  60. {
  61.     if( ev->asciiCode==0x0D ) {
  62.         mWindow->GetDrawFocus();
  63.         Rect drawRect= mContentRect;
  64.         ::InsetRect( &drawRect, 1, 1 );
  65.         ::InvertRoundRect( &drawRect, 6, 6 );
  66.         long ret;
  67.         ::Delay( 3, &ret );
  68.         ::InvertRoundRect( &drawRect, 6, 6 );
  69.         mWindow->ReleaseDrawFocus();
  70.         MEventDispatcher::GetDispatcher()->Quit();
  71.     }
  72. }