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

XMDialogs.h

Go to the documentation of this file.
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 /*
00279 ** Facility:
00280 **   Motif C++ class support.
00281 ** Abstract:
00282 **   XMDialogs.h  - This file contains support for C++ access to Motif
00283 **                  dialogs.
00284 ** Author:
00285 **  Ron Fox
00286 **  NSCL
00287 **  Michigan State University
00288 **  East Lansing, MI 48824-1321
00289 ** Versioning
00290 **   @(#)XMDialogs.h    8.2 7/10/95 
00291 */
00292 
00293 #ifndef XMDialogs_h
00294 #define XMDialogs_h
00295 #include <stdio.h>
00296 
00297 #include <X11/StringDefs.h>
00298 #include <Xm/MessageB.h>
00299 #include <Xm/SelectioB.h>
00300 #include <Xm/FileSB.h>
00301 
00302 #include "XMWidget.h"
00303 #include "XMPushbutton.h"
00304 #include "XMManagers.h"
00305 #include "XMCallback.h"
00306 
00307 /*
00308 ** #Defines:
00309 **
00310 */
00311 #ifdef unix
00312 #define XMFILE_DEFAULT_DIR     "./"
00313 #define XMFILE_DEFAULT_DIRMASK "./*"
00314 #endif
00315 
00316 #ifdef VMS
00317 #define XMFILE_DEFAULT_DIR     "SYS$DISK:[]"
00318 #define XMFILE_DEFAULT_DIRMASK "SYS$DISK:[]*.*;0"
00319 #endif
00320 
00321 /* The message box is the parent widget type of all message like dialogs: */
00322 
00323 class XMMessageBox : public XMManagedWidget
00324                    {
00325                    protected:
00326                      XMPushButton *okbutton;
00327                      XMPushButton *cancelbutton;
00328                      XMPushButton *helpbutton;
00329                      void GetButtons()
00330                        {
00331                          Widget wid;
00332                          wid = XmMessageBoxGetChild(id, XmDIALOG_OK_BUTTON);
00333                          okbutton = new XMPushButton(wid);
00334 
00335                          wid = XmMessageBoxGetChild(id, XmDIALOG_CANCEL_BUTTON);
00336                          cancelbutton = new XMPushButton(wid);
00337 
00338                          wid = XmMessageBoxGetChild(id, XmDIALOG_HELP_BUTTON);
00339                          helpbutton = new  XMPushButton(wid); 
00340                        }
00341                    public:
00342                      /* Constructors and destructors */
00343 
00344                      virtual ~XMMessageBox()
00345                        { delete okbutton;
00346                          delete cancelbutton;
00347                          delete helpbutton;
00348                        }
00349                      XMMessageBox(char *n) : XMManagedWidget(n) {}
00350                      XMMessageBox(Widget w) : XMManagedWidget(w)
00351                        {
00352                          GetButtons(); 
00353                        }
00354                      /* Get Button Widgets: */
00355 
00356                      XMPushButton *GetOkButton()     { return okbutton; }
00357                      XMPushButton *GetCancelButton() { return cancelbutton; }
00358                      XMPushButton *GetHelpButton()   { return helpbutton; }
00359                      
00360                      /* Modify the dialog text: */
00361 
00362                      virtual void SetText(char *txt)
00363                {
00364                          XmString s = XmStringCreateLtoR(txt, 
00365                                                      XmSTRING_DEFAULT_CHARSET);
00366                          SetAttribute(XmNmessageString, s);
00367                          XmStringFree(s);
00368                        }
00369                      /* Add Ok/Cancel callbacks: */
00370 
00371                      Callback_data *AddOkCallback(void (*cb)(XMWidget *w,
00372                                                    XtPointer, 
00373                                                    XtPointer),
00374                                         XtPointer cd = NULL)
00375                        {
00376                          return AddCallback(XmNokCallback, cb, cd);
00377                        }
00378                      Callback_data *AddCancelCallback(void (*cb)(XMWidget *w,
00379                                                        XtPointer,
00380                                                        XtPointer),
00381                                             XtPointer cd = NULL)
00382                        {
00383                          return AddCallback(XmNcancelCallback, cb, cd);
00384                        }
00385                      /* Label cancel/Help/OK buttons */
00386 
00387                      void LabelCancelButton(char *txt) 
00388                        { XmString str = XmStringCreateLtoR(txt, 
00389                                                  XmSTRING_DEFAULT_CHARSET);
00390                          SetAttribute(XmNcancelLabelString, str);
00391                          XmStringFree(str);
00392                        }
00393                      void LabelOkButton(char *txt)
00394                        {
00395                          XmString str = XmStringCreateLtoR(txt,
00396                                                  XmSTRING_DEFAULT_CHARSET);
00397                          SetAttribute(XmNokLabelString, str);
00398                          XmStringFree(str);
00399                        }
00400                      void LabelHelpButton(char *txt)
00401                        { helpbutton->Label(txt); }
00402 
00403                      /* Set default button types: */
00404 
00405                      void DefaultToOk()
00406                        { SetAttribute(XmNdefaultButtonType,
00407                                       XmDIALOG_OK_BUTTON);
00408                        }
00409                      void DefaultToCancel()
00410                        { SetAttribute(XmNdefaultButtonType,
00411                                       XmDIALOG_CANCEL_BUTTON);
00412                        }
00413                      void DefaultToHelp()
00414                        {
00415                          SetAttribute(XmNdefaultButtonType,
00416                                       XmDIALOG_HELP_BUTTON);
00417                        }
00418                      void Show() {
00419                        Manage();
00420                        XtPopup(XtParent(id), XtGrabNone);
00421                      }
00422                      void Hide() {
00423                        UnManage();
00424                      }
00425                      void SetModal(unsigned char modality)
00426                        { SetAttribute(XmNdialogStyle, modality); }
00427                    };
00428 
00429 
00430 
00431 /* Error dialogs specialize the Message box widget for error messages */
00432 
00433 
00434 
00435 class XMErrorDialog : public XMMessageBox
00436                    {
00437                    public:
00438                      /*  Constructors: */
00439                      XMErrorDialog(char *n, Widget parent, char *msg,
00440                                    void (*cb)(XMWidget *,
00441                                               XtPointer, XtPointer) = NULL,
00442                                    XtPointer cbd = NULL,
00443                                    ArgList list = NULL, Cardinal argcount = 0):
00444                                      XMMessageBox(n)
00445                                        {
00446                                          id = XmCreateErrorDialog(parent,
00447                                                                   name,
00448                                                                   list,
00449                                                                   argcount);
00450                                          SetText(msg);
00451                                          GetButtons();
00452                                          LabelOkButton("Dismiss");
00453                                          cancelbutton->Disable();
00454                                          helpbutton->Disable();
00455                                          if(cb)
00456                                            AddOkCallback(cb, cbd);
00457                                          Manage();
00458                                          XtPopup(XtParent(id), XtGrabNone);
00459                                        }
00460                      XMErrorDialog(char *n, XMWidget &parent, char *msg,
00461                                    void (*cb)(XMWidget *,
00462                                               XtPointer, XtPointer) = NULL,
00463                                    XtPointer cbd = NULL,
00464                                    ArgList list = NULL, Cardinal argcount = 0):
00465                                      XMMessageBox(n)
00466                                        {
00467                                          id = XmCreateErrorDialog(parent.getid(),
00468                                                                   name,
00469                                                                   list,
00470                                                                   argcount);
00471                                          SetText(msg);
00472                                          GetButtons();
00473                                          LabelOkButton("Dismiss");
00474                                          cancelbutton->Disable();
00475                                          helpbutton->Disable();
00476                                          if(cb) 
00477                                            AddOkCallback(cb, cbd);
00478                                          Manage();
00479                                          XtPopup(XtParent(id), XtGrabNone);
00480                                        }
00481                      XMErrorDialog(Widget w) : XMMessageBox(w)
00482                        {
00483                        }
00484                    };
00485 
00486 /* Information dialogs specialize MessageBox for informative messages: */
00487 
00488 
00489 class XMInformationDialog : public XMMessageBox
00490 {
00491  public:
00492   /*  Constructors: */
00493   XMInformationDialog(char *n,Widget parent, char *msg,
00494                       void (*cb)(XMWidget *,
00495                                  XtPointer, XtPointer) = NULL,
00496                       XtPointer cbd = NULL,
00497                       ArgList list = NULL, Cardinal argcount=0) :
00498                         XMMessageBox(n)
00499                           {
00500                             id = XmCreateInformationDialog(parent,
00501                                                            name,
00502                                                            list,
00503                                                            argcount);
00504                             SetText(msg);
00505                             GetButtons();
00506                             LabelOkButton("Dismiss");
00507                             cancelbutton->Disable();
00508                             helpbutton->Disable();
00509                             if(cb)
00510                               AddOkCallback(cb, cbd);
00511                             Manage();
00512                             XtPopup(XtParent(id), XtGrabNone);
00513                           }
00514   XMInformationDialog(char *n, XMWidget &parent, char *msg,
00515                       void (*cb)(XMWidget *,
00516                                  XtPointer, XtPointer) = NULL,
00517                       XtPointer cbd = NULL,
00518                       ArgList list = NULL, Cardinal argcount=0) :
00519                                      XMMessageBox(n)
00520                                        {
00521                                          id = XmCreateInformationDialog(
00522                                                                   parent.getid(),
00523                                                                   name,
00524                                                                   list,
00525                                                                   argcount);
00526                                          SetText(msg);
00527                                          GetButtons();
00528                                          LabelOkButton("Dismiss");
00529                                          cancelbutton->Disable();
00530                                          helpbutton->Disable();
00531                                          if(cb) 
00532                                            AddOkCallback(cb, cbd);
00533                                          Manage();
00534                                          XtPopup(XtParent(id), XtGrabNone);
00535                                        }
00536                        XMInformationDialog(Widget w) : XMMessageBox(w)
00537                        {
00538                        }
00539                    };
00540 
00541 /*  Message Dialogs: Put up interaction messages: */
00542 
00543 
00544 class XMMessageDialog : public XMMessageBox
00545                    {
00546                    public:
00547                      /*  Constructors: */
00548                      XMMessageDialog(char *n,Widget parent, char *msg,
00549                                    void (*cb)(XMWidget *,
00550                                               XtPointer, XtPointer) = NULL,
00551                                    XtPointer cbd = NULL,
00552                                    ArgList list = NULL, Cardinal argcount=0) :
00553                                      XMMessageBox(n)
00554                                        {
00555                                          id = XmCreateMessageDialog(parent,
00556                                                                   name,
00557                                                                   list,
00558                                                                   argcount);
00559                                          SetText(msg);
00560                                          GetButtons();
00561                                          LabelOkButton("Dismiss");
00562                                          cancelbutton->Disable();
00563                                          helpbutton->Disable();
00564                                          if(cb)
00565                                            AddOkCallback(cb, cbd);
00566                                          Manage();
00567                                          XtPopup(XtParent(id), XtGrabNone);
00568                                        }
00569                      XMMessageDialog(char *n, XMWidget &parent, char *msg,
00570                                    void (*cb)(XMWidget *,
00571                                               XtPointer, XtPointer) = NULL,
00572                                    XtPointer cbd = NULL,
00573                                    ArgList list = NULL, Cardinal argcount=0) :
00574                                      XMMessageBox(n)
00575                                        {
00576                                          id = XmCreateMessageDialog(parent.getid(),
00577                                                                   name,
00578                                                                   list,
00579                                                                   argcount);
00580                                          SetText(msg);
00581                                          GetButtons();
00582                                          LabelOkButton("Dismiss");
00583                                          cancelbutton->Disable();
00584                                          helpbutton->Disable();
00585                                          if(cb) 
00586                                            AddOkCallback(cb, cbd);
00587                                          Manage();
00588                                          XtPopup(XtParent(id), XtGrabNone);
00589                                        }
00590                      XMMessageDialog(Widget w) : XMMessageBox(w)
00591                        {
00592                        }
00593                    };
00594 
00595 /*  Question dialogs ask users questions about things: */
00596 
00597 class XMQuestionDialog : public XMMessageBox
00598                    {
00599                    public:
00600                      /*  Constructors: */
00601                      XMQuestionDialog(char *n,Widget parent, char *msg,
00602                                    void (*cb)(XMWidget *,
00603                                               XtPointer, XtPointer) = NULL,
00604                                    XtPointer cbd = NULL,
00605                                    ArgList list = NULL, Cardinal argcount=0) :
00606                                      XMMessageBox(n)
00607                                        {
00608                                          id = XmCreateQuestionDialog(parent,
00609                                                                   name,
00610                                                                   list,
00611                                                                   argcount);
00612                                          SetText(msg);
00613                                          GetButtons();
00614                                          LabelOkButton("Yes");
00615                                          LabelCancelButton("No");
00616                                          helpbutton->Disable();
00617                                          if(cb)
00618                                            AddOkCallback(cb, cbd);
00619                                          Manage();
00620                                          XtPopup(XtParent(id), XtGrabNone);
00621                                        }
00622                      XMQuestionDialog(char *n, XMWidget &parent, char *msg,
00623                                    void (*cb)(XMWidget *,
00624                                               XtPointer, XtPointer) = NULL,
00625                                    XtPointer cbd = NULL,
00626                                    ArgList list = NULL, Cardinal argcount=0) :
00627                                      XMMessageBox(n)
00628                                        {
00629                                          id = XmCreateQuestionDialog(parent.getid(),
00630                                                                   name,
00631                                                                   list,
00632                                                                   argcount);
00633                                          SetText(msg);
00634                                          GetButtons();
00635                                          LabelOkButton("Yes");
00636                                          LabelCancelButton("No");
00637                                          helpbutton->Disable();
00638                                          if(cb) 
00639                                            AddOkCallback(cb, cbd);
00640                                          Manage();
00641                                          XtPopup(XtParent(id), XtGrabNone);
00642                                        }
00643                      XMQuestionDialog(Widget w) : XMMessageBox(w)
00644                        {
00645                        }
00646                    };
00647 /*
00648 **  XMQuestioner is a self contained version of the XMQuestionDialog
00649 **  It makes available virtual functions for the Ok and Cancel buttons
00650 **  which both just unmanage the dialog.  The user is supposed to derive
00651 **  a class specific to their own application which replaces one or more
00652 **  of the callback methods.
00653 */
00654 
00655 class XMQuestioner : public XMQuestionDialog {
00656   public:
00657      XMQuestioner(char *n, Widget parent, char *msg,
00658                   XtPointer cbd,
00659                   ArgList list = NULL, Cardinal argcount = 0);
00660      XMQuestioner(char *n, XMWidget &parent, char *msg,
00661                   XtPointer cbd,
00662                   ArgList list = NULL, Cardinal argcount = 0);
00663      ~XMQuestioner();
00664   protected:
00665      XMCallback<XMQuestioner> yescallback;
00666      XMCallback<XMQuestioner> nocallback;
00667      virtual void Yescb(XMWidget *wid, XtPointer ud, XtPointer cd);
00668      virtual void Nocb(XMWidget *wid, XtPointer ud, XtPointer cd);
00669   private:
00670 
00671 };
00672 /* Warning dialogs warn the user of some impending disaster */
00673 
00674 
00675 class XMWarningDialog : public XMMessageBox
00676                    {
00677                    public:
00678                      /*  Constructors: */
00679                      XMWarningDialog(char *n,Widget parent, char *msg,
00680                                    void (*cb)(XMWidget *,
00681                                               XtPointer, XtPointer) = NULL,
00682                                    XtPointer cbd = NULL,
00683                                    ArgList list = NULL, Cardinal argcount=0) :
00684                                      XMMessageBox(n)
00685                                        {
00686                                          id = XmCreateWarningDialog(parent,
00687                                                                   name,
00688                                                                   list,
00689                                                                   argcount);
00690                                          SetText(msg);
00691                                          LabelOkButton("Dismiss");
00692                                          cancelbutton->Disable();
00693                                          helpbutton->Disable();
00694                                          GetButtons();
00695                                          if(cb)
00696                                            AddOkCallback(cb, cbd);
00697                                          Manage();
00698                                          XtPopup(XtParent(id), XtGrabNone);
00699                                        }
00700                      XMWarningDialog(char *n, XMWidget &parent, char *msg,
00701                                    void (*cb)(XMWidget *,
00702                                               XtPointer, XtPointer) = NULL,
00703                                    XtPointer cbd = NULL,
00704                                    ArgList list = NULL, Cardinal argcount=0) :
00705                                      XMMessageBox(n)
00706                                        {
00707                                          id = XmCreateWarningDialog(parent.getid(),
00708                                                                   name,
00709                                                                   list,
00710                                                                   argcount);
00711                                          SetText(msg);
00712                                          GetButtons();
00713                                          LabelOkButton("Dismiss");
00714                                          cancelbutton->Disable();
00715                                          helpbutton->Disable();
00716                                          GetButtons();
00717                                          if(cb) 
00718                                            AddOkCallback(cb, cbd);
00719                                          Manage();
00720                                          XtPopup(XtParent(id), XtGrabNone);
00721                                        }
00722                      XMWarningDialog(Widget w) : XMMessageBox(w)
00723                        {
00724                        }
00725                    };
00726 
00727 /*  Working dialogs let the user know something is happening */
00728 
00729 
00730 class XMWorkingDialog : public XMMessageBox
00731                    {
00732                    public:
00733                      /*  Constructors: */
00734                      XMWorkingDialog(char *n,Widget parent, char *msg,
00735                                    void (*cb)(XMWidget *,
00736                                               XtPointer, XtPointer) = NULL,
00737                                    XtPointer cbd = NULL,
00738                                    ArgList list = NULL, Cardinal argcount=0) :
00739                                      XMMessageBox(n)
00740                                        {
00741                                          id = XmCreateWorkingDialog(parent,
00742                                                                   name,
00743                                                                   list,
00744                                                                   argcount);
00745                                          SetText(msg);
00746                                          GetButtons();
00747                                          LabelOkButton("Dismiss");
00748                                          cancelbutton->Disable();
00749                                          helpbutton->Disable();
00750                                          GetButtons();
00751                                          if(cb)
00752                                            AddOkCallback(cb, cbd);
00753                                          Manage();
00754                                          XtPopup(XtParent(id), XtGrabNone);
00755                                        }
00756                      XMWorkingDialog(char *n, XMWidget &parent, char *msg,
00757                                    void (*cb)(XMWidget *,
00758                                               XtPointer, XtPointer) = NULL,
00759                                    XtPointer cbd = NULL,
00760                                    ArgList list = NULL, Cardinal argcount=0) :
00761                                      XMMessageBox(n)
00762                                        {
00763                                          id = XmCreateWorkingDialog(parent.getid(),
00764                                                                   name,
00765                                                                   list,
00766                                                                   argcount);
00767                                          SetText(msg);
00768                                          GetButtons();
00769                                          LabelOkButton("Dismiss");
00770                                          cancelbutton->Disable();
00771                                          helpbutton->Disable();
00772                                          GetButtons();
00773                                          if(cb) 
00774                                            AddOkCallback(cb, cbd);
00775                                          Manage();
00776                                          XtPopup(XtParent(id), XtGrabNone);
00777                                        }
00778                      XMWorkingDialog(Widget w) : XMMessageBox(w)
00779                        {
00780                        }
00781                    };
00782 
00783 /*  In order to prevent a circular include file dependency, helpmenu.h has been
00784 **  textually included here.  At some point another pass through the XM Object system
00785 **  def must be done to eliminate some of these circular dependencies.
00786 */
00787 
00788 /*
00789  ** Structure definitions:
00790  */
00791 
00792 /* XM_help_client_data is a client data structure which is build to
00793  ** drive the XM_display_help callback function.
00794  */
00795 
00796 struct XM_help_client_data { 
00797                                   char                *name; /* Widget name */
00798                                   XMInformationDialog *dialog; /* Widget object */
00799                                   char                **text; /* Help text. */
00800                                 };
00801 
00802 /*
00803  ** The following public items define the help menus which are described in
00804  ** helpmenu.cc:
00805  */
00806 
00807 extern XM_help_client_data XM_About;
00808 extern XM_help_client_data XM_Help_Overview;
00809 /*
00810 ** The following are public entry points to the module:
00811 */
00812 
00813 XMInformationDialog *XM_help(char *name, 
00814                                  XMWidget *parent, char **help_text);
00815 void                 XM_display_help(XMWidget *caller,
00816                                          XtPointer client_data,
00817                                          XtPointer reason = NULL);
00818 
00819 
00820 
00821 /*
00822 **  SelectionBox is the base class for all the selection box dialogs.
00823 **  These include:
00824 **    List selection boxes,
00825 **    File selection dialogs
00826 ** and Prompt dialogs.
00827 **   While command widgets are similar in nature they are different since they
00828 **   don't live in dialog shells.
00829 **/
00830 class XMSelection : public XMMessageBox
00831        {
00832        protected:
00833          XMPushButton *applybutton;
00834          void GetButtons() { /* Get the subwidget buttons: */
00835 
00836            Widget wid;
00837            wid = XmSelectionBoxGetChild(id, XmDIALOG_OK_BUTTON);
00838            okbutton = new XMPushButton(wid);
00839            
00840            wid = XmSelectionBoxGetChild(id, XmDIALOG_CANCEL_BUTTON);
00841            cancelbutton = new XMPushButton(wid);
00842            
00843            wid = XmSelectionBoxGetChild(id, XmDIALOG_HELP_BUTTON);
00844            helpbutton = new  XMPushButton(wid); 
00845            
00846            applybutton  = new XMPushButton(
00847                                    XmSelectionBoxGetChild(id,
00848                                                 XmDIALOG_APPLY_BUTTON));
00849          }
00850        public:
00851          /*
00852          ** Constructors and destructors:
00853          */
00854          XMSelection(char *name) : XMMessageBox(name) {}
00855          XMSelection(Widget w)   : XMMessageBox(w) {
00856            GetButtons();
00857          }
00858          virtual ~XMSelection() {
00859            delete applybutton;
00860          }
00861          /*  Set the width of the text field: */
00862 
00863          void SetTextWidth(Cardinal n) {
00864            SetAttribute(XmNtextColumns, (short)n);
00865          }
00866 
00867          /* Functions to add callbacks to functions:  */
00868 
00869          Callback_data *AddDoCallback(void (*cb)(XMWidget *, /* Do callbacks are  */
00870                                        XtPointer, /* attached to both the ok */
00871                                        XtPointer), /* and the apply button. */
00872                             XtPointer client_data = NULL,
00873                                       Callback_data **apply = NULL) {
00874            Callback_data *apcb;
00875            apcb = AddCallback(XmNapplyCallback, cb, client_data);
00876            if (apply != NULL) *apply = apcb;
00877            return AddCallback(XmNokCallback, cb, client_data);
00878          }
00879          Callback_data *AddApplyCallback(void (*cb)(XMWidget *,
00880                                           XtPointer,
00881                                           XtPointer),
00882                                XtPointer client_data  = NULL) {
00883            return AddCallback(XmNapplyCallback, cb, client_data);
00884          }
00885 
00886          /* Get the button widgets: */
00887 
00888          XMPushButton *GetApplyButton() { return applybutton;}
00889         
00890          /* Labelling functions */
00891 
00892          virtual void SetText(char *txt) {
00893            XmString s = XmStringCreateLtoR(txt, XmSTRING_DEFAULT_CHARSET);
00894            SetAttribute(XmNtextString, s);
00895            XmStringFree(s);
00896          }
00897          virtual void SetLabelString(char *txt) {
00898            XmString s = XmStringCreateLtoR(txt, 
00899                                            XmSTRING_DEFAULT_CHARSET);
00900            SetAttribute(XmNselectionLabelString, s);
00901            XmStringFree(s);
00902          }
00903          /* Label the apply buton: */
00904 
00905          void LabelApplyButton(char *txt) {
00906            XmString str = XmStringCreateLtoR(txt,
00907                                              XmSTRING_DEFAULT_CHARSET);
00908            SetAttribute(XmNapplyLabelString, str);
00909            XmStringFree(str);
00910          }
00911          /* Set default button: */
00912 
00913          void DefaultToOk() {
00914            SetAttribute(XmNdefaultButton,
00915                         okbutton->getid());
00916          }
00917          void DefaultToCancel() {
00918            SetAttribute(XmNdefaultButton,
00919                         cancelbutton->getid());
00920          }
00921          void DefaultToHelp() {
00922            SetAttribute(XmNdefaultButton,
00923                         helpbutton->getid());
00924          }
00925          void DefaultToApply() {
00926            SetAttribute(XmNdefaultButton,
00927                         applybutton->getid());
00928          }
00929        };
00930 /*
00931 ** Prompt dialog - This dialog consists of a single line text widget and
00932 **                 associated label string.  By default the Apply button
00933 **                 is not managed.
00934 **/
00935 
00936 class XMPromptDialog : public XMSelection
00937        {
00938        protected:
00939          void GetButtons() {
00940            Widget w;
00941            w = XmSelectionBoxGetChild(id, XmDIALOG_HELP_BUTTON);
00942            helpbutton = new XMPushButton(w);
00943 
00944            w = XmSelectionBoxGetChild(id, XmDIALOG_CANCEL_BUTTON);
00945            cancelbutton = new XMPushButton(w);
00946 
00947            w = XmSelectionBoxGetChild(id, XmDIALOG_APPLY_BUTTON);
00948            applybutton = new XMPushButton(w);
00949 
00950            w = XmSelectionBoxGetChild(id, XmDIALOG_OK_BUTTON);
00951            okbutton = new XMPushButton(w);
00952          }
00953        public:
00954          XMPromptDialog(char *n, Widget parent, char *prompt = NULL,
00955                         void (*cb)(XMWidget *,
00956                                    XtPointer, XtPointer) = NULL,
00957                         XtPointer cbd = NULL,
00958                         ArgList list = NULL, Cardinal argcount = 0) :
00959                           XMSelection(n) {
00960             id = XmCreatePromptDialog(parent, name,
00961                                       list, argcount);
00962             GetButtons();
00963             if(prompt) SetLabelString(prompt);
00964             helpbutton->Disable();
00965             if(cb) AddDoCallback(cb, cbd);
00966             Manage();
00967             XtPopup(XtParent(id), XtGrabNone);
00968           }
00969          XMPromptDialog(char *n, XMWidget &parent, char *prompt = NULL,
00970                          void (*cb)(XMWidget *,
00971                                     XtPointer, XtPointer) = NULL,
00972                          XtPointer cbd = NULL,
00973                          ArgList list = NULL, Cardinal argcount = 0) :
00974                            XMSelection(n) {
00975                    id = XmCreatePromptDialog(parent.getid(),
00976                                              name, list, argcount);
00977                    GetButtons();
00978                    if(prompt) SetLabelString(prompt);
00979                    if(cb) AddDoCallback(cb, cbd);
00980                    helpbutton->Disable();
00981                    Manage();
00982                    XtPopup(XtParent(id), XtGrabNone);
00983                  }
00984          XMPromptDialog(Widget w) : XMSelection(w) { }
00985 
00986                           
00987        };
00988 /*
00989 ** XMPrompter specializes XMPromptDialog to encapsulate the behavior of
00990 ** the Action area of the dialog as follows:
00991 **    Ok    - Perform virtual function is called and if it returns
00992 **            True then the box is unmanaged.
00993 **    Apply - Perform virtual function is called.
00994 **    Cancel- Box is unmanaged.
00995 **    Help  - Help text is displayed... Either the text last 
00996 **            set via Set Help Text or a default help text which describes
00997 **            in general terms how to use a prompter dialog.
00998 */
00999 class XMPrompter : public XMPromptDialog {
01000  public:
01001   XMPrompter(char *name, Widget parent, char *prompt = NULL,
01002              XtPointer calldata = NULL);
01003   XMPrompter(char *name, XMWidget &parent, char *prompt = NULL,
01004              XtPointer calldata = NULL);
01005   ~XMPrompter();
01006 
01007 
01008   void SetHelpText(char **new_help);
01009   void RevertHelpText();
01010  protected:
01011   XMCallback<XMPrompter> ok;
01012   XMCallback<XMPrompter> apply;
01013   XMCallback<XMPrompter> cancel;
01014   XMCallback<XMPrompter> help;
01015  private:
01016   virtual void OkCallback(XMWidget *wid, XtPointer userd, XtPointer calld);
01017   virtual void ApplyCallback(XMWidget *wid, XtPointer userd, XtPointer calld);
01018   virtual void CancelCallback(XMWidget *wid, XtPointer userd, XtPointer calld);
01019   virtual void HelpCallback(XMWidget *wid, XtPointer userd, XtPointer calld);
01020   virtual Boolean Perform(XMWidget *wid, XtPointer userd, XtPointer calld);
01021 
01022   struct XM_help_client_data help_info;
01023 };
01024 /*
01025 ** A selection dialog has a list of alternatives to choose from.
01026 ** The list can be scrolled around and either picked from with the mouse
01027 ** or typed in to a text widget.
01028 */
01029 class XMSelectionDialog : public XMSelection
01030       {
01031       public:
01032          XMSelectionDialog(char *n, Widget parent, char *prompt = NULL,
01033                         void (*cb)(XMWidget *,
01034                                    XtPointer, XtPointer) = NULL,
01035                         XtPointer cbd = NULL,
01036                         ArgList list = NULL, Cardinal argcount = 0) :
01037                           XMSelection(n) {
01038             id = XmCreateSelectionDialog(parent, name,
01039                                       list, argcount);
01040             GetButtons();
01041             if(prompt) SetLabelString(prompt);
01042             helpbutton->Disable();
01043             if(cb) AddDoCallback(cb, cbd);
01044             Manage();
01045             XtPopup(XtParent(id), XtGrabNone);
01046           }
01047          XMSelectionDialog(char *n, XMWidget &parent, char *prompt = NULL,
01048                          void (*cb)(XMWidget *,
01049                                     XtPointer, XtPointer) = NULL,
01050                          XtPointer cbd = NULL,
01051                          ArgList list = NULL, Cardinal argcount = 0) :
01052                            XMSelection(n) {
01053                    id = XmCreateSelectionDialog(parent.getid(),
01054                                              name, list, argcount);
01055                    GetButtons();
01056                    if(prompt) SetLabelString(prompt);
01057                    if(cb) AddDoCallback(cb, cbd);
01058                    helpbutton->Disable();
01059                    Manage();
01060                    XtPopup(XtParent(id), XtGrabNone);
01061                  }
01062          XMSelectionDialog(Widget w) : XMSelection(w) { }
01063 
01064          /*
01065          ** Selection boxes also need a method to set the list... it can be
01066          ** set in the argument list, but the following is more convenient
01067          */
01068 
01069          void SetSelectionList(Cardinal list_count, char **selections);
01070          void SetVisibleItemCount(Cardinal num_visible) {
01071            SetAttribute(XmNvisibleItemCount, num_visible);
01072          }
01073 
01074          /*
01075          ** Selection boxes are allowed to restrict choices to items on the
01076          ** list.  This gives them an additional callback (XmNnoMatchCallback).
01077          */
01078 
01079          void RestrictChoices() {
01080            SetAttribute(XmNmustMatch, True);
01081          }
01082          void NoRestrictChoices() {
01083            SetAttribute(XmNmustMatch, (XtArgVal)False);
01084          }
01085          Callback_data *AddNoMatchCallback(void (*cb)(XMWidget *,
01086                                             XtPointer, XtPointer),
01087                                  XtPointer client_data = NULL) {
01088            return AddCallback(XmNnoMatchCallback, cb, client_data);
01089          }
01090            
01091        };
01092 
01093 /*
01094 ** XMSelector:  This class is a self contained version of XMSelectionDialog
01095 **              Self contained means that the class contains methods to
01096 **              respond to the callbacks as well as some additional
01097 **              virtual functions intended to be superceded when the
01098 **              user actually makes use of this class.  The class is not
01099 **              intended to be typically used, Usually, the client will
01100 **              specialize the class, supplying overrides for one or more
01101 **              of the methods:
01102 **                   SetUpList     - Defines the set of items in the list.
01103 **                   Perform       - Application sensitive processing of
01104 **                                   the Ok or Apply buttons.
01105 **                   Constructors/Destructors.
01106 */
01107 class XMSelector : public XMSelectionDialog
01108 {
01109   public:
01110      XMSelector(char *n, Widget parent, char *prompt = NULL,
01111                 XtPointer cbd = NULL,
01112                 ArgList list = NULL, Cardinal argcount = 0);
01113      XMSelector(char *n, XMWidget &parent, char *prompt = NULL,
01114                 XtPointer cbd = NULL,
01115                 ArgList list = NULL, Cardinal argcount = 0);
01116      ~XMSelector();
01117 
01118      virtual void SetupList();          /* Set up the selectionlist. */
01119      void         SetHelpText(char **text);
01120      void         RevertHelpText();
01121    protected:
01122      virtual Boolean Perform(XMWidget *wid, XtPointer cd,
01123                           int reason, XmString value, int size);
01124      virtual void OkCb(XMWidget *wid, XtPointer cd, XtPointer ud);
01125      virtual void NoMatchCb(XMWidget *wid, XtPointer cd, XtPointer ud);
01126      virtual void ApplyCb(XMWidget *wid, XtPointer cd, XtPointer ud);
01127      virtual void CancelCb(XMWidget *wid, XtPointer cd, XtPointer ud);
01128      virtual void HelpCb(XMWidget *wid, XtPointer cd, XtPointer ud);
01129   private:
01130      XMCallback<XMSelector> okbuttonCB;
01131      XMCallback<XMSelector> applybuttonCB;
01132      XMCallback<XMSelector> cancelbuttonCB;
01133      XMCallback<XMSelector> helpbuttonCB;
01134      XMCallback<XMSelector> nomatchCB;
01135 
01136      struct XM_help_client_data helpinfo;
01137  
01138 };
01139 /*
01140 ** A file selection dialog is a pair of list boxes.  One selects/displays
01141 ** the directories.  Another displays the list of files present in that 
01142 ** directory.  There are two text entry areas.  The top one allows the user
01143 ** to set a file directory/search mask.  The bottom one allows the user to
01144 ** enter filenames directly.  The following buttons are available by default:
01145 **  Ok, Apply, Cancel.  Help is present but default ghosted.
01146 */
01147 class XMFileListDialog : public XMSelection
01148        {
01149        protected:
01150          void GetButtons() {
01151            helpbutton = new 
01152              XMPushButton(XmFileSelectionBoxGetChild(id,
01153                                                      XmDIALOG_HELP_BUTTON));
01154            cancelbutton = new
01155              XMPushButton(XmFileSelectionBoxGetChild(id,
01156                                                      XmDIALOG_CANCEL_BUTTON));
01157            okbutton = new
01158              XMPushButton(XmFileSelectionBoxGetChild(id,
01159                                                      XmDIALOG_OK_BUTTON));
01160            applybutton = new
01161              XMPushButton(XmFileSelectionBoxGetChild(id,
01162                                                      XmDIALOG_APPLY_BUTTON));
01163          }
01164                                                                     
01165        public:
01166          XMFileListDialog(char *n, Widget parent, char 
01167                           *directory = XMFILE_DEFAULT_DIRMASK,
01168                         void (*cb)(XMWidget *,
01169                                    XtPointer, XtPointer) = NULL,
01170                         XtPointer cbd = NULL,
01171                         ArgList list = NULL, Cardinal argcount = 0) :
01172                           XMSelection(n) {
01173             id = XmCreateFileSelectionDialog(parent, name,
01174                                       list, argcount);
01175             GetButtons();
01176             helpbutton->Disable();
01177             SetLabelString("Filename: ");
01178             if(cb) AddDoCallback(cb, cbd);
01179 
01180             /* Set the search path directory: */
01181 
01182             DoSearch(directory);
01183             Manage();
01184             XtPopup(XtParent(id), XtGrabNone);
01185           }
01186          XMFileListDialog(char *n, XMWidget &parent, 
01187                           char *directory = XMFILE_DEFAULT_DIRMASK,
01188                          void (*cb)(XMWidget *,
01189                                     XtPointer, XtPointer) = NULL,
01190                          XtPointer cbd = NULL,
01191                          ArgList list = NULL, Cardinal argcount = 0) :
01192                            XMSelection(n) {
01193                    id = XmCreateFileSelectionDialog(parent.getid(),
01194                                                     name, list, argcount);
01195                    GetButtons();
01196                    DoSearch(directory);
01197                    if(cb) AddDoCallback(cb, cbd);
01198                    helpbutton->Disable();
01199                    SetLabelString("Filename: ");
01200                    Manage();
01201                    XtPopup(XtParent(id), XtGrabNone);
01202                  }
01203          XMFileListDialog(Widget w) : XMSelection(w) { }
01204 
01205          /* Methods which manipulate the search strings: */
01206          void DoSearch(XmString dir) {
01207            XmFileSelectionDoSearch(id, dir);
01208          }
01209          void DoSearch(char *dir) {
01210            XmString d;
01211            d = XmStringCreateLtoR(dir, XmSTRING_DEFAULT_CHARSET);
01212            XmFileSelectionDoSearch(id, d);
01213            XmStringFree(d);
01214          }
01215          void DoSearch() {      /* Do search on current mask. */
01216            XmString dirmask;    /* Will hold the directory search mask. */
01217            GetAttribute(XmNdirMask, &dirmask);
01218 
01219            XmFileSelectionDoSearch(id, dirmask);
01220            XmStringFree(dirmask); /* Get rid of dirmask. */
01221          }
01222 
01223          char *GetDirectory();
01224          char *GetFileMask();
01225          char *GetFullSearchString();
01226 
01227          /* Methods to manipulate the labels: */
01228 
01229          virtual void SetLabelString(char *txt) {
01230            XmString s = XmStringCreateLtoR(txt, XmSTRING_DEFAULT_CHARSET);
01231            XtVaSetValues(XmFileSelectionBoxGetChild(id, 
01232                                                     XmDIALOG_SELECTION_LABEL),
01233                          XmNlabelString, s,
01234                          NULL);
01235            XmStringFree(s);
01236          }
01237          virtual void SetFilterString(char *txt) {
01238            XmString s = XmStringCreateLtoR(txt, XmSTRING_DEFAULT_CHARSET);
01239            SetAttribute(XmNfilterLabelString, s);
01240            XmStringFree(s);
01241          }
01242          /* Set restrictions on the file types searched: */
01243 
01244          void SetFileTypes(unsigned char fileset) {
01245            SetAttribute(XmNfileTypeMask, fileset);
01246          }
01247          void RestrictChoices() {
01248            SetAttribute(XmNmustMatch, True);
01249          }
01250          void NoRestrictChoices() {
01251            SetAttribute(XmNmustMatch, (XtArgVal)False);
01252          }
01253 
01254          /* Add callbacks if no match on filename selected */
01255 
01256          Callback_data *AddNoMatchCallback(void (*cb)(XMWidget *,
01257                                             XtPointer, XtPointer),
01258                                  XtPointer client_data = NULL) {
01259            return AddCallback(XmNnoMatchCallback, cb, client_data);
01260          }
01261          
01262        };
01263 /*
01264 **  The XMFileSelector Dialog is a self contained version of the 
01265 **  XMFileListDialog.  Self contained, in this case means that the
01266 **  callback functions are redirected to method functions and that
01267 **  the method functions are virtualized to allow descendent application
01268 **  specific instances of these classes to be constructed.
01269 **  The strategy used for virtualizing is similar to that taken by
01270 **  the XMSelector class.  Individual callbacks can be overridden by the
01271 **  user to supply ok, filter, cancel and help callbacks, however,
01272 **  the Ok callback calls the Perform function with the filename string
01273 **  as an argument and in most cases that's all that the client will need
01274 **  to override (as well as supplying constructors and desctructors.
01275 */
01276 class XMFileSelector : public XMFileListDialog
01277 {
01278   public:
01279     XMFileSelector(char *n, Widget parent, 
01280                    XtPointer calld = NULL,
01281                    char *directory = XMFILE_DEFAULT_DIRMASK);
01282 
01283     XMFileSelector(char *n, XMWidget &parent, 
01284                    XtPointer ud = NULL,
01285                    char *directory = XMFILE_DEFAULT_DIRMASK);
01286 
01287 
01288     ~XMFileSelector();
01289                    
01290     void SetHelpText(char **text);
01291     void RevertHelpText();
01292   protected:
01293     virtual Boolean Perform(XMWidget *wid, XtPointer ud,
01294                             char *filename,
01295                             int reason);
01296     virtual void OkCb(XMWidget *wid, XtPointer ud, XtPointer cd);
01297     virtual void NomatchCb(XMWidget *wid, XtPointer ud, XtPointer cd);
01298     virtual void FilterCb(XMWidget *wid, XtPointer ud, XtPointer cd);
01299     virtual void CancelCb(XMWidget *wid, XtPointer ud, XtPointer cd);
01300     virtual void HelpCb(XMWidget *wid, XtPointer ud, XtPointer cd);
01301                          
01302 
01303   private:
01304     XMCallback<XMFileSelector> okcb;
01305     XMCallback<XMFileSelector> nomatchcb;
01306     XMCallback<XMFileSelector> filtercb;
01307     XMCallback<XMFileSelector> cancelcb;
01308     XMCallback<XMFileSelector> helpcb;
01309 
01310     struct XM_help_client_data helpinfo;
01311 };
01312 
01313 /*
01314 ** The  XMCustomDialog class is a useful subclass for building basic
01315 ** Customized dialogs.  It is implemented as follows:
01316 **    A dialog shell is created which contains a paned window as a manger
01317 **    child.  The paned window manages two widgets.  A form called
01318 **    work_area which is where the user should lay out the work area of
01319 **    the form and a row_column widget called action_area which contains
01320 **    the action area buttons.
01321 ** The idea is that clients will specialize constructors and other methods
01322 ** to build up, maintain and process the work_area subwidgets.
01323 ** Action area buttons are:
01324 **     OK  - when pressed, the Do call back is initiated.
01325 ** Accept  -  When pressed, the Do callback is initiated.
01326 ** Cancel  -  When pressed, the Cancel callback is initiated.
01327 ** Help    - When pressed, the Help callback is initiated.
01328 */
01329 
01330 class XMCustomDialog : public XMWidget /* Create unmanaged for greater layout ctl. */
01331 {
01332  protected:
01333   XMForm        *shell_child;   /* Form present to allow modalization */
01334   XMPanedWindow *top_manager;   /* Top level manager widget. */
01335   XMRowColumn   *action_area;   /* The action area widget. */
01336   XMForm        *work_area;     /* The form which manages the work area */
01337   XMPushButton  *Ok;            /* Buttons in the action area. */
01338   XMPushButton  *Apply;
01339   XMPushButton  *Cancel;
01340   XMPushButton  *Help;
01341   void CreateDialog(char *name, Widget parent, char *title,
01342                     ArgList l, Cardinal num_args);
01343  public:
01344   /* Constructors: */
01345 
01346   XMCustomDialog(char *name, XMWidget &parent, char *title,
01347                  ArgList l = NULL, Cardinal num_args = 0) : 
01348                    XMWidget(name) { 
01349                      CreateDialog(name, parent.getid(), title, 
01350                                   l, num_args);
01351                    }
01352   XMCustomDialog(char *name, Widget parent, char *title,
01353                  ArgList l = NULL, Cardinal num_args = 0) :
01354                    XMWidget(name) {
01355                      CreateDialog(name, parent, title, l, num_args); }
01356 
01357   /* Destructors:  */
01358 
01359   ~XMCustomDialog() {
01360     delete Ok;
01361     delete Apply;
01362     delete Cancel;
01363     delete Help;
01364     delete action_area;
01365     delete work_area;
01366     delete top_manager;
01367     delete shell_child;
01368   }
01369 
01370   /* Operation on the skeleton dialog */
01371 
01372   void Manage();
01373   void UnManage();
01374 
01375   XMPanedWindow *TopManager() { return top_manager; }
01376   XMRowColumn   *ActionArea() { return action_area; }
01377   XMForm        *WorkArea()   { return work_area;   }
01378   XMPushButton  *ok()          { return Ok;          }
01379   XMPushButton  *apply()       { return Apply;       }
01380   XMPushButton  *cancel()      { return Cancel;      }
01381   XMPushButton  *help()        { return Help;        }
01382 
01383   Callback_data *AddDoCallback(void (*callback)(XMWidget *, XtPointer, XtPointer),
01384                      XtPointer user_data = NULL,
01385                      Callback_data **okcb = NULL) 
01386     { 
01387       Callback_data *okc;
01388       okc = Ok->AddCallback(callback, user_data);
01389       if(okcb != NULL) *okcb = okc;
01390       return Apply->AddCallback(callback, user_data);
01391     }
01392   Callback_data *AddOkCallback(void (*callback)(XMWidget *, XtPointer, XtPointer),
01393                      XtPointer user_data = NULL)
01394     { return Ok->AddCallback(callback, user_data); }
01395   Callback_data *AddApplyCallback(void (*callback)(XMWidget *, XtPointer, XtPointer),
01396                         XtPointer user_data = NULL)
01397     { return Apply->AddCallback(callback, user_data); }
01398   Callback_data *AddCancelCallback(void (*callback)(XMWidget *, XtPointer, XtPointer),
01399                      XtPointer user_data = NULL)
01400     { return Cancel->AddCallback(callback, user_data); }
01401   Callback_data *AddHelpCallback(void (*callback)(XMWidget *, XtPointer, XtPointer),
01402                      XtPointer user_data = NULL)
01403     { return Help->AddCallback(callback, user_data); }
01404 
01405   void SetModal(unsigned char modality)
01406     { shell_child->SetAttribute(XmNdialogStyle, modality); }
01407 
01408 };
01409 /*
01410 ** Base class for a custom dialog box.
01411 */
01412 class XMCustomDialogBox : public XMCustomDialog
01413 {
01414  public:
01415   XMCustomDialogBox(char *name, XMWidget &parent, char *title,
01416                     ArgList l= NULL, Cardinal num_args=0);
01417   XMCustomDialogBox(char *name, Widget parent, char *title,
01418                     ArgList l=NULL, Cardinal num_args=0);
01419   ~XMCustomDialogBox();
01420 
01421 
01422   void SetHelpText(char **help_text);
01423   void RevertHelpText();
01424 
01425  protected:
01426   XMCallback<XMCustomDialogBox>   OkCb;
01427   XMCallback<XMCustomDialogBox>   ApplyCb;
01428   XMCallback<XMCustomDialogBox>   CancelCb;
01429   XMCallback<XMCustomDialogBox>   HelpCb;
01430 
01431   virtual Boolean Perform(XMWidget *wid, XtPointer cli, XtPointer call);
01432   virtual void OkPressed(XMWidget *wid, XtPointer cli, XtPointer call);
01433   virtual void ApplyPressed(XMWidget *wid, XtPointer cli, XtPointer call);
01434   virtual void CancelPressed(XMWidget *wid, XtPointer cli, XtPointer call);
01435   virtual void HelpPressed(XMWidget *wid, XtPointer cli, XtPointer call);
01436   
01437  private:
01438   void InitializeHelp();
01439   void SetCallbacks();          /* Used by all constructors. */
01440   XM_help_client_data help_info;
01441 
01442 };
01443 #endif

Generated on Thu Jan 6 16:58:42 2005 for Spectrodaq External Event Framework by  doxygen 1.3.9.1