Back to index

tetex-bin  3.0
Classes | Functions
topic-window.h File Reference
#include "xdvi-config.h"
#include "xdvi.h"
#include "version.h"
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  topic_item
struct  topic_info

Functions

Widget create_topic_window (Widget parent, const char *window_title, const char *widget_name, struct topic_info *info, void(*init_items_func)(struct topic_info *info), const char *ok_label, const char *cancel_label)
void select_topic (struct topic_info *info, size_t idx)

Class Documentation

struct topic_item

Definition at line 37 of file topic-window.h.

Class Members
char * title
char * topic
Widget widget

Function Documentation

Widget create_topic_window ( Widget  parent,
const char *  window_title,
const char *  widget_name,
struct topic_info info,
void(*)(struct topic_info *info init_items_func,
const char *  ok_label,
const char *  cancel_label 
)

Definition at line 474 of file topic-window.c.

{
    Widget topic_window, topics_list, topic_label;
    Widget pane, form, left_form, right_container_form, right_form;
    Widget action_area, ok_button, cancel_button;
    XtTranslations xlats;

    XtAppContext app = NULL;
    Atom WM_DELETE_WINDOW;

    char *translation_str;
    size_t i;
    
#if !MOTIF
    translation_str = get_string_va("<Message>WM_PROTOCOLS: WM_popdown(%p)", info);
    xlats = XtParseTranslationTable(translation_str);
    free(translation_str);
#endif
       
    topic_window = XtVaCreatePopupShell(widget_name, SHELL_WIDGET_CLASS,
                                   parent,
                                   XtNtitle, window_title,
                                   HELP_SHELL_ARGS);

#if MOTIF
    /* make the window manager destroy action pop down the window */
    WM_DELETE_WINDOW = XmInternAtom(XtDisplay(topic_window), "WM_DELETE_WINDOW", False);
    XmAddWMProtocolCallback(topic_window, WM_DELETE_WINDOW, cancel_cb, info);
#else
    WM_DELETE_WINDOW = XInternAtom(XtDisplay(topic_window), "WM_DELETE_WINDOW", False);
#endif
    app = XtWidgetToApplicationContext(topic_window);
    XtAppAddActions(app, popdown_actions, XtNumber(popdown_actions));

    pane = XtVaCreateWidget("topic_pane", PANED_WIDGET_CLASS, topic_window, HELP_PANED_ARGS);

    form = XtVaCreateWidget("form", FORM_WIDGET_CLASS, pane, FORM_ARGS);

    /* left pane for topics selection */
    left_form = XtVaCreateWidget("left_form", FORM_WIDGET_CLASS, form, LEFT_FORM_ARGS);

    /* right form for topics display */
    right_container_form = XtVaCreateWidget("right_container_form", FORM_WIDGET_CLASS, form, RIGHT_FORM_ARGS);

    /*
      Initialize the topic label and title string with dummy values - the real values
      are only known inside init_items_func(). For Xaw, the size of the widget will be
      adjusted below (for Motif it's always the full width of the right form, which is
      what we want).
    */
    /* FIXME: Motif label is still chopped off if it's longer than right form -
       work around by putting longest possible lable here ... */
    /* Also, not all children will be sized correctly, e.g. the colors - work around
       by specifying a rather large dummy text ... */
    info->items[0].topic = "text text text";
    info->items[0].title = "text text text text text text text text text text text text text text text text text";
    topic_label = create_label_widget(right_container_form, "topic_label", info);
    info->topic_label = topic_label;

    right_form = XtVaCreateWidget("right_form", FORM_WIDGET_CLASS,
                              right_container_form,
#if MOTIF
                              XmNtopAttachment, XmATTACH_WIDGET,
                              XmNtopWidget, topic_label,
                              XmNtopOffset, 10,
                              XmNleftAttachment, XmATTACH_FORM,
                              XmNrightAttachment, XmATTACH_FORM,
                              XmNbottomAttachment, XmATTACH_FORM,
#else
                              XtNborderWidth, 0,
                              XtNfromVert, topic_label,
                              XtNvertDistance, 6,
#endif /* MOTIF */
                              NULL);
    info->right_form = right_form;
    
    /*
      Call the init_items_func callback. This will populate the info->items list
      with the appropriate info, and create the forms (info->items[i].widget)
      which are the children of right_form (which is accessed inside init_items_func()
      through info->right_form), and all their subchildren.

      It is important that every child form is already managed inside init_items_func
      so that the total size of the preferences window is set to the maximum size of
      the children. (The children will be unmanaged again below). All these widgets
      are never destroyed, and are managed by demand via the list selection callback
      (select_topic_cb).
    */
    init_items_func(info);

    XtManageChild(topic_label);
    
    topics_list = create_list_widget(left_form, "topics_list", info);
    info->topics_list = topics_list;

    translation_str = get_string_va("#override \n"
                                "<Key>q:close-topic-window(%p)\n"
#ifdef MOTIF
                                "<Key>osfCancel:close-topic-window(%p)\n"
#else
                                "<Key>Escape:close-topic-window(%p)\n"
#endif
                                "<Key>Return:close-topic-window(%p)",
                                info, info, info);
    xlats = XtParseTranslationTable(translation_str);
    free(translation_str);
    translation_str = NULL;

    XtOverrideTranslations(pane, xlats);
    XtOverrideTranslations(topics_list, xlats);

    XtManageChild(left_form);
    
    XtManageChild(right_form);
    XtManageChild(right_container_form);

    /* action area at bottom */
    action_area = XtVaCreateWidget("action_area", FORM_WIDGET_CLASS, pane, ACTION_AREA_ARGS);
       
    ok_button = create_button(action_area, ok_label, True, True);
    XtOverrideTranslations(ok_button, xlats);
    
    if (cancel_label != NULL) {
       cancel_button = create_button(action_area, cancel_label, False, False);
       adjust_width(ok_button, cancel_button);
#if MOTIF
       XtAddCallback(cancel_button, XmNactivateCallback, cancel_cb, info);
#else
       XtAddCallback(cancel_button, XtNcallback, cancel_cb, info);
#endif
       XtOverrideTranslations(cancel_button, xlats);
    }
       
    XtManageChild(action_area);

    XtManageChild(form);

    XtManageChild(pane);
       
    XtRealizeWidget(topic_window);
    
    /* Now unmanage all children of right_form, as described above. */
    for (i = 0; info->items[i].topic != NULL; i++) {
       XtUnmanageChild(info->items[i].widget);
    }
    info->curr_selected = 0;
    
#if MOTIF
    /* enable OK button */
    XmProcessTraversal(ok_button, XmTRAVERSE_CURRENT);
    XtOverrideTranslations(ok_button,
                        XtParseTranslationTable("<Key>Return:ArmAndActivate()\n"
                                             "<Key>q:ArmAndActivate()"));
    XtAddCallback(ok_button, XmNactivateCallback, ok_cb, info);
    XmAddWMProtocolCallback(topic_window, WM_DELETE_WINDOW, cancel_cb, info);
    { /* disable resizing of lower part of pane (and button) */
       Dimension h;
       XtVaGetValues(ok_button, XmNheight, &h, NULL);
       XtVaSetValues(action_area,
                    XmNpaneMaximum, h + 20,
                    XmNpaneMinimum, h + 20,
                    NULL);
    }
#else
    XSetWMProtocols(XtDisplay(topic_window), XtWindow(topic_window), &WM_DELETE_WINDOW, 1);
    XtAddCallback(ok_button, XtNcallback, ok_cb, info);
#endif
    return topic_window;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void select_topic ( struct topic_info info,
size_t  idx 
)

Definition at line 242 of file topic-window.c.

{
#if MOTIF
    XmString label;
#else
    char *label;
#endif

    /* change the heading in right window */
    label = create_label_string(info->items[idx].topic, info->items[idx].title);
    XtVaSetValues(info->topic_label,
#if MOTIF
                XmNlabelString,
#else
                XtNlabel,
#endif
                label, NULL);

#if MOTIF
    XmStringFree(label);
    XmListSelectPos(info->topics_list, idx + 1, False);
#else
    free(label);
    XawListHighlight(info->topics_list, idx);
#endif
    
    if (info->curr_selected != 0) {
       XtUnmanageChild(info->curr_selected);
    }
    else {
       /* Note: doesn't matter if not managed yet */
/*     XtUnmanageChild(info->items[0].widget); */
    }

    XtManageChild(info->items[idx].widget);
    info->curr_selected = info->items[idx].widget;

#if MOTIF
    XmUpdateDisplay(info->shell);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function: