Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cmd_menu.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_menu.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.38 $       $Date: 2019/01/17 21:21:03 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for window/menu control
00019  ***************************************************************************/
00020 
00021 #include <string.h>
00022 #include <ctype.h>
00023 #include <stdlib.h>
00024 #include <tcl.h>
00025 #include "config.h"
00026 #include "utilities.h"
00027 #include "VMDApp.h"
00028 
00029 #ifdef VMDTK
00030 #include "VMDTkMenu.h"
00031 #endif
00032 
00033 #define TCL_HELP 99 //internal code to generate error AND display menu command help
00034 
00035 int text_cmd_menu(ClientData cd, Tcl_Interp *interp, int argc,
00036                      const char *argv[]) {
00037 
00038   VMDApp *app = (VMDApp *)cd;
00039   int retval = TCL_OK;
00040 
00041   // make sure a menu was named
00042   if (argc < 2) retval = TCL_HELP;
00043 
00044   if (argc == 2 && !strupncmp(argv[1], "list", CMDLEN)) {
00045       // return a list of the available menus
00046       for (int i=0; i<app->num_menus(); i++) 
00047         Tcl_AppendElement(interp,  app->menu_name(i));
00048   }
00049 #ifdef VMDTK
00050   else if (argc > 1 && !strupncmp(argv[1], "tk", CMDLEN)) {
00051 #ifndef MACVMD
00052     if ((argc == 5 || argc == 6 ) && !strupncmp(argv[2], "add", CMDLEN)) {
00053       VMDMenu *menu = new VMDTkMenu(argv[3], argv[4], app, interp);
00054       if (!app->add_menu(menu)) {
00055         delete menu;
00056         char buf[50];
00057         sprintf(buf, "Unable to add menu %s.\n", argv[3]);
00058         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00059         retval = TCL_ERROR;
00060       } else {
00061         // tell VMD that this is a menu extension
00062         if (argc==6) app->menu_add_extension(argv[3],argv[5]);
00063         else app->menu_add_extension(argv[3],argv[3]);
00064   
00065         // tell Tcl that a new menu extension has been added
00066         Tcl_SetVar(interp, "vmd_menu_extension", argv[3], TCL_GLOBAL_ONLY);
00067       }
00068     } else if ((argc == 5 || argc == 6 ) && !strupncmp(argv[2], "register", CMDLEN)) {
00069       VMDTkMenu *menu = new VMDTkMenu(argv[3], NULL, app, interp);
00070       menu->register_proc(argv[4]);
00071       if (!app->add_menu(menu)) {
00072         delete menu;
00073         char buf[50];
00074         sprintf(buf, "Unable to add menu %s\n", argv[3]);
00075         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00076         retval = TCL_ERROR;
00077       } else {
00078         // tell VMD that this is a menu extension
00079         if (argc==6) app->menu_add_extension(argv[3],argv[5]);
00080         else app->menu_add_extension(argv[3],argv[3]);
00081   
00082         // tell Tcl that a new menu extension has been added
00083         Tcl_SetVar(interp, "vmd_menu_extension", argv[3], TCL_GLOBAL_ONLY);
00084       }
00085     } else if (argc == 4 && !strupncmp(argv[2], "remove", CMDLEN)) {
00086       if (!app->remove_menu(argv[3])) {
00087         char buf[50];
00088         sprintf(buf, "Unable to remove menu %s\n", argv[3]);
00089         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00090         retval = TCL_ERROR;
00091       }
00092       else app->menu_remove_extension(argv[3]);
00093     }
00094     else retval = TCL_HELP;
00095 #else
00096     /* MACVMD just eats it, and does nothing presently */
00097 #endif
00098   }
00099 #endif
00100   else if (argc == 4 && !strupncmp(argv[2], "selectmol", CMDLEN)) {
00101     // undocumented command for internal use only!
00102     int ind;
00103     if (Tcl_GetInt(interp, argv[3], &ind) != TCL_OK) retval = TCL_HELP;
00104     else app->menu_select_mol(argv[1], ind);
00105   }
00106   else if(argc == 3) {
00107     if(!strupncmp(argv[2],"on",CMDLEN))
00108       app->menu_show(argv[1], 1);
00109     else if (!strupncmp(argv[2],"off",CMDLEN))
00110       app->menu_show(argv[1], 0);
00111     else if (!strupncmp(argv[2],"loc",CMDLEN)) {
00112       int x, y;
00113       if (app->menu_location(argv[1], x, y)) {
00114         char buf[20];
00115         sprintf(buf, "%d %d", x, y);
00116         Tcl_SetResult(interp, buf, TCL_VOLATILE);
00117       } 
00118       else {
00119         Tcl_AppendResult(interp, "menu loc: menu '", argv[1], 
00120           "' does not exist.", NULL);
00121         retval = TCL_ERROR;
00122       }
00123     } 
00124     else if (!strupncmp(argv[2], "status", CMDLEN))
00125       Tcl_AppendResult(interp, app->menu_status(argv[1]) ? "on" : "off", NULL);
00126     else  retval = TCL_HELP;
00127   }
00128   else if (argc == 5 && !strupncmp(argv[2],"move",CMDLEN))
00129     app->menu_move(argv[1], atoi(argv[3]), atoi(argv[4]));
00130   else
00131     retval = TCL_HELP;
00132   
00133   if (retval == TCL_HELP) {
00134     Tcl_SetResult(interp, 
00135       (char *) "Usage:\n"
00136       "\tmenu list                 -- returns list of available menus\n"
00137       "\tmenu <name> on            -- turn menu with given name on\n"
00138       "\tmenu <name> off           -- turn menu with given name off\n"
00139       "\tmenu <name> status         -- returns 'on' or 'off'\n"
00140       "\tmenu <name> loc           -- returns current position of menu\n"
00141       "\tmenu <name> move x y      -- move menu to given position\n"
00142       "\tmenu tk add <name> <tk window> [<menu path>]\n"
00143       "\t      -- add Tk menu to Extensions\n"
00144       "\tmenu tk register <name> <procname> [<menu path>]\n" 
00145       "\t      -- same as 'add', but <procname> returns tk window handle.\n"
00146       "\tmenu tk remove <name> -- remove menu from Extensions\n"
00147       "The Tk 'menu' command is also available.",
00148       TCL_STATIC);
00149     retval = TCL_ERROR;
00150   }
00151  
00152   return retval;
00153 }
00154 

Generated on Thu Apr 25 02:42:00 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002