home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / CDimmerCluster / Dimmer srcs / CDimmerCluster.cp < prev    next >
Encoding:
Text File  |  1995-12-01  |  8.8 KB  |  375 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CDimmerCluster.cp
  3.  
  4.     Contains:    Implementation of the dimmer cluster and dimming edittext classes.
  5.  
  6.     Written by:    Sak Wathanasin
  7.                 Network Analysis Ltd
  8.                 178 Wainbody Ave South
  9.                 Coventry CV3 6BX
  10.                 UK
  11.     Phone:        (+44) 1203 419996
  12.     E-mail:        sw@network-analysis-ltd.co.uk
  13.     
  14.     Thanks to:    Donald E. Carlile who contributed the dimmable caption
  15.                 (carlile@beachnet.gen.ca.us)
  16.     
  17.     Copyright:    © 1995 Network Analysis Ltd. All rights reserved.
  18.  
  19.     Change History (most recent first):
  20.  
  21.     <1.1>        01/12/95    dec        Add dimmable captions
  22.     <1.0>        07/08/95    sw        First public release.
  23.  
  24.     To Do:
  25. */
  26.  
  27. #ifndef __CDimmerCluster__
  28. #include "CDimmerCluster.h"
  29. #endif
  30.  
  31. // This implements a (transparent) view that dims its sub-panes
  32. // depending on the setting of a distinguished sub-pane (the "master").
  33. // This is often a checkbox, but any LControl sub-class can be used.
  34. // 
  35. // The idea is to use Constructor for most of the hard-work: the pane ID
  36. // of the master is put into the "user constant" field of the view,
  37. //  and each sub-pane that is to be dimmed has its user constant set to 1.
  38.  
  39. CDimmerCluster::CDimmerCluster()
  40. {
  41.     mController    = nil;
  42. }
  43.  
  44. CDimmerCluster::CDimmerCluster(LStream* inStream)
  45.     : LView(inStream)
  46. {
  47.     mController    = nil;
  48. }
  49.  
  50. CDimmerCluster::CDimmerCluster(const SPaneInfo    &inPaneInfo,
  51.                                const SViewInfo &inViewInfo)
  52.     : LView(inPaneInfo, inViewInfo)
  53. {
  54.     mController    = nil;
  55. }
  56.  
  57. CDimmerCluster::CDimmerCluster(const LView    &inOriginal)
  58.     : LView(inOriginal)
  59. {
  60.     mController    = this->FindController();
  61. }
  62.  
  63.  
  64. CDimmerCluster::~CDimmerCluster()
  65. {
  66. }
  67.  
  68. #pragma segment CDim
  69. CDimmerCluster*
  70. CDimmerCluster::CreateDimmerStream(LStream *inStream)    //Override
  71. {
  72.     return (new CDimmerCluster(inStream));
  73. }
  74.  
  75.  
  76. #pragma segment CDim
  77. void    CDimmerCluster::FinishCreate()    //Override
  78.  
  79. {
  80.     LView::FinishCreate ();                // do the std thing
  81.     // now add ourselves as a listener for the controller
  82.     mController    = this->FindController();
  83.     mController->AddListener(this);
  84. }
  85.  
  86.  
  87. // The controller sub-pane must broadcast a message "cmd_DimGroup" (3000)
  88. // whose ioParm is 0 or 1 depending on whether the control is on or
  89. // off (0 = dim, 1 = don't dim)
  90. #pragma segment CDim
  91. void CDimmerCluster::ListenToMessage(MessageT inMessage, void *ioParam) 
  92. {
  93.     if (inMessage == cmd_DimGroup)
  94.     {
  95.         
  96.         SignalIf_(mController == nil);
  97.         
  98.         // if it is the master controller, then dim/undim the other controls as appr
  99.         LListIterator iterator(mSubPanes, iterate_FromStart);
  100.         LPane    *theSub;
  101.         if (*(long*)ioParam == 0)
  102.         {
  103.             // dim: for all sub-panes we disable if the user flag is set
  104.             while (iterator.Next(&theSub))
  105.             {
  106.                 if (theSub->GetUserCon() == eOn && theSub->IsEnabled())
  107.                 {
  108.                     theSub->SetUserCon(eWasDimmed);
  109.                     theSub->Disable();
  110.                 }
  111.             }
  112.         }
  113.         else
  114.         {
  115.             // undim any controls that were dimmed by us
  116.             while (iterator.Next(&theSub))
  117.             {
  118.                 if (theSub->GetUserCon() == eWasDimmed)
  119.                 {
  120.                     theSub->SetUserCon(eOn);
  121.                     theSub->Enable();
  122.                 }
  123.             }
  124.         }
  125.     }
  126. }
  127.  
  128. #pragma segment CDim
  129. LControl* CDimmerCluster::FindController() 
  130. {
  131.     return (LControl*) FindPaneByID(this->GetUserCon());
  132.     
  133. }
  134.  
  135. // ---------------------------------------------------------------------------
  136. //        • CreateEditFieldStream
  137. // ---------------------------------------------------------------------------
  138. //    Create a new EditField object from the data in a Stream
  139.  
  140. CDimmableEditText*
  141. CDimmableEditText::CreateDimmableEditTextStream(
  142.     LStream    *inStream)
  143. {
  144.     return (new CDimmableEditText(inStream));
  145. }
  146.  
  147.  
  148. // ---------------------------------------------------------------------------
  149. //        • CDimmableEditText
  150. // ---------------------------------------------------------------------------
  151. //    Default Contructor
  152.  
  153. CDimmableEditText::CDimmableEditText()
  154.     :LEditField()
  155. {
  156.     mWasTarget    = false;
  157. }
  158.  
  159.  
  160. // ---------------------------------------------------------------------------
  161. //        • CDimmableEditText(CDimmableEditText&)
  162. // ---------------------------------------------------------------------------
  163. //    Copy Contructor
  164.  
  165. CDimmableEditText::CDimmableEditText(
  166.     const CDimmableEditText    &inOriginal)
  167.         : LEditField(inOriginal)
  168. {
  169.     mWasTarget    = false;
  170. }
  171.  
  172.  
  173. // ---------------------------------------------------------------------------
  174. //        • CDimmableEditText
  175. // ---------------------------------------------------------------------------
  176. //    Contruct from input parameters
  177.  
  178. CDimmableEditText::CDimmableEditText(
  179.     const SPaneInfo    &inPaneInfo,
  180.     Str255            inString,
  181.     ResIDT            inTextTraitsID,
  182.     Int16            inMaxChars,
  183.     Boolean            inHasBox,
  184.     Boolean            inHasWordWrap,
  185.     KeyFilterFunc    inKeyFilter,
  186.     LCommander        *inSuper)
  187.         : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inHasBox, inHasWordWrap, inKeyFilter, inSuper)
  188. {
  189.     mWasTarget    = false;
  190. }
  191.  
  192.  
  193. CDimmableEditText::CDimmableEditText(
  194.     const SPaneInfo    &inPaneInfo,
  195.     Str255            inString,
  196.     ResIDT            inTextTraitsID,
  197.     Int16            inMaxChars,
  198.     Uint8            inAttributes,
  199.     KeyFilterFunc    inKeyFilter,
  200.     LCommander        *inSuper)
  201.         : LEditField(inPaneInfo, inString, inTextTraitsID, inMaxChars, inAttributes, inKeyFilter, inSuper)
  202. {
  203.     mWasTarget    = false;
  204. }
  205.  
  206.  
  207. // ---------------------------------------------------------------------------
  208. //        • CDimmableEditText(LStream*)
  209. // ---------------------------------------------------------------------------
  210. //    Contruct an EditField from the data in a Stream
  211.  
  212. CDimmableEditText::CDimmableEditText(
  213.     LStream    *inStream)
  214.         : LEditField(inStream)
  215. {
  216.     mWasTarget    = false;
  217. }
  218.  
  219. void
  220. CDimmableEditText::DisableSelf()
  221. {
  222.     TEHandle    aTEH    = GetMacTEH();
  223.     
  224.     // checking for systems without grayishTextOr
  225.     // left as an exercise for the reader, but I don't
  226.     // think PP runs on systems that don't have grayishTextOr...
  227.     (*aTEH)->txMode        = grayishTextOr;
  228.     mWasTarget = this->IsTarget();
  229.     if (mWasTarget)
  230.     {
  231.         this->SwitchTarget(nil);
  232.     }
  233.     this->Disable();
  234.     this->Refresh();    // do the std thing
  235. }
  236.  
  237. void
  238. CDimmableEditText::EnableSelf()
  239. {
  240.     TEHandle    aTEH    = GetMacTEH();
  241.     
  242.     (*aTEH)->txMode        = mTxMode;
  243.     this->Enable();
  244.     if (this->WasTarget())
  245.     {
  246.         this->SwitchTarget(this);
  247.     }
  248.     this->Refresh();    // do the std thing
  249. }
  250.  
  251. void
  252. CDimmableEditText::FinishCreate()    //Override
  253. {
  254.     TEHandle    aTEH    = GetMacTEH();
  255.     mTxMode    = (*aTEH)->txMode;
  256. }
  257.  
  258. //CDimCaption.cp
  259. //Donald E. Carlile 1995
  260. //I hestitate to copyright, because a lot of this is Powerplant modified slightly
  261.  
  262. // ---------------------------------------------------------------------------
  263. //        Ä CreateCaptionStream
  264. // ---------------------------------------------------------------------------
  265. //    Create a new Caption object from the data in a Stream
  266.  
  267. CDimCaption*
  268. CDimCaption::CreateDimCaptionStream(
  269.     LStream    *inStream)
  270. {
  271.     return (new CDimCaption(inStream));
  272. }
  273.  
  274.  
  275. // ---------------------------------------------------------------------------
  276. //        Ä CDimCaption
  277. // ---------------------------------------------------------------------------
  278. //    Default Constructor
  279.  
  280. CDimCaption::CDimCaption()
  281.     :LCaption()
  282. {
  283.     Int32 myIntensity = 34952;
  284.     mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
  285. }
  286.  
  287.  
  288. // ---------------------------------------------------------------------------
  289. //        Ä CDimCaption(const LCaption&)
  290. // ---------------------------------------------------------------------------
  291. //    Copy Constructor
  292.  
  293. CDimCaption::CDimCaption(
  294.     const CDimCaption    &inOriginal)
  295.         : LCaption(inOriginal)
  296. {
  297.     mText = inOriginal.mText;
  298.     mTxtrID = inOriginal.mTxtrID;
  299.     Int32 myIntensity = 34952;
  300.     mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
  301. }
  302.  
  303.  
  304. // ---------------------------------------------------------------------------
  305. //        Ä CDimCaption(SPaneInfo&, Str255, ResIDT)
  306. // ---------------------------------------------------------------------------
  307. //    Construct from parameters. Use this constructor to create a Caption
  308. //    from runtime data.
  309.  
  310. CDimCaption::CDimCaption(
  311.     const SPaneInfo    &inPaneInfo,
  312.     ConstStringPtr    inString,
  313.     ResIDT            inTextTraitsID)
  314.         : LCaption(inPaneInfo, inString,inTextTraitsID)
  315. {
  316.     Int32 myIntensity = 34952;
  317.     mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
  318. }    
  319.  
  320.  
  321. // ---------------------------------------------------------------------------
  322. //        Ä CDimCaption(LStream*)
  323. // ---------------------------------------------------------------------------
  324. //    Construct from data in a Stream
  325.  
  326. CDimCaption::CDimCaption(
  327.     LStream    *inStream)
  328.         : LCaption(inStream)
  329. {
  330.     Int32 myIntensity = 34952;
  331.     mDimColor.red = mDimColor.green = mDimColor.blue = myIntensity;
  332. }
  333.  
  334.  
  335. // ---------------------------------------------------------------------------
  336. //        Ä ~CDimCaption
  337. // ---------------------------------------------------------------------------
  338. //    Destructor
  339.  
  340. CDimCaption::~CDimCaption()
  341. {
  342. }
  343.  
  344. void
  345. CDimCaption::EnableSelf()
  346. {
  347.     DrawSelf();
  348. }
  349.  
  350. void
  351. CDimCaption::DisableSelf()
  352. {
  353.     DrawSelf();
  354. }
  355.  
  356.  
  357. void
  358. CDimCaption::DrawSelf()
  359. {
  360.     Rect    frame;
  361.     CalcLocalFrameRect(frame);
  362.     
  363.     Int16    just = UTextTraits::SetPortTextTraits(mTxtrID);
  364.     
  365.     RGBColor    textColor;
  366.     if (GetUserCon() == eWasDimmed) {
  367.         textColor = mDimColor;
  368.     } else {
  369.         ::GetForeColor(&textColor);
  370.     }
  371.     ApplyForeAndBackColors();
  372.     ::RGBForeColor(&textColor);
  373.     
  374.     UTextDrawing::DrawWithJustification((Ptr)&mText[1], mText[0], frame, just);
  375. }