home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / CommandKeyAttachments / CInternalCmdKeyAttachment.cp < prev    next >
Encoding:
Text File  |  1997-01-31  |  4.1 KB  |  108 lines  |  [TEXT/R*ch]

  1. // ===========================================================================
  2. //    File:                        CInternalCmdKeyAttachment.cp
  3. // Version:                    1.0.1 - Jan 31, 1997
  4. //    Author:                    Mike Shields (mshields@inconnect.com)
  5. //                            
  6. //    Copyright ©1996 Mike Shields. All rights reserved.
  7. //    I hereby grant users of CInternalCmdKeyAttachment permission to use it (or any modified 
  8. //    version of it) in applications (or any other type of Macintosh software 
  9. //    like extensions -- freeware, shareware, commercial, or other) for free, 
  10. //    subject to the terms that:
  11. //
  12. //        (1)  This agreement is non-exclusive.
  13. //
  14. //        (2)  I, Mike Shields, retain the copyright to the original source code.
  15. //
  16. //    These two items are the only required conditions for use. However, I do have 
  17. //    an additional request. Note, however, that this is only a request, and 
  18. //    that it is not a required condition for use of this code.
  19. //
  20. //        (1) That I be given credit for CInternalCmdKeyAttachment code in the copyrights or 
  21. //            acknowledgements section of your manual or other appropriate documentation.
  22. //
  23. //
  24. //    I would like to repeat that this last item is only a request. You are prefectly 
  25. //    free to choose not to do any or all of them.
  26. //    
  27. //        This source code is distributed in the hope that it will be useful,
  28. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. // ===========================================================================
  31. //    CInternalCmdKeyAttachment.h        <- double-click + Command-D to see class declaration
  32. //
  33. //    Class which handles drawing and responding to command keys when it is attached 
  34. // to a button
  35.  
  36. #include "CInternalCmdKeyAttachment.h"
  37. #include <LStream.h>
  38.  
  39. //----------------------------------------------------------------------------------------
  40. // CInternalCmdKeyAttachment::DrawCommandKey
  41. //----------------------------------------------------------------------------------------
  42. CInternalCmdKeyAttachment* CInternalCmdKeyAttachment::CreateFromStream(LStream    *inStream)
  43. {
  44.     return new CInternalCmdKeyAttachment(inStream);
  45. }
  46.  
  47. //----------------------------------------------------------------------------------------
  48. // CExternalCmdKeyAttachment::DrawCommandKey
  49. //----------------------------------------------------------------------------------------
  50. CInternalCmdKeyAttachment::CInternalCmdKeyAttachment()
  51.     : mShowingCommandKey(false)
  52. {
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // CInternalCmdKeyAttachment::DrawCommandKey
  57. //----------------------------------------------------------------------------------------
  58. CInternalCmdKeyAttachment::CInternalCmdKeyAttachment(LStream *inStream)
  59.     : CCmdKeyAttachment(inStream), mShowingCommandKey(false)
  60. {
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // CInternalCmdKeyAttachment::DrawCommandKey
  65. //----------------------------------------------------------------------------------------
  66. CInternalCmdKeyAttachment::~CInternalCmdKeyAttachment()
  67. {
  68. }
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CInternalCmdKeyAttachment::DrawCommandKey
  72. //----------------------------------------------------------------------------------------
  73. void CInternalCmdKeyAttachment::EnableCommandKey(Boolean inCmdDown)
  74. {
  75.     if ( inCmdDown == true && mShowingCommandKey == false )
  76.         DrawCommandKey(true);
  77.     else if ( inCmdDown == false && mShowingCommandKey == true )
  78.         DrawCommandKey(false);
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // CInternalCmdKeyAttachment::DrawCommandKey
  83. //----------------------------------------------------------------------------------------
  84. void CInternalCmdKeyAttachment::DrawCommandKey(Boolean inVisible)
  85. {
  86.     LStr255    controlTitle;
  87.  
  88.     mMyControl->GetDescriptor(controlTitle);
  89.     
  90.     if ( inVisible )
  91.     {
  92.         char    temp = mCommandKey;
  93.  
  94.         ::UpperText(&temp, 1);
  95.         controlTitle += char_Space;
  96.         controlTitle += char_Propeller;
  97.         controlTitle += temp;
  98.     }
  99.     else
  100.         controlTitle.Remove(controlTitle.Length() - 2, 3);
  101.     
  102.     mShowingCommandKey = inVisible;
  103.     
  104.     mMyControl->SetDescriptor(controlTitle);
  105. }
  106.  
  107.  
  108.