From: Richard K. <ric...@us...> - 2005-07-06 17:29:02
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26496 Modified Files: NSWindow.as ASRootWindowView.as Log Message: added code for window levels and title bars Index: ASRootWindowView.as =================================================================== RCS file: /cvsroot/actionstep/actionstep/src/org/actionstep/ASRootWindowView.as,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ASRootWindowView.as 21 Jun 2005 03:22:33 -0000 1.4 --- ASRootWindowView.as 6 Jul 2005 17:28:51 -0000 1.5 *************** *** 30,34 **** --- 30,40 ---- import org.actionstep.NSView; + import org.actionstep.NSApplication; + import org.actionstep.NSWindow; import org.actionstep.NSRect; + import org.actionstep.NSFont; + import org.actionstep.NSColor; + import org.actionstep.NSPoint; + import org.actionstep.NSEvent; class org.actionstep.ASRootWindowView extends NSView { *************** *** 36,58 **** // Static Functions ! var m_contentRect:NSRect; ! var m_swfLoading:Boolean; ! var m_swfLoaded:Boolean; public function ASRootWindowView() { m_swfLoading = false; m_swfLoaded = false; } ! public function initWithFrameWindow(frame, window):ASRootWindowView { initWithFrame(frame); m_window = window; return this; } private function createFrameMovieClip() { - var clipDepth = 100+m_window.windowNumber(); var self = this; ! m_mcFrame = _root.createEmptyMovieClip("ASRootWindowView"+clipDepth, clipDepth); m_mcFrame.onEnterFrame = function() { self.m_window.displayIfNeeded(); --- 42,183 ---- // Static Functions ! private static var g_lowestView:ASRootWindowView = null; ! ! private var m_contentRect:NSRect; ! private var m_swfLoading:Boolean; ! private var m_swfLoaded:Boolean; ! private var m_window:NSWindow; ! private var m_titleRect:NSRect; ! private var m_trackingData; ! ! private var m_lowerView:ASRootWindowView; ! private var m_higherView:ASRootWindowView; ! private var m_targetDepth:Number; ! ! private var m_titleTextField:TextField; ! private var m_titleFont:NSFont; ! private var m_titleFontColor:NSColor; ! ! public static function lowestView():ASRootWindowView { ! return g_lowestView; ! } ! ! public function dump(view:ASRootWindowView) { ! if(view == null) view = g_lowestView; ! TRACE(view.lowerView().window().windowNumber()+" - "+view.window().windowNumber()+" - "+view.higherView().window().windowNumber()); ! if(view.higherView() != null) { ! dump(view.higherView()); ! } else { ! TRACE("---"); ! } ! } ! ! public function highestViewOfLevel():ASRootWindowView { ! var view:ASRootWindowView = g_lowestView; ! while(view.higherView() != null && view.higherView().level()<=level()) { ! view = view.higherView(); ! } ! return view; ! } ! ! public function lowestViewOfLevel():ASRootWindowView { ! var view:ASRootWindowView = g_lowestView; ! while(view != null && view.level()>=level()) { ! view = view.higherView(); ! } ! return view; ! } public function ASRootWindowView() { m_swfLoading = false; m_swfLoaded = false; + m_titleRect = new NSRect(0,0,0,22); } ! public function initWithFrameWindow(frame:NSRect, window:NSWindow):ASRootWindowView { initWithFrame(frame); + m_titleFont = NSFont.systemFontOfSize(12); + m_titleFontColor = NSColor.systemFontColor(); m_window = window; + setLowerView(highestViewOfLevel()); return this; } + public function level():Number { + return m_window.level(); + } + + public function setHigherView(view:ASRootWindowView) { + m_higherView = view; + } + + public function higherView():ASRootWindowView { + return m_higherView; + } + + public function setLowerView(view:ASRootWindowView) { + if (view == null) { + if (g_lowestView != null) { + g_lowestView.setLowerView(this); + } + m_lowerView = view; + g_lowestView = this; + } else { + if (view != m_lowerView) { + m_lowerView = view; + view.higherView().setLowerView(this); + view.setHigherView(this); + } + } + setTargetDepths(); + } + + public function setTargetDepths() { + var view:ASRootWindowView = g_lowestView; + var i = 100; + view.setTargetDepth(i++); + while(view.higherView() != null) { + view.higherView().setTargetDepth(i++); + view = view.higherView(); + } + } + + public function setTargetDepth(depth:Number) { + m_targetDepth = depth; + } + + public function extractView() { + var lower:ASRootWindowView = m_lowerView; + var higher:ASRootWindowView = m_higherView; + m_higherView = null; + m_lowerView = null; + if (g_lowestView == this) { + g_lowestView = higher; + higher.m_lowerView = null; + return; + } + higher.m_lowerView = lower; + lower.m_higherView = higher; + } + + public function lowerView():ASRootWindowView { + return m_lowerView; + } + + public function matchDepth() { + if (m_mcFrame == null) { + return; + } + var oldDepth:Number = m_mcFrame.getDepth(); + if (m_targetDepth != oldDepth) { + m_mcFrame.swapDepths(m_targetDepth); + _root.getInstanceAtDepth(oldDepth).view.matchDepth(); + } + } + private function createFrameMovieClip() { var self = this; ! m_mcFrame = _root.createEmptyMovieClip("ASRootWindowView"+m_window.windowNumber(), m_targetDepth); ! _root["ASRootWindowView"+m_window.windowNumber()].window = m_window; m_mcFrame.onEnterFrame = function() { self.m_window.displayIfNeeded(); *************** *** 119,124 **** --- 244,335 ---- } } + + public function mouseDown(event:NSEvent) { + if (m_window.styleMask() == NSWindow.NSBorderlessWindowMask) { + return; + } + var location:NSPoint = event.mouseLocation; + location = convertPointFromView(location); + if(m_titleRect.pointInRect(location)) { + dragWindow(event); + } + } + + private function dragWindow(event:NSEvent) { + var point:NSPoint = convertPointFromView(event.mouseLocation, null); + m_trackingData = { + offsetX: point.x, + offsetY: point.y, + mouseDown: true, + eventMask: NSEvent.NSLeftMouseDownMask | NSEvent.NSLeftMouseUpMask | NSEvent.NSLeftMouseDraggedMask + | NSEvent.NSMouseMovedMask | NSEvent.NSOtherMouseDraggedMask | NSEvent.NSRightMouseDraggedMask, + complete: false, + }; + dragWindowCallback(event); + } + public function dragWindowCallback(event:NSEvent) { + if (event.type == NSEvent.NSLeftMouseUp) { + return; + } + m_window.setFrameOrigin(new NSPoint(event.mouseLocation.x - m_trackingData.offsetX, event.mouseLocation.y - m_trackingData.offsetY)); + NSApplication.sharedApplication().callObjectSelectorWithNextEventMatchingMaskDequeue(this, "dragWindowCallback", m_trackingData.eventMask, true); + } + public function drawRect(rect:NSRect) { + m_mcBounds.clear(); + var styleMask:Number = m_window.styleMask(); + if (styleMask == NSWindow.NSBorderlessWindowMask) { + return; + } + + var fillColors:Array = [0xFFFFFF, 0xDEDEDE, 0xC6C6C6]; + var fillAlpha:Number = 100; + var cornerRadius:Number = 4; + var x = rect.origin.x; + var y = rect.origin.y; + var width = rect.size.width-1; + var height = 22; + m_titleRect.size.width = width; + + if (m_titleTextField == null || m_titleTextField._parent == null) { + m_titleTextField = createBoundsTextField(); + m_titleTextField.autoSize = true; + m_titleTextField.align = "center"; + m_titleTextField.selectable = false; + m_titleTextField._alpha = m_titleFontColor.alphaComponent()*100; + m_titleTextField.embedFonts = m_titleFont.isEmbedded(); + } + if (m_titleTextField.text != m_window.title()) { + m_titleTextField.text = m_window.title(); + var textFormat = m_titleFont.textFormat(); + textFormat.bold = true; + textFormat.color = m_titleFontColor.value; + m_titleTextField.setTextFormat(textFormat); + m_titleTextField._y = (22 - (m_titleTextField.textHeight+2))/2;; + m_titleTextField._x = (width - (m_titleTextField.textWidth+4))/2; + } + + var totalHeight = rect.size.height-1; + with (m_mcBounds) { + lineStyle(1.5, 0x8E8E8E, 100); + beginGradientFill("linear", fillColors, [100,100,100], [0, 50, 255], + {matrixType:"box", x:x,y:y,w:width,h:height,r:(.5*Math.PI)}); + moveTo(x+cornerRadius, y); + lineTo(x+width-cornerRadius, y); + lineTo(x+width, y+cornerRadius); //Angle + lineTo(x+width, y+height); + lineStyle(1.5, 0x6E6E6E, 100); + lineTo(x, y+height); + lineStyle(1.5, 0x8E8E8E, 100); + lineTo(x, y+cornerRadius); + lineTo(x+cornerRadius, y); //Angle + endFill(); + moveTo(x, y+height); + lineStyle(1.5, 0x8E8E8E, 100); + lineTo(x, y+totalHeight); + lineTo(x+width, y+totalHeight); + lineTo(x+width, y+height); + } } Index: NSWindow.as =================================================================== RCS file: /cvsroot/actionstep/actionstep/src/org/actionstep/NSWindow.as,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** NSWindow.as 24 Jun 2005 02:21:17 -0000 1.15 --- NSWindow.as 6 Jul 2005 17:28:51 -0000 1.16 *************** *** 70,74 **** private static var g_instances:Array = new Array(); - private static var g_zOrder:Array = new Array(); public static function instances():Array { --- 70,73 ---- *************** *** 115,118 **** --- 114,118 ---- m_viewsNeedDisplay = true; m_fieldEditor= ASFieldEditor.instance(); + m_title = ""; m_isKey = false; m_isMain = false; *************** *** 172,183 **** } ! public function contentRectForFrameRect():NSRect { //! Based on style masks reshape? ! return m_frameRect.clone(); } public function frameRectForContentRect():NSRect { ! //! Based on style masks reshape? ! return m_contentRect.clone(); } --- 172,219 ---- } ! // Calculating layout ! ! public function contentRectForFrameRectStyleMask(styleMask:Number):NSRect { ! var rect:NSRect = m_frameRect.clone(); ! if (styleMask == NSBorderlessWindowMask) { ! return rect; ! } ! if (styleMask & NSTitledWindowMask) { ! rect.origin.y += 23; ! rect.size.height -= 24; ! rect.origin.x += 1; ! rect.size.width -= 2; ! } ! return rect; ! } ! ! public function frameRectForContentRectStyleMask(styleMask:Number):NSRect { ! var rect:NSRect = m_contentRect.clone(); ! if (styleMask == NSBorderlessWindowMask) { ! return rect; ! } ! /* ! public static var NSBorderlessWindowMask = 0 ! public static var NSTitledWindowMask = 1 ! public static var NSClosableWindowMask = 2 ! public static var NSMiniaturizableWindowMask = 4 ! public static var NSResizableWindowMask = 8 ! */ //! Based on style masks reshape? ! if (styleMask & NSTitledWindowMask) { ! rect.origin.y -= 23; ! rect.size.height += 24; ! rect.origin.x -= 1; ! rect.size.width += 2; ! } ! return rect; ! } ! ! public function contentRectForFrameRect():NSRect { ! return contentRectForFrameRectStyleMask(m_styleMask); } public function frameRectForContentRect():NSRect { ! return frameRectForContentRectStyleMask(m_styleMask); } *************** *** 222,261 **** // Ordering Windows public function orderBack(sender:Object) { ! removeFromZOrder(); ! var start:Number = removeFromZOrder(); ! for(var i = start;i >= 0;i--) { ! if (g_instances[g_zOrder[i]].level() != m_level) { ! g_zOrder.splice(i,0,m_windowNumber); ! return; ! } ! } ! g_zOrder.unshift(m_windowNumber); } public function orderFront(sender:Object) { ! var start:Number = removeFromZOrder(); ! for(var i = start;i < g_zOrder.length;i++) { ! if (g_instances[g_zOrder[i]].level() != m_level) { ! g_zOrder.splice(i,0,m_windowNumber); ! return; ! } ! } ! g_zOrder.push(m_windowNumber); ! } ! ! private function removeFromZOrder():Number { ! for(var i = 0;i<g_zOrder.length;i++) { ! if (g_zOrder[i] == m_windowNumber) { ! g_zOrder.splice(i,1); ! return i; ! } ! } ! for(var i = 0;i<g_zOrder.length;i++) { ! if (g_instances[g_zOrder[i]].level() == m_level || g_instances[g_zOrder[i]].level() > m_level) { ! return i; ! } ! } } --- 258,276 ---- // Ordering Windows + + public function rootView():ASRootWindowView { + return m_rootView; + } public function orderBack(sender:Object) { ! m_rootView.extractView(); ! m_rootView.lowestViewOfLevel().setLowerView(m_rootView); ! m_rootView.matchDepth(); } public function orderFront(sender:Object) { ! m_rootView.extractView(); ! m_rootView.setLowerView(m_rootView.highestViewOfLevel()); ! m_rootView.matchDepth(); } *************** *** 269,293 **** public function orderWindowRelativeTo(positioned:NSWindowOrderingMode, windowNumber:Number) { ! removeFromZOrder(); ! for(var i = 0;i<g_zOrder.length;i++) { ! if (g_zOrder[i] == windowNumber) { ! switch(positioned) { ! case NSWindowOrderingMode.NSWindowAbove: ! g_zOrder.splice(i,0,m_windowNumber); ! break; ! case NSWindowOrderingMode.NSWindowBelow: ! g_zOrder.splice(i-1,0,m_windowNumber); ! break; ! case NSWindowOrderingMode.NSWindowOut: ! //! How to handle this? ! break; ! } ! return; ! } } } public function setLevel(newLevel:Number) { - removeFromZOrder(); m_level = newLevel; orderFront(); --- 284,306 ---- public function orderWindowRelativeTo(positioned:NSWindowOrderingMode, windowNumber:Number) { ! var windowRoot:ASRootWindowView = g_instances[windowNumber].rootView(); ! switch(positioned) { ! case NSWindowOrderingMode.NSWindowAbove: ! m_rootView.extractView(); ! m_rootView.setLowerView(windowRoot); ! m_rootView.matchDepth(); ! break; ! case NSWindowOrderingMode.NSWindowBelow: ! m_rootView.extractView(); ! windowRoot.setLowerView(m_rootView); ! m_rootView.matchDepth(); ! break; ! case NSWindowOrderingMode.NSWindowOut: ! //! How to handle this? ! break; } } public function setLevel(newLevel:Number) { m_level = newLevel; orderFront(); *************** *** 334,338 **** public function makeKeyAndOrderFront() { makeKeyWindow(); ! //! Order front } --- 347,351 ---- public function makeKeyAndOrderFront() { makeKeyWindow(); ! orderFront(this); } *************** *** 496,501 **** m_contentView = view; m_rootView.setContentView(m_contentView); m_contentView.setNextResponder(this); - m_rootView.displayIfNeeded(); } --- 509,514 ---- m_contentView = view; m_rootView.setContentView(m_contentView); + m_contentView.setFrame(NSRect.withOriginSize(convertScreenToBase(m_contentRect.origin), m_contentRect.size)); m_contentView.setNextResponder(this); } |