1 /* Paths.c- pixmap/icon paths
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 typedef struct _Panel
{
33 CallbackRec callbacks
;
55 #define ICON_FILE "paths"
59 addPathToList(WMList
*list
, int index
, char *path
)
61 char *fpath
= wexpandpath(path
);
64 item
= WMInsertListItem(list
, index
, path
);
66 if (access(fpath
, X_OK
)!=0) {
74 showData(_Panel
*panel
)
76 proplist_t array
, val
;
79 array
= GetObjectForKey("IconPath");
80 if (!array
|| !PLIsArray(array
)) {
82 wwarning(_("bad value in option IconPath. Using default path list"));
83 addPathToList(panel
->icoL
, -1, "~/pixmaps");
84 addPathToList(panel
->icoL
, -1, "~/GNUstep/Library/Icons");
85 addPathToList(panel
->icoL
, -1, "/usr/include/X11/pixmaps");
86 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Icons");
87 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
88 addPathToList(panel
->icoL
, -1, "/usr/share/WindowMaker/Icons");
90 for (i
=0; i
<PLGetNumberOfElements(array
); i
++) {
91 val
= PLGetArrayElement(array
, i
);
92 addPathToList(panel
->icoL
, -1, PLGetString(val
));
96 array
= GetObjectForKey("PixmapPath");
97 if (!array
|| !PLIsArray(array
)) {
99 wwarning(_("bad value in option PixmapPath. Using default path list"));
100 addPathToList(panel
->pixL
, -1, "~/pixmaps");
101 addPathToList(panel
->pixL
, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
102 addPathToList(panel
->pixL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
104 for (i
=0; i
<PLGetNumberOfElements(array
); i
++) {
105 val
= PLGetArrayElement(array
, i
);
106 addPathToList(panel
->pixL
, -1, PLGetString(val
));
113 pushButton(WMWidget
*w
, void *data
)
115 _Panel
*panel
= (_Panel
*)data
;
119 if (w
== panel
->icorB
) {
120 i
= WMGetListSelectedItemRow(panel
->icoL
);
123 WMRemoveListItem(panel
->icoL
, i
);
127 if (w
== panel
->pixrB
) {
128 i
= WMGetListSelectedItemRow(panel
->pixL
);
131 WMRemoveListItem(panel
->pixL
, i
);
137 browseForFile(WMWidget
*w
, void *data
)
139 _Panel
*panel
= (_Panel
*)data
;
140 WMFilePanel
*filePanel
;
142 filePanel
= WMGetOpenPanel(WMWidgetScreen(w
));
144 WMSetFilePanelCanChooseFiles(filePanel
, False
);
146 if (WMRunModalFilePanelForDirectory(filePanel
, panel
->win
, "/",
147 _("Select path"), NULL
) == True
) {
148 char *str
= WMGetFilePanelFileName(filePanel
);
151 int len
= strlen(str
);
153 /* Remove the trailing '/' except if the path is exactly / */
154 if (len
> 1 && str
[len
-1] == '/') {
162 if (w
== panel
->icoaB
)
164 else if (w
== panel
->pixaB
)
167 i
= WMGetListSelectedItemRow(lPtr
);
169 addPathToList(lPtr
, i
, str
);
170 WMSetListBottomPosition(lPtr
, WMGetListNumberOfRows(lPtr
));
181 paintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
184 int width
, height
, x
, y
;
185 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
186 WMScreen
*scr
= WMWidgetScreen(lPtr
);
187 Display
*dpy
= WMScreenDisplay(scr
);
189 width
= rect
->size
.width
;
190 height
= rect
->size
.height
;
194 if (state
& WLDSSelected
)
195 XFillRectangle(dpy
, d
, WMColorGC(panel
->white
), x
, y
, width
,
198 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
201 WMDrawString(scr
, d
, WMColorGC(panel
->red
), panel
->font
, x
+4, y
,
204 WMDrawString(scr
, d
, WMColorGC(panel
->black
), panel
->font
, x
+4, y
,
212 storeData(_Panel
*panel
)
219 list
= PLMakeArrayFromElements(NULL
, NULL
);
220 for (i
=0; i
<WMGetListNumberOfRows(panel
->icoL
); i
++) {
221 p
= WMGetListItem(panel
->icoL
, i
)->text
;
222 tmp
= PLMakeString(p
);
223 PLAppendArrayElement(list
, tmp
);
225 SetObjectForKey(list
, "IconPath");
227 list
= PLMakeArrayFromElements(NULL
, NULL
);
228 for (i
=0; i
<WMGetListNumberOfRows(panel
->pixL
); i
++) {
229 p
= WMGetListItem(panel
->pixL
, i
)->text
;
230 tmp
= PLMakeString(p
);
231 PLAppendArrayElement(list
, tmp
);
233 SetObjectForKey(list
, "PixmapPath");
239 createPanel(Panel
*p
)
241 _Panel
*panel
= (_Panel
*)p
;
242 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
244 panel
->white
= WMWhiteColor(scr
);
245 panel
->black
= WMBlackColor(scr
);
246 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
247 panel
->font
= WMSystemFontOfSize(scr
, 12);
249 panel
->frame
= WMCreateFrame(panel
->win
);
250 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
251 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
254 panel
->icoF
= WMCreateFrame(panel
->frame
);
255 WMResizeWidget(panel
->icoF
, 230, 210);
256 WMMoveWidget(panel
->icoF
, 25, 10);
257 WMSetFrameTitle(panel
->icoF
, _("Icon Search Paths"));
259 panel
->icoL
= WMCreateList(panel
->icoF
);
260 WMResizeWidget(panel
->icoL
, 200, 147);
261 WMMoveWidget(panel
->icoL
, 15, 20);
262 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
263 WMHangData(panel
->icoL
, panel
);
265 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
266 WMResizeWidget(panel
->icoaB
, 90, 24);
267 WMMoveWidget(panel
->icoaB
, 125, 176);
268 WMSetButtonText(panel
->icoaB
, _("Add"));
269 WMSetButtonAction(panel
->icoaB
, browseForFile
, panel
);
270 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
272 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
273 WMResizeWidget(panel
->icorB
, 90, 24);
274 WMMoveWidget(panel
->icorB
, 15, 176);
275 WMSetButtonText(panel
->icorB
, _("Remove"));
276 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
278 WMMapSubwidgets(panel
->icoF
);
281 panel
->pixF
= WMCreateFrame(panel
->frame
);
282 WMResizeWidget(panel
->pixF
, 230, 210);
283 WMMoveWidget(panel
->pixF
, 270, 10);
284 WMSetFrameTitle(panel
->pixF
, _("Pixmap Search Paths"));
286 panel
->pixL
= WMCreateList(panel
->pixF
);
287 WMResizeWidget(panel
->pixL
, 200, 147);
288 WMMoveWidget(panel
->pixL
, 15, 20);
289 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
290 WMHangData(panel
->pixL
, panel
);
292 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
293 WMResizeWidget(panel
->pixaB
, 90, 24);
294 WMMoveWidget(panel
->pixaB
, 125, 176);
295 WMSetButtonText(panel
->pixaB
, _("Add"));
296 WMSetButtonAction(panel
->pixaB
, browseForFile
, panel
);
297 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
299 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
300 WMResizeWidget(panel
->pixrB
, 90, 24);
301 WMMoveWidget(panel
->pixrB
, 15, 176);
302 WMSetButtonText(panel
->pixrB
, _("Remove"));
303 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
306 WMMapSubwidgets(panel
->pixF
);
308 WMRealizeWidget(panel
->frame
);
309 WMMapSubwidgets(panel
->frame
);
317 InitPaths(WMScreen
*scr
, WMWindow
*win
)
321 panel
= wmalloc(sizeof(_Panel
));
322 memset(panel
, 0, sizeof(_Panel
));
324 panel
->sectionName
= _("Search Path Configuration");
326 panel
->description
= _("Search paths to use when looking for pixmaps\n"
331 panel
->callbacks
.createWidgets
= createPanel
;
332 panel
->callbacks
.updateDomain
= storeData
;
334 AddSection(panel
, ICON_FILE
);