home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / Colors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  2.8 KB  |  117 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        Colors.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for the application.        */
  28.  
  29. #ifndef __PICKER__
  30. #include <Picker.h>
  31. #endif
  32.  
  33. #ifndef __TREEOBJ2__
  34. #include "TreeObj2.h"
  35. #endif
  36.  
  37. extern RGBColor    gBorderColor, gContentColor;
  38.  
  39.  
  40.  
  41. /*****************************************************************************/
  42. /*****************************************************************************/
  43.  
  44.  
  45.  
  46. #pragma segment Color
  47. OSErr    ChangeColor(FileRecHndl frHndl, WindowPtr window, short part)
  48. {
  49. #ifndef __MWERKS__
  50. #pragma unused (window)
  51. #endif
  52.  
  53.     short            i;
  54.     TreeObjHndl        root, cobj;
  55.     RGBColor        rgb, rgb2;
  56.     Boolean            gotColor;
  57.     static Point    minus1Org = {-1, -1};
  58.  
  59.     rgb = (part == kBorderColor) ? gBorderColor : gContentColor;
  60.     gotColor = false;
  61.  
  62.     root = (*frHndl)->d.doc.root;
  63.     for (i = (*root)->numChildren; i;) {
  64.         cobj = GetChildHndl(root, --i);
  65.         if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  66.             if ((*cobj)->type < GROUPOBJ) {
  67.                 rgb2 = (part == kBorderColor) ? mDerefCommon(cobj)->borderColor :
  68.                                                 mDerefCommon(cobj)->contentColor;
  69.                 if (!gotColor) {
  70.                     gotColor = true;
  71.                     rgb = rgb2;
  72.                     continue;
  73.                 }
  74.                 if (
  75.                     (rgb.red   != rgb2.red)   ||
  76.                     (rgb.green != rgb2.green) ||
  77.                     (rgb.blue  != rgb2.blue)
  78.                 ) {
  79.                     switch (part) {
  80.                         case kBorderColor:
  81.                             rgb.red = rgb.green = rgb.blue = 0;
  82.                             break;
  83.                         case kContentColor:
  84.                             rgb.red = rgb.green = rgb.blue = 0xFFFF;
  85.                             break;
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91.  
  92.     if (GetColor(minus1Org, "\p", &rgb, &rgb2)) {
  93.         if (part == kBorderColor)
  94.             gBorderColor = rgb2;
  95.         else
  96.             gContentColor = rgb2;
  97.         for (i = (*root)->numChildren; i;) {
  98.             cobj = GetChildHndl(root, --i);
  99.             if (DoTreeObjMethod(cobj, GETSELECTMESSAGE, 0)) {
  100.                 if ((*cobj)->type < GROUPOBJ) {
  101.                     if (ModifyChild(COLORCHANGE_EDIT, root, i, false)) return(memFullErr);
  102.                     if (part == kBorderColor)
  103.                         mDerefCommon(cobj)->borderColor = rgb2;
  104.                     else
  105.                         mDerefCommon(cobj)->contentColor = rgb2;
  106.                 }
  107.             }
  108.         }
  109.         DoImageDocument(frHndl);
  110.     }
  111.  
  112.     return(noErr);
  113. }
  114.  
  115.  
  116.  
  117.