VirtualStringTree OnNodeRightClick - delphi-7

I am looking for a procedure or something that gets fired if I right click on a Node (or in general on the VirtualStringTree)
I have the following scenario:
I have my VST close to a listview.
I can only multi select root nodes with the mouse (hold mousebutton and move the mouse)
If I click on ANY child node (right or left) - it is selected (+ [VSelected] State)
If I right click on a root node it selects automatically and opens a popupmenu.
Now I would like to have a different popupmenu for ( 1 common ) for all my child nodes (and only if they are selected).
Hope you can understand what I mean, thank your for your help.

I won't answer your question but point you to the right event since you've said you want to have different popup menu for each node. The right click solution would have a weakness at least in missing menu key press which invokes the popup menu as well.
1.1 How to use different popup menu for each node depending on node level ?
procedure TForm1.VirtualTreeGetPopupMenu(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; const P: TPoint;
var AskParent: Boolean; var PopupMenu: TPopupMenu);
begin
case VirtualTree.GetNodeLevel(Node) of
0: PopupMenu := PopupMenu1;
1: PopupMenu := PopupMenu2;
end;
end;
1.2 How to enable right mouse button click node selection ?
And to allow the right mouse button node selection, simply add the toRightClickSelect option to the TreeOptions.SelectionOptions option set.

You can use the normal OnMouseDown event, make sure the Button is mbRight and then use the GetHitTestInfoAt function to check which node is under the cursor (if there is any).
var
HitInfo : THitInfo;
...
TreeView.GetHitTestInfoAt(X, Y, HitInfo);
if (HitInfo.Node = ?) and (HitInfo.Column = ?) then
begin
...
end;
There is also OnGetPopupMenu which gives you a node and a column and lets you return any TPopupMenu.

Related

MFC: CListView: Why SetItemState(-1, 0, LVIS_SELECTED) doesn't work if multiple items were selected with SHIFT + arrow key?

Easy to reproduce problem using default MFC dialog application:
Add listview control and link it to CListCtrl class - m_listCtrl.
Enable "owner data" or LVS_OWNERDATA flag to enable virtual list view mode. Enable multiple selection and "Always show selection".
In OnInitDialog() add at least one column and call m_listCtrl.SetItemCount() to set number of items in the list to more than one.
Link button click with a method that calls m_listCtrl.SetItemState(-1, 0, LVIS_SELECTED); That call should deselect all entries in the list.
Click on item in the list and use SHIFT + arrow key to extend selection to at least two entries. If selection is extended with mouse or CTRL + click or CTRL + SHIFT, then the issue doesn't appear.
Click on a button that triggers SetItemState() call in step (4) and notice that items don't get deselected the first time. They only get deselected the second time.
Is that a bug in listview control or am I doing something wrong?
Calling m_listCtrl.SetItemState(-1, 0, LVIS_SELECTED); should deselect all entries with the first call, but it does so only when called twice.

JavaFX: Disable all Buttons from a ToggleGroup

Like the title says, i want to disable all Buttons in a Togglegroup. I know it is possible to select the Buttons individually and button.setDisable(true).
But is there a possibillity like group.setDisable(true)?
Thanks for any help or hints.
Greetings
If all the toggles are in the same container (Group or Pane), and there is nothing else in that container (at least, nothing that you care about being disabled, so Labels might be OK), then you can just disable the container (the disabled state propagates to child nodes).
Otherwise there is no direct way to do this: you can just iterate through the toggles, use the appropriate cast, and disable it:
toggleGroup.getToggles().forEach(toggle -> {
Node node = (Node) toggle ;
node.setDisable(true);
});

show a popup menu when I left click on a button in oracle form

I have created a popup menu and assigned it into a button,when i right click
the button the popup menu will be displayed.Now i want if i normally click the
button that is left click the popup menu to be displayed
It works in Oracle Forms 6:
declare
w_id pls_integer;
begin
w_id := GET_ITEM_PROPERTY(Find_Item('CONTROL.B_REPORTS'), WINDOW_HANDLE);
WIN_API_SHELL.SendMessage( w_id, 516 ); -- WM_RBUTTONDOWN
WIN_API_SHELL.SendMessage( w_id, 517 ); -- WM_RBUTTONUP
end;
I completely agree with #APC above; this is not a standard UI convention. And it is not possible to override the default functionality of the right click menu within Forms. You could however, build a small window/canvas/block made to look like the right click menu and default it's starting window position to be the mouse X,Y coordinate.

Creating a menu button in Windows

Microsoft's User Experience Interaction Guidelines give some UI guidelines for when to use a menu button:
http://i.msdn.microsoft.com/Aa511453.command51(en-us,MSDN.10).png
How do I create one of these menu buttons? I've found information on
how to create a split button in Vista and above
how to create a toolbar button with a dropdown menu
how to create a regular pushbutton and manually wire up an OnClick event handler that pops up a menu
But is there any standard way to create a button, not in a toolbar, with the little down triangle, that automatically pops up a menu when clicked?
(I'm using Delphi / C++Builder, but other solutions are welcome.)
You can use the OnClick to force the popup, and for consistency don't use the cursor position, but rather the control position.
procedure TForm1.Button1Click(Sender: TObject);
var
pt : TPoint;
begin
Pt.X := Button1.Left;
Pt.Y := Button1.Top+Button1.Height;
pt := ClientToScreen(Pt);
PopupMenu1.Popup(pt.x,pt.y);
end;
You can then add the "glyph" using either a Delphi 2010 button, or a previous version TBitBtn and assign the bitmap/glyph property to an appropriate image and align right.
You don't mention which version of Delphi you are using, but in Delphi 2010 TButton has new properties for this: DropDownList which can be associated with a TPopupMenu to define the menu items, and Style which can be set to bsSplitButton.
This produces a button that you can press that also has a dropdown arrow on the right of it, To make the menu popup when you click to the left of the arrow this code in the button click handler should do the job.
procedure TForm1.Button1Click(Sender: TObject);
var
CursorPos: TPoint;
begin
GetCursorPos(CursorPos);
PopupMenu1.Popup(CursorPos.X, CursorPos.Y);
end;
in previous versions of Delphi I think you had to use TToolBar.

How to position a Popup menu right underneath a button in VB6

I have a VB6 app. There is a main form. It houses a user control. This user control has a button control. When I click the button, I want a menu to pop up so that the top left of the menu is right underneath the bottom left of the button.
if I do:
frm.PopupMenu mnuBlah
the menu comes up where the mouse is.
if I try to provide coordinates
frm.PopupMenu mnuBlah, btn.Left, btn.Top + btn.Height
the math comes out totally wrong and the menu is displayed way off target.
I am not quite sure what type of coordinates the PopupMenu call requires and how to calculate the position underneath the button.
PopupMenu wants X and Y coordinates in the ScaleMode of the form on which the menu is being popped up. In this case, that probably means the user control.
But it really depends on where you're handling the MouseDown event. (You don't get coordinates with the Click event.) If your event handler is in the user control itself, then you shouldn't have any problem using the supplied coordinates. However, the code you posted is missing the Flags parameter (should be vbPopupMenuLeftAlign), which could explain why your coordinate math isn't working. Plus, you have to define the menu as a property of the user control itself.
On the other hand, if you raise the MouseDown event out of the user control, and handle it in the containing form, the popup menu has to be a property of the containing form. In this case, you can ignore the X and Y parameters, but you have to do coordinate calculations yourself. The left edge of the button, relative to the main form, will be the sum of user control's left edge and the offset of the button within the control. Similar math will work to calculate the bottom edge of the button. In other words:
Private Sub UserControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PopupMenu mnuPopup, vbPopupMenuLeftAlign, _
UserControl1.Left + UserControl1.Button.Left, _
UserControl1.Top + UserControl1.Button.Top + UserControl1.Button.Height
End Sub
Note that this will require that you also expose the button (Button) as a property of the user control so that you can access its Left, Top, and Height properties. That's easy enough:
Public Property Get Button() As CommandButton
Set Button = Command1
End Property
Raising the event is simple enough as well; just put
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
at the top of the user control, then use this:
RaiseEvent MouseDown(Button, Shift, X, Y)
in the MouseDown event of the button in the user control.
Finally, to wire up the event handler in the main form, use the two dropdowns at the top of the code editing window. Select the user control from the one on the left, then select the MouseDown event from the one on the right. This will insert the event handler, which you fill in with the code above.
As far as which way is better, handling the menu inside the user control itself, and raising meaningful events when one is selected keeps things separated. The user control handles the UI work, leaving the main application to handle whatever needs to be done in response to the user's selection, without worrying about placement of the menu.
So you wouldn't actually be raising the MouseDown event; rather you'd raise events like OptionOneSelected, OptionTwoSelected, or OptionThreeSelected. (More meaningful names would be much better, of course.)
Anyway, I hope this isn't too late to be helpful...
You need to pass the vbPopupMenuLeftAlign flag to the PopupMenu method. Note, this contradicts the documentation on the PopupMenu method (could Microsoft actually have made a mistake?), but it works.
frm.PopupMenu mnuBlah, vbPopupMenuLeftAlign, btn.Left, btn.Top + btn.Height
You need to include the height and left values for the parent container (this is usually the form, but could also be a frame, or some other container).
I think you're looking for something like this:
btn.Parent.PopupMenu mnuBlah, vbPopupMenuLeftAlign , btn.Left, btn.Top + btn.Height

Resources