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

Skip to content

Commit 7ec1c85

Browse files
committed
- "manage" controls created by CreateXxxXxxControl() functions.
- FindControlUnderMouse() returns an existing control, not a new one.
1 parent f36cfef commit 7ec1c85

3 files changed

Lines changed: 67 additions & 48 deletions

File tree

Mac/Modules/ctl/_Ctlmodule.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,29 +4035,6 @@ static PyObject *Ctl_FindControl(PyObject *_self, PyObject *_args)
40354035
return _res;
40364036
}
40374037

4038-
static PyObject *Ctl_FindControlUnderMouse(PyObject *_self, PyObject *_args)
4039-
{
4040-
PyObject *_res = NULL;
4041-
ControlHandle _rv;
4042-
Point inWhere;
4043-
WindowPtr inWindow;
4044-
SInt16 outPart;
4045-
#ifndef FindControlUnderMouse
4046-
PyMac_PRECHECK(FindControlUnderMouse);
4047-
#endif
4048-
if (!PyArg_ParseTuple(_args, "O&O&",
4049-
PyMac_GetPoint, &inWhere,
4050-
WinObj_Convert, &inWindow))
4051-
return NULL;
4052-
_rv = FindControlUnderMouse(inWhere,
4053-
inWindow,
4054-
&outPart);
4055-
_res = Py_BuildValue("O&h",
4056-
CtlObj_New, _rv,
4057-
outPart);
4058-
return _res;
4059-
}
4060-
40614038
static PyObject *Ctl_IdleControls(PyObject *_self, PyObject *_args)
40624039
{
40634040
PyObject *_res = NULL;
@@ -4137,7 +4114,7 @@ static PyObject *Ctl_CreateRootControl(PyObject *_self, PyObject *_args)
41374114
&outControl);
41384115
if (_err != noErr) return PyMac_Error(_err);
41394116
_res = Py_BuildValue("O&",
4140-
CtlObj_WhichControl, outControl);
4117+
CtlObj_New, outControl);
41414118
return _res;
41424119
}
41434120

@@ -4340,7 +4317,7 @@ static PyObject *Ctl_CreateDisclosureTriangleControl(PyObject *_self, PyObject *
43404317
&outControl);
43414318
if (_err != noErr) return PyMac_Error(_err);
43424319
_res = Py_BuildValue("O&",
4343-
CtlObj_WhichControl, outControl);
4320+
CtlObj_New, outControl);
43444321
return _res;
43454322
}
43464323

@@ -4375,7 +4352,7 @@ static PyObject *Ctl_CreateProgressBarControl(PyObject *_self, PyObject *_args)
43754352
&outControl);
43764353
if (_err != noErr) return PyMac_Error(_err);
43774354
_res = Py_BuildValue("O&",
4378-
CtlObj_WhichControl, outControl);
4355+
CtlObj_New, outControl);
43794356
return _res;
43804357
}
43814358

@@ -4410,7 +4387,7 @@ static PyObject *Ctl_CreateLittleArrowsControl(PyObject *_self, PyObject *_args)
44104387
&outControl);
44114388
if (_err != noErr) return PyMac_Error(_err);
44124389
_res = Py_BuildValue("O&",
4413-
CtlObj_WhichControl, outControl);
4390+
CtlObj_New, outControl);
44144391
return _res;
44154392
}
44164393

@@ -4433,7 +4410,7 @@ static PyObject *Ctl_CreateChasingArrowsControl(PyObject *_self, PyObject *_args
44334410
&outControl);
44344411
if (_err != noErr) return PyMac_Error(_err);
44354412
_res = Py_BuildValue("O&",
4436-
CtlObj_WhichControl, outControl);
4413+
CtlObj_New, outControl);
44374414
return _res;
44384415
}
44394416

@@ -4456,7 +4433,7 @@ static PyObject *Ctl_CreateSeparatorControl(PyObject *_self, PyObject *_args)
44564433
&outControl);
44574434
if (_err != noErr) return PyMac_Error(_err);
44584435
_res = Py_BuildValue("O&",
4459-
CtlObj_WhichControl, outControl);
4436+
CtlObj_New, outControl);
44604437
return _res;
44614438
}
44624439

@@ -4485,7 +4462,7 @@ static PyObject *Ctl_CreateGroupBoxControl(PyObject *_self, PyObject *_args)
44854462
&outControl);
44864463
if (_err != noErr) return PyMac_Error(_err);
44874464
_res = Py_BuildValue("O&",
4488-
CtlObj_WhichControl, outControl);
4465+
CtlObj_New, outControl);
44894466
return _res;
44904467
}
44914468

@@ -4520,7 +4497,7 @@ static PyObject *Ctl_CreateCheckGroupBoxControl(PyObject *_self, PyObject *_args
45204497
&outControl);
45214498
if (_err != noErr) return PyMac_Error(_err);
45224499
_res = Py_BuildValue("O&",
4523-
CtlObj_WhichControl, outControl);
4500+
CtlObj_New, outControl);
45244501
return _res;
45254502
}
45264503

@@ -4564,7 +4541,7 @@ static PyObject *Ctl_CreatePopupGroupBoxControl(PyObject *_self, PyObject *_args
45644541
&outControl);
45654542
if (_err != noErr) return PyMac_Error(_err);
45664543
_res = Py_BuildValue("O&",
4567-
CtlObj_WhichControl, outControl);
4544+
CtlObj_New, outControl);
45684545
return _res;
45694546
}
45704547

@@ -4593,7 +4570,7 @@ static PyObject *Ctl_CreatePopupArrowControl(PyObject *_self, PyObject *_args)
45934570
&outControl);
45944571
if (_err != noErr) return PyMac_Error(_err);
45954572
_res = Py_BuildValue("O&",
4596-
CtlObj_WhichControl, outControl);
4573+
CtlObj_New, outControl);
45974574
return _res;
45984575
}
45994576

@@ -4616,7 +4593,7 @@ static PyObject *Ctl_CreatePlacardControl(PyObject *_self, PyObject *_args)
46164593
&outControl);
46174594
if (_err != noErr) return PyMac_Error(_err);
46184595
_res = Py_BuildValue("O&",
4619-
CtlObj_WhichControl, outControl);
4596+
CtlObj_New, outControl);
46204597
return _res;
46214598
}
46224599

@@ -4645,7 +4622,7 @@ static PyObject *Ctl_CreateClockControl(PyObject *_self, PyObject *_args)
46454622
&outControl);
46464623
if (_err != noErr) return PyMac_Error(_err);
46474624
_res = Py_BuildValue("O&",
4648-
CtlObj_WhichControl, outControl);
4625+
CtlObj_New, outControl);
46494626
return _res;
46504627
}
46514628

@@ -4671,7 +4648,7 @@ static PyObject *Ctl_CreateUserPaneControl(PyObject *_self, PyObject *_args)
46714648
&outControl);
46724649
if (_err != noErr) return PyMac_Error(_err);
46734650
_res = Py_BuildValue("O&",
4674-
CtlObj_WhichControl, outControl);
4651+
CtlObj_New, outControl);
46754652
return _res;
46764653
}
46774654

@@ -4706,7 +4683,7 @@ static PyObject *Ctl_CreateEditTextControl(PyObject *_self, PyObject *_args)
47064683
&outControl);
47074684
if (_err != noErr) return PyMac_Error(_err);
47084685
_res = Py_BuildValue("O&",
4709-
CtlObj_WhichControl, outControl);
4686+
CtlObj_New, outControl);
47104687
return _res;
47114688
}
47124689

@@ -4735,7 +4712,7 @@ static PyObject *Ctl_CreateStaticTextControl(PyObject *_self, PyObject *_args)
47354712
&outControl);
47364713
if (_err != noErr) return PyMac_Error(_err);
47374714
_res = Py_BuildValue("O&",
4738-
CtlObj_WhichControl, outControl);
4715+
CtlObj_New, outControl);
47394716
return _res;
47404717
}
47414718

@@ -4761,7 +4738,7 @@ static PyObject *Ctl_CreateWindowHeaderControl(PyObject *_self, PyObject *_args)
47614738
&outControl);
47624739
if (_err != noErr) return PyMac_Error(_err);
47634740
_res = Py_BuildValue("O&",
4764-
CtlObj_WhichControl, outControl);
4741+
CtlObj_New, outControl);
47654742
return _res;
47664743
}
47674744

@@ -4787,7 +4764,7 @@ static PyObject *Ctl_CreatePushButtonControl(PyObject *_self, PyObject *_args)
47874764
&outControl);
47884765
if (_err != noErr) return PyMac_Error(_err);
47894766
_res = Py_BuildValue("O&",
4790-
CtlObj_WhichControl, outControl);
4767+
CtlObj_New, outControl);
47914768
return _res;
47924769
}
47934770

@@ -4819,7 +4796,7 @@ static PyObject *Ctl_CreateRadioButtonControl(PyObject *_self, PyObject *_args)
48194796
&outControl);
48204797
if (_err != noErr) return PyMac_Error(_err);
48214798
_res = Py_BuildValue("O&",
4822-
CtlObj_WhichControl, outControl);
4799+
CtlObj_New, outControl);
48234800
return _res;
48244801
}
48254802

@@ -4851,7 +4828,7 @@ static PyObject *Ctl_CreateCheckBoxControl(PyObject *_self, PyObject *_args)
48514828
&outControl);
48524829
if (_err != noErr) return PyMac_Error(_err);
48534830
_res = Py_BuildValue("O&",
4854-
CtlObj_WhichControl, outControl);
4831+
CtlObj_New, outControl);
48554832
return _res;
48564833
}
48574834

@@ -4892,7 +4869,7 @@ static PyObject *Ctl_CreatePopupButtonControl(PyObject *_self, PyObject *_args)
48924869
&outControl);
48934870
if (_err != noErr) return PyMac_Error(_err);
48944871
_res = Py_BuildValue("O&",
4895-
CtlObj_WhichControl, outControl);
4872+
CtlObj_New, outControl);
48964873
return _res;
48974874
}
48984875

@@ -4915,7 +4892,7 @@ static PyObject *Ctl_CreateRadioGroupControl(PyObject *_self, PyObject *_args)
49154892
&outControl);
49164893
if (_err != noErr) return PyMac_Error(_err);
49174894
_res = Py_BuildValue("O&",
4918-
CtlObj_WhichControl, outControl);
4895+
CtlObj_New, outControl);
49194896
return _res;
49204897
}
49214898

@@ -4953,7 +4930,7 @@ static PyObject *Ctl_CreateScrollingTextBoxControl(PyObject *_self, PyObject *_a
49534930
&outControl);
49544931
if (_err != noErr) return PyMac_Error(_err);
49554932
_res = Py_BuildValue("O&",
4956-
CtlObj_WhichControl, outControl);
4933+
CtlObj_New, outControl);
49574934
return _res;
49584935
}
49594936

@@ -4979,7 +4956,30 @@ static PyObject *Ctl_CreateDataBrowserControl(PyObject *_self, PyObject *_args)
49794956
&outControl);
49804957
if (_err != noErr) return PyMac_Error(_err);
49814958
_res = Py_BuildValue("O&",
4982-
CtlObj_WhichControl, outControl);
4959+
CtlObj_New, outControl);
4960+
return _res;
4961+
}
4962+
4963+
static PyObject *Ctl_FindControlUnderMouse(PyObject *_self, PyObject *_args)
4964+
{
4965+
PyObject *_res = NULL;
4966+
ControlHandle _rv;
4967+
Point inWhere;
4968+
WindowPtr inWindow;
4969+
SInt16 outPart;
4970+
#ifndef FindControlUnderMouse
4971+
PyMac_PRECHECK(FindControlUnderMouse);
4972+
#endif
4973+
if (!PyArg_ParseTuple(_args, "O&O&",
4974+
PyMac_GetPoint, &inWhere,
4975+
WinObj_Convert, &inWindow))
4976+
return NULL;
4977+
_rv = FindControlUnderMouse(inWhere,
4978+
inWindow,
4979+
&outPart);
4980+
_res = Py_BuildValue("O&h",
4981+
CtlObj_WhichControl, _rv,
4982+
outPart);
49834983
return _res;
49844984
}
49854985

@@ -5011,8 +5011,6 @@ static PyMethodDef Ctl_methods[] = {
50115011
"(WindowPtr theWindow, RgnHandle updateRegion) -> None"},
50125012
{"FindControl", (PyCFunction)Ctl_FindControl, 1,
50135013
"(Point testPoint, WindowPtr theWindow) -> (ControlPartCode _rv, ControlHandle theControl)"},
5014-
{"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
5015-
"(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
50165014
{"IdleControls", (PyCFunction)Ctl_IdleControls, 1,
50175015
"(WindowPtr inWindow) -> None"},
50185016

@@ -5090,6 +5088,8 @@ static PyMethodDef Ctl_methods[] = {
50905088
"(WindowPtr window, Rect boundsRect, SInt16 contentResID, Boolean autoScroll, UInt32 delayBeforeAutoScroll, UInt32 delayBetweenAutoScroll, UInt16 autoScrollAmount) -> (ControlHandle outControl)"},
50915089
{"CreateDataBrowserControl", (PyCFunction)Ctl_CreateDataBrowserControl, 1,
50925090
"(WindowPtr window, Rect boundsRect, OSType style) -> (ControlHandle outControl)"},
5091+
{"FindControlUnderMouse", (PyCFunction)Ctl_FindControlUnderMouse, 1,
5092+
"(Point inWhere, WindowPtr inWindow) -> (ControlHandle _rv, SInt16 outPart)"},
50935093
{"as_Control", (PyCFunction)Ctl_as_Control, 1,
50945094
"(Handle h) -> (ControlHandle _rv)"},
50955095
{NULL, NULL, 0}

Mac/Modules/ctl/ctledit.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# FindControlUnderMouse() returns an existing control, not a new one,
2+
# so create this one by hand.
3+
f = Function(ExistingControlHandle, 'FindControlUnderMouse',
4+
(Point, 'inWhere', InMode),
5+
(WindowRef, 'inWindow', InMode),
6+
(SInt16, 'outPart', OutMode),
7+
)
8+
functions.append(f)
9+
110
f = Function(ControlHandle, 'as_Control',
211
(Handle, 'h', InMode))
312
functions.append(f)
@@ -25,3 +34,12 @@
2534
f.docstring = lambda : "() -> None"
2635

2736
methods.append(f)
37+
38+
# All CreateXxxXxxControl() functions return a new object in an output
39+
# parameter; these should however be managed by us (we're creating them
40+
# after all), so set the type to ControlRef.
41+
for f in functions:
42+
if f.name.startswith("Create"):
43+
v = f.argumentList[-1]
44+
if v.type == ExistingControlHandle:
45+
v.type = ControlRef

Mac/Modules/ctl/ctlscan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def writeinitialdefs(self):
4545

4646
def makeblacklistnames(self):
4747
return [
48+
'FindControlUnderMouse', # Generated manually, returns an existing control, not a new one.
4849
'DisposeControl', # Generated manually
4950
'KillControls', # Implied by close of dialog
5051
'SetCtlAction',

0 commit comments

Comments
 (0)