Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df901df

Browse files
committed
Added a function SetUserItemHandler: this takes a function(dialog,
item) as parameter and returns a handle suitable for passing to SetDialogItem as a user-item redraw routine. Note that you can only make one of these, for now.
1 parent ba0d061 commit df901df

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

Mac/Modules/dlg/Dlgmodule.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ Dlg_PassFilterProc(PyObject *callback)
106106
return &Dlg_UnivFilterProc;
107107
}
108108

109+
static PyObject *Dlg_UserItemProc_callback = NULL;
110+
111+
static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
112+
short item)
113+
{
114+
PyObject *args, *res;
115+
116+
if (Dlg_UserItemProc_callback == NULL)
117+
return; /* Default behavior */
118+
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
119+
args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
120+
if (args == NULL)
121+
res = NULL;
122+
else {
123+
res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
124+
Py_DECREF(args);
125+
}
126+
if (res == NULL) {
127+
fprintf(stderr, "Exception in Dialog UserItem proc\n");
128+
PyErr_Print();
129+
}
130+
Py_XDECREF(res);
131+
return;
132+
}
133+
109134
extern PyMethodChain WinObj_chain;
110135

111136
static PyObject *Dlg_Error;
@@ -1087,6 +1112,37 @@ static PyObject *Dlg_NewFeaturesDialog(_self, _args)
10871112
return _res;
10881113
}
10891114

1115+
static PyObject *Dlg_SetUserItemHandler(_self, _args)
1116+
PyObject *_self;
1117+
PyObject *_args;
1118+
{
1119+
PyObject *_res = NULL;
1120+
1121+
PyObject *new = NULL;
1122+
1123+
1124+
if (!PyArg_ParseTuple(_args, "|O", &new))
1125+
return NULL;
1126+
1127+
if (Dlg_UserItemProc_callback && new && new != Py_None) {
1128+
PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
1129+
return NULL;
1130+
}
1131+
1132+
if (new == Py_None) {
1133+
new = NULL;
1134+
_res = Py_None;
1135+
Py_INCREF(Py_None);
1136+
} else {
1137+
Py_INCREF(new);
1138+
_res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
1139+
}
1140+
1141+
Dlg_UserItemProc_callback = new;
1142+
return _res;
1143+
1144+
}
1145+
10901146
static PyMethodDef Dlg_methods[] = {
10911147
{"NewDialog", (PyCFunction)Dlg_NewDialog, 1,
10921148
"(Rect boundsRect, Str255 title, Boolean visible, SInt16 procID, WindowPtr behind, Boolean goAwayFlag, SInt32 refCon, Handle items) -> (DialogPtr _rv)"},
@@ -1122,6 +1178,8 @@ static PyMethodDef Dlg_methods[] = {
11221178
"() -> None"},
11231179
{"NewFeaturesDialog", (PyCFunction)Dlg_NewFeaturesDialog, 1,
11241180
"(Rect inBoundsRect, Str255 inTitle, Boolean inIsVisible, SInt16 inProcID, WindowPtr inBehind, Boolean inGoAwayFlag, SInt32 inRefCon, Handle inItemListHandle, UInt32 inFlags) -> (DialogPtr _rv)"},
1181+
{"SetUserItemHandler", (PyCFunction)Dlg_SetUserItemHandler, 1,
1182+
NULL},
11251183
{NULL, NULL, 0}
11261184
};
11271185

Mac/Modules/dlg/dlgsupport.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,31 @@
9292
return &Dlg_UnivFilterProc;
9393
}
9494
95+
static PyObject *Dlg_UserItemProc_callback = NULL;
96+
97+
static pascal void Dlg_UnivUserItemProc(DialogPtr dialog,
98+
short item)
99+
{
100+
PyObject *args, *res;
101+
102+
if (Dlg_UserItemProc_callback == NULL)
103+
return; /* Default behavior */
104+
Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */
105+
args = Py_BuildValue("O&h", WinObj_WhichWindow, dialog, item);
106+
if (args == NULL)
107+
res = NULL;
108+
else {
109+
res = PyEval_CallObject(Dlg_UserItemProc_callback, args);
110+
Py_DECREF(args);
111+
}
112+
if (res == NULL) {
113+
fprintf(stderr, "Exception in Dialog UserItem proc\\n");
114+
PyErr_Print();
115+
}
116+
Py_XDECREF(res);
117+
return;
118+
}
119+
95120
extern PyMethodChain WinObj_chain;
96121
"""
97122

@@ -145,6 +170,33 @@ def outputFreeIt(self, itselfname):
145170
f = Method(void, 'SetGrafPortOfDialog', (DialogRef, 'dialog', InMode))
146171
object.add(f)
147172

173+
setuseritembody = """
174+
PyObject *new = NULL;
175+
176+
177+
if (!PyArg_ParseTuple(_args, "|O", &new))
178+
return NULL;
179+
180+
if (Dlg_UserItemProc_callback && new && new != Py_None) {
181+
PyErr_SetString(Dlg_Error, "Another UserItemProc is already installed");
182+
return NULL;
183+
}
184+
185+
if (new == Py_None) {
186+
new = NULL;
187+
_res = Py_None;
188+
Py_INCREF(Py_None);
189+
} else {
190+
Py_INCREF(new);
191+
_res = Py_BuildValue("O&", ResObj_New, (Handle)NewUserItemProc(Dlg_UnivUserItemProc));
192+
}
193+
194+
Dlg_UserItemProc_callback = new;
195+
return _res;
196+
"""
197+
f = ManualGenerator("SetUserItemHandler", setuseritembody)
198+
module.add(f)
199+
148200
# generate output
149201
SetOutputFileName('Dlgmodule.c')
150202
module.generate()

0 commit comments

Comments
 (0)