1 /* Paths.c- pixmap/icon paths
3 * WPrefs - WindowMaker 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
, Drawable d
, char *text
, int state
, WMRect
*rect
)
228 int width
, height
, x
, y
;
229 _Panel
*panel
= (_Panel
*)WMGetHangedData(lPtr
);
230 WMScreen
*scr
= WMWidgetScreen(lPtr
);
231 Display
*dpy
= WMScreenDisplay(scr
);
233 width
= rect
->size
.width
;
234 height
= rect
->size
.height
;
238 if (state
& WLDSSelected
)
239 XFillRectangle(dpy
, d
, WMColorGC(panel
->white
), x
, y
, width
,
242 XClearArea(dpy
, d
, x
, y
, width
, height
, False
);
245 WMDrawString(scr
, d
, WMColorGC(panel
->red
), panel
->font
, x
+4, y
,
248 WMDrawString(scr
, d
, WMColorGC(panel
->black
), panel
->font
, x
+4, y
,
256 storeData(_Panel
*panel
)
263 list
= PLMakeArrayFromElements(NULL
, NULL
);
264 for (i
=0; i
<WMGetListNumberOfRows(panel
->icoL
); i
++) {
265 p
= WMGetListItem(panel
->icoL
, i
)->text
;
266 tmp
= PLMakeString(p
);
267 PLAppendArrayElement(list
, tmp
);
269 SetObjectForKey(list
, "IconPath");
271 list
= PLMakeArrayFromElements(NULL
, NULL
);
272 for (i
=0; i
<WMGetListNumberOfRows(panel
->pixL
); i
++) {
273 p
= WMGetListItem(panel
->pixL
, i
)->text
;
274 tmp
= PLMakeString(p
);
275 PLAppendArrayElement(list
, tmp
);
277 SetObjectForKey(list
, "PixmapPath");
283 createPanel(Panel
*p
)
285 _Panel
*panel
= (_Panel
*)p
;
286 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
288 panel
->white
= WMWhiteColor(scr
);
289 panel
->black
= WMBlackColor(scr
);
290 panel
->red
= WMCreateRGBColor(scr
, 0xffff, 0, 0, True
);
291 panel
->font
= WMSystemFontOfSize(scr
, 12);
293 panel
->frame
= WMCreateFrame(panel
->win
);
294 WMResizeWidget(panel
->frame
, FRAME_WIDTH
, FRAME_HEIGHT
);
295 WMMoveWidget(panel
->frame
, FRAME_LEFT
, FRAME_TOP
);
298 panel
->icoF
= WMCreateFrame(panel
->frame
);
299 WMResizeWidget(panel
->icoF
, 230, 210);
300 WMMoveWidget(panel
->icoF
, 25, 10);
301 WMSetFrameTitle(panel
->icoF
, _("Icon Search Paths"));
303 panel
->icoL
= WMCreateList(panel
->icoF
);
304 WMResizeWidget(panel
->icoL
, 200, 120);
305 WMMoveWidget(panel
->icoL
, 15, 20);
306 WMSetListAction(panel
->icoL
, listClick
, panel
);
307 WMSetListUserDrawProc(panel
->icoL
, paintItem
);
308 WMHangData(panel
->icoL
, panel
);
310 panel
->icoaB
= WMCreateCommandButton(panel
->icoF
);
311 WMResizeWidget(panel
->icoaB
, 90, 24);
312 WMMoveWidget(panel
->icoaB
, 125, 145);
313 WMSetButtonText(panel
->icoaB
, _("Add"));
314 WMSetButtonAction(panel
->icoaB
, pushButton
, panel
);
315 WMSetButtonImagePosition(panel
->icoaB
, WIPRight
);
317 panel
->icorB
= WMCreateCommandButton(panel
->icoF
);
318 WMResizeWidget(panel
->icorB
, 90, 24);
319 WMMoveWidget(panel
->icorB
, 15, 145);
320 WMSetButtonText(panel
->icorB
, _("Remove"));
321 WMSetButtonAction(panel
->icorB
, pushButton
, panel
);
323 panel
->icoT
= WMCreateTextField(panel
->icoF
);
324 WMResizeWidget(panel
->icoT
, 200, 20);
325 WMMoveWidget(panel
->icoT
, 15, 175);
326 WMAddNotificationObserver(textEditedObserver
, panel
,
327 WMTextDidEndEditingNotification
, panel
->icoT
);
328 WMAddNotificationObserver(textBeginObserver
, panel
,
329 WMTextDidBeginEditingNotification
, panel
->icoT
);
331 WMMapSubwidgets(panel
->icoF
);
334 panel
->pixF
= WMCreateFrame(panel
->frame
);
335 WMResizeWidget(panel
->pixF
, 230, 210);
336 WMMoveWidget(panel
->pixF
, 270, 10);
337 WMSetFrameTitle(panel
->pixF
, _("Pixmap Search Paths"));
339 panel
->pixL
= WMCreateList(panel
->pixF
);
340 WMResizeWidget(panel
->pixL
, 200, 120);
341 WMMoveWidget(panel
->pixL
, 15, 20);
342 WMSetListAction(panel
->pixL
, listClick
, panel
);
343 WMSetListUserDrawProc(panel
->pixL
, paintItem
);
344 WMHangData(panel
->pixL
, panel
);
346 panel
->pixaB
= WMCreateCommandButton(panel
->pixF
);
347 WMResizeWidget(panel
->pixaB
, 90, 24);
348 WMMoveWidget(panel
->pixaB
, 125, 145);
349 WMSetButtonText(panel
->pixaB
, _("Add"));
350 WMSetButtonAction(panel
->pixaB
, pushButton
, panel
);
351 WMSetButtonImagePosition(panel
->pixaB
, WIPRight
);
353 panel
->pixrB
= WMCreateCommandButton(panel
->pixF
);
354 WMResizeWidget(panel
->pixrB
, 90, 24);
355 WMMoveWidget(panel
->pixrB
, 15, 145);
356 WMSetButtonText(panel
->pixrB
, _("Remove"));
357 WMSetButtonAction(panel
->pixrB
, pushButton
, panel
);
359 panel
->pixT
= WMCreateTextField(panel
->pixF
);
360 WMResizeWidget(panel
->pixT
, 200, 20);
361 WMMoveWidget(panel
->pixT
, 15, 175);
362 WMAddNotificationObserver(textEditedObserver
, panel
,
363 WMTextDidEndEditingNotification
, panel
->pixT
);
364 WMAddNotificationObserver(textBeginObserver
, panel
,
365 WMTextDidBeginEditingNotification
, panel
->pixT
);
367 WMMapSubwidgets(panel
->pixF
);
369 WMRealizeWidget(panel
->frame
);
370 WMMapSubwidgets(panel
->frame
);
378 InitPaths(WMScreen
*scr
, WMWindow
*win
)
382 panel
= wmalloc(sizeof(_Panel
));
383 memset(panel
, 0, sizeof(_Panel
));
385 panel
->sectionName
= _("Search Path Configuration");
389 panel
->callbacks
.createWidgets
= createPanel
;
390 panel
->callbacks
.updateDomain
= storeData
;
392 AddSection(panel
, ICON_FILE
);