coolicon.c

来自「具有IDE功能的编辑器」· C语言 代码 · 共 858 行 · 第 1/2 页

C
858
字号
}int save_icons (void){    char *t;    char s[256];    XUngrabPointer (CDisplay, CurrentTime);    t = loadfile (current_config_file, 0);    if (t) {/* create backup of config */	if (savefile (catstrs (current_config_file, "~", 0), t, strlen (t), 0600) < 0)	    goto error;	free (t);    }    t = gather_icon_options_for_config ();    if (savefile (current_config_file, t, strlen (t), 0600) < 0)	goto error;    free (t);    return 0;  error:    sprintf (s, _ (" Error trying to save config file `%s' or backup file `%s~' "), current_config_file, current_config_file);    CErrorDialog (CRoot, 20, 20, _ (" Save Icons "), get_sys_error (s));    return 1;}void new_dialog (CWidget * w){    CPowerIcon icon;    XUngrabPointer (CDisplay, CurrentTime);    memset (&icon, 0, sizeof (CPowerIcon));    icon.x = w->x;    icon.y = w->y + w->height;    if (edit_dialog (&icon, _(" New Icon "))) {	CDrawPowerIcon (&icon);	save_icons ();    }}void icon_menu (char *ident);void close_all (CWidget * w){    XUngrabPointer (CDisplay, CurrentTime);    CSetOverrideRedirect ();    switch (CQueryDialog (CRoot, w->x, w->y, _(" Exit "), _(" This will kill the icon application : "), _(" Kill "), _(" Save all and kill "), _(" Don't kill "), 0)) {    case -1:    case 2:	CClearOverrideRedirect ();	return;    case 0:	break;    case 1:	if (save_icons ()) {	    CClearOverrideRedirect ();	    return;	}	break;    }    CShutdown ();    free_all_lists ();    catstrs_clean ();    exit (0);}GC shape_gc;Pixmap shape_pixmap = 0;int this_thes;void shape_create (Window win, int width, int height){    shape_pixmap = XCreatePixmap (CDisplay, CRoot, width, height, 1);    shape_gc = XCreateGC (CDisplay, shape_pixmap, 0, 0);}void shape_free (void){    if (!shape_pixmap)	return;    XFreeGC (CDisplay, shape_gc);    XFreePixmap (CDisplay, shape_pixmap);    shape_pixmap = 0;}void this_striangle (int x0, int y0,		      int x1, int y1,		      int x2, int y2, int z0, int bf){    long n;    XPoint p[3];    p[0].x = x0;    p[0].y = y0;    p[1].x = x1;    p[1].y = y1;    p[2].x = x2;    p[2].y = y2;    if ((((n = (x0 - x1) * (y0 - y2) - (y0 - y1) * (x0 - x2)) > 0) + bf) & 1 || bf == 2) {	if (abs (n) < this_thes) {	    if (abs (x0) + abs (x1) + abs (x2) + abs (y0) + abs (y1) + abs (y2) < 32000)		XFillPolygon (CDisplay, shape_pixmap, shape_gc, p, 3, Convex, CoordModeOrigin);	}    }}void local_striangle (int x0, int y0,		      int x1, int y1,		      int x2, int y2, int z0, int bf);void shape_combine (char *ident){    CWidget *w;    TD_Solid *object;    w = CIdent (ident);    object = w->solid;    object->draw_striangle = this_striangle;    gl_setcontext (w->gl_graphicscontext);    gl_enableclipping ();    this_thes = w->width * w->height;    XSetForeground (CDisplay, shape_gc, 0);    XFillRectangle (CDisplay, shape_pixmap, shape_gc, 0, 0, w->width - 4, w->height - 4);    XSetForeground (CDisplay, shape_gc, 1);    TD_draw_solid (object);    XShapeCombineMask (CDisplay, w->winid, ShapeBounding, 2, 2, shape_pixmap, ShapeSet);    object->draw_striangle = local_striangle;}extern int override_8bit_non_lookup;void set_object_options (char *ident){    int j, n;    CWidget *w;    TD_Solid *object;    w = CIdent (ident);    object = w->solid;    n = object->num_surfaces;    object->render = TD_SOLID;#if 0    object->option_flags &= (0xFFFFFFFFUL - TDOPTION_FLAT_TRIANGLE);#endif    for (j = 0; j < n; j++) {	object->surf[j].backfacing = 1;	object->surf[j].depth_per_color = 4;	object->surf[j].mesh_color = color_palette (6);	if (CDepth >= 8 && (ClassOfVisual (CVisual) == PseudoColor || ClassOfVisual (CVisual) == StaticGray)) {#if 0	    object->surf[j].shadow = color_widget (1);	    object->surf[j].maxcolor = color_widget (15);#else	    override_8bit_non_lookup = 1;	    object->surf[j].shadow = 1;	    object->surf[j].maxcolor = 15;#endif	} else {	    object->surf[j].shadow = 1;	    object->surf[j].maxcolor = 15;	}    }}int cb_object (CWidget * w, XEvent * xevent, CEvent * cwevent);int object_update (CWidget * w, XEvent * x, CEvent * ce);void show_e (void){    static char *object_text;    Window win;    int x, y, load_error = 0;    x = WidthOfScreen (DefaultScreenOfDisplay (CDisplay)) / 2 - START_WIDTH / 2;    y = HeightOfScreen (DefaultScreenOfDisplay (CDisplay)) / 2 - START_HEIGHT / 2;    if (option_shape) {	win = CRoot;    } else {	win = CDrawMainWindow ("objectwin", " You have new mail ");	CGetHintPos (&x, &y);    }    CSetOverrideRedirect ();    CDraw3DObject ("object", win, x, y, START_WIDTH, START_HEIGHT, 1, 25);    CClearOverrideRedirect ();    CAddCallback ("object", cb_object);    set_object_options ("object");    if (option_shape)	shape_create (CIdent ("object")->winid, CIdent ("object")->width - 4, CIdent ("object")->height - 4);    if (!object_text) {	object_text = loadfile (e_data_file_name, 0);	if (!object_text) {	    object_text = "scale 200\n\nsphere 0 0 0 100\n\n";	    load_error = 1;	}    }    CDraw3DFromText ("object", object_text);    if (option_shape) {	shape_combine ("object");    } else {	CSetSizeHintPos ("objectwin");	CMapDialog ("objectwin");    }    if (load_error) {	CErrorDialog (CRoot, 20, 20, _ (" Check Mailbox "), \	get_sys_error (catstrs (_ ("Unable to load 3D data from file "), \				E_DATA, " ", 0)));    }}void hide_e (void){    if (option_shape)	shape_free ();    CDestroyWidget ("object");    CDestroyWidget ("objectwin");}int object_update (CWidget * w, XEvent * x, CEvent * ce){    static long mail_box_size = -2;    static int count = 0;    struct stat stats;    if (!mail_box_file_name)	return 1;    w = CIdent ("object");    if (!w)	if (option_shape)	    shape_free ();    if (!w) {	if (mail_box_size < 0) {	    if (stat (mail_box_file_name, &stats)) {		if (mail_box_size == -2) {		    CErrorDialog (CRoot, 20, 20, _ (" Check Mailbox "), get_sys_error (_ ("Unable to stat mailbox, check you mailbox filename")));		    CAddCallback ("AlarmCallback", 0);		}		return 1;	    }	    mail_box_size = stats.st_size;	    return 1;	}	count++;	if (count > CGetCursorBlinkRate () * mail_check_seconds) {	    count = 0;	    if (!stat (mail_box_file_name, &stats)) {		if (stats.st_size > mail_box_size + 80) {	/* there are at least 80 characters in a mail header */		    show_e ();		}		mail_box_size = stats.st_size;	    }	    return 1;	}    } else {	mail_box_size = -1;	w->solid->alpha += 0.1;	w->solid->beta += 0.01;	if (option_shape)	    shape_combine ("object");	CRedraw3DObject ("object", 1);    }    return 1;}int cb_object (CWidget * w, XEvent * xevent, CEvent * cwevent){    static int y3dprev = 0, x3dprev = 0;    static float alphaprev = 0, betaprev = 0;    if (cwevent->type == ButtonPress && cwevent->double_click) {	hide_e ();	return 1;    }    if (cwevent->type == ButtonPress && cwevent->button == Button2)	XLowerWindow (CDisplay, w->winid);    if (cwevent->type == ButtonPress && cwevent->button == Button1) {	XRaiseWindow (CDisplay, w->winid);	x3dprev = cwevent->x;	y3dprev = cwevent->y;	alphaprev = w->solid->alpha;	betaprev = w->solid->beta;    }    if ((cwevent->type == MotionNotify && (cwevent->state & Button1Mask)) ||	(cwevent->type == ButtonRelease && cwevent->button == Button1)) {	w->solid->alpha = (float) alphaprev + (float) ((float) cwevent->x - x3dprev) / 100;	w->solid->beta = (float) betaprev + (float) ((float) cwevent->y - y3dprev) / 100;	if (!CCheckWindowEvent (w->winid, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, 0)) {	    if (option_shape)		shape_combine (w->ident);	    CRedraw3DObject (w->ident, 1);	}    }    return 0;}void load_trivial_options (void);extern struct drop drop;char *load_config (char *file, long *l){    char *t;    t = loadfile (file, l);    if (!t)	return 0;    if (strstr (t, "DndFile")	|| strstr (file, "DndNotDnd")	|| strstr (file, "DndUnknown")	|| strstr (file, "DndRawData")	|| strstr (file, "DndFile")	|| strstr (file, "DndFiles")	|| strstr (file, "DndText")	|| strstr (file, "DndDir")	|| strstr (file, "DndLink")	|| strstr (file, "DndExe")	|| strstr (file, "DndURL")	|| strstr (file, "DndMIME"))	CMessageDialog (0, 0, 0, 0, "Coolicon Warning",			"Coolicon has detected that you have used one of the Dnd types in your\n" \			"icon scripts. Dnd is no longer supported. Please refer to the\n" \			"cooledit(1) and coolman(1) man pages for an explanation of the new XDND\n" \			"protocol types. These will be MIME types with %%%%T denoting the top-level\n" \			"type and %%%%s denoting the sub-type.");    return t;}extern int option_auto_spellcheck;void extra_loop_stuff (XEvent * xevent){    if (xevent->type == AlarmEvent) {	if (cursor_revert_timeout <= 0 && cursor_revert_window) {	    edit_tri_cursor (cursor_revert_window);	    cursor_revert_window = 0;	} else {	    cursor_revert_timeout--;	}    }    if (CDndClass->stage == XDND_DROP_STAGE_IDLE && drop.data) {	CWidget *w;	w = CIdent (drop.ident);	if (w)	    execute_icon_drop (w, (CPowerIcon *) w->user,			       (char *) drop.data, drop.size,			       drop.atom_name);	free (drop.data);	free (drop.ident);	free (drop.atom_name);	memset (&drop, 0, sizeof (drop));    }}int main (int argc, char **argv){    char *config;    int done = 0;    Window win;    CInitData coolicon_startup;    CEvent cwevent;    XEvent xevent;    memset (&drop, 0, sizeof (drop));    setlocale (LC_CTYPE, "");    setlocale (LC_TIME, "");    setlocale (LC_MESSAGES, "");    bindtextdomain (PACKAGE, LOCALEDIR);    textdomain (PACKAGE);    option_auto_spellcheck = 0;    load_trivial_options ();    process_command_line (argc, argv);/* initialise the library */    memset (&coolicon_startup, 0, sizeof (coolicon_startup));    coolicon_startup.name = argv[0];    coolicon_startup.display = option_display;    coolicon_startup.font = "7x13";    coolicon_startup.widget_font = option_font;    if (option_wait_for_display)	coolicon_startup.options |= CINIT_OPTION_WAIT_FOR_DISPLAY;    CInitialise (&coolicon_startup);    CPushFont ("icon", "-*-helvetica-bold-r-*--12-*-*-*-*-*-*");    CPushFont ("editor", 0);    CPushFont ("widget", 0);/* create main window that will not be displayed (needed because the   library does some important initialisation with the first window) */    win = CDrawMainWindow ("dummy", "Nothing");    if (!current_config_file)	current_config_file = (char *) strdup (catstrs (home_dir, "/.coolicon", 0));    config = load_config (current_config_file, 0);    if (config) {		/* user config file is optional */	draw_icons_from_config (config);	free (config);    } else {	config = load_config (SYSTEM_ICONS, 0);	if (!config) {	    char s[256];	    sprintf (s, _ (" Error trying to load system wide icon config file `%s' "), SYSTEM_ICONS);	    CErrorDialog (CRoot, 20, 20, _ (" Load Config "), get_sys_error (s));	    exit (1);	}	draw_icons_from_config (config);	free (config);    }    set_signals ();    CAddCallback ("AlarmCallback", object_update);/* Run the application. */    while (!done) {	CNextEvent (&xevent, &cwevent);	extra_loop_stuff (&xevent);    }    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?