On Thu, Jun 27, 2002 at 04:28:54PM +0200, [EMAIL PROTECTED] wrote:
> Hi!
> 
> Although it seems, that I'm alone on this list I'm not too shy to ask

The list can be quiet.. there's usually more lively conversation in IRC :)

> another question. I'm in the process of porting a small editor MP,
> 
> http://www.triptoco.com
> 
> to PGUI. I have the problem, that this editor has dynamic menues. This
> means, I need to make a menu, step by step, hide it and let it pop up,
> if I press the button in the uppermost menubar. This is a wellknown
> task in many other widget toolkits. The problem is, that PGUI does not
> have such a "menu" widget. Maybe, this is not needed...
> 
> All the examples that come with PGUI seem to use hardcoded menues.
> They work in that way, that they build up the menu at the time, where
> a callback funtion is called. But this means, that the menu is
> hardcoded in this function.

Actually, all menus are by nature dynamic in PicoGUI, most apps just use functions 
that build it all in one step, for convenience. You can use pgNewPopupAt to create a 
new popup widget, then add menuitems or whatever else.

> 
> I now want to bring up a dynamic menu instead. Here is my try on a
> generic callback function for all menues. It looks, from which Widget
> it is called and decides then what menu to bring up. For now only a
> box pops up:
> 
> int _mpv_menu_callback(struct pgEvent *evt)
> /* menu click callback */
> {
>   pghandle result,toolbar;
> 
>   /* Do our own context management */
>   pgEnterContext();
> 
>   /* Get the widget we come from */
>   result = pgGetWidget(pgGetEvent()->from,PG_WP_TEXT);
> 
>   if (result)
>     pgMessageDialogFmt("Menu results",0,
>                        "You selected \"%s\"",
>                        pgGetString(result));
> 
>   /* Clean-up time */
>   pgLeaveContext();
> 
>   return 0;
> 
> }

I don't understand what this code is trying to do...
The pgEnterContext/pgLeaveContext in this function has no effect.
pgGetEvent() waits for a new event, but since you're already in an event handler 
there's an event in the "evt" parameter.

> 
> Yes, possibly you know this code. My problem is: I do now the same,
> but don't want to bring up a box, but a menu:
> 
> 
> int _mpv_menu_callback(struct pgEvent *evt)
> /* menu click callback */
> {
>   pghandle result,toolbar;
> 
>   /* Do our own context management */
>   pgEnterContext();
> 
>   /* Get the widget we come from */
>   result = pgGetWidget(pgGetEvent()->from,PG_WP_TEXT);
> 
>   if (result) {
> 
>       /* Create a popup menu at the cursor with automatic sizing */
>       pgNewPopupAt(PG_POPUP_ATEVENT,PG_POPUP_ATEVENT,
>                    PGDEFAULT,PGDEFAULT);
>       pgNewWidget(PG_WIDGET_LABEL,0,0);
>       pgSetWidget(PGDEFAULT,
>                   PG_WP_TEXT,pgNewString("Click something:"),
>                   0);
>   }
> 
>   /* Clean-up time */
>   pgLeaveContext();
> 
>   return 0;
> }
> 
> 
> The strange thing is: If I put the menu on top of the "if (result)",
> everything works fine. So it seems to me, that the line, which finds
> out the callee widget, breaks something. This is a bug, or I make a
> mistake - well, I'm totally new to pgui. So: What does the
> pgNewPopupAt() routine need, that it can not show up, like the routine
> pgMessageDialogFmt()?


In this code, as soon as you create the menu it would be destroyed due
to the pgLeaveContext right afterwards. You need to wait for an event,
using a pgGetEvent loop or pgEventLoop/pgBind.

> 
> 
> Thanks in advance...
> --
> Martin Doering
> 
> 
> -------------------------------------------------------
> Sponsored by:
> ThinkGeek at http://www.ThinkGeek.com/
> _______________________________________________
> Pgui-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/pgui-devel

-- 
Only you can prevent creeping featurism!


-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
_______________________________________________
Pgui-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/pgui-devel

Reply via email to