| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | # Scan <Controls.h>, generating ctlgen.py. | 
| Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 2 | import sys | 
 | 3 | import os | 
 | 4 | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') | 
 | 5 | sys.path.append(BGENDIR) | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 6 |  | 
 | 7 | from scantools import Scanner | 
| Jack Jansen | c574b43 | 1996-04-12 16:26:59 +0000 | [diff] [blame] | 8 | from bgenlocations import TOOLBOXDIR | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 9 |  | 
 | 10 | def main(): | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 11 | #	input = "Controls.h" # Universal Headers < 3.3 | 
 | 12 | 	input = ["Controls.h", "ControlDefinitions.h"] # Universal Headers >= 3.3 | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 13 | 	output = "ctlgen.py" | 
| Jack Jansen | c574b43 | 1996-04-12 16:26:59 +0000 | [diff] [blame] | 14 | 	defsoutput = TOOLBOXDIR + "Controls.py" | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 15 | 	scanner = MyScanner(input, output, defsoutput) | 
 | 16 | 	scanner.scan() | 
 | 17 | 	scanner.close() | 
 | 18 | 	print "=== Done scanning and generating, now doing 'import ctlsupport' ===" | 
 | 19 | 	import ctlsupport | 
 | 20 | 	print "=== Done.  It's up to you to compile Ctlmodule.c ===" | 
 | 21 |  | 
 | 22 | class MyScanner(Scanner): | 
 | 23 |  | 
 | 24 | 	def destination(self, type, name, arglist): | 
 | 25 | 		classname = "Function" | 
 | 26 | 		listname = "functions" | 
 | 27 | 		if arglist: | 
 | 28 | 			t, n, m = arglist[0] | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 29 | 			if t in ("ControlHandle", "ControlRef") and m == "InMode": | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 30 | 				classname = "Method" | 
 | 31 | 				listname = "methods" | 
 | 32 | 		return classname, listname | 
 | 33 |  | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 34 | 	def writeinitialdefs(self): | 
 | 35 | 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") | 
 | 36 | 		self.defsfile.write("from TextEdit import *\n") | 
 | 37 | 		self.defsfile.write("from QuickDraw import *\n") | 
| Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 38 | 		self.defsfile.write("from Dragconst import *\n") | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 39 | 		self.defsfile.write("\n") | 
 | 40 |  | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 41 | 	def makeblacklistnames(self): | 
 | 42 | 		return [ | 
| Jack Jansen | cfb60ee | 1996-10-01 10:46:46 +0000 | [diff] [blame] | 43 | 			'DisposeControl', # Generated manually | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 44 | 			'KillControls', # Implied by close of dialog | 
 | 45 | 			'SetCtlAction', | 
| Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 46 | 			'TrackControl',	# Generated manually | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 47 | 			'HandleControlClick',	# Generated manually | 
 | 48 | 			'SetControlData',	# Generated manually | 
 | 49 | 			'GetControlData',	# Generated manually | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 50 | 			'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition | 
 | 51 | 			'kControlProgressBarIndeterminateTag', # ditto | 
 | 52 | 			# The following are unavailable for static 68k (appearance manager) | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 53 | ##			'GetBevelButtonMenuValue', | 
 | 54 | ##			'SetBevelButtonMenuValue', | 
 | 55 | ##			'GetBevelButtonMenuHandle', | 
 | 56 | ##			'SetBevelButtonTransform', | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 57 | 			'SetBevelButtonGraphicAlignment', | 
 | 58 | 			'SetBevelButtonTextAlignment', | 
 | 59 | 			'SetBevelButtonTextPlacement', | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 60 | ##			'SetImageWellTransform', | 
 | 61 | ##			'GetTabContentRect', | 
 | 62 | ##			'SetTabEnabled', | 
 | 63 | ##			'SetDisclosureTriangleLastValue', | 
| Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 64 | ## 			# Unavailable in CW Pro 3 libraries | 
 | 65 | ## 			'SetUpControlTextColor', | 
 | 66 | ## 			# Unavailable in Jack's CW Pro 5.1 libraries | 
 | 67 | ## 			'GetControlRegion', | 
 | 68 | ## 			'RemoveControlProperty', | 
 | 69 | ## 			'IsValidControlHandle', | 
 | 70 | ## 			'SetControl32BitMinimum', | 
 | 71 | ## 			'GetControl32BitMinimum', | 
 | 72 | ## 			'SetControl32BitMaximum', | 
 | 73 | ## 			'GetControl32BitMaximum', | 
 | 74 | ## 			'SetControl32BitValue', | 
 | 75 | ## 			'GetControl32BitValue', | 
 | 76 | ## 			'SetControlViewSize', | 
 | 77 | ## 			'GetControlViewSize', | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 78 | 			# Generally Bad News | 
 | 79 | 			'GetControlProperty', | 
 | 80 | 			'SetControlProperty', | 
 | 81 | 			'GetControlPropertySize', | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 82 | 			] | 
 | 83 |  | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 84 | 	def makegreylist(self): | 
 | 85 | 		return [ | 
| Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 86 | 			('#if !TARGET_API_MAC_CARBON', [ | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 87 | 				'GetAuxiliaryControlRecord', | 
 | 88 | 				'SetControlColor', | 
| Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 89 | 				# These have suddenly disappeared in UH 3.3.2... | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 90 | ##				'GetBevelButtonMenuValue', | 
 | 91 | ##				'SetBevelButtonMenuValue', | 
 | 92 | ##				'GetBevelButtonMenuHandle', | 
 | 93 | ##				'SetBevelButtonTransform', | 
 | 94 | ##				'SetImageWellTransform', | 
 | 95 | ##				'GetTabContentRect', | 
 | 96 | ##				'SetTabEnabled', | 
 | 97 | ##				'SetDisclosureTriangleLastValue', | 
 | 98 | 			]), | 
 | 99 | 			('#if TARGET_API_MAC_CARBON', [ | 
 | 100 | 				'IsAutomaticControlDragTrackingEnabledForWindow', | 
 | 101 | 				'SetAutomaticControlDragTrackingEnabledForWindow', | 
| Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 102 | 				'HandleControlDragReceive', | 
 | 103 | 				'HandleControlDragTracking', | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 104 | 				'GetControlByID', | 
 | 105 | 				'IsControlDragTrackingEnabled', | 
 | 106 | 				'SetControlDragTrackingEnabled', | 
 | 107 | 				'GetControlPropertyAttributes', | 
 | 108 | 				'ChangeControlPropertyAttributes', | 
 | 109 | 				'GetControlID', | 
 | 110 | 				'SetControlID', | 
 | 111 | 				'HandleControlSetCursor', | 
 | 112 | 				'GetControlClickActivation', | 
 | 113 | 				'HandleControlContextualMenuClick', | 
 | 114 | 			]), | 
 | 115 | 			('#if ACCESSOR_CALLS_ARE_FUNCTIONS', [ | 
 | 116 | 				# XXX These are silly, they should be #defined to access the fields | 
 | 117 | 				# directly. Later... | 
 | 118 | 				'GetControlBounds', | 
 | 119 | 				'IsControlHilited', | 
 | 120 | 				'GetControlHilite', | 
 | 121 | 				'GetControlOwner', | 
 | 122 | 				'GetControlDataHandle', | 
 | 123 | 				'GetControlPopupMenuHandle', | 
 | 124 | 				'GetControlPopupMenuID', | 
 | 125 | 				'SetControlDataHandle', | 
 | 126 | 				'SetControlBounds', | 
 | 127 | 				'SetControlPopupMenuHandle', | 
 | 128 | 				'SetControlPopupMenuID', | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 129 | 			])] | 
 | 130 | 			 | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 131 | 	def makeblacklisttypes(self): | 
 | 132 | 		return [ | 
 | 133 | 			'ProcPtr', | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 134 | 			'ControlActionUPP', | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 135 | 			'ControlButtonContentInfoPtr', | 
 | 136 | 			'Ptr', | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 137 | 			'ControlDefSpec', # Don't know how to do this yet | 
 | 138 | 			'ControlDefSpec_ptr', # ditto | 
 | 139 | 			'Collection', # Ditto | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 140 | 			] | 
 | 141 |  | 
 | 142 | 	def makerepairinstructions(self): | 
 | 143 | 		return [ | 
 | 144 | 			([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], | 
 | 145 | 			 [("InBuffer", "*", "*")]), | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 146 |  | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 147 | 			([("void", "*", "OutMode"), ("long", "*", "InMode"), | 
 | 148 | 			                            ("long", "*", "OutMode")], | 
 | 149 | 			 [("VarVarOutBuffer", "*", "InOutMode")]), | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 150 |  | 
| Jack Jansen | 848250c | 1998-05-28 14:20:09 +0000 | [diff] [blame] | 151 | ##			# For TrackControl | 
 | 152 | ##			([("ProcPtr", "actionProc", "InMode")], | 
 | 153 | ##			 [("FakeType('(ControlActionUPP)0')", "*", "*")]), | 
 | 154 | ##			([("ControlActionUPP", "actionProc", "InMode")], | 
 | 155 | ##			 [("FakeType('(ControlActionUPP)0')", "*", "*")]), | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 156 |  | 
| Jack Jansen | 4100900 | 1999-03-07 20:05:20 +0000 | [diff] [blame] | 157 | 			# For GetControlTitle | 
 | 158 | 			([('Str255', 'title', 'InMode')], | 
 | 159 | 			 [('Str255', 'title', 'OutMode')]), | 
| Jack Jansen | 229c086 | 1999-12-09 16:03:50 +0000 | [diff] [blame] | 160 |  | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 161 | 			([("ControlHandle", "*", "OutMode")], | 
 | 162 | 			 [("ExistingControlHandle", "*", "*")]), | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 163 | 			([("ControlRef", "*", "OutMode")],	# Ditto, for Universal Headers | 
 | 164 | 			 [("ExistingControlHandle", "*", "*")]), | 
| Jack Jansen | a9e3db3 | 2001-01-09 22:10:16 +0000 | [diff] [blame^] | 165 | 			  | 
 | 166 | 			([("Rect_ptr", "*", "ReturnMode")], # GetControlBounds | 
 | 167 | 			 [("void", "*", "ReturnMode")]), | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 168 | 			] | 
 | 169 |  | 
 | 170 | if __name__ == "__main__": | 
 | 171 | 	main() |