home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / AGA Classes 1.2 / Buttons / LAGATextButton.cp < prev    next >
Encoding:
Text File  |  1996-06-30  |  3.3 KB  |  106 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LAGATextButton.cp
  3. // ===========================================================================
  4. //    “Apple Grayscale Appearance” compliant text button
  5. //    Copyright © 1996 Chrisoft (Christophe ANDRES)  All rights reserved.
  6. //
  7. //    You may use this source code in any application (commercial, shareware, freeware,
  8. //    postcardware, etc), but not remove this notice (no need to acknowledge the use of
  9. //    this class in the about box)
  10. //    You may not sell this source code in any form. This source code may be placed on 
  11. //    publicly accessable archive sites and source code disks. It may not be placed on 
  12. //    profit archive sites and source code disks without the permission of the author, 
  13. //    Christophe ANDRES.
  14. //    
  15. //        This source code is distributed in the hope that it will be useful,
  16. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. //
  19. //    If you make any change or improvement on this class, please send the improved/changed
  20. //    version to : chrisoft@calva.net or Christophe ANDRES
  21. //                                     20, rue Prosper Mérimée
  22. //                                     67100 STRASBOURG
  23. //                                     FRANCE
  24. //
  25. // ===========================================================================
  26. //    LAGATextButton.h            <- double-click + Command-D to see class implementation
  27. //
  28. //    LAGATextButton is a replacement class for LTextButton, that is needed, because in CW9 (PP 1.4)
  29. //        the LTextButton::DrawSelf doesn't use ApplyForeAndBackColors anymore, so that ::DrawText 
  30. //        puts a white background under the text, which is of course bad for a non-white background
  31. //        window
  32. //
  33. //        Version : 1.2
  34. //
  35. //        Change History (most recent first, date in US form : mm/dd/yy):
  36. //
  37. //                        06/30/96    ca        Public release of version 1.2
  38. //                        06/29/96    ca        class made available by Christophe ANDRES <chrisoft@calva.net>
  39. //                                                        (version 1.2 to be consistent with the other classes)
  40. //
  41. //        To Do:
  42. //
  43.  
  44.  
  45. #include "LAGATextButton.h"
  46.  
  47. void LAGATextButton::RegisterClass ()
  48.  
  49. {
  50.     URegistrar::RegisterClass(LAGATextButton::class_ID, (ClassCreatorFunc)LAGATextButton::CreateAGATextButtonStream);
  51. }
  52.  
  53. LAGATextButton* LAGATextButton::CreateAGATextButtonStream (LStream *inStream)
  54.  
  55. {
  56.     return(new LAGATextButton(inStream));
  57. }
  58.  
  59. LAGATextButton::LAGATextButton ()
  60.  
  61. {
  62. }
  63.  
  64. LAGATextButton::LAGATextButton (LStream* inStream) : LTextButton(inStream)
  65.  
  66. {
  67. }
  68.  
  69. void LAGATextButton::DrawSelf ()
  70.  
  71. {
  72.     StTextState        origTextState;
  73.     StColorPenState    origCPenState;
  74.  
  75.     // Configure the text state. If the button is selected,
  76.     // modify the text style.
  77.  
  78.     Int16 theJust = UTextTraits::SetPortTextTraits(mTextTraitsID);
  79.     if (mValue != Button_Off)
  80.         {
  81.             GrafPtr currPort = UQDGlobals::GetCurrentPort();
  82.             Int16 currStyle = currPort->txFace;
  83.             ::TextFace(currStyle ^ mSelectedStyle);
  84.         }
  85.  
  86.     // Draw the text.
  87.     
  88.     Rect theFrame;
  89.     CalcLocalFrameRect(theFrame);
  90.  
  91.     if (theJust == teFlushDefault)
  92.         {
  93.             theJust = ::GetSysDirection();
  94.         }
  95.  
  96.         // Set background color
  97.     
  98.     RGBColor    textColor;            // Text has its own foreground color
  99.     ::GetForeColor(&textColor);
  100.     
  101.     ApplyForeAndBackColors();
  102.     ::RGBForeColor(&textColor);
  103.  
  104.     UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0],
  105.                                         theFrame, theJust);    
  106. }