Back to index

tetex-bin  3.0
help-window.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 the xdvik development team
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00017  * PAUL VOJTA OR ANY OTHER AUTHOR OF THIS SOFTWARE BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  */
00023 
00024 /*
00025  * Help window for xdvik, using the `topics' window framework.
00026  */
00027 
00028 #include "xdvi-config.h"
00029 #include "xdvi.h"
00030 #include "version.h"
00031 
00032 #include <X11/Xatom.h>
00033 #include <X11/Intrinsic.h>
00034 #include <X11/StringDefs.h>
00035 
00036 #if MOTIF
00037 # include <Xm/Xm.h>
00038 # include <Xm/Form.h>
00039 # include <Xm/Frame.h>
00040 # include <Xm/Text.h>
00041 # include <Xm/Protocols.h>
00042 #else /* MOTIF */
00043 # include <X11/Xaw/Paned.h>
00044 # include <X11/Xaw/Form.h>
00045 # include <X11/Xaw/AsciiText.h>
00046 #endif /* MOTIF */
00047 
00048 #include <sys/stat.h>
00049 #include <stdio.h>
00050 #include <unistd.h>
00051 
00052 #include "message-window.h"
00053 #include "util.h"
00054 #include "x_util.h"
00055 #include "string-utils.h"
00056 #include "topic-window.h"
00057 #include "help-window.h"
00058 
00059 /* missing features that will be listed in the help window */
00060 #if !XDVI_XT_TIMER_HACK
00061 #define HAVE_MISSING_FEATURES 1
00062 #endif
00063 
00064 #if !HAVE_REGEX_H
00065 #define HAVE_MISSING_FEATURES 1
00066 #endif
00067 
00068 /*
00069  * The number of help topics - must larger or equal to actual number of items,
00070  * also keep in sync with elements resource.help_* !!!
00071  */
00072 #define NUM_HELP_TOPICS 16
00073 
00074 /*
00075  * helper routines
00076  */
00077 
00078 static Widget
00079 create_help_text(Widget parent, const char *name, const char *value)
00080 {
00081     Widget text;
00082 #if MOTIF
00083     Arg args[20];
00084     int n = 0;
00085 
00086     XtSetArg(args[n], XmNeditable, False);                     n++;
00087     XtSetArg(args[n], XmNcursorPositionVisible, False);        n++;
00088     XtSetArg(args[n], XmNvalue, value);                        n++;
00089     XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT);         n++;
00090     XtSetArg(args[n], XmNwordWrap, True);               n++;
00091     XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM);        n++;
00092 /*     XtSetArg(args[n], XmNtopWidget, top_widget);            n++; */
00093 /*     XtSetArg(args[n], XmNtopOffset, 10);                    n++; */
00094     XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM);       n++;
00095     XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM);      n++;
00096     XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM);     n++;
00097     XtSetArg(args[n], XmNscrollingPolicy, XmAUTOMATIC);        n++;
00098     XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
00099     
00100     text = XmCreateScrolledText(parent, (char *)name, args, n);
00101 
00102     XtManageChild(text);
00103 #else /* MOTIF */
00104     text = XtVaCreateManagedWidget(name, asciiTextWidgetClass, parent,
00105                                /*                          XtNfromVert, top_widget, */
00106                                /*                          XtNvertDistance, 10, */
00107                                XtNstring, value,
00108                                XtNheight, 400,
00109                                XtNwidth, 500,
00110                                /* resizing of pane by user isn't needed */
00111                                XtNshowGrip, False,
00112                                XtNscrollVertical, XawtextScrollAlways,
00113                                XtNscrollHorizontal, XawtextScrollNever,
00114                                XtNeditType, XawtextRead,
00115                                XtNleftMargin, 5,
00116                                NULL);
00117     XawTextDisplayCaret(text, False);
00118 #endif /* MOTIF */
00119     return text;
00120 }
00121 
00122 
00123 static void
00124 get_title_and_summary(const char *str, int len, char **title, char **summary)
00125 {
00126     char *tmp = xmalloc(len + 1);
00127     char *ptr;
00128 
00129     memcpy(tmp, str, len);
00130     tmp[len] = '\0';
00131 
00132     if ((ptr = strchr(tmp, '\t')) == NULL) {
00133        XDVI_WARNING((stderr, "Help resource label `%s' doesn't contain a tab character - ignoring it.", tmp));
00134        *title = tmp;
00135        *summary = NULL;
00136     }
00137     else {
00138        *ptr++ = '\0';
00139        *title = tmp;
00140        *summary = ptr;
00141     }
00142     
00143     TRACE_GUI((stderr, "Title, Summary: |%s|%s|", *title, *summary));
00144 }
00145 
00146 static void
00147 init_item(const char *resource, const char **resource_default,
00148          struct topic_info *info, size_t idx, Dimension *width)
00149 {
00150     const char *ptr = NULL;
00151     char *widget_text = NULL;
00152     Widget help_form;
00153     Widget text;
00154     struct topic_item *item = &(info->items[idx]);
00155     char *translation_str = get_string_va("#override \n"
00156                                      "<Key>q:close-topic-window(%p)\n"
00157 #ifdef MOTIF
00158                                      "<Key>osfCancel:close-topic-window(%p)\n"
00159 #else
00160                                      "<Key>Escape:close-topic-window(%p)\n"
00161 #endif
00162                                      "<Key>Return:close-topic-window(%p)",
00163                                      info, info, info);
00164     
00165     if (resource != NULL) {
00166        if ((ptr = strchr(resource, '\n')) == NULL) {
00167            XDVI_WARNING((stderr, "Help resource text `%s' doesn't contain a newline character.", resource));
00168            ptr = resource;
00169        }
00170        else
00171            ptr++;
00172        get_title_and_summary(resource, ptr - resource - 1,
00173                            &(item->topic), &(item->title));
00174     }
00175     else { /* resource not set; copy resource_default into malloc()ed widget_text: */
00176        size_t size = 0, alloc_len = 0, offset;
00177        const size_t alloc_step = 1024;
00178        int i;
00179 
00180        for (i = 0; resource_default[i] != NULL; i++) {
00181            if (i == 0) { /* special case */
00182               get_title_and_summary(resource_default[i], strlen(resource_default[i]) - 1,
00183                                   &(item->topic), &(item->title));
00184            }
00185            else {
00186               offset = size;
00187               size += strlen(resource_default[i]);
00188               /*
00189                * allocate chunks of `alloc_step' to avoid frequent calls to malloc.
00190                * `alloc_len' is always 1 more than `size', for the terminating NULL character.
00191                */
00192               while (size + 1 > alloc_len) {
00193                   alloc_len += alloc_step;
00194                   widget_text = xrealloc(widget_text, alloc_len);
00195               }
00196               memcpy(widget_text + offset, resource_default[i], size - offset);
00197            }
00198        }
00199        /* null-terminate string */
00200        widget_text[size] = '\0';
00201     }
00202 
00203     help_form =  XtVaCreateManagedWidget("help_form",
00204 #if MOTIF
00205                                     xmFormWidgetClass, info->right_form,
00206                                     XmNtopAttachment, XmATTACH_FORM,
00207                                     XmNleftAttachment, XmATTACH_FORM,
00208                                     XmNrightAttachment, XmATTACH_FORM,
00209                                     XmNbottomAttachment, XmATTACH_FORM,
00210 #else
00211                                     formWidgetClass, info->right_form,
00212                                     XtNborderWidth, 0,
00213                                     XtNdefaultDistance, 0,
00214 #endif
00215                                     NULL);
00216     item->widget = help_form;
00217     if (ptr != NULL) {
00218        text = create_help_text(help_form, "help_text", ptr);
00219     }
00220     else {
00221        text = create_help_text(help_form, "help_text", widget_text);
00222        free(widget_text);
00223     }
00224     XtOverrideTranslations(text, XtParseTranslationTable(translation_str));
00225     free(translation_str);
00226 #if !MOTIF
00227     {
00228        Dimension w;
00229        XtVaGetValues(text, XtNwidth, &w, NULL);
00230        if (w > *width)
00231            *width = w;
00232     }
00233 #else
00234     UNUSED(width);
00235 #endif
00236 }
00237 
00238 static void
00239 initialize_items(struct topic_info *info)
00240 {
00241     size_t k;
00242     Dimension width;
00243     
00244     /*
00245      * Define fallbacks: default_xyz is used as fallback text if
00246      * X resource xyz isn't specified.
00247      *
00248      * We use arrays of strings rather than simple strings because of C's
00249      * limitations on maximum string length; but since the resource needs to
00250      * be a simple `char *', these have to be copied into larger buffers
00251      * later on (which is a bit wasteful to space). OTOH, splitting the
00252      * strings into smaller pieces would make them hard to deal with as
00253      * X resources. They are defined as static so that they are initialized
00254      * only once.
00255      *
00256      * Last elem of each array is NULL for ease of looping through it.
00257      *
00258      * Advantages of this method vs. putting the help texts into a file:
00259      * - couldn't use #ifdef's as easily
00260      * - would need to invent our own file format
00261      * - file searching is more error-prone (needs to be installed etc.)
00262      */
00263 
00264     static const char *default_help_general[] = {
00265        "Introduction\tAbout this version of xdvi\n",
00266        "This is xdvik, version ",
00267        XDVI_TERSE_VERSION_INFO
00268        ".\nThe program's homepage is located at:\n",
00269        "http://sourceforge.net/projects/xdvi\n",
00270        "where you can find updates, report bugs and submit feature requests.\n",
00271        "\n",
00272        "\n",
00273        "Xdvi has many command-line options, too numerous to be listed here;\n",
00274        "see the man page for a full description.\n",
00275        "\n",
00276        "The most important key bindings are listed in the help sections shown\n",
00277        "in the left window.\n",
00278        "\n",
00279        "Note: Unless a key binding also has an uppercase version,\n",
00280        "all bindings are case-insensitive.\n\n",
00281        "\n",
00282        "The major parts of Xdvik are licensed under the X Consortium license.\n",
00283        "Parts (encoding.c) are licensed under the GNU General Public License.\n",
00284        "Xdvik uses the following libraries:\n",
00285        "- The kpathsea library, licensed in part under the GNU General Public\n",
00286        "  License, in part under the GNU Library General Public License.\n",
00287        "- t1lib, licensed in parts under the GNU Library General Public License,\n",
00288        "  in parts under the X Consortium license.\n",
00289        "There is NO WARRANTY of anything.\n",
00290        "\n",    
00291        "Built on ",
00292        __DATE__,
00293        " using these configure options:\n",
00294 #if MOTIF
00295        "- Motif toolkit (",
00296        XmVERSION_STRING,
00297        ")\n",
00298 #else
00299        "- Athena toolkit\n",
00300 #endif
00301 #ifdef A4
00302        "- paper: a4, units cm\n",
00303 #else
00304        "- paper: letter, units inches\n",
00305 #endif
00306 #ifdef GREY
00307        "- anti-aliasing (grey) enabled\n",
00308 #endif
00309 #ifdef T1LIB
00310        "- T1lib (direct rendering of PS fonts) enabled\n",
00311 #endif
00312 #if HAVE_ICONV_H
00313        "- Iconv support compiled in\n",
00314 #if USE_LANGINFO
00315        "- Langinfo support compiled in\n",
00316 #else
00317        "- Langinfo support not compiled in\n",
00318 #endif
00319 #else
00320        "- Iconv/langinfo support not compiled in\n",
00321 #endif
00322 #ifdef TEXXET
00323        "- left-to-right typesetting (TeXXeT) support enabled\n",
00324 #endif
00325 #ifdef USE_GF
00326        "- gf file support enabled\n",
00327 #endif
00328 #if HAVE_MISSING_FEATURES
00329        "\n",
00330        "Features not available on this platform:\n",
00331 #if !XDVI_XT_TIMER_HACK
00332        "- Could not redefine XtAppAddTimeOut(); some widgets may\n",
00333        "  not be updated until the mouse is moved.\n",
00334 #endif
00335 #if !HAVE_REGEX_H
00336        "- regex.h header not available, regular expression support\n",
00337        "  in string search is disabled.\n",
00338 #endif
00339 #endif /* HAVE_MISSING_FEATURES */
00340        NULL
00341     };
00342 
00343     static const char *default_help_hypertex[] = {
00344        "Hyperlinks\tNavigating links\n",
00345        "Whenever the mouse is positioned on a link, the cursor changes\n",
00346        "to a `hand' shape and the target of the link is displayed\n",
00347        "in the statusline at the bottom of the window.\n",
00348        "\n",
00349        "The following keybindings are pre-configured:\n",
00350        "\n",
00351         "Mouse-1\n",
00352        "      Follow the link at the cursor position.\n",
00353        "      If the link target is not a DVI file, try to launch\n",
00354        "      an application to view the file.\n",
00355         "Mouse-2\n",
00356        "      Open a new xdvi window displaying the link\n",
00357         "     at the cursor position if the link is a DVI file;\n",
00358        "      else, try to launch an application to view the file.\n",
00359         "B",
00360 #if MOTIF
00361        ", toolbar button 9\n",
00362 #else
00363        "\n",
00364 #endif 
00365         "     Go back to the previous hyperlink in the history.\n",
00366         "F",
00367 #if MOTIF
00368        ", toolbar button 10\n",
00369 #else
00370        "\n",
00371 #endif 
00372        "      Go forward to the next hyperlink in the history.\n",
00373        "\n",
00374        "By default, the hyperlinks are displayed in the colors \n",
00375        "`linkColor' and `visitedLinkColor' (for visited links) and \n",
00376        "underlined in the same colors. This can be customized \n",
00377        "by setting the resource or command-line option `linkstyle' \n",
00378        "to a value between 0 and 3, which have the following meaning:\n",
00379        "    0: no highlighting of links,\n",
00380        "    1: underline links,\n",
00381        "    2: color links,\n",
00382        "    3: color and underline links.\n\n",
00383        NULL
00384     };
00385 
00386     static const char *default_help_othercommands[] = {
00387        "Other Commands\tMiscellaneous other commands\n",
00388        "Ctrl-f\n",
00389        "     Opens a dialog window to search for a text string\n",
00390        "     in the DVI file.\n",
00391        "\n",
00392        "Ctrl-g\n",
00393        "     Search for the next string match.\n",
00394        "\n",
00395        "Ctrl-l\n",
00396        "     Toggles fullscreen mode (which may not work with your\n",
00397        "     window manager/desktop).\n",
00398        "\n",
00399        "Ctrl-o",
00400 #if MOTIF
00401        ", toolbar button 1\n",
00402 #else
00403        "\n",
00404 #endif 
00405        "     Opens a popup window to select another DVI file.\n",
00406        "     With a prefix argument `n', the `n'th file from the file history\n",
00407        "     is opened instead.\n",
00408        "\n",
00409        "Ctrl-p",
00410 #if MOTIF
00411        ", toolbar button 11\n",
00412 #else
00413        "\n",
00414 #endif 
00415        "     Opens a popup window for printing the DVI file, or parts of it.\n",
00416        "\n",
00417        "Ctrl-r or Clear\n",
00418        "     Redisplays the current page.\n",
00419        "\n",
00420        "Ctrl-s\n",
00421        "     Opens a popup window for saving the DVI file, or parts of it.\n",
00422        "\n",
00423        "G\n",
00424        "     Toggles the use of greyscale anti-aliasing for\n",
00425        "     displaying shrunken bitmaps.  In addition, the key\n",
00426        "     sequences `0G' and `1G' clear and set this flag,\n",
00427        "     respectively.  See also the -nogrey option.\n",
00428        "\n",
00429        "k\n",
00430        "     Normally when xdvi switches pages, it moves to the home\n",
00431        "     position as well.  The `k' keystroke toggles a `keep-\n",
00432        "     position' flag which, when set, will keep the same\n",
00433        "     position when moving between pages.  Also `0k' and `1k'\n",
00434        "     clear and set this flag, respectively.  See also the\n",
00435        "     -keep option.\n",
00436        "\n",
00437        "M\n",
00438        "     Sets the margins so that the point currently under the\n",
00439        "     cursor is the upper left-hand corner of the text in the\n",
00440        "     page.  Note that this command itself does not move the\n",
00441        "     image at all.  For details on how the margins are used,\n",
00442        "     see the -margins option.\n",
00443        "\n",
00444        "P\n",
00445        "     ``This is page number n.''  This can be used to make\n",
00446        "     the `g' keystroke refer to a different page number.\n",
00447        "     (See also `Options->Use TeX Page Numbers' and the\n",
00448        "     `T' keystroke).\n",
00449        "\n",
00450        "R",
00451 #if MOTIF
00452        ", toolbar button 2\n",
00453 #else
00454        "\n",
00455 #endif
00456        "     Forces the DVI file to be reread.\n",
00457        "\n",
00458        "s\n",
00459        "     Changes the shrink factor to the given number.\n",
00460        "     If no number is given, the smallest factor that makes the\n",
00461        "     entire page fit in the window will be used.  (Margins\n",
00462        "     are ignored in this computation.)\n",
00463        "\n",
00464        "S\n",
00465        "     Sets the density factor to be used when shrinking\n",
00466        "     bitmaps.  This should be a number between 0 and 100;\n",
00467        "     higher numbers produce lighter characters.\n",
00468        "\n",
00469        "t\n",
00470        "     Switches to the next unit in a sorted list of TeX dimension\n",
00471        "     units for the popup magnifier ruler and `Ruler mode' (see the\n",
00472        "     section `Modes').\n"  
00473        "\n",
00474        "V\n",
00475        "     Toggles Ghostscript anti-aliasing.  Also `0V' and `1V' clear\n",
00476        "     and enables this mode, respectively.  See also the the\n",
00477        "     -gsalpha option.\n",
00478        "\n",
00479        "\n",
00480        "v\n",
00481        "     Toggles between several modes of displaying postscript specials:\n",
00482        "     Display specials, display specials with their bounding box\n",
00483        "     (if available), and display bounding boxes only (if available).\n",
00484        "     The prefix arguments 1, 2 and 0 also allow you to select one of\n"
00485        "     these states directly.\n",
00486        "\n",
00487        "x\n",
00488        "     Toggles expert mode (in which ",
00489 #if MOTIF
00490        "the menu bar, the toolbar\n",
00491 #else
00492        "the menu buttons,\n",
00493 #endif
00494        "     the page list and the statusline do not appear).\n",
00495        "     `1x' toggles the display of the statusline at the bottom of the window.\n",
00496        "     `2x' toggles the scrollbars,\n",
00497 #if MOTIF
00498        "     `3x' toggles the page list,\n",
00499        "     `4x' toggles the toolbar,\n",
00500        "     `5x' toggles the menu bar.\n",
00501 #else
00502        "     `3x' toggles the page list and menu buttons.\n",
00503 #endif
00504        "\n",
00505        "Ctrl-+",
00506 #if MOTIF
00507        ", toolbar button 7\n",
00508 #else
00509        "\n",
00510 #endif
00511        "     Makes the display of the page larger (zooms in).\n",
00512        "\n",
00513        "Ctrl-+",
00514 #if MOTIF
00515        ", toolbar button 8\n",
00516 #else
00517        "\n",
00518 #endif
00519        "     Makes the display of the page smaller (zooms out).\n",
00520        "\n",
00521        "Alt-Ctrl-+",
00522 #if MOTIF
00523        ", toolbar button 16\n",
00524 #else
00525        "\n",
00526 #endif
00527        "     Makes the fonts darker (by adding to the gamma value).\n",
00528        "\n",
00529        "Alt-Ctrl--",
00530 #if MOTIF
00531        ", toolbar button 17\n",
00532 #else
00533        "\n",
00534 #endif
00535        "     Makes the fonts lighter (by substracting from the gamma\n",
00536        "     value).\n",
00537        "\n",
00538        NULL
00539     };
00540 
00541     static const char *default_help_marking[] = {
00542        "Printing and Saving\tMarking, printing and saving pages\n",
00543        "The `Save' and `Print' dialogs allow you to save or print all,\n",
00544        "pages, a range of pages, or all marked pages from a DVI file.\n",
00545        "\n",
00546        "Note that the page numbers for the `From ... to ...' range\n",
00547        "refer to physical pages, not TeX pages (compare the option\n",
00548        "`Use TeX Page Numbers' and the `T' keystroke).\n",
00549        "\n",
00550        "To mark a page or a range of pages, use one of the folllowing\n",
00551        "methods:\n",
00552        "- Click on the page in the page list with Mouse Button 2 to mark\n",
00553        "  a single page, or drag the mouse while holding down Button 2\n",
00554        "  to mark a range of pages.\n",
00555        "- Use one of the following key combinations:\n",
00556        "     m:  toggle the mark of the current page,\n",
00557        "     1m  toggle the marks of all odd pages,\n",
00558        "     2m  toggle the marks of all even pages,\n",
00559        "     0m: unmark all pages,\n",
00560        "     Ctrl-n: toggle mark of current page, then move one page forward,\n",
00561        "     Ctrl-u: move one page back, then toggle mark of that page.\n",
00562 #if MOTIF
00563         "- Use one of the toobar buttons 12 to 15 to toggle the marks\n",
00564         "  of odd pages, toggle the marks of even pages, toggle the mark\n",
00565        "  of the current page, or unmark all pages, respectively.\n",
00566 #endif
00567        "\n",
00568        "If the X resource or command line option `paper' has been used,\n",
00569        "its value is inserted into the `Dvips Options' field of the printing\n",
00570        "dialog so that the appropriate options can be passed to dvips.\n",
00571        "This doesn't happen if the paper size has been specified explicitly\n",
00572        "in the DVI file (e.g. by using the LaTeX `geometry' package).\n",
00573        "Note that  not all of the paper options used by xdvi\n",
00574        "may be understood by dvips; dvips will ignore the option\n",
00575        "in that case, and will use its default paper setting.\n",
00576        NULL
00577     };
00578     
00579     static const char *default_help_pagemotion[] = {
00580        "Page Motion\tMoving around in the document\n",
00581        "\n",
00582         "[\n",
00583        "     Moves back one item in the page history. With a prefix\n",
00584        "     argument n, move back n history items.\n"
00585        "\n",
00586         "]\n",
00587        "     Moves forward one item in the page history. With a prefix\n",
00588        "     argument n, move forward n history items.\n"
00589        "\n",
00590         "Ctr-[\n",
00591        "     Deletes current item in the page history and move\n",
00592        "     to the history item before the deleted one. With a prefix\n",
00593        "     argument n, delete n previous history items.\n",
00594        "\n",
00595         "Ctr-]\n",
00596        "     Deletes current item in the page history and move\n",
00597        "     to the history item after the deleted one. With a prefix\n",
00598        "     argument n, delete n next history items.\n",
00599        "\n",
00600        "n or f or Space or Return or LineFeed or PgDn",
00601 #if MOTIF
00602        ", toolbar button 5\n",
00603 #else
00604        "\n",
00605 #endif
00606        "     Moves to the next page (or to the nth next page if a\n",
00607        "     number is given).\n",
00608        "\n",
00609        "p or b or Ctrl-h or BackSpace or Del or PgUp",
00610 #if MOTIF
00611        ", toolbar button 4\n",
00612 #else
00613        "\n",
00614 #endif
00615        "     Moves to the previous page (or back n pages).\n",
00616        "\n",
00617        "Up-arrow\n",
00618        "     Scrolls page up.\n",
00619        "\n",
00620        "Down-arrow\n",
00621        "     Scrolls page down.\n",
00622        "u\n",
00623        "     Moves page up two thirds of a window-full.\n",
00624        "\n",
00625        "d\n",
00626        "     Moves page down two thirds of a window-full.\n",
00627        "\n",
00628        "Left-arrow\n",
00629        "     Scrolls page left.\n",
00630        "\n",
00631        "Right-arrow\n",
00632        "     Scrolls page right.\n",
00633        "\n",
00634        "l\n",
00635        "     Moves page left two thirds of a window-full.\n",
00636        "\n",
00637        "r\n",
00638        "     Moves page right two thirds of a window-full.\n",
00639        "\n",
00640        "T\n",
00641        "     Toggle the use of TeX page numbers instead of physical\n",
00642        "     pages for the page list and the `g' command.\n",
00643        "     (See also the `Options -> Use TeX Pages' menu.)\n",
00644        "\n",
00645        "g\n",
00646        "     Moves to the page with the given number.  Initially,\n",
00647        "     the first page is assumed to be page number 1, but this\n",
00648        "     can be changed with the `P' keystroke, described in the\n",
00649        "     section `Other Commands'.  If no page number is given,\n",
00650        "     it moves to the last page.\n",
00651        "\n",
00652        "<, Ctrl-Home",
00653 #if MOTIF
00654        ", toolbar button 3\n",
00655 #else
00656        "\n",
00657 #endif
00658        "     Moves to first page in the document.\n",
00659        "\n",
00660        ">, Ctrl-End",
00661 #if MOTIF
00662        ", toolbar button 6\n",
00663 #else
00664        "\n",
00665 #endif
00666        "     Moves to last page in the document.\n",
00667        "\n",
00668        "^\n",
00669        "     Move to the ``home'' position of the page.  This is\n",
00670        "     normally the upper left-hand corner of the page,\n",
00671        "     depending on the margins set via the -margins option.\n",
00672        "\n",
00673        "Home\n",
00674        "     Move to the ``home'' position of the page (the upper\n",
00675        "     left-hand corner), or to the top of the page if the `keep'\n",
00676        "     flag is set.\n",
00677        "\n",
00678        "End\n",
00679        "     Move to the end position of the page (the lower\n",
00680        "     right-hand corner), or to the bottom of the page if the\n",
00681        "     `keep' flag is set.\n",
00682        "\n",
00683        "c\n",
00684        "     Moves the page so that the point currently beneath the\n",
00685        "     cursor is moved to the middle of the window.  It also\n",
00686        "     warps the cursor to the same place.\n",
00687        "\n",
00688        NULL
00689     };
00690 
00691 
00692     static const char *default_help_mousebuttons[] = {
00693        "Mouse Buttons\tActions bound to the mouse buttons\n",
00694        "The mouse buttons can be customized just like the keys;\n",
00695        "however the bindings cannot be intermixed (since\n",
00696        "a mouse event always requires the cursor location\n",
00697        "to be present, which a key event doesn't).\n",
00698         "The default bindings are as follows:\n"
00699        "\n",
00700        "Buttons 1-3\n",
00701        "     Pops up magnifier windows of different sizes.\n",
00702        "     When the mouse is over a hyperlink, the link overrides\n",
00703        "     the magnifier. In that case, Button 1 jumps to the link\n",
00704        "     in the current xdvi window, Button 2 opens the link target\n",
00705        "     in a new instance of xdvi.\n",
00706        "     In `Ruler Mode', Button1 shows/drags the ruler instead;\n",
00707        "     in `Text Selection Mode', Button1 can be used to select\n",
00708        "     a rectangular region of text from the DVI file.\n",
00709        "\n",
00710        "Shift-Button1 to Shift-Button3\n",
00711        "     Drag the page in each direction (Button 1), vertically\n",
00712        "     only (Button 2) or horizontally only (Button 3).\n",
00713        "\n",
00714        "Ctrl-Button1\n",
00715        "     Invoke a reverse search for the text on the cursor\n",
00716        "     location (see the section SOURCE SPECIALS for more\n",
00717        "     information on this).\n",
00718        "\n",
00719        "The buttons 4 and 5 (wheel up and down for wheel mice)\n",
00720        "scroll the page up and down respectively, or jump to the\n",
00721        "next/previous page when the mouse is over the page list.",
00722        "\n",
00723        "In the page list, Button 2 toggles the mark a page (see\n",
00724        "section `Marking Pages'); moving the mouse while holding\n",
00725        "Button 2 lets you toggle a range of pages.\n",
00726        "\n",
00727        NULL
00728     };
00729 
00730     static const char *default_help_sourcespecials[] = {
00731        "Source Specials\tNavigating between the TeX and the DVI file\n",
00732        "Some TeX implementations have an option to automatically\n",
00733        "include so-called `source specials' into a DVI file. These\n",
00734        "contain the line number and the filename of the TeX source\n",
00735        "and make it possible to go from a DVI file to the\n",
00736        "(roughly) corresponding place in the TeX source and back\n",
00737        "(this is also called `reverse search' and `forward search').\n",
00738        "\n",
00739        "On the TeX side, you need a TeX version that supports the `-src'\n",
00740        "option (e.g. teTeX >= 2.0) or a macro package like srcltx.sty\n",
00741        "to insert the specials into the DVI file.\n",
00742        "\n",
00743        "Source special mode can be customized for various editors\n",
00744        "by using the command line option \"-editor\" or one of the\n",
00745        "environment variables \"XEDITOR\", \"VISUAL\" or \"EDITOR\".\n",
00746        "See the xdvi man page on the \"-editor\" option for details\n",
00747        "and examples.\n",
00748        "\n",
00749        "Forward search can be performed by a program (i.e. your editor)\n",
00750        "invoking xdvi with the \"-sourceposition\" option like this:\n",
00751        "xdvi -sourceposition \"<line> <filename>\" <main file>\n",
00752        "If there is already an instance of xdvi running that displays\n",
00753        "<main file>, it will try to open the page specified by\n",
00754        "<line> and <filename> an highlight this location on the page.\n",
00755        "Else, a new instance of xdvi will be started that will try to\n",
00756        "do the same.\n",
00757        "\n",
00758        "The following keybindings are pre-configured:\n",
00759        "\n",
00760        "Ctrl-Mouse1\n",
00761        "     [source-special()] Invoke the editor (the value\n",
00762        "     of the \"editor\" resource ) to display the line in the\n",
00763        "     TeX file corresponding to special at cursor position.\n",
00764        "\n",
00765        "Ctrl-v\n",
00766        "     [show-source-specials()]  Show bounding boxes for every\n",
00767        "     source special on the current page, and print the strings\n",
00768        "     contained in these specials to  stderr. With prefix 1,\n",
00769        "     show every bounding box on the page (for debugging purposes).\n",
00770        "\n",
00771        "Ctrl-x\n",
00772        "     [source-what-special()]  Display information about the\n",
00773        "     source special next to the cursor, similar to\n",
00774        "     \"source-special()\", but without actually invoking\n",
00775        "     the editor (for debugging purposes).\n",
00776        "\n",
00777        NULL
00778     };
00779 
00780     static const char *default_help_modes[] = {
00781        "Mouse Modes\tMagnifier Mode, Ruler Mode and Text Selection Mode\n",
00782        "The keystroke Ctrl-m [switch-mode()] switches between\n",
00783        "three different bindings for Mouse-1, which can also be\n",
00784        "activated via the Modes menu (in Motif, this is a submenu\n",
00785        "of the Options menu).  The default mode at startup can be\n",
00786        "customized via the X resource `mouseMode' or the command-line\n",
00787        "option `-mousemode'.  The default startup mode is Magnifier Mode.\n",
00788        "\n",
00789        "Note: The modes are activated by changing the magnifier()\n",
00790        "action. Switching the mode will not work if Mouse-1 has\n",
00791        "been customized to an action sequence that does not contain\n",
00792        "the magnifier() action.\n",
00793         "\n",
00794         "Magnifier Mode\n",
00795         "\n",
00796         "       In this mode, the mouse buttons 1 to 5 will pop up a\n",
00797         "       ``magnifying glass'' that shows an unshrunken image of\n",
00798        "       the page (i.e. an image at the resolution determined by\n",
00799        "       the option/X resource pixels or mfmode) at varying sizes.\n",
00800         "       When the magnifier is moved, small ruler-like tick marks\n",
00801        "       are displayed at the edges of the magnifier (unless\n",
00802         "       the X resource delayRulers is set to false, in which case\n",
00803        "       the tick marks are always displayed).\n",
00804         "\n",
00805         "       The unit of the marks is determined by the X resource\n",
00806         "       `tickUnits' (mm by default). This unit can be changed at\n",
00807         "       runtime via the action `switch-magnifier-units()', by\n",
00808         "       default bound to the keystroke `t' (see the description\n",
00809         "       of that key, and of `switch-magnifier-units()' for more\n",
00810         "       details on the units available).  The length of the tick\n",
00811         "       marks can be changed via the X resource `tickLength'\n",
00812         "       (4 by default). A zero or negative value suppresses the\n",
00813         "       tick marks.\n",
00814         "\n",
00815         "\n",
00816         "Text Selection Mode\n",
00817         "\n",
00818         "       This mode allows you to select a rectangular region of\n",
00819         "       text in the DVI file by holding down Mouse-1 and moving\n",
00820         "       the mouse. The text is put into the X primary selection\n",
00821         "       so that it can be pasted into other X applications with\n",
00822         "       Mouse-2.\n",
00823         "\n",
00824         "       If xdvi has been compiled with locale, nl_langinfo() and\n",
00825         "       iconv support, the selected text is converted into the\n",
00826         "       character set of the current locale (see the output of\n",
00827         "       `locale -a' for a list of locale settings available on\n",
00828         "       your system).  If nl_langinfo() is not available, but\n",
00829         "       iconv is, you can specify the input encoding for iconv\n",
00830         "       via the X resource `textEncoding' (see the output of\n",
00831         "       `iconv -l' for a list of valid encodings). If iconv support\n",
00832         "       is not available, only the encodings ISO-8859-1 and UTF-8\n",
00833         "       are supported (these names are case-insensitive).\n",
00834         "\n",
00835         "       Note that UTF-8 is the only encoding that can render all\n",
00836         "       characters (e.g. mathematical symbols). If ISO-8859-1 is\n",
00837         "       active, characters that cannot be displayed are replaced\n",
00838         "       by `\' followed by the hexadecimal character code.  If a\n",
00839         "       character is not recognized at all, it is replaced by\n",
00840         "       `?'.  For other encodings, such characters may trigger\n",
00841         "       iconv error messages.\n",
00842         "\n",
00843         "       If you want to extract larger portions of text, you\n",
00844         "       can also save selected pages or the entire file in\n",
00845         "       text format from the `File > Save as ...'  menu.\n",
00846         "\n",
00847         "\n",
00848         "Ruler Mode\n",
00849         "\n",
00850         "       This mode provides a simple way of measuring distances\n",
00851         "       on the page.  When this mode is activated, the mouse\n",
00852         "       cursor changes into a thin cross, and a larger, cross-\n",
00853         "       shaped ruler is drawn in the highlight color at the\n",
00854         "       mouse location. The ruler doesn't have units attached\n",
00855         "       to it; instead, the current distance between the ruler\n",
00856         "       and the mouse cursor is continously printed to the\n",
00857         "       statusline.\n",
00858         "\n",
00859         "       When activating Ruler Mode, the ruler is at first\n",
00860         "       attached to the mouse and can be moved around.  It can\n",
00861         "       then be positioned at a fixed place by clicking Mouse-1.\n",
00862         "       After that, the mouse cursor can be moved to measure the\n",
00863         "       horizontal (dx), vertical (dy) and direct (shortest)\n",
00864         "       (dr) distance between the ruler center point and the\n",
00865         "       mouse.\n",
00866         "\n",
00867         "       Clicking Mouse-1 again will move the ruler to the\n",
00868         "       current mouse position, and holding down Mouse-1 will\n",
00869         "       drag the ruler around.\n",
00870         "\n",
00871         "       In Ruler Mode, the following special keybindings extend\n",
00872         "       or replace the default bindings:\n",
00873         "\n",
00874         "       o      [ruler-snap-origin()] Snap the ruler back to\n",
00875         "              the origin coordinate (0,0).\n",
00876         "\n",
00877         "       t      [overrides switch-magnifier-units()] Toggle\n",
00878         "              between various ruler units,  which can be\n",
00879         "              specified by the X resource tickUnits (`mm'\n",
00880         "              by default).\n",
00881         "\n",
00882         "       P      [overrides declare-page-number()] Print the\n",
00883         "              distances shown in the statusline to standard\n",
00884         "              output.\n",
00885         NULL
00886     };
00887 
00888     static const char *default_help_search[] = {
00889        "String Search\tSearching for strings in the DVI file\n",
00890         "The keystroke Ctrl-f or the menu entry File->Find ...\n",
00891         "opens a dialog window to search for a text string or a\n",
00892         "regular expression in the DVI file. The keystroke Ctrl-g\n",
00893        "jumps to the next match.\n",
00894 #ifdef MOTIF
00895        "(With Motif, you can also click on the `Binoculars' symbol\n",
00896        "in the toolbar.)\n",
00897 #endif
00898         "\n",
00899 #if HAVE_ICONV_H
00900 #if USE_LANGINFO
00901        "The search term is converted from the character set specified\n",
00902        "by the current locale into UTF-8. (See the output of `locale -a'\n",
00903        "for a list of locale settings available on your system).\n",
00904 #else /* USE_LANGINFO */
00905        "Since langinfo() support is not available on this platform,\n",
00906        "the character set of the search string should be specified\n",
00907        "via the X resource/command-line option textEncoding if the\n",
00908        "encoding is different from iso_8859-1.\n",
00909 #endif /* USE_LANGINFO */
00910 #else /* HAVE_ICONV_H */
00911         "Since iconv() support is not available on this platform,\n",
00912        "the search term should be a string in the encoding specified\n",
00913         "by the X resource/command-line option textEncoding;\n",
00914         "currently, only the values iso_8859-1 and utf-8 are suported.\n",
00915 #endif
00916         "Internally, the text in the DVI file is represented in\n",
00917         "UTF-8 encoding (you can view the text by saving the DVI\n",
00918         "file to a text file in UTF-8 encoding via the `File -> Save As ...'\n",
00919         "dialog).\n",
00920        "\n",
00921        "Ideographic characters from CJKV fonts are treated specially:\n",
00922        "All white space (spaces and newlines) before and after such\n",
00923        "characters is ignored in the search string and in the DVI file.\n",
00924        "\n",
00925        "To match a newline character, use `\\n' in the search string;\n",
00926        "to match the string `\\n', use `\\\\n'.\n",
00927         "\n",
00928         "If the checkbox Regular Expression is activated, the\n",
00929         "string is teated as a regular expression in extended POSIX\n",
00930         "format, with the following properties:\n",
00931         "\n",
00932         "   a? matches a zero or one times\n",
00933         "\n",
00934         "   a* matches a zero or more times\n",
00935         "\n",
00936         "   a+ matches a one or more times. Note that * and + are\n",
00937         "   greedy, i.e. they match the longest possible\n",
00938         "   sub string.\n",
00939         "\n",
00940         "   a{n} matches a exactly n times\n",
00941         "\n",
00942         "   a{n,m} matches a at least n and no more than m times\n",
00943         "\n",
00944         "   a|b matches a or b. Brackets can be used for grouping,\n",
00945         "   e.g.: (a|b)|c.\n",
00946         "\n",
00947         "   The string matched by the nth group can be referenced\n",
00948         "   by \\n, e.g. \\1 refers to the first match.\n",
00949         "\n",
00950         "   The characters ^ and $ match the beginning and the end\n",
00951         "   of a line, respectively.\n",
00952         "\n",
00953         "   [abc] matches any of the letters a, b, c, and [a-z]\n",
00954         "   matches all characters from a to z.\n",
00955         "\n",
00956         "   The patterns . and [...] without an explicit newline\n",
00957         "   don't match a newline character.\n",
00958         "\n",
00959         "   Each item in a regular expression can also be one of\n",
00960         "   the following POSIX character classes:\n",
00961         "   [[:alnum:]] [[:alpha:]] [[:blank:]] [[:cntrl:]] [[:digit:]]\n",
00962         "   [[:graph:]] [[:lower:]] [[:print:]] [[:space:]] [[:upper:]]\n",
00963         "\n",
00964         "   These can be negated by inserting a ^ symbol after the\n",
00965         "   first bracket: [^[:alpha:]]\n",
00966         "\n",
00967         "   For more details on POSIX regular expressions, see\n",
00968         "   e.g. the IEEE Std 1003.1 available online from:\n",
00969         "\n",
00970         "   http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap09.html\n",
00971        "\n",
00972         "   As a non-standard extension, the following Perl-like\n",
00973         "   abbreviations can be used instead of the POSIX classes:\n",
00974         "\n",
00975         "\n",
00976         "      Symbol Meaning                       POSIX Class\n",
00977         "\n",
00978         "        \\w   an alphanumeric character     [[:alnum:]]\n",
00979         "        \\W   a non-alphanumeric character  [^[:alnum:]]\n",
00980         "        \\d   a digit character             [[:digit:]]\n",
00981         "        \\D   a non-digit character         [^[:digit:]]\n",
00982         "        \\s   a whitespace character        [[:space:]]\n",
00983         "        \\S   a non-whitespace character    [^[:space:]]\n",
00984         "\n",
00985         "   The following characters are special symbols; they\n",
00986         "   need to be escaped with \\ in order to match them\n",
00987         "   literally: ( ) [ ] . * ? + ^ $ \\.\n",
00988         "\n",
00989         "The dialog also provides checkboxes to search backwards,\n",
00990         "to match in a case-sensitive manner (the default is to\n",
00991         "ignore case, i.e. a search string Test will match both\n",
00992         "the strings test and TEST in the DVI file) and to ignore\n",
00993        "newlines and hyphens in the DVI file.\n",
00994        "\n",
00995        NULL
00996     };
00997     
00998     k = width = 0;
00999 
01000     init_item(resource.help_general, default_help_general, info, k++, &width);
01001     init_item(resource.help_pagemotion, default_help_pagemotion, info, k++, &width);
01002     init_item(resource.help_othercommands, default_help_othercommands, info, k++, &width);
01003     init_item(resource.help_hypertex, default_help_hypertex, info, k++, &width);
01004     init_item(resource.help_mousebuttons, default_help_mousebuttons, info, k++, &width);
01005     init_item(resource.help_modes, default_help_modes, info, k++, &width);
01006     init_item(resource.help_search, default_help_search, info, k++, &width);
01007     init_item(resource.help_pagemotion, default_help_marking, info, k++, &width);
01008     init_item(resource.help_sourcespecials, default_help_sourcespecials, info, k++, &width);
01009 
01010     ASSERT(k < NUM_HELP_TOPICS, "Too many elements in help topics!");
01011 
01012     /* NULL-terminate items info */
01013     info->items[k].widget = 0;
01014     info->items[k].topic = info->items[k].title = NULL;
01015 
01016     /* adjust width of topics label to longest text */
01017 #if !MOTIF
01018     XtVaSetValues(info->topic_label, XtNwidth, width, NULL);
01019 #endif
01020 }
01021 
01022 
01023 
01024 /*
01025  * Pops up the help window. If topic != NULL, also selects the topic.
01026  */
01027 void
01028 show_help(Widget toplevel, const char *topic)
01029 {
01030     size_t i;
01031     static Widget help_shell = 0;
01032     static struct topic_info info;
01033     static struct topic_item items[NUM_HELP_TOPICS];
01034     static Boolean first_time = True;
01035     
01036     if (help_shell == 0) { /* called 1st time; create widget */
01037 
01038        /* no special callbacks for OK/Cancel buttons */
01039        info.ok_callback = NULL;
01040        info.cancel_callback = NULL;
01041        info.items = items;
01042 /*     info.items_size = NUM_HELP_TOPICS; */
01043            
01044        help_shell = create_topic_window(toplevel,
01045                                     "xdvik: Help",
01046                                     "help_window",
01047                                     &info,
01048                                     initialize_items,
01049                                     "Close",
01050                                     /* no Cancel button needed */
01051                                     NULL);
01052        info.shell = help_shell;
01053        
01054        center_window(help_shell, globals.widgets.top_level);
01055     }
01056     
01057 #if MOTIF
01058     { /* check if resources are set properly */
01059        Dimension w, h;
01060        XtVaGetValues(help_shell, XtNwidth, &w, XtNheight, &h, NULL);
01061        if (h < 200 || w < 400) {
01062            XDVI_WARNING((stderr, "Initial help window size too small (%dx%d); overriding size.\n"
01063                        "Please check/update your application defaults file, and set both of\n"
01064                        "`XDvi*help_text.rows' and `XDvi*help_text.columns' to a realistic value.",
01065                        h, w));
01066            XtVaSetValues(help_shell, XtNwidth, 620, XtNheight, 520, NULL);
01067        }
01068     }
01069 #endif
01070     XtPopup(help_shell, XtGrabNone);
01071 
01072     if (topic != NULL) {
01073        Boolean matched = False;
01074        for (i = 0; info.items[i].topic != NULL; i++) {
01075            if (strcmp(info.items[i].topic, topic) == 0) { /* match */
01076               select_topic(&info, i);
01077               matched = True;
01078            }
01079        }
01080        if (!matched) {
01081            XBell(DISP, 0);
01082            popup_message(help_shell,
01083                        MSG_WARN,
01084                        NULL,
01085                        "Shouldn't happen: Could not find topic `%s' in help list!\n"
01086                        REPORT_XDVI_BUG_TEMPLATE,
01087                        topic);
01088        }
01089     }
01090     else if (first_time) {
01091        first_time = False;
01092        select_topic(&info, 0);
01093     }
01094 }