00001 /* 00002 GNU GENERAL PUBLIC LICENSE 00003 Version 2, June 1991 00004 00005 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 00006 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00007 Everyone is permitted to copy and distribute verbatim copies 00008 of this license document, but changing it is not allowed. 00009 00010 Preamble 00011 00012 The licenses for most software are designed to take away your 00013 freedom to share and change it. By contrast, the GNU General Public 00014 License is intended to guarantee your freedom to share and change free 00015 software--to make sure the software is free for all its users. This 00016 General Public License applies to most of the Free Software 00017 Foundation's software and to any other program whose authors commit to 00018 using it. (Some other Free Software Foundation software is covered by 00019 the GNU Library General Public License instead.) You can apply it to 00020 your programs, too. 00021 00022 When we speak of free software, we are referring to freedom, not 00023 price. Our General Public Licenses are designed to make sure that you 00024 have the freedom to distribute copies of free software (and charge for 00025 this service if you wish), that you receive source code or can get it 00026 if you want it, that you can change the software or use pieces of it 00027 in new free programs; and that you know you can do these things. 00028 00029 To protect your rights, we need to make restrictions that forbid 00030 anyone to deny you these rights or to ask you to surrender the rights. 00031 These restrictions translate to certain responsibilities for you if you 00032 distribute copies of the software, or if you modify it. 00033 00034 For example, if you distribute copies of such a program, whether 00035 gratis or for a fee, you must give the recipients all the rights that 00036 you have. You must make sure that they, too, receive or can get the 00037 source code. And you must show them these terms so they know their 00038 rights. 00039 00040 We protect your rights with two steps: (1) copyright the software, and 00041 (2) offer you this license which gives you legal permission to copy, 00042 distribute and/or modify the software. 00043 00044 Also, for each author's protection and ours, we want to make certain 00045 that everyone understands that there is no warranty for this free 00046 software. If the software is modified by someone else and passed on, we 00047 want its recipients to know that what they have is not the original, so 00048 that any problems introduced by others will not reflect on the original 00049 authors' reputations. 00050 00051 Finally, any free program is threatened constantly by software 00052 patents. We wish to avoid the danger that redistributors of a free 00053 program will individually obtain patent licenses, in effect making the 00054 program proprietary. To prevent this, we have made it clear that any 00055 patent must be licensed for everyone's free use or not licensed at all. 00056 00057 The precise terms and conditions for copying, distribution and 00058 modification follow. 00059 00060 GNU GENERAL PUBLIC LICENSE 00061 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 00062 00063 0. This License applies to any program or other work which contains 00064 a notice placed by the copyright holder saying it may be distributed 00065 under the terms of this General Public License. The "Program", below, 00066 refers to any such program or work, and a "work based on the Program" 00067 means either the Program or any derivative work under copyright law: 00068 that is to say, a work containing the Program or a portion of it, 00069 either verbatim or with modifications and/or translated into another 00070 language. (Hereinafter, translation is included without limitation in 00071 the term "modification".) Each licensee is addressed as "you". 00072 00073 Activities other than copying, distribution and modification are not 00074 covered by this License; they are outside its scope. The act of 00075 running the Program is not restricted, and the output from the Program 00076 is covered only if its contents constitute a work based on the 00077 Program (independent of having been made by running the Program). 00078 Whether that is true depends on what the Program does. 00079 00080 1. You may copy and distribute verbatim copies of the Program's 00081 source code as you receive it, in any medium, provided that you 00082 conspicuously and appropriately publish on each copy an appropriate 00083 copyright notice and disclaimer of warranty; keep intact all the 00084 notices that refer to this License and to the absence of any warranty; 00085 and give any other recipients of the Program a copy of this License 00086 along with the Program. 00087 00088 You may charge a fee for the physical act of transferring a copy, and 00089 you may at your option offer warranty protection in exchange for a fee. 00090 00091 2. You may modify your copy or copies of the Program or any portion 00092 of it, thus forming a work based on the Program, and copy and 00093 distribute such modifications or work under the terms of Section 1 00094 above, provided that you also meet all of these conditions: 00095 00096 a) You must cause the modified files to carry prominent notices 00097 stating that you changed the files and the date of any change. 00098 00099 b) You must cause any work that you distribute or publish, that in 00100 whole or in part contains or is derived from the Program or any 00101 part thereof, to be licensed as a whole at no charge to all third 00102 parties under the terms of this License. 00103 00104 c) If the modified program normally reads commands interactively 00105 when run, you must cause it, when started running for such 00106 interactive use in the most ordinary way, to print or display an 00107 announcement including an appropriate copyright notice and a 00108 notice that there is no warranty (or else, saying that you provide 00109 a warranty) and that users may redistribute the program under 00110 these conditions, and telling the user how to view a copy of this 00111 License. (Exception: if the Program itself is interactive but 00112 does not normally print such an announcement, your work based on 00113 the Program is not required to print an announcement.) 00114 00115 These requirements apply to the modified work as a whole. If 00116 identifiable sections of that work are not derived from the Program, 00117 and can be reasonably considered independent and separate works in 00118 themselves, then this License, and its terms, do not apply to those 00119 sections when you distribute them as separate works. But when you 00120 distribute the same sections as part of a whole which is a work based 00121 on the Program, the distribution of the whole must be on the terms of 00122 this License, whose permissions for other licensees extend to the 00123 entire whole, and thus to each and every part regardless of who wrote it. 00124 00125 Thus, it is not the intent of this section to claim rights or contest 00126 your rights to work written entirely by you; rather, the intent is to 00127 exercise the right to control the distribution of derivative or 00128 collective works based on the Program. 00129 00130 In addition, mere aggregation of another work not based on the Program 00131 with the Program (or with a work based on the Program) on a volume of 00132 a storage or distribution medium does not bring the other work under 00133 the scope of this License. 00134 00135 3. You may copy and distribute the Program (or a work based on it, 00136 under Section 2) in object code or executable form under the terms of 00137 Sections 1 and 2 above provided that you also do one of the following: 00138 00139 a) Accompany it with the complete corresponding machine-readable 00140 source code, which must be distributed under the terms of Sections 00141 1 and 2 above on a medium customarily used for software interchange; or, 00142 00143 b) Accompany it with a written offer, valid for at least three 00144 years, to give any third party, for a charge no more than your 00145 cost of physically performing source distribution, a complete 00146 machine-readable copy of the corresponding source code, to be 00147 distributed under the terms of Sections 1 and 2 above on a medium 00148 customarily used for software interchange; or, 00149 00150 c) Accompany it with the information you received as to the offer 00151 to distribute corresponding source code. (This alternative is 00152 allowed only for noncommercial distribution and only if you 00153 received the program in object code or executable form with such 00154 an offer, in accord with Subsection b above.) 00155 00156 The source code for a work means the preferred form of the work for 00157 making modifications to it. For an executable work, complete source 00158 code means all the source code for all modules it contains, plus any 00159 associated interface definition files, plus the scripts used to 00160 control compilation and installation of the executable. However, as a 00161 special exception, the source code distributed need not include 00162 anything that is normally distributed (in either source or binary 00163 form) with the major components (compiler, kernel, and so on) of the 00164 operating system on which the executable runs, unless that component 00165 itself accompanies the executable. 00166 00167 If distribution of executable or object code is made by offering 00168 access to copy from a designated place, then offering equivalent 00169 access to copy the source code from the same place counts as 00170 distribution of the source code, even though third parties are not 00171 compelled to copy the source along with the object code. 00172 00173 4. You may not copy, modify, sublicense, or distribute the Program 00174 except as expressly provided under this License. Any attempt 00175 otherwise to copy, modify, sublicense or distribute the Program is 00176 void, and will automatically terminate your rights under this License. 00177 However, parties who have received copies, or rights, from you under 00178 this License will not have their licenses terminated so long as such 00179 parties remain in full compliance. 00180 00181 5. You are not required to accept this License, since you have not 00182 signed it. However, nothing else grants you permission to modify or 00183 distribute the Program or its derivative works. These actions are 00184 prohibited by law if you do not accept this License. Therefore, by 00185 modifying or distributing the Program (or any work based on the 00186 Program), you indicate your acceptance of this License to do so, and 00187 all its terms and conditions for copying, distributing or modifying 00188 the Program or works based on it. 00189 00190 6. Each time you redistribute the Program (or any work based on the 00191 Program), the recipient automatically receives a license from the 00192 original licensor to copy, distribute or modify the Program subject to 00193 these terms and conditions. You may not impose any further 00194 restrictions on the recipients' exercise of the rights granted herein. 00195 You are not responsible for enforcing compliance by third parties to 00196 this License. 00197 00198 7. If, as a consequence of a court judgment or allegation of patent 00199 infringement or for any other reason (not limited to patent issues), 00200 conditions are imposed on you (whether by court order, agreement or 00201 otherwise) that contradict the conditions of this License, they do not 00202 excuse you from the conditions of this License. If you cannot 00203 distribute so as to satisfy simultaneously your obligations under this 00204 License and any other pertinent obligations, then as a consequence you 00205 may not distribute the Program at all. For example, if a patent 00206 license would not permit royalty-free redistribution of the Program by 00207 all those who receive copies directly or indirectly through you, then 00208 the only way you could satisfy both it and this License would be to 00209 refrain entirely from distribution of the Program. 00210 00211 If any portion of this section is held invalid or unenforceable under 00212 any particular circumstance, the balance of the section is intended to 00213 apply and the section as a whole is intended to apply in other 00214 circumstances. 00215 00216 It is not the purpose of this section to induce you to infringe any 00217 patents or other property right claims or to contest validity of any 00218 such claims; this section has the sole purpose of protecting the 00219 integrity of the free software distribution system, which is 00220 implemented by public license practices. Many people have made 00221 generous contributions to the wide range of software distributed 00222 through that system in reliance on consistent application of that 00223 system; it is up to the author/donor to decide if he or she is willing 00224 to distribute software through any other system and a licensee cannot 00225 impose that choice. 00226 00227 This section is intended to make thoroughly clear what is believed to 00228 be a consequence of the rest of this License. 00229 00230 8. If the distribution and/or use of the Program is restricted in 00231 certain countries either by patents or by copyrighted interfaces, the 00232 original copyright holder who places the Program under this License 00233 may add an explicit geographical distribution limitation excluding 00234 those countries, so that distribution is permitted only in or among 00235 countries not thus excluded. In such case, this License incorporates 00236 the limitation as if written in the body of this License. 00237 00238 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 00239 00240 Each version is given a distinguishing version number. If the Program 00241 specifies a version number of this License which applies to it and "any 00242 later version", you have the option of following the terms and conditions 00243 either of that version or of any later version published by the Free Software 00244 Foundation. If the Program does not specify a version number of this License, 00245 you may choose any version ever published by the Free Software Foundation. 00246 00247 10. If you wish to incorporate parts of the Program into other free 00248 programs whose distribution conditions are different, write to the author to 00249 ask for permission. For software which is copyrighted by the Free Software 00250 Foundation, write to the Free Software Foundation; we sometimes make 00251 exceptions for this. Our decision will be guided by the two goals of 00252 preserving the free status of all derivatives of our free software and of 00253 promoting the sharing and reuse of software generally. 00254 00255 NO WARRANTY 00256 00257 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR 00258 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 00259 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE 00260 THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 00261 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00262 FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 00263 PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, 00264 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 00265 00266 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 00267 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 00268 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 00269 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 00270 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO 00271 LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR 00272 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 00273 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 00274 DAMAGES. 00275 00276 END OF TERMS AND CONDITIONS ' 00277 */ 00278 static const char* Copyright= "(C) Copyright Michigan State University 2002, All rights reserved";/* 00279 ** Facility: 00280 ** Xamine MOTIF C++ support. 00281 ** Abstract: 00282 ** XMMenus.cc - This file contains method code to support the XMMenus 00283 ** classes. These class allows the client to construct 00284 ** menu items a bit more easily than direct motif calls. 00285 ** Methods for the following classes are present: 00286 ** XMPulldown - Pulldown menu. 00287 ** XMMenuBar - Menu bar class. 00288 ** Author: 00289 ** Ron Fox 00290 ** NSCL 00291 ** Michigan State University 00292 ** East Lansing, MI 48824-1321 00293 ** Version information: 00294 ** @(#)XMMenus.cc 8.1 6/23/95 00295 */ 00296 00297 /* 00298 ** Include files: 00299 */ 00300 #include <config.h> 00301 #include <stdio.h> 00302 #include <Xm/Separator.h> 00303 #include "XMMenus.h" 00304 00305 #ifdef HAVE_STD_NAMESPACE 00306 using namespace std; 00307 #endif 00308 00309 /* 00310 ** Declarations: 00311 */ 00312 00313 extern "C" { 00314 void exit(int); 00315 } 00316 00317 00318 /* 00319 ** Method description: 00320 ** BuildMenu - This private method builds a pulldown menu. 00321 ** At this point, nothing has been done since we've invoked 00322 ** the default constructor of the XMManaged widget which 00323 ** just copies the widget name. 00324 ** Formal Parameters: 00325 ** Cardinal max_items: 00326 00327 ** The maximum number of items in the menu. This includes buttons, 00328 ** submenus and yes, even separators. 00329 ** Widget parent: 00330 ** The parent widget for the menu... this should either be another menu 00331 ** or a menu bar. 00332 ** ArgList l: 00333 ** A posibly null argument list of resource modifiers. 00334 ** Cardinal num_args: 00335 ** A possibly zero number entries in l. 00336 */ 00337 void XMPulldown::BuildMenu(Cardinal max_items, Widget parent, 00338 ArgList l, Cardinal num_args) 00339 { 00340 00341 /* Attempt to get the required storage: */ 00342 00343 if(max_items == 0) { 00344 fprintf(stderr, "Error from XMPulldown constructor... max_items = 0\n"); 00345 exit(-1); 00346 } 00347 menu_count = 0; 00348 max_menu_items = max_items; 00349 menu_items = new XMMenuItem[max_items]; 00350 if(menu_items == NULL) { 00351 fprintf(stderr, "Error from XMPulldown constructor...%s\n", 00352 "Unable to allocate menu_items"); 00353 exit(-1); 00354 } 00355 for(int i = 0; i < max_menu_items; i++) { 00356 menu_items[i].item = NULL; 00357 menu_items[i].type = Unused; 00358 } 00359 00360 /* Create the pulldown menu: */ 00361 00362 id = XmCreatePulldownMenu(parent, name, l, num_args); 00363 00364 /* Now we create a cascade button which is linked to the pulldown via 00365 ** the XmNsubMenuId resource. 00366 */ 00367 pd_button = new XMCascadeButton(name, parent); 00368 pd_button->Label(name); 00369 pd_button->SetAssociatedMenu(id); 00370 pd_button->SetMnemonic(name[0]); 00371 00372 if(pd_button == NULL) { 00373 fprintf(stderr, 00374 "XMPulldown constructor error...Could not make new cascade button\n"); 00375 } 00376 } 00377 00378 /* 00379 ** Method Description: 00380 ** ~XMPulldown - Destructor for the pulldown menu class. 00381 ** We must destroy the cascade button widget as well 00382 ** as all the widgets in the menu list. 00383 */ 00384 XMPulldown::~XMPulldown() 00385 { 00386 delete pd_button; /* Destroy the cascade button. */ 00387 00388 00389 /* Destroy all the widgets and submenus: */ 00390 00391 for(int idx = 0; idx < menu_count; idx++) { 00392 XMManagedWidget *mw; 00393 XMPushButton *pb; 00394 XMToggleButton *tb; 00395 XMPulldown *pd; 00396 switch(menu_items[idx].type) { 00397 case Unused: 00398 break; 00399 case Separator: 00400 mw = (XMManagedWidget *)menu_items[idx].item; 00401 delete mw; 00402 break; 00403 case Button: 00404 pb = (XMPushButton *)menu_items[idx].item; 00405 delete pb; 00406 break; 00407 case ToggleButton: 00408 tb = (XMToggleButton *)menu_items[idx].item; 00409 delete tb; 00410 break; 00411 case Submenu: 00412 pd = (XMPulldown *)menu_items[idx].item; 00413 delete pd; 00414 break; 00415 default: 00416 fprintf(stderr, 00417 "Error in XMMenu destructor... invalid item type\n"); 00418 break; 00419 } 00420 } 00421 /* Destroy the book keeping storage: */ 00422 00423 delete []menu_items; 00424 00425 } 00426 00427 /* 00428 ** Method Description: 00429 ** XMPulldown::AddMenuButton - This method adds a pushbutton menu entry to the 00430 ** pulldown menu. This is done at the end of the 00431 ** current list of menu items. 00432 ** Formal Parameters: 00433 ** char *n: 00434 ** Name of the button, also used as the label string. 00435 ** void (*callback)(XMWIdget, XtPointer, XtPointer): 00436 ** Callback to be associated with the activation of the button. 00437 ** NULL for no callback. 00438 ** XtPointer client_data: 00439 ** Possibly null client data for the callback. 00440 ** ArgList l: 00441 ** Possibly null argument list of resource overrides for the pushbutton. 00442 ** Most commonly used to set up the button mnemonic, or to control the 00443 ** initial sensitivity of the button. 00444 ** Cardinal num_args: 00445 ** Possibly zero argument list size. 00446 */ 00447 XMPushButton *XMPulldown::AddMenuButton(char *n, 00448 void (*callback)(XMWidget *, 00449 XtPointer, 00450 XtPointer), 00451 XtPointer client_data, 00452 ArgList l, 00453 Cardinal num_args) 00454 { 00455 XMPushButton *pb; 00456 /* First ensure that there's room: */ 00457 00458 if(menu_count >= max_menu_items) { 00459 fprintf(stderr, 00460 "Error in XMPulldown::AddmenuButton - Maximum menu size exceeded\n" 00461 ); 00462 exit(-1); 00463 } 00464 menu_items[menu_count].item = pb = new XMPushButton(n, 00465 *this, 00466 callback, 00467 client_data); 00468 if(pb == NULL) { 00469 fprintf(stderr, 00470 "Error in XMPulldown::AddmenuButton - unable to new pushbutton\n"); 00471 exit(-1); 00472 } 00473 /* Set the item list properties: */ 00474 00475 for(int i = 0; i < num_args; i++) { 00476 pb->SetAttribute(l[i].name, l[i].value); 00477 } 00478 menu_items[menu_count].type = Button; 00479 00480 /* Count one more entry and return the widget object pointer. */ 00481 00482 menu_count++; 00483 return pb; 00484 } 00485 00486 /* 00487 ** Method Description: 00488 ** XMToggleButton *XMPulldown::AddMenuToggleButton - 00489 ** This function adds a toggle button 00490 ** to the pulldown menu. 00491 ** Formal Parameters: 00492 ** char *n: 00493 ** Name of the button and default label. 00494 ** void (*callback)(XMWidget *, XtPointer, XtPointer): 00495 ** Pointer to the callback or NULL If there isn't to be one. 00496 ** XtPointer client_data: 00497 ** Call back function client data or NULL if there isn't any. 00498 ** ArgList l: 00499 ** Possibly NULL set of override resources. 00500 ** Cardinal num_args: 00501 ** Possibly zero count of override resources 00502 ** Returns: 00503 ** Pointer to toggle button widget object. 00504 */ 00505 XMToggleButton *XMPulldown::AddMenuToggleButton(char *n, 00506 void (*callback)(XMWidget *, 00507 XtPointer, 00508 XtPointer), 00509 XtPointer client_data, 00510 ArgList l, 00511 Cardinal num_args) 00512 { 00513 XMToggleButton *pb; 00514 /* First ensure that there's room: */ 00515 00516 if(menu_count >= max_menu_items) { 00517 fprintf(stderr, 00518 "Error in XMPulldown::AddmenuToggleButton - Maximum menu size exceeded\n" 00519 ); 00520 exit(-1); 00521 } 00522 menu_items[menu_count].item = pb = new XMToggleButton(n, 00523 *this, 00524 callback, 00525 client_data); 00526 if(pb == NULL) { 00527 fprintf(stderr, 00528 "Error in XMPulldown::AddmenuButton - unable to new pushbutton\n"); 00529 exit(-1); 00530 } 00531 /* Set the item list properties: */ 00532 00533 for(int i = 0; i < num_args; i++) { 00534 pb->SetAttribute(l[i].name, l[i].value); 00535 } 00536 menu_items[menu_count].type = ToggleButton; 00537 00538 /* Count one more entry and return the widget object pointer. */ 00539 00540 menu_count++; 00541 return pb; 00542 } 00543 00544 00545 /* 00546 ** Method Description: 00547 ** XMPulldown::AddSeparator - This method adds a separator object to a menu. 00548 ** A separator looks like a horizontal line that spans the 00549 ** width of the menu. 00550 ** Returns: 00551 ** Pointer to the created object widget. 00552 */ 00553 XMWidget *XMPulldown::AddSeparator() 00554 { 00555 XMManagedWidget *sep; 00556 char n[30]; 00557 00558 /* Make sure there's room: */ 00559 00560 if(menu_count >= max_menu_items) { 00561 fprintf(stderr, 00562 "Error in XMPullDown::AddSeparator. Too many menu items\n"); 00563 exit(-1); 00564 } 00565 00566 /* Now create the widget: */ 00567 00568 sprintf(n, "Sep_%d", menu_count); 00569 menu_items[menu_count].item = sep = 00570 new XMManagedWidget(n, 00571 xmSeparatorWidgetClass, 00572 *this); 00573 if(sep == NULL) { 00574 fprintf(stderr, 00575 "Error in XMPullDown::AddSeparator.. Failed new XMManagedWidget\n"); 00576 exit(-1); 00577 } 00578 /* Set the entry type and return to the caller: */ 00579 00580 menu_items[menu_count].type = Separator; 00581 menu_count++; 00582 00583 return sep; 00584 00585 } 00586 00587 /* 00588 ** Method Description: 00589 ** XMPulldown::AddSubmenu - This method adds a submenu to the parent 00590 ** menu. The submenu is a pull right menu. 00591 ** This is done by creating a new Pulldown 00592 ** with 'this' as the parent. 00593 ** Formal Parameters: 00594 ** char *n: 00595 ** Pulldown name and button label. 00596 ** int size: 00597 ** Maximum number of items in the menu 00598 ** ArgList l: 00599 ** Possibly null list of resource modifiers. 00600 ** Cardinal num_args: 00601 ** Possibly zero count of the argument list. 00602 ** Returns: 00603 ** Pointer to the created widget object. 00604 */ 00605 XMPulldown *XMPulldown::AddSubmenu(char *n, int size, ArgList l, Cardinal num_args) 00606 { 00607 XMPulldown *pd; 00608 00609 /* Check that we won't be exceeding bounds on menu size: */ 00610 00611 if(menu_count >= max_menu_items) { 00612 fprintf(stderr, 00613 "Error in XMPulldown::AddSubmenu - menu size exceeded\n"); 00614 exit(-1); 00615 } 00616 /* Generate the new pulldown: */ 00617 00618 menu_items[menu_count].item = pd = 00619 new XMPulldown(n, *this, size, l, num_args); 00620 if(pd == NULL) { 00621 fprintf(stderr, 00622 "Error in XMPulldown::AddSubmenu - new XMPulldown failed\n"); 00623 exit(-1); 00624 00625 } 00626 /* Set type, increment the size and return the pulldown */ 00627 00628 menu_items[menu_count].type = Submenu; 00629 menu_count++; 00630 00631 return pd; 00632 } 00633 00634 /* 00635 ** Method Description: 00636 ** XMPulldown::FindMenuItem - Locates a menu item in a Pulldown. 00637 ** If there are descendents submenus, 00638 ** they too are searched. Note that the 00639 ** name could be that of a submenu legally. 00640 ** Formal Parameters: 00641 ** char *n: 00642 ** Name of the item to find. 00643 ** Returns: 00644 ** Pointer to the entry located or 00645 */ 00646 XMMenuItem *XMPulldown::FindMenuItem(char *n) 00647 { 00648 XMMenuItem *here, *found; 00649 00650 here = menu_items; 00651 for(int i = 0; i < menu_count; i ++,here++) { 00652 XMPulldown *sm; 00653 switch(here->type) { 00654 case Unused: 00655 break; /* No associated widget. */ 00656 case Separator: 00657 case Button: 00658 case ToggleButton: 00659 if(strcmp(n, here->item->getname()) == 0) 00660 return here; 00661 break; 00662 case Submenu: /* Search recursively: */ 00663 { 00664 sm = (XMPulldown *)here->item; 00665 found = sm->FindMenuItem(n); 00666 if(found) return found; 00667 } 00668 break; 00669 default: 00670 fprintf(stderr, 00671 "Error XMPulldown::FindMenuItem invalid menu item type\n"); 00672 exit(-1); 00673 } 00674 } 00675 return NULL; 00676 } 00677 00678 /* 00679 ** Method Description: 00680 ** XMPulldown::GetNextMenuItem - This function returns the next menu 00681 ** item in an interative retrieval. 00682 ** Returns: 00683 ** Pointer to the menu entry or NULL if at the end of the list. 00684 */ 00685 XMMenuItem *XMPulldown::GetNextMenuItem() 00686 { 00687 XMMenuItem *here; 00688 00689 if(menu_cursor < menu_count) { 00690 here = &menu_items[menu_cursor]; 00691 menu_cursor++; 00692 } 00693 else { 00694 here = NULL; 00695 } 00696 return here; 00697 } 00698 00699 /* 00700 ** Method Description: 00701 ** XMMenuBar::mbCreate - This method is used by the creation 00702 ** operators (constructors) of the menubar class. 00703 ** We do the following: 00704 ** Initialize attribute values. 00705 ** Allocate storage for the menubar book-keeping 00706 ** fields. 00707 ** Create the menubar widget. 00708 ** Note, while we inherit from XMManagedWidget, 00709 ** we have not yet been created as the constructor 00710 ** has called a null constructor which has only copied 00711 ** the widget name into the name field. 00712 ** Formal Parameters: 00713 ** Widget parent: 00714 ** Parent widget id. 00715 ** Cardinal num_menus: 00716 ** Maximum number of pull down menus the bar will support. 00717 ** ArgList l: 00718 ** Possibly null list of resource overrides. 00719 ** Cardinal num_args: 00720 ** Possibly zero count of elements in l. 00721 */ 00722 typedef XMPulldown *pdpointer; 00723 void XMMenuBar::mbCreate(Widget parent, Cardinal num_menus, ArgList l, 00724 Cardinal num_args) 00725 { 00726 /* Initialize the attribute fields */ 00727 00728 menu_count = 0; 00729 max_menu_items = num_menus; 00730 help_pulldown = NULL; /* No help pulldown yet. */ 00731 00732 /* Allocate storage for the pulldown list: */ 00733 00734 menu_items = new pdpointer[max_menu_items]; 00735 if(menu_items == NULL) { 00736 fprintf(stderr, 00737 "XMMenuBar constructor error.. could not allocate menu list\n"); 00738 exit(-1); 00739 } 00740 for(int i = 0; i < max_menu_items; i++) 00741 menu_items[i] = NULL; 00742 00743 /* Create the menu bar: */ 00744 00745 id = XmCreateMenuBar(parent, name, l, num_args); 00746 00747 } 00748 00749 /* 00750 ** Method Description: 00751 ** ~XMMenuBar - Destructor for the menu bar class. 00752 ** We must delete all the pulldowns that have been 00753 ** added and we must free the storage taken up by the 00754 ** pulldown widget list. 00755 */ 00756 XMMenuBar::~XMMenuBar() 00757 { 00758 00759 00760 /* Kill the pulldowns: */ 00761 00762 for(int i = 0; i < max_menu_items; i++) { 00763 delete menu_items[i]; 00764 } 00765 delete []menu_items; /* Kill the pointer storage. */ 00766 00767 /* The managed widget destructor will take care of killing the menubar 00768 ** widget 00769 */ 00770 } 00771 00772 /* 00773 ** Method Description: 00774 ** XMMenuBar::AddPulldown - This method adds a pulldown menu to a menu bar. 00775 ** If there is a free element in the widget list, 00776 ** a pulldown is dynamically created and added 00777 ** to the list. 00778 ** Formal Parameters: 00779 ** char *n: 00780 ** Name of the pulldown menu -- will also wind up being the menu label. 00781 ** int max_items: 00782 ** Number of items in the menu. 00783 ** ArgList l: 00784 ** Possibly null set of resource overrides for the pulldown menu widget. 00785 ** Note to override the cascade button widget resources, you must get 00786 ** the cascade button widget and then SetAttributes on it. 00787 ** Cardinal num_args: 00788 ** Possibly zero argument list count. 00789 ** Returns: 00790 ** A pointer to the pulldown menu object so that the user can stock it 00791 ** with menu entries. 00792 **/ 00793 00794 XMPulldown *XMMenuBar::AddPulldown(char *n, int max_items, 00795 ArgList l, Cardinal num_args) 00796 { 00797 XMPulldown *pd; 00798 00799 /* Check to see that we have room for the new kid: */ 00800 00801 if(menu_count >= max_menu_items) { 00802 fprintf(stderr, 00803 "XMMenuBar::AddPulldown - Menu bar size exceeded\n"); 00804 exit(-1); 00805 } 00806 00807 /* Create and add the new pulldown: */ 00808 00809 menu_items[menu_count] = pd = 00810 new XMPulldown(n, *this, max_items, l, num_args); 00811 if(pd == NULL) { 00812 fprintf(stderr, 00813 "XMMenuBar::AddPulldown - Pulldown creation failed\n"); 00814 exit(-1); 00815 } 00816 00817 /* Update the count and return the widget: */ 00818 00819 menu_count++; 00820 return pd; 00821 } 00822 00840 XMPulldown *XMMenuBar::AddHelpPulldown(char *n, int max_items, 00841 ArgList l, Cardinal num_args) 00842 { 00843 if(help_pulldown) { /* Attempting second help menu */ 00844 fprintf(stderr, 00845 "XMMenuBar::AddHelpPulldown--attempted to add second pulldown \n"); 00846 exit(-1); 00847 } 00848 help_pulldown = AddPulldown(n, max_items, l, num_args); /* It's a pulldown */ 00849 if(help_pulldown == NULL) { 00850 fprintf(stderr, 00851 "XMMenuBar::AddHelpPulldown - Add of help pulldown failed\n"); 00852 exit(-1); 00853 } 00854 SetAttribute(XmNmenuHelpWidget, help_pulldown->GetCascadeButton()->getid()); 00855 00856 return help_pulldown; 00857 } 00858 00859 /* 00860 ** Method Description: 00861 ** XMMenuBar::GetPulldown - Returns a pointer to a named pulldown object 00862 ** or NULL if there isn't a match 00863 ** Formal Parameters: 00864 ** char *n: 00865 ** The name of the pulldown sought. 00866 ** Returns: 00867 ** Pointer to the pulldown or NULL if there is no match. 00868 */ 00869 XMPulldown *XMMenuBar::GetPulldown(char *n) 00870 { 00871 for(int i = 0; i < menu_count; i++) { 00872 if(strcmp(menu_items[i]->getname(), n) == 0) 00873 return menu_items[i]; 00874 } 00875 return NULL; 00876 } 00877 00878 /* 00879 ** Method Description: 00880 ** XMMenuBar::GetMenuItem - Searches the menu hiearchy attached to this 00881 ** menu bar for a match with a widget name. 00882 ** Formal Parameters: 00883 ** char *n: 00884 ** Name of the widget to hunt for. 00885 ** Returns: 00886 ** Pointer to the XMMenuItem which describes the menu item or NULL if 00887 ** there is no match in the menu hierarchy. 00888 **/ 00889 00890 XMMenuItem *XMMenuBar::GetMenuItem(char *n) 00891 { 00892 XMMenuItem *theone; 00893 00894 for(int i = 0; i < menu_count; i++) { 00895 theone = menu_items[i]->FindMenuItem(n); 00896 if(theone) 00897 return theone; 00898 } 00899 return NULL; 00900 00901 } 00902 00903 /* 00904 ** Method Description: 00905 ** XMMenuBar::GetNextPulldown - This method iterates through the pulldown 00906 ** menu list associated with the menu bar 00907 ** and returns the next pulldown 00908 ** Returns: 00909 ** XMPulldown * pointer to the next pulldown or NULL If there aren't any more 00910 */ 00911 XMPulldown *XMMenuBar::GetNextPulldown() 00912 { 00913 XMPulldown *here; 00914 00915 if(menu_cursor < menu_count) { 00916 here = menu_items[menu_cursor]; 00917 menu_cursor++; 00918 } 00919 else 00920 here = NULL; 00921 return here; 00922 }