3 #include <WINGs/WINGsP.h> /* for: scr->normalFont */
11 #define LABEL_HEIGHT 16
12 #define LABEL_WIDTH 48
14 typedef struct _Panel
{
18 CallbackRec callbacks
;
22 WMLabel
*defaultLabel
;
25 WMTextField
*execField
;
36 displayDefault(_Panel
*panel
)
41 exec
= FSGetStringForNameKey(panel
->fileInfo
->extn
, "viewer");
45 WMSetLabelText(panel
->defaultLabel
, exec
);
46 WMSetTextFieldText(panel
->execField
, exec
);
50 WMSetLabelText(panel
->defaultLabel
, "");
51 WMSetTextFieldText(panel
->execField
, "");
54 WMSetButtonImagePosition(panel
->appBtn
, WIPNoImage
);
55 WMSelectListItem(panel
->appList
, -1);
65 showData(_Panel
*panel
)
67 WMPropList
* array
= NULL
;
69 WMClearList(panel
->appList
);
71 array
= FSGetUDObjectForKey(defaultsDB
, "EXE");
72 if(array
&& WMIsPLArray(array
))
76 numElem
= WMGetPropListItemCount(array
);
77 for(i
= 0; i
< numElem
; i
++)
78 WMAddListItem(panel
->appList
,
79 WMGetPropListDescription(WMGetFromPLArray(array
, i
), False
));
81 WMSortListItems(panel
->appList
);
83 displayDefault(panel
);
88 storeData(_Panel
*panel
)
92 exec
= WMGetTextFieldText(panel
->execField
);
96 WMPropList
* array
= NULL
;
98 FSSetStringForNameKey(panel
->fileInfo
->extn
, "viewer", exec
);
99 array
= FSGetUDObjectForKey(defaultsDB
, "EXTN");
100 if(array
&& WMIsPLArray(array
))
101 InsertArrayElement(array
, WMCreatePLString(panel
->fileInfo
->extn
));
107 handleAppBtnEvents(XEvent
*event
, void *data
)
109 /* if(WMIsDoubleClick(event)) */
110 /* printf("Double Click\n"); */
114 appListClick(WMWidget
*self
, void *data
)
119 char *selected
= NULL
;
120 Panel
*panel
= (Panel
*) data
;
122 selected
= ((WMListItem
*)WMGetListSelectedItem(panel
->appList
))->text
;
124 tmp
= FSGetStringForNameKey(selected
, "icon");
125 icon
= LocateImage(tmp
);
126 exec
= FSGetStringForNameKey(selected
, "exec");
138 pixmap
= WMCreateBlendedPixmapFromFile(WMWidgetScreen(panel
->win
),
142 WMSetButtonImagePosition(panel
->appBtn
, WIPImageOnly
);
143 WMSetButtonImage(panel
->appBtn
, pixmap
);
146 WMSetButtonImagePosition(panel
->appBtn
, WIPNoImage
);
149 WMSetButtonImagePosition(panel
->appBtn
, WIPNoImage
);
152 WMSetTextFieldText(panel
->execField
, exec
);
155 WMSetTextFieldText(panel
->execField
, "");
167 buttonClick(WMWidget
*self
, void *data
)
169 Panel
*panel
= (Panel
*)data
;
171 if ((WMButton
*)self
== panel
->okBtn
)
175 WMSetButtonEnabled(panel
->revertBtn
, True
);
177 else if ((WMButton
*)self
== panel
->revertBtn
)
179 displayDefault(panel
);
180 WMSetButtonEnabled(panel
->revertBtn
, False
);
182 else if ((WMButton
*)self
== panel
->appBtn
)
185 WMListItem
*item
= NULL
;
187 item
= WMGetListSelectedItem(panel
->appList
);
188 exeStr
= WMGetTextFieldText(panel
->execField
);
190 if (item
&& strcmp("", exeStr
))
195 path
= GetPathnameFromPathName(panel
->fileInfo
->path
,
196 panel
->fileInfo
->name
);
198 exec
= FSParseExecString(path
, exeStr
);
210 createAppList(Panel
*panel
)
212 panel
->appList
= WMCreateList(panel
->frame
);
214 WMMoveWidget(panel
->appList
, 8, 36);
215 WMResizeWidget(panel
->appList
, 180, 115);
216 WMSetListAction(panel
->appList
, appListClick
, panel
);
220 createClickLabel(Panel
*panel
)
224 l
= WMCreateLabel(panel
->frame
);
225 WMSetLabelWraps(l
, 1);
226 WMResizeWidget(l
, WIDTH
-8, LABEL_HEIGHT
*2);
227 WMMoveWidget(l
, 4, 0);
228 WMSetLabelText(l
, _("Click button to edit selected document"));
229 /* WMSetLabelTextAlignment(l, WACenter); */
230 WMSetLabelRelief(l
, WRFlat
);
231 WMSetLabelTextColor(l
, WMDarkGrayColor(WMWidgetScreen(panel
->win
)));
236 createDefaultLabels(Panel
*panel
)
242 l
= WMCreateLabel(panel
->frame
);
243 WMSetLabelText(l
, _("Default:"));
244 scr
= WMWidgetScreen(panel
->win
);
245 tw
= WMWidthOfString(scr
->normalFont
, WMGetLabelText(l
),
246 strlen(WMGetLabelText(l
)));
247 WMResizeWidget(l
, tw
+4, LABEL_HEIGHT
);
248 WMMoveWidget(l
, 4, 182);
249 WMSetLabelRelief(l
, WRFlat
);
250 WMSetLabelTextColor(l
, WMDarkGrayColor(WMWidgetScreen(panel
->win
)));
251 /* Position of "defaultLabel" is adjusted by width of "l"
252 to make i18n support easier for translators */
253 panel
->defaultLabel
= WMCreateLabel(panel
->frame
);
254 /* Initilalization without text */
255 WMSetLabelText(panel
->defaultLabel
,"");
256 WMResizeWidget(panel
->defaultLabel
, WIDTH
, LABEL_HEIGHT
);
257 /* x-Position should be: 4 + width("Default:") + 4 */
258 WMMoveWidget(panel
->defaultLabel
, 8+tw
, 182);
259 WMSetLabelRelief(panel
->defaultLabel
, WRFlat
);
263 createSetDefaultLabels(Panel
*panel
)
267 l
= WMCreateLabel(panel
->frame
);
268 WMSetLabelWraps(l
, 1);
269 WMResizeWidget(l
, WIDTH
-8, LABEL_HEIGHT
*2);
270 WMMoveWidget(l
, 4, 206);
271 WMSetLabelText(l
, _("Click \"Set Default\" to set default "\
272 "application for all documents with this extension."));
273 WMSetLabelTextAlignment(l
, WALeft
);
274 WMSetLabelRelief(l
, WRFlat
);
275 WMSetLabelTextColor(l
, WMDarkGrayColor(WMWidgetScreen(panel
->win
)));
280 createExecField(Panel
*panel
)
282 panel
->execField
= WMCreateTextField(panel
->frame
);
283 WMMoveWidget(panel
->execField
, 8, 159);
284 WMResizeWidget(panel
->execField
, 256, 18);
288 createButtons(Panel
*panel
)
290 panel
->revertBtn
= WMCreateCommandButton(panel
->frame
);
291 WMMoveWidget(panel
->revertBtn
, 16, HEIGHT
-24);
292 WMResizeWidget(panel
->revertBtn
, 115, 24);
293 WMSetButtonText(panel
->revertBtn
, _("Revert"));
294 WMSetButtonAction(panel
->revertBtn
, buttonClick
, panel
);
295 WMSetButtonEnabled(panel
->revertBtn
, False
);
297 panel
->okBtn
= WMCreateCommandButton(panel
->frame
);
298 WMMoveWidget(panel
->okBtn
, 140, HEIGHT
-24);
299 WMResizeWidget(panel
->okBtn
, 115, 24);
300 WMSetButtonText(panel
->okBtn
, _("Set Default"));
301 WMSetButtonImage(panel
->okBtn
,
302 WMGetSystemPixmap(WMWidgetScreen(panel
->win
),
304 WMSetButtonAltImage(panel
->okBtn
,
305 WMGetSystemPixmap(WMWidgetScreen(panel
->win
),
306 WSIHighlightedReturnArrow
));
307 WMSetButtonImagePosition(panel
->okBtn
, WIPRight
);
308 WMSetButtonEnabled(panel
->okBtn
, True
);
309 WMSetButtonAction(panel
->okBtn
, buttonClick
, panel
);
311 panel
->appBtn
= WMCreateCommandButton(panel
->frame
);
312 WMMoveWidget(panel
->appBtn
, 196, 59); /* 36 + (115/2) - 68/2 = 59 */
313 WMResizeWidget(panel
->appBtn
, 68, 68);
314 WMSetButtonEnabled(panel
->appBtn
, True
);
315 WMSetButtonImagePosition(panel
->appBtn
, WIPImageOnly
);
316 WMSetButtonAction(panel
->appBtn
, buttonClick
, panel
);
317 WMCreateEventHandler(WMWidgetView(panel
->appBtn
), ButtonPressMask
,
318 handleAppBtnEvents
, panel
);
322 createPanel(Panel
*p
)
324 _Panel
*panel
= (_Panel
*)p
;
325 panel
->frame
= WMCreateFrame(panel
->win
);
327 WMResizeWidget(panel
->frame
, WIDTH
, HEIGHT
);
328 WMMoveWidget(panel
->frame
, 0, 138);
329 WMSetFrameRelief(panel
->frame
, WRFlat
);
331 createSetDefaultLabels(panel
);
332 createAppList(panel
);
333 createDefaultLabels(panel
);
334 createClickLabel(panel
);
335 createExecField(panel
);
336 createButtons(panel
);
338 WMRealizeWidget(panel
->frame
);
339 WMMapSubwidgets(panel
->frame
);
344 InitViewer(WMWindow
*win
, FileInfo
*fileInfo
)
348 panel
= wmalloc(sizeof(_Panel
));
349 memset(panel
, 0, sizeof(_Panel
));
351 panel
->sectionName
= (char *) wmalloc(strlen(_("Viewer Inspector"))+1);
352 strcpy(panel
->sectionName
, _("Viewer Inspector"));
356 panel
->callbacks
.createWidgets
= createPanel
;
357 panel
->callbacks
.updateDomain
= storeData
;
358 panel
->callbacks
.updateDisplay
= showData
;
360 panel
->fileInfo
= fileInfo
;