For libwraster:
[wmaker-crm.git] / WINGs / Tests / wmfile.c
blob500cf49bd45400423be0b24dc34f5d01c0325ecb
1 /*
2 * Author: Len Trigg <trigg@cs.waikato.ac.nz>
3 */
5 /*
6 Update: Franck Wolff <frawolff@club-internet.fr>
7 -----------------------------------------------------------------------
8 List of updated functions :
9 - main :
10 add -s option for a save panel...
11 -----------------------------------------------------------------------
16 #include <WINGs/WINGs.h>
18 #include <unistd.h>
19 #include <stdio.h>
21 #include "logo.xpm"
26 void
27 wAbort()
29 exit(1);
32 char *ProgName;
34 void usage(void)
36 fprintf(stderr,
37 "usage:\n"
38 "\t%s [-options]\n"
39 "\n"
40 "options:\n"
41 " -s\t\tSave panel (default open panel)\n"
42 " -i <str>\tInitial directory (default /)\n"
43 " -t <str>\tQuery window title (default none)\n"
44 "\n"
45 "information:\n"
46 "\t%s pops up a WindowMaker style file selection panel.\n"
47 "\n"
48 "version:\n"
49 "\t%s\n"
50 ,ProgName,ProgName,__DATE__
52 exit(0);
55 #define OPEN_PANEL_TYPE 0
56 #define SAVE_PANEL_TYPE 1
58 int main(int argc, char **argv)
60 Display *dpy = XOpenDisplay("");
61 WMScreen *scr;
62 WMPixmap *pixmap;
63 WMOpenPanel *oPanel;
64 WMSavePanel *sPanel;
65 /* RImage *image;*/
66 char *title = NULL;
67 char *initial = "/";
68 int ch;
69 int panelType = OPEN_PANEL_TYPE;
70 extern char *optarg;
71 extern int optind;
73 WMInitializeApplication("WMFile", &argc, argv);
75 ProgName = argv[0];
77 if (!dpy) {
78 puts("could not open display");
79 exit(1);
81 while((ch = getopt(argc, argv, "si:ht:")) != -1)
82 switch(ch)
84 case 's':
85 panelType = SAVE_PANEL_TYPE;
86 break;
87 case 'i':
88 initial = optarg;
89 break;
90 case 't':
91 title = optarg;
92 break;
93 default:
94 usage();
97 for(; optind <argc; optind++)
98 usage();
100 scr = WMCreateSimpleApplicationScreen(dpy);
104 pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
105 WMSetApplicationIconPixmap(scr, pixmap);
106 WMReleasePixmap(pixmap);
107 if (panelType == SAVE_PANEL_TYPE) {
108 sPanel = WMGetSavePanel(scr);
109 if (WMRunModalFilePanelForDirectory(sPanel, NULL, initial,
110 /*title*/ NULL, NULL) == True)
111 printf("%s\n", WMGetFilePanelFileName(sPanel));
112 else
113 printf("\n");
114 } else {
115 oPanel = WMGetOpenPanel(scr);
116 if (WMRunModalFilePanelForDirectory(oPanel, NULL, initial,
117 /*title*/ NULL, NULL) == True)
118 printf("%s\n", WMGetFilePanelFileName(oPanel));
119 else
120 printf("\n");
122 return 0;