1. [Win32Lib] How add/remove MENU ITEMS "on the fly"?

What should I do to allow an app user to add or remove certain menu items
from the menu bar while the program is running?  I'm pretty sure it can be
done, & I could futz with it to try to make it happen, but I'm hoping
someone actually KNOWS how to do it already  :)

Situation is, I set up some menu items (from a file of items), with the idea
that the user could add more or delete some.  I should be able to handle
saving the results of the users action (to a dat file), and then the making
of the menu items on re-start the program (when it would read the amended
file); but how do I make the add/delete action show up *while* the program
is running (and *correctly*)?

Here's approximetely what I did:

the menu items which may be added or deleted are "categories".

constant Menu_Edit = createEx( Menu, "Edit", Window1, 0, 0, 0, 0, 0, 0 )

procedureCategory_onClick(integer self, integer event, sequence
params)--params is ()
  -- this will handle clicking on any category,
  -- but not the "add/delete a category" item at the *end* of the menu
end procedure

sequence Cats -- is a sequence of categories
sequence CatsMenu  -- to hold the result of creating the menu items

-- create menus for different categories:
procedure CreateCategoriesMenus()
integer lengthCats

  lengthCats = length(Cats)  -- so I know how many actual categories
  CatsMenus = {}
  for n = 1 to lengthCats do
     CatsMenus &= {createEx( MenuItem, Cats[n], Menu_Edit, 0, 0, 0, 0, 0,
0 )}
  end for
  CatsMenus &= {createEx( MenuItem, "-", Menu_Edit, 0, 0, 0, 0, 0, 0 )} -- 
separator
  CatsMenus &= {createEx( MenuItem, "Add/Delete a Category", Menu_Edit, 0,
0, 0, 0, 0, 0 )}
  -- now set up an event handler for ALL categories
  -- (but NOT for the separator or last item, yet):
  setHandler( CatsMenus[1..lengthCats], w32HClick,
routine_id("Category_onClick"))

end procedure

So, what should I do (with the CatsMenus?), to "re-do" (re-display) the
menus after a user has added or deleted categories, so the Edit menu now has
 the users choices showing, AND pointed to the handler, WHILE the program is
running??

tia,
Dan Moyer

new topic     » topic index » view message » categorize

2. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

On Sun, 6 Mar 2005 20:14:04 -0800, Dan Moyer <DANIELMOYER at prodigy.net>
wrote:

>What should I do to allow an app user to add or remove certain menu items
>from the menu bar while the program is running?  I'm pretty sure it can be
>done, & I could futz with it to try to make it happen, but I'm hoping
>someone actually KNOWS how to do it already  :)

The latest version of MEditor has a dynamic Window menu, see routine
rebuildWindowMenu() in files.e, which is also called from options.ew.
It does not attempt to change the 'bar', but I don't think you
actually meant that anyway.

Mike's ARWEN also has a demo which adds/removes menu entries on the
fly.

>So, what should I do (with the CatsMenus?), to "re-do" (re-display) the
>menus after a user has added or deleted categories, so the Edit menu now has
> the users choices showing, AND pointed to the handler, WHILE the program is
>running??
I believe CatsMenus is purely an internal list of win32lib id's, which
is a good thing to have and you can freely manipulate as a normal
Euphoria sequence. Windows itself should cope via the create/destroy
calls you made.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

3. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

Hey Daniel,

Well, this is somewhat a simple solution.  It comes to the point of two possible
answers that you can follow, to make it work.  The first method, is to staticly
create the Menu Items under all of the Menus, then use setVisible() to hide, and
show thoes items that the User Selects.  That's Method one.

Method Two, is to store a list of Menu Items in a Sequence, which should look
something like this:

constant MenuArch = {
  {ID_FILE,"&New",ID_NEW},
  {ID_FILE,"E&xit",ID_EXIT},
  {ID_EDIT,"&Cut",ID_CUT},
  {ID_EDIT,"C&opy",ID_COPY},
  {ID_EDIT,"&Paste",ID_PASTE}
}


This way, you have your Basic Structure of where items will go, and drop
them in there fairly easy.  Then you can dynamically have a sequece list
of the actual item id's, so you can delete them.  You wouldn't need it
for anything else, cause you can simply use setHandler() to add the 
w32HClick event to the Menu Item, when you create the control.  Other then
that, it's fairly easy. Any Win32 Control can be created multiple times, with
the same definition, as long as you can get a Unique ID to identify it from
others.

BTW, there will be one more option you can use, which is to use SOOP to
handle it.  You can have a simple sequence in the main "Menu" class, which
holds all of the Menu's, and Sub-Menus, then create a "MenuItem" class, in
which to classified everything, and structure your routines as such.

It's pretty much how you will do it now, with Normal Euphoria, but offers a
more structured way of doing things, since you can Inherit from a parent
class, and have everything run the same exact way, only with your own
customizable Routines.  This will be one of the Win32lib Demos I will do for
SOOP 1.0

Hope this helps,

Mario Steele
http://enchantedblade.trilake.net
Attaining World Dominiation, one byte at a time...

new topic     » goto parent     » topic index » view message » categorize

4. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

(whispering quietly:  I forgot all about the "destroy" procedure, 'cause
I've never used it before.  Thanks.)

Dan
(embarrassed grin :)

From: "Pete Lomax" <petelomax at blueyonder.co.uk>
>
> On Sun, 6 Mar 2005 20:14:04 -0800, Dan Moyer <DANIELMOYER at prodigy.net>
> wrote:
>
> >What should I do to allow an app user to add or remove certain menu items
> >from the menu bar while the program is running?  I'm pretty sure it can
be
> >done, & I could futz with it to try to make it happen, but I'm hoping
> >someone actually KNOWS how to do it already  :)
>
> The latest version of MEditor has a dynamic Window menu, see routine
> rebuildWindowMenu() in files.e, which is also called from options.ew.
> It does not attempt to change the 'bar', but I don't think you
> actually meant that anyway.

You're right, just want to change the items under one "top level" menu.

>
> Mike's ARWEN also has a demo which adds/removes menu entries on the
> fly.
>
> >So, what should I do (with the CatsMenus?), to "re-do" (re-display) the
> >menus after a user has added or deleted categories, so the Edit menu now
has
> > the users choices showing, AND pointed to the handler, WHILE the program
is
> >running??
> I believe CatsMenus is purely an internal list of win32lib id's, which
> is a good thing to have and you can freely manipulate as a normal
> Euphoria sequence. Windows itself should cope via the create/destroy
> calls you made.

Oh, there's a DESTROY procedure !  :)  RTFM Dan!

>
> Regards,
> Pete
>
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

> posted by: Mario Steele <eumario at trilake.net>
>
> Hey Daniel,
>
> Well, this is somewhat a simple solution.  It comes to the point of two
possible
> answers that you can follow, to make it work.  The first method, is to
staticly
> create the Menu Items under all of the Menus, then use setVisible() to
hide, and
> show thoes items that the User Selects.  That's Method one.
>
> Method Two, is to store a list of Menu Items in a Sequence, which should
look
> something like this:
>
> }}}
<eucode>
> constant MenuArch = {
>   {ID_FILE,"&New",ID_NEW},
>   {ID_FILE,"E&xit",ID_EXIT},
>   {ID_EDIT,"&Cut",ID_CUT},
>   {ID_EDIT,"C&opy",ID_COPY},
>   {ID_EDIT,"&Paste",ID_PASTE}
> }
> </eucode>
{{{

>
> This way, you have your Basic Structure of where items will go, and drop
> them in there fairly easy.  Then you can dynamically have a sequece list
> of the actual item id's, so you can delete them.  You wouldn't need it
> for anything else, cause you can simply use setHandler() to add the
> w32HClick event to the Menu Item, when you create the control.  Other then
> that, it's fairly easy. Any Win32 Control can be created multiple times,
with
> the same definition, as long as you can get a Unique ID to identify it
from
> others.

Thanks Mario;  I did store the created items in a sequence, but completely
forgot about the "destroy" procedure, which Pete accidentally (?) reminded
me of.  It should be relatively easy now.

Dan


>
> BTW, there will be one more option you can use, which is to use SOOP to
> handle it.  You can have a simple sequence in the main "Menu" class, which
> holds all of the Menu's, and Sub-Menus, then create a "MenuItem" class, in
> which to classified everything, and structure your routines as such.
>
> It's pretty much how you will do it now, with Normal Euphoria, but offers
a
> more structured way of doing things, since you can Inherit from a parent
> class, and have everything run the same exact way, only with your own
> customizable Routines.  This will be one of the Win32lib Demos I will do
for
> SOOP 1.0
>
> Hope this helps,
>
> Mario Steele
> http://enchantedblade.trilake.net
> Attaining World Dominiation, one byte at a time...
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

a related question:
if, (to accomplish removing menu items as a program is running), I initially
create the original menu items "in" a sequence and set handler(s) to them, &
then allow app user to delete menu items from the sequence, & then destroy
those controls, shouldn't I at some point also "destroy" the original
handler connection made by "setHandler" for the controls destroyed?  If so,
how?  (I presume then re-link handlers to the "new" controls.)

Would it be something like this:
setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, -1)  ??
or,
setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, {-1,
routine_id("myhandler")} )  ??

And should I do this before I destroy the controls?

Dan Moyer


Dan wrote:
>
> (whispering quietly:  I forgot all about the "destroy" procedure, 'cause
> I've never used it before.  Thanks.)
>
> Dan
> (embarrassed grin :)
>
> From: "Pete Lomax" <petelomax at blueyonder.co.uk>
> >
> > On Sun, 6 Mar 2005 20:14:04 -0800, Dan Moyer <DANIELMOYER at prodigy.net>
> > wrote:
> >
> > >What should I do to allow an app user to add or remove certain menu
items
> > >from the menu bar while the program is running?  I'm pretty sure it can
> be
> > >done, & I could futz with it to try to make it happen, but I'm hoping
> > >someone actually KNOWS how to do it already  :)
> >
> > The latest version of MEditor has a dynamic Window menu, see routine
> > rebuildWindowMenu() in files.e, which is also called from options.ew.
> > It does not attempt to change the 'bar', but I don't think you
> > actually meant that anyway.
>
> You're right, just want to change the items under one "top level" menu.
>
> >
> > Mike's ARWEN also has a demo which adds/removes menu entries on the
> > fly.
> >
> > >So, what should I do (with the CatsMenus?), to "re-do" (re-display) the
> > >menus after a user has added or deleted categories, so the Edit menu
now
> has
> > > the users choices showing, AND pointed to the handler, WHILE the
program
> is
> > >running??
> > I believe CatsMenus is purely an internal list of win32lib id's, which
> > is a good thing to have and you can freely manipulate as a normal
> > Euphoria sequence. Windows itself should cope via the create/destroy
> > calls you made.
>
> Oh, there's a DESTROY procedure !  :)  RTFM Dan!
>
> >
> > Regards,
> > Pete
> >
> >
>
>
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

danielmoyer wrote:
> 
> a related question:
> if, (to accomplish removing menu items as a program is running), I initially
> create the original menu items "in" a sequence and set handler(s) to them, &
> then allow app user to delete menu items from the sequence, & then destroy
> those controls, shouldn't I at some point also "destroy" the original
> handler connection made by "setHandler" for the controls destroyed?  If so,
> how?  (I presume then re-link handlers to the "new" controls.)
> 
> Would it be something like this:
> setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, -1)  ??
> or,
> setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, {-1,
> routine_id("myhandler")} )  ??
> 
> And should I do this before I destroy the controls?
> 
> Dan Moyer

Actually, when you destroy() the control in question, it will remove all
handlers for that control automatically.  So you wouldn't have to worry
about removing them.  However, you will need to re-apply the handlers to
the control, when you re-make it.  Otherwise, Win32lib will be sitting
there, twiddling it's thumbs, wondering what you want to do with the
control when an action happens on it.

Mario Steele
http://enchantedblade.trilake.net
Attaining World Dominiation, one byte at a time...

new topic     » goto parent     » topic index » view message » categorize

8. Re: [Win32Lib] How add/remove MENU ITEMS "on the fly"?

>
> posted by: Mario Steele <eumario at trilake.net>
>
> danielmoyer wrote:
> >
> > a related question:
> > if, (to accomplish removing menu items as a program is running), I
initially
> > create the original menu items "in" a sequence and set handler(s) to
them, &
> > then allow app user to delete menu items from the sequence, & then
destroy
> > those controls, shouldn't I at some point also "destroy" the original
> > handler connection made by "setHandler" for the controls destroyed?  If
so,
> > how?  (I presume then re-link handlers to the "new" controls.)
> >
> > Would it be something like this:
> > setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, -1)  ??
> > or,
> > setHandler ( SequenceOfAllOfTheControlsToBeDeleted, w32HClick, {-1,
> > routine_id("myhandler")} )  ??
> >
> > And should I do this before I destroy the controls?
> >
> > Dan Moyer
>
> Actually, when you destroy() the control in question, it will remove all
> handlers for that control automatically.  So you wouldn't have to worry
> about removing them.  However, you will need to re-apply the handlers to
> the control, when you re-make it.  Otherwise, Win32lib will be sitting
> there, twiddling it's thumbs, wondering what you want to do with the
> control when an action happens on it.
>
> Mario Steele

OH, very good to know that destroying a control also destroys the handler
link(s), thanks!  And it didn't hurt to mention the necessity to re-apply
handlers to new controls, does follow logically, I kinda assumed that but I
could'a been wrong.

Dan

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu