Beispiel #1
0
/* Get a widget with `name' somewhere in the widget hierarchy below `parent'
   (matching is done against `*name') and return it in `ret'.
   If `report_error' is True, a warning message is popped up if the widget isn't found.
*/
Boolean
get_widget_by_name(Widget *ret, Widget parent, const char *name, Boolean report_error)
{
    char buf[1024];
    Widget test;

    /*      if (parent == 0 || !XtIsManaged(parent)) { */
    /*  	fprintf(stderr, "Widget %p not managed!\n", parent); */
    /*  	return False; */
    /*      } */
    
    if (strlen(name) > 1023) {
	popup_message(globals.widgets.top_level,
		      MSG_ERR,
		      REPORT_XDVI_BUG_TEMPLATE,
		      "Widget name `%s' too long, couldn't get parent", name);
	return False;
    }

    buf[0] = '*'; /* add wildcard to also match paths */
    strcpy(buf + 1, name);

    if ((test = XtNameToWidget(parent, buf)) != NULL) {
	*ret = test;
	return True;
    }
    else {
	if (report_error)
	    popup_message(globals.widgets.top_level,
			  MSG_ERR,
			  REPORT_XDVI_BUG_TEMPLATE,
			  "XtNameToWidget failed for `%s', parent `%s'", name, XtName(parent));
	return False;
    }
}
Beispiel #2
0
static void
accept_callback(Widget w,
                XtPointer client_data,
                XtPointer call_data)
{
    XmFileSelectionBoxCallbackStruct *fcb;
    struct filesel_callback *callback;

    UNUSED(w);

    ASSERT(client_data != NULL, "struct filesel_callback pointer expected in client data");
    callback = (struct filesel_callback *)client_data;

    /* get the filename from the file selection box */
    fcb = (XmFileSelectionBoxCallbackStruct *)call_data;
    if (callback->browse_fname != NULL) {
        XtFree(callback->browse_fname);
        callback->browse_fname = NULL;
    }
    XmStringGetLtoR(fcb->value, G_charset, &callback->browse_fname);

    if (0 && callback->must_exist) {
        FILE *tmp_fp = XFOPEN(callback->browse_fname, "r");
        dviErrFlagT errflag = NO_ERROR;
        if (tmp_fp == NULL) {
            popup_message(XtParent(callback->shell),
                          MSG_ERR, NULL, "Could not open %s: %s.\n",
                          callback->browse_fname, strerror(errno));
            /* leave file selection box open */
            return;
        }
        else if (!process_preamble(tmp_fp, &errflag)
                 || !find_postamble(tmp_fp, &errflag)
                 || !read_postamble(tmp_fp, &errflag, True
#if DELAYED_MKTEXPK
                                    , False
#endif
                                   )) {
            popup_message(XtParent(callback->shell),
                          MSG_ERR, NULL, "Error opening %s:\n%s.",
                          callback->browse_fname, get_dvi_error(errflag));
            fclose(tmp_fp);
            /* leave file selection box open */
            return;
        }
        else { /* file is OK */
            fclose(tmp_fp);
        }
    }

    /* success; close dialog, and call our callback */
    XtUnmanageChild(callback->shell);
    callback->func_ptr(callback->browse_fname, callback->data);
}
static void
gui_buttons_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);
    char *name = XtName(w);
    
    UNUSED(call_data);

    if (strcmp(name, Xdvi_GUI_STATUSLINE_STR) == 0) {
	resource.expert_mode ^= XPRT_SHOW_STATUSLINE;
	toggle_statusline();
	update_expert_mode();
    }
    else if (strcmp(name, Xdvi_GUI_TOOLBAR_STR) == 0) {
	resource.expert_mode ^= XPRT_SHOW_TOOLBAR;
	toggle_toolbar();
	update_expert_mode();
    }
    else if (strcmp(name, Xdvi_GUI_PAGELIST_STR) == 0) {
	resource.expert_mode ^= XPRT_SHOW_PAGELIST;
	toggle_pagelist();
	update_expert_mode();
    }
    else if (strcmp(name, Xdvi_GUI_SCROLLBARS_STR) == 0) {
#if defined(LESSTIF_VERSION)
	static Boolean warned_about_lesstif = False;
#endif
	resource.expert_mode ^= XPRT_SHOW_SCROLLBARS;
	toggle_scrollbars();
	update_expert_mode();
#if defined(LESSTIF_VERSION)
	if (!warned_about_lesstif) {
	    warned_about_lesstif = True;
	    popup_message(globals.widgets.top_level,
			  MSG_INFO,
			  NULL,
			  "This version has been compiled with LessTif; "
			  "toggling the scrollbars won't work with LessTif.");
	}
#endif
    }
    else {
	popup_message(globals.widgets.top_level,
		      MSG_ERR,
		      REPORT_XDVI_BUG_TEMPLATE,
		      "Unexpected label in gui buttons: |%s|!\n", name);
    }
    store_preference(&(prefs->db), "expertMode", "%d", resource.expert_mode);
}
Beispiel #4
0
/**
 * info:
 * @irrelevance: minimum verbosity level to output the message,
 * @format: format string for vprintf.
 *
 * Print the formatted message to standard output if verbosity is high
 * enough.
 **/
int
info (int         irrelevance,
      const char *format, ...)
{
    va_list ap;
    int     ret;

    if (verbosity >= irrelevance) {
        va_start (ap, format);
        if (cursed) {
            char msg[512];

            ret = vsnprintf (msg, sizeof (msg), format, ap);
            msg[sizeof (msg) - 1] = 0;

            popup_message (msg);
        } else {
            ret = vprintf (format, ap);
        }

        va_end (ap);
        return ret;
    } else {
        return 0;
    }
}
static void
help_action(Widget w, XtPointer client_data, XtPointer call_data)
{
    UNUSED(call_data);

    /* open another window with the help text */
    popup_message(get_matching_parent(w, globals.widgets.top_level,
	"message_popup", NULL), MSG_HELP, NULL, "%s", client_data);
}
Beispiel #6
0
void
unexpected_widget_in_callback(Widget w, const char *callback)
{
    ASSERT(w != NULL, "Widget mustn't be NULL!");
    popup_message(globals.widgets.top_level,
		  MSG_ERR,
		  REPORT_XDVI_BUG_TEMPLATE,
		  "Unexpected widget `%s' in callback `%s'",
		  XtName(w), callback);
}
Beispiel #7
0
static void
search_callback(Widget w,
		XtPointer client_data,
		XmAnyCallbackStruct *call_data)
{
    UNUSED(w);
    UNUSED(client_data);
    UNUSED(call_data);
    
    popup_message(globals.widgets.top_level,
		  MSG_ERR, NULL, "Sorry, not yet implemented");
}
Beispiel #8
0
Datei: FED.C Projekt: MegaGod/TW
void help_select( void ) {
	static char *select_menu[] = {
		"Select font Menu",
		"Arrow key to move cursor",
		"<Ins> to insert a blank character",
		"<Del> to delete character",
		"'O' to OR first char with the seconds",
		"<ESC> to exit",
		0
	};
	popup_message( select_menu );
}
/* Check if selecting pages worked, report error else */
static Boolean
select_pages_report_error(const struct save_or_print_info *info)
{
    if (info->pinfo->errflag == NO_ERROR)
	return False;
    
    popup_message(globals.widgets.top_level,
		  MSG_INFO,
		  NULL,
		  "Could not save DVI file to %s: %s.",
		  info->finfo->tmp_dvi_file,
		  get_dvi_error(info->pinfo->errflag));
    return True;
}
Beispiel #10
0
Datei: FED.C Projekt: MegaGod/TW
void help( void ) {
	static char *editing_menu[] = {
		"Editing Menu",
		"<ESC> to exit and make change",
		"<Insert> to toggle dot,undot",
		"<M>irror  <I>nvert",
		"<U>ndo",
		"<R>ow insert <E>rase row",
		"<C>olumninsert <D>eletecolumn",
		"'.' change mode",
		"Arrow key to move cursor",
		"Shift+Arrow key", 0 };
	popup_message( editing_menu );
}
Beispiel #11
0
void
popup_preferences_dialog(Widget parent, int arg)
{
    static Widget preferences_shell = 0;
    static struct topic_info info;
    static struct topic_item items[NUM_PREFS_TOPICS];
    static struct prefs_choice *prefs = NULL;

    if (preferences_shell == 0) { /* called 1st time; create widget */
	info.ok_callback = apply_prefs_cb;
	info.cancel_callback = revert_prefs_cb;
	info.items = items;
	/* 	info.items_size = NUM_PREFS_TOPICS; */

	prefs = xmalloc(sizeof *prefs);
	prefs->depwin_cnt = 0;
	prefs->depwin = NULL;
	/* 	prefs->orig = orig_prefs; */
	/* apply_prefs_cb/revert_prefs_cb are responsible for copying
	   the changed preferences into the current preferences as
	   appropriate, and free()ing prefs.changed */
	/* 	prefs->changed = xmalloc(sizeof *(prefs->changed)); */
	/* 	copy_resources(orig_prefs, prefs->changed); */
	prefs->db = NULL; /*  XrmGetStringDatabase(""); */
	info.data = prefs;
	
	preferences_shell = create_topic_window(parent,
						"xdvik: Preferences",
						Xdvi_PREFS_DIALOG_NAME,
						&info,
						initialize_items,
						"OK", "Cancel");
	info.shell = preferences_shell;
	center_window(preferences_shell, parent);
	select_topic(&info, 0);
    }

    if (arg >= 0)
	select_topic(&info, arg);
    
    XtPopup(preferences_shell, XtGrabNone);

    if (resource.no_init_file) {
	popup_message(preferences_shell,
		      MSG_WARN,
		      NULL,
		      "You specified the resource `noInitFile' or the `-q' command-line option. "
		      "Any preferences that you set in this dialog will be lost when you exit xdvi.");
    }
}
Beispiel #12
0
void
warn_overstrike(void)
{
    static Boolean warned_overstrike = False;

    if (!warned_overstrike) {
	popup_message(globals.widgets.top_level,
		      MSG_WARN,
		      /* helptext */
		      "Greyscaling is running in copy mode; this will cause overstrike characters to "
		      "appear incorrectly, and may result in poor display quality.  "
		      "Possible fixes are:\n"
		      "- Use the ``-thorough'' command-line option.\n"
		      "- Quit some other color-hungry applications (e.g. Netscape).\n"
		      "- Use the ``-install'' command-line option.\n"
		      "See the section ``GREYSCALING AND COLORMAPS'' in the "
		      "xdvi manual page for more details.",
		      /* text */
		      "Couldn't allocate enough colors - expect low display quality.");
	warned_overstrike = True;
    }
}
Beispiel #13
0
/* 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;
}
Beispiel #14
0
/* How to use me correctly */
int usage(int ret) {
  if (GetConsoleWindow()) print_message(stderr, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_CONFIGURATION, NSSM_DATE);
  else popup_message(0, MB_OK, NSSM_MESSAGE_USAGE, NSSM_VERSION, NSSM_CONFIGURATION, NSSM_DATE);
  return(ret);
}
Beispiel #15
0
void check_and_transmit_messages(time_t time) {
    int i;
    char temp[200];
    char to_call[40];


    // Skip this function if we did it during this second already.
    if (last_check_and_transmit == time) {
        return;
    }
    last_check_and_transmit = time;

    for (i=0; i<MAX_OUTGOING_MESSAGES;i++) {
        if (message_pool[i].active==MESSAGE_ACTIVE) {
            if (message_pool[i].wait_on_first_ack!=1) { // Tx only if 0
                if (message_pool[i].active_time < time) {
                    char *last_ack_ptr;
                    char last_ack[5+1];


                    if (message_pool[i].tries < MAX_TRIES) {
                        char new_path[MAX_LINE_SIZE+1];

 
                        /* sending message let the tnc and net transmits check to see if we should */
                        if (debug_level & 2)
                            fprintf(stderr,
                                "Time %ld Active time %ld next time %ld\n",
                                (long)time,
                                (long)message_pool[i].active_time,
                                (long)message_pool[i].next_time);

                        if (debug_level & 2)
                            fprintf(stderr,"Send message#%d to <%s> from <%s>:%s-%s\n",
                                message_pool[i].tries,
                                message_pool[i].to_call_sign,
                                message_pool[i].from_call_sign,
                                message_pool[i].message_line,
                                message_pool[i].seq);

                        pad_callsign(to_call,message_pool[i].to_call_sign);

                        // Add Leading ":" as per APRS Spec.
                        // Add trailing '}' to signify that we're
                        // Reply/Ack protocol capable.
                        last_ack_ptr = get_most_recent_ack(to_call);
                        if (last_ack_ptr != NULL)
                            xastir_snprintf(last_ack,
                                sizeof(last_ack),
                                "%s",
                                last_ack_ptr);
                        else
                            last_ack[0] = '\0';
                        
                        xastir_snprintf(temp, sizeof(temp), ":%s:%s{%s}%s",
                                to_call,
                                message_pool[i].message_line,
                                message_pool[i].seq,
                                last_ack);

                        if (debug_level & 2)
                            fprintf(stderr,"MESSAGE OUT>%s<\n",temp);


                        // Check for a custom path having been set
                        // in the Send Message dialog.  If so, use
                        // this for our outgoing path instead and
                        // reset all of the queued message paths to
                        // this station to this new path.
                        //
                        get_send_message_path(to_call,
                            new_path,
                            sizeof(new_path));

//fprintf(stderr,"get_send_message_path(%s) returned: %s\n",to_call,new_path);
 
                        if (new_path[0] != '\0'
                                && strcmp(new_path,message_pool[i].path) != 0) {

                            // We have a custom path set which is
                            // different than the path saved with
                            // the outgoing message.
                            //
                            // Change all messages to that callsign
                            // to match the new path.
                            //
                            change_path_outgoing_messages_to(to_call,new_path);
                        }


                        // Transmit the message
                        transmit_message_data(message_pool[i].to_call_sign,
                            temp,
                            message_pool[i].path);


                        message_pool[i].active_time = time + message_pool[i].next_time;

                        //fprintf(stderr,"%d\n",(int)message_pool[i].next_time);
                    }

/*
fprintf(stderr,
    "Msg Interval = %3ld seconds or %4.1f minutes\n",
    message_pool[i].next_time,
    message_pool[i].next_time / 60.0);
*/

                    // Record the interval we're using.  Put it with
                    // the message in the general message pool, so
                    // that the Send Message dialog can display it.
                    // It will only display it if the message is
                    // actively being transmitted.  If it has been
                    // cancelled, timed out, or hasn't made it to
                    // the transmit position yet, it won't be shown.
                    //
                    msg_record_interval_tries(message_pool[i].to_call_sign,
                        message_pool[i].from_call_sign,
                        message_pool[i].seq,
                        message_pool[i].next_time,  // Interval
                        message_pool[i].tries);     // Tries

                    // Start at 7 seconds for the interval.  We set
                    // it to 7 seconds in output_message() above.
                    // Double the interval each retry until we hit
                    // 10 minutes.  Keep transmitting at 10 minute
                    // intervals until we hit MAX_TRIES.

                    // Double the interval between messages
                    message_pool[i].next_time = message_pool[i].next_time * 2;

                    // Limit the max interval to 10 minutes
                    if (message_pool[i].next_time > (time_t)600l)
                        message_pool[i].next_time = (time_t)600l;

                    message_pool[i].tries++;

                    // Expire it if we hit the limit
                    if (message_pool[i].tries > MAX_TRIES) {
                        char temp[150];
                        char temp_to[20];

                        xastir_snprintf(temp,sizeof(temp),"To: %s, Msg: %s",
                            message_pool[i].to_call_sign,
                            message_pool[i].message_line);
                        //popup_message(langcode("POPEM00004"),langcode("POPEM00017"));
                        popup_message( "Retries Exceeded!", temp );

                        // Fake the system out: We're pretending
                        // that we got an ACK back from it so that
                        // we can either release the next message to
                        // go out, or at least make the send button
                        // sensitive again.
                        // We need to copy the to_call_sign into
                        // another variable because the
                        // clear_acked_message() function clears out
                        // the message then needs this parameter to
                        // do another compare (to enable the Send Msg
                        // button again).
                        xastir_snprintf(temp_to,
                            sizeof(temp_to),
                            "%s",
                            message_pool[i].to_call_sign);

                        // Record a fake ack and add "*TIMEOUT*" to
                        // the message.  This will be displayed in
                        // the Send Message dialog.
                        msg_record_ack(temp_to,
                            message_pool[i].from_call_sign,
                            message_pool[i].seq,
                            1,  // "1" specifies a timeout
                            0); // Not a cancel

                        clear_acked_message(temp_to,
                            message_pool[i].from_call_sign,
                            message_pool[i].seq);

//                        if (mw[i].send_message_dialog!=NULL) /* clear submit */
//                            XtSetSensitive(mw[i].button_ok,TRUE);
                    }
                }
            } else {
                if (debug_level & 2)
                    fprintf(stderr,"Message #%s is waiting to have a previous one cleared\n",message_pool[i].seq);
            }
        }
    }
}
Beispiel #16
0
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;
}
Beispiel #17
0
static void
fork_dvips(char **argv, struct save_or_print_info *info, childProcT proc)
{
    int print_io[2];
    int i;
    struct file_info *finfo = info->finfo;
    /*     printlog_append(argv[0], strlen(argv[0])); */
    FILE *fout = NULL;

    if (info->act == FILE_SAVE || info->print_target == TO_FILE) { /* printing to PS file, open file for writing */
	const char *out_file;

	if (info->print_target == TO_FILE || info->fmt == FMT_PS)
	    out_file = finfo->out_file;
	else
	    out_file = finfo->tmp_ps_file;
    
	if ((fout = XFOPEN(out_file, "w")) == NULL) {
	    popup_message(globals.widgets.top_level,
			  MSG_ERR,
			  NULL, "Could not open %s for writing: %s.",
			  out_file,
			  strerror(errno));
	    return;
	}
    }

    printlog_popup(info);

    printlog_append_str(info, "Calling: `");
    printlog_append_str(info, argv[0]);

    for (i = 1; argv[i] != NULL; i++) {
	printlog_append_str(info, " ");
	printlog_append_str(info, argv[i]);
    }
    printlog_append_str(info, "'\n");
    
    if (xpipe(print_io) != 0) {
 	perror("[xdvi] pipe");
 	return;
    }
 
    /* Fork process */
    
    /* flush output buffers to avoid double buffering (i.e. data
       waiting in the output buffer being written twice, by the parent
       and the child) */
    fflush(stderr);
    fflush(stdout);

    print_child.name = xstrdup(argv[0]);
    print_child.proc = proc;
    print_child.data = info;
    print_child.pid = fork();
    if (print_child.pid == 0) {	/* if child */
	/* change into dir of DVI file so that included image files etc. are found */
	(void)chdir(globals.dvi_file.dirname);

	/* make the input file pointer the STDIN of the dvips process */
	if (info->page_selection == PAGE_MARKED) { /* printing selected pages from temporary file */
	    ASSERT(finfo->tmp_dvi_fp != NULL, "tmp fp mustn't be NULL!");
	    (void)dup2(fileno(finfo->tmp_dvi_fp), STDIN_FILENO);
	}
	else { /* printing from main or backup file */
	    (void)dup2(fileno(finfo->in_fp), STDIN_FILENO);
	}
	(void)lseek(0, 0, SEEK_SET);
	
 	if (fout != NULL) { /* printing to file, make stdout of child go to fout */
	    (void)dup2(fileno(fout), STDOUT_FILENO);
 	    (void)close(fileno(fout));
 	}
	else { /* printing to printer, make stdout of child go to print_io[1] */
 	    (void)dup2(print_io[1], STDOUT_FILENO);
 	}

	/* make stderr of child go to print_io[1] */
 	(void)dup2(print_io[1], STDERR_FILENO);
 	(void)close(print_io[1]);
 	(void)close(print_io[0]);
 
 	if (setsid() == -1) {	/* so we can kill the process group */
 	    perror("setsid");
 	    fflush(stderr);
 	    _exit(1);
 	}
 	(void)execvp(*argv, argv);
 	popup_message(globals.widgets.top_level,
		      MSG_ERR,
		      NULL,
		      "Execution of \"%s\" failed: %s.\n", *argv, strerror(errno));
 	fflush(stderr);
 	_exit(1);
    }
 
    if (fout != NULL)
 	fclose(fout);
 
    if (print_child.pid == -1) {	/* error */
 	perror("[xdvi] vfork");
 	return;
    }
 
    set_chld(&print_child);
    dvips_sig = SIGINT;

    (void)close(print_io[1]);
 
    /* Set up file descriptor for non-blocking I/O */
    prep_fd(print_io[0], True);
    print_xio.fd = print_io[0];
    print_xio.data = info;
    set_io(&print_xio);
 
    dvips_status = DVIPS_STAT_RUN;	/* running */
}
Beispiel #18
0
static void
goto_location(const char *filename)
{
#if DEBUG
    fprintf(stderr, "going to file %s\n", filename);
#endif
    if (strcmp(globals.dvi_name, filename) != 0) { /* it's a different file */
	Boolean tried_dvi_ext = True;
	char *new_dvi_name;
#if DEBUG
	fprintf(stderr, "different file: |%s|\n", filename);
#endif
	if ((new_dvi_name = open_dvi_file_wrapper(filename, True, False,
						  &tried_dvi_ext, True)) == NULL) {
	    statusline_append(STATUS_MEDIUM,
			      "Re-opening file",
			      "Re-opening file \"%s\" failed!", filename);
#if DEBUG
	    fprintf(stderr, "Re-opening file \"%s\" failed!\n", filename);
#endif
	    page_history_delete(1);
	    return;
	}
	else {
	    dviErrFlagT errflag;
	    if (load_dvi_file(
#if !DELAYED_MKTEXPK
			      True,
#endif
			      &errflag)) {
		set_dvi_name(new_dvi_name);

		globals.ev.flags |= EV_NEWDOC;
		globals.ev.flags |= EV_PAGEHIST_GOTO_PAGE;
#if DEBUG
		fprintf(stderr, "Back to file: \"%s\"\n", globals.dvi_name);
#endif
	    }
	    else { /* re-open old file */
		popup_message(globals.widgets.top_level,
			      MSG_ERR,
			      NULL,
			      "Could not open `%s': %s.\n"
			      /* "Removing this file from the history." */,
			      globals.dvi_name, get_dvi_error(errflag));

		if (!internal_open_dvi(globals.dvi_name, &errflag, True
#if DELAYED_MKTEXPK
				       , True
#endif
				       )) {
		    popup_message(globals.widgets.top_level,
				  MSG_ERR,
				  NULL,
				  "Couldn't reopen `%s': %s.\n"
				  /* "Removing this file from the history." */,
				  globals.dvi_name, get_dvi_error(errflag));
		}
		else {
		    globals.ev.flags |= EV_NEWPAGE;
		}
		page_history_delete(1);
	    }
	}
    }
    else {
	globals.ev.flags |= EV_PAGEHIST_GOTO_PAGE;
    }
}