#! ../mofe --f

XmMainWindow main topLevel
 XmMenuBar menu_bar main 
    XmPulldownMenu mpa menu_bar unmanaged
      XmPushButton Quit mpa activateCallback quit
    XmCascadeButton Actions menu_bar subMenuId mpa

    XmPulldownMenu mph menu_bar unmanaged
      XmPushButton Help mph activateCallback "manageChild helpbox"
    XmCascadeButton Help menu_bar subMenuId mph
    sV menu_bar menuHelpWidget Help

 XmMessageDialog helpbox Help unmanaged \
	dialogTitle "$argv0 Help" okLabelString "Close" messageString " 
  
   This is a tiny sample program to illustrate, how additional menu
   entries can be added to the window menu of mwm or some compliant
   window manager.
 
   Menu Entries can be added using the command:
     XmAddProtocolCallback topLevel _MOTIF_WM_MESSAGES _MY_PROTO myProtocol
 
   The last argument if XmAddProtocolCallback is an arbitrary wafe
   command and can have several arguments itself (use quotes or curly
   braces).
 
   Note that each time when XmAddProtocolCallback is executed an
   additional callback procedure is added to the callback
   list. Therefore the callback cannot be redefined using
   XmAddProtocolCallback. However, the callback procedure can of
   course obtain data from other widgets, access global data, or can
   be redefined completely in cases where the behavior of the created
   menu entry should change according to some program state.
 
    Gustaf Neumann                     Mohegan Lake,  Sun Oct 30, 1994    
  "
  unmanageChild \
	[XmMessageBoxGetChild helpbox DIALOG_CANCEL_BUTTON] \
	[XmMessageBoxGetChild helpbox DIALOG_HELP_BUTTON] 

#-------------------- here starts the real work -----------------

XmAddProtocolCallback topLevel _MOTIF_WM_MESSAGES _MY_PROTO myProtocol
sV topLevel \
    mwmMenu "MyProtocol _P Ctrl<Key>P f.send_msg [atomId topLevel _MY_PROTO]"

XmRowColumn rc main
 if [motifWMRunning topLevel] {
  set greet "Congratulations, you are using a motif compliant window manager; "
 } else {
  set greet "If you would run a motif compliant window manager, you should "
 }
 XmLabel l rc  recomputeSize false labelString "\n \n  $greet
  check the window manager pulldown menu in the left corner!   \n"
 XmRadioBox buttons rc orientation HORIZONTAL
  XmToggleButton activate buttons \
      set true labelString "WM-menu entry activated" \
      armCallback {XmActivateProtocol topLevel _MOTIF_WM_MESSAGES _MY_PROTO} 
  XmToggleButton deactivate buttons \
      labelString "WM-menu entry deactivated" \
      armCallback {XmDeactivateProtocol topLevel _MOTIF_WM_MESSAGES _MY_PROTO}

realize

proc myProtocol {} {
  global msgCnt msg
  sV l labelString $msg($msgCnt)
  set msgCnt [expr ($msgCnt+1)%4]
}
set msgCnt 0
set msg(0) "    This message was brought to you by Mr. WM!"
set msg(1) "  This message was brought to you by Mr. WM as well."
set msg(2) " Also this message was brought to you by the Window Manager."
set msg(3) "    ... this is starting to become boring... "