static void revert_prefs_cb(XtPointer arg) { struct topic_info *info = (struct topic_info *)arg; struct prefs_choice *prefs = (struct prefs_choice *)info->data; size_t i; /* pop down dependent windows */ TRACE_GUI((stderr, "window count: %lu", (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, or prefs not changed */ return; } revert_resources(); XrmDestroyDatabase(prefs->db); prefs->db = NULL; }
void ImageFunctionsView::SetImageDebugInfo(ImageDebugInfo* imageDebugInfo) { if (imageDebugInfo == fImageDebugInfo) return; TRACE_GUI("ImageFunctionsView::SetImageDebugInfo(%p)\n", imageDebugInfo); if (fImageDebugInfo != NULL) fImageDebugInfo->ReleaseReference(); fImageDebugInfo = imageDebugInfo; if (fImageDebugInfo != NULL) fImageDebugInfo->AcquireReference(); fFunctionsTableModel->SetImageDebugInfo(fImageDebugInfo); // If there's only one source file (i.e. "no source file"), expand the item. if (fImageDebugInfo != NULL && fFunctionsTableModel->CountSourceFiles() == 1) { TreeTablePath path; path.AddComponent(0); fFunctionsTable->SetNodeExpanded(path, true, false); } if (fImageDebugInfo != NULL) fFunctionsTable->ResizeAllColumnsToPreferred(); TRACE_GUI("ImageFunctionsView::SetImageDebugInfo(%p) done\n", imageDebugInfo); }
void ImageListView::SetImage(Image* image) { if (image == fImage) return; TRACE_GUI("ImageListView::SetImage(%p)\n", image); if (fImage != NULL) fImage->ReleaseReference(); fImage = image; if (fImage != NULL) { fImage->AcquireReference(); for (int32 i = 0; Image* other = fImagesTableModel->ImageAt(i); i++) { if (fImage == other) { fImagesTable->SelectRow(i, false); TRACE_GUI("ImageListView::SetImage() done\n"); return; } } } fImagesTable->DeselectAllRows(); TRACE_GUI("ImageListView::SetImage() done\n"); }
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 toggle_statusline(void) { #ifdef MOTIF if ((resource.expert_mode & XPRT_SHOW_STATUSLINE) == 0) XtUnmanageChild(statusline); else XtManageChild(statusline); set_menu(&resource.expert_mode, Act_set_expert_mode, check_resource_expert); #else static Boolean initialized = False; static Boolean statusline_mapped = False; Boolean make_statusline_visible = False; Boolean make_statusline_invisible = False; if (!initialized) { statusline_mapped = (resource.expert_mode & XPRT_SHOW_STATUSLINE) != 0; initialized = True; } if ((resource.expert_mode & XPRT_SHOW_STATUSLINE) == 0) { if (statusline_mapped) make_statusline_invisible = True; } else { if (!statusline_mapped) make_statusline_visible = True; } if (make_statusline_invisible) { XtDestroyWidget(statusline); statusline_mapped = False; } if (make_statusline_visible) { static Dimension window_w, window_h; static Arg arg_wh[] = { {XtNwidth, (XtArgVal) &window_w}, {XtNheight, (XtArgVal) &window_h}, }; #ifdef MOTIF XtGetValues(globals.widgets.main_window, arg_wh, XtNumber(arg_wh)); #else XtGetValues(globals.widgets.vport_widget, arg_wh, XtNumber(arg_wh)); #endif XtVaSetValues(globals.widgets.vport_widget, XtNresizable, (XtArgVal)True, NULL); TRACE_GUI((stderr, "statusline: w %d, h %d", window_w, window_h)); XtVaSetValues(globals.widgets.vport_widget, XtNwidth, (XtArgVal)window_w, XtNheight, (XtArgVal)window_h, NULL); TRACE_GUI((stderr, "after statusline")); create_statusline(); statusline_mapped = True; } #endif /* MOTIF */ }
/* helper routine for get_matching_parent() */ static Widget matches_parent(Widget w, const char *name) { for (; w != NULL; w = XtParent(w)) { char *ptr; ptr = XtName(w); TRACE_GUI((stderr, "parent: %s", ptr == NULL ? "<NULL>" : ptr)); if (ptr != NULL && strcmp(ptr, name) == 0) { /* found */ TRACE_GUI((stderr, "match!")); break; } } TRACE_GUI((stderr, "returning: %p (0x%lx)", (void *)w, w ? XtWindow(w) : 0)); return w; }
/* Position window w at coordinates x, y */ void position_window(Widget w, Position x, Position y) { if (!XtIsRealized(w)) return; TRACE_GUI((stderr, "positioning %ld at %d, %d", (unsigned long)w, x, y)); XtVaSetValues(w, XtNx, x, XtNy, y, NULL); }
void TeamWindow::FunctionSourceCodeChanged(Function* function) { TRACE_GUI("TeamWindow::FunctionSourceCodeChanged(%p): source: %p, " "state: %d\n", function, function->GetSourceCode(), function->SourceCodeState()); PostMessage(MSG_FUNCTION_SOURCE_CODE_CHANGED); }
int xm_get_width(Widget w) { int ret_w = 0; static Arg args = { XtNwidth, (XtArgVal)0 }; ASSERT(w != NULL, "widget in xm_get_width mustn't be NULL!"); args.value = (XtArgVal)&ret_w; XtGetValues(w, &args, 1); TRACE_GUI((stderr, "xm_get_width: %d", ret_w)); return ret_w; }
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 ImageFunctionsView::SetFunction(FunctionInstance* function) { TRACE_GUI("ImageFunctionsView::SetFunction(%p)\n", function); TreeTablePath path; if (fFunctionsTableModel->GetFunctionPath(function, path)) { fFunctionsTable->SetNodeExpanded(path, true, true); fFunctionsTable->SelectNode(path, false); fFunctionsTable->ScrollToNode(path); } else fFunctionsTable->DeselectAllNodes(); }
void TeamWindow::_HandleImageDebugInfoChanged(image_id imageID) { TRACE_GUI("TeamWindow::_HandleImageDebugInfoChanged(%ld)\n", imageID); // We're only interested in the currently selected thread if (fActiveImage == NULL || imageID != fActiveImage->ID()) return; AutoLocker< ::Team> locker(fTeam); ImageDebugInfo* imageDebugInfo = fActiveImage != NULL ? fActiveImage->GetImageDebugInfo() : NULL; TRACE_GUI(" image debug info: %p\n", imageDebugInfo); BReference<ImageDebugInfo> imageDebugInfoReference(imageDebugInfo); // hold a reference until we've set it locker.Unlock(); fImageFunctionsView->SetImageDebugInfo(imageDebugInfo); }
int xm_get_height(Widget w) { int ret_h = 0; static Dimension h0, h1, h2; static Arg args[] = { {XmNheight, (XtArgVal) &h0}, {XmNmarginHeight, (XtArgVal) &h1}, {XmNshadowThickness, (XtArgVal) &h2}, }; ASSERT(w != NULL, "widget in xm_get_width mustn't be NULL!"); XtGetValues(w, args, XtNumber(args)); ret_h = h0 + 2 * h1 + 2 * h2; TRACE_GUI((stderr, "xm_get_height: %d", ret_h)); return ret_h; }
static void filehist_select_cb(Widget w, XtPointer client_data, XtPointer call_data) { char *label, *ptr; int idx; UNUSED(client_data); UNUSED(call_data); XtVaGetValues(w, XtNlabel, &label, NULL); idx = strtol(label, &ptr, 10) - 1; while (isspace((unsigned char)*ptr)) ptr++; TRACE_GUI((stderr, "User selected: %d, `%s'", idx, ptr)); if (idx == 0) { globals.ev.flags |= EV_RELOAD; return; } file_history_open(ptr); }
static void update_menu_labels(Widget menu) { WidgetList children; int num_children; int i; static char *buf = NULL; static size_t buf_len = 0; size_t new_len; XtVaGetValues(menu, XtNnumChildren, &num_children, XtNchildren, &children, NULL); for (i = 0; i < (int)file_history_size(); i++) { int dummy_page; char *filename; if ((filename = file_history_get_elem(i, &dummy_page)) == NULL) { XDVI_ERROR((stderr, "Error accessing element %d of file history", i)); continue; } new_len = LENGTH_OF_INT + strlen(filename) + 1; if (new_len > buf_len) { buf = xrealloc(buf, new_len); buf_len = new_len; } sprintf(buf, "%d %s", i + 1, filename); XtVaSetValues(children[i], XtNlabel, buf, NULL); TRACE_GUI((stderr, "child %d: `%s'", i, buf)); } /* if history size < number of menu entries, destroy excess menu entries */ for (; i < num_children; i++) { XtDestroyWidget(children[i]); } }
/* Acutally pop up the pullright menu */ static void popup_pullright(XtPointer client_data, XtIntervalId *id) { int pos_x, pos_y; Dimension w1; Window dummy; static Widget files_submenu = NULL; struct pullright_position_info *info = (struct pullright_position_info *)client_data; UNUSED(id); if (files_submenu == NULL) files_submenu = create_files_submenu(); /* XtManageChild(files_submenu); */ XTranslateCoordinates(DISP, XtWindow(XtParent(m_submenu)), RootWindowOfScreen(SCRN), info->w, info->y, &pos_x, &pos_y, &dummy); XtRealizeWidget(files_submenu); XtVaGetValues(files_submenu, XtNwidth, &w1, NULL); TRACE_GUI((stderr, "Popping up at %d, %d, %d, %d", pos_x, pos_y, w1, WidthOfScreen(SCRN))); /* if not sufficient place on the right, pop it up on the left */ /* fprintf(stderr, "border_width: %d\n", info->border_width); */ if (pos_x + w1 > WidthOfScreen(SCRN)) { /* fprintf(stderr, "%d > %d!\n", pos_x + w1, WidthOfScreen(SCRN)); */ pos_x -= (w1 + info->w + 3 * info->border_width); /* fprintf(stderr, "new x: %d\n", pos_x); */ } else { pos_x += info->border_width; } XtVaSetValues(files_submenu, XtNx, pos_x, XtNy, pos_y, NULL); /* use XtPopupSpringLoaded() instead of XtPopup() since it does a few things that make the pullright behave like a proper menu, like highlighting the current selection, setting the cursor shape etc. */ XtPopupSpringLoaded(files_submenu); m_active_submenu = files_submenu; }
/* Traverse widget hieararchy upwards until a widget matches a name in the (NULL-terminated) list fmt, or Widget d (`default') if none is found. */ Widget get_matching_parent(Widget w, Widget d, const char *fmt, ...) { Widget parent = d; const char *str = fmt; va_list argp; va_start(argp, fmt); TRACE_GUI((stderr, "get_matching_parent of %p (0x%lx)", (void *)w, XtWindow(w))); while (str != NULL) { Widget p; if ((p = matches_parent(w, str)) != NULL) { parent = p; break; } str = va_arg(argp, char *); } va_end(argp); return parent; }
/* * Read the user preferences from xdvirc_filename and merge them into the * current resource database *and* into m_user_db so that all of them are * saved again when xdvi exits. */ void read_user_preferences(Widget toplevel, const char *filename) { char *fullpath; XrmDatabase db; #if XtSpecificationRelease == 4 XrmDatabase file_db; #endif fullpath = get_xdvirc_path(filename); TRACE_GUI((stderr, "Reading resources from `%s'", fullpath)); db = XtDatabase(XtDisplay(toplevel)); #if XtSpecificationRelease == 4 file_db = XrmGetFileDatabase(fullpath); XrmMergeDatabases(file_db, &db); XrmMergeDatabases(file_db, &m_user_db); #else /* Xt >= X11R5 */ XrmCombineFileDatabase(fullpath, &db, True); XrmCombineFileDatabase(fullpath, &m_user_db, True); #endif free(fullpath); }
static void save_geometry(void) { int x_off, y_off; Dimension w, h; Window dummy; /* char *geom_str; */ (void)XTranslateCoordinates(DISP, XtWindow(globals.widgets.top_level), RootWindowOfScreen(SCRN), 0, 0, &x_off, &y_off, &dummy); XtVaGetValues(globals.widgets.top_level, XtNwidth, &w, XtNheight, &h, #ifdef MOTIF /* XmNgeometry, &geom_str, */ #endif NULL); TRACE_GUI((stderr, "geometry: %dx%d+%d+%d", w, h, x_off, y_off)); store_preference(NULL, "windowSize", "%dx%d", w, h); }
static void filehist_insert_submenu(int idx, const char *filename, int pageno, void *data) { Widget menu = (Widget)data; Widget w; static char *buf = NULL; static size_t buf_len = 0; size_t new_len = LENGTH_OF_INT + strlen(filename) + 1; UNUSED(pageno); if (new_len > buf_len) { buf = xrealloc(buf, new_len); buf_len = new_len; } sprintf(buf, "%d %s", idx + 1, filename); TRACE_GUI((stderr, "Creating menu `%s'", buf)); w = XtVaCreateManagedWidget("_filehist", smeBSBObjectClass, menu, XtNlabel, buf, XtNleftMargin, 10, NULL); XtAddCallback(w, XtNcallback, filehist_select_cb, NULL); }
/* * Merge the resource `name' with a value specified by `fmt' into * the database `db' (if db == NULL, use m_user_db). */ void store_preference(XrmDatabase *db, const char *name, const char *fmt, ...) { size_t offset = strlen("xdvi."); size_t name_len = strlen(name); char *name_buf = xmalloc(name_len + offset + 1); char *buf = NULL; XrmDatabase tmp_db = NULL; if (db == NULL) db = &m_user_db; XDVI_GET_STRING_ARGP(buf, fmt); memcpy(name_buf, "xdvi.", offset); strcpy(name_buf + offset, name); TRACE_GUI((stderr, "storing resource: `%s: %s'", name_buf, buf)); XrmPutStringResource(&tmp_db, name_buf, buf); XrmMergeDatabases(tmp_db, db); free(buf); free(name_buf); }
/* * Create a toolbar with buttons, return toolbar widget. */ Widget create_toolbar(Widget parent, Widget menu_bar) { #if HAVE_XPM size_t alloc_len = 0, n; size_t alloc_step = 16; const char *c_ptr, *e_ptr; #endif /* HAVE_XPM */ Widget tool_bar; resource.toolbar_unusable = False; tool_bar_frame = XtVaCreateWidget("toolBarFrame", xmFrameWidgetClass, parent, XmNshadowType, XmSHADOW_OUT, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, menu_bar, NULL); tool_bar = XtVaCreateManagedWidget("toolBar", xmRowColumnWidgetClass, tool_bar_frame, XmNchildType, XmFRAME_WORKAREA_CHILD, XmNrowColumnType, XmWORK_AREA, XmNorientation, XmHORIZONTAL, XmNtraversalOn, False, XmNisHomogeneous, False, XmNpacking, XmPACK_TIGHT, XmNspacing, 0, /* override to use SEPARATOR(n) instead */ XmNadjustLast, True, NULL); #if HAVE_XPM /* parse toolbar_translations, create the widgets and assign the actions */ for (n = 0, c_ptr = resource.toolbar_translations; c_ptr != NULL && *c_ptr != '\0'; c_ptr = e_ptr, n++) { char **line_items = NULL; int extra_space; size_t len, curr, item_count = 0; if ((e_ptr = strchr(c_ptr, '\n')) == NULL /* ... and in case last line doesn't end with \n ... */ && (e_ptr = strchr(c_ptr, '\0')) == NULL) { break; } if (e_ptr == c_ptr) { XDVI_WARNING((stderr, "Skipping empty line in toolbarTranslations resource.")); e_ptr++; continue; } len = e_ptr - c_ptr; TRACE_GUI((stderr, "LEN %lu: |%.*s|", (unsigned long)len, (int)len, c_ptr)); line_items = split_line(c_ptr, SEP_CHAR, 0, len, &item_count); if (globals.debug & DBG_GUI) { int k; for (k = 0; line_items[k] != NULL; k++) { fprintf(stderr, "ITEM %d of %lu: |%s|\n", k, (unsigned long)item_count, line_items[k]); } } while (alloc_len <= n + 1) { alloc_len += alloc_step; toolbar_buttons = xrealloc(toolbar_buttons, alloc_len * sizeof *toolbar_buttons); } if (item_count == 1 && sscanf(line_items[0], "SPACER(%d)", &extra_space) == 1) { TRACE_GUI((stderr, "creating spacer of witdh %d at %lu", extra_space, (unsigned long)n)); create_toolbar_separator(tool_bar, &(toolbar_buttons[n].button), extra_space); toolbar_buttons[n].type = TB_SEPARATOR; } else if (item_count == 4) { Pixmap sens, insens; int idx = strtoul(line_items[0], (char **)NULL, 10); struct xdvi_action *action; sens = insens = 0; /* make compiler happy ... */ TRACE_GUI((stderr, "creating pixmap at %d", idx)); if (!create_pixmap(tool_bar, idx, &sens, &insens)) { free(toolbar_buttons); toolbar_buttons = NULL; break; } TRACE_GUI((stderr, "creating button %ld", (unsigned long)n)); if (!create_toolbar_button(tool_bar, &(toolbar_buttons[n].button), &sens, &insens)) { free(toolbar_buttons); toolbar_buttons = NULL; break; } toolbar_buttons[n].type = TB_BUTTON; if (compile_action(line_items[3], &action)) { char *long_tooltip = xstrdup(line_items[1]); toolbar_buttons[n].tip = xstrdup(line_items[2]); /* char *short_tooltip = xstrdup(line_items[2]); */ command_call[0].closure = (XtPointer) action; /* eventually save this widget in list of `special' buttons that need to toggle between sensitive/insensitive */ button_info_save(action, toolbar_buttons[n].button); XtVaSetValues(toolbar_buttons[n].button, XmNactivateCallback, (XtArgVal)command_call, NULL); XtAddEventHandler(toolbar_buttons[n].button, EnterWindowMask | LeaveWindowMask, False, enter_leave, long_tooltip); } else { XDVI_WARNING((stderr, "Invalid action \"%s\" in toolbarTranslations resource:\n\"%.*s\"", line_items[3], (int)len, c_ptr)); } } else { XDVI_WARNING((stderr, "Skipping malformed line \"%.*s\" in toolbarTranslations resource " "(%lu instead of 4 items).", (int)len, c_ptr, (unsigned long)item_count)); toolbar_buttons[n].button = 0; } for (curr = 0; curr < item_count; curr++) { free(line_items[curr]); } free(line_items); line_items = NULL; if (*e_ptr != '\0') e_ptr++; } #else if ((resource.expert_mode & XPRT_SHOW_SCROLLBARS) != 0) { XDVI_WARNING((stderr, "This version has been compiled without XPM support. " "Disabling the toolbar, which needs XPM.")); } #endif /* HAVE_XPM */ if (toolbar_buttons == NULL) { resource.toolbar_unusable = True; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; } else { #if HAVE_XPM toolbar_buttons[n].button = 0; /* terminate info */ #endif } return tool_bar; }
static Boolean create_pixmap(Widget parent, int iconidx, Pixmap *sen, Pixmap *insen) { static Boolean first_time = True; static Window rootWindow; static XpmColorSymbol color[5] = { {"none", "none", 0}, {"iconColor1", NULL, 0}, {"bottomShadowColor", NULL, 0}, {"topShadowColor", NULL, 0}, {"selectColor", NULL, 0} }; static int screenNum; static Pixmap tools_map; static Pixmap tools_mask; static Pixmap shade_map; static Pixmap shade_mask; int status = 0; XpmAttributes attr; Pixmap map; Pixmap mask; static String pixmap_file_path = NULL; /* note: never free()d */ ASSERT(iconidx >= 0, "index must be positive"); if (first_time) { /* FIXME: We use a dummy window here to get the correct depth/visual for the pixmap creation (cant use globals.widgets.top_level since it's not realized yet and realizing it now would result in wrong dimensions) ... */ Widget dummy = XtVaAppCreateShell("xdvi", "Xdvi", transientShellWidgetClass, DISP, XtNdepth, G_depth, XtNvisual, G_visual, XtNcolormap, G_colormap, XtNmappedWhenManaged, False, NULL); XtRealizeWidget(dummy); /* note: doesn't pop it up */ rootWindow = XtWindow(dummy); screenNum = DefaultScreen(XtDisplay(globals.widgets.top_level)); ASSERT(rootWindow != 0, ""); XtVaGetValues(parent, XmNbackground, &color[BACKGROUND].pixel, XmNforeground, &color[FOREGROUND].pixel, XmNbottomShadowColor, &color[BOTTOM_SHADOW].pixel, XmNtopShadowColor, &color[TOP_SHADOW].pixel, XmNhighlightColor, &color[HIGHLIGHT].pixel, NULL); /* try to locate the XPM file with the toolbar pixmaps */ pixmap_file_path = XtResolvePathname(DISP, "pixmaps", resource.toolbar_pixmap_file, (String)NULL, /* suffix */ (String)NULL, /* use default path */ (Substitution)NULL, /* substitutions */ 0, /* number of substitutions */ (XtFilePredicate)NULL); /* return True iff file exists */ TRACE_GUI((stderr, "pixmap file search via XtResolvePathname: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { pixmap_file_path = (String)kpse_find_file(resource.toolbar_pixmap_file, kpse_program_text_format, 0); TRACE_GUI((stderr, "pixmap file search via kpse_find_file: %s => %s", resource.toolbar_pixmap_file, pixmap_file_path ? (char*)pixmap_file_path : "<NULL>")); if (pixmap_file_path == NULL) { TRACE_GUI((stderr, "No installed toolbar pixmap found, using built-in pixmap.")); } } } /* Setup the color subsititution table */ attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; /* Create the "sensitive" pixmap */ if (!tools_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &tools_map, &tools_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &tools_map, &tools_mask, &attr); } } else status = XpmSuccess; map = tools_map; mask = tools_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } XpmFreeAttributes(&attr); if (map != 0) { static GC back_gc, bots_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[BACKGROUND].pixel; back_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); gcvalues.foreground = color[BOTTOM_SHADOW].pixel; bots_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); /* Create the "sensitive" pixmap. */ *sen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *sen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx != -1) XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); else XCopyArea(XtDisplay(globals.widgets.top_level), map, *sen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); /* Create the "insensitive" pixmap. */ if (insen != NULL) { Pixmap map; Pixmap mask; attr.valuemask = XpmColorSymbols | XpmCloseness | XpmColorKey | XpmColormap | XpmDepth | XpmVisual; attr.closeness = 65535; /* accuracy isn't crucial */ attr.colorsymbols = color; attr.numsymbols = XtNumber(color); attr.color_key = XPM_MONO; attr.visual = G_visual; attr.colormap = G_colormap; attr.depth = G_depth; if (!shade_map) { if (pixmap_file_path != NULL) { status = XpmReadFileToPixmap(XtDisplay(globals.widgets.top_level), rootWindow, pixmap_file_path, &shade_map, &shade_mask, &attr); } else { status = XpmCreatePixmapFromData(XtDisplay(globals.widgets.top_level), rootWindow, (char **)toolbar_xpm, &shade_map, &shade_mask, &attr); } } else status = XpmSuccess; map = shade_map; mask = shade_mask; if (status == XpmSuccess) { static Pixmap tmp_mask; static GC gc; if (first_time) { tmp_mask = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, 1); gc = XCreateGC(XtDisplay(globals.widgets.top_level), tmp_mask, 0, NULL); } XCopyArea(XtDisplay(globals.widgets.top_level), mask, tmp_mask, gc, iconidx * PIXMAP_WIDTH, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT, 0, 0); mask = tmp_mask; } else { /* something went wrong */ popup_message(globals.widgets.top_level, MSG_ERR, "Something's wrong with your XPM file - " "try to load it into an image editor and fix the problem.", "Xpm error: %s - switching toolbar off.", XpmGetErrorString(status)); sen = insen = NULL; resource.expert_mode ^= XPRT_SHOW_TOOLBAR; return False; } if (mask != 0) { static GC tops_gc; if (first_time) { XGCValues gcvalues; gcvalues.foreground = color[TOP_SHADOW].pixel; tops_gc = XCreateGC(XtDisplay(globals.widgets.top_level), rootWindow, GCForeground, &gcvalues); } /* Need to create new Pixmaps with the mask applied. */ XSetClipMask(XtDisplay(globals.widgets.top_level), bots_gc, mask); XSetClipMask(XtDisplay(globals.widgets.top_level), tops_gc, mask); XSetClipOrigin(XtDisplay(globals.widgets.top_level), tops_gc, 1, 1); *insen = XCreatePixmap(XtDisplay(globals.widgets.top_level), rootWindow, PIXMAP_WIDTH, PIXMAP_HEIGHT, G_depth); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, back_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, tops_gc, 1, 1, PIXMAP_WIDTH - 1, PIXMAP_HEIGHT - 1); XFillRectangle(XtDisplay(globals.widgets.top_level), *insen, bots_gc, 0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT); if (iconidx == -1) XFreePixmap(XtDisplay(globals.widgets.top_level), map); } XpmFreeAttributes(&attr); } } first_time = False; return True; }
/* * Report dvips exit status, and remove temporary DVI file if needed. */ static void dvips_exited(int exitval, struct xchild *child) { char str[128] = ""; int ms; struct save_or_print_info *info = (struct save_or_print_info *)child->data; read_from_dvips(0, info); clear_io(&print_xio); (void)close(print_xio.fd); if (WIFEXITED(exitval)) { if (WEXITSTATUS(exitval) == 0) { if (info->act == FILE_SAVE || info->print_target == TO_FILE) { printlog_append_str(info, "\nCreated Postscript file "); printlog_append_str(info, info->finfo->out_file); printlog_append_str(info, ".\n"); } else { printlog_append_str(info, "Done.\n"); } /* remove temporary DVI file if it exists */ if (info->finfo->tmp_dvi_file != NULL) { if (globals.debug & DBG_GUI) TRACE_GUI((stderr, "NOT removing temporary DVI file: |%s|", info->finfo->tmp_dvi_file)); else { if (info->finfo->tmp_dvi_fp != NULL) { fclose(info->finfo->tmp_dvi_fp); info->finfo->tmp_dvi_fp = NULL; } unlink(info->finfo->tmp_dvi_file); info->finfo->tmp_dvi_file = NULL; } } } else sprintf(str, "\nDvips returned exit code %d.\n", WEXITSTATUS(exitval)); } else if (WIFSIGNALED(exitval)) sprintf(str, "\nDvips terminated by signal %d.\n", WTERMSIG(exitval)); else sprintf(str, "\nDvips returned unknown status 0x%x.\n", exitval); ms = resource.dvips_hang; if (str[0] != '\0') { xdvi_bell(); ms = resource.dvips_fail_hang; printlog_append_str(info, str); } if (ms > 0) { dvips_timer.data = info; set_timer(&dvips_timer, ms); dvips_status = DVIPS_STAT_WAIT; } else { dvips_status = DVIPS_STAT_NONE; } printlog_enable_closebutton(info); }
/* toggle scrollbars to state `visible' */ void toggle_scrollbars(void) { Widget v_bar = XtNameToWidget(globals.widgets.vport_widget, "vertical"); Widget h_bar = XtNameToWidget(globals.widgets.vport_widget, "horizontal"); static Dimension bar_thick; static Boolean v_bar_mapped = False, h_bar_mapped = False; static Boolean initialized = False; Boolean make_v_bar_visible = False; Boolean make_v_bar_invisible = False; Boolean make_h_bar_visible = False; Boolean make_h_bar_invisible = False; if (v_bar != 0) { int test_v = 0; XtVaGetValues(v_bar, XtNwidth, &test_v, NULL); if (test_v > 1) v_bar_mapped = True; } if (h_bar != 0) { int test_h = 0; XtVaGetValues(h_bar, XtNheight, &test_h, NULL); if (test_h > 1) h_bar_mapped = True; } if (!initialized) { v_bar_mapped = h_bar_mapped = (resource.expert_mode & XPRT_SHOW_SCROLLBARS) != 0; initialized = True; if (v_bar != 0) XtVaGetValues(v_bar, XtNwidth, &bar_thick, NULL); else if (h_bar != 0) XtVaGetValues(h_bar, XtNheight, &bar_thick, NULL); else bar_thick = 15; /* FIXME */ } if ((resource.expert_mode & XPRT_SHOW_SCROLLBARS) == 0) { if (v_bar_mapped) make_v_bar_invisible = True; if (h_bar_mapped) make_h_bar_invisible = True; } else { if (!v_bar_mapped) make_v_bar_visible = True; if (!h_bar_mapped) make_h_bar_visible = True; } if (make_h_bar_visible || make_v_bar_visible) { if (make_h_bar_visible && h_bar != 0) { TRACE_GUI((stderr, "h_bar: h %d", bar_thick)); XtVaSetValues(h_bar, XtNheight, bar_thick, XtNx, bar_thick, XtNy, 0, XtNborderWidth, 1, NULL); XtManageChild(h_bar); h_bar_mapped = True; } if (make_v_bar_visible && v_bar != 0) { TRACE_GUI((stderr, "v_bar: w %d", bar_thick)); XtVaSetValues(v_bar, XtNwidth, bar_thick, XtNx, 0, XtNy, bar_thick, XtNborderWidth, 1, NULL); XtManageChild(v_bar); v_bar_mapped = True; } if (h_bar != 0 || v_bar != 0) { /* need to reconfigure screen */ reconfig_window(); } } else if (make_h_bar_invisible || make_v_bar_invisible) { if (make_h_bar_invisible && h_bar != 0) { XtUnmanageChild(h_bar); XtVaSetValues(h_bar, XtNheight, 1, XtNx, 0, XtNy, 0, XtNborderWidth, 0, NULL); h_bar_mapped = False; } if (make_v_bar_invisible && v_bar != 0) { XtUnmanageChild(v_bar); XtVaSetValues(v_bar, XtNwidth, 1, XtNy, 0, XtNy, 0, XtNborderWidth, 0, NULL); v_bar_mapped = False; } if (h_bar != 0 || v_bar != 0) { /* need to reconfigure screen */ reconfig_window(); } } }
/* * This event handler (to be called by read_events(), the main event handling loop) * creates a timeout for the pullright to pop up. */ void SubMenuHandleEvent(XtAppContext app, XEvent *event) { static int flag = 0; static struct pullright_position_info info = { -1, 0, 0, 0, NULL }; UNUSED(app); if (m_submenu == NULL) return; if (event->type == EnterNotify || event->type == MotionNotify || event->type == LeaveNotify || event->type == ButtonPress) { /* fprintf(stderr, "SubMenuHandleEvent: 0x%lx, 0x%lx\n", event->xany.window, XtWindow(m_submenu)); */ /* Could also loop through a list of windows here ... We need to check for the parent of the menu item, since smeBSBObject is not a real window, and then manually check whether the pointer is inside the menu item. */ if (XtParent(m_submenu) != NULL && event->xany.window == XtWindow(XtParent(m_submenu))) { /* don't need to check for x coordinates since we already know that pointer is inside the parent */ if (info.y == -1) { /* initialize info */ XtVaGetValues(m_submenu, XtNy, &(info.y), XtNwidth, &(info.w), XtNheight, &(info.h), NULL); XtVaGetValues(XtParent(m_submenu), XtNborderWidth, &(info.border_width), NULL); info.menu = m_submenu; } if (info.y < event->xbutton.y && info.y + info.h > event->xbutton.y) { if (flag == 0) { /* Create a timeout of 200ms to pop up the menu, so that it doesn't pop up always when the cursor is only moved over the pulldown menu. I think this is about the same delay as the one used by Motif. */ flag = 1; TRACE_GUI((stderr, "ENTER: %d, %d, %d; %d, %d", info.y, info.w, info.h, event->xbutton.x, event->xbutton.y)); m_timeout = XtAppAddTimeOut(app, 200, popup_pullright, &info); return; } } else if (flag == 1) { flag = 0; TRACE_GUI((stderr, "LEAVE!")); if (m_timeout != 0) XtRemoveTimeOut(m_timeout); m_timeout = 0; if (m_active_submenu != NULL) XtPopdown(m_active_submenu); m_active_submenu = NULL; } } } }
/* Save user preferences to ~/.xdvirc. If `backup_only' is True, it only writes to ~/.xdvirc.tmp and does not remove this temporary file (this is used for synchronization between several xdvi instances). */ Boolean save_user_preferences(Boolean full_save) { char testbuf[1024]; char *xdvirc_name; char *tmpname; FILE *from_fp, *to_fp; int fd; if (resource.no_init_file || m_user_db == NULL) /* nothing to do */ return True; if (resource.remember_windowsize) save_geometry(); xdvirc_name = get_xdvirc_path(xdvirc_filename); if ((to_fp = fopen(xdvirc_name, "r")) != NULL) { TRACE_GUI((stderr, "~/.xdvirc exists, checking file contents ...")); if (fgets(testbuf, 1024, to_fp) != NULL && memcmp(testbuf, xdvirc_signature_line, strlen(xdvirc_signature_line)) != 0) { popup_message(globals.widgets.top_level, MSG_WARN, "Xdvi uses the file ~/.xdvirc to save the preferences set via " "the menu bar or the preferences dialog (in the Motif version only). " "To avoid overwriting files created by the user, the first line of the " "file is compared with a special signature line. If that signature line " "is not found, the preferences won't be written. Your file doesn't seem " "to contain that signature line. You should move the file to a safe location, " "and then try to quit xdvi again.", /* message */ "The file `%s' was apparently not written by xdvi(k). " "Please move or delete this file first, then try to exit xdvi again. ", xdvirc_name); return False; } fclose(to_fp); } /* don't use xdvi_temp_fd here, since XrmPutFileDatabase() closes the FILE*, creating a temp race */ tmpname = xstrdup(xdvirc_name); tmpname = xstrcat(tmpname, ".tmp"); /* since XrmPutFileDatabase doesn't give a useful error message if it fails, check that creating the file works beforehand. The file is created with 0600 permissions. */ if ((fd = try_open_mode(tmpname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", tmpname, strerror(errno))); return True; } close(fd); XrmPutFileDatabase(m_user_db, tmpname); if (full_save) { if ((from_fp = try_fopen(tmpname, "r")) == NULL) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for reading failed: %s", tmpname, strerror(errno))); return True; } /* again, create the file with 600 permissions */ if ((fd = try_open_mode(xdvirc_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) { XDVI_ERROR((stderr, "Could not save preferences!\nOpening %s for writing failed: %s", xdvirc_name, strerror(errno))); return True; } if ((to_fp = fdopen(fd, "w")) == NULL) { XDVI_ERROR((stderr, "Could not save preferences!\nfdopen for %s for writing failed: %s", xdvirc_name, strerror(errno))); return True; } if (fputs(xdvirc_signature_line, to_fp) == EOF || fputs(xdvirc_header, to_fp) == EOF || !copy_fp(from_fp, to_fp)) { XDVI_ERROR((stderr, "Could not save preferences!\nError writing to %s: %s", xdvirc_name, strerror(errno))); } fclose(from_fp); fclose(to_fp); } free(xdvirc_name); if (full_save) unlink(tmpname); free(tmpname); return True; }