2 Copyright © 2003-2017, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
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>
25 /*** String Data ************************************************************/
27 STATIC CONST_STRPTR ui_Pages
[] = {NULL
,NULL
,NULL
};
33 #define UI_DEVICE_PARALLEL 0
34 #define UI_DEVICE_SERIAL 1
35 #define UI_DEVICE_PRINTTOFILE 2
36 #define UI_DEVICE_USBPARALLEL 3
38 STATIC CONST_STRPTR ui_Port
[] = {NULL
,NULL
,NULL
,NULL
,NULL
};
41 STATIC CONST_STRPTR ui_PaperTypes
[] = {NULL
,NULL
,NULL
};
44 STATIC CONST_STRPTR
const ui_PaperSize
[] = {
62 #define UI_UNITS_IN 0 /* inches */
63 #define UI_UNITS_MM 1 /* millimeters */
64 #define UI_UNITS_PT 2 /* 1/72 of an inch */
66 STATIC CONST_STRPTR
const ui_Units
[] = {
73 STATIC CONST_STRPTR
const ui_Pitch
[] = {
80 STATIC CONST_STRPTR
const ui_Spacing
[] = {
86 STATIC CONST_STRPTR ui_Quality
[] = {NULL
,NULL
,NULL
};
89 STATIC CONST_STRPTR ui_Aspect
[] = {NULL
,NULL
,NULL
};
92 STATIC CONST_STRPTR ui_Shade
[] = {NULL
,NULL
,NULL
,NULL
,NULL
};
95 STATIC CONST_STRPTR ui_Image
[] = {NULL
,NULL
,NULL
};
98 STATIC CONST_STRPTR ui_Dimensions
[] = {NULL
,NULL
,NULL
,NULL
,NULL
,NULL
};
101 STATIC CONST_STRPTR ui_Dithering
[] = {NULL
,NULL
,NULL
,NULL
};
104 /*** Instance Data **********************************************************/
106 struct PrinterEditor_DATA
108 STRPTR UnitLabels
[UNIT_COUNT
];
109 int PrinterDeviceUnit
;
113 Object
*pd_UnitNum
; /* Cycle */
114 Object
*pd_UnitName
; /* String */
116 Object
*pt_DriverList
; /* Dirlist */
117 Object
*pt_Driver
; /* Text */
118 Object
*pt_Port
; /* Cycle */
119 Object
*pt_PaperType
; /* Cycle */
120 Object
*pt_PaperSize
; /* Cycle */
121 Object
*pt_PaperLength
; /* String (integer) */
122 Object
*pt_Pitch
; /* Cycle */
123 Object
*pt_Spacing
; /* Cycle */
124 Object
*pt_LeftMargin
; /* String (integer) */
125 Object
*pt_RightMargin
; /* String (integer) */
126 Object
*pt_Quality
; /* Cycle */
128 Object
*pu_UnitNum
; /* String (integer) */
129 Object
*pu_DeviceName
; /* String */
130 Object
*pu_DeviceNameCustom
;/* CheckMark */
132 Object
*pg_Aspect
; /* Cycle */
133 Object
*pg_Shade
; /* Cycle */
134 Object
*pg_Image
; /* Cycle */
135 Object
*pg_Threshold
; /* Slider */
136 Object
*pg_Dimensions
; /* Cycle */
137 Object
*pg_Dithering
; /* Cycle */
138 Object
*pg_GraphicFlags_Center
; /* CheckMark */
139 Object
*pg_GraphicFlags_AntiAlias
; /* CheckMark */
140 Object
*pg_GraphicFlags_IntScaling
; /* CheckMark */
141 Object
*pg_PrintDensity
; /* Slider */
143 Object
*pg_MaxUnits
; /* Cycle */
144 Object
*pg_PrintMaxWidth
; /* String (integer) */
145 Object
*pg_PrintMaxHeight
; /* String (integer) */
147 Object
*pg_OffsetUnits
; /* Label */
148 Object
*pg_PrintXOffset
; /* String (integer) */
149 Object
*pg_PrintYOffset
; /* String (integer) */
152 STATIC VOID
PrinterPrefs2Gadgets(Class
*CLASS
, Object
*self
);
153 STATIC VOID
Gadgets2PrinterPrefs(Class
*CLASS
, Object
*self
);
155 /*** Macros *****************************************************************/
156 #define SETUP_INST_DATA struct PrinterEditor_DATA *data = INST_DATA(CLASS, self)
158 /*** Methods ****************************************************************/
159 Object
*PrinterEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
163 ui_Pages
[0] = (STRPTR
)__(MSG_PRINTER_DRIVER
);
164 ui_Pages
[1] = (STRPTR
)__(MSG_PRINTER_SETTINGS
);
166 ui_Port
[0] = (STRPTR
)__(MSG_PRINTER_PARALLEL
);
167 ui_Port
[1] = (STRPTR
)__(MSG_PRINTER_SERIAL
);
168 ui_Port
[2] = (STRPTR
)__(MSG_PRINTER_TO_FILE
);
169 ui_Port
[3] = (STRPTR
)__(MSG_PRINTER_USB
);
171 ui_PaperTypes
[0] = (STRPTR
)__(MSG_TISK_FANFOLD
);
172 ui_PaperTypes
[1] = (STRPTR
)__(MSG_TISK_SINGLE
);
174 ui_Quality
[0] = (STRPTR
)__(MSG_TISK_DRAFT
);
175 ui_Quality
[1] = (STRPTR
)__(MSG_TISK_LETTER
);
177 ui_Aspect
[0] = (STRPTR
)__(MSG_TISK_PORTRAIT
);
178 ui_Aspect
[1] = (STRPTR
)__(MSG_TISK_LANDSCAPE
);
180 ui_Shade
[0] = (STRPTR
)__(MSG_TISK_BW
);
181 ui_Shade
[1] = (STRPTR
)__(MSG_TISK_GRAY
);
182 ui_Shade
[2] = (STRPTR
)__(MSG_TISK_COLOR
);
183 ui_Shade
[3] = (STRPTR
)__(MSG_TISK_GRAY2
);
185 ui_Image
[0] = (STRPTR
)__(MSG_TISK_POSITIVE
);
186 ui_Image
[1] = (STRPTR
)__(MSG_TISK_NEGATIVE
);
188 ui_Dimensions
[0] = (STRPTR
)__(MSG_TISK_IGNORE
);
189 ui_Dimensions
[1] = (STRPTR
)__(MSG_TISK_BOUNDED
);
190 ui_Dimensions
[2] = (STRPTR
)__(MSG_TISK_ABSOLUTE
);
191 ui_Dimensions
[3] = (STRPTR
)__(MSG_TISK_PIXEL
);
192 ui_Dimensions
[4] = (STRPTR
)__(MSG_TISK_MULTIPLY
);
194 ui_Dithering
[0] = (STRPTR
)__(MSG_TISK_ORDERED
);
195 ui_Dithering
[1] = (STRPTR
)__(MSG_TISK_HALFTONE
);
196 ui_Dithering
[2] = (STRPTR
)__(MSG_TISK_FLOYDSTEINBERG
);
202 D(bug("[PrinterEdit class] PrinterEdit Class New\n"));
205 * we create self first and then create the child,
206 * so we have self->data available already
208 self
= (Object
*) DoSuperNewTags
211 MUIA_PrefsEditor_Name
, _(MSG_WINTITLE
),
212 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/printer.prefs",
213 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/Printer",
222 data
->PrinterDeviceUnit
= 0;
223 for (i
= 0; i
< UNIT_COUNT
; i
++)
225 sprintf(buf
, _(MSG_PRINTER_DEVICE_UNIT
), i
);
226 data
->UnitLabels
[i
] = StrDup(buf
);
230 icon
= DtpicObject
, MUIA_Dtpic_Name
, "PROGDIR:Printer.info", End
;
232 if (!icon
) icon
= HVSpace
;
238 Child
, (IPTR
) HGroup
,
242 Child
, (IPTR
) LLabel1(__(MSG_PRINTER_UNIT
)),
243 Child
, (IPTR
) (data
->pd_UnitNum
= CycleObject
,
244 MUIA_Cycle_Entries
, (IPTR
)data
->UnitLabels
,
246 Child
, (IPTR
) LLabel1(__(MSG_PRINTER_NAME
)),
247 Child
, (IPTR
) (data
->pd_UnitName
= StringObject
,
249 MUIA_String_MaxLen
, UNITNAMESIZE
,
253 Child
, (IPTR
) RegisterGroup(ui_Pages
),
254 /* Driver and Device page */
255 Child
, (IPTR
) HGroup
,
256 Child
, (IPTR
) VGroup
,
257 Child
, (IPTR
) CLabel(__(MSG_PRINTER_SELECT_DRIVER
)),
258 Child
, (IPTR
) HCenter((ListviewObject
,
259 MUIA_Listview_List
, (IPTR
) (data
->pt_DriverList
= DirlistObject
,
261 MUIA_List_Format
, (IPTR
) "COL=0",
262 MUIA_List_AdjustWidth
, TRUE
,
263 MUIA_Dirlist_Directory
, (IPTR
)"DEVS:Printers",
264 MUIA_Dirlist_RejectPattern
, (IPTR
)"#?.dbg",
265 MUIA_Dirlist_FilesOnly
, TRUE
,
266 MUIA_Dirlist_RejectIcons
, TRUE
,
270 Child
, (IPTR
) BalanceObject
, End
,
271 Child
, (IPTR
) VGroup
,
272 Child
, (IPTR
) (HGroup
,
273 Child
, (IPTR
) (data
->pt_Driver
= TextObject
,
274 MUIA_Text_Contents
, (IPTR
)"generic",
277 Child
, (IPTR
) (HGroup
,
278 Child
, (IPTR
) (data
->pt_Port
= CycleObject
,
279 MUIA_Cycle_Entries
, (IPTR
) ui_Port
,
281 Child
, (IPTR
)HVSpace
,
282 Child
, (IPTR
) Label(__(MSG_PRINTER_PS_UNIT
)),
283 Child
, (IPTR
) (data
->pu_UnitNum
= StringObject
,
285 MUIA_String_Format
, MUIV_String_Format_Right
,
286 MUIA_String_Accept
, (IPTR
)"0123456879",
287 MUIA_String_Integer
, 0,
290 Child
, (IPTR
) HGroup
,
291 Child
, (IPTR
) (data
->pu_DeviceNameCustom
= CheckMark(FALSE
)),
292 Child
, (IPTR
) Label(__(MSG_PRINTER_CUSTOM_DEVICE
)),
293 Child
, (IPTR
) (data
->pu_DeviceName
= StringObject
,
295 MUIA_String_Format
, MUIV_String_Format_Right
,
296 MUIA_String_MaxLen
, DEVICENAMESIZE
,
299 Child
, (IPTR
)HVSpace
,
303 Child
, (IPTR
) VGroup
,
304 Child
, (IPTR
) HGroup
,
305 Child
, (IPTR
) ColGroup(2),
306 Child
, (IPTR
) LLabel(__(MSG_TISK_PAPER_TYPE
)),
307 Child
, (IPTR
) (data
->pt_PaperType
= CycleObject
,
308 MUIA_Cycle_Entries
, (IPTR
) ui_PaperTypes
,
310 Child
, (IPTR
) LLabel(__(MSG_TISK_PAPER_SIZE
)),
311 Child
, (IPTR
) (data
->pt_PaperSize
= CycleObject
,
312 MUIA_Cycle_Entries
, (IPTR
) ui_PaperSize
,
314 Child
, (IPTR
) (data
->pg_MaxUnits
= CycleObject
,
315 MUIA_Cycle_Entries
, (IPTR
) ui_Units
,
317 Child
, (IPTR
) HGroup
,
318 Child
, (IPTR
) (data
->pg_PrintMaxWidth
= StringObject
,
321 MUIA_String_Format
, MUIV_String_Format_Right
,
322 MUIA_String_Accept
, (IPTR
)".0123456879",
323 MUIA_String_Contents
, (IPTR
)"0.0",
325 Child
, (IPTR
) CLabel("x"),
326 Child
, (IPTR
) (data
->pg_PrintMaxHeight
= StringObject
,
329 MUIA_String_Format
, MUIV_String_Format_Right
,
330 MUIA_String_Accept
, (IPTR
)".0123456879",
331 MUIA_String_Contents
, (IPTR
)"0.0",
334 Child
, (IPTR
) LLabel(__(MSG_TISK_QUALITY
)),
335 Child
, (IPTR
) (data
->pt_Quality
= CycleObject
,
336 MUIA_Cycle_Entries
, (IPTR
) ui_Quality
,
338 Child
, (IPTR
) LLabel(__(MSG_TISK_PITCH
)),
339 Child
, (IPTR
) (data
->pt_Pitch
= CycleObject
,
340 MUIA_Cycle_Entries
, (IPTR
) ui_Pitch
,
342 Child
, (IPTR
) LLabel(__(MSG_TISK_SPACING
)),
343 Child
, (IPTR
) (data
->pt_Spacing
= CycleObject
,
344 MUIA_Cycle_Entries
, (IPTR
) ui_Spacing
,
346 Child
, (IPTR
) LLabel(__(MSG_TISK_LEFT_MARGIN
)),
347 Child
, (IPTR
) (data
->pt_LeftMargin
= StringObject
,
349 MUIA_String_Format
, MUIV_String_Format_Right
,
350 MUIA_String_Accept
, (IPTR
)"0123456879",
351 MUIA_String_Integer
, 0,
353 Child
, (IPTR
) LLabel(__(MSG_TISK_RIGHT_MARGIN
)),
354 Child
, (IPTR
) (data
->pt_RightMargin
= StringObject
,
356 MUIA_String_Format
, MUIV_String_Format_Right
,
357 MUIA_String_Accept
, (IPTR
)"0123456879",
358 MUIA_String_Integer
, 0,
360 Child
, (IPTR
) LLabel(__(MSG_TISK_LINE_PER_PAGE
)),
361 Child
, (IPTR
) (data
->pt_PaperLength
= StringObject
,
363 MUIA_String_Format
, MUIV_String_Format_Right
,
364 MUIA_String_Accept
, (IPTR
)"0123456879",
365 MUIA_String_Integer
, 0,
367 Child
, (IPTR
) LLabel(__(MSG_TISK_DENSITY
)),
368 Child
, (IPTR
) (data
->pg_PrintDensity
= SliderObject
,
370 MUIA_Slider_Horiz
, TRUE
,
371 MUIA_Slider_Level
, 1,
376 Child
, (IPTR
) ColGroup(2),
377 Child
, (IPTR
) LLabel(__(MSG_TISK_ASPECT
)),
378 Child
, (IPTR
) (data
->pg_Aspect
= CycleObject
,
379 MUIA_Cycle_Entries
, (IPTR
) ui_Aspect
,
381 Child
, (IPTR
) LLabel(__(MSG_TISK_SHADE
)),
382 Child
, (IPTR
) (data
->pg_Shade
= CycleObject
,
383 MUIA_Cycle_Entries
, (IPTR
) ui_Shade
,
385 Child
, (IPTR
) LLabel(__(MSG_TISK_IMAGE
)),
386 Child
, (IPTR
) (data
->pg_Image
= CycleObject
,
387 MUIA_Cycle_Entries
, (IPTR
) ui_Image
,
389 Child
, (IPTR
) LLabel(__(MSG_TISK_TRESHOLD
)),
390 Child
, (IPTR
) (data
->pg_Threshold
= SliderObject
,
391 MUIA_Slider_Horiz
, TRUE
,
393 MUIA_Numeric_Max
, 15,
395 Child
, (IPTR
) LLabel(__(MSG_TISK_DITHERING
)),
396 Child
, (IPTR
) (data
->pg_Dithering
= CycleObject
,
397 MUIA_Cycle_Entries
, (IPTR
) ui_Dithering
,
399 Child
, (IPTR
) LLabel(__(MSG_TISK_DIMENSION
)),
400 Child
, (IPTR
) (data
->pg_Dimensions
= CycleObject
,
401 MUIA_Cycle_Entries
, (IPTR
) ui_Dimensions
,
403 Child
, (IPTR
) HGroup
,
404 Child
, (IPTR
) LLabel(__(MSG_TISK_PAPER_OFFSET
)),
405 Child
, (IPTR
) (data
->pg_OffsetUnits
= LLabel("mm")),
406 Child
, (IPTR
) LLabel("): "),
408 Child
, (IPTR
) HGroup
,
409 Child
, (IPTR
) (data
->pg_PrintXOffset
= StringObject
,
411 MUIA_String_Format
, MUIV_String_Format_Right
,
412 MUIA_String_Accept
, (IPTR
)".0123456879",
413 MUIA_String_Contents
, (IPTR
)"0.0",
415 Child
, (IPTR
) CLabel("x"),
416 Child
, (IPTR
) (data
->pg_PrintYOffset
= StringObject
,
418 MUIA_String_Format
, MUIV_String_Format_Right
,
419 MUIA_String_Accept
, (IPTR
)".0123456879",
420 MUIA_String_Contents
, (IPTR
)"0.0",
423 Child
, (IPTR
) LLabel(__(MSG_TISK_CENTER_IMAGE
)),
424 Child
, (IPTR
) (data
->pg_GraphicFlags_Center
= CheckMark(FALSE
)),
425 Child
, (IPTR
) LLabel(__(MSG_TISK_ANTIALIAS
)),
426 Child
, (IPTR
) (data
->pg_GraphicFlags_AntiAlias
= CheckMark(FALSE
)),
427 Child
, (IPTR
) LLabel(__(MSG_TISK_INTEGER_SCALING
)),
428 Child
, (IPTR
) (data
->pg_GraphicFlags_IntScaling
= CheckMark(FALSE
)),
435 if (data
->child
== NULL
) {
437 MUI_DisposeObject(icon
);
439 MUI_DisposeObject(self
);
444 DoMethod(self
, OM_ADDMEMBER
, (IPTR
) data
->child
);
446 #define PREF_NOTIFY(x, field) DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
447 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE)
448 #define PREF_REFRESH(x, field) PREF_NOTIFY(x, field); \
449 DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
450 (IPTR)self, 1, MUIM_PrinterEditor_Refresh)
452 /* Select a different config file */
453 DoMethod(data
->pd_UnitNum
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
454 (IPTR
)self
, 1, MUIM_PrinterEditor_Sync
);
456 PREF_NOTIFY(pd_UnitName
, MUIA_String_Contents
);
458 PREF_REFRESH(pt_DriverList
, MUIA_List_Active
);
459 PREF_NOTIFY(pt_Port
, MUIA_Cycle_Active
);
460 PREF_NOTIFY(pt_PaperType
, MUIA_Cycle_Active
);
461 PREF_REFRESH(pt_PaperSize
, MUIA_Cycle_Active
);
462 PREF_NOTIFY(pt_PaperLength
, MUIA_String_Integer
);
463 PREF_NOTIFY(pt_Pitch
, MUIA_Cycle_Active
);
464 PREF_NOTIFY(pt_Spacing
, MUIA_Cycle_Active
);
465 PREF_NOTIFY(pt_LeftMargin
, MUIA_String_Integer
);
466 PREF_NOTIFY(pt_RightMargin
, MUIA_String_Integer
);
467 PREF_NOTIFY(pt_Quality
, MUIA_Cycle_Active
);
469 PREF_NOTIFY(pu_UnitNum
, MUIA_String_Integer
);
470 PREF_NOTIFY(pu_DeviceName
, MUIA_String_Contents
);
471 PREF_REFRESH(pu_DeviceNameCustom
, MUIA_Selected
);
473 PREF_NOTIFY(pg_Aspect
, MUIA_Cycle_Active
);
474 PREF_NOTIFY(pg_Shade
, MUIA_Cycle_Active
);
475 PREF_NOTIFY(pg_Image
, MUIA_Cycle_Active
);
476 PREF_NOTIFY(pg_Threshold
, MUIA_Numeric_Value
);
477 PREF_NOTIFY(pg_Dimensions
, MUIA_Cycle_Active
);
478 PREF_NOTIFY(pg_Dithering
, MUIA_Cycle_Active
);
479 PREF_NOTIFY(pg_PrintDensity
, MUIA_Numeric_Value
);
480 PREF_NOTIFY(pg_GraphicFlags_Center
, MUIA_Selected
);
481 PREF_NOTIFY(pg_GraphicFlags_AntiAlias
, MUIA_Selected
);
482 PREF_NOTIFY(pg_GraphicFlags_IntScaling
, MUIA_Selected
);
483 PREF_REFRESH(pg_MaxUnits
, MUIA_Cycle_Active
);
484 PREF_NOTIFY(pg_PrintMaxWidth
, MUIA_String_Integer
);
485 PREF_NOTIFY(pg_PrintMaxHeight
, MUIA_String_Integer
);
486 PREF_NOTIFY(pg_PrintXOffset
, MUIA_String_Integer
);
487 PREF_NOTIFY(pg_PrintYOffset
, MUIA_String_Integer
);
489 DoMethod(data
->pu_DeviceNameCustom
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
490 (IPTR
)data
->pt_Port
, 3, MUIM_Set
, MUIA_Disabled
, MUIV_TriggerValue
);
491 DoMethod(data
->pu_DeviceNameCustom
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
492 (IPTR
)data
->pu_DeviceName
, 3, MUIM_Set
, MUIA_Disabled
, MUIV_NotTriggerValue
);
494 printerprefs
.pp_DeviceUnit
.pd_UnitNum
= -1;
495 DoMethod(self
, MUIM_PrinterEditor_Sync
);
501 IPTR
PrinterEditor__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg msg
)
507 for (i
= 0; i
< UNIT_COUNT
; i
++)
508 FreeVec(data
->UnitLabels
[i
]);
510 return DoSuperMethodA(CLASS
, self
, msg
);
513 static inline LONG
todeci(LONG units
, double val
)
516 case UI_UNITS_IN
: val
*= 10.0; break;
517 case UI_UNITS_MM
: val
/= 2.54; break;
518 case UI_UNITS_PT
: val
/= 7.2 ; break;
524 static inline double fromdeci(LONG units
, LONG value
)
529 case UI_UNITS_IN
: val
/= 10.0; break;
530 case UI_UNITS_MM
: val
*= 2.54; break;
531 case UI_UNITS_PT
: val
*= 7.2 ; break;
537 STATIC
void UpdatePrintMax (struct PrinterEditor_DATA
*data
, int units
, BOOL from_prefs
)
544 pt_PaperSize
= printerprefs
.pp_Txt
.pt_PaperSize
;
546 pt_PaperSize
= XGET(data
->pt_PaperSize
, MUIA_Cycle_Active
) << 4;
549 switch (pt_PaperSize
) {
550 /* PaperSize (in deci-inches) */
551 case US_LETTER
: width
= 85; height
= 110; break; /* 8.5"x11" */
552 case US_LEGAL
: width
= 85; height
= 140; break; /* 8.5"x14" */
553 case N_TRACTOR
: width
= 95; height
= 110; break; /* 9.5"x11" */
554 case W_TRACTOR
: width
= 149; height
= 110; break; /* 14.86"x11" */
556 case EURO_A0
: width
= 841 * 100 / 254; height
= 1189 * 100 / 254; break; /* A0: 841 x 1189 */
557 case EURO_A1
: width
= 594 * 100 / 254; height
= 841 * 100 / 254; break; /* A1: 594 x 841 */
558 case EURO_A2
: width
= 420 * 100 / 254; height
= 594 * 100 / 254; break; /* A2: 420 x 594 */
559 case EURO_A3
: width
= 297 * 100 / 254; height
= 420 * 100 / 254; break; /* A3: 297 x 420 */
560 case EURO_A4
: width
= 210 * 100 / 254; height
= 297 * 100 / 254; break; /* A4: 210 x 297 */
561 case EURO_A5
: width
= 148 * 100 / 254; height
= 210 * 100 / 254; break; /* A5: 148 x 210 */
562 case EURO_A6
: width
= 105 * 100 / 254; height
= 148 * 100 / 254; break; /* A6: 105 x 148 */
563 case EURO_A7
: width
= 74 * 100 / 254; height
= 105 * 100 / 254; break; /* A7: 74 x 105 */
564 case EURO_A8
: width
= 52 * 100 / 254; height
= 74 * 100 / 254; break; /* A8: 52 x 74 */
571 NNSET(data
->pg_PrintMaxWidth
, MUIA_Disabled
, (pt_PaperSize
== CUSTOM
) ? FALSE
: TRUE
);
572 NNSET(data
->pg_PrintMaxHeight
, MUIA_Disabled
, (pt_PaperSize
== CUSTOM
) ? FALSE
: TRUE
);
574 if (pt_PaperSize
!= CUSTOM
) {
575 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, width
));
576 NNSET(data
->pg_PrintMaxWidth
, MUIA_String_Contents
, buf
);
577 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, height
));
578 NNSET(data
->pg_PrintMaxHeight
, MUIA_String_Contents
, buf
);
583 * update struct printerprefs with actual data selected in gadgets
585 STATIC
void Gadgets2PrinterPrefs (Class
*CLASS
, Object
*self
)
589 struct PrinterTxtPrefs
*txt
= &printerprefs
.pp_Txt
;
590 struct PrinterGfxPrefs
*gfx
= &printerprefs
.pp_Gfx
;
591 struct PrinterUnitPrefs
*unit
= &printerprefs
.pp_Unit
;
592 struct PrinterDeviceUnitPrefs
*devunit
= &printerprefs
.pp_DeviceUnit
;
598 D(bug("Gadgets2PrinterPrefs\n"));
600 /* Internal scale is deci-inches. Yeah.
602 units
= XGET(data
->pg_MaxUnits
, MUIA_Cycle_Active
);
604 switch (XGET(data
->pt_Port
, MUIA_Cycle_Active
)) {
605 case UI_DEVICE_SERIAL
:
606 txt
->pt_Port
= PP_SERIAL
;
607 strcpy(unit
->pu_DeviceName
, "serial");
609 case UI_DEVICE_PARALLEL
:
610 txt
->pt_Port
= PP_PARALLEL
;
611 strcpy(unit
->pu_DeviceName
, "parallel");
613 case UI_DEVICE_USBPARALLEL
:
614 txt
->pt_Port
= PP_PARALLEL
;
615 strcpy(unit
->pu_DeviceName
, "usbparallel");
617 case UI_DEVICE_PRINTTOFILE
:
618 txt
->pt_Port
= PP_PARALLEL
;
619 strcpy(unit
->pu_DeviceName
, "printtofile");
623 custom
= XGET(data
->pu_DeviceNameCustom
, MUIA_Selected
) ? TRUE
: FALSE
;
625 str
= (CONST_STRPTR
)XGET(data
->pu_DeviceName
, MUIA_String_Contents
);
626 strcpy(unit
->pu_DeviceName
, str
);
628 unit
->pu_UnitNum
= (LONG
)XGET(data
->pu_UnitNum
, MUIA_String_Integer
);
630 strcpy(txt
->pt_Driver
, (CONST_STRPTR
)XGET(data
->pt_Driver
, MUIA_Text_Contents
));
632 txt
->pt_PaperType
= XGET(data
->pt_PaperType
, MUIA_Cycle_Active
);
633 txt
->pt_PaperSize
= XGET(data
->pt_PaperSize
, MUIA_Cycle_Active
) << 4;
635 UpdatePrintMax(data
, units
, FALSE
);
637 txt
->pt_PaperLength
= XGET(data
->pt_PaperLength
, MUIA_String_Integer
);
638 txt
->pt_Pitch
= XGET(data
->pt_Pitch
, MUIA_Cycle_Active
);
639 txt
->pt_Spacing
= XGET(data
->pt_Spacing
, MUIA_Cycle_Active
);
640 txt
->pt_LeftMargin
= XGET(data
->pt_LeftMargin
, MUIA_String_Integer
);
641 txt
->pt_RightMargin
= XGET(data
->pt_RightMargin
, MUIA_String_Integer
);
642 txt
->pt_Quality
= XGET(data
->pt_Quality
, MUIA_Cycle_Active
);
644 strcpy(devunit
->pd_UnitName
, (CONST_STRPTR
)XGET(data
->pd_UnitName
, MUIA_String_Contents
));
646 gfx
->pg_Aspect
= XGET(data
->pg_Aspect
, MUIA_Cycle_Active
);
647 gfx
->pg_Shade
= XGET(data
->pg_Shade
, MUIA_Cycle_Active
);
648 gfx
->pg_Image
= XGET(data
->pg_Image
, MUIA_Cycle_Active
);
649 gfx
->pg_Threshold
= XGET(data
->pg_Threshold
, MUIA_Numeric_Value
);
650 gfx
->pg_ColorCorrect
= 0; /* TODO! */
651 gfx
->pg_Dimensions
= XGET(data
->pg_Dimensions
, MUIA_Cycle_Active
);
652 gfx
->pg_Dithering
= XGET(data
->pg_Dithering
, MUIA_Cycle_Active
);
653 gfx
->pg_PrintDensity
= XGET(data
->pg_PrintDensity
, MUIA_Numeric_Value
);
654 gfx
->pg_GraphicFlags
=
655 (XGET(data
->pg_GraphicFlags_Center
, MUIA_Selected
) ? PGFF_CENTER_IMAGE
: 0) |
656 (XGET(data
->pg_GraphicFlags_AntiAlias
, MUIA_Selected
) ? PGFF_ANTI_ALIAS
: 0) |
657 (XGET(data
->pg_GraphicFlags_IntScaling
, MUIA_Selected
) ? PGFF_INTEGER_SCALING
: 0);
659 str
= (CONST_STRPTR
)XGET(data
->pg_PrintMaxWidth
, MUIA_String_Contents
);
660 gfx
->pg_PrintMaxWidth
= todeci(units
, atof(str
));
661 str
= (CONST_STRPTR
)XGET(data
->pg_PrintMaxHeight
, MUIA_String_Contents
);
662 gfx
->pg_PrintMaxHeight
= todeci(units
, atof(str
));
664 str
= (CONST_STRPTR
)XGET(data
->pg_PrintXOffset
, MUIA_String_Contents
);
665 gfx
->pg_PrintXOffset
= todeci(units
, atof(str
));
666 str
= (CONST_STRPTR
)XGET(data
->pg_PrintYOffset
, MUIA_String_Contents
);
667 gfx
->pg_PrintYOffset
= todeci(units
, atof(str
));
669 NNSET(data
->pg_OffsetUnits
, MUIA_Text_Contents
, (IPTR
)ui_Units
[units
]);
671 D(bug("Gadgets2PrinterPrefs left\n"));
675 * update gadgets with values of struct printerprefs
677 STATIC VOID
PrinterPrefs2Gadgets(Class
*CLASS
, Object
*self
)
681 struct PrinterTxtPrefs
*txt
= &printerprefs
.pp_Txt
;
682 struct PrinterGfxPrefs
*gfx
= &printerprefs
.pp_Gfx
;
683 struct PrinterUnitPrefs
*unit
= &printerprefs
.pp_Unit
;
684 struct PrinterDeviceUnitPrefs
*devunit
= &printerprefs
.pp_DeviceUnit
;
688 D(bug("PrinterPrefs2Gadgets: Unit %d\n", devunit
->pd_UnitNum
));
690 /* Internal scale is deci-inches. Yeah.
692 units
= XGET(data
->pg_MaxUnits
, MUIA_Cycle_Active
);
694 NNSET(data
->pd_UnitNum
, MUIA_Cycle_Active
, devunit
->pd_UnitNum
);
696 NNSET(data
->pd_UnitName
, MUIA_String_Contents
, devunit
->pd_UnitName
);
698 NNSET(data
->pt_DriverList
, MUIA_List_Active
, MUIV_List_Active_Off
);
699 NNSET(data
->pt_Driver
, MUIA_Text_Contents
, txt
->pt_Driver
);
700 NNSET(data
->pt_Port
, MUIA_Cycle_Active
, txt
->pt_Port
);
701 NNSET(data
->pt_PaperType
, MUIA_Cycle_Active
, txt
->pt_PaperType
);
702 NNSET(data
->pt_PaperSize
, MUIA_Cycle_Active
, txt
->pt_PaperSize
>> 4);
703 NNSET(data
->pt_PaperLength
, MUIA_String_Integer
, txt
->pt_PaperLength
);
704 NNSET(data
->pt_Pitch
, MUIA_Cycle_Active
, txt
->pt_Pitch
);
705 NNSET(data
->pt_Spacing
, MUIA_Cycle_Active
, txt
->pt_Spacing
);
706 NNSET(data
->pt_LeftMargin
, MUIA_String_Integer
, txt
->pt_LeftMargin
);
707 NNSET(data
->pt_RightMargin
, MUIA_String_Integer
, txt
->pt_RightMargin
);
708 NNSET(data
->pt_Quality
, MUIA_Cycle_Active
, txt
->pt_Quality
);
710 NNSET(data
->pu_UnitNum
, MUIA_String_Integer
, unit
->pu_UnitNum
);
712 if (strcmp(unit
->pu_DeviceName
, "serial") == 0) {
713 NNSET(data
->pt_Port
, MUIA_Cycle_Active
, UI_DEVICE_SERIAL
);
714 SET(data
->pu_DeviceNameCustom
, MUIA_Selected
, FALSE
);
715 NNSET(data
->pu_DeviceName
, MUIA_String_Contents
, (IPTR
)"");
716 } else if (strcmp(unit
->pu_DeviceName
, "parallel") == 0) {
717 NNSET(data
->pt_Port
, MUIA_Cycle_Active
, UI_DEVICE_PARALLEL
);
718 SET(data
->pu_DeviceNameCustom
, MUIA_Selected
, FALSE
);
719 NNSET(data
->pu_DeviceName
, MUIA_String_Contents
, (IPTR
)"");
720 } else if (strcmp(unit
->pu_DeviceName
, "printtofile") == 0) {
721 NNSET(data
->pt_Port
, MUIA_Cycle_Active
, UI_DEVICE_PRINTTOFILE
);
722 SET(data
->pu_DeviceNameCustom
, MUIA_Selected
, FALSE
);
723 NNSET(data
->pu_DeviceName
, MUIA_String_Contents
, (IPTR
)"");
724 } else if (strcmp(unit
->pu_DeviceName
, "usbparallel") == 0) {
725 NNSET(data
->pt_Port
, MUIA_Cycle_Active
, UI_DEVICE_USBPARALLEL
);
726 SET(data
->pu_DeviceNameCustom
, MUIA_Selected
, FALSE
);
727 NNSET(data
->pu_DeviceName
, MUIA_String_Contents
, (IPTR
)"");
729 SET(data
->pu_DeviceNameCustom
, MUIA_Selected
, TRUE
);
730 NNSET(data
->pu_DeviceName
, MUIA_String_Contents
, (IPTR
)unit
->pu_DeviceName
);
733 NNSET(data
->pg_Aspect
, MUIA_Cycle_Active
, gfx
->pg_Aspect
);
734 NNSET(data
->pg_Shade
, MUIA_Cycle_Active
, gfx
->pg_Shade
);
735 NNSET(data
->pg_Image
, MUIA_Cycle_Active
, gfx
->pg_Image
);
736 NNSET(data
->pg_Threshold
, MUIA_Numeric_Value
, gfx
->pg_Threshold
);
737 NNSET(data
->pg_Dimensions
, MUIA_Cycle_Active
, gfx
->pg_Dimensions
);
738 NNSET(data
->pg_Dithering
, MUIA_Cycle_Active
, gfx
->pg_Dithering
);
739 NNSET(data
->pg_PrintDensity
, MUIA_Numeric_Value
, gfx
->pg_PrintDensity
<= 0 ? 1 : gfx
->pg_PrintDensity
);
740 NNSET(data
->pg_GraphicFlags_Center
, MUIA_Selected
, (gfx
->pg_GraphicFlags
& PGFF_CENTER_IMAGE
) ? TRUE
: FALSE
);
741 NNSET(data
->pg_GraphicFlags_AntiAlias
, MUIA_Selected
, (gfx
->pg_GraphicFlags
& PGFF_ANTI_ALIAS
) ? TRUE
: FALSE
);
742 NNSET(data
->pg_GraphicFlags_IntScaling
, MUIA_Selected
, (gfx
->pg_GraphicFlags
& PGFF_INTEGER_SCALING
) ? TRUE
: FALSE
);
743 NNSET(data
->pg_PrintDensity
, MUIA_Cycle_Active
, gfx
->pg_PrintDensity
);
745 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, gfx
->pg_PrintMaxWidth
));
746 NNSET(data
->pg_PrintMaxWidth
, MUIA_String_Contents
, buf
);
747 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, gfx
->pg_PrintMaxHeight
));
748 NNSET(data
->pg_PrintMaxHeight
, MUIA_String_Contents
, buf
);
750 UpdatePrintMax(data
, units
, TRUE
);
752 NNSET(data
->pg_OffsetUnits
, MUIA_Text_Contents
, (IPTR
)ui_Units
[units
]);
754 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, gfx
->pg_PrintXOffset
));
755 NNSET(data
->pg_PrintXOffset
, MUIA_String_Contents
, buf
);
756 sprintf(buf
, "%.*f", (units
== UI_UNITS_IN
) ? 1 : 0, fromdeci(units
, gfx
->pg_PrintYOffset
));
757 NNSET(data
->pg_PrintYOffset
, MUIA_String_Contents
, buf
);
759 DoMethod(self
, MUIM_PrinterEditor_Refresh
);
761 D(bug("PrinterPrefs2Gadgets: Done\n"));
764 IPTR
PrinterEditor__MUIM_PrefsEditor_ImportFH (
765 Class
*CLASS
, Object
*self
,
766 struct MUIP_PrefsEditor_ImportFH
*message
771 D(bug("[PrinterEdit class] PrinterEdit Class Import\n"));
773 success
= Prefs_ImportFH(message
->fh
);
774 if (success
) PrinterPrefs2Gadgets(CLASS
, self
);
779 IPTR PrinterEditor__MUIM_PrefsEditor_ExportFH
781 Class
*CLASS
, Object
*self
,
782 struct MUIP_PrefsEditor_ExportFH
*message
787 D(bug("[PrinterEdit class] PrinterEdit Class Export\n"));
789 Gadgets2PrinterPrefs(CLASS
, self
);
790 success
= Prefs_ExportFH(message
->fh
);
795 IPTR PrinterEditor__MUIM_PrefsEditor_SetDefaults
797 Class
*CLASS
, Object
*self
, Msg message
802 D(bug("[PrinterEdit class] PrinterEdit Class SetDefaults\n"));
804 success
= Prefs_Default(0);
805 if (success
) PrinterPrefs2Gadgets(CLASS
, self
);
810 /* Re-synchronize with the pd_UnitNum
812 IPTR
PrinterEditor__MUIM_PrinterEditor_Sync(Class
*CLASS
, Object
*self
, Msg message
)
816 struct PrinterDeviceUnitPrefs
*devunit
= &printerprefs
.pp_DeviceUnit
;
821 unit
= XGET(data
->pd_UnitNum
, MUIA_Cycle_Active
);
823 if (unit
!= devunit
->pd_UnitNum
) {
825 char path
[sizeof(buf
) + 7]; /* ENVARC: */
827 D(bug("PrinterEditor_Sync: Unit %d -> %d\n", devunit
->pd_UnitNum
, unit
));
828 sprintf(buf
, "SYS/printer%d.prefs", (int)unit
);
829 str
= (unit
? buf
: "SYS/printer.prefs");
830 NNSET(self
, MUIA_PrefsEditor_Path
, (IPTR
) str
);
831 /*-- Reload preferences --*/
832 sprintf(path
, "ENV:%s", str
);
833 if (!DoMethod(self
, MUIM_PrefsEditor_Import
, path
))
835 sprintf(path
, "ENVARC:%s", str
);
836 if (!DoMethod(self
, MUIM_PrefsEditor_Import
, path
))
839 PrinterPrefs2Gadgets(CLASS
, self
);
840 SET(self
, MUIA_PrefsEditor_Changed
, TRUE
);
841 D(bug("PrinterEditor_Sync: Defaults\n"));
845 NNSET(data
->pd_UnitNum
, MUIA_Cycle_Active
, unit
);
846 devunit
->pd_UnitNum
= unit
;
847 D(bug("PrinterEditor_Sync: Loaded\n"));
854 IPTR
PrinterEditor__MUIM_PrinterEditor_Refresh(Class
*CLASS
, Object
*self
, Msg message
)
861 D(bug("PrinterEditor_Refresh: Begin\n"));
863 /* Internal scale is deci-inches. Yeah.
865 units
= XGET(data
->pg_MaxUnits
, MUIA_Cycle_Active
);
867 if (XGET(data
->pt_DriverList
, MUIA_List_Active
) != MUIV_List_Active_Off
) {
868 str
= (CONST_STRPTR
)XGET(data
->pt_DriverList
, MUIA_Dirlist_Path
);
869 NNSET(data
->pt_Driver
, MUIA_Text_Contents
, FilePart(str
));
872 UpdatePrintMax(data
, units
, FALSE
);
874 NNSET(data
->pg_OffsetUnits
, MUIA_Text_Contents
, (IPTR
)ui_Units
[units
]);
876 D(bug("PrinterEditor_Refresh: End\n"));
881 /*** Setup ******************************************************************/
884 PrinterEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
885 OM_NEW
, struct opSet
*,
887 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
888 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
889 MUIM_PrefsEditor_SetDefaults
, Msg
,
890 MUIM_PrinterEditor_Sync
, Msg
,
891 MUIM_PrinterEditor_Refresh
, Msg