Hi,
Is it possible to provide TreeView with two icons (one for expanded & one for collapsed node)? I can't find a way & all tree usages in Dolphin are using only one type of icon... Quite bizzare. mm_aa |
mm_aa wrote:
> Is it possible to provide TreeView with two icons (one for expanded & > one for collapsed node)? As far as I know there's no really straightforward way of doing it, but it should be possible even so. You need to make the #getImageBlock of the TreeView answer an appropriate icon, but to do that there are a few obstacles. One is that you can only find out if an object's node is expanded by asking the View, but that means that you can't just enter a simple Block expression in the View Composer (since, when the Block is evaluated at run-time, there's no obvious way of getting a reference to the View). The best approach that I've discovered so far is to set the #getImageBlock from the Presenter's #onViewOpened method, at which time you could say something like: self view getImageBlock: [:it | self iconIndexFor: it]. where your #iconImageFor: method will check with the View to see if "it" is expanded before deciding what icon's index to answer. The next slight nuisance is that TreeView provides (again, as far as I know) no direct way to tell if an object's node is expanded. The best way that I know of is first to see if the object has any children, and then to check if any one of *them* is visible. The last problem is how to find out if the child is visible. I don't know of a better way than to use the TreeView's private method #handleFromObject: which will answer some number if the child is displayed and nil otherwise. HTH -- chris |
Chris Uppal wrote:
> You need to make the #getImageBlock of the TreeView answer an appropriate > icon, but to do that there are a few obstacles. > > One is that you can only find out if an object's node is expanded by asking > the View, but that means that you can't just enter a simple Block expression > in the View Composer (since, when the Block is evaluated at run-time, there's > no obvious way of getting a reference to the View). The best approach that > I've discovered so far is to set the #getImageBlock from the Presenter's > #onViewOpened method, at which time you could say something like: > self view getImageBlock: [:it | self iconIndexFor: it]. > where your #iconImageFor: method will check with the View to see if "it" is > expanded before deciding what icon's index to answer. ...and you can then check the expanded state of "it" via the following route: handle := yourTreeView handleFromObject: it. tvItem := yourTreeView getItemState: handle. isExpanded := tvItem dwState anyMask: ##(CommCtrlConstants at: 'TVIS_EXPANDED'). Unfortunately, when testing this out I found that the 'old' icon wasn't being erased when an item expanded/collapsed. I got round this by amending TreeView>>tvnItemExpanded: tvnItemExpanded: pNMHDR | tviNew nmtv | nmtv := self notificationClass fromAddress: pNMHDR. (nmtv action = TVE_EXPAND or: [nmtv action = TVE_COLLAPSE]) ifTrue: [tviNew := nmtv itemNew. self onItemUpdated:(self objectFromHandle: tviNew hItem)]. ^nil ...although you probably don't want to do this for all tree views, so you may want to add a way to flag an individual tree view as 'update icons on expand'. Hope this helps, John Aspinall Solutions Software http://www.solutionsoft.co.uk |
Free forum by Nabble | Edit this page |