void wrapToFitToggleCB( Widget w, XtPointer client_data, XtPointer call_data) { char *cb; Widget sw_w, sww_w; XmToggleButtonCallbackStruct *acs; acs = (XmToggleButtonCallbackStruct *) call_data; cb = "wrapToFitToggleCB"; sw_w = get_widget_by_name(w, cb, "textWindow"); sww_w = get_widget_by_name(w, cb, "textWindowWrapped"); switch (acs->set) { case XmSET: XtManageChild(sww_w); XtUnmanageChild(sw_w); break; default: XtManageChild(sw_w); XtUnmanageChild(sww_w); break; } }
void overstrikeToggleCB( Widget w, XtPointer client_data, XtPointer call_data) { char *cb; Widget doc_w, docw_w, overstrike_lbl_w; XmString s; XmToggleButtonCallbackStruct *acs; cb = "overstrikeToggleCB"; acs = (XmToggleButtonCallbackStruct *)call_data; doc_w = get_widget_by_name(w, cb, "documentText"); docw_w = get_widget_by_name(w, cb, "documentTextWrapped"); overstrike_lbl_w = get_widget_by_name(w, "overstrikeToggleCB", "overstrikeLabel"); XtCallActionProc(doc_w, "toggle-overstrike", NULL, NULL, 0); XtCallActionProc(docw_w, "toggle-overstrike", NULL, NULL, 0); switch (acs->set) { case XmSET: s = XmStringCreateLocalized("Overstrike"); XtVaSetValues(overstrike_lbl_w, XmNlabelString, s, NULL); break; default: s = XmStringCreateLocalized("Insert"); XtVaSetValues(overstrike_lbl_w, XmNlabelString, s, NULL); break; } XmStringFree(s); }
static void match_cb(Widget w, XtPointer client_data, XtPointer call_data) { struct topic_info *info = (struct topic_info *)client_data; struct prefs_choice *prefs = (struct prefs_choice *)(info->data); Widget inverted, boxed; UNUSED(w); UNUSED(call_data); resource.match_highlight_inverted = !resource.match_highlight_inverted; /* force a redraw so that a current match is updated if there was one */ globals.ev.flags |= EV_NEWPAGE; store_preference(&(prefs->db), "matchInverted", "%s", resource.match_highlight_inverted ? "True" : "False"); if (get_widget_by_name(&inverted, info->shell, Xdvi_MATCH_INVERTED_STR, True) && get_widget_by_name(&boxed, info->shell, Xdvi_MATCH_BOXED_STR, True)) { XmToggleButtonGadgetSetState(inverted, resource.match_highlight_inverted, False); XmToggleButtonGadgetSetState(boxed, !resource.match_highlight_inverted, False); } }
static void toolbar_buttons_cb(Widget w, XtPointer client_data, XtPointer call_data) { struct topic_info *info = (struct topic_info *)client_data; struct x_resources *res = (struct x_resources *)(info->data); Boolean is_flat = False, is_raised = False; Widget flat_b, raised_b; UNUSED(call_data); if (!get_widget_by_name(&flat_b, XtParent(w), TB_BUTTONS_FLAT_STR, True) || !get_widget_by_name(&raised_b, XtParent(w), TB_BUTTONS_RAISED_STR, True)) return; if (w == flat_b) { is_flat = True; } else if (w == raised_b) { is_raised = True; } else { unexpected_widget_in_callback(w, "toolbar_buttons_cb()"); return; } res->toolbar_buttons_raised = is_raised ? True : False; XmToggleButtonGadgetSetState(raised_b, is_raised, False); XmToggleButtonGadgetSetState(flat_b, is_flat, False); }
Boolean preferences_changed(void) { Widget prefs_shell = 0, topic_pane = 0; if (get_widget_by_name(&prefs_shell, globals.widgets.top_level, "preferences_window", False) && get_widget_by_name(&topic_pane, prefs_shell, "topic_pane", False)) { struct topic_info *info = NULL; struct prefs_choice *prefs = NULL; XtVaGetValues(topic_pane, XmNuserData, &info, NULL); if (info == NULL) { return False; } prefs = (struct prefs_choice *)info->data; if (prefs->db != NULL) { /* prefs changed */ Widget popup = choice3_dialog(prefs_shell, MSG_QUESTION, NULL, #ifndef MOTIF NULL, #endif close_prefs_exit, info, /* pre_callbacks */ "Save and Exit", save_prefs_exit, info, "Exit, don't Save", no_save_prefs_exit, info, "Cancel", NULL, NULL, "Preferences have been changed, but not saved yet. " "Save them now?"); add_to_deplist(prefs, popup); return True; } } return False; }
void update_preferences_hyperlinks(void) { Widget shell, button; /* it's not an error if the prefs dialog doesn't exist yet */ if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) && get_widget_by_name(&button, shell, Xdvi_LINKS_UNDERLINED_STR, True)) { XmToggleButtonGadgetSetState(button, resource.link_style & 1 ? True : False, False); } }
void update_preferences_color(void) { Widget shell, button; /* it's not an error if the prefs dialog doesn't exist yet */ if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) && get_widget_by_name(&button, shell, Xdvi_DOCUMENT_COLORS_STR, True)) { XmToggleButtonGadgetSetState(button, resource.use_color, False); } }
static void tooltips_cb(Widget w, XtPointer client_data, XtPointer call_data) { struct topic_info *info = (struct topic_info *)client_data; struct prefs_choice *prefs = (struct prefs_choice *)(info->data); const char *w_name = XtName(w); UNUSED(call_data); if (strcmp(w_name, Xdvi_TIPS_STATUSLINE) == 0) { resource.tooltips_in_statusline = !resource.tooltips_in_statusline; store_preference(&(prefs->db), "tooltipsInStatusline", "%s", resource.tooltips_in_statusline ? "True" : "False"); } else if (strcmp(w_name, Xdvi_TIPS_POPUPS) == 0) { Widget label1, text, label2; resource.show_tooltips = !resource.show_tooltips; if (!resource.show_tooltips && resource.tooltips_wait_period >= 0) { if (resource.tooltips_wait_period == 0) resource.tooltips_wait_period = -1; else resource.tooltips_wait_period = -resource.tooltips_wait_period; } else if (resource.show_tooltips && resource.tooltips_wait_period < 0) { resource.tooltips_wait_period = -resource.tooltips_wait_period; } store_preference(&(prefs->db), "showTooltips", "%s", resource.show_tooltips ? "True" : "False"); if (get_widget_by_name(&label1, info->shell, Xdvi_TIPS_DELAY_LABEL1, True) && get_widget_by_name(&text, info->shell, Xdvi_TIPS_DELAY_TEXT, True) && get_widget_by_name(&label2, info->shell, Xdvi_TIPS_DELAY_LABEL2, True)) { XtSetSensitive(label1, resource.show_tooltips); XtSetSensitive(text, resource.show_tooltips); XtSetSensitive(label2, resource.show_tooltips); } } else if (strcmp(w_name, Xdvi_TIPS_DELAY_TEXT) == 0) { char *buf = XmTextFieldGetString(w); int val = strtol(buf, (char **)NULL, 10); XtFree((char *)buf); TRACE_GUI((stderr, "tooltips_cb wait period2: %d\n", val)); resource.tooltips_wait_period = val; store_preference(&(prefs->db), "tipShell.waitPeriod", "%d", val); } else { XDVI_WARNING((stderr, "unexpected widget name `%s' in tooltips_cb", XtName(w))); } }
void update_preferences_search(void) { Widget shell; Widget inverted, boxed; if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, True) && get_widget_by_name(&inverted, shell, Xdvi_MATCH_INVERTED_STR, True) && get_widget_by_name(&boxed, shell, Xdvi_MATCH_BOXED_STR, True)) { XmToggleButtonGadgetSetState(inverted, resource.match_highlight_inverted, False); XmToggleButtonGadgetSetState(boxed, !resource.match_highlight_inverted, False); } }
static void update_button_by_name(Pixel pix, const char *name) { static Widget pref_shell = 0; Widget button; if (pref_shell == 0 && !get_widget_by_name(&pref_shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, True)) return; if (get_widget_by_name(&button, pref_shell, name, True)) { update_button(button, pix); } }
void filehist_menu_add_entry(const char *filename) { static char *buf = NULL; static size_t buf_len = 0; size_t new_len = LENGTH_OF_INT + strlen(filename) + 1; Widget menu; /* Don't report an error here, since "filehist_pullright" is only created on-demand when user clicks on menu, but this may be called before from the event loop. (The menu will still contain this entry when it's created later.) */ if (get_widget_by_name(&menu, globals.widgets.top_level, "filehist_pullright", False)) { int num_children; Widget w; if (new_len > buf_len) { buf = xrealloc(buf, new_len); buf_len = new_len; } XtVaGetValues(menu, XtNnumChildren, &num_children, NULL); sprintf(buf, "%d %s", num_children + 1, filename); w = XtVaCreateManagedWidget("_filehist", smeBSBObjectClass, menu, XtNlabel, buf, XtNleftMargin, 10, NULL); XtAddCallback(w, XtNcallback, filehist_select_cb, NULL); update_menu_labels(menu); } }
void lineTextFieldActivateCB( Widget w, XtPointer client_data, XtPointer call_data) { short line, rows, cols; int conv; char *cb, *buf, *linestr; Widget doc_w, line_w; XmTextPosition pos; cb = "lineTextFieldActivateCB"; doc_w = get_document_text(w, cb); line_w = get_widget_by_name(w, cb, "lineTextField"); XtVaGetValues(doc_w, XmNrows, &rows, XmNcolumns, &cols, NULL); buf = XmTextGetString(doc_w); linestr = XmTextFieldGetString(line_w); conv = atoi(linestr); if (conv > rows) { manage_widget(w, cb, "lineOutOfRangeMessageBox"); goto Cleanup; } line = (short) conv; pos = line_to_position(buf, line, rows, cols); XmTextSetInsertionPosition(doc_w, pos); Cleanup: XtFree(linestr); XtFree(buf); }
static void apply_prefs_cb(XtPointer arg) { struct topic_info *info = (struct topic_info *)arg; struct prefs_choice *prefs = (struct prefs_choice *)info->data; size_t i; Widget colorsel; if (get_widget_by_name(&colorsel, globals.widgets.top_level, Xdvi_COLOR_DIALOG_NAME, False)) { XtPopdown(XtParent(colorsel)); } /* pop down dependent windows */ TRACE_GUI((stderr, "window count: %lu\n", (unsigned long)prefs->depwin_cnt)); for (i = 0; i < prefs->depwin_cnt; i++) { TRACE_GUI((stderr, "popping down %lu: %p", (unsigned long)i, (void *)(prefs->depwin[i]))); if (XtIsRealized(prefs->depwin[i])) { XtCallCallbacks(prefs->depwin[i], XmNcancelCallback, NULL); XSync(DISP, True); /* wait for server to catch up */ if (XtIsRealized(prefs->depwin[i])) { TRACE_GUI((stderr, "calling XmNokCallback of %lu: %p", (unsigned long)i, (void *)(prefs->depwin[i]))); XtCallCallbacks(prefs->depwin[i], XmNokCallback, NULL); } } } free(prefs->depwin); prefs->depwin = NULL; prefs->depwin_cnt = 0; if (prefs->db == NULL) /* callback invoked multiple times? */ return; merge_into_user_db(prefs->db); /* this destroys prefs->db */ prefs->db = NULL; /* remember some current values */ free(globals.curr_paper); if (resource.paper != NULL) globals.curr_paper = xstrdup(resource.paper); free(globals.curr_editor); if (resource.editor != NULL) globals.curr_editor = xstrdup(resource.editor); free(globals.curr_browser); if (resource.browser != NULL) globals.curr_browser = xstrdup(resource.browser); /* fprintf(stderr, "set curr_browser to: |%s|\n", globals.curr_browser); */ /* fprintf(stderr, "set curr_editor to: |%s|\n", globals.curr_editor); */ if (get_xdvi_window_id(False, NULL) && save_user_preferences(False)) { /* if other instances of xdvi are running, make them reread the changed preferences by writing them to ~/.xdvirc.tmp and having them read that file; otherwise they would overwrite the file if user quits them after the current instance. */ get_xdvi_window_id(False, reread_prefs_cb); } }
void update_preferences_darkness(void) { Widget shell, text; if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) && get_widget_by_name(&text, shell, Xdvi_DARKNESS_TEXT, True)) { char buf[LENGTH_OF_INT]; SNPRINTF(buf, LENGTH_OF_INT, "%d", (int)(resource.gamma * 100.0 + 0.5)); #if USE_SPINBOX XmTextFieldSetString(text, buf); XtVaSetValues(text, XmNposition, (int)(resource.gamma * 100.0 + 0.5), NULL); #else XtVaSetValues(text, XmNvalue, buf, NULL); #endif } }
void update_preferences_expert(void) { Widget shell; Widget statusline_b, toolbar_b, pagelist_b, scrollbars_b; /* it's not an error if the prefs dialog doesn't exist yet */ if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, False) && get_widget_by_name(&statusline_b, shell, Xdvi_GUI_STATUSLINE_STR, True) && get_widget_by_name(&toolbar_b, shell, Xdvi_GUI_TOOLBAR_STR, True) && get_widget_by_name(&pagelist_b, shell, Xdvi_GUI_PAGELIST_STR, True) && get_widget_by_name(&scrollbars_b, shell, Xdvi_GUI_SCROLLBARS_STR, True)) { XmToggleButtonGadgetSetState(statusline_b, resource.expert_mode & XPRT_SHOW_STATUSLINE ? True : False, False); XmToggleButtonGadgetSetState(toolbar_b, resource.expert_mode & XPRT_SHOW_TOOLBAR ? True : False, False); XmToggleButtonGadgetSetState(pagelist_b, resource.expert_mode & XPRT_SHOW_PAGELIST ? True : False, False); XmToggleButtonGadgetSetState(scrollbars_b, resource.expert_mode & XPRT_SHOW_SCROLLBARS ? True : False, False); } }
void BxUnmanageCB( Widget w, XtPointer client_data, XtPointer call_data) { char *name; Widget widget; name = (char *) client_data; widget = get_widget_by_name(w, "BxUnmanageCB", name); XtUnmanageChild(widget); }
void filehist_menu_refresh(void) { Widget menu; /* Don't report an error here, since "filehist_pullright" is only created on-demand when user clicks on menu, but this may be called before from the event loop. (The menu will still contain this entry when it's created later.) */ if (get_widget_by_name(&menu, globals.widgets.top_level, "filehist_pullright", False)) { update_menu_labels(menu); } }
void update_preferences_tooltips(void) { Widget shell; Widget statusline_b, popup_b, label1, text, label2; if (resource.toolbar_unusable) return; if (get_widget_by_name(&shell, globals.widgets.top_level, Xdvi_PREFS_DIALOG_NAME, True) && get_widget_by_name(&statusline_b, shell, Xdvi_TIPS_STATUSLINE, True) && get_widget_by_name(&popup_b, shell, Xdvi_TIPS_POPUPS, True) && get_widget_by_name(&label1, shell, Xdvi_TIPS_DELAY_LABEL1, True) && get_widget_by_name(&text, shell, Xdvi_TIPS_DELAY_TEXT, True) && get_widget_by_name(&label2, shell, Xdvi_TIPS_DELAY_LABEL2, True)) { char buf[LENGTH_OF_INT]; SNPRINTF(buf, LENGTH_OF_INT, "%d", ABS(resource.tooltips_wait_period)); XtVaSetValues(text, XmNvalue, buf, NULL); XmToggleButtonGadgetSetState(statusline_b, resource.tooltips_in_statusline, False); XmToggleButtonGadgetSetState(popup_b, resource.show_tooltips, False); XtSetSensitive(label1, resource.show_tooltips); XtSetSensitive(text, resource.show_tooltips); XtSetSensitive(label2, resource.show_tooltips); } }
/* * Callback for cancel button in choice_dialog. */ static void cancel_action(Widget w, XtPointer client_data, XtPointer call_data) { XtPointer p; ptrdiff_t idx = -1; UNUSED(call_data); #if MOTIF /* for motif, the index is in XmNuserData */ UNUSED(client_data); if (strcmp(XtName(w), Xdvi_MESSAGE_SHELL_NAME) == 0) { /* invoked by the WM, get the messagebox child */ Widget child; if (get_widget_by_name(&child, w, Xdvi_MESSAGE_DIALOG_NAME, True)) { XtVaGetValues(child, XmNuserData, &p, NULL); idx = (ptrdiff_t)p; } } else { XtVaGetValues(w, XmNuserData, &p, NULL); idx = (ptrdiff_t)p; } ASSERT(idx >= 0, "Couldn't get idx from XmNuserData!"); #else UNUSED(p); UNUSED(w); idx = (ptrdiff_t)client_data; #endif ASSERT(idx >= 0 && idx < MAX_POPUPS, "Invalid widget index in cancel_action()"); /* First call pre_message_cb with window widget ID * as additional parameter. */ if (pre_callbacks[idx].callback != NULL) { pre_callbacks[idx].callback(popup_window[idx], pre_callbacks[idx].arg); } /* Then pop down window and mark its position as free, then * invoke the OK callback. The reason for this is that the callback * may need to wait for open windows. */ XtPopdown(popup_window[idx]); XtDestroyWidget(popup_window[idx]); g_popup_array[idx] = 0; XSync(DISP, True); /* invoke the callback if present */ if (cancel_callbacks[idx].callback != NULL) { cancel_callbacks[idx].callback(cancel_callbacks[idx].arg); } }
void newDocCB( Widget w, XtPointer client_data, XtPointer call_data) { Widget widget; widget = get_document_text(w, "newDocCB"); XmTextSetString(widget, ""); widget = get_widget_by_name(w, "newDocCB", "lineTextField"); XmTextFieldSetString(widget, ""); update_message(w, "newDocCB", "Created new empty file."); set_save_path(NULL); set_been_saved(False); update_document_linecount(w, "newDocCB"); update_window_title(w, "newDocCB"); }
void statusBarToggleCB( Widget w, XtPointer client_data, XtPointer call_data) { Widget widget; XmToggleButtonCallbackStruct *cbs; cbs = (XmToggleButtonCallbackStruct *)call_data; widget = get_widget_by_name(w, "statusBarToggleCB", "statusBar"); switch (cbs->set) { case XmSET: XtManageChild(widget); break; default: XtUnmanageChild(widget); break; } }
static Boolean revert_colors(Pixel fg, Pixel bg, Pixel hl) { XColor color_data[2]; Boolean need_redraw = False; Widget button; Pixel visited, unvisited; color_data[0].pixel = resource.fore_Pixel; color_data[1].pixel = resource.back_Pixel; str_to_pixel(globals.widgets.top_level, resource.visited_link_color, &visited); str_to_pixel(globals.widgets.top_level, resource.link_color, &unvisited); XQueryColors(DISP, G_colormap, color_data, 2); if (fg != resource.fore_Pixel) { XGCValues values; fg_initial.r = color_data[0].red; fg_initial.g = color_data[0].green; fg_initial.b = color_data[0].blue; values.foreground = resource.rule_pixel = resource.fore_Pixel; XChangeGC(DISP, globals.gc.ruler, GCForeground, &values); scanned_page = scanned_page_color = scanned_page_reset; update_button_by_name(resource.fore_Pixel, Xdvi_FG_COLOR_BTN); need_redraw = True; } if (bg != resource.back_Pixel) { bg_initial.r = color_data[1].red; bg_initial.g = color_data[1].green; bg_initial.b = color_data[1].blue; scanned_page = scanned_page_color = scanned_page_reset; update_button_by_name(resource.back_Pixel, Xdvi_BG_COLOR_BTN); need_redraw = True; } if (hl != resource.hl_Pixel) { XGCValues values; values.foreground = resource.hl_Pixel; XChangeGC(DISP, globals.gc.high, GCForeground, &values); /* hack to update match GC: fake change in inverted property, redraw so that GC is cleared, then change inverted property back */ resource.match_highlight_inverted = !resource.match_highlight_inverted; search_draw_inverted_regions(); resource.match_highlight_inverted = !resource.match_highlight_inverted; update_button_by_name(resource.hl_Pixel, Xdvi_HL_COLOR_BTN); need_redraw = True; } /* NOTE: pixels for hyperlinks are not stored anywhere; just update always: */ if (get_widget_by_name(&button, globals.widgets.top_level, Xdvi_VISITED_LINKS_BTN, True)) { update_button(button, visited); h_update_hyperlinks(button, visited); /* this already triggers a redraw */ } if (get_widget_by_name(&button, globals.widgets.top_level, Xdvi_UNVISITED_LINKS_BTN, True)) { update_button(button, unvisited); h_update_hyperlinks(button, unvisited); /* this already triggers a redraw */ } return need_redraw; }