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
{
31 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
->icoaB
) {
120 char *text
= WMGetTextFieldText(panel
->icoT
);
122 if (text
&& strlen(text
) > 0) {
123 i
= WMGetListSelectedItemRow(panel
->icoL
);
125 addPathToList(panel
->icoL
, i
, text
);
126 WMSetListBottomPosition(panel
->icoL
,
127 WMGetListNumberOfRows(panel
->icoL
));
132 WMSetTextFieldText(panel
->icoT
, NULL
);
133 } else if (w
== panel
->icorB
) {
134 i
= WMGetListSelectedItemRow(panel
->icoL
);
137 WMRemoveListItem(panel
->icoL
, i
);
141 if (w
== panel
->pixaB
) {
142 char *text
= WMGetTextFieldText(panel
->pixT
);
144 if (text
&& strlen(text
) > 0) {
145 i
= WMGetListSelectedItemRow(panel
->pixL
);
147 addPathToList(panel
->pixL
, i
, text
);
148 WMSetListBottomPosition(panel
->pixL
,
149 WMGetListNumberOfRows(panel
->pixL
));
153 WMSetTextFieldText(panel
->pixT
, NULL
);
154 } else if (w
== panel
->pixrB
) {
155 i
= WMGetListSelectedItemRow(panel
->pixL
);
158 WMRemoveListItem(panel
->pixL
, i
);
164 textEditedObserver(void *observerData
, WMNotification
*notification
)
166 _Panel
*panel
= (_Panel
*)observerData
;
168 switch ((int)WMGetNotificationClientData(notification
)) {
169 case WMReturnTextMovement
:
170 if (WMGetNotificationObject(notification
) == panel
->icoT
)
171 WMPerformButtonClick(panel
->icoaB
);
173 WMPerformButtonClick(panel
->pixaB
);
176 case WMIllegalTextMovement
:
177 if (WMGetNotificationObject(notification
) == panel
->icoT
) {
178 WMSetButtonImage(panel
->icoaB
, NULL
);
179 WMSetButtonImage(panel
->icoaB
, NULL
);
181 WMSetButtonImage(panel
->pixaB
, NULL
);
182 WMSetButtonImage(panel
->pixaB
, NULL
);
190 textBeginObserver(void *observerData
, WMNotification
*notification
)
192 _Panel
*panel
= (_Panel
*)observerData
;
193 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
194 WMPixmap
*arrow1
= WMGetSystemPixmap(scr
, WSIReturnArrow
);
195 WMPixmap
*arrow2
= WMGetSystemPixmap(scr
, WSIHighlightedReturnArrow
);
197 if (WMGetNotificationObject(notification
)==panel
->icoT
) {
198 WMSetButtonImage(panel
->icoaB
, arrow1
);
199 WMSetButtonAltImage(panel
->icoaB
, arrow2
);
201 WMSetButtonImage(panel
->pixaB
, arrow1
);
202 WMSetButtonAltImage(panel
->pixaB
, arrow2
);
209 listClick(WMWidget
*w
, void *data
)
211 _Panel
*panel
= (_Panel
*)data
;
214 if (w
== panel
->icoL
) {
215 t
= WMGetListSelectedItem(panel
->icoL
)->text
;
216 WMSetTextFieldText(panel
->icoT
, t
);
218 t
= WMGetListSelectedItem(panel
->pixL
)->text
;
219 WMSetTextFieldText(panel
->pixT
, t
);
226 paintItem(WMList
*lPtr
, int index
, Drawable d
, char *text
, int state
,
229 int width
, height
, x
, y
;
230 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
231 WMScreen
*scr
= WMWidgetScreen(lPtr
);
232 Display
*dpy
= WMScreenDisplay(scr
);
234 width
= rect
->size
.width
;
235 height
= rect
->size
.height
;
239 if (state
& WLDSSelected
)
240 XFillRectangle(dpy
, d
, WMColorGC(panel
->white
), x
, y
, width
,
243 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
246 WMDrawString(scr
, d
, WMColorGC(panel
->red
), panel
->font
, x
+4, y
,
249 WMDrawString(scr
, d
, WMColorGC(panel
->black
), panel
->font
, x
+4, y
,
257 storeData(_Panel
*panel
)
264 list
= PLMakeArrayFromElements(NULL
, NULL
);
265 for (i
=0; i
<WMGetListNumberOfRows(panel
->icoL
); i
++) {
266 p
= WMGetListItem(panel
->icoL
, i
)->text
;
267 tmp
= PLMakeString(p
);
268 PLAppendArrayElement(list
, tmp
);
270 SetObjectForKey(list
, "IconPath");
272 list
= PLMakeArrayFromElements(NULL
, NULL
);
273 for (i
=0; i
<WMGetListNumberOfRows(panel
->pixL
); i
++) {
274 p
= WMGetListItem(panel
->pixL
, i
)->text
;
275 tmp
= PLMakeString(p
);
276 PLAppendArrayElement(list
, tmp
);
278 SetObjectForKey(list
, "PixmapPath");
284 createPanel(Panel
*p
)
286 _Panel
*panel
= (_Panel
*)p
;
287 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
289 panel
->white
= WMWhiteColor(scr
);
290 panel
->black
= WMBlackColor(scr
);
291 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
292 panel
->font
= WMSystemFontOfSize(scr
, 12);
294 panel
->frame
= WMCreateFrame(panel
->win
);
295 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
296 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
299 panel
->icoF
= WMCreateFrame(panel
->frame
);
300 WMResizeWidget(panel
->icoF
, 230, 210);
301 WMMoveWidget(panel
->icoF
, 25, 10);
302 WMSetFrameTitle(panel
->icoF
, _("Icon Search Paths"));
304 panel
->icoL
= WMCreateList(panel
->icoF
);
305 WMResizeWidget(panel
->icoL
, 200, 120);
306 WMMoveWidget(panel
->icoL
, 15, 20);
307 WMSetListAction(panel
->icoL
, listClick
, panel
);
308 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
309 WMHangData(panel
->icoL
, panel
);
311 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
312 WMResizeWidget(panel
->icoaB
, 90, 24);
313 WMMoveWidget(panel
->icoaB
, 125, 145);
314 WMSetButtonText(panel
->icoaB
, _("Add"));
315 WMSetButtonAction(panel
->icoaB
, pushButton
, panel
);
316 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
318 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
319 WMResizeWidget(panel
->icorB
, 90, 24);
320 WMMoveWidget(panel
->icorB
, 15, 145);
321 WMSetButtonText(panel
->icorB
, _("Remove"));
322 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
324 panel
->icoT
= WMCreateTextField(panel
->icoF
);
325 WMResizeWidget(panel
->icoT
, 200, 20);
326 WMMoveWidget(panel
->icoT
, 15, 175);
327 WMAddNotificationObserver(textEditedObserver
, panel
,
328 WMTextDidEndEditingNotification
, panel
->icoT
);
329 WMAddNotificationObserver(textBeginObserver
, panel
,
330 WMTextDidBeginEditingNotification
, panel
->icoT
);
332 WMMapSubwidgets(panel
->icoF
);
335 panel
->pixF
= WMCreateFrame(panel
->frame
);
336 WMResizeWidget(panel
->pixF
, 230, 210);
337 WMMoveWidget(panel
->pixF
, 270, 10);
338 WMSetFrameTitle(panel
->pixF
, _("Pixmap Search Paths"));
340 panel
->pixL
= WMCreateList(panel
->pixF
);
341 WMResizeWidget(panel
->pixL
, 200, 120);
342 WMMoveWidget(panel
->pixL
, 15, 20);
343 WMSetListAction(panel
->pixL
, listClick
, panel
);
344 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
345 WMHangData(panel
->pixL
, panel
);
347 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
348 WMResizeWidget(panel
->pixaB
, 90, 24);
349 WMMoveWidget(panel
->pixaB
, 125, 145);
350 WMSetButtonText(panel
->pixaB
, _("Add"));
351 WMSetButtonAction(panel
->pixaB
, pushButton
, panel
);
352 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
354 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
355 WMResizeWidget(panel
->pixrB
, 90, 24);
356 WMMoveWidget(panel
->pixrB
, 15, 145);
357 WMSetButtonText(panel
->pixrB
, _("Remove"));
358 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
360 panel
->pixT
= WMCreateTextField(panel
->pixF
);
361 WMResizeWidget(panel
->pixT
, 200, 20);
362 WMMoveWidget(panel
->pixT
, 15, 175);
363 WMAddNotificationObserver(textEditedObserver
, panel
,
364 WMTextDidEndEditingNotification
, panel
->pixT
);
365 WMAddNotificationObserver(textBeginObserver
, panel
,
366 WMTextDidBeginEditingNotification
, panel
->pixT
);
368 WMSetTextFieldNextTextField(panel
->pixT
, panel
->icoT
);
369 WMSetTextFieldPrevTextField(panel
->pixT
, panel
->icoT
);
371 WMMapSubwidgets(panel
->pixF
);
373 WMRealizeWidget(panel
->frame
);
374 WMMapSubwidgets(panel
->frame
);
382 InitPaths(WMScreen
*scr
, WMWindow
*win
)
386 panel
= wmalloc(sizeof(_Panel
));
387 memset(panel
, 0, sizeof(_Panel
));
389 panel
->sectionName
= _("Search Path Configuration");
393 panel
->callbacks
.createWidgets
= createPanel
;
394 panel
->callbacks
.updateDomain
= storeData
;
396 AddSection(panel
, ICON_FILE
);