3.3.10 IconBar

  The XmIconButton in Open Motif 2.3 can also be used as a menubar by arranging the buttons to one line on a top region in ApplicationView .
The following IconBar program is an example to display a menu for some file editing operations by using IconBar class (motif++ 1.0.5).
Please note that to add a button to the IconBar, we specify an icon filename to XmNiconFileName which is an OZ++ specific resource :

  ar.set(XmNiconFileName, items[i].iconFile);  //Specify an icon filename
  ar.set(XmNlabelString, cs);
  ar.set(XmNshadowThickness, 0);    //Flat button
  iconBar -> addButton(ar,
        XmNactivateCallback, this,;   //Add an XmNactivate callback to an instance of IconButton
        (Callback)&MainView::activate, NULL);

//Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.

#include <oz++/motif/ApplicationView.h>
#include <oz++/motif/SashlessPanedWindow.h>
#include <oz++/motif/ScrolledText.h>
#include <oz++/motif/IconBar.h>
#include <oz++/motif/FileDialog.h>
#include <oz++/Pair.h>

namespace OZ {

class MainView :public ApplicationView {
  SmartPtr<SashlessPanedWindow> panedw;
  SmartPtr<FileDialog>          fileDialog;
  SmartPtr<IconBar>             iconBar;
  SmartPtr<ScrolledText>        sctext;
  typedef enum {NEW, OPEN, SAVE, QUIT} MENU;
  int menuId;

  void   activate(Action& action)
     View* sender = (View*) action.getSender();
     XmString xms;
     sender -> get(XmNlabelString, (XtArgVal)&xms);
     sender -> get(XmNuserData, (XtArgVal)&menuId);

     CompoundString cs(xms);
     char* name = cs.unparse();
     printf("activate %s menuId=%d\n", name, menuId);

  void handleMenu(Action& action)
    switch(menuId) { 
     case NEW:
       sctext -> getText() -> setString("");

     case OPEN:
       fileDialog -> manage();

     case SAVE:
       fileDialog -> manage();
     case QUIT:

  void  cancel(Action& action)
    fileDialog ->unmanage();

  void  open(Action& action)
    XmFileSelectionBoxCallbackStruct* cbs =
    CompoundString cs(cbs->value);
    char* filename;
    printf("filename: %s\n", filename);
    if (menuId == OPEN) {
      sctext -> getText() -> load(filename);
    if (menuId == SAVE) {
      sctext -> getText() -> save(filename);
    fileDialog ->unmanage();

  MainView(Application& applet, const char* name, Args& args)
  :ApplicationView(applet, name, args)
    menuId = -1;
    Args ar;
    panedw = new SashlessPanedWindow(this, "", ar);

    ar.set(XmNpaneMinimum, 60);
    iconBar = new IconBar(panedw, "", ar);
    static const IconBarItem items[] = 
          {"New", NEW,         "../xpm/file.xpm"},
          {"Open", OPEN,       "../xpm/open.xpm"},
          {"Save", SAVE,       "../xpm/save.xpm"},
          {"Quit", QUIT,       "../xpm/close.xpm" },
    for (int  i = 0; i<XtNumber(items); i++) {
      CompoundString cs(items[i].name);
      ar.set(XmNuserData, items[i].menuId);
      args.set(XmNminimumCellHeight, 48);        
      ar.set(XmNiconFileName, items[i].iconFile); 
      ar.set(XmNlabelString, cs);
      ar.set(XmNshadowThickness, 0);
      iconBar -> addButton(ar, 
                  XmNactivateCallback, this,
                 (Callback)&MainView::activate, NULL);
    sctext = new ScrolledText(panedw, "", ar);

    fileDialog = new FileDialog(this, "FileDialog", ar);
    fileDialog -> getFileBox()
               -> addCallback(XmNokCallback, this,
                      (Callback)&MainView::open, NULL);

    fileDialog -> getFileBox()
               -> addCallback(XmNcancelCallback, this,
                      (Callback)&MainView::cancel, NULL);




int main(int argc, char** argv)
  const char*  appclass = argv[0];
  Application applet(appclass, argc, argv);
  try {
    Args args;
    args.set(XmNgeometry, "600x500");
    MainView view(applet, argv[0], args);

  } catch (Exception& ex) {
  return 0;

Last modified: 1 Jan 2017

 Last modified: 1 Jan 2017

Copyright (c) 2000-2017 Antillia.com ALL RIGHTS RESERVED.