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

  1. // ===========================================================================
  2. //    File:                        CExternalCmdKeyAttachment.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 CExternalCmdKeyAttachment 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 CExternalCmdKeyAttachment 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. //    CExternalCmdKeyAttachment.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 "CExternalCmdKeyAttachment.h"
  37. #include <LStream.h>
  38.  
  39. //----------------------------------------------------------------------------------------
  40. // CExternalCmdKeyAttachment::CreateFromStream
  41. //----------------------------------------------------------------------------------------
  42. CExternalCmdKeyAttachment* CExternalCmdKeyAttachment::CreateFromStream(LStream    *inStream)
  43. {
  44.     return new CExternalCmdKeyAttachment(inStream);
  45. }
  46.  
  47. //----------------------------------------------------------------------------------------
  48. // CExternalCmdKeyAttachment::CExternalCmdKeyAttachment
  49. //----------------------------------------------------------------------------------------
  50. CExternalCmdKeyAttachment::CExternalCmdKeyAttachment()
  51.     : mCommandKeyLocation(position_Right)
  52. {
  53.     mCommandKeyOffset.h = mCommandKeyOffset.v = 0;
  54. }
  55.  
  56. //----------------------------------------------------------------------------------------
  57. // CExternalCmdKeyAttachment::CExternalCmdKeyAttachment
  58. //----------------------------------------------------------------------------------------
  59. CExternalCmdKeyAttachment::CExternalCmdKeyAttachment(LStream *inStream)
  60.     : CCmdKeyAttachment(inStream)
  61. {
  62.     inStream->ReadData(&mCommandKeyLocation, sizeof(Int16));
  63.     inStream->ReadData(&mCommandKeyOffset, sizeof(Point));
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // CExternalCmdKeyAttachment::~CExternalCmdKeyAttachment
  68. //----------------------------------------------------------------------------------------
  69. CExternalCmdKeyAttachment::~CExternalCmdKeyAttachment()
  70. {
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // CExternalCmdKeyAttachment::EnableCommandKey
  75. //----------------------------------------------------------------------------------------
  76. // All this finction has to do is to draw the command key. We don't do any checking of
  77. // if the command key is already down because since we draw outside of the controls 
  78. // frame, we won't update correctly if the control's frame is not invalidated but
  79. // the area we draw in is.
  80. void CExternalCmdKeyAttachment::EnableCommandKey(Boolean inCmdDown)
  81. {
  82.     DrawCommandKey(inCmdDown);
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // CExternalCmdKeyAttachment::GetCommandKeyPosition
  87. //----------------------------------------------------------------------------------------
  88. // This determines where to place the command key based on the location and offset
  89. // the programmer specified.
  90. void CExternalCmdKeyAttachment::GetCommandKeyPosition(Point& outPosition)
  91. {
  92.     Rect                frame;
  93.     mMyControl->CalcLocalFrameRect(frame);
  94.     
  95.     switch ( mCommandKeyLocation )
  96.     {
  97.         case position_Top:
  98.             outPosition.h = frame.left + mCommandKeyOffset.h;
  99.             outPosition.v = frame.top - mCommandKeyOffset.v;
  100.             break;
  101.             
  102.         case position_Left:
  103.             outPosition.h = frame.left - mCommandKeyOffset.h;
  104.             outPosition.v = frame.top + mCommandKeyOffset.v;
  105.             break;
  106.             
  107.         case position_Bottom:
  108.             outPosition.h = frame.left + mCommandKeyOffset.h;
  109.             outPosition.v = frame.bottom + mCommandKeyOffset.v;
  110.             break;
  111.             
  112.         case position_Right:
  113.             // That's right we're falling on through
  114.         default:
  115.             outPosition.h = frame.right + mCommandKeyOffset.h;
  116.             outPosition.v = frame.top + mCommandKeyOffset.v;
  117.     }
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. // CExternalCmdKeyAttachment::DrawCommandKey
  122. //----------------------------------------------------------------------------------------
  123. void CExternalCmdKeyAttachment::DrawCommandKey(Boolean inVisible)
  124. {
  125.     Point                pos;
  126.     char                str[2] = { char_Propeller, mCommandKey };
  127.  
  128.     if ( mMyControl->FocusExposed() )
  129.     {
  130.         StColorPenState    colorPenState;
  131.         StTextState            textState;
  132.         
  133.         ::TextFont(systemFont);
  134.         ::TextSize(12);
  135.         ::TextFace(0);
  136.         
  137.         if ( inVisible == false )
  138.         {
  139.             RGBColor    backColor;
  140.             ::GetBackColor(&backColor);
  141.             ::RGBForeColor(&backColor);
  142.         }
  143.         
  144.         this->GetCommandKeyPosition(pos);
  145.  
  146.         ::MoveTo(pos.h, pos.v);
  147.         ::UpperText(&str[1], 1);
  148.         ::DrawText(str, 0, sizeof(str));
  149.     }
  150. }
  151.  
  152.  
  153.