Patch by Jason Harper to allow IDE to work again under MacOS 8.1. Plus appearance support for Wlist frames and focussing. Plus commented-out appearance support for the same for Wtext, which still needs some work.

This commit is contained in:
Jack Jansen 2001-12-04 13:30:29 +00:00
parent f227252c21
commit b6b6c6c33f
3 changed files with 145 additions and 35 deletions

View File

@ -7,7 +7,7 @@ class ControlWidget(Wbase.ClickableWidget):
"""Baseclass for all native controls."""
def __init__(self, possize, title = "Control", procID = 0, callback = None, value = 0, min = 0, max = 1):
def __init__(self, possize, title = "Control", procID = 0, callback = None, value = 0, min = 0, max = 1, viewsize = 0):
Wbase.ClickableWidget.__init__(self, possize)
self._control = None
self._title = title
@ -17,21 +17,54 @@ class ControlWidget(Wbase.ClickableWidget):
self._min = min
self._max = max
self._enabled = 1
self._viewsize = 0
self._viewsize = viewsize
def open(self):
self._calcbounds()
# NewControl doesn't accept 32-bit value, min, or max, so for consistency
# with the new 32-bit set/get methods, out-of-range values are initially
# set as zero, followed by a 32-bit set of the actual value.
# Values not representable in 16 bits will fail on MacOS 8.1, however
# the vast majority of control usage should still be compatible.
_value, _min, _max = self._value, self._min, self._max
if -32768 <= _value <= 32767:
bigvalue = None
else:
bigvalue = _value
_value = 0
if -32768 <= _min <= 32767:
bigmin = None
else:
bigmin = _min
_min = 0
if -32768 <= _max <= 32767:
bigmax = None
else:
bigmax = _max
_max = 0
self._control = Ctl.NewControl(self._parentwindow.wid,
self._bounds,
self._title,
1,
self._value,
self._min,
self._max,
_value,
_min,
_max,
self._procID,
0)
if bigvalue:
self._control.SetControl32BitValue(bigvalue)
if bigmin:
self._control.SetControl32BitMinimum(bigmin)
if bigmax:
self._control.SetControl32BitMaximum(bigmax)
if self._viewsize:
self._control.SetControlViewSize(self._viewsize)
try:
self._control.SetControlViewSize(self._viewsize)
# Not available in MacOS 8.1, but that's OK since it only affects
# proportional scrollbars which weren't available in 8.1 either.
except NotImplementedError:
pass
self.enable(self._enabled)
def adjust(self, oldbounds):
@ -100,13 +133,23 @@ class ControlWidget(Wbase.ClickableWidget):
def set(self, value):
if self._control:
self._control.SetControl32BitValue(value)
if -32768 <= value <= 32767:
# No 32-bit control support in MacOS 8.1, so use
# the 16-bit interface when possible.
self._control.SetControlValue(value)
else:
self._control.SetControl32BitValue(value)
else:
self._value = value
def get(self):
if self._control:
return self._control.GetControl32BitValue()
try:
return self._control.GetControl32BitValue()
# No 32-bit control support in MacOS 8.1, so fall
# back to the 16-bit interface when needed.
except NotImplementedError:
return self._control.GetControlValue()
else:
return self._value
@ -279,27 +322,52 @@ class Scrollbar(ControlWidget):
def setmin(self, min):
if self._control is not None:
self._control.SetControl32BitMinimum(min)
if -32768 <= min <= 32767:
# No 32-bit control support in MacOS 8.1, so use
# the 16-bit interface when possible.
self._control.SetControlMinimum(min)
else:
self._control.SetControl32BitMinimum(min)
else:
self._min = min
def setmax(self, max):
if self._control is not None:
self._control.SetControl32BitMaximum(max)
if -32768 <= max <= 32767:
# No 32-bit control support in MacOS 8.1, so use
# the 16-bit interface when possible.
self._control.SetControlMaximum(max)
else:
self._control.SetControl32BitMaximum(max)
else:
self._max = max
def setviewsize(self, viewsize):
if self._control is not None:
self._control.SetControlViewSize(viewsize)
try:
self._control.SetControlViewSize(viewsize)
# Not available in MacOS 8.1, but that's OK since it only affects
# proportional scrollbars which weren't available in 8.1 either.
except NotImplementedError:
pass
else:
self._viewsize = viewsize
def getmin(self):
return self._control.GetControl32BitMinimum()
try:
return self._control.GetControl32BitMinimum()
# No 32-bit control support in MacOS 8.1, so fall
# back to the 16-bit interface when needed.
except NotImplementedError:
return self._control.GetControlMinimum()
def getmax(self):
return self._control.GetControl32BitMaximum()
try:
return self._control.GetControl32BitMaximum()
# No 32-bit control support in MacOS 8.1, so fall
# back to the 16-bit interface when needed.
except NotImplementedError:
return self._control.GetControlMaximum()
# internals
def click(self, point, modifiers):
@ -334,7 +402,12 @@ class Scrollbar(ControlWidget):
def _hit(self, part):
if part == Controls.inThumb:
value = self._control.GetControl32BitValue()
try:
value = self._control.GetControl32BitValue()
# No 32-bit control support in MacOS 8.1, so fall
# back to the 16-bit interface when needed.
except NotImplementedError:
value = self._control.GetControlValue()
elif part == Controls.inUpButton:
value = "+"
elif part == Controls.inDownButton:

View File

@ -55,12 +55,11 @@ class List(Wbase.SelectableWidget):
def adjust(self, oldbounds):
self.SetPort()
if self._selected:
self.GetWindow().InvalWindowRect(Qd.InsetRect(oldbounds, -3, -3))
self.GetWindow().InvalWindowRect(Qd.InsetRect(self._bounds, -3, -3))
else:
self.GetWindow().InvalWindowRect(oldbounds)
self.GetWindow().InvalWindowRect(self._bounds)
# Appearance frames are drawn outside the specified bounds,
# so we always need to outset the invalidated area.
self.GetWindow().InvalWindowRect(Qd.InsetRect(oldbounds, -3, -3))
self.GetWindow().InvalWindowRect(Qd.InsetRect(self._bounds, -3, -3))
if oldbounds[:2] == self._bounds[:2]:
# set visRgn to empty, to prevent nasty drawing side effect of LSize()
Qd.RectRgn(self._parentwindow.wid.GetWindowPort().visRgn, (0, 0, 0, 0))
@ -255,24 +254,25 @@ class List(Wbase.SelectableWidget):
if not visRgn:
visRgn = self._parentwindow.wid.GetWindowPort().visRgn
self._list.LUpdate(visRgn)
App.DrawThemeListBoxFrame(self._bounds, kThemeStateActive)
#if self._selected and self._activated:
# self.drawselframe(1)
state = [kThemeStateActive, kThemeStateInactive][not self._activated]
App.DrawThemeListBoxFrame(Qd.InsetRect(self._bounds, 1, 1), state)
if self._selected and self._activated:
self.drawselframe(1)
def select(self, onoff, isclick = 0):
if Wbase.SelectableWidget.select(self, onoff):
return
self.SetPort()
state = [kThemeStateActive, kThemeStatePressed][onoff]
App.DrawThemeListBoxFrame(self._bounds, kThemeStateActive)
#self.drawselframe(onoff)
self.drawselframe(onoff)
def activate(self, onoff):
self._activated = onoff
if self._visible:
self._list.LActivate(onoff)
#if self._selected:
# self.drawselframe(onoff)
state = [kThemeStateActive, kThemeStateInactive][not onoff]
App.DrawThemeListBoxFrame(Qd.InsetRect(self._bounds, 1, 1), state)
if self._selected:
self.drawselframe(onoff)
def get(self):
return self.items

View File

@ -70,6 +70,11 @@ class _ScrollWidget:
destwidth = dr - dl
bar = self._parent._barx
bar.setmax(destwidth - viewwidth)
# MacOS 8.1 doesn't automatically disable
# scrollbars whose max <= min
bar.enable(destwidth > viewwidth)
bar.setviewsize(viewwidth)
bar.set(vl - dl)
if self._parent._bary:
@ -77,6 +82,11 @@ class _ScrollWidget:
destheight = db - dt
bar = self._parent._bary
bar.setmax(destheight - viewheight)
# MacOS 8.1 doesn't automatically disable
# scrollbars whose max <= min
bar.enable(destheight > viewheight)
bar.setviewsize(viewheight)
bar.set(vt - dt)
@ -218,6 +228,9 @@ class EditText(Wbase.SelectableWidget, _ScrollWidget):
def adjust(self, oldbounds):
self.SetPort()
# Note: if App.DrawThemeEditTextFrame is ever used, it will be necessary
# to unconditionally outset the invalidated rectangles, since Appearance
# frames are drawn outside the bounds.
if self._selected and self._parentwindow._hasselframes:
self.GetWindow().InvalWindowRect(Qd.InsetRect(oldbounds, -3, -3))
self.GetWindow().InvalWindowRect(Qd.InsetRect(self._bounds, -3, -3))
@ -351,12 +364,19 @@ class EditText(Wbase.SelectableWidget, _ScrollWidget):
def activate(self, onoff):
self._activated = onoff
if self._selected and self._visible:
if onoff:
self.ted.WEActivate()
else:
self.ted.WEDeactivate()
if self._visible:
self.SetPort()
# DISABLED! There are too many places where it is assumed that
# the frame of an EditText item is 1 pixel, inside the bounds.
#state = [kThemeStateActive, kThemeStateInactive][not onoff]
#App.DrawThemeEditTextFrame(Qd.InsetRect(self._bounds, 1, 1), state)
if self._selected:
if onoff:
self.ted.WEActivate()
else:
self.ted.WEDeactivate()
self.drawselframe(onoff)
def select(self, onoff, isclick = 0):
@ -376,10 +396,15 @@ class EditText(Wbase.SelectableWidget, _ScrollWidget):
if not visRgn:
visRgn = self._parentwindow.wid.GetWindowPort().visRgn
self.ted.WEUpdate(visRgn)
# DISABLED! There are too many places where it is assumed that
# the frame of an EditText item is 1 pixel, inside the bounds.
#state = [kThemeStateActive, kThemeStateInactive][not self._activated]
#App.DrawThemeEditTextFrame(Qd.InsetRect(self._bounds, 1, 1), state)
Qd.FrameRect(self._bounds)
if self._selected and self._activated:
self.drawselframe(1)
Qd.FrameRect(self._bounds)
#App.DrawThemeEditTextFrame(self._bounds, kThemeStateActive)
# scrolling
def scrollpageup(self):
@ -604,6 +629,18 @@ class TextEditor(EditText):
if self._selected and self._activated:
self.drawselframe(1)
def activate(self, onoff):
self._activated = onoff
if self._visible:
self.SetPort()
# doesn't draw frame, as EditText.activate does
if self._selected:
if onoff:
self.ted.WEActivate()
else:
self.ted.WEDeactivate()
self.drawselframe(onoff)
import re
commentPat = re.compile("[ \t]*(#)")