home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / ConversionScripts / ColorConversion.tops < prev    next >
Encoding:
Text File  |  1996-08-30  |  13.5 KB  |  331 lines

  1. /*********** ColorConversion: color declarations ***********/
  2.  
  3. replace "NXColor *<var>" with "NSColor *<var>"
  4.     
  5. replace "(NXColor *)" with "(NSColor *)"
  6.  
  7. replace "(const NXColor *)" with "(NSColor *)"
  8.  
  9. replace "NXColor" with "NSColor *"
  10.  
  11. /*********** ColorConversion: files ***********/
  12.  
  13. replace "\"color.h\"" with "\"NSColor.h\""
  14.  
  15. replace "<AppKit/color.h>" with "<AppKit/NSColor.h>"
  16.  
  17. /*********** ColorConversion: #defines ***********/
  18.  
  19. replace "<old>" with "<new>"
  20.     where ("<old>", "<new>") isOneOf {
  21.      ("NX_COLORBLACK", "[NSColor blackColor]"),
  22.      ("NX_COLORWHITE", "[NSColor whiteColor]"),
  23.      ("NX_COLORGRAY", "[NSColor grayColor]"),
  24.      ("NX_COLORLTGRAY", "[NSColor lightGrayColor]"),
  25.      ("NX_COLORDKGRAY", "[NSColor darkGrayColor]"),
  26.      ("NX_COLORRED", "[NSColor redColor]"),
  27.      ("NX_COLORGREEN", "[NSColor greenColor]"),
  28.      ("NX_COLORBLUE", "[NSColor blueColor]"),
  29.      ("NX_COLORCYAN", "[NSColor cyanColor]"),
  30.      ("NX_COLORYELLOW", "[NSColor yellowColor]"),
  31.      ("NX_COLORMAGENTA", "[NSColor magentaColor]"),
  32.      ("NX_COLORORANGE", "[NSColor orangeColor]"),
  33.      ("NX_COLORPURPLE", "[NSColor purpleColor]"),
  34.      ("NX_COLORBROWN", "[NSColor brownColor]"),
  35.      ("NX_COLORCLEAR", "[NSColor clearColor]"),
  36.     }
  37.     
  38. replace "NX_NOALPHA" with "1.0"
  39.     warning "ColorConversion: Was NX_NOALPHA."
  40.  
  41. /*********** ColorConversion: conversion functions ***********/
  42.  
  43. replace "NXConvertRGBToColor (<a>, <b>, <c>)" with "[NSColor colorWithCalibratedRed:<a> green:<b> blue:<c> alpha:1.0]"
  44.  
  45. replace "NXConvertRGBAToColor (<a>, <b>, <c>, <alpha>)" with "[NSColor colorWithCalibratedRed:<a> green:<b> blue:<c> alpha:1.0]"
  46.     where ("<alpha>") isOneOf {
  47.     ("-1"),
  48.     ("-1."),
  49.     ("-1.0")
  50.     }
  51.  
  52. replace "NXConvertRGBAToColor (<a>, <b>, <c>, <d>)" with "[NSColor colorWithCalibratedRed:<a> green:<b> blue:<c> alpha:<d>]"
  53.  
  54. replace "NXConvertHSBToColor (<a>, <b>, <c>)" with "[NSColor colorWithCalibratedHue:<a> saturation:<b> brightness:<c> alpha:1.0]"
  55.  
  56. replace "NXConvertHSBAToColor (<a>, <b>, <c>, <alpha>)" with "[NSColor colorWithCalibratedHue:<a> saturation:<b> brightness:<c> alpha:1.0]"
  57.     where ("<alpha>") isOneOf {
  58.     ("-1"),
  59.     ("-1."),
  60.     ("-1.0")
  61.     }
  62.  
  63. replace "NXConvertHSBAToColor (<a>, <b>, <c>, <d>)" with "[NSColor colorWithCalibratedHue:<a> saturation:<b> brightness:<c> alpha:<d>]"
  64.  
  65. replace "NXConvertCMYKToColor (<a>, <b>, <c>, <d>)" with "[NSColor colorWithDeviceCyan:<a> magenta:<b> yellow:<c> black:<d> alpha:1.0]"
  66.  
  67. replace "NXConvertCMYKAToColor (<a>, <b>, <c>, <d>, <e>)" with "[NSColor colorWithDeviceCyan:<a> magenta:<b> yellow:<c> black:<d> alpha:<e>]"
  68.  
  69. replace "NXConvertGrayToColor (<a>)" with "[NSColor colorWithCalibratedWhite:<a> alpha:1.0]"
  70.  
  71. replace "NXConvertGrayAlphaToColor (<a>, <alpha>)" with "[NSColor colorWithCalibratedWhite:<a> alpha:1.0]"
  72.     where ("<alpha>") isOneOf {
  73.     ("-1"),
  74.     ("-1."),
  75.     ("-1.0")
  76.     }
  77.  
  78. replace "NXConvertGrayAlphaToColor (<a>, <b>)" with "[NSColor colorWithCalibratedWhite:<a> alpha:<b>]"
  79.  
  80. replace "NXConvertColorToRGB (<color>, <a>, <b>, <c>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:<a> green:<b> blue:<c> alpha:NULL]"
  81.  
  82. replace "NXConvertColorToRGBA (<color>, <a>, <b>, <c>, <d>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:<a> green:<b> blue:<c> alpha:<d>]"
  83.  
  84. replace "NXConvertColorToHSB (<color>, <a>, <b>, <c>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getHue:<a> saturation:<b> brightness:<c> alpha:NULL]"
  85.  
  86. replace "NXConvertColorToHSBA (<color>, <a>, <b>, <c>, <d>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getHue:<a> saturation:<b> brightness:<c> alpha:<d>]"
  87.  
  88. replace "NXConvertColorToCMYK (<color>, <a>, <b>, <c>, <d>)" with "[[<color> colorUsingColorSpaceName:NSDeviceCMYKColorSpace] getCyan:<a> magenta:<b> yellow:<c> black:<d> alpha:NULL]"
  89.  
  90. replace "NXConvertColorToCMYKA (<color>, <a>, <b>, <c>, <d>, <e>)" with "[[<color> colorUsingColorSpaceName:NSDeviceCMYKColorSpace] getCyan:<a> magenta:<b> yellow:<c> black:<d> alpha:<e>]"
  91.  
  92. replace "NXConvertColorToGray (<color>, <a>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] getWhite:<a> alpha:NULL]"
  93.  
  94. replace "NXConvertColorToGrayAlpha (<color>, <a>, <b>)" with "[[<color> colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] getWhite:<a> alpha:<b>]"
  95.  
  96. /*********** ColorConversion: color component functions ***********/
  97.  
  98. replace "<func>(<c>)" with "[[<c> colorUsingColorSpaceName:<colorSpace>] <method>]"
  99.     where ("<func>", "<colorSpace>", "<method>") isOneOf {
  100.     ("NXGrayComponent", "NSCalibratedWhiteColorSpace", "whiteComponent"),
  101.     ("NXRedComponent", "NSCalibratedRGBColorSpace", "redComponent"),
  102.     ("NXBlueComponent", "NSCalibratedRGBColorSpace", "blueComponent"),
  103.     ("NXGreenComponent", "NSCalibratedRGBColorSpace", "greenComponent"),
  104.     ("NXHueComponent", "NSCalibratedRGBColorSpace", "hueComponent"),
  105.     ("NXSaturationComponent", "NSCalibratedRGBColorSpace", "saturationComponent"),
  106.     ("NXBrightnessComponent", "NSCalibratedRGBColorSpace", "brightnessComponent"),
  107.     ("NXCyanComponent", "NSDeviceCMYKColorSpace", "cyanComponent"),
  108.     ("NXYellowComponent", "NSDeviceCMYKColorSpace", "yellowComponent"),
  109.     ("NXMagentaComponent", "NSDeviceCMYKColorSpace", "magentaComponent"),
  110.     ("NXBlackComponent", "NSDeviceCMYKColorSpace", "blackComponent")
  111.     ("NXColorListName", "NSNamedColorSpace", "catalogNameComponent"),
  112.     ("NXColorName", "NSNamedColorSpace", "colorNameComponent")
  113.     }
  114.  
  115. replace "NXAlphaComponent (<a>)" with "[<a> alphaComponent]"
  116.  
  117. replace "NXChangeAlphaComponent(<c>,<arg>)" with "[<c> colorWithAlphaComponent:<arg>]"
  118.  
  119. replace "<func>(<c>,<arg>)" with "[<c> <method>:<arg>]"
  120.     error "ColorConversion: [<c> <method>:<arg>] (used to be <func>(<c>,<arg>)) is not in the API. Rewrite this code, or implement a category on NSColor to support this method."
  121.     where ("<func>", "<method>") isOneOf {
  122.     ("NXChangeRedComponent", "colorWithRedComponent"),
  123.     ("NXChangeBlueComponent", "colorWithBlueComponent"),
  124.     ("NXChangeGreenComponent", "colorWithGreenComponent"),
  125.     ("NXChangeGrayComponent", "colorWithWhiteComponent"),
  126.     ("NXChangeHueComponent", "colorWithHueComponent"),
  127.     ("NXChangeSaturationComponent", "colorWithSaturationComponent"),
  128.     ("NXChangeBrightnessComponent", "colorWithBrightnessComponent"),
  129.     ("NXChangeCyanComponent", "colorWithCyanComponent"),
  130.     ("NXChangeYellowComponent", "colorWithYellowComponent"),
  131.     ("NXChangeMagentaComponent", "colorWithMagentaComponent"),
  132.     ("NXChangeBlackComponent", "colorWithBlackComponent"),
  133.     }
  134.  
  135. /*********** ColorConversion: color pasteboard functions ***********/
  136.  
  137. replace "NXReadColorFromPasteboard(<pasteboard>)" with "[NSColor colorFromPasteboard:<pasteboard>]"
  138.  
  139. replace "NXWriteColorToPasteboard(<pasteboard>, <color>)" with "[<color> writeToPasteboard:<pasteboard>]"
  140.  
  141. /*********** ColorConversion: other functions ***********/
  142.  
  143. replace "NXEqualColor (<a>, <b>)" with "[<a> isEqual:<b>]"
  144.  
  145. replace "NXSetColor (<a>)" with "[<a> set]"
  146.  
  147. replace "NXFindColorNamed (<list>, <name>, <c>)" with "(<c> = [[NSColorList colorListNamed:<list>] colorWithKey:<name>])"
  148.  
  149. /*********** ColorConversion: color background methods ***********/
  150.  
  151. replace "[<obj> <method>:<minusOne>]" with "[<obj> <replacementMethod>:NO]"
  152.     warning "ColorConversion: [<obj> <replacementMethod>:NO] was [<obj> <method>:<minusOne>]"
  153.     where ("<minusOne>") isOneOf {
  154.     ("-1"),
  155.     ("-1.0")
  156.     }
  157.     where ("<method>", "<replacementMethod>") isOneOf {
  158.     ("setBackgroundGray", "setDrawsBackground"),
  159.     ("setCellBackgroundGray", "setDrawsCellBackground")
  160.     }
  161.  
  162. replace "([<obj> <method>] <comp>)" with "(![<obj> <replacementMethod>])"
  163.     where ("<comp>") isOneOf {
  164.     ("< 0"),
  165.     ("< 0.0"),
  166.     ("== -1"),
  167.     ("== -1.0")
  168.     }
  169.     where ("<method>", "<replacementMethod>") isOneOf {
  170.     ("backgroundGray", "drawsBackground"),
  171.     ("cellBackgroundGray", "drawsCellBackground")
  172.     }
  173.  
  174. replace "[<obj> <method>:<arg>]" with "[<obj> <replacementMethod>:!(<arg>)]"
  175.     where ("<method>", "<replacementMethod>") isOneOf {
  176.       ("setBackgroundTransparent", "setDrawsBackground"),
  177.       ("setCellBackgroundTransparent", "setDrawsCellBackground")
  178.     }
  179.  
  180. replace "[<obj> <method>]" with "(![<obj> <replacementMethod>])"
  181.     where ("<method>", "<replacementMethod>") isOneOf {
  182.       ("isBackgroundTransparent", "drawsBackground"),
  183.       ("isCellBackgroundTransparent", "drawsCellBackground")
  184.     }
  185.  
  186. replace "[<obj> <method>:<arg>]" with "[<obj> <replacementMethod>:[NSColor colorWithCalibratedWhite:<arg> alpha:1.0]]"
  187. where ("<method>", "<replacementMethod>") isOneOf {
  188.     ("setBackgroundGray", "setBackgroundColor"),
  189.     ("setCellBackgroundGray", "setCellBackgroundColor"),
  190.     ("setTitleGray", "setTitleColor"),
  191.     ("setTextGray", "setTextColor")
  192.     ("setForegroundGray", "setForegroundColor")
  193.     ("setPeakGray", "setPeakColor")
  194.     ("setSelGray", "setSelColor")
  195. }
  196.  
  197. replace "[<obj> <method>]" with "[[[<obj> <replacementMethod>] colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] whiteComponent]"
  198.     warning "ColorConversion: Do you really want gray?"
  199.     where ("<method>", "<replacementMethod>") isOneOf {
  200.     ("backgroundGray", "backgroundColor"),
  201.     ("cellBackgroundGray", "cellBackgroundColor"),
  202.     ("titleGray", "titleColor"),
  203.     ("textGray", "textColor")
  204.     ("foregroundGray", "foregroundColor")
  205.     ("peakGray", "peakColor")
  206.     ("selGray", "selColor")
  207.     }
  208.     
  209. /*********** ColorConversion: other methods ***********/
  210.  
  211. replace "[<obj> runGray:<run>]" with "[[[<obj> runColor:<run>] colorUsingColorSpace:NSCalibratedWhiteColorSpace] whiteComponent]"
  212.     warning "ColorConversion: Do you really want gray?"
  213.  
  214. /*********** ColorConversion: cleanup ***********/
  215.  
  216. replace "[NSColor colorWithCalibratedWhite:<gray> alpha:1.0]" with "[NSColor <method>]"
  217.     where ("<gray>", "<method>") isOneOf {
  218.     ("NX_LTGRAY", "lightGrayColor"),
  219.     ("NX_DKGRAY", "darkGrayColor"),
  220.     ("NX_WHITE", "whiteColor"),
  221.     ("NX_BLACK", "blackColor"),
  222.     ("0.666", "lightGrayColor"),
  223.     ("0.667", "lightGrayColor"),
  224.     ("0.333", "darkGrayColor"),
  225.     ("1.0", "whiteColor"),
  226.     ("0.0", "blackColor"),
  227.     ("1", "whiteColor"),
  228.     ("0", "blackColor")
  229.     }
  230.  
  231. replace "<old>" with "<new>"
  232.     where ("<old>", "<new>") isOneOf {
  233.     ("NX_LTGRAY", "NSLightGray"),
  234.     ("NX_DKGRAY", "NSDarkGray"),
  235.     ("NX_WHITE", "NSWhite"),
  236.     ("NX_BLACK", "NSBlack"),
  237.     ("!(YES)", "NO"),
  238.     ("!(NO)", "YES")
  239.     }
  240.  
  241. /*********** ColorConversion: NSColorList  ***********/
  242.  
  243. replace "NXColorList" with "NSColorList"
  244.  
  245. replacemethod "<old>" with "<new>"
  246.     where ("<old>", "<new>") isOneOf {
  247.     ("setColorNamed:<key> color:<color>", "setColor:<color> forKey:<key>"),
  248.     ("removeColorNamed:", "removeColorWithKey:"),
  249.     ("colorNamed:", "colorWithKey:"),
  250.     ("findColorListNamed:", "colorListNamed:")
  251.     }
  252.  
  253. replacemethod "saveTo:" with "writeToFile:"
  254.     warning "ColorConversion: 'writeToFile:' was 'saveTo:' ; conversion should only apply to NSColorList ; 'writeToFile:' returns BOOL rather than raising"
  255.  
  256. /*********** ColorConversion: obsolete NSColorList methods  ***********/
  257.  
  258. replace "[<obj> freeAndRemoveFile]" with "{[<obj> removeFile]; [<obj> release];}"
  259.     
  260. replace "[<obj> colorCount]" with "[[<obj> allKeys] count]"
  261.  
  262. replacemethod "colorCount" with same
  263.     error "ColorConversion: 'colorCount' is obsolete ; use [[<obj> allKeys] count]"
  264.     
  265. replace "[<obj> nameOfColorAt:<loc>]" with "[[<obj> allKeys] objectAtIndex:<loc>]"
  266.  
  267. replacemethod "nameOfColorAt:" with same
  268.     error "ColorConversion: 'nameOfColorAt:' is obsolete ; use [[<obj> allKeys] objectAtIndex:<loc>]"
  269.     
  270. replace "[<obj> localizedNameForColorNamed:<name>]" with "(<name>)"
  271.     warning "ColorConversion: Was localizedNameForColorNamed:"
  272.  
  273. replacemethod "localizedNameForColorNamed:" with same
  274.     error "ColorConversion: 'localizedNameForColorNamed:' is obsolete"
  275.  
  276. replacemethod "generatesNamedColors" with same
  277.     error "ColorConversion: 'generatesNamedColors' is obsolete"
  278.  
  279. replacemethod "deactivateAllWells" with same
  280.     error "ColorConversion: 'deactivateAllWells' is obsolete"
  281.  
  282. /* (The ColorList delegate methods are taken care of in NotificationConversion) */
  283.  
  284. /*********** ColorConversion: obsolete conversion header hacks  ***********/
  285.  
  286. replace "NXReadColor(<coder>)" with "[[<coder> decodeNXColor] retain]" 
  287.     warning "ColorConversion: [[<coder> decodeNXColor] retain] used to be NXReadColor(<coder>).  Use 'decodeNXColor' to read old style colors, but use 'decodeObject' to read OpenStep colors."
  288.  
  289. replace "NXWriteColor(<coder>, <color>)" with "[<coder> encodeObject:<color>]" 
  290.  
  291. /*********** ColorConversion: methods now obsolete  ***********/
  292.  
  293. replacemethod "<sel>" with same
  294.     error "ColorConversion: <sel> is obsolete. Use the NSColor class"
  295.     where "<sel>" isOneOf {
  296.     "setSelGray:"
  297.     "setBackroundGray:"
  298.     }
  299.  
  300. /*********** ColorConversion: window depth  ***********/
  301.  
  302. replace "NX_TwoBitGrayDepth" with "NSBestDepth(NSCalibratedWhiteColorSpace, 2, 2, YES, NULL)"
  303.  
  304. replace "NX_EightBitGrayDepth" with "NSBestDepth(NSCalibratedWhiteColorSpace, 8, 8, YES, NULL)"
  305.  
  306. replace "NX_EightBitRGBDepth" with "NSBestDepth(NSCalibratedRGBColorSpace, 8, 8, YES, NULL)"
  307.  
  308. replace "NX_TwelveBitRGBDepth" with "NSBestDepth(NSCalibratedRGBColorSpace, 4, 12, NO, NULL)"
  309.  
  310. replace "NX_TwentyFourBitRGBDepth" with "NSBestDepth(NSCalibratedRGBColorSpace, 8, 24, NO, NULL)"
  311.  
  312. replace "NX_DefaultDepth" with "0"
  313.  
  314. replace "f = NXGetBestDepth(<depth>, <n>, <bps>)" with "*<depth> = NSBestDepth(((<n>==1) ? NSCalibratedWhiteColorSpace : ((<n>==4) ? NSDeviceCMYKColorSpace : NSCalibratedRGBColorSpace )), <bps>, 0, YES, &<f>)"
  315.  
  316. replace "*&" with ""
  317.  
  318. replace "&*" with ""
  319.  
  320. /*********** ColorConversion: color spaces ***********/
  321.  
  322. replace "NX_CustomColorSpace" with "NSCustomColorSpace"
  323.  
  324. replace "NX_OneIsBlackColorSpace" with "NSCalibratedBlackColorSpace"
  325.  
  326. replace "NX_OneIsWhiteColorSpace" with "NSCalibratedWhiteColorSpace"
  327.  
  328. replace "NX_RGBColorSpace"  with "NSCalibratedRGBColorSpace"        
  329.  
  330. replace "NX_CMYKColorSpace" with "NSDeviceCMYKColorSpace"
  331.