coolicon.c
来自「具有IDE功能的编辑器」· C语言 代码 · 共 858 行 · 第 1/2 页
C
858 行
/* coolicons.c - example usage of the coolwidget X API Copyright (C) 1996-2000 Paul Sheer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */#include "coolwidget.h"#include "3dtext.h"#include "cmdlineopt.h"#include "icon.h"#include <sys/types.h>#include <my_string.h>#if HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#include <sys/stat.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include "mad.h"#if (RETSIGTYPE==void)#define handler_return return#else#define handler_return return 1#endifchar *loadfile (const char *filename, long *filelen);void draw_icons_from_config (char *t);CWidget *CDrawPowerIcon (CPowerIcon * p);int savefile (const char *filename, const char *data, int len, int permissions);char *gather_icon_options_for_config (void);void edit_tri_cursor (Window win);void free_icon_elements (CPowerIcon * icon);void free_all_lists (void);void extra_loop_stuff (XEvent * xevent);#define SYSTEM_ICONS LIBDIR "/coolicon.config"#define E_DATA LIBDIR "/e.data"#define START_WIDTH size_of_e#define START_HEIGHT size_of_e/* {{{ command-line options */#ifdef HAVE_DNDextern int option_dnd_version;#endifint option_wait_for_display = 0;int option_shape = 0;int size_of_e = 150;int option_daemon = 0;/* usually in /var/spool/mail/$USERNAME or similar */char *mail_box_file_name = 0;char *e_data_file_name = E_DATA;/* interval to stat the above file */int mail_check_seconds = 30;/* shell command to run */extern char *option_man_cmdline;/* argv[0] */char *argv_nought = 0;/* font from the library */extern char *init_font;/* server from command line */char *option_display = 0;/* font from the command line */char *option_font = "-*-helvetica-medium-r-normal--*-120-*-*-*-*-*-*";/* config file */char *current_config_file = 0;static int get_help = 0;static int get_version = 0;int cursor_revert_timeout = 0;Window cursor_revert_window = 0;/* other things on the command line */static char *command_line_args[] ={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};void usage (void){ printf (\ _ ("Coolicon version %s\nUsage:\n" \ "Coolicon [options]\n" \ "-d, -display <display> the X server to display on\n" \ "-w, --wait-for-display if the server is not available\n" \ " then keep trying to connect\n" \ "-s, --shape floating email `e' image using\n" \ " shape extension\n" \ "-X, --size <pixels> size of `e' window in pixels\n" \ "-e, --e-data <file-name> 3d data to read from\n" \ " default %s\n" \ "-M, --mail-name <file-name> specify the mail box file-name\n" \ "-S, --mail-seconds <seconds> interval to check above file\n" \ "-f, -fn, -font <font-name> default: 8x13bold\n" \ "-C, -config, --config-file <file-name> use <file-name> as config file\n" \ "-h, -H, -?, --help print this message to stdout\n" \ "-V, -v, --version print versiom info\n" \ "\n"), \ VERSION, E_DATA);}void version (void){ printf (_ ("Coolicon version %s\n"), VERSION);}struct prog_options coolicon_options[] ={ {' ', "", "", ARG_STRINGS, 0, command_line_args, 0},#ifdef HAVE_DND {0, "-dnd-old", "--dnd-old", ARG_CLEAR, 0, 0, &option_dnd_version},#endif {'f', "-fn", "-font", ARG_STRING, &option_font, 0, 0}, {'C', "-config", "--config-file", ARG_STRING, ¤t_config_file, 0, 0}, {'M', "", "--mail-name", ARG_STRING, &mail_box_file_name, 0, 0}, {'X', "", "--size", ARG_INT, 0, 0, &size_of_e}, {'S', "", "--mail-seconds", ARG_INT, 0, 0, &mail_check_seconds}, {'e', "", "--e-data", ARG_STRING, &e_data_file_name, 0, 0}, {'h', "-?", "--help", ARG_SET, 0, 0, &get_help}, {'w', "", "--wait-for-display", ARG_SET, 0, 0, &option_wait_for_display}, {'s', "-shape", "--shape", ARG_SET, 0, 0, &option_shape}, {'H', "-help", "--help", ARG_SET, 0, 0, &get_help}, {'V', "-v", "--version", ARG_SET, 0, 0, &get_version}, {'d', "", "-display", ARG_STRING, &option_display, 0, 0},/* {'D', "", "--deamon", ARG_SET, 0, 0, &option_daemon}, */ {0, 0, 0, 0, 0, 0, 0}};/* here we use our own function (which is better than get_opt() or get_opt_long()) */static void process_command_line (int argc, char **argv){ int error; error = get_cmdline_options (argc, argv, coolicon_options); if (error) { fprintf (stderr, _ ("%s: error processing commandline argument %d\n"), argv[0], error); usage (); exit (1); } if (get_help) usage (); if (get_version) version (); if (get_help || get_version) exit (0);}/* }}} command-line options */static void set_signals (void){ signal (SIGPIPE, SIG_IGN);}static int icon_width;int sort_icons (CWidget ** a, CWidget ** b){ int p, q; p = (((*a)->x - 5 - icon_width / 2 + icon_width * 2) / icon_width) * 65536 + (*a)->y; q = (((*b)->x - 5 - icon_width / 2 + icon_width * 2) / icon_width) * 65536 + (*b)->y; return p > q ? 1 : (p < q ? -1 : 0);}#define ICON_SPACING 1void arrange_icons (void){ int i, n, width, height; int h, x, y; CWidget *icons[1024]; i = n = 0; width = height = 0; while (last_widget > i++) if (CIndex (i) != 0) if ((CIndex (i))->kind == C_ICON_WIDGET) { if ((CIndex (i))->user) icons[n++] = CIndex (i); if (width < (CIndex (i))->width) width = (CIndex (i))->width; if (height < (CIndex (i))->height) height = (CIndex (i))->height; } width += ICON_SPACING; height += ICON_SPACING; icon_width = width; h = HeightOfScreen (DefaultScreenOfDisplay (CDisplay)) - 30 - height; qsort (icons, n, sizeof (CWidget *), (int (*)(const void *, const void *)) sort_icons); x = 5; y = 5; for (i = 0; i < n; i++) { if (y > h) { y = 5; x += width; } CSetWidgetPosition (icons[i]->ident, x + (width - icons[i]->width) / 2, y + (height - icons[i]->height) / 2); y += height; }}static long raise_lower_all_callback (CWidget * w, long r){ if (w->kind == C_ICON_WIDGET) { if (r) XRaiseWindow (CDisplay, w->winid); else XLowerWindow (CDisplay, w->winid); } return 0;}void raise_lower_all (int r){ XUngrabPointer (CDisplay, CurrentTime); for_all_widgets ((void *) raise_lower_all_callback, (void *) r, 0);}void edit_change_directory (void){ char *new_dir; XUngrabPointer (CDisplay, CurrentTime); new_dir = CGetDirectory (CRoot, 20, 20, current_dir, "", /* heads the 'Change Directory' dialog box */ _(" Change Current Directory ")); if (new_dir) { if (change_directory (new_dir) < 0) { /* which should never happen *//* heads the 'Change Directory' dialog box */ CErrorDialog(CRoot, 20, 20, _(" Change directory "), get_sys_error (_(" Error return from chdir. "))); } }}void icon_help (void){ switch (fork ()) { case 0: set_signal_handlers_to_default (); execlp ("coolman", "coolman", "coolicon", 0); exit (0); case -1: CErrorDialog (0, 0, 0, _ (" Run 'coolman' "), get_sys_error (_ (" Error trying to fork process "))); return; default: return; }}int edit_dialog (CPowerIcon * icon, char *heading){ CEvent cwevent; Window win; CWidget *edit0, *edit1, *edit2; int x, y, yu, x2, y2; int w, h, result = 0, half; char *mime_majors = 0; if (CIdent ("edit")) return 0; XUngrabPointer (CDisplay, CurrentTime); win = CDrawHeadedDialog ("edit", CRoot, 20, 20, heading); CGetHintPos (&x, &y); yu = y;/* this must be the longest of the messages in this dialog */ CTextSize (&w, &h, _(" Prompt before executing : ")); w += WIDGET_SPACING * 2; CDrawText ("edit.ttitle", win, x, y, _(" Icon title : ")); CPushFont ("editor", 0); edit0 = CDrawEditor ("edit.title", win, x + w, y, FONT_MEAN_WIDTH * 41, 2 * FONT_PIX_PER_LINE, icon->title ? icon->title : "", 0, 0, EDITOR_NO_TEXT | EDITOR_NO_FILE | EDITOR_NO_SCROLL, strlen (icon->title ? icon->title : "")); CPopFont (); CGetHintPos (0, &y); CDrawText ("edit.tfilename", win, x, y, _(" Icon XPM file-name : ")); CDrawTextInput ("edit.filename", win, x + w, y, FONT_MEAN_WIDTH * 41, AUTO_HEIGHT, 256, icon->xpm_filename ? icon->xpm_filename : ""); CGetHintPos (0, &y); CDrawText ("edit.tprompt", win, x, y, _(" Prompt before executing : ")); CDrawTextInput ("edit.prompt", win, x + w, y, FONT_MEAN_WIDTH * 41, AUTO_HEIGHT, 256, icon->prompt ? icon->prompt : ""); CGetHintPos (0, &y); CDrawText ("edit.tconfirm", win, x, y, _(" Confirmation prompt : ")); CDrawTextInput ("edit.confirm", win, x + w, y, FONT_MEAN_WIDTH * 41, AUTO_HEIGHT, 256, icon->confirm ? icon->confirm : ""); CGetHintPos (0, &y); CDrawText ("edit.tpos", win, x, y, _(" Starting position ")); CDrawText ("edit.tx", win, x + w, y, _(" X : ")); CGetHintPos (&x2, 0); x2 -= WIDGET_SPACING; CDrawTextInput ("edit.x", win, x2, y, FONT_MEAN_WIDTH * 14, AUTO_HEIGHT, 256, itoa (icon->x)); CGetHintPos (&x2, 0); CDrawText ("edit.tx", win, x2, y, _(" Y : ")); CGetHintPos (&x2, 0); x2 -= WIDGET_SPACING; CDrawTextInput ("edit.y", win, x2, y, FONT_MEAN_WIDTH * 14, AUTO_HEIGHT, 256, itoa (icon->y)); CGetHintPos (0, &y); CDrawText ("edit.ttoolhint", win, x, y, _(" Toolhint : ")); (CDrawTextInput ("edit.toolhint", win, x + w, y, FONT_MEAN_WIDTH * 40, AUTO_HEIGHT, 256, icon->tool_hint ? icon->tool_hint : ""))->position |= POSITION_FILL; CGetHintPos (0, &y); CDrawText ("edit.tconfdclick", win, x, y, _(" Double click : ")); CDrawSwitch ("edit.confdclick", win, x + w, y, icon->options & ICON_OPTION_CONFIRM_DOUBLE_CLICK, _ (" Ask confirm "), 1); CGetHintPos (&x2, 0); CDrawSwitch ("edit.promptdclick", win, x2, y, icon->options & ICON_OPTION_PROMPT_DOUBLE_CLICK, _ (" Show prompt "), 1); CGetHintPos (0, &y); CDrawText ("edit.tconfdrop", win, x, y, _(" Recieve drop : ")); CDrawSwitch ("edit.confdrop", win, x + w, y, icon->options & ICON_OPTION_CONFIRM_DROP, _ (" Ask confirm "), 2); CGetHintPos (&x2, 0); CDrawSwitch ("edit.promptdrop", win, x2, y, icon->options & ICON_OPTION_PROMPT_DROP, _ (" Show prompt "), 2); CGetHintPos (0, &y); CDrawText ("edit.tmimetypes", win, x, y, _(" A prioritised comma separated list of MIME types : ")); CGetHintPos (0, &y); mime_majors = 0; if (icon->mime_majors) convert_array_to_commalist (icon->mime_majors, &mime_majors); (CDrawTextInput ("edit.mimetypes", win, x, y, FONT_MEAN_WIDTH * 40, AUTO_HEIGHT, 256, mime_majors ? mime_majors : ""))->position |= POSITION_FILL; if (mime_majors) free (mime_majors); CGetHintPos (0, &y); CDrawText ("edit.tdropscript", win, x, y, _(" Script for receiving a drop : ")); CGetHintPos (0, &y2); CPushFont ("editor", 0); edit1 = CDrawEditor ("edit.dropscript", win, x, y2, 40 * FONT_MEAN_WIDTH, 10 * FONT_PIX_PER_LINE, icon->drop_script ? icon->drop_script : "#!/bin/sh\n\n", 0, 0, EDITOR_NO_TEXT | EDITOR_NO_FILE, strlen (icon->drop_script ? icon->drop_script : "#!/bin/sh\n\n")); CPopFont (); CGetHintPos (&half, 0); CDrawText ("edit.tdclick", win, x + half, y, _(" Script for double click : ")); CPushFont ("editor", 0); edit2 = CDrawEditor ("edit.dclick", win, x + half, y2, 40 * FONT_MEAN_WIDTH, 10 * FONT_PIX_PER_LINE, icon->double_click_script ? icon->double_click_script : "#!/bin/sh\n\n", 0, 0, EDITOR_NO_TEXT | EDITOR_NO_FILE, strlen (icon->double_click_script ? icon->double_click_script : "#!/bin/sh\n\n")); CPopFont (); CGetHintPos (0, &y); get_hint_limits (&x, &y); x -= WIDGET_SPACING + TICK_BUTTON_WIDTH; CDrawPixmapButton ("edit.ok", win, x, yu, PIXMAP_BUTTON_TICK); yu += WIDGET_SPACING + TICK_BUTTON_WIDTH; CDrawPixmapButton ("edit.cancel", win, x, yu, PIXMAP_BUTTON_CROSS); CFocus (CIdent ("edit.title")); CSetSizeHintPos ("edit"); CMapDialog ("edit"); for (;;) { XEvent xevent; CNextEvent (&xevent, &cwevent); extra_loop_stuff (&xevent); if (!CIdent ("edit")) break; if (!strcmp (cwevent.ident, "edit.cancel")) break; if (cwevent.command == CK_Cancel) break; if (!strcmp (cwevent.ident, "edit.ok") || (!cwevent.handled && cwevent.command == CK_Enter)) { free_icon_elements (icon); icon->title = edit_get_buffer_as_text (edit0->editor); icon->xpm_filename = (char *) strdup (CIdent ("edit.filename")->text); icon->prompt = (char *) strdup (CIdent ("edit.prompt")->text); icon->confirm = (char *) strdup (CIdent ("edit.confirm")->text); icon->x = atoi (CIdent ("edit.x")->text); icon->y = atoi (CIdent ("edit.y")->text); icon->drop_script = edit_get_buffer_as_text (edit1->editor); icon->double_click_script = edit_get_buffer_as_text (edit2->editor); icon->tool_hint = (char *) strdup (CIdent ("edit.toolhint")->text); convert_commalist_to_array (CIdent ("edit.mimetypes")->text, &icon->mime_majors); icon->options = 0; icon->options |= CIdent ("edit.confdclick")->keypressed != 0 ? ICON_OPTION_CONFIRM_DOUBLE_CLICK : 0; icon->options |= CIdent ("edit.promptdclick")->keypressed != 0 ? ICON_OPTION_PROMPT_DOUBLE_CLICK : 0; icon->options |= CIdent ("edit.confdrop")->keypressed != 0 ? ICON_OPTION_CONFIRM_DROP : 0; icon->options |= CIdent ("edit.promptdrop")->keypressed != 0 ? ICON_OPTION_PROMPT_DROP : 0; result = 1; break; } } CDestroyWidget ("edit"); return result;}void change_config_file (CWidget * icon){ char *a; static char *config_file = 0; a = CInputDialog ("iconconfig", CRoot, icon->x, icon->y, 300 | INPUT_DIALOG_BROWSE_SAVE, current_config_file, _(" Change Config File "), _(" Enter new config file : ")); if (a) { current_config_file = a; if (config_file) free (config_file); config_file = a; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?