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
;
57 #define ICON_FILE "paths"
61 addPathToList(WMList
*list
, int index
, char *path
)
63 char *fpath
= wexpandpath(path
);
66 item
= WMInsertListItem(list
, index
, path
);
68 if (access(fpath
, X_OK
)!=0) {
76 showData(_Panel
*panel
)
78 proplist_t array
, val
;
81 array
= GetObjectForKey("IconPath");
82 if (!array
|| !PLIsArray(array
)) {
84 wwarning(_("bad value in option IconPath. Using default path list"));
85 addPathToList(panel
->icoL
, -1, "~/pixmaps");
86 addPathToList(panel
->icoL
, -1, "~/GNUstep/Library/Icons");
87 addPathToList(panel
->icoL
, -1, "/usr/include/X11/pixmaps");
88 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Icons");
89 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
90 addPathToList(panel
->icoL
, -1, "/usr/share/WindowMaker/Icons");
92 for (i
=0; i
<PLGetNumberOfElements(array
); i
++) {
93 val
= PLGetArrayElement(array
, i
);
94 addPathToList(panel
->icoL
, -1, PLGetString(val
));
98 array
= GetObjectForKey("PixmapPath");
99 if (!array
|| !PLIsArray(array
)) {
101 wwarning(_("bad value in option PixmapPath. Using default path list"));
102 addPathToList(panel
->pixL
, -1, "~/pixmaps");
103 addPathToList(panel
->pixL
, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
104 addPathToList(panel
->pixL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
106 for (i
=0; i
<PLGetNumberOfElements(array
); i
++) {
107 val
= PLGetArrayElement(array
, i
);
108 addPathToList(panel
->pixL
, -1, PLGetString(val
));
115 pushButton(WMWidget
*w
, void *data
)
117 _Panel
*panel
= (_Panel
*)data
;
121 if (w
== panel
->icorB
) {
122 i
= WMGetListSelectedItemRow(panel
->icoL
);
125 WMRemoveListItem(panel
->icoL
, i
);
129 if (w
== panel
->pixrB
) {
130 i
= WMGetListSelectedItemRow(panel
->pixL
);
133 WMRemoveListItem(panel
->pixL
, i
);
139 browseForFile(WMWidget
*w
, void *data
)
141 _Panel
*panel
= (_Panel
*)data
;
142 WMFilePanel
*filePanel
;
144 filePanel
= WMGetOpenPanel(WMWidgetScreen(w
));
146 WMSetFilePanelCanChooseFiles(filePanel
, False
);
148 if (WMRunModalFilePanelForDirectory(filePanel
, panel
->win
, "/",
149 _("Select directory"), NULL
) == True
) {
150 char *str
= WMGetFilePanelFileName(filePanel
);
153 int len
= strlen(str
);
155 /* Remove the trailing '/' except if the path is exactly / */
156 if (len
> 1 && str
[len
-1] == '/') {
164 if (w
== panel
->icoaB
)
166 else if (w
== panel
->pixaB
)
169 i
= WMGetListSelectedItemRow(lPtr
);
171 addPathToList(lPtr
, i
, str
);
172 WMSetListBottomPosition(lPtr
, WMGetListNumberOfRows(lPtr
));
183 paintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
186 int width
, height
, x
, y
;
187 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
188 WMScreen
*scr
= WMWidgetScreen(lPtr
);
189 Display
*dpy
= WMScreenDisplay(scr
);
191 width
= rect
->size
.width
;
192 height
= rect
->size
.height
;
196 if (state
& WLDSSelected
)
197 XFillRectangle(dpy
, d
, WMColorGC(panel
->white
), x
, y
, width
,
200 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
203 WMDrawString(scr
, d
, WMColorGC(panel
->red
), panel
->font
, x
+4, y
,
206 WMDrawString(scr
, d
, WMColorGC(panel
->black
), panel
->font
, x
+4, y
,
214 storeData(_Panel
*panel
)
221 list
= PLMakeArrayFromElements(NULL
, NULL
);
222 for (i
=0; i
<WMGetListNumberOfRows(panel
->icoL
); i
++) {
223 p
= WMGetListItem(panel
->icoL
, i
)->text
;
224 tmp
= PLMakeString(p
);
225 PLAppendArrayElement(list
, tmp
);
227 SetObjectForKey(list
, "IconPath");
229 list
= PLMakeArrayFromElements(NULL
, NULL
);
230 for (i
=0; i
<WMGetListNumberOfRows(panel
->pixL
); i
++) {
231 p
= WMGetListItem(panel
->pixL
, i
)->text
;
232 tmp
= PLMakeString(p
);
233 PLAppendArrayElement(list
, tmp
);
235 SetObjectForKey(list
, "PixmapPath");
241 createPanel(Panel
*p
)
243 _Panel
*panel
= (_Panel
*)p
;
244 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
247 panel
->white
= WMWhiteColor(scr
);
248 panel
->black
= WMBlackColor(scr
);
249 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
250 panel
->font
= WMSystemFontOfSize(scr
, 12);
252 panel
->frame
= WMCreateFrame(panel
->win
);
253 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
254 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
256 panel
->tabv
= WMCreateTabView(panel
->frame
);
257 WMMoveWidget(panel
->tabv
, 12, 10);
258 WMResizeWidget(panel
->tabv
, 500, 215);
263 panel
->icoF
= WMCreateFrame(panel
->frame
);
264 WMSetFrameRelief(panel
->icoF
, WRFlat
);
265 WMResizeWidget(panel
->icoF
, 230, 210);
267 tab
= WMCreateTabViewItemWithIdentifier(0);
268 WMSetTabViewItemView(tab
, WMWidgetView(panel
->icoF
));
269 WMAddItemInTabView(panel
->tabv
, tab
);
270 WMSetTabViewItemLabel(tab
, _("Icon Search Paths"));
272 panel
->icoL
= WMCreateList(panel
->icoF
);
273 WMResizeWidget(panel
->icoL
, 480, 147);
274 WMMoveWidget(panel
->icoL
, 10, 10);
275 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
276 WMHangData(panel
->icoL
, panel
);
278 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
279 WMResizeWidget(panel
->icoaB
, 95, 24);
280 WMMoveWidget(panel
->icoaB
, 293, 165);
281 WMSetButtonText(panel
->icoaB
, _("Add"));
282 WMSetButtonAction(panel
->icoaB
, browseForFile
, panel
);
283 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
285 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
286 WMResizeWidget(panel
->icorB
, 95, 24);
287 WMMoveWidget(panel
->icorB
, 395, 165);
288 WMSetButtonText(panel
->icorB
, _("Remove"));
289 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
291 WMMapSubwidgets(panel
->icoF
);
294 panel
->pixF
= WMCreateFrame(panel
->frame
);
295 WMSetFrameRelief(panel
->pixF
, WRFlat
);
296 WMResizeWidget(panel
->pixF
, 230, 210);
298 tab
= WMCreateTabViewItemWithIdentifier(0);
299 WMSetTabViewItemView(tab
, WMWidgetView(panel
->pixF
));
300 WMAddItemInTabView(panel
->tabv
, tab
);
301 WMSetTabViewItemLabel(tab
, _("Pixmap Search Paths"));
303 panel
->pixL
= WMCreateList(panel
->pixF
);
304 WMResizeWidget(panel
->pixL
, 480, 147);
305 WMMoveWidget(panel
->pixL
, 10, 10);
306 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
307 WMHangData(panel
->pixL
, panel
);
309 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
310 WMResizeWidget(panel
->pixaB
, 95, 24);
311 WMMoveWidget(panel
->pixaB
, 293, 165);
312 WMSetButtonText(panel
->pixaB
, _("Add"));
313 WMSetButtonAction(panel
->pixaB
, browseForFile
, panel
);
314 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
316 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
317 WMResizeWidget(panel
->pixrB
, 95, 24);
318 WMMoveWidget(panel
->pixrB
, 395, 165);
319 WMSetButtonText(panel
->pixrB
, _("Remove"));
320 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
323 WMMapSubwidgets(panel
->pixF
);
325 WMRealizeWidget(panel
->frame
);
326 WMMapSubwidgets(panel
->frame
);
334 InitPaths(WMScreen
*scr
, WMWindow
*win
)
338 panel
= wmalloc(sizeof(_Panel
));
339 memset(panel
, 0, sizeof(_Panel
));
341 panel
->sectionName
= _("Search Path Configuration");
343 panel
->description
= _("Search paths to use when looking for pixmaps\n"
348 panel
->callbacks
.createWidgets
= createPanel
;
349 panel
->callbacks
.updateDomain
= storeData
;
351 AddSection(panel
, ICON_FILE
);