From: Scott H. <sco...@us...> - 2005-05-17 01:43:38
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15532/src/org/actionstep Modified Files: NSMatrix.as Log Message: Uses new theming stuff Index: NSMatrix.as =================================================================== RCS file: /cvsroot/actionstep/actionstep/src/org/actionstep/NSMatrix.as,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NSMatrix.as 16 May 2005 22:24:42 -0000 1.4 --- NSMatrix.as 17 May 2005 01:43:26 -0000 1.5 *************** *** 40,45 **** import org.actionstep.NSColor; import org.actionstep.NSSize; ! ! import org.actionstep.ASDrawer; import org.actionstep.constants.NSMatrixMode; --- 40,45 ---- import org.actionstep.NSColor; import org.actionstep.NSSize; ! import org.actionstep.NSApplication; ! import org.actionstep.ASTheme; import org.actionstep.constants.NSMatrixMode; *************** *** 92,95 **** --- 92,98 ---- private var m_sel:NSArray; + private var m_target:Object; + private var m_action:String; + /** * The reason this is here, and not in a cell, is because a matrix can *************** *** 225,232 **** if (m_numrows > 0 && m_numcols > 0) { ! m_cellsize = new NSSize( ! m_frame.size.width / m_numcols, ! m_frame.size.height / m_numrows); ! } // --- 228,233 ---- if (m_numrows > 0 && m_numcols > 0) { ! recalcCellSize(); ! } // *************** *** 411,448 **** } - /** - * Returns the action method sent by the receiver to its target when the - * user double-clicks an entry, or NULL if thereâs no double-click action. - * The double-click action of an NSMatrix is sent after the appropriate - * single-click action (for the NSCell clicked or for the NSMatrix if - * the NSCell doesnât have its own action). If there is no double-click - * action and the NSMatrix doesnât ignore multiple clicks, the single-click - * action is sent twice. - */ - public function doubleAction():String - { - return m_doubleaction; - } - - - /** - * Makes aSelector the action sent to the target of the receiver when the - * user double-clicks a cell. A double-click action is always sent after - * the appropriate single-click action, which is the cellâs single-click - * action, if it has one, or the receiver single-click action, otherwise. - * If aSelector is a non-NULL selector, this method also sets the - * ignoresMultiClick flag to TRUE; otherwise, it leaves the flag unchanged. - * - * If an NSMatrix has no double-click action set, then by default a double - * click is treated as a single click. - * - * For the method to have any effect, the receiverâs action and target must - * be set to the class in which the selector is declared. - */ - public function setDoubleAction(aSelector:String):Void - { - m_doubleaction = aSelector; - } - /** --- 412,415 ---- *************** *** 503,506 **** --- 470,474 ---- { m_cellspacing = aSize; + recalcCellSize(); } *************** *** 682,685 **** --- 650,815 ---- return loc.row; } + + //****************************************************** + //* Target and Action * + //****************************************************** + + /** + * Returns the the method name that is called on this control's target + * when a double click occurs. + * + * @see org.actionstep.NSMatrix#setDoubleAction + * @see org.actionstep.NSMatrix#sendDoubleAction + */ + public function doubleAction():String + { + return m_doubleaction; + } + + + /** + * If the selected cell has a target and an action, a message is sent + * to the target. + * + * If the cell's target is null, this control's target is used. + * + * If there is no selected cell or the selected cell has no action, this + * control triggers its target's action. + * + * This method returns TRUE if a target responds to the message, and FALSE + * otherwise. + */ + public function sendAction():Boolean + { + var selcell:NSCell = selectedCell(); + + if (selcell == null || selcell.action() == null) + { + // + // No selection or selection has no action, so use this control's + // target and action. + // + return sendActionTo(m_action, m_target); + } + else if (selcell.target() == null) + { + // + // Selection has no target, so use this control's target. + // + return sendActionTo(selcell.action(), m_target); //! is this right? + } + else + { + // + // Selection has target and action, so send it. + // + return sendActionTo(selcell.action(), selcell.target()); //! is this right? + } + } + + + /** + * Iterates through all cells if toAllCells is TRUE or selected cells if + * toAllCells is FALSE, calling aSelector on anObject for each cell + * passing the current cell as the only parameter. + * + * The return type for anObject::aSelector() must be boolean. When + * anObject::aSelector returns TRUE, iteration continues to the next cell. + * When it returns FALSE, the iteration halts immediately. + */ + public function sendActionToForAllCells(aSelector:String, anObject:Object, + toAllCells:Boolean):Void + { + var cells:NSArray = toAllCells ? cells() : selectedCells(); + var app:NSApplication = NSApplication.sharedApplication(); + var itr:NSEnumerator = cells.objectEnumerator(); + var cell:NSCell; + var cont:Boolean = true; + + while ((null != (cell = NSCell(itr.nextObject()))) && cont) + { + cont = app.sendActionToFrom(aSelector, anObject, cell); + } + } + + + /** + * This method does the following in the specified order, until + * success is reached: + * + * 1. If doubleAction is set, a message will be sent to this control's + * target. + * 2. If the selected cell has an action set, that message will be sent + * to the cell's target. + * 3. A single-click action will be sent to this control's target. + * + * + * If the selected cell is disabled, no action is sent. + * + * This method should not be called directly (from the outside of this + * object), but can be overridden by subclasses for specialized + * behaviour. + */ + public function sendDoubleAction():Boolean + { + // Step 1. + if (m_doubleaction != null) + return sendActionTo(m_doubleaction, m_target); + + // Step 2. + var selcell:NSCell = selectedCell(); + + if (selcell != null) + { + if (!selcell.isEnabled()) + return false; + + if (selcell.action() != undefined) + return sendActionTo(selcell.action(), selcell.target()); //! is this right? + } + + // Step 3. + //! How do I do this? + + return false; + } + + + /** + * @see org.actionstep.NSControl#setAction + */ + public function setAction(aSelector:String):Void + { + m_action = aSelector; + } + + + /** + * Makes aSelector the action sent to the target of the receiver when the + * user double-clicks a cell. A double-click action is always sent after + * the appropriate single-click action, which is the cellâs single-click + * action, if it has one, or the receiver single-click action, otherwise. + * If aSelector is a non-NULL selector, this method also sets the + * ignoresMultiClick flag to TRUE; otherwise, it leaves the flag unchanged. + * + * If an NSMatrix has no double-click action set, then by default a double + * click is treated as a single click. + * + * For the method to have any effect, the receiverâs action and target must + * be set to the class in which the selector is declared. + */ + public function setDoubleAction(aSelector:String):Void + { + m_doubleaction = aSelector; + } + + + /** + * @see org.actionstep.NSControl#setTarget + */ + public function setTarget(target:Object):Void + { + m_target = target; + } //****************************************************** *************** *** 1225,1230 **** var frame:NSRect = cellFrameAtRowColumn(row, column); ! ! TRACE("(" + row + ", " + column + ") with frame: " + frame); // --- 1355,1360 ---- var frame:NSRect = cellFrameAtRowColumn(row, column); ! ! TRACE("drawing " + frame); // *************** *** 1233,1241 **** if (m_drawscellbg) { ! ASDrawer.current.drawFillWithRectColorInView(frame, m_cellbgcolor, this); } else { ! ASDrawer.current.drawFillWithRectColorInView(frame, m_bgcolor, this); } --- 1363,1371 ---- if (m_drawscellbg) { ! ASTheme.current().drawFillWithRectColorInView(frame, m_cellbgcolor, this); } else { ! ASTheme.current().drawFillWithRectColorInView(frame, m_bgcolor, this); } *************** *** 1543,1548 **** public function mouseDown(theEvent:NSEvent):Boolean { ! TRACE("hit mousedown"); ! m_mousedownflags = theEvent.modifierFlags; return false; } --- 1673,1717 ---- public function mouseDown(theEvent:NSEvent):Boolean { ! TRACE(theEvent); // debug info ! ! m_mousedownflags = theEvent.modifierFlags; // record flags ! ! // ! // Get the location of the cell, then the cell itself (if available). ! // ! var pt:NSPoint = convertPointFromView(theEvent.mouseLocation, null); ! ! TRACE(pt); ! ! var loc:Object = getRowColumnForPoint(pt); ! ! TRACE("row: " + loc.row + ", column: " + loc.column); ! ! /* ! if (theEvent.clickCount == 2 && loc == null) ! { ! return sendDoubleAction(); ! } ! ! var cell:NSCell = cellAtRowColumn(loc.row, loc.column); ! ! switch (cell.type()) ! { ! case NSCellType.NSTextCellType: ! cell.s ! break; ! ! case NSCellType.NSImageCellType: ! ! break; ! ! case NSCellType.NSNullCellType: ! ! default: ! ! break; ! ! } ! */ return false; } *************** *** 1553,1556 **** --- 1722,1728 ---- //****************************************************** + /** + * Draws the thing. + */ public function drawRect(rect:NSRect):Void { *************** *** 1560,1564 **** if (m_drawsbg) { ! ASDrawer.current.drawFillWithRectColorInView(rect, m_bgcolor, this); } --- 1732,1736 ---- if (m_drawsbg) { ! ASTheme.current().drawFillWithRectColorInView(rect, m_bgcolor, this); } *************** *** 1845,1849 **** m_sel.removeObject(toDelete[i]); } ! //****************************************************** //* Public Static Properties * --- 2017,2034 ---- m_sel.removeObject(toDelete[i]); } ! ! ! /** ! * Recalculates the cell size. ! */ ! private function recalcCellSize():Void ! { ! m_cellsize = new NSSize( ! (m_frame.size.width - (m_cellspacing.width * (m_numcols + 1))) / m_numcols, ! (m_frame.size.height - (m_cellspacing.height * (m_numrows + 1))) / m_numrows); ! ! TRACE(m_cellsize); ! } ! //****************************************************** //* Public Static Properties * |