1 /* 2 ***************************************************************************** 3 ** xbmbrowser version 5.0 (c) Copyright Ashley Roll, all rights reserved. 4 ** FILE: xbmbrowser.h 5 ** 6 ** Copyright transfered to Anthony Thyssen 7 ** 8 ** xbmbrowser is Public Domain. However it, and all the code still belong to me. 9 ** I do, however grant permission for you to freely copy and distribute it on 10 ** the condition that this and all other copyright notices remain unchanged in 11 ** all distributions. 12 ** 13 ** This software comes with NO warranty whatsoever. I therefore take no 14 ** responsibility for any damages, losses or problems that the program may 15 ** cause. 16 ***************************************************************************** 17 */ 18 19 #include <X11/Xos.h> /* X operating system includes */ 20 #include <X11/Xlib.h> /* X programming includes */ 21 #include <X11/Xutil.h> 22 #include <X11/Xatom.h> 23 #include <X11/cursorfont.h> 24 #include <X11/Intrinsic.h> 25 #include <X11/StringDefs.h> 26 27 #include <stdio.h> /* C library includes */ 28 #include <dirent.h> /* Filename length (and dir functions) */ 29 #include <assert.h> /* debugging assertions */ 30 31 #include <X11/Xaw/Form.h> /* widget includes */ 32 #include <X11/Xaw/Box.h> 33 #include <X11/Xaw/Dialog.h> 34 #include <X11/Xaw/MenuButton.h> 35 #include <X11/Xaw/SimpleMenu.h> 36 #include <X11/Xaw/SmeBSB.h> 37 #include <X11/Xaw/SmeLine.h> 38 #include <X11/Xaw/AsciiText.h> 39 #include <X11/Xaw/List.h> 40 #include <X11/Xaw/Paned.h> 41 #include <X11/Xaw/Viewport.h> 42 43 #include "IconLabel.h" /* Special Widget -- IconLabel */ 44 45 #ifdef DO_XPMS 46 # include <xpm.h> 47 #endif 48 49 /*************************************************************************** 50 SITE SPECIFIC STUFF - EDIT TO MATCH YOUR SETUP 51 ***************************************************************************/ 52 /* 53 ** The full path to the default menu configuration file 54 */ 55 #ifndef LIBRARY_RC 56 #define LIBRARY_RC "/usr/lib/X11/xbmbrowser/xbmbrowser.menu" 57 #endif 58 59 /* 60 ** The name of the users menu (rc) file to find in users home 61 */ 62 #ifndef USERS_RC 63 #define USERS_RC ".xbmbrowserrc" 64 #endif 65 66 /*************************************************************************** 67 PROGRAM STUFF - CHANGE IT AT YOUR OWN RISK 68 ***************************************************************************/ 69 70 /***** Type Definitions *****/ 71 72 /* the various types of file we deal with */ 73 enum FileType { 74 Unknown, /* Unknown, Special Files */ 75 Dir, DirUp, DirLink, DirBad, /* Directory types */ 76 /* NOTE: Non-File == (type < File) */ 77 File, Text, Binary, /* File types ( File = undetermined file ) */ 78 Xbm, Xpm, XpmBad, /* Image files ( XpmBad is a filed load ) */ 79 NumFileTypes /* Count of file types */ 80 }; 81 82 /* item structure */ 83 typedef struct _item { 84 struct _item *next; /* next item */ 85 char fname[MAXNAMLEN]; /* This files name in current dir */ 86 char info[MAXNAMLEN+40]; /* information to display about icon */ 87 time_t mtime; /* last modification time */ 88 enum FileType type; /* file type */ 89 Boolean visible; /* visible to user? */ 90 int index; /* widget the pixmap is currently in */ 91 Pixmap pixmap; /* pixmap from this file - to widget */ 92 #ifdef DO_XPMS 93 Pixmap mask; /* the xpm mask bitmap */ 94 XpmAttributes attr; /* xpm attributes */ 95 #endif 96 } Item; 97 98 /* a couple of macros to make life easier */ 99 #define IsDirItem(item) ( (item)->type != Unknown && (item)->type < File ) 100 #define IsFileItem(item) ( (item)->type >= File) 101 102 /* resource data structure */ 103 typedef struct { 104 char *cmd_rc; /* the config file given on command line */ 105 char *user_rc; /* the user's rc file in his/her home dir */ 106 char *library_rc; /* the library menu configuration file */ 107 /* --- option menu --- */ 108 /* Display Style */ 109 Boolean solid_bgnd; /* solid color and shaped windows on/off */ 110 Boolean shape_syms; /* shape the file symbols */ 111 Boolean label_all; /* add labels to all displayed widgets */ 112 Boolean label_icons; /* add labels to icons only */ 113 Boolean label_syms; /* add labels to symbols only */ 114 Boolean label_dirs; /* add labels to direcories only */ 115 /* Show What */ 116 Boolean icons_only; /* display icons only */ 117 Boolean show_dir; /* show these file symbols ( unless icons_only ) */ 118 Boolean show_xpmbad; 119 Boolean show_other; 120 Boolean show_hidden; 121 /* Scan Style */ 122 Boolean recursive; /* recursive directory scan -- watch it */ 123 /* --- colors --- */ 124 Pixel sym_fg; /* foreground for file symbols */ 125 Pixel sym_bg; /* background for file symbols */ 126 Pixel icon_fg; /* foreground for bitmap icons */ 127 Pixel icon_bg; /* background for bitmap icons */ 128 Pixel icon_tr; /* transparent color for pixmaps (unshaped) */ 129 Pixel solid_bg; /* solid background color (shaped bgnd) */ 130 Pixel stipple_bg; /* stipple background color */ 131 } AppData; 132 133 134 /***** Variable Definitions *****/ 135 136 #ifdef MAIN 137 #define ext 138 #else 139 #define ext extern 140 #endif 141 142 /* application resource structure */ 143 ext AppData app_data; 144 145 /* Display information */ 146 ext Display *display; /* Xlib display pointer */ 147 ext Screen *screen; /* The Screen we are on */ 148 ext Colormap colormap; /* the default colormap of screen */ 149 ext int depth; /* the depth of the display */ 150 151 /* Extra Stuff we use -- shouldn't these be resources? or in app_data? */ 152 ext Cursor normalCursor, waitCursor; /* Cursours */ 153 ext Pixmap tickoff, tickon; /* tickbox bitmaps for option menu */ 154 ext Pixmap sym_bmaps[(int)NumFileTypes]; /* default file type icon images */ 155 ext Pixmap sym_masks[(int)NumFileTypes]; /* To be initialized later */ 156 157 /* Globally Known Widgets */ 158 ext Widget mainpw; /* main pane widget -- for cursors */ 159 ext Widget mainmenu, dirwidget; /* menu button and dir_dialog */ 160 ext Widget dirmenu, dirlist; /* directory list popup */ 161 ext Widget label, iconbox; /* information and iconbox */ 162 ext Widget recur_opt; /* recursive toggle menu option */ 163 164 /* user menu widgets which may or may-not be defined by the user */ 165 ext Widget menu_main, menu_global; 166 ext Widget menu_bitmap, menu_pixmap; 167 ext Widget menu_directory, menu_other; 168 169 /* substitution strings for function argument macro substitions */ 170 ext char dir_name[MAXNAMLEN]; /* %d the current directory */ 171 ext char file_name[MAXNAMLEN]; /* %f current filename */ 172 ext char base_name[MAXNAMLEN]; /* %b basename for current file */ 173 ext char suffix[MAXNAMLEN]; /* %s suffix of current file */ 174 ext char input[MAXNAMLEN]; /* %i input string from user */ 175 ext char home_dir[MAXNAMLEN]; /* %h the users home directory */ 176 ext char init_dir[MAXNAMLEN]; /* %D initial startup directory */ 177 178 /* Information strings for display in application label */ 179 ext char label_info[MAXNAMLEN]; /* label to show when outside bitmap */ 180 ext Item *current_item; /* which item the user is pointing to */ 181 182 /* some external variables */ 183 extern char icon_trans[]; /* Translations to use for MenuPopup */ 184 185 186 /***** Proceedure Definitions *****/ 187 188 /* callback procedures "callbacks.c" */ 189 extern void set_name(); /* set the info line with file name */ 190 extern void set_label(); /* reset the info line to file counts */ 191 extern void dir_return(); /* return key in directory string */ 192 extern void pos_dir(); /* position directory menu */ 193 extern void dir_menu(); /* menu button in directory string */ 194 extern void rescan(); /* rescan button callback */ 195 extern void scan(); /* scan button callback */ 196 extern void toggle_option(); /* user option toggle callback */ 197 extern void popup_user_menu(); /* menu popup over icon or symbol */ 198 199 /* user defined menu module "user-menu.c" */ 200 extern void menu_item_abort(); /* abort -- menu function sequence */ 201 extern void menu_item_continue(); /* continue sequence after popup end */ 202 extern void read_user_menu(); /* read menu configuration file */ 203 204 /* user functions "user-functs.c" */ 205 extern void quit_browser(); /* quit the browser */ 206 extern void expand_tilde(); /* expand any ~ to the users home dir */ 207 extern void change_dir(); /* change the directory to that given */ 208 extern void exec_string(); /* execute the string given */ 209 extern void user_confirm(); /* ask the user for confirmation */ 210 extern void input_string(); /* input a string from the user */ 211 extern void file_selected(); /* check that user has selected a file */ 212 213 /* icon display routines "images.c" */ 214 extern Item *alloc_item(); /* Item allocation (from misc.c) */ 215 extern Item *free_item(); /* free file/image item */ 216 extern void free_list(); /* free a list of items */ 217 extern void rescan_item(); /* just re-load this one item */ 218 extern void redisplay_images(); /* just redisplay all images - fast */ 219 extern void reassign_images(); /* reassign all items to widgets */ 220 extern void rescan_images(); /* scan for changes and reload them */ 221 extern void scan_images(); /* full scan of the current directory */ 222 223 /* miscelanous functions "misc.c" */ 224 extern void set_busywait(); /* Set the watch cursor */ 225 extern void clear_busywait(); /* Remove the watch cursor */ 226 extern void set_stipple(); /* Set/Reset the stipple background */ 227 extern void init_stipple(); /* Initialize the stipple color & pixmap */ 228 extern Item *get_files(); /* Scan a directory and initialise items */ 229 extern time_t check_file_time(); /* check if a file was modified */ 230 231 232 /*********** Macros ************/ 233 234 /* CAT: Macro to concatenate two arguments into one compiler symbol 235 ** example: CAT(symbol,_height) becomes symbol_height 236 ** Note: some sites may need to set this explicitely. If this doesn't 237 ** work mail me which element does, and the CPP sysmbols defined for 238 ** machine. 239 */ 240 #ifndef CAT 241 # ifdef __STDC__ 242 # define CAT(a,b) a##b /* ANSI concatenate */ 243 # else 244 # ifndef sun 245 # define CAT(a,b) a/**/b /* Old K&R concatenate */ 246 # else 247 # undef IDENT 248 # define IDENT(x) x 249 # define CAT(a,b) IDENT(a)b /* Sun concatenate */ 250 # endif 251 # endif 252 #endif 253 254 255 /* LOAD_BMAP: Macro to create a Bitmap from the Bitmap data given. 256 ** Assumes that the filename given is also the symbol names used within 257 ** the included bitmap file. */ 258 #define LOAD_BMAP(file) \ 259 XCreateBitmapFromData( display, RootWindowOfScreen(screen),\ 260 (char *)CAT(file,_bits), CAT(file,_width), CAT(file,_height) ) 261 262 /* The macros to insure that symbolic links work on all systems 263 ** have been moved into misc.c 264 */ 265 266 /*********************************/ 267 268