- Confine window moves to screen boundaries

- Added windowbounds() function to help programmer with staggering
  windows
- Added event parameter to idle routine
- Added settext(label) method to menu entries
- Erase/invalidate only visRgn in stead of everything
- Correctly handle clicks in inactive ControlWindows
This commit is contained in:
Jack Jansen 1996-04-19 16:00:28 +00:00
parent 2cc41604c7
commit c4eec9fce1
1 changed files with 35 additions and 9 deletions

View File

@ -55,9 +55,28 @@ partname[6] = 'inGoAway'
partname[7] = 'inZoomIn' partname[7] = 'inZoomIn'
partname[8] = 'inZoomOut' partname[8] = 'inZoomOut'
# A rectangle that's bigger than the screen, #
# but not so big that adding the screen size to it will cause 16-bit overflow # The useable portion of the screen
everywhere = (-16000, -16000, 16000, 16000) #
screenbounds = qd.screenBits.bounds
screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
screenbounds[2]-4, screenbounds[3]-4
next_window_x = 40
next_window_y = 40
def windowbounds(width, height):
"Return sensible window bounds"
global next_window_x, next_window_y
r, b = next_window_x+width, next_window_y+height
if r > screenbounds[2]:
next_window_x = 40
if b > screenbounds[3]:
next_window_y = 40
l, t = next_window_x, next_window_y
r, b = next_window_x+width, next_window_y+height
next_window_x, next_window_y = next_window_x+20, next_window_y+20
return l, t, r, b
class Application: class Application:
@ -122,9 +141,9 @@ class Application:
if ok: if ok:
self.dispatch(event) self.dispatch(event)
else: else:
self.idle() self.idle(event)
def idle(self): def idle(self, event):
pass pass
def getevent(self, mask = everyEvent, wait = 0): def getevent(self, mask = everyEvent, wait = 0):
@ -452,6 +471,9 @@ class MenuItem:
self.menu.menu.EnableItem(self.item) self.menu.menu.EnableItem(self.item)
else: else:
self.menu.menu.DisableItem(self.item) self.menu.menu.DisableItem(self.item)
def settext(self, text):
self.menu.menu.SetMenuItemText(self.item, text)
class RadioItem(MenuItem): class RadioItem(MenuItem):
@ -519,7 +541,7 @@ class Window:
where = event[3] where = event[3]
window.DragWindow(where, self.draglimit) window.DragWindow(where, self.draglimit)
draglimit = everywhere draglimit = screenbounds
def do_inGoAway(self, partcode, window, event): def do_inGoAway(self, partcode, window, event):
where = event[3] where = event[3]
@ -547,7 +569,7 @@ class Window:
width = result & 0xffff # Lo word width = result & 0xffff # Lo word
self.do_resize(width, height, window) self.do_resize(width, height, window)
growlimit = everywhere growlimit = screenbounds
def do_resize(self, width, height, window): def do_resize(self, width, height, window):
window.SizeWindow(width, height, 0) window.SizeWindow(width, height, 0)
@ -555,7 +577,7 @@ class Window:
def do_postresize(self, width, height, window): def do_postresize(self, width, height, window):
SetPort(window) SetPort(window)
InvalRect(everywhere) InvalRect(window.GetWindowPort().portRect)
def do_inContent(self, partcode, window, event): def do_inContent(self, partcode, window, event):
# #
@ -582,7 +604,7 @@ class Window:
window.EndUpdate() window.EndUpdate()
def do_update(self, window, event): def do_update(self, window, event):
EraseRect(everywhere) EraseRgn(window.GetWindowPort().visRgn)
def do_activate(self, activate, event): def do_activate(self, activate, event):
if DEBUG: print 'Activate %d for %s'%(activate, self.wid) if DEBUG: print 'Activate %d for %s'%(activate, self.wid)
@ -591,6 +613,7 @@ class ControlsWindow(Window):
def do_rawupdate(self, window, event): def do_rawupdate(self, window, event):
if DEBUG: print "raw update for", window if DEBUG: print "raw update for", window
SetPort(window)
window.BeginUpdate() window.BeginUpdate()
self.do_update(window, event) self.do_update(window, event)
DrawControls(window) DrawControls(window)
@ -601,6 +624,9 @@ class ControlsWindow(Window):
if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode if DEBUG: print "control hit in", window, "on", control, "; pcode =", pcode
def do_inContent(self, partcode, window, event): def do_inContent(self, partcode, window, event):
if FrontWindow() <> window:
window.SelectWindow()
return
(what, message, when, where, modifiers) = event (what, message, when, where, modifiers) = event
SetPort(window) # XXXX Needed? SetPort(window) # XXXX Needed?
local = GlobalToLocal(where) local = GlobalToLocal(where)