Enabling checkboxes in treeitems of ctreecntrl - windows

I am trying to enable/disable checkboxes in treeitems in ctreecntrl of visual c++ 6.0. I have found the options to do that for all items, but couldn't do that per item basis. Is there any function to do that?

To turn checkboxes on and off for individual tree items, you need to send TVM_SETITEM messages, which are used to set attributes for items in a TreeView.
The documentation says the wParam must be zero, and the lParam is a pointer to a TVITEM structure that contains the new item attributes.
So the real battle is in getting the TVITEM structure filled out accordingly. Here are the important parts:
The hItem member must contain the handle to the tree item that you want to modify.
The mask member should be set to TVIF_STATE, which indicates that the state and stateMask members are valid. Those are the ones you'll be using to turn checkboxes on and off.
The state member can be set to 0, which will hide the checkbox for the specified tree item.
To show the checkbox for the tree item, set this member of 1 << 12. (See the docs for details).
The stateMask member should be set to TVIS_STATEIMAGEMASK to indicate that you're changing the item's state image index.
Since you've set mask to indicate that you're only using the state and stateMask members, you can happily ignore the rest of the members.
And finally, once you've got the TVITEM structure set, you can either use the standard SendMessage function, or the TreeView_SetItem macro, to send the message to the tree item.
(Of course, the entire TreeView must have the TVS_CHECKBOXES style set in order for any of the above to work! But you said you already figured out how to do that.)

Related

CarouselView control: how to block user from getting to the next item in certain situations

I use the latest ver of .Net Maui. In the scenario there is ObservableCollection of items bound to ItemsSource's CarouselView. User is supposed to do some actions upon the current item to make it "valid" in order to be able to move to the next one. CarouselView should block user from swiping card to the next one until the current one is valid, and valid state is defined by properties of the item.
First thing that came my mind was to subscribe for one of Scroll or PositionChanged event and cancel the action propagation, but I do not think the events are cancelable, did not find it in the even arguments. Second less desirable way to implement is to add items dynamically to the ObservableCollection of items once current item got valid. It won't be able to go to the next just because the current is always the last. It though seems to be a bit of a hacky way to resolve this, and I would prefer to implement it on a view level rather than model level (adding items on the fly). So if you know more direct ways to get it implemented please let me know. Thanks.
Update: I'd like users to be able to swipe to all previously handled items (all valid), getting back and forward, but only for valid cards.
Set the property IsSwipeEnable to false when the current item is not yet valid.
From docs
IsSwipeEnabled, of type bool, which determines whether a swipe gesture will change the displayed item. The default value is true.

winapi - WM_MEASUREITEM - how to determine an event source

I use a custom-drawn context menu (MFT_OWNERDRAW). I handle WM_MEASUREITEM and WM_DRAWITEM messages.
For the WM_DRAWITEM message, I can identify the event source based on the DRAWITEMSTRUCT structure. It contains hwndItem - for menus, this member is a handle to the menu that contains the item.
The MEASUREITEMSTRUCT structure doesn't contain such information. Is it possible to somehow determine the event source for WM_MEASUREITEM?
EDIT: I can use itemData to send some custom struct. When handling WM_MEASUREITEM, I have to cast ULONG_PTR to my struct, eg:
A* a = (A*)item->itemData
What if WM_MEASUREITEM is sent for some other control with a different itemData, for example a B struct? How to determine that at runtime?
According to the WM_MEASUREITEM:
Contains the value of the CtlID member of the MEASUREITEMSTRUCT structure pointed to by the lParam parameter. This value identifies the control that sent the WM_MEASUREITEM message. If the value is zero, the message was sent by a menu. If the value is nonzero, the message was sent by a combo box or by a list box. If the value is nonzero, and the value of the itemID member of the MEASUREITEMSTRUCT pointed to by lParam is (UINT) 1, the message was sent by a combo edit field.
The CtlID is the identifier of the combo box or list box and itemID is the identifier for a menu item or the position of a list box or combo box item MEASUREITEMSTRUCT.You can use them to distinguish different controls.

How to bind hidden property in a control when a integer equals some certain value in OSX?

I've got a RadioGroup with 3 cells. I want to hide some controls when the selected index in radio group is 1. That is:
[someControl setHidden: radioGroup.selectedIndex == 1];
I've got a lot of controls will show/hidden when radio group selection changed. Some might show when the selected index equals 0, some might show when equals 2.
I want it to be done by binding, not connect each control reference using outlet.
How to acheive that?
There are at least two ways of doing this, as binding hidden requires a Boolean balue:
Create a property that is of type BOOL and returns YES or NO based on your value comparison, then in your class use KVO to observe the original value and set the Boolean property inside of the KVO observer (this is required to make sure the object is updated at the right time)
Use bindings alone, but create a Value Transformer to transform each value you need into a BOOL as necessary to be interpreted correctly. There is an existing value transformer that changes YES to NO and vice-versa, but for other value transforms you will have to create these yourself, and there is no good way to parametrize them inside of the xib file.
The first solution is probably easier.

WP7 - Implementing a tree of comments. ListBox, Tree controls, etc?

I want to implement a screen to display a tree of comments in WP7. Each comment can have children comments and so on. Each child comment will be visually distinct from its parent via indenting
ie:
"comment text"
"Some child comment text"
"Some child comment text"
"some child comment text"
"comment text"
"Some child comment text"
What would be the best way to go about implementing this? I'd like to keep the implementation as simple as possible so initially I was thinking I could use a single ListBox and programmatically set the Padding/Margin of each comment/ListItem, depending on its depth in the tree. But I can't seem to get it working. Any examples, suggestions, recommendations, etc?
Edit: Doing some additional reading, it seems like a DataTrigger would have been perfect for this sort of thing http://www.codeproject.com/Articles/113152/Applying-Data-Templates-Dynamically-by-Type-in-WP7 ...But WP7 doesn't support triggers.
One other idea I had was to make the Margin/Padding a Property of the Comment class, and then databind to that...this should work, but I'm contaminating my Comment class with display information. Any ideas on how I could databind the Margin/Padding value but somehow not mix model & view codes?
You'll have to roll your own, either from scratch, or by assembling something out of existing controls. ListBox looks like a good bet for this purpose.
Take a peek at this MSDN thread (web archive - thread now moved/deleted), it has several suggestions about simulating a TreeView using a ListBox, and a claim (which I have not verified) that you can use System.Windows.Controls.TreeView in WP7 (with the caveat that you also need System.Windows.Controls.Toolkit).
The marked answer, written by Shaun Taulbee:
Tree view behaviour in a listbox could be mimiced with a bit of smarts in the collection handling. Features your classes would need to support that come to mind are
a collection whose elements supports retrieving child collections
similarly to be able to detect if an element has child collections
in the data template for the listbox show one element of the stackpanel for expansion state based on presence of children and whether or not expanded
in the data template for the listbox show one element of the stackpanel for indent which reflects the depth of the child - to accomplish this best you should have a collection that represents a flat version of your tree data to bind to - then when you insert items you can make the indent based on the indent of the parent item that was just clicked
when a node is clicked in the listbox you insert the children from that node into the flat collection that the listbox is bound to
when the node is clicked again the children are deleted from the flat collection
You could encapsulate all of this into some neat classes to provide a fairly simple reusable api I would imagine if you wanted.
This thread has a fair amount of noise, but down at the bottom there's a comment from Mark Chamberlain:
"TreeView is not a natural fit for the phone, you can emulate Treeview
in other ways, for example, with ListBox item templates, Pivot or with
other List patterns. It will depend on how many levels of the tree
you will have.
"For example, you can template your ListItem to contain a label and
another Listbox with same item template. Doing this you can emulate
as many drill in levels as you need to handle, but only one branch at
a time."
"You may be able to re-template the TreeView (source is also available
in the Silverlight Toolkit), but it isn’t a supported scenario, and
you would need to do a decent amount of work to get it looking good on
the phone from a design & re-templating standpoint."
The following should be good starting points, both altering the ItemTemplate for a ListBox control :-
http://3water.wordpress.com/2010/07/25/listbox-on-wp7/
http://weblogs.asp.net/psheriff/archive/2010/10/27/windows-phone-list-box-with-images.aspx
For WP8 you can use this one TreeView_WP8

Enabling NSButton with bindings, based on NSTableView selection

I have a NSWindow containing an NSButton and an NSTableView.
I'd like the button to be enabled if and only if the table contains at least one item, and exactly one item is selected. (The table does not allow multiple selection.)
What can I bind the button's enabled binding to to make this happen?
This is an old thread, but here are my 2 cents:
Use and array controller and bind the button's enabled state to
Controller Key: selectedObjects
Model Key Path: #count
Works fine.
Try binding to the array controller's selectedObjects, model key path count, with no value transformer.
Note that this would be unsafe if you allowed multiple selection: For one thing, the count could easily be neither YES nor NO; for another, if the user selected a multiple of 256 items, the lowest byte of the count would be 0, so the BOOL value would be NO even though there is a selection.
I ran into this today and I got it to work after some efforts.
My button should be disabled if nothing is selected in the "Master Table":
Problems I ran into:
Use the actual button and not the enclosed Button cell
Specify NO = disabled for Multiple values, No selection etc.
Bind the Enabled property to the Master Table's selection and use a property (code in my case), which is present.
Use the transformer NSIsNotNil to enable the button if something is selected in the master table.

Resources