| 1 | # Scan an Apple header file, generating a Python file of generator calls.
|
|---|
| 2 | import sys
|
|---|
| 3 | import os
|
|---|
| 4 | from bgenlocations import TOOLBOXDIR, BGENDIR
|
|---|
| 5 | sys.path.append(BGENDIR)
|
|---|
| 6 |
|
|---|
| 7 | from scantools import Scanner
|
|---|
| 8 |
|
|---|
| 9 | def main():
|
|---|
| 10 | input = "MacWindows.h"
|
|---|
| 11 | output = "wingen.py"
|
|---|
| 12 | defsoutput = TOOLBOXDIR + "Windows.py"
|
|---|
| 13 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 14 | scanner.scan()
|
|---|
| 15 | scanner.close()
|
|---|
| 16 | print "=== Testing definitions output code ==="
|
|---|
| 17 | execfile(defsoutput, {}, {})
|
|---|
| 18 | print "=== Done scanning and generating, now importing the generated code... ==="
|
|---|
| 19 | import winsupport
|
|---|
| 20 | print "=== Done. It's up to you to compile it now! ==="
|
|---|
| 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]
|
|---|
| 29 | if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
|
|---|
| 30 | classname = "Method"
|
|---|
| 31 | listname = "methods"
|
|---|
| 32 | return classname, listname
|
|---|
| 33 |
|
|---|
| 34 | def writeinitialdefs(self):
|
|---|
| 35 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
|---|
| 36 | self.defsfile.write("false = 0\n")
|
|---|
| 37 | self.defsfile.write("true = 1\n")
|
|---|
| 38 | self.defsfile.write("kWindowNoConstrainAttribute = 0x80000000\n")
|
|---|
| 39 |
|
|---|
| 40 | def makeblacklistnames(self):
|
|---|
| 41 | return [
|
|---|
| 42 | 'DisposeWindow', # Implied when the object is deleted
|
|---|
| 43 | 'CloseWindow',
|
|---|
| 44 | 'SetWindowProperty', # For the moment
|
|---|
| 45 | 'GetWindowProperty',
|
|---|
| 46 | 'GetWindowPropertySize',
|
|---|
| 47 | 'RemoveWindowProperty',
|
|---|
| 48 | 'MacCloseWindow',
|
|---|
| 49 | 'GetWindowList', # Don't know whether this is safe...
|
|---|
| 50 | # Constants with funny definitions
|
|---|
| 51 | 'kMouseUpOutOfSlop',
|
|---|
| 52 | 'kAllWindowClasses',
|
|---|
| 53 | 'kWindowNoConstrainAttribute',
|
|---|
| 54 | # OS8 only:
|
|---|
| 55 | 'GetAuxWin',
|
|---|
| 56 | 'GetWindowDataHandle',
|
|---|
| 57 | 'SaveOld',
|
|---|
| 58 | 'DrawNew',
|
|---|
| 59 | 'SetWinColor',
|
|---|
| 60 | 'SetDeskCPat',
|
|---|
| 61 | 'InitWindows',
|
|---|
| 62 | 'InitFloatingWindows',
|
|---|
| 63 | 'GetWMgrPort',
|
|---|
| 64 | 'GetCWMgrPort',
|
|---|
| 65 | 'ValidRgn', # Use versions with Window in their name
|
|---|
| 66 | 'ValidRect',
|
|---|
| 67 | 'InvalRgn',
|
|---|
| 68 | 'InvalRect',
|
|---|
| 69 | 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
|
|---|
| 70 | 'GetWindowZoomFlag', # Not available in Carbon
|
|---|
| 71 | 'GetWindowTitleWidth', # Ditto
|
|---|
| 72 | 'GetWindowGoAwayFlag',
|
|---|
| 73 | 'GetWindowSpareFlag',
|
|---|
| 74 | ]
|
|---|
| 75 |
|
|---|
| 76 | def makeblacklisttypes(self):
|
|---|
| 77 | return [
|
|---|
| 78 | 'ProcPtr',
|
|---|
| 79 | 'DragGrayRgnUPP',
|
|---|
| 80 | 'WindowPaintUPP',
|
|---|
| 81 | 'Collection', # For now, to be done later
|
|---|
| 82 | 'WindowDefSpec', # Too difficult for now
|
|---|
| 83 | 'WindowDefSpec_ptr',
|
|---|
| 84 | 'EventRef', #TBD
|
|---|
| 85 | ]
|
|---|
| 86 |
|
|---|
| 87 | def makerepairinstructions(self):
|
|---|
| 88 | return [
|
|---|
| 89 |
|
|---|
| 90 | # GetWTitle
|
|---|
| 91 | ([("Str255", "*", "InMode")],
|
|---|
| 92 | [("*", "*", "OutMode")]),
|
|---|
| 93 |
|
|---|
| 94 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
|
|---|
| 95 | [("InBuffer", "*", "*")]),
|
|---|
| 96 |
|
|---|
| 97 | ([("void", "*", "OutMode"), ("long", "*", "InMode"),
|
|---|
| 98 | ("long", "*", "OutMode")],
|
|---|
| 99 | [("VarVarOutBuffer", "*", "InOutMode")]),
|
|---|
| 100 |
|
|---|
| 101 | ([("void", "wStorage", "OutMode")],
|
|---|
| 102 | [("NullStorage", "*", "InMode")]),
|
|---|
| 103 |
|
|---|
| 104 | # match FindWindowOfClass
|
|---|
| 105 | ([("WindowRef", "outWindow", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")],
|
|---|
| 106 | [("ExistingWindowPtr", "*", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")]),
|
|---|
| 107 | # then match CreateNewWindow and CreateWindowFromResource
|
|---|
| 108 | ([("WindowRef", "outWindow", "OutMode")],
|
|---|
| 109 | [("WindowRef", "*", "*")]),
|
|---|
| 110 |
|
|---|
| 111 | ([("WindowPtr", "*", "OutMode")],
|
|---|
| 112 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 113 | ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
|
|---|
| 114 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 115 |
|
|---|
| 116 | ([("WindowPtr", "FrontWindow", "ReturnMode")],
|
|---|
| 117 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 118 | ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
|
|---|
| 119 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 120 | ([("WindowPtr", "FrontNonFloatingWindow", "ReturnMode")],
|
|---|
| 121 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 122 | ([("WindowRef", "FrontNonFloatingWindow", "ReturnMode")], # Ditto
|
|---|
| 123 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 124 |
|
|---|
| 125 | ([("Rect_ptr", "*", "ReturnMode")], # GetWindowXXXState accessors
|
|---|
| 126 | [("void", "*", "ReturnMode")]),
|
|---|
| 127 | ]
|
|---|
| 128 |
|
|---|
| 129 | if __name__ == "__main__":
|
|---|
| 130 | main()
|
|---|