|
| 1 | + |
| 2 | +/* ========================== Module Help =========================== */ |
| 3 | + |
| 4 | +#include "Python.h" |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +#define SystemSevenOrLater 1 |
| 9 | + |
| 10 | +#include "macglue.h" |
| 11 | +#include <Memory.h> |
| 12 | +#include <Dialogs.h> |
| 13 | +#include <Menus.h> |
| 14 | +#include <Controls.h> |
| 15 | + |
| 16 | +extern PyObject *ResObj_New(Handle); |
| 17 | +extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | +extern PyObject *OptResObj_New(Handle); |
| 19 | +extern int OptResObj_Convert(PyObject *, Handle *); |
| 20 | + |
| 21 | +extern PyObject *WinObj_New(WindowPtr); |
| 22 | +extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 23 | +extern PyTypeObject Window_Type; |
| 24 | +#define WinObj_Check(x) ((x)->ob_type == &Window_Type) |
| 25 | + |
| 26 | +extern PyObject *DlgObj_New(DialogPtr); |
| 27 | +extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 28 | +extern PyTypeObject Dialog_Type; |
| 29 | +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 30 | + |
| 31 | +extern PyObject *MenuObj_New(MenuHandle); |
| 32 | +extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 33 | + |
| 34 | +extern PyObject *CtlObj_New(ControlHandle); |
| 35 | +extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 36 | + |
| 37 | +extern PyObject *GrafObj_New(GrafPtr); |
| 38 | +extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 39 | + |
| 40 | +extern PyObject *BMObj_New(BitMapPtr); |
| 41 | +extern int BMObj_Convert(PyObject *, BitMapPtr *); |
| 42 | + |
| 43 | +extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 44 | + |
| 45 | +#include <Balloons.h> |
| 46 | + |
| 47 | +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 48 | + |
| 49 | +static PyObject *Help_Error; |
| 50 | + |
| 51 | +static PyObject *Help_HMGetHelpMenuHandle(_self, _args) |
| 52 | + PyObject *_self; |
| 53 | + PyObject *_args; |
| 54 | +{ |
| 55 | + PyObject *_res = NULL; |
| 56 | + OSErr _err; |
| 57 | + MenuRef mh; |
| 58 | + if (!PyArg_ParseTuple(_args, "")) |
| 59 | + return NULL; |
| 60 | + _err = HMGetHelpMenuHandle(&mh); |
| 61 | + if (_err != noErr) return PyMac_Error(_err); |
| 62 | + _res = Py_BuildValue("O&", |
| 63 | + ResObj_New, mh); |
| 64 | + return _res; |
| 65 | +} |
| 66 | + |
| 67 | +static PyObject *Help_HMRemoveBalloon(_self, _args) |
| 68 | + PyObject *_self; |
| 69 | + PyObject *_args; |
| 70 | +{ |
| 71 | + PyObject *_res = NULL; |
| 72 | + OSErr _err; |
| 73 | + if (!PyArg_ParseTuple(_args, "")) |
| 74 | + return NULL; |
| 75 | + _err = HMRemoveBalloon(); |
| 76 | + if (_err != noErr) return PyMac_Error(_err); |
| 77 | + Py_INCREF(Py_None); |
| 78 | + _res = Py_None; |
| 79 | + return _res; |
| 80 | +} |
| 81 | + |
| 82 | +static PyObject *Help_HMGetBalloons(_self, _args) |
| 83 | + PyObject *_self; |
| 84 | + PyObject *_args; |
| 85 | +{ |
| 86 | + PyObject *_res = NULL; |
| 87 | + Boolean _rv; |
| 88 | + if (!PyArg_ParseTuple(_args, "")) |
| 89 | + return NULL; |
| 90 | + _rv = HMGetBalloons(); |
| 91 | + _res = Py_BuildValue("b", |
| 92 | + _rv); |
| 93 | + return _res; |
| 94 | +} |
| 95 | + |
| 96 | +static PyObject *Help_HMSetBalloons(_self, _args) |
| 97 | + PyObject *_self; |
| 98 | + PyObject *_args; |
| 99 | +{ |
| 100 | + PyObject *_res = NULL; |
| 101 | + OSErr _err; |
| 102 | + Boolean flag; |
| 103 | + if (!PyArg_ParseTuple(_args, "b", |
| 104 | + &flag)) |
| 105 | + return NULL; |
| 106 | + _err = HMSetBalloons(flag); |
| 107 | + if (_err != noErr) return PyMac_Error(_err); |
| 108 | + Py_INCREF(Py_None); |
| 109 | + _res = Py_None; |
| 110 | + return _res; |
| 111 | +} |
| 112 | + |
| 113 | +static PyObject *Help_HMIsBalloon(_self, _args) |
| 114 | + PyObject *_self; |
| 115 | + PyObject *_args; |
| 116 | +{ |
| 117 | + PyObject *_res = NULL; |
| 118 | + Boolean _rv; |
| 119 | + if (!PyArg_ParseTuple(_args, "")) |
| 120 | + return NULL; |
| 121 | + _rv = HMIsBalloon(); |
| 122 | + _res = Py_BuildValue("b", |
| 123 | + _rv); |
| 124 | + return _res; |
| 125 | +} |
| 126 | + |
| 127 | +static PyObject *Help_HMSetFont(_self, _args) |
| 128 | + PyObject *_self; |
| 129 | + PyObject *_args; |
| 130 | +{ |
| 131 | + PyObject *_res = NULL; |
| 132 | + OSErr _err; |
| 133 | + SInt16 font; |
| 134 | + if (!PyArg_ParseTuple(_args, "h", |
| 135 | + &font)) |
| 136 | + return NULL; |
| 137 | + _err = HMSetFont(font); |
| 138 | + if (_err != noErr) return PyMac_Error(_err); |
| 139 | + Py_INCREF(Py_None); |
| 140 | + _res = Py_None; |
| 141 | + return _res; |
| 142 | +} |
| 143 | + |
| 144 | +static PyObject *Help_HMSetFontSize(_self, _args) |
| 145 | + PyObject *_self; |
| 146 | + PyObject *_args; |
| 147 | +{ |
| 148 | + PyObject *_res = NULL; |
| 149 | + OSErr _err; |
| 150 | + UInt16 fontSize; |
| 151 | + if (!PyArg_ParseTuple(_args, "h", |
| 152 | + &fontSize)) |
| 153 | + return NULL; |
| 154 | + _err = HMSetFontSize(fontSize); |
| 155 | + if (_err != noErr) return PyMac_Error(_err); |
| 156 | + Py_INCREF(Py_None); |
| 157 | + _res = Py_None; |
| 158 | + return _res; |
| 159 | +} |
| 160 | + |
| 161 | +static PyObject *Help_HMGetFont(_self, _args) |
| 162 | + PyObject *_self; |
| 163 | + PyObject *_args; |
| 164 | +{ |
| 165 | + PyObject *_res = NULL; |
| 166 | + OSErr _err; |
| 167 | + SInt16 font; |
| 168 | + if (!PyArg_ParseTuple(_args, "")) |
| 169 | + return NULL; |
| 170 | + _err = HMGetFont(&font); |
| 171 | + if (_err != noErr) return PyMac_Error(_err); |
| 172 | + _res = Py_BuildValue("h", |
| 173 | + font); |
| 174 | + return _res; |
| 175 | +} |
| 176 | + |
| 177 | +static PyObject *Help_HMGetFontSize(_self, _args) |
| 178 | + PyObject *_self; |
| 179 | + PyObject *_args; |
| 180 | +{ |
| 181 | + PyObject *_res = NULL; |
| 182 | + OSErr _err; |
| 183 | + UInt16 fontSize; |
| 184 | + if (!PyArg_ParseTuple(_args, "")) |
| 185 | + return NULL; |
| 186 | + _err = HMGetFontSize(&fontSize); |
| 187 | + if (_err != noErr) return PyMac_Error(_err); |
| 188 | + _res = Py_BuildValue("h", |
| 189 | + fontSize); |
| 190 | + return _res; |
| 191 | +} |
| 192 | + |
| 193 | +static PyObject *Help_HMSetDialogResID(_self, _args) |
| 194 | + PyObject *_self; |
| 195 | + PyObject *_args; |
| 196 | +{ |
| 197 | + PyObject *_res = NULL; |
| 198 | + OSErr _err; |
| 199 | + SInt16 resID; |
| 200 | + if (!PyArg_ParseTuple(_args, "h", |
| 201 | + &resID)) |
| 202 | + return NULL; |
| 203 | + _err = HMSetDialogResID(resID); |
| 204 | + if (_err != noErr) return PyMac_Error(_err); |
| 205 | + Py_INCREF(Py_None); |
| 206 | + _res = Py_None; |
| 207 | + return _res; |
| 208 | +} |
| 209 | + |
| 210 | +static PyObject *Help_HMSetMenuResID(_self, _args) |
| 211 | + PyObject *_self; |
| 212 | + PyObject *_args; |
| 213 | +{ |
| 214 | + PyObject *_res = NULL; |
| 215 | + OSErr _err; |
| 216 | + SInt16 menuID; |
| 217 | + SInt16 resID; |
| 218 | + if (!PyArg_ParseTuple(_args, "hh", |
| 219 | + &menuID, |
| 220 | + &resID)) |
| 221 | + return NULL; |
| 222 | + _err = HMSetMenuResID(menuID, |
| 223 | + resID); |
| 224 | + if (_err != noErr) return PyMac_Error(_err); |
| 225 | + Py_INCREF(Py_None); |
| 226 | + _res = Py_None; |
| 227 | + return _res; |
| 228 | +} |
| 229 | + |
| 230 | +static PyObject *Help_HMScanTemplateItems(_self, _args) |
| 231 | + PyObject *_self; |
| 232 | + PyObject *_args; |
| 233 | +{ |
| 234 | + PyObject *_res = NULL; |
| 235 | + OSErr _err; |
| 236 | + SInt16 whichID; |
| 237 | + SInt16 whichResFile; |
| 238 | + ResType whichType; |
| 239 | + if (!PyArg_ParseTuple(_args, "hhO&", |
| 240 | + &whichID, |
| 241 | + &whichResFile, |
| 242 | + PyMac_GetOSType, &whichType)) |
| 243 | + return NULL; |
| 244 | + _err = HMScanTemplateItems(whichID, |
| 245 | + whichResFile, |
| 246 | + whichType); |
| 247 | + if (_err != noErr) return PyMac_Error(_err); |
| 248 | + Py_INCREF(Py_None); |
| 249 | + _res = Py_None; |
| 250 | + return _res; |
| 251 | +} |
| 252 | + |
| 253 | +static PyObject *Help_HMGetDialogResID(_self, _args) |
| 254 | + PyObject *_self; |
| 255 | + PyObject *_args; |
| 256 | +{ |
| 257 | + PyObject *_res = NULL; |
| 258 | + OSErr _err; |
| 259 | + SInt16 resID; |
| 260 | + if (!PyArg_ParseTuple(_args, "")) |
| 261 | + return NULL; |
| 262 | + _err = HMGetDialogResID(&resID); |
| 263 | + if (_err != noErr) return PyMac_Error(_err); |
| 264 | + _res = Py_BuildValue("h", |
| 265 | + resID); |
| 266 | + return _res; |
| 267 | +} |
| 268 | + |
| 269 | +static PyObject *Help_HMGetMenuResID(_self, _args) |
| 270 | + PyObject *_self; |
| 271 | + PyObject *_args; |
| 272 | +{ |
| 273 | + PyObject *_res = NULL; |
| 274 | + OSErr _err; |
| 275 | + SInt16 menuID; |
| 276 | + SInt16 resID; |
| 277 | + if (!PyArg_ParseTuple(_args, "h", |
| 278 | + &menuID)) |
| 279 | + return NULL; |
| 280 | + _err = HMGetMenuResID(menuID, |
| 281 | + &resID); |
| 282 | + if (_err != noErr) return PyMac_Error(_err); |
| 283 | + _res = Py_BuildValue("h", |
| 284 | + resID); |
| 285 | + return _res; |
| 286 | +} |
| 287 | + |
| 288 | +static PyObject *Help_HMGetBalloonWindow(_self, _args) |
| 289 | + PyObject *_self; |
| 290 | + PyObject *_args; |
| 291 | +{ |
| 292 | + PyObject *_res = NULL; |
| 293 | + OSErr _err; |
| 294 | + WindowPtr window; |
| 295 | + if (!PyArg_ParseTuple(_args, "")) |
| 296 | + return NULL; |
| 297 | + _err = HMGetBalloonWindow(&window); |
| 298 | + if (_err != noErr) return PyMac_Error(_err); |
| 299 | + _res = Py_BuildValue("O&", |
| 300 | + WinObj_New, window); |
| 301 | + return _res; |
| 302 | +} |
| 303 | + |
| 304 | +static PyMethodDef Help_methods[] = { |
| 305 | + {"HMGetHelpMenuHandle", (PyCFunction)Help_HMGetHelpMenuHandle, 1, |
| 306 | + "() -> (MenuRef mh)"}, |
| 307 | + {"HMRemoveBalloon", (PyCFunction)Help_HMRemoveBalloon, 1, |
| 308 | + "() -> None"}, |
| 309 | + {"HMGetBalloons", (PyCFunction)Help_HMGetBalloons, 1, |
| 310 | + "() -> (Boolean _rv)"}, |
| 311 | + {"HMSetBalloons", (PyCFunction)Help_HMSetBalloons, 1, |
| 312 | + "(Boolean flag) -> None"}, |
| 313 | + {"HMIsBalloon", (PyCFunction)Help_HMIsBalloon, 1, |
| 314 | + "() -> (Boolean _rv)"}, |
| 315 | + {"HMSetFont", (PyCFunction)Help_HMSetFont, 1, |
| 316 | + "(SInt16 font) -> None"}, |
| 317 | + {"HMSetFontSize", (PyCFunction)Help_HMSetFontSize, 1, |
| 318 | + "(UInt16 fontSize) -> None"}, |
| 319 | + {"HMGetFont", (PyCFunction)Help_HMGetFont, 1, |
| 320 | + "() -> (SInt16 font)"}, |
| 321 | + {"HMGetFontSize", (PyCFunction)Help_HMGetFontSize, 1, |
| 322 | + "() -> (UInt16 fontSize)"}, |
| 323 | + {"HMSetDialogResID", (PyCFunction)Help_HMSetDialogResID, 1, |
| 324 | + "(SInt16 resID) -> None"}, |
| 325 | + {"HMSetMenuResID", (PyCFunction)Help_HMSetMenuResID, 1, |
| 326 | + "(SInt16 menuID, SInt16 resID) -> None"}, |
| 327 | + {"HMScanTemplateItems", (PyCFunction)Help_HMScanTemplateItems, 1, |
| 328 | + "(SInt16 whichID, SInt16 whichResFile, ResType whichType) -> None"}, |
| 329 | + {"HMGetDialogResID", (PyCFunction)Help_HMGetDialogResID, 1, |
| 330 | + "() -> (SInt16 resID)"}, |
| 331 | + {"HMGetMenuResID", (PyCFunction)Help_HMGetMenuResID, 1, |
| 332 | + "(SInt16 menuID) -> (SInt16 resID)"}, |
| 333 | + {"HMGetBalloonWindow", (PyCFunction)Help_HMGetBalloonWindow, 1, |
| 334 | + "() -> (WindowPtr window)"}, |
| 335 | + {NULL, NULL, 0} |
| 336 | +}; |
| 337 | + |
| 338 | + |
| 339 | + |
| 340 | + |
| 341 | +void initHelp() |
| 342 | +{ |
| 343 | + PyObject *m; |
| 344 | + PyObject *d; |
| 345 | + |
| 346 | + |
| 347 | + |
| 348 | + |
| 349 | + m = Py_InitModule("Help", Help_methods); |
| 350 | + d = PyModule_GetDict(m); |
| 351 | + Help_Error = PyMac_GetOSErrException(); |
| 352 | + if (Help_Error == NULL || |
| 353 | + PyDict_SetItemString(d, "Error", Help_Error) != 0) |
| 354 | + Py_FatalError("can't initialize Help.Error"); |
| 355 | +} |
| 356 | + |
| 357 | +/* ======================== End module Help ========================= */ |
| 358 | + |
0 commit comments