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
;
56 #define ICON_FILE "paths"
58 static void addPathToList(WMList
* list
, int index
, char *path
)
60 char *fpath
= wexpandpath(path
);
63 item
= WMInsertListItem(list
, index
, path
);
65 if (access(fpath
, X_OK
) != 0) {
71 static void showData(_Panel
* panel
)
73 WMPropList
*array
, *val
;
76 array
= GetObjectForKey("IconPath");
77 if (!array
|| !WMIsPLArray(array
)) {
79 wwarning(_("bad value in option IconPath. Using default path list"));
80 addPathToList(panel
->icoL
, -1, "~/pixmaps");
81 addPathToList(panel
->icoL
, -1, "~/GNUstep/Library/Icons");
82 addPathToList(panel
->icoL
, -1, "/usr/include/X11/pixmaps");
83 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Icons");
84 addPathToList(panel
->icoL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
85 addPathToList(panel
->icoL
, -1, "/usr/share/WindowMaker/Icons");
87 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
88 val
= WMGetFromPLArray(array
, i
);
89 addPathToList(panel
->icoL
, -1, WMGetFromPLString(val
));
93 array
= GetObjectForKey("PixmapPath");
94 if (!array
|| !WMIsPLArray(array
)) {
96 wwarning(_("bad value in option PixmapPath. Using default path list"));
97 addPathToList(panel
->pixL
, -1, "~/pixmaps");
98 addPathToList(panel
->pixL
, -1, "~/GNUstep/Library/WindowMaker/Pixmaps");
99 addPathToList(panel
->pixL
, -1, "/usr/local/share/WindowMaker/Pixmaps");
101 for (i
= 0; i
< WMGetPropListItemCount(array
); i
++) {
102 val
= WMGetFromPLArray(array
, i
);
103 addPathToList(panel
->pixL
, -1, WMGetFromPLString(val
));
108 static void pushButton(WMWidget
* w
, void *data
)
110 _Panel
*panel
= (_Panel
*) data
;
114 if (w
== panel
->icorB
) {
115 i
= WMGetListSelectedItemRow(panel
->icoL
);
118 WMRemoveListItem(panel
->icoL
, i
);
122 if (w
== panel
->pixrB
) {
123 i
= WMGetListSelectedItemRow(panel
->pixL
);
126 WMRemoveListItem(panel
->pixL
, i
);
130 static void browseForFile(WMWidget
* w
, void *data
)
132 _Panel
*panel
= (_Panel
*) data
;
133 WMFilePanel
*filePanel
;
135 assert(w
== panel
->icoaB
|| w
== panel
->pixaB
);
137 filePanel
= WMGetOpenPanel(WMWidgetScreen(w
));
139 WMSetFilePanelCanChooseFiles(filePanel
, False
);
141 if (WMRunModalFilePanelForDirectory(filePanel
, panel
->parent
, "/", _("Select directory"), NULL
) == True
) {
142 char *str
= WMGetFilePanelFileName(filePanel
);
145 int len
= strlen(str
);
147 /* Remove the trailing '/' except if the path is exactly / */
148 if (len
> 1 && str
[len
- 1] == '/') {
156 if (w
== panel
->icoaB
)
158 else if (w
== panel
->pixaB
)
161 i
= WMGetListSelectedItemRow(lPtr
);
164 addPathToList(lPtr
, i
, str
);
165 WMSetListBottomPosition(lPtr
, WMGetListNumberOfRows(lPtr
));
173 static void paintItem(WMList
* lPtr
, int index
, Drawable d
, char *text
, int state
, WMRect
* rect
)
175 int width
, height
, x
, y
;
176 _Panel
*panel
= (_Panel
*) WMGetHangedData(lPtr
);
177 WMScreen
*scr
= WMWidgetScreen(lPtr
);
178 Display
*dpy
= WMScreenDisplay(scr
);
179 WMColor
*backColor
= (state
& WLDSSelected
) ? panel
->white
: panel
->gray
;
181 width
= rect
->size
.width
;
182 height
= rect
->size
.height
;
186 XFillRectangle(dpy
, d
, WMColorGC(backColor
), x
, y
, width
, height
);
189 WMDrawString(scr
, d
, panel
->red
, panel
->font
, x
+ 4, y
, text
, strlen(text
));
191 WMDrawString(scr
, d
, panel
->black
, panel
->font
, x
+ 4, y
, text
, strlen(text
));
195 static void storeData(_Panel
* panel
)
202 list
= WMCreatePLArray(NULL
, NULL
);
203 for (i
= 0; i
< WMGetListNumberOfRows(panel
->icoL
); i
++) {
204 p
= WMGetListItem(panel
->icoL
, i
)->text
;
205 tmp
= WMCreatePLString(p
);
206 WMAddToPLArray(list
, tmp
);
208 SetObjectForKey(list
, "IconPath");
210 list
= WMCreatePLArray(NULL
, NULL
);
211 for (i
= 0; i
< WMGetListNumberOfRows(panel
->pixL
); i
++) {
212 p
= WMGetListItem(panel
->pixL
, i
)->text
;
213 tmp
= WMCreatePLString(p
);
214 WMAddToPLArray(list
, tmp
);
216 SetObjectForKey(list
, "PixmapPath");
219 static void createPanel(Panel
* p
)
221 _Panel
*panel
= (_Panel
*) p
;
222 WMScreen
*scr
= WMWidgetScreen(panel
->parent
);
225 panel
->white
= WMWhiteColor(scr
);
226 panel
->black
= WMBlackColor(scr
);
227 panel
->gray
= WMGrayColor(scr
);
228 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
229 panel
->font
= WMSystemFontOfSize(scr
, 12);
231 panel
->box
= WMCreateBox(panel
->parent
);
232 WMSetViewExpandsToParent(WMWidgetView(panel
->box
), 2, 2, 2, 2);
234 panel
->tabv
= WMCreateTabView(panel
->box
);
235 WMMoveWidget(panel
->tabv
, 12, 10);
236 WMResizeWidget(panel
->tabv
, 500, 215);
239 panel
->icoF
= WMCreateFrame(panel
->box
);
240 WMSetFrameRelief(panel
->icoF
, WRFlat
);
241 WMResizeWidget(panel
->icoF
, 230, 210);
243 tab
= WMCreateTabViewItemWithIdentifier(0);
244 WMSetTabViewItemView(tab
, WMWidgetView(panel
->icoF
));
245 WMAddItemInTabView(panel
->tabv
, tab
);
246 WMSetTabViewItemLabel(tab
, _("Icon Search Paths"));
248 panel
->icoL
= WMCreateList(panel
->icoF
);
249 WMResizeWidget(panel
->icoL
, 480, 147);
250 WMMoveWidget(panel
->icoL
, 10, 10);
251 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
252 WMHangData(panel
->icoL
, panel
);
254 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
255 WMResizeWidget(panel
->icoaB
, 95, 24);
256 WMMoveWidget(panel
->icoaB
, 293, 165);
257 WMSetButtonText(panel
->icoaB
, _("Add"));
258 WMSetButtonAction(panel
->icoaB
, browseForFile
, panel
);
259 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
261 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
262 WMResizeWidget(panel
->icorB
, 95, 24);
263 WMMoveWidget(panel
->icorB
, 395, 165);
264 WMSetButtonText(panel
->icorB
, _("Remove"));
265 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
267 WMMapSubwidgets(panel
->icoF
);
270 panel
->pixF
= WMCreateFrame(panel
->box
);
271 WMSetFrameRelief(panel
->pixF
, WRFlat
);
272 WMResizeWidget(panel
->pixF
, 230, 210);
274 tab
= WMCreateTabViewItemWithIdentifier(0);
275 WMSetTabViewItemView(tab
, WMWidgetView(panel
->pixF
));
276 WMAddItemInTabView(panel
->tabv
, tab
);
277 WMSetTabViewItemLabel(tab
, _("Pixmap Search Paths"));
279 panel
->pixL
= WMCreateList(panel
->pixF
);
280 WMResizeWidget(panel
->pixL
, 480, 147);
281 WMMoveWidget(panel
->pixL
, 10, 10);
282 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
283 WMHangData(panel
->pixL
, panel
);
285 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
286 WMResizeWidget(panel
->pixaB
, 95, 24);
287 WMMoveWidget(panel
->pixaB
, 293, 165);
288 WMSetButtonText(panel
->pixaB
, _("Add"));
289 WMSetButtonAction(panel
->pixaB
, browseForFile
, panel
);
290 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
292 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
293 WMResizeWidget(panel
->pixrB
, 95, 24);
294 WMMoveWidget(panel
->pixrB
, 395, 165);
295 WMSetButtonText(panel
->pixrB
, _("Remove"));
296 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
298 WMMapSubwidgets(panel
->pixF
);
300 WMRealizeWidget(panel
->box
);
301 WMMapSubwidgets(panel
->box
);
306 Panel
*InitPaths(WMScreen
* scr
, WMWidget
* parent
)
310 panel
= wmalloc(sizeof(_Panel
));
311 memset(panel
, 0, sizeof(_Panel
));
313 panel
->sectionName
= _("Search Path Configuration");
315 panel
->description
= _("Search paths to use when looking for pixmaps\n" "and icons.");
317 panel
->parent
= parent
;
319 panel
->callbacks
.createWidgets
= createPanel
;
320 panel
->callbacks
.updateDomain
= storeData
;
322 AddSection(panel
, ICON_FILE
);