1 /* Paths.c- pixmap/icon paths
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 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
;
58 #define ICON_FILE "paths"
62 addPathToList(WMList
*list
, int index
, char *path
)
64 char *fpath
= wexpandpath(path
);
67 item
= WMInsertListItem(list
, index
, path
);
69 if (access(fpath
, X_OK
)!=0) {
77 showData(_Panel
*panel
)
79 WMPropList
*array
, *val
;
82 array
= GetObjectForKey("IconPath");
83 if (!array
|| !WMIsPLArray(array
)) {
85 wwarning(_("bad value in option IconPath. Using default path list"));
86 addPathToList(panel
->icoL
, -1, "~/pixmaps");
87 addPathToList(panel
->icoL
, -1, "~/GNUstep/Library/Icons");
88 addPathToList(panel
->icoL
, -1, "/usr/include/X11/pixmaps");
89 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Icons");
90 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
91 addPathToList(panel
->icoL
, -1, "/usr/share/WindowMaker/Icons");
93 for (i
=0; i
<WMGetPropListItemCount(array
); i
++) {
94 val
= WMGetFromPLArray(array
, i
);
95 addPathToList(panel
->icoL
, -1, WMGetFromPLString(val
));
99 array
= GetObjectForKey("PixmapPath");
100 if (!array
|| !WMIsPLArray(array
)) {
102 wwarning(_("bad value in option PixmapPath. Using default path list"));
103 addPathToList(panel
->pixL
, -1, "~/pixmaps");
104 addPathToList(panel
->pixL
, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
105 addPathToList(panel
->pixL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
107 for (i
=0; i
<WMGetPropListItemCount(array
); i
++) {
108 val
= WMGetFromPLArray(array
, i
);
109 addPathToList(panel
->pixL
, -1, WMGetFromPLString(val
));
116 pushButton(WMWidget
*w
, void *data
)
118 _Panel
*panel
= (_Panel
*)data
;
122 if (w
== panel
->icorB
) {
123 i
= WMGetListSelectedItemRow(panel
->icoL
);
126 WMRemoveListItem(panel
->icoL
, i
);
130 if (w
== panel
->pixrB
) {
131 i
= WMGetListSelectedItemRow(panel
->pixL
);
134 WMRemoveListItem(panel
->pixL
, i
);
140 browseForFile(WMWidget
*w
, void *data
)
142 _Panel
*panel
= (_Panel
*)data
;
143 WMFilePanel
*filePanel
;
145 filePanel
= WMGetOpenPanel(WMWidgetScreen(w
));
147 WMSetFilePanelCanChooseFiles(filePanel
, False
);
149 if (WMRunModalFilePanelForDirectory(filePanel
, panel
->parent
, "/",
150 _("Select directory"), NULL
) == True
) {
151 char *str
= WMGetFilePanelFileName(filePanel
);
154 int len
= strlen(str
);
156 /* Remove the trailing '/' except if the path is exactly / */
157 if (len
> 1 && str
[len
-1] == '/') {
165 if (w
== panel
->icoaB
)
167 else if (w
== panel
->pixaB
)
170 i
= WMGetListSelectedItemRow(lPtr
);
172 addPathToList(lPtr
, i
, str
);
173 WMSetListBottomPosition(lPtr
, WMGetListNumberOfRows(lPtr
));
184 paintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
*rect
)
186 int width
, height
, x
, y
;
187 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
188 WMScreen
*scr
= WMWidgetScreen(lPtr
);
189 Display
*dpy
= WMScreenDisplay(scr
);
190 WMColor
*backColor
= (state
& WLDSSelected
) ? panel
->white
: panel
->gray
;
192 width
= rect
->size
.width
;
193 height
= rect
->size
.height
;
197 XFillRectangle(dpy
, d
, WMColorGC(backColor
), x
, y
, width
, height
);
200 WMDrawString(scr
, d
, panel
->red
, panel
->font
, x
+4, y
, text
, strlen(text
));
202 WMDrawString(scr
, d
, panel
->black
, panel
->font
, x
+4, y
, text
, strlen(text
));
209 storeData(_Panel
*panel
)
216 list
= WMCreatePLArray(NULL
, NULL
);
217 for (i
=0; i
<WMGetListNumberOfRows(panel
->icoL
); i
++) {
218 p
= WMGetListItem(panel
->icoL
, i
)->text
;
219 tmp
= WMCreatePLString(p
);
220 WMAddToPLArray(list
, tmp
);
222 SetObjectForKey(list
, "IconPath");
224 list
= WMCreatePLArray(NULL
, NULL
);
225 for (i
=0; i
<WMGetListNumberOfRows(panel
->pixL
); i
++) {
226 p
= WMGetListItem(panel
->pixL
, i
)->text
;
227 tmp
= WMCreatePLString(p
);
228 WMAddToPLArray(list
, tmp
);
230 SetObjectForKey(list
, "PixmapPath");
236 createPanel(Panel
*p
)
238 _Panel
*panel
= (_Panel
*)p
;
239 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
242 panel
->white
= WMWhiteColor(scr
);
243 panel
->black
= WMBlackColor(scr
);
244 panel
->gray
= WMGrayColor(scr
);
245 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
246 panel
->font
= WMSystemFontOfSize(scr
, 12);
248 panel
->box
= WMCreateBox(panel
->parent
);
249 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
252 panel
->tabv
= WMCreateTabView(panel
->box
);
253 WMMoveWidget(panel
->tabv
, 12, 10);
254 WMResizeWidget(panel
->tabv
, 500, 215);
259 panel
->icoF
= WMCreateFrame(panel
->box
);
260 WMSetFrameRelief(panel
->icoF
, WRFlat
);
261 WMResizeWidget(panel
->icoF
, 230, 210);
263 tab
= WMCreateTabViewItemWithIdentifier(0);
264 WMSetTabViewItemView(tab
, WMWidgetView(panel
->icoF
));
265 WMAddItemInTabView(panel
->tabv
, tab
);
266 WMSetTabViewItemLabel(tab
, _("Icon Search Paths"));
268 panel
->icoL
= WMCreateList(panel
->icoF
);
269 WMResizeWidget(panel
->icoL
, 480, 147);
270 WMMoveWidget(panel
->icoL
, 10, 10);
271 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
272 WMHangData(panel
->icoL
, panel
);
274 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
275 WMResizeWidget(panel
->icoaB
, 95, 24);
276 WMMoveWidget(panel
->icoaB
, 293, 165);
277 WMSetButtonText(panel
->icoaB
, _("Add"));
278 WMSetButtonAction(panel
->icoaB
, browseForFile
, panel
);
279 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
281 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
282 WMResizeWidget(panel
->icorB
, 95, 24);
283 WMMoveWidget(panel
->icorB
, 395, 165);
284 WMSetButtonText(panel
->icorB
, _("Remove"));
285 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
287 WMMapSubwidgets(panel
->icoF
);
290 panel
->pixF
= WMCreateFrame(panel
->box
);
291 WMSetFrameRelief(panel
->pixF
, WRFlat
);
292 WMResizeWidget(panel
->pixF
, 230, 210);
294 tab
= WMCreateTabViewItemWithIdentifier(0);
295 WMSetTabViewItemView(tab
, WMWidgetView(panel
->pixF
));
296 WMAddItemInTabView(panel
->tabv
, tab
);
297 WMSetTabViewItemLabel(tab
, _("Pixmap Search Paths"));
299 panel
->pixL
= WMCreateList(panel
->pixF
);
300 WMResizeWidget(panel
->pixL
, 480, 147);
301 WMMoveWidget(panel
->pixL
, 10, 10);
302 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
303 WMHangData(panel
->pixL
, panel
);
305 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
306 WMResizeWidget(panel
->pixaB
, 95, 24);
307 WMMoveWidget(panel
->pixaB
, 293, 165);
308 WMSetButtonText(panel
->pixaB
, _("Add"));
309 WMSetButtonAction(panel
->pixaB
, browseForFile
, panel
);
310 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
312 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
313 WMResizeWidget(panel
->pixrB
, 95, 24);
314 WMMoveWidget(panel
->pixrB
, 395, 165);
315 WMSetButtonText(panel
->pixrB
, _("Remove"));
316 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
319 WMMapSubwidgets(panel
->pixF
);
321 WMRealizeWidget(panel
->box
);
322 WMMapSubwidgets(panel
->box
);
330 InitPaths(WMScreen
*scr
, WMWidget
*parent
)
334 panel
= wmalloc(sizeof(_Panel
));
335 memset(panel
, 0, sizeof(_Panel
));
337 panel
->sectionName
= _("Search Path Configuration");
339 panel
->description
= _("Search paths to use when looking for pixmaps\n"
342 panel
->parent
= parent
;
344 panel
->callbacks
.createWidgets
= createPanel
;
345 panel
->callbacks
.updateDomain
= storeData
;
347 AddSection(panel
, ICON_FILE
);