symbian-qemu-0.9.1-12/python-2.6.1/Mac/Modules/ah/_AHmodule.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 
       
     2 /* =========================== Module _AH =========================== */
       
     3 
       
     4 #include "Python.h"
       
     5 
       
     6 
       
     7 
       
     8 #include "pymactoolbox.h"
       
     9 
       
    10 /* Macro to test whether a weak-loaded CFM function exists */
       
    11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
       
    12         PyErr_SetString(PyExc_NotImplementedError, \
       
    13         "Not available in this shared library/OS version"); \
       
    14         return NULL; \
       
    15     }} while(0)
       
    16 
       
    17 
       
    18 #include <Carbon/Carbon.h>
       
    19 
       
    20 
       
    21 static PyObject *Ah_Error;
       
    22 
       
    23 static PyObject *Ah_AHSearch(PyObject *_self, PyObject *_args)
       
    24 {
       
    25 	PyObject *_res = NULL;
       
    26 	OSStatus _err;
       
    27 	CFStringRef bookname;
       
    28 	CFStringRef query;
       
    29 	if (!PyArg_ParseTuple(_args, "O&O&",
       
    30 	                      CFStringRefObj_Convert, &bookname,
       
    31 	                      CFStringRefObj_Convert, &query))
       
    32 		return NULL;
       
    33 	_err = AHSearch(bookname,
       
    34 	                query);
       
    35 	if (_err != noErr) return PyMac_Error(_err);
       
    36 	Py_INCREF(Py_None);
       
    37 	_res = Py_None;
       
    38 	return _res;
       
    39 }
       
    40 
       
    41 static PyObject *Ah_AHGotoMainTOC(PyObject *_self, PyObject *_args)
       
    42 {
       
    43 	PyObject *_res = NULL;
       
    44 	OSStatus _err;
       
    45 	AHTOCType toctype;
       
    46 	if (!PyArg_ParseTuple(_args, "h",
       
    47 	                      &toctype))
       
    48 		return NULL;
       
    49 	_err = AHGotoMainTOC(toctype);
       
    50 	if (_err != noErr) return PyMac_Error(_err);
       
    51 	Py_INCREF(Py_None);
       
    52 	_res = Py_None;
       
    53 	return _res;
       
    54 }
       
    55 
       
    56 static PyObject *Ah_AHGotoPage(PyObject *_self, PyObject *_args)
       
    57 {
       
    58 	PyObject *_res = NULL;
       
    59 	OSStatus _err;
       
    60 	CFStringRef bookname;
       
    61 	CFStringRef path;
       
    62 	CFStringRef anchor;
       
    63 	if (!PyArg_ParseTuple(_args, "O&O&O&",
       
    64 	                      CFStringRefObj_Convert, &bookname,
       
    65 	                      CFStringRefObj_Convert, &path,
       
    66 	                      CFStringRefObj_Convert, &anchor))
       
    67 		return NULL;
       
    68 	_err = AHGotoPage(bookname,
       
    69 	                  path,
       
    70 	                  anchor);
       
    71 	if (_err != noErr) return PyMac_Error(_err);
       
    72 	Py_INCREF(Py_None);
       
    73 	_res = Py_None;
       
    74 	return _res;
       
    75 }
       
    76 
       
    77 static PyObject *Ah_AHLookupAnchor(PyObject *_self, PyObject *_args)
       
    78 {
       
    79 	PyObject *_res = NULL;
       
    80 	OSStatus _err;
       
    81 	CFStringRef bookname;
       
    82 	CFStringRef anchor;
       
    83 	if (!PyArg_ParseTuple(_args, "O&O&",
       
    84 	                      CFStringRefObj_Convert, &bookname,
       
    85 	                      CFStringRefObj_Convert, &anchor))
       
    86 		return NULL;
       
    87 	_err = AHLookupAnchor(bookname,
       
    88 	                      anchor);
       
    89 	if (_err != noErr) return PyMac_Error(_err);
       
    90 	Py_INCREF(Py_None);
       
    91 	_res = Py_None;
       
    92 	return _res;
       
    93 }
       
    94 
       
    95 static PyObject *Ah_AHRegisterHelpBook(PyObject *_self, PyObject *_args)
       
    96 {
       
    97 	PyObject *_res = NULL;
       
    98 	OSStatus _err;
       
    99 	FSRef appBundleRef;
       
   100 	if (!PyArg_ParseTuple(_args, "O&",
       
   101 	                      PyMac_GetFSRef, &appBundleRef))
       
   102 		return NULL;
       
   103 	_err = AHRegisterHelpBook(&appBundleRef);
       
   104 	if (_err != noErr) return PyMac_Error(_err);
       
   105 	Py_INCREF(Py_None);
       
   106 	_res = Py_None;
       
   107 	return _res;
       
   108 }
       
   109 
       
   110 static PyMethodDef Ah_methods[] = {
       
   111 	{"AHSearch", (PyCFunction)Ah_AHSearch, 1,
       
   112 	 PyDoc_STR("(CFStringRef bookname, CFStringRef query) -> None")},
       
   113 	{"AHGotoMainTOC", (PyCFunction)Ah_AHGotoMainTOC, 1,
       
   114 	 PyDoc_STR("(AHTOCType toctype) -> None")},
       
   115 	{"AHGotoPage", (PyCFunction)Ah_AHGotoPage, 1,
       
   116 	 PyDoc_STR("(CFStringRef bookname, CFStringRef path, CFStringRef anchor) -> None")},
       
   117 	{"AHLookupAnchor", (PyCFunction)Ah_AHLookupAnchor, 1,
       
   118 	 PyDoc_STR("(CFStringRef bookname, CFStringRef anchor) -> None")},
       
   119 	{"AHRegisterHelpBook", (PyCFunction)Ah_AHRegisterHelpBook, 1,
       
   120 	 PyDoc_STR("(FSRef appBundleRef) -> None")},
       
   121 	{NULL, NULL, 0}
       
   122 };
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 void init_AH(void)
       
   128 {
       
   129 	PyObject *m;
       
   130 	PyObject *d;
       
   131 
       
   132 
       
   133 
       
   134 
       
   135 	m = Py_InitModule("_AH", Ah_methods);
       
   136 	d = PyModule_GetDict(m);
       
   137 	Ah_Error = PyMac_GetOSErrException();
       
   138 	if (Ah_Error == NULL ||
       
   139 	    PyDict_SetItemString(d, "Error", Ah_Error) != 0)
       
   140 		return;
       
   141 }
       
   142 
       
   143 /* ========================= End module _AH ========================= */
       
   144