Skip to content

Commit 9b4947e

Browse files
author
jack
committed
Added a GetControlRect() method to controls which returns the bounding rectangle. To my surprise this call is missing from the C API...
git-svn-id: http://svn.python.org/projects/python/trunk@14754 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 509834c commit 9b4947e

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

Mac/Modules/ctl/Ctlmodule.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern PyObject *WinObj_WhichWindow(WindowPtr);
4646

4747
#define as_Control(h) ((ControlHandle)h)
4848
#define as_Resource(ctl) ((Handle)ctl)
49+
#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
4950

5051
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
5152

@@ -1021,6 +1022,21 @@ static PyObject *CtlObj_as_Resource(_self, _args)
10211022
return _res;
10221023
}
10231024

1025+
static PyObject *CtlObj_GetControlRect(_self, _args)
1026+
ControlObject *_self;
1027+
PyObject *_args;
1028+
{
1029+
PyObject *_res = NULL;
1030+
Rect rect;
1031+
if (!PyArg_ParseTuple(_args, ""))
1032+
return NULL;
1033+
GetControlRect(_self->ob_itself,
1034+
&rect);
1035+
_res = Py_BuildValue("O&",
1036+
PyMac_BuildRect, &rect);
1037+
return _res;
1038+
}
1039+
10241040
static PyObject *CtlObj_DisposeControl(_self, _args)
10251041
ControlObject *_self;
10261042
PyObject *_args;
@@ -1442,6 +1458,8 @@ static PyMethodDef CtlObj_methods[] = {
14421458
"(ControlPartCode inPart, ResType inTagName) -> (Size outMaxSize)"},
14431459
{"as_Resource", (PyCFunction)CtlObj_as_Resource, 1,
14441460
"() -> (Handle _rv)"},
1461+
{"GetControlRect", (PyCFunction)CtlObj_GetControlRect, 1,
1462+
"() -> (Rect rect)"},
14451463
{"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1,
14461464
"() -> None"},
14471465
{"TrackControl", (PyCFunction)CtlObj_TrackControl, 1,
@@ -1890,6 +1908,7 @@ PyObject *CtlObj_NewUnmanaged(itself)
18901908
it = PyObject_NEW(ControlObject, &Control_Type);
18911909
if (it == NULL) return NULL;
18921910
it->ob_itself = itself;
1911+
it->ob_callbackdict = NULL;
18931912
return (PyObject *)it;
18941913
}
18951914

Mac/Modules/ctl/ctledit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
f = Method(Handle, 'as_Resource', (ControlHandle, 'ctl', InMode))
66
methods.append(f)
77

8+
f = Method(void, 'GetControlRect', (ControlHandle, 'ctl', InMode), (Rect, 'rect', OutMode))
9+
methods.append(f)
10+
811
DisposeControl_body = """
912
if (!PyArg_ParseTuple(_args, ""))
1013
return NULL;

Mac/Modules/ctl/ctlsupport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
4747
#define as_Control(h) ((ControlHandle)h)
4848
#define as_Resource(ctl) ((Handle)ctl)
49+
#define GetControlRect(ctl, rectp) (*(rectp) = ((*(ctl))->contrlRect))
4950
5051
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
5152
@@ -100,6 +101,7 @@
100101
it = PyObject_NEW(ControlObject, &Control_Type);
101102
if (it == NULL) return NULL;
102103
it->ob_itself = itself;
104+
it->ob_callbackdict = NULL;
103105
return (PyObject *)it;
104106
}
105107

0 commit comments

Comments
 (0)