Don't keep asking for S2EVENT_CONNECT reports if driver doen't
[AROS.git] / workbench / prefs / printer / editor.c
blob3225ec7e17f05eccb3ee9e6a1746dca1b9ce5257
1 /*
2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <stdlib.h>
9 #include <stdio.h> /* for sprintf */
11 #include <aros/debug.h>
13 #include <zune/customclasses.h>
14 #include <zune/prefseditor.h>
16 #include <proto/alib.h>
17 #include <proto/intuition.h>
18 #include <proto/muimaster.h>
19 #include <proto/dos.h>
21 #include "locale.h"
22 #include "editor.h"
23 #include "prefs.h"
25 /*** String Data ************************************************************/
27 STATIC CONST_STRPTR const ui_Pages[] = {
28 "Driver",
29 "Settings",
30 NULL,
33 STATIC CONST_STRPTR const ui_DeviceUnits[] = {
34 "Unit 0",
35 "Unit 1",
36 "Unit 2",
37 "Unit 3",
38 "Unit 4",
39 "Unit 5",
40 "Unit 6",
41 "Unit 7",
42 "Unit 8",
43 "Unit 9",
44 NULL,
47 #define UI_DEVICE_PARALLEL 0
48 #define UI_DEVICE_SERIAL 1
49 #define UI_DEVICE_PRINTTOFILE 2
50 #define UI_DEVICE_USBPARALLEL 3
52 STATIC CONST_STRPTR const ui_Port[] = {
53 "Parallel",
54 "Serial",
55 "Print to file",
56 "USB Printer",
57 NULL,
60 STATIC CONST_STRPTR const ui_PaperTypes[] = {
61 "Fanfold",
62 "Single",
63 NULL,
66 STATIC CONST_STRPTR const ui_PaperSize[] = {
67 "US Letter",
68 "US Legal",
69 "80 Column",
70 "132 Column",
71 "Custom",
72 "A0",
73 "A1",
74 "A2",
75 "A3",
76 "A4",
77 "A5",
78 "A6",
79 "A7",
80 "A8",
81 NULL,
84 #define UI_UNITS_IN 0 /* inches */
85 #define UI_UNITS_MM 1 /* millimeters */
86 #define UI_UNITS_PT 2 /* 1/72 of an inch */
88 STATIC CONST_STRPTR const ui_Units[] = {
89 "in",
90 "mm",
91 "pt",
92 NULL,
95 STATIC CONST_STRPTR const ui_Pitch[] = {
96 "10 cpi (Pica)",
97 "12 cpi (Elite)",
98 "17.1 cpi (Fine)",
99 NULL,
102 STATIC CONST_STRPTR const ui_Spacing[] = {
103 "6 lpi",
104 "8 lpi",
105 NULL,
108 STATIC CONST_STRPTR const ui_Quality[] = {
109 "Draft (72 dpi)",
110 "Letter (240 dpi)",
111 NULL,
114 STATIC CONST_STRPTR const ui_Aspect[] = {
115 "Portrait",
116 "Landscape",
117 NULL,
121 STATIC CONST_STRPTR const ui_Shade[] = {
122 "Black & White",
123 "Greyscape",
124 "Color",
125 "Greyscape 2",
126 NULL,
130 STATIC CONST_STRPTR const ui_Image[] = {
131 "Positive",
132 "Negative",
133 NULL,
137 STATIC CONST_STRPTR const ui_Dimensions[] = {
138 "Ignore",
139 "Bounded",
140 "Absolute",
141 "Pixel",
142 "Multiply",
143 NULL,
147 STATIC CONST_STRPTR const ui_Dithering[] = {
148 "Ordered",
149 "Halftone",
150 "Floyd-Steinberg",
151 NULL,
155 /*** Instance Data **********************************************************/
157 struct PrinterEditor_DATA
159 STRPTR UnitLabels[10];
160 int PrinterDeviceUnit;
162 Object *child;
164 Object *pd_UnitNum; /* Cycle */
165 Object *pd_UnitName; /* String */
167 Object *pt_DriverList; /* Dirlist */
168 Object *pt_Driver; /* Text */
169 Object *pt_Port; /* Cycle */
170 Object *pt_PaperType; /* Cycle */
171 Object *pt_PaperSize; /* Cycle */
172 Object *pt_PaperLength; /* String (integer) */
173 Object *pt_Pitch; /* Cycle */
174 Object *pt_Spacing; /* Cycle */
175 Object *pt_LeftMargin; /* String (integer) */
176 Object *pt_RightMargin; /* String (integer) */
177 Object *pt_Quality; /* Cycle */
179 Object *pu_UnitNum; /* String (integer) */
180 Object *pu_DeviceName; /* String */
181 Object *pu_DeviceNameCustom;/* CheckMark */
183 Object *pg_Aspect; /* Cycle */
184 Object *pg_Shade; /* Cycle */
185 Object *pg_Image; /* Cycle */
186 Object *pg_Threshold; /* Slider */
187 Object *pg_Dimensions; /* Cycle */
188 Object *pg_Dithering; /* Cycle */
189 Object *pg_GraphicFlags_Center; /* CheckMark */
190 Object *pg_GraphicFlags_AntiAlias; /* CheckMark */
191 Object *pg_GraphicFlags_IntScaling; /* CheckMark */
192 Object *pg_PrintDensity; /* Slider */
194 Object *pg_MaxUnits; /* Cycle */
195 Object *pg_PrintMaxWidth; /* String (integer) */
196 Object *pg_PrintMaxHeight; /* String (integer) */
198 Object *pg_OffsetUnits; /* Label */
199 Object *pg_PrintXOffset; /* String (integer) */
200 Object *pg_PrintYOffset; /* String (integer) */
203 STATIC VOID PrinterPrefs2Gadgets(Class *CLASS, Object *self);
204 STATIC VOID Gadgets2PrinterPrefs(Class *CLASS, Object *self);
206 /*** Macros *****************************************************************/
207 #define SETUP_INST_DATA struct PrinterEditor_DATA *data = INST_DATA(CLASS, self)
209 /*** Methods ****************************************************************/
210 Object *PrinterEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
212 int i;
213 #if SHOWICON
214 Object *icon;
215 #endif
216 D(bug("[PrinterEdit class] PrinterEdit Class New\n"));
219 * we create self first and then create the child,
220 * so we have self->data available already
222 self = (Object *) DoSuperNewTags
224 CLASS, self, NULL,
225 MUIA_PrefsEditor_Name, _(MSG_WINTITLE),
226 MUIA_PrefsEditor_Path, (IPTR) "SYS/printer.prefs",
227 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Printer",
229 TAG_DONE
232 if (self)
234 SETUP_INST_DATA;
236 data->PrinterDeviceUnit = 0;
237 for (i = 0; i < 10; i++) {
238 data->UnitLabels[i] = StrDup(ui_DeviceUnits[i]);
241 #if SHOWPIC
242 icon = MUI_NewObject("Dtpic.mui", MUIA_Dtpic_Name, "PROGDIR:Printer.info", TAG_DONE);
244 if (!icon) icon = HVSpace;
245 #endif
247 data->child =
248 VGroup,
249 /* Unit selection */
250 Child, (IPTR) HGroup,
251 #if SHOWPIC
252 Child, icon,
253 #endif
254 Child, (IPTR) LLabel1("Printer Unit:"),
255 Child, (IPTR) (data->pd_UnitNum = CycleObject,
256 MUIA_Cycle_Entries, (IPTR)data->UnitLabels,
257 End),
258 Child, (IPTR) LLabel1("Name:"),
259 Child, (IPTR) (data->pd_UnitName = StringObject,
260 StringFrame,
261 MUIA_String_MaxLen, UNITNAMESIZE,
262 End),
263 End,
264 /* Pages */
265 Child, (IPTR) RegisterGroup(ui_Pages),
266 /* Driver and Device page */
267 Child, (IPTR) HGroup,
268 Child, (IPTR) VGroup,
269 Child, (IPTR) CLabel("Select Driver:"),
270 Child, (IPTR) HCenter((ListviewObject,
271 MUIA_Listview_List, (IPTR) (data->pt_DriverList = DirlistObject,
272 InputListFrame,
273 MUIA_List_Format, (IPTR) "COL=0",
274 MUIA_List_AdjustWidth, TRUE,
275 MUIA_Dirlist_Directory, (IPTR)"DEVS:Printers",
276 MUIA_Dirlist_FilesOnly, TRUE,
277 MUIA_Dirlist_RejectIcons, TRUE,
278 End),
279 End)),
280 End,
281 Child, (IPTR) BalanceObject, End,
282 Child, (IPTR) VGroup,
283 Child, (IPTR) (HGroup,
284 Child, (IPTR) (data->pt_Driver = TextObject,
285 MUIA_Text_Contents, (IPTR)"generic",
286 End),
287 End),
288 Child, (IPTR) (HGroup,
289 Child, (IPTR) (data->pt_Port = CycleObject,
290 MUIA_Cycle_Entries, (IPTR) ui_Port,
291 End),
292 Child, (IPTR)HVSpace,
293 Child, (IPTR) Label("Unit:"),
294 Child, (IPTR) (data->pu_UnitNum = StringObject,
295 StringFrame,
296 MUIA_String_Format, MUIV_String_Format_Right,
297 MUIA_String_Accept, (IPTR)"0123456879",
298 MUIA_String_Integer, 0,
299 End),
300 End),
301 Child, (IPTR) HGroup,
302 Child, (IPTR) (data->pu_DeviceNameCustom = CheckMark(FALSE)),
303 Child, (IPTR) Label("Custom device:"),
304 Child, (IPTR) (data->pu_DeviceName = StringObject,
305 StringFrame,
306 MUIA_String_Format, MUIV_String_Format_Right,
307 MUIA_String_MaxLen, DEVICENAMESIZE,
308 End),
309 End,
310 Child, (IPTR)HVSpace,
311 End,
312 End,
313 /* Settings page */
314 Child, (IPTR) VGroup,
315 Child, (IPTR) HGroup,
316 Child, (IPTR) ColGroup(2),
317 Child, (IPTR) LLabel("Paper Type:"),
318 Child, (IPTR) (data->pt_PaperType = CycleObject,
319 MUIA_Cycle_Entries, (IPTR) ui_PaperTypes,
320 End),
321 Child, (IPTR) LLabel("Paper Size:"),
322 Child, (IPTR) (data->pt_PaperSize = CycleObject,
323 MUIA_Cycle_Entries, (IPTR) ui_PaperSize,
324 End),
325 Child, (IPTR) (data->pg_MaxUnits = CycleObject,
326 MUIA_Cycle_Entries, (IPTR) ui_Units,
327 End),
328 Child, (IPTR) HGroup,
329 Child, (IPTR) (data->pg_PrintMaxWidth = StringObject,
330 StringFrame,
331 MUIA_Disabled, TRUE,
332 MUIA_String_Format, MUIV_String_Format_Right,
333 MUIA_String_Accept, (IPTR)".0123456879",
334 MUIA_String_Contents, (IPTR)"0.0",
335 End),
336 Child, (IPTR) CLabel("x"),
337 Child, (IPTR) (data->pg_PrintMaxHeight = StringObject,
338 StringFrame,
339 MUIA_Disabled, TRUE,
340 MUIA_String_Format, MUIV_String_Format_Right,
341 MUIA_String_Accept, (IPTR)".0123456879",
342 MUIA_String_Contents, (IPTR)"0.0",
343 End),
344 End,
345 Child, (IPTR) LLabel("Quality:"),
346 Child, (IPTR) (data->pt_Quality = CycleObject,
347 MUIA_Cycle_Entries, (IPTR) ui_Quality,
348 End),
349 Child, (IPTR) LLabel("Pitch:"),
350 Child, (IPTR) (data->pt_Pitch = CycleObject,
351 MUIA_Cycle_Entries, (IPTR) ui_Pitch,
352 End),
353 Child, (IPTR) LLabel("Spacing:"),
354 Child, (IPTR) (data->pt_Spacing = CycleObject,
355 MUIA_Cycle_Entries, (IPTR) ui_Spacing,
356 End),
357 Child, (IPTR) LLabel("Left Margin:"),
358 Child, (IPTR) (data->pt_LeftMargin = StringObject,
359 StringFrame,
360 MUIA_String_Format, MUIV_String_Format_Right,
361 MUIA_String_Accept, (IPTR)"0123456879",
362 MUIA_String_Integer, 0,
363 End),
364 Child, (IPTR) LLabel("Right Margin:"),
365 Child, (IPTR) (data->pt_RightMargin = StringObject,
366 StringFrame,
367 MUIA_String_Format, MUIV_String_Format_Right,
368 MUIA_String_Accept, (IPTR)"0123456879",
369 MUIA_String_Integer, 0,
370 End),
371 Child, (IPTR) LLabel("Lines per Page:"),
372 Child, (IPTR) (data->pt_PaperLength = StringObject,
373 StringFrame,
374 MUIA_String_Format, MUIV_String_Format_Right,
375 MUIA_String_Accept, (IPTR)"0123456879",
376 MUIA_String_Integer, 0,
377 End),
378 Child, (IPTR) LLabel("Density:"),
379 Child, (IPTR) (data->pg_PrintDensity = SliderObject,
380 SliderFrame,
381 MUIA_Slider_Horiz, TRUE,
382 MUIA_Slider_Level, 1,
383 MUIA_Slider_Min, 1,
384 MUIA_Slider_Max, 7,
385 End),
386 End,
387 Child, (IPTR) ColGroup(2),
388 Child, (IPTR) LLabel("Aspect:"),
389 Child, (IPTR) (data->pg_Aspect = CycleObject,
390 MUIA_Cycle_Entries, (IPTR) ui_Aspect,
391 End),
392 Child, (IPTR) LLabel("Shade:"),
393 Child, (IPTR) (data->pg_Shade = CycleObject,
394 MUIA_Cycle_Entries, (IPTR) ui_Shade,
395 End),
396 Child, (IPTR) LLabel("Image:"),
397 Child, (IPTR) (data->pg_Image = CycleObject,
398 MUIA_Cycle_Entries, (IPTR) ui_Image,
399 End),
400 Child, (IPTR) LLabel("Threshold:"),
401 Child, (IPTR) (data->pg_Threshold = SliderObject,
402 MUIA_Slider_Horiz, TRUE,
403 MUIA_Numeric_Min, 1,
404 MUIA_Numeric_Max, 15,
405 End),
406 Child, (IPTR) LLabel("Dithering:"),
407 Child, (IPTR) (data->pg_Dithering = CycleObject,
408 MUIA_Cycle_Entries, (IPTR) ui_Dithering,
409 End),
410 Child, (IPTR) LLabel("Dimensions:"),
411 Child, (IPTR) (data->pg_Dimensions = CycleObject,
412 MUIA_Cycle_Entries, (IPTR) ui_Dimensions,
413 End),
414 Child, (IPTR) HGroup,
415 Child, (IPTR) LLabel("Offset ("),
416 Child, (IPTR) (data->pg_OffsetUnits = LLabel("mm")),
417 Child, (IPTR) LLabel("): "),
418 End,
419 Child, (IPTR) HGroup,
420 Child, (IPTR) (data->pg_PrintXOffset = StringObject,
421 StringFrame,
422 MUIA_String_Format, MUIV_String_Format_Right,
423 MUIA_String_Accept, (IPTR)".0123456879",
424 MUIA_String_Contents, (IPTR)"0.0",
425 End),
426 Child, (IPTR) CLabel("x"),
427 Child, (IPTR) (data->pg_PrintYOffset = StringObject,
428 StringFrame,
429 MUIA_String_Format, MUIV_String_Format_Right,
430 MUIA_String_Accept, (IPTR)".0123456879",
431 MUIA_String_Contents, (IPTR)"0.0",
432 End),
433 End,
434 Child, (IPTR) LLabel("Center Image:"),
435 Child, (IPTR) (data->pg_GraphicFlags_Center = CheckMark(FALSE)),
436 Child, (IPTR) LLabel("AntiAlias:"),
437 Child, (IPTR) (data->pg_GraphicFlags_AntiAlias = CheckMark(FALSE)),
438 Child, (IPTR) LLabel("Integer Scaling:"),
439 Child, (IPTR) (data->pg_GraphicFlags_IntScaling = CheckMark(FALSE)),
440 End,
441 End,
442 End,
443 End,
444 End;
446 if (data->child == NULL) {
447 #if SHOWICON
448 MUI_DisposeObject(icon);
449 #endif
450 MUI_DisposeObject(self);
451 return NULL;
455 DoMethod(self, OM_ADDMEMBER, (IPTR) data->child);
457 #define PREF_NOTIFY(x, field) DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
458 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE)
459 #define PREF_REFRESH(x, field) PREF_NOTIFY(x, field); \
460 DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
461 (IPTR)self, 1, MUIM_PrinterEditor_Refresh)
463 /* Select a different config file */
464 DoMethod(data->pd_UnitNum, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
465 (IPTR)self, 1, MUIM_PrinterEditor_Sync);
467 PREF_NOTIFY(pd_UnitName, MUIA_String_Contents);
469 PREF_REFRESH(pt_DriverList, MUIA_List_Active);
470 PREF_NOTIFY(pt_Port, MUIA_Cycle_Active);
471 PREF_NOTIFY(pt_PaperType, MUIA_Cycle_Active);
472 PREF_REFRESH(pt_PaperSize, MUIA_Cycle_Active);
473 PREF_NOTIFY(pt_PaperLength, MUIA_String_Integer);
474 PREF_NOTIFY(pt_Pitch, MUIA_Cycle_Active);
475 PREF_NOTIFY(pt_Spacing, MUIA_Cycle_Active);
476 PREF_NOTIFY(pt_LeftMargin, MUIA_String_Integer);
477 PREF_NOTIFY(pt_RightMargin, MUIA_String_Integer);
478 PREF_NOTIFY(pt_Quality, MUIA_Cycle_Active);
480 PREF_NOTIFY(pu_UnitNum, MUIA_String_Integer);
481 PREF_NOTIFY(pu_DeviceName, MUIA_String_Contents);
482 PREF_REFRESH(pu_DeviceNameCustom, MUIA_Selected);
484 PREF_NOTIFY(pg_Aspect, MUIA_Cycle_Active);
485 PREF_NOTIFY(pg_Shade, MUIA_Cycle_Active);
486 PREF_NOTIFY(pg_Image, MUIA_Cycle_Active);
487 PREF_NOTIFY(pg_Threshold, MUIA_Numeric_Value);
488 PREF_NOTIFY(pg_Dimensions, MUIA_Cycle_Active);
489 PREF_NOTIFY(pg_Dithering, MUIA_Cycle_Active);
490 PREF_NOTIFY(pg_PrintDensity, MUIA_Numeric_Value);
491 PREF_NOTIFY(pg_GraphicFlags_Center, MUIA_Selected);
492 PREF_NOTIFY(pg_GraphicFlags_AntiAlias, MUIA_Selected);
493 PREF_NOTIFY(pg_GraphicFlags_IntScaling, MUIA_Selected);
494 PREF_REFRESH(pg_MaxUnits, MUIA_Cycle_Active);
495 PREF_NOTIFY(pg_PrintMaxWidth, MUIA_String_Integer);
496 PREF_NOTIFY(pg_PrintMaxHeight, MUIA_String_Integer);
497 PREF_NOTIFY(pg_PrintXOffset, MUIA_String_Integer);
498 PREF_NOTIFY(pg_PrintYOffset, MUIA_String_Integer);
500 DoMethod(data->pu_DeviceNameCustom, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
501 (IPTR)data->pt_Port, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
502 DoMethod(data->pu_DeviceNameCustom, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
503 (IPTR)data->pu_DeviceName, 3, MUIM_Set, MUIA_Disabled, MUIV_NotTriggerValue);
505 printerprefs.pp_DeviceUnit.pd_UnitNum = -1;
506 DoMethod(self, MUIM_PrinterEditor_Sync);
509 return self;
512 static inline LONG todeci(LONG units, double val)
514 switch (units) {
515 case UI_UNITS_IN: val *= 10.0; break;
516 case UI_UNITS_MM: val /= 2.54; break;
517 case UI_UNITS_PT: val /= 7.2 ; break;
520 return (LONG)val;
523 static inline double fromdeci(LONG units, LONG value)
525 double val = value;
527 switch (units) {
528 case UI_UNITS_IN: val /= 10.0; break;
529 case UI_UNITS_MM: val *= 2.54; break;
530 case UI_UNITS_PT: val *= 7.2 ; break;
533 return val;
536 STATIC void UpdatePrintMax (struct PrinterEditor_DATA *data, int units, BOOL from_prefs)
538 LONG width, height;
539 char buf[64];
540 LONG pt_PaperSize;
542 if (from_prefs) {
543 pt_PaperSize = printerprefs.pp_Txt.pt_PaperSize;
544 } else {
545 pt_PaperSize = XGET(data->pt_PaperSize, MUIA_Cycle_Active) << 4;
548 switch (pt_PaperSize) {
549 /* PaperSize (in deci-inches) */
550 case US_LETTER: width = 85; height = 110; break; /* 8.5"x11" */
551 case US_LEGAL: width = 85; height = 140; break; /* 8.5"x14" */
552 case N_TRACTOR: width = 95; height = 110; break; /* 9.5"x11" */
553 case W_TRACTOR: width = 149; height = 110; break; /* 14.86"x11" */
554 /* European sizes */
555 case EURO_A0: width = 841 * 100 / 254; height = 1189 * 100 / 254; break; /* A0: 841 x 1189 */
556 case EURO_A1: width = 594 * 100 / 254; height = 841 * 100 / 254; break; /* A1: 594 x 841 */
557 case EURO_A2: width = 420 * 100 / 254; height = 594 * 100 / 254; break; /* A2: 420 x 594 */
558 case EURO_A3: width = 297 * 100 / 254; height = 420 * 100 / 254; break; /* A3: 297 x 420 */
559 case EURO_A4: width = 210 * 100 / 254; height = 297 * 100 / 254; break; /* A4: 210 x 297 */
560 case EURO_A5: width = 148 * 100 / 254; height = 210 * 100 / 254; break; /* A5: 148 x 210 */
561 case EURO_A6: width = 105 * 100 / 254; height = 148 * 100 / 254; break; /* A6: 105 x 148 */
562 case EURO_A7: width = 74 * 100 / 254; height = 105 * 100 / 254; break; /* A7: 74 x 105 */
563 case EURO_A8: width = 52 * 100 / 254; height = 74 * 100 / 254; break; /* A8: 52 x 74 */
564 default:
565 width = height = 0;
566 break;
570 NNSET(data->pg_PrintMaxWidth, MUIA_Disabled, (pt_PaperSize == CUSTOM) ? FALSE : TRUE);
571 NNSET(data->pg_PrintMaxHeight, MUIA_Disabled, (pt_PaperSize == CUSTOM) ? FALSE : TRUE);
573 if (pt_PaperSize != CUSTOM) {
574 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, width));
575 NNSET(data->pg_PrintMaxWidth, MUIA_String_Contents, buf);
576 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, height));
577 NNSET(data->pg_PrintMaxHeight, MUIA_String_Contents, buf);
582 * update struct printerprefs with actual data selected in gadgets
584 STATIC void Gadgets2PrinterPrefs (Class *CLASS, Object *self)
586 SETUP_INST_DATA;
588 struct PrinterTxtPrefs *txt = &printerprefs.pp_Txt;
589 struct PrinterGfxPrefs *gfx = &printerprefs.pp_Gfx;
590 struct PrinterUnitPrefs *unit = &printerprefs.pp_Unit;
591 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
593 CONST_STRPTR str;
594 int units;
595 BOOL custom;
597 D(bug("Gadgets2PrinterPrefs\n"));
599 /* Internal scale is deci-inches. Yeah.
601 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
603 switch (XGET(data->pt_Port, MUIA_Cycle_Active)) {
604 case UI_DEVICE_SERIAL:
605 txt->pt_Port = PP_SERIAL;
606 strcpy(unit->pu_DeviceName, "serial");
607 break;
608 case UI_DEVICE_PARALLEL:
609 txt->pt_Port = PP_PARALLEL;
610 strcpy(unit->pu_DeviceName, "parallel");
611 break;
612 case UI_DEVICE_USBPARALLEL:
613 txt->pt_Port = PP_PARALLEL;
614 strcpy(unit->pu_DeviceName, "usbparallel");
615 break;
616 case UI_DEVICE_PRINTTOFILE:
617 txt->pt_Port = PP_PARALLEL;
618 strcpy(unit->pu_DeviceName, "printtofile");
619 break;
622 custom = XGET(data->pu_DeviceNameCustom, MUIA_Selected) ? TRUE : FALSE;
623 if (custom) {
624 str = (CONST_STRPTR)XGET(data->pu_DeviceName, MUIA_String_Contents);
625 strcpy(unit->pu_DeviceName, str);
627 unit->pu_UnitNum = (LONG)XGET(data->pu_UnitNum, MUIA_String_Integer);
629 strcpy(txt->pt_Driver, (CONST_STRPTR)XGET(data->pt_Driver, MUIA_Text_Contents));
631 txt->pt_PaperType = XGET(data->pt_PaperType, MUIA_Cycle_Active);
632 txt->pt_PaperSize = XGET(data->pt_PaperSize, MUIA_Cycle_Active) << 4;
634 UpdatePrintMax(data, units, FALSE);
636 txt->pt_PaperLength = XGET(data->pt_PaperLength, MUIA_String_Integer);
637 txt->pt_Pitch = XGET(data->pt_Pitch, MUIA_Cycle_Active);
638 txt->pt_Spacing = XGET(data->pt_Spacing, MUIA_Cycle_Active);
639 txt->pt_LeftMargin = XGET(data->pt_LeftMargin, MUIA_String_Integer);
640 txt->pt_RightMargin = XGET(data->pt_RightMargin, MUIA_String_Integer);
641 txt->pt_Quality = XGET(data->pt_Quality, MUIA_Cycle_Active);
643 strcpy(devunit->pd_UnitName, (CONST_STRPTR)XGET(data->pd_UnitName, MUIA_String_Contents));
645 gfx->pg_Aspect = XGET(data->pg_Aspect, MUIA_Cycle_Active);
646 gfx->pg_Shade = XGET(data->pg_Shade, MUIA_Cycle_Active);
647 gfx->pg_Image = XGET(data->pg_Image, MUIA_Cycle_Active);
648 gfx->pg_Threshold = XGET(data->pg_Threshold, MUIA_Numeric_Value);
649 gfx->pg_ColorCorrect = 0; /* TODO! */
650 gfx->pg_Dimensions = XGET(data->pg_Dimensions, MUIA_Cycle_Active);
651 gfx->pg_Dithering = XGET(data->pg_Dithering, MUIA_Cycle_Active);
652 gfx->pg_PrintDensity = XGET(data->pg_PrintDensity, MUIA_Numeric_Value);
653 gfx->pg_GraphicFlags =
654 (XGET(data->pg_GraphicFlags_Center, MUIA_Selected) ? PGFF_CENTER_IMAGE : 0) |
655 (XGET(data->pg_GraphicFlags_AntiAlias, MUIA_Selected) ? PGFF_ANTI_ALIAS : 0) |
656 (XGET(data->pg_GraphicFlags_IntScaling, MUIA_Selected) ? PGFF_INTEGER_SCALING : 0);
658 str = (CONST_STRPTR)XGET(data->pg_PrintMaxWidth, MUIA_String_Contents);
659 gfx->pg_PrintMaxWidth = todeci(units, atof(str));
660 str = (CONST_STRPTR)XGET(data->pg_PrintMaxHeight, MUIA_String_Contents);
661 gfx->pg_PrintMaxHeight = todeci(units, atof(str));
663 str = (CONST_STRPTR)XGET(data->pg_PrintXOffset, MUIA_String_Contents);
664 gfx->pg_PrintXOffset = todeci(units, atof(str));
665 str = (CONST_STRPTR)XGET(data->pg_PrintYOffset, MUIA_String_Contents);
666 gfx->pg_PrintYOffset = todeci(units, atof(str));
668 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
670 D(bug("Gadgets2PrinterPrefs left\n"));
674 * update gadgets with values of struct printerprefs
676 STATIC VOID PrinterPrefs2Gadgets(Class *CLASS, Object *self)
678 SETUP_INST_DATA;
680 struct PrinterTxtPrefs *txt = &printerprefs.pp_Txt;
681 struct PrinterGfxPrefs *gfx = &printerprefs.pp_Gfx;
682 struct PrinterUnitPrefs *unit = &printerprefs.pp_Unit;
683 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
684 int units;
685 char buf[64];
687 D(bug("PrinterPrefs2Gadgets: Unit %d\n", devunit->pd_UnitNum));
689 /* Internal scale is deci-inches. Yeah.
691 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
693 NNSET(data->pd_UnitNum, MUIA_Cycle_Active, devunit->pd_UnitNum);
695 NNSET(data->pd_UnitName, MUIA_String_Contents, devunit->pd_UnitName);
697 NNSET(data->pt_DriverList, MUIA_List_Active, MUIV_List_Active_Off);
698 NNSET(data->pt_Driver, MUIA_Text_Contents, txt->pt_Driver);
699 NNSET(data->pt_Port, MUIA_Cycle_Active, txt->pt_Port);
700 NNSET(data->pt_PaperType, MUIA_Cycle_Active, txt->pt_PaperType);
701 NNSET(data->pt_PaperSize, MUIA_Cycle_Active, txt->pt_PaperSize >> 4);
702 NNSET(data->pt_PaperLength, MUIA_String_Integer, txt->pt_PaperLength);
703 NNSET(data->pt_Pitch, MUIA_Cycle_Active, txt->pt_Pitch);
704 NNSET(data->pt_Spacing, MUIA_Cycle_Active, txt->pt_Spacing);
705 NNSET(data->pt_LeftMargin, MUIA_String_Integer, txt->pt_LeftMargin);
706 NNSET(data->pt_RightMargin, MUIA_String_Integer, txt->pt_RightMargin);
707 NNSET(data->pt_Quality, MUIA_Cycle_Active, txt->pt_Quality);
709 NNSET(data->pu_UnitNum, MUIA_String_Integer, unit->pu_UnitNum);
711 if (strcmp(unit->pu_DeviceName, "serial") == 0) {
712 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_SERIAL);
713 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
714 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
715 } else if (strcmp(unit->pu_DeviceName, "parallel") == 0) {
716 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_PARALLEL);
717 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
718 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
719 } else if (strcmp(unit->pu_DeviceName, "printtofile") == 0) {
720 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_PRINTTOFILE);
721 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
722 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
723 } else if (strcmp(unit->pu_DeviceName, "usbparallel") == 0) {
724 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_USBPARALLEL);
725 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
726 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
727 } else {
728 SET(data->pu_DeviceNameCustom, MUIA_Selected, TRUE);
729 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)unit->pu_DeviceName);
732 NNSET(data->pg_Aspect, MUIA_Cycle_Active, gfx->pg_Aspect);
733 NNSET(data->pg_Shade, MUIA_Cycle_Active, gfx->pg_Shade);
734 NNSET(data->pg_Image, MUIA_Cycle_Active, gfx->pg_Image);
735 NNSET(data->pg_Threshold, MUIA_Numeric_Value, gfx->pg_Threshold);
736 NNSET(data->pg_Dimensions, MUIA_Cycle_Active, gfx->pg_Dimensions);
737 NNSET(data->pg_Dithering, MUIA_Cycle_Active, gfx->pg_Dithering);
738 NNSET(data->pg_PrintDensity, MUIA_Numeric_Value, gfx->pg_PrintDensity <= 0 ? 1 : gfx->pg_PrintDensity);
739 NNSET(data->pg_GraphicFlags_Center, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_CENTER_IMAGE) ? TRUE : FALSE);
740 NNSET(data->pg_GraphicFlags_AntiAlias, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_ANTI_ALIAS) ? TRUE : FALSE);
741 NNSET(data->pg_GraphicFlags_IntScaling, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_INTEGER_SCALING) ? TRUE : FALSE);
742 NNSET(data->pg_PrintDensity, MUIA_Cycle_Active, gfx->pg_PrintDensity);
744 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintMaxWidth));
745 NNSET(data->pg_PrintMaxWidth, MUIA_String_Contents, buf);
746 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintMaxHeight));
747 NNSET(data->pg_PrintMaxHeight, MUIA_String_Contents, buf);
749 UpdatePrintMax(data, units, TRUE);
751 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
753 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintXOffset));
754 NNSET(data->pg_PrintXOffset, MUIA_String_Contents, buf);
755 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintYOffset));
756 NNSET(data->pg_PrintYOffset, MUIA_String_Contents, buf);
758 DoMethod(self, MUIM_PrinterEditor_Refresh);
760 D(bug("PrinterPrefs2Gadgets: Done\n"));
763 IPTR PrinterEditor__MUIM_PrefsEditor_ImportFH (
764 Class *CLASS, Object *self,
765 struct MUIP_PrefsEditor_ImportFH *message
768 BOOL success = TRUE;
770 D(bug("[PrinterEdit class] PrinterEdit Class Import\n"));
772 success = Prefs_ImportFH(message->fh);
773 if (success) PrinterPrefs2Gadgets(CLASS, self);
775 return success;
778 IPTR PrinterEditor__MUIM_PrefsEditor_ExportFH
780 Class *CLASS, Object *self,
781 struct MUIP_PrefsEditor_ExportFH *message
784 BOOL success = TRUE;
786 D(bug("[PrinterEdit class] PrinterEdit Class Export\n"));
788 Gadgets2PrinterPrefs(CLASS, self);
789 success = Prefs_ExportFH(message->fh);
791 return success;
794 IPTR PrinterEditor__MUIM_PrefsEditor_SetDefaults
796 Class *CLASS, Object *self, Msg message
799 BOOL success = TRUE;
801 D(bug("[PrinterEdit class] PrinterEdit Class SetDefaults\n"));
803 success = Prefs_Default(0);
804 if (success) PrinterPrefs2Gadgets(CLASS, self);
806 return success;
809 /* Re-synchronize with the pd_UnitNum
811 IPTR PrinterEditor__MUIM_PrinterEditor_Sync(Class *CLASS, Object *self, Msg message)
813 SETUP_INST_DATA;
815 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
817 CONST_STRPTR str;
818 LONG unit;
820 unit = XGET(data->pd_UnitNum, MUIA_Cycle_Active);
822 if (unit != devunit->pd_UnitNum) {
823 char buf[64];
824 char path[sizeof(buf) + 7]; /* ENVARC: */
826 D(bug("PrinterEditor_Sync: Unit %d -> %d\n", devunit->pd_UnitNum, unit));
827 sprintf(buf, "SYS/printer%d.prefs", (int)unit);
828 str = (unit ? buf : "SYS/printer.prefs");
829 NNSET(self, MUIA_PrefsEditor_Path, (IPTR) str);
830 /*-- Reload preferences --*/
831 sprintf(path, "ENV:%s", str);
832 if (!DoMethod(self, MUIM_PrefsEditor_Import, path))
834 sprintf(path, "ENVARC:%s", str);
835 if (!DoMethod(self, MUIM_PrefsEditor_Import, path))
837 Prefs_Default(unit);
838 PrinterPrefs2Gadgets(CLASS, self);
839 SET(self, MUIA_PrefsEditor_Changed, TRUE);
840 D(bug("PrinterEditor_Sync: Defaults\n"));
841 return TRUE;
844 NNSET(data->pd_UnitNum, MUIA_Cycle_Active, unit);
845 devunit->pd_UnitNum = unit;
846 D(bug("PrinterEditor_Sync: Loaded\n"));
847 return TRUE;
850 return TRUE;
853 IPTR PrinterEditor__MUIM_PrinterEditor_Refresh(Class *CLASS, Object *self, Msg message)
855 SETUP_INST_DATA;
857 CONST_STRPTR str;
858 int units;
860 D(bug("PrinterEditor_Refresh: Begin\n"));
862 /* Internal scale is deci-inches. Yeah.
864 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
866 if (XGET(data->pt_DriverList, MUIA_List_Active) != MUIV_List_Active_Off) {
867 str = (CONST_STRPTR)XGET(data->pt_DriverList, MUIA_Dirlist_Path);
868 NNSET(data->pt_Driver, MUIA_Text_Contents, FilePart(str));
871 UpdatePrintMax(data, units, FALSE);
873 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
875 D(bug("PrinterEditor_Refresh: End\n"));
877 return TRUE;
880 /*** Setup ******************************************************************/
881 ZUNE_CUSTOMCLASS_6
883 PrinterEditor, NULL, MUIC_PrefsEditor, NULL,
884 OM_NEW, struct opSet *,
885 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
886 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
887 MUIM_PrefsEditor_SetDefaults, Msg,
888 MUIM_PrinterEditor_Sync, Msg,
889 MUIM_PrinterEditor_Refresh, Msg