Laxkit  0.0.7.1
Public Member Functions | Protected Attributes
Laxkit::PopupMenu Class Reference

Class for, of all things, popup menus. More...

Inheritance diagram for Laxkit::PopupMenu:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 PopupMenu (const char *nname, const char *ntitle, unsigned long long style, int xx, int yy, int ww, int hh, int brder, unsigned long nowner, const char *mes, int mouseid, MenuInfo *usethismenu, char mislocal, PopupMenu *nparentmenu=NULL, unsigned long long extrastyle=0)
 Constructor. Sets win_style to have ANXWIN_BARE|ANXWIN_HOVER_FOCUS.
virtual ~PopupMenu ()
 Destructor.
virtual const charwhattype ()
virtual int Idle (int tid=0)
virtual int MouseMove (int x, int y, unsigned int state, const LaxMouse *d)
 Implements PopupMenu specific mouse move traits.
virtual int RBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Right button currently just escapes out of the window.
virtual int RBUp (int x, int y, unsigned int state, const LaxMouse *d)
 RBUp escapes out of the window entirely.
virtual int CharInput (unsigned int ch, const char *buffer, int len, unsigned int state, const LaxKeyboard *d)
 In addition to the MenuSelector::CharInput, left goes up a menu, right goes down, ESC escapes.
virtual char MouseIn (int x, int y)
 Return whether the given coordinate is in the window or not.
virtual void addselect (int i, unsigned int state)
 Must capture before and after selecting, to control what popups should be up.
- Public Member Functions inherited from Laxkit::MenuSelector
 MenuSelector (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev, unsigned long nowner=0, const char *mes=0, unsigned long long nmstyle=0, MenuInfo *minfo=NULL, char nmenuislocal=0)
 Constructor.
virtual ~MenuSelector ()
 Destructor, just does if (menu && menuislocal) delete menu.
virtual int init ()
 Set some values that are derived from other values (pagesize, hightlight, shadow, ...).
virtual void Refresh ()
 Draw the window.
virtual int Event (const EventData *e, const char *mes)
 Intercept LAX_onMapped in case MENUSEL_GRAB_ON_MAP is set.
virtual int LBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Left button down.
virtual int LBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Left button up.
virtual int WheelUp (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Scroll screen down.
virtual int WheelDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Scroll screen up.
virtual int MoveResize (int nx, int ny, int nw, int nh)
 Calls ScrolledWindow::MoveResize(nx,ny,nw,nh).
virtual int Resize (int nw, int nh)
 Calls ScrolledWindow::Resize(nw,nh).
virtual int FocusOn (const FocusChangeData *e)
 Focus on draws the char over item.
virtual int FocusOff (const FocusChangeData *e)
 Focus off draws the char over item.
virtual int WrapToMouse (int mouseid, anXWindow *onedgeofthis=NULL)
 Resize the window to the extent of the items, and reposition near the mouse.
virtual int WrapToPosition (int screen_x, int screen_y, int screen, anXWindow *onedgeofthis=NULL)
 Orient the window's size and position to be near the given screen coordinates.
virtual int movescreen (int dx, int dy)
 Try to move the screen by dx pixels and dy pixels.
virtual int SetFirst (int which, int x, int y)
 Make item which be near screen coordinate x,y.
virtual int Curitem ()
 Return curitem, which is the last item whose state was toggled.
virtual const MenuItemItem (int c)
virtual int Select (int which)
 Programs call this to select index which.
virtual int NumSelected ()
 Return how many items are currently selected.
virtual intWhichSelected (unsigned int state)
 Return a new'd int array of which items are in the given state, if there are any, else NULL.
virtual void SetLineHeight (int ntotalheight, int newleading, char forcearrange=1)
 Set the new line height and leading.
virtual void Sync ()
 This is meant to be called when the window is going, but you just added or removed a bunch of stuff.
virtual void Sort (int t)
 Sort the items alphabetically by the name.
virtual int AddItems (const char **i, int n, int startid)
 Add a bunch of items all at once.
virtual int AddItem (const char *i, int nid, int nst)
 Add item with text i to the top index of menuitems.
- Public Member Functions inherited from Laxkit::ScrolledWindow
 ScrolledWindow (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev, unsigned long nowner=0, const char *nsend=NULL, PanController *pan=NULL)
virtual int send ()
 Send what? huh?***.
virtual int UseThisWindow (anXWindow *nwindow)
 Use nwindow as the nested window.
- Public Member Functions inherited from Laxkit::PanUser
 PanUser (PanController *npan=NULL)
 Create with a new panner.
virtual ~PanUser ()
 Removes this from panner tellstack. Delete panner if necessary.
virtual PanControllercreateNewPanner (PanController *pan=NULL)
 Create a new panner that is a copy of pan if given.
virtual void UseThisPanner (PanController *npanner)
 Replace the current panner with npanner, which can be NULL to mean make a new one.
- Public Member Functions inherited from Laxkit::anXWindow
 anXWindow (anXWindow *parnt, const char *nname, const char *ntitle, unsigned long nstyle, int xx, int yy, int ww, int hh, int brder, anXWindow *prev, unsigned long nowner, const char *nsend)
 Constructor.
virtual ~anXWindow ()
 anXWindow destructor. Its X window should have been XDestroy'd before here.
virtual const charWindowTitle (int which=0)
 Return basically the name of the window.
virtual void WindowTitle (const char *newtitle)
 Change the title of the window. This text would usually be displayed in the bar provided by a window manager.
virtual const chartooltip (int mouseid=0)
 By default, return win_tooltip.
virtual const chartooltip (const char *newtooltip)
 Replace the current tooltip, return the current tooltip (after replacing).
virtual anXWindowfindChildWindowByTitle (const char *title)
 Find the first immediate child window that has win_title==title.
virtual anXWindowfindChildWindowByName (const char *name)
 Find the first immediate child window that has win_name==name.
virtual int Grayed ()
 Return whether this window is grayed.
virtual int Grayed (int g)
 Set the gray state of this window. Returns Grayed(void).
virtual int preinit ()
virtual int close ()
 Called by anXApp from anXApp::destroywindow() when a window is to be destroyed.
virtual DisplayerMakeCurrent ()
virtual int Needtodraw ()
 Default is to return needtodraw.
virtual void Needtodraw (int nntd)
 If 0, then the window does not need refreshing. Otherwise it does.
virtual int deletenow ()
 Return whether the window is allowed to be deleted.
virtual int setWinStyle (unsigned int stylebit, int newvalue)
 Control various window related basic styling of win_style.
virtual int getWinStyle (unsigned int stylebit)
 Currently, simply return win_style&stylebit.
virtual void installColors (WindowColors *newcolors)
 Dec_count old and inc_count new.
virtual ShortcutHandlerGetShortcuts ()
 Return a ShortcutHandler that contains stacks of bound shortcuts and possible window actions.
virtual int PerformAction (int action_number)
virtual int ExposeChange (ScreenEventData *e)
 Default behavior on Expose events is to call Needtodraw(1).
virtual int DeviceChange (const DeviceEventData *e)
virtual int KeyUp (unsigned int ch, unsigned int state, const LaxKeyboard *kb)
 Called when a key is released.
virtual int ButtonDown (int button, int x, int y, unsigned int state, int count, const LaxMouse *m)
virtual int ButtonUp (int button, int x, int y, unsigned int state, const LaxMouse *m)
virtual int MBDown (int x, int y, unsigned int state, int count, const LaxMouse *d)
 Default is just to return 1.
virtual int MBUp (int x, int y, unsigned int state, const LaxMouse *d)
 Default is just to return 1.
virtual void contentChanged ()
 Windows may call this when their contents change.
virtual void selectionChanged ()
 Windows may call this when their selections change.
virtual anXWindowGetController ()
 Return the window most relevant for tab control loops.
virtual int SelectNextControl (const LaxDevice *d)
 Transfer focus to nextcontrol.
virtual int SelectPrevControl (const LaxDevice *d)
 Transfer the focus to prevcontrol.
virtual void ControlActivation (int on)
 Do special activation or not when controls are activated by tabbing.
virtual int AddPrevControl (anXWindow *prev)
virtual int AddNextControl (anXWindow *next)
virtual int ConnectControl (anXWindow *towhat, int after=1)
 Connect towhat to this. Used for tab loops.
virtual int CloseControlLoop ()
 Close a tab loop.
virtual void SetOwner (anXWindow *nowner, const char *mes=NULL, unsigned int send_mask=0)
 Set the new owner and control message.
virtual void SetOwner (unsigned long nowner_id, const char *mes=NULL, unsigned int send_mask=0)
virtual void dump_out (FILE *f, int indent, int what, anObject *context)
 Simple dumping function.
virtual LaxFiles::Attributedump_out_atts (LaxFiles::Attribute *att, int what, anObject *context)
virtual void dump_in_atts (LaxFiles::Attribute *att, int flag, anObject *context)
- Public Member Functions inherited from Laxkit::Tagged
virtual int HasTag (const char *tag, int casematters)
 Return whether the tag exists.
virtual int NumberOfTags ()
 Return the number of tags, strangely enough.
virtual const charGetTag (int i)
 Return const pointer to the tag text for tag number i, where i==0 is the first tag.
virtual charGetAllTags ()
 Return a new char[] with a space separated list of all the tags.
virtual int InsertTags (const char *tags, int casematters)
 Insert tags from a string such as 'tag1 tag2 tag3 "tag with spaces" tag4'.
virtual int InsertTag (const char *tag, int casematters)
 Insert tag if it doesn't exist already.
virtual int RemoveTag (const char *tag)
 The tag must be an exact match.
virtual int RemoveTag (int i)
 Remove tag number i. i must be in range [0..NumberOfTags()-1].
virtual void FlushTags ()
- Public Member Functions inherited from LaxFiles::DumpUtility
virtual void dump_in (FILE *f, int indent, int what, Laxkit::anObject *loadcontext, Attribute **att)
 Read in a file segment as an Attribute, and pass parsing duties to dump_in_atts.
virtual ~DumpUtility ()
 Empty virtual destructor.
- Public Member Functions inherited from Laxkit::aDrawable
 aDrawable (Drawable d=0)
virtual int DrawableType ()
virtual int ValidDrawable ()

Protected Attributes

PopupMenuparentmenu
 The popup that is the parent of this.
PopupMenusubmenu
 The popup that is the (open) child of this.
- Protected Attributes inherited from Laxkit::MenuSelector
ButtonDownInfo buttondown
int mousedragged
 Flag for whether the mouse has been dragged since a button was down.
NumStack< intcolumns
 Each element of the stack holds the width of that column.
MenuInfomenu
 Stores the actual menu items.
char menuislocal
 Whether menu is local to this MenuSelector.
int mx
int my
int sgw
 The width of the status graphic element of a menu item. (only one width, not per item)
int checkw
 The width of the check mark graphic of a menu item. (only one width, not per item)
int subw
 The width of the sub menu indicator graphic of a menu item. (only one width, not per item)
int firstinw
 The equivalent index of the first line in the window.
int textheight
 The height of lines are leading+(text height).
int lineheight
int pagesize
 The number of lines that can be comfortably fit in inrect.
int columnsize
 The maximum number of actual elements in any the columns.
MenuItemcurmenuitem
 The MenuItem corresponding to curitem.
int curitem
 The last selected or deselected item.
int ccuritem
 The item which one has cursored to.
int timerid

Additional Inherited Members

- Public Attributes inherited from Laxkit::MenuSelector
unsigned long highlight
 Highlight color of beveled graphics.
unsigned long shadow
 Shadow color of beveled graphics.
unsigned long long menustyle
int padg
 The pad to place between text and other graphic elements.
int pad
int leading
 The height of lines are leading+(text height).
- Public Attributes inherited from Laxkit::ScrolledWindow
IntRectangle inrect
 The rectangle that thewindow resides in.
IntRectangle outrect
 The rectangle that holds all of thewindow and scrollers.
int scrollwidth
PanPopuppanpopup
anXWindowthewindow
Scrollerxscroller
Scrolleryscroller
- Public Attributes inherited from Laxkit::PanUser
PanControllerpanner
- Public Attributes inherited from Laxkit::anXWindow
WindowColorswin_colors
anXAppapp
charwin_name
 An arbitrary string to be used as an id.
charwin_title
 The title of the window.
anXWindowwin_parent
int win_screen
unsigned long win_style
int win_x
int win_y
int win_w
int win_h
unsigned int win_border
int win_pointer_shape
 Identifier for a stock mouse shape.
char win_on
 Nonzero if the window is mapped.
char win_active
 Should be positive when the window has a keyboard focus, 0 otherwise.
unsigned long win_owner
 Who gets control messages from this window.
unsigned int win_owner_send_mask
charwin_sendthis
 The type of message that gets sent to owner.
anXWindownextcontrol
anXWindowprevcontrol
- Public Attributes inherited from Laxkit::Tagged
int sorttags
- Protected Member Functions inherited from Laxkit::MenuSelector
virtual void adjustinrect ()
 Remove the pads from inrect.
virtual void findoutrect ()
 Set outrect to be the window minus space for title.
virtual double getitemextent (MenuItem *mitem, double *w, double *h, double *gx, double *tx)
 Find extent of text+graphic+(pad between graphic and text).
virtual double getgraphicextent (MenuItem *mitem, double *x, double *y)
 Base MenuSelector currently just does text, so points w and h to 0.
virtual void drawStatusGraphic (int x, int y, int state)
 Draw the status graphic at window coordinates x,y,width=sgw,height=textheight+leading, with state.
virtual void drawitem (MenuItem *mitem, IntRectangle *itemspot)
 Draw the item in the provided area..
virtual void drawitem (int c)
 Draw the item with the index value c.
virtual void drawsep (const char *name, IntRectangle *rect)
 Draw a separator (default is just a win_colors->grayedfg colored line) across rect widthwise.
virtual void drawarrow (int x, int y, int r, int type)
 Draw the arrows for menus, really just THING_Triangle_Up, Down, Left, Right for submenus.
virtual void drawcheck (int on, int x, int y)
 Draw a check mark in rectangle x,y,width=checkw, height=textheight+leading.
virtual void drawsubindicator (MenuItem *mitem, int x, int y)
 Draws a submenu indicator in rectangle x,y,width=subw, height=textheight+leading.
virtual void drawitemname (MenuItem *mitem, IntRectangle *rect)
 Draw the item icon and name in rect.
virtual void drawtitle ()
 Draw the menu title if present. Default is print it out at top of window (not inrect).
virtual int send (int deviceid)
 Send message to owner.
virtual int findmaxwidth (int s, int e, int *h_ret)
 Find the maximum width of (text+ pad+ graphic+ statusgraphicw+ checkwidth+ subw) of items in range [s,e].
virtual int findItem (int x, int y)
 Find the would be item at window coordinates (x,y).
virtual int findRect (int c, IntRectangle *itemspot)
 Find screen rectangle item c goes in.
virtual void editInPlace ()
 Set up the edit in place mode. ****TODO!!
virtual int numItems ()
 Default is to return the number of items in menu->menuitems stack.
virtual MenuItemitem (int i, char skipcache=0)
 Return the item corresponding to screen index i.
virtual void arrangeItems (int forwrapping=0)
 Setup columns based on inrect, then sync up the panner.
virtual void setcuritem (int i)
 Sets curitem and curmenuitem. Internal function.
virtual void syncWindows (int useinrect=0)
 Called same for ScrolledWindow, then arrangeItems.
virtual int makeinwindow ()
 Make sure that ccuritem is visible by shifting screen so it is.

Detailed Description

Class for, of all things, popup menus.

#include <lax/popupmenu.h>

This is specifically for the popup part of popup menus. This is separate from the (usually horizontal) MenuBar from which you pull down popups, as is so common in applications.

Almost all the real work is done in MenuSelector. This class adds features to keep track of which menu the mouse enters, and modify which submenus are actually popped up up accordingly. This is done basically by keeping a linked lists of popped up menus, and checks where the mouse is with each mouse movement. The pointer is grabbed by each menu it enters, so this is relatively easy.

It is worth noting that each PopupMenu is created from scratch each time it is needed, and deleted when not needed. This menu system does not use persistent windows that are just mapped on and off. That might be a useful feature for complex menus, but for now, that is just a remote TODO.

Todo:

***** mondo needs work!!!!!!!!!! *** problem when menu is popped up from a running dialog, crossing over between the popped menus makes all events be blocked!!!

add support for tearoff menus

POPMENU_LEAVE_DESTROYS should abandon the windows if the mouse leaves a menu, and does not enter another one.

  ***TODO:
  // *** clicking on the item leading to an open submenu should simply close the submenu, not select said item
  // **** must process leavenotify/enternotify to make sure all ok
  // *** focus must revert back to the calling window!!
  // ***** mondo needs work!!!!!!!!!!
  // *** put left/right to go to sub/parent menu
  // 
  //    if you intend to modify menu states, each id must be unique (see Modify(...))
  // ids should be non-negative
  // —
  //Read in from file or char:???
  // MenuTitle:
  // name idnumber g[rayed]
  // ** need to iron out having window checked as well as highlighted!!!!
  //  "This is the menu title":
  //    blah1 1
  //    blah2 2 g
  //    blah3d 3
  //        a 4
  //        b 5
  //        c 6
  //        d 7
  //            1 8
  //            2 9
  //            3 10
  //    blah4 11
  //    —-
  //  "blah5 blah" 12
  //  
  //
  // menu.Modify(int id,const char *newitemname,int nid,*newsubmenu)
  //
  

Constructor & Destructor Documentation

Laxkit::PopupMenu::PopupMenu ( const char nname,
const char ntitle,
unsigned long long  style,
int  xx,
int  yy,
int  ww,
int  hh,
int  brder,
unsigned long  nowner,
const char mes,
int  mouseid,
MenuInfo usethismenu,
char  mislocal,
PopupMenu nparentmenu = NULL,
unsigned long long  extrastyle = 0 
)

Constructor. Sets win_style to have ANXWIN_BARE|ANXWIN_HOVER_FOCUS.

This creates a MenuSelector that has no parent, and is set with
menustyle= MENUSEL_ZERO_OR_ONE | MENUSEL_CURSSELECTS | MENUSEL_FOLLOW_MOUSE | MENUSEL_SEND_ON_UP | MENUSEL_GRAB_ON_ENTER | MENUSEL_OUT_CLICK_DESTROYS | MENUSEL_CLICK_UP_DESTROYS.

If nparentmenu is NULL, then MENUSEL_GRAB_ON_MAP is also set.

Ignores parnt and nstyle, and uses NULL and (ANXWIN_BARE|ANXWIN_HOVER_FOCUS) instead.

This always tries to popup near the mouse, next to nparentmenu.

Parameters:
usethismenuPass in a MenuInfo class, if not NULL is assumed to not be local
mislocalWhether the passed in menu is local
nparentmenuThis is the calling menu, if any
extrastyleExtra MenuSelector styles to pass along

References Laxkit::MenuSelector::menu, parentmenu, Laxkit::MenuSelector::Select(), submenu, Laxkit::MenuSelector::WrapToMouse(), and Laxkit::MenuSelector::WrapToPosition().

Referenced by addselect().

Laxkit::PopupMenu::~PopupMenu ( )
virtual

Destructor.

Calls app->destroywindow(submenu) if submenu is not NULL, and also app->destroywindow(parentmenu) if parentmenu is not NULL. Care must be taken in addselect and any other place that parts of the popup tree are destroywindow'd!

References Laxkit::anXApp::destroywindow(), parentmenu, and submenu.


Member Function Documentation

void Laxkit::PopupMenu::addselect ( int  i,
unsigned int  state 
)
virtual

Must capture before and after selecting, to control what popups should be up.

! Focus off maybe destroys the menus. ! Also, if MENUSEL_FOCUS_OFF_DESTROYS, then an off focus destroys this window.

Reimplemented from Laxkit::MenuSelector.

References Laxkit::MenuSelector::curitem, Laxkit::anXApp::destroywindow(), Laxkit::PtrStack< T >::e, Laxkit::MenuSelector::findRect(), Laxkit::MenuItem::GetSubmenu(), Laxkit::getUniqueNumber(), Laxkit::MenuSelector::menu, Laxkit::MenuInfo::menuitems, numtostr(), parentmenu, PopupMenu(), Laxkit::anXApp::rundialog(), Laxkit::MenuItem::state, submenu, Laxkit::anXWindow::win_owner, and Laxkit::anXWindow::win_sendthis.

int Laxkit::PopupMenu::Idle ( int  tid = 0)
virtual

If there are no mice in any of the related menus, then destroy all the related menus.

Reimplemented from Laxkit::MenuSelector.

References Laxkit::mouseposition(), parentmenu, Laxkit::anXApp::removetimer(), and submenu.

int Laxkit::PopupMenu::MouseMove ( int  x,
int  y,
unsigned int  state,
const LaxMouse d 
)
virtual

Implements PopupMenu specific mouse move traits.

Since PopupMenus grab the mouse, it is easy to keep track of where the mouse is. It is especially easy since the menu keeps track of the parent and sub menus that are open. Basically this function just shifts the pointer grab to whichever popped up menu it is in.

Reimplemented from Laxkit::MenuSelector.

References Laxkit::anXApp::addtimer(), MouseIn(), parentmenu, Laxkit::anXApp::setfocus(), submenu, and Laxkit::anXWindow::WindowTitle().

int Laxkit::PopupMenu::RBDown ( int  x,
int  y,
unsigned int  state,
int  count,
const LaxMouse d 
)
virtual

Right button currently just escapes out of the window.

TODO: might want to think about some mechanism to have it easy to popup another popup window to modify something about the item that the mouse is over, something akin to "create a link to this on the desktop".

Reimplemented from Laxkit::MenuSelector.


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:53:00, Laxkit