How to programatically manipulate a popup menu on multiple dynamic widgets in Progress - menu

Language: Progress 10.1C
I have a Windows form, and on it I dynamically create a number of widgets (toggle-boxes in this case). I can create anything from 0 to 64 widgets, depending on how many do-hickies the user has in the current collection. As the user changes from one collection to another, the widgets are deleted or created as needed. The form will resize according to how many widgets are displayed.
The user can check any number of them and perform certain processes on the checked items by selecting actions from a menu bar, toolbar or keyboard shortcuts. But I also want the user to be able to right-click on a single widget, which should bring up a popup menu with actions that can be performed on just the one clicked item, whether it's checked or not.
In itself, this is pretty straight forward. In the past I had done this kind of thing (in other languages) by having a single popup menu that pops up when the user clicks on any one of the dynamic controls. But I'm having a hard time doing this simple thing in Progress:
I am unable to have one popup menu that responds to the right-click of all the widgets. I tried creating a single popup menu, and then as I create each dynamic widget, I set its popup-menu attribute to this menu. The problem is that a menu can only be applied to one widget. Once I've assigned it to Widget1, I cannot assign it to Widget2. This leads one to think of creating a seperate but identical menu for each widget. And as the widgets are destroyed and recreated, so will these menus. In a single session I will create and destroy hundreds or even thousands of these identical menus, while the user might use one of them once or twice. Or not at all. So this does not seem like a good option to me.
My next solution would be to create a single menu which I can pop up programatically, but all attempts to programatically pop up a menu have failed. I have tried APPLY "MENU-DROP" TO MENU MyMenu and other similar things and I cannot for the life of me figure out how to do it. I also find it very difficult to search for information on this. It's as if nobody else has ever tried this, and the rare cases where someone has asked about it, there has been no satisfactory answers. I'm suspecting this cannot be done.
While trying all these things, I have also had endless problems with the events MOUSE-MENU-DOWN, MOUSE-MENU-UP and MOUSE-MENU-CLICK. MOUSE-MENU-CLICK seems to never happen, not for my dynamic widgets anyway. I am unable to figure out why. MOUSE-MENU-UP occurs sometimes, but it depends on what happens in MOUSE-MENU-DOWN and other events of the widgets as well as the widgets' parents. I have not been able to figure out exactly when it will or won't fire, it's very counter-intuitive. MOUSE-MENU-DOWN is the only one I can count on firing.
So: I can't show a menu programatically, I can only show it by right clicking on the menu's parent. The only way to avoid having hundreds of identical menus, is to have a popup menu on the parent of the widgets, for example the default frame.
With a static popup menu on the default frame, I can right-click on the widgets and the menu will come up, but it comes up if I click anywhere in the frame. I can disable the menu, and then in the right-click event of the widget, I enable it. This works very well the first time; if I click anywhere in the frame, nothing happens (the menu is diabled), but if I click on my widget, the menu is enabled and pops up. Yay! But now the menu is enabled and now it pops up if I right-click anywhere, on buttons, empty space, progress bars, etc. When do I disable it again? After the menu has popped up, the user can click anywhere and the menu will dissappear. There is no event that fires when the menu is closed, so I'm stuck.
Sorry about the long ramblings, I'll restate the question briefly: I want to have one popup menu that pops up when the user right-clicks one of a number of dynamically created widgets.
Using Tom's answer, this is how I implemented it:
/* Somewhere in Control Definitions... */
DEFINE MENU m_Popup
MENU-ITEM m_Test1 LABEL "Test 1"
MENU-ITEM m_Test2 LABEL "Test 2".
/* Somewhere, where I need to dynamically create the widgets. */
/* Loop through the items in the temp table and create a widget for each. */
FOR EACH ttItem BY ttItem.ItemName:
CREATE TOGGLE-BOX hWidget
ASSIGN
FRAME = FRAME DEFAULT-FRAME:HANDLE
LABEL = STRING(ttItem.ttItemName)
TRIGGERS:
ON MOUSE-MENU-DOWN PERSISTENT RUN GetMenu IN THIS-PROCEDURE.
END TRIGGERS.
END.
/* If the user right-clicks on any one of the widgets, this procedure */
/* is run with SELF being the widget that was clicked on. */
PROCEDURE GetMenu:
/* Remove the menu from its current owner and assign it to SELF. */
MENU m_Popup:OWNER:POPUP-MENU = ?.
SELF:POPUP-MENU = MENU m_Popup:HANDLE.
END PROCEDURE.
/* The user clicks on one of the menu items */
/* Here SELF is the menu item that was clicked. I can */
/* get m_Popup from SELF:PARENT and the widget it was */
/* was assigned to from SELF:PARENT:OWNER. */
ON CHOOSE OF MENU-ITEM m_Test1
DO:
MESSAGE "You selected " SELF:LABEL " for " SELF:PARENT:OWNER:LABEL.
END.

My buddy Mike Fechner (who is not currently on SO but who does this stuff a lot more than I do) tells me that, while this example is static, something very similar should work:
Procedure getMenu:
DEFINE INPUT PARAMETER phWidget AS HANDLE NO-UNDO.
DO WITH FRAME {&FRAME-NAME}:
FILL-IN-1:POPUP-MENU = ? .
FILL-IN-2:POPUP-MENU = ? .
FILL-IN-3:POPUP-MENU = ? .
END.
phWidget:POPUP-MENU = MENU POPUP-MENU-FILL-IN-1:HANDLE .
END procedure.
ON RIGHT-MOUSE-DOWN of all three fill-in’s you "RUN getMenu (SELF)." to steal the popup menu from whomever has it.

Related

Keep taskbar icon, replace MFC dialog

I have a MFC dialog based application. User can change the language of the dialog, and I made this by closing existing dialog, and opening another with changed language. The problem is that the effect in the taskbar is that one icon is removed, and another identical is created in its place. If my application's icon is not the last icon in the task bar it will be perceived as it was moved to the end of taskbar icon set.
I want to retain icon's position in the taskbar, and rather to prevent icon flicker at all from happening. How do I do that?
The application must support OS'es from Windows XP to Windows 7.
EDIT: alternative question for which I would accept an answer is how to create an invisible window that is nevertheless shown in the taskbar, and how to forward relevant window messages from that window to my main window?
Make the dialog a child of another outer parent window. The parent can be a dialog or any other kind of window; all it will be providing is the title bar. If the user tries to resize it it will have to forward resizing commands to the dialog, but otherwise you shouldn't need to do much in the parent window.
Why not replace the dialog with a CFormView instead? That way there's a frame window that wraps around the dialog (which is embedded in a form view) and it's the frame window that owns the taskbar icon.
Create an SDI application that displays a CFormView. Display the dialog in the default language (or whatever langauge the user previously chose) on initialization. When the user chooses the 'change language' option, simply change the form view that's being displayed with a new one.
Bonus feature: with this design, the framework will take care of things like language-specific accelerators and menus for you with no effort on your part.
For more on how to do this, check out http://www.codeguru.com/cpp/w-d/doc_view/viewmanagement/article.php/c3341/Multiple-Views-Using-SDI.htm

Selecting and Deselecting segment on UISegmentedControl?

I've added a segmented control as the right bar button item of my navigation bar. The control has two segments and I'm attempting to use the control as bar button items. So I was wondering haw can I deselect a selected segment once the user preses it. I've already tried setting the selectedSegmentIndex property to -1 when the action method is called but that is preventing the segment from even being highlighted. Any idea on how can can get the segments to behave like bar button item?
do segmentedControl.momentary = YES; during setup or if using IB, select the Momentary checkbox in the Attributes Inspector.

left and right command menus in LWUIT form

Using LWUIT framework to develop mobile application.
In LWUIT by default first command is placed in the left and subsequent commands will be placed in the right menu of the form including the command which is already placed in form left.I need to add two menus to form.Left menu contains general application specific commands such as "Minimize","Back" and "Exit". Right Menu contains screen specific commands such as "Play Audio","Play Video" etc... Initially left softbutton of the form contains the text "Options" and the right softbutton of the form contains the text "Menu". When user selects "Options", a menu will be displayed with the following commands:
Minimize
Back
Exit
When user selects right soft button "Menu", a menu will be displayed with screen specific commands:
Play Audio
Play Video etc...
Commands of the right menu keeps changing from one form to another form, whereas the commands of left menu remains the same for all screens(forms). I know command menu can be customized by overriding "Form.createCommandList(Vector)" which returns a list. But here in my case I need two lists(menus). One at the left of the form and the other one at the right of the form.Please do help me in resolving this issue.
A LWUIT menu is just a dialog containing a List (or buttons for touch menu or pretty much anything you want), so to implement this just create a Command called options and place it in the left soft button. When options is pressed just show the dialog with your "additional commands". Since a List can accept a command array or vector doing something like this can be really easy.
You can look at the code for MenuBar which is pretty simple, you can also replace the menu bar component in the latest version LWUIT (SVN at the moment) but that seems redundant for this particular use case.

SharePoint 2007 navigation and removing its delay

In SharePoint 2007, there's a top nav that the user can hover over, which reveals a dropdown menu of subitems. When they remove their mouse from the dropdown, it disappears, but only after a short delay. This can cause problems, as if people are trying to click a link on the page somewhere, but the nav menu hasn't hidden itself yet, they'll accidentally click it instead. This is compounded with the fact that the menu appearing in the first place is delayed as well, so right before they mouse over the link on the page they actually want to click, the menu will suddenly appear and intercept their click when they weren't meaning to.
I've poked at core.js at some suspect areas, but can't seem to nail it down. Any thoughts?
This is the normal behaviour of SharePoint. This control is the asp:Menu control of ASP.Net 2.0 and the only thing you can do is customized the MasterPage or the DefaultPage of your Site.
If you change the core.js file of "layouts" folder you'll lose Microsoft support, so take care about change any of the file from this folder.
I recommend that you modify the existent control or create a new one and put it in this position of the MasterPage.
This bit of CSS will fix it. I just had the same thing in sharepoint 2010 and this was all that was required to make the list disappear as soon as you roll off:
li.hover-off>ul
{
display:none;
}
The way it works is when you hover over an item in the nav it adds a css class called "hover" and as soon as your mouse leaves the area it changes the class to "hover-off" for 1 second before removing it completely. This CSS will hide the unordered list directly below the list item that has the class "hover-off" thus hiding the flyout as soon as your mouse leaves the parent.

Altering the YUI menu's mousing behavior

I'm using Yui to build a "popup" menu that works a bit differently with the mouse than usual. This is not a ContextMenu, because I want it to respond to left clicks, and the ContextMenu seems bent on responding to right clicks.
Following the examples, if I do this, the menu comes up and everything is close to how I want it:
YAHOO.util.Event.addListener(myClickTarget, 'click', myThingGotClicked);
In my myThingGotClicked function, I manually set the menu's position and show() it.
My problem is that I want to "bind" the menu visibility to the state of the mouse button. That is, on a mouseDown, I want the menu to come up, and on a mouseUp, I want the menu to disappear (selecting the active item, if any). So, listening to the 'click' event doesn't do the right thing, because a "click" is only sent after mouseUp.
The "obvious" solution is to do this:
YAHOO.util.Event.addListener(myClickTarget, 'mousedown', myThingGotClicked);
But this doesn't work. Stepping through in a debugger, you can see that it does actually bring up the menu on a mousedown, but then something immediately hides the menu. At full speed, it looks like nothing happens at all.
Any thoughts?
The problem is that the MenuManager class listens for the mousedown event at the document level and hides all visible Menu instances. So, since you are building a unique sort of Menu implementation, you'll need to stop the propagation of the mousedown event inside your handler so that the MenuManager doesn't handle the event. Here is some pseudo code for you:
var myThingGotClicked = function (event) {
YAHOO.util.Event.stopPropagation(event);
// Do other stuff
};
YAHOO.util.Event.on(myClickTarget, 'mousedown', myThingGotClicked);
Todd
That's a bit closer, as the menu does pop up, but if you try to make a selection in the menu, the text selection of the page underneath goes sort of nuts. I also need to add a mouseup handler, I think, as the menu doesn't go down on mouse release.
What I really want here are menus that work like menus on every version of the Mac OS (until more recently when OS X added the "click to make the menu 'sticky' to the default behavior).

Resources