On 19 Mar 2009, at 6:28 AM, Yvonne Du wrote: Hi, Please ignore the first email sent by me. I sent it out by mistake.a I write a custom class which has two NSPopupButtonCells. The interface looks like this: @interface CustomCellArray:NSCell { NSMutableArray * cells; } @end in this array cells, it contains two NSPopupButtonCells. I embed this custom cell CustomCellArray in the column B of a NSTableView. It works well to show the two NSPopupButtonCells, and respond to the mouse events. But I have problems when add accessibility support for this kind of custom cell. I override the NSTalbeView's - (id)accessibilityHitTest:(NSPoint)point like this. the uiElements is an array hosted in the NSTableView. the FauxUIElement has adopted the NSAccessibility protocol. - (id)accessibilityHitTest:(NSPoint)point { id result = [super accessibilityHitTest:point]; NSPoint windowPoint = [[self window] convertScreenToBase:point]; NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; NSInteger row = [self rowAtPoint:localPoint]; NSInteger col = [self columnAtPoint:localPoint]; if(col == 1 &&row >= 0) //hit the valid row and the customized column { if(uiElements == nil) { FauxUIElement * ele1 = [FauxUIElement elementWithRole:NSAccessibilityPopUpButtonRole parent: self]; FauxUIElement * ele2 = [FauxUIElement elementWithRole:NSAccessibilityPopUpButtonRole parent: self]; uiElements = [[NSArray alloc] initWithObjects:ele1, ele2, nil]; } NSRect cellFrame = [self frameOfCellAtColumn:col row: row]; NSRect cell1 = cellFrame; cell1.size.width = cellFrame.size.width * 0.6; NSRect cell2 = cellFrame; cell2.origin.x = cell1.origin.x + cell1.size.width; cell2.size.width = cellFrame.size.width * 0.4; if(NSPointInRect(localPoint, cell1)) //check whether it hits the first popupcell or the second one. return [uiElements objectAtIndex:0]; else if(NSPointInRect(localPoint, cell2)) return [uiElements objectAtIndex:1]; } return result; }
But when I use the accessibility inspector to check it. the two cells are marked as AXUnknown. I also wonder is it a right place to override the accessiblityHitTest in NSTableView to achieve this? Any suggestions? Thanks. I'd say that at least the UI elements must be in the accessibility hierarchy, i.e. as children. This method by itself is therefore not sufficient.
However, NSTableView has some custom handling of its cell children for accessibility, it does not strictly follow the generic rules. This is due to the fact that cells in a tableview are shared, so they can't by themselves act as the UI elements. How NSTableView does this is, unfortunately, not documented and not part of the API. This makes it very hard, if not impossible, to modify this. I would expect that changing the children of the NSTableView is not possible, so your idea almost certainly won't work.
However the UI elements the NSTableView creates must be based on the cells, which implement NSAccessibility. Here's a strategy that may work, though I don't know for sure (haven't tried). Make the cell an AXGroup, and add the faux UI elements for the subcells as children.
Christiaan
|