SysMon: remove dead code
[AROS.git] / workbench / prefs / printer / editor.c
blobc26242e7f4befabf8de2b619076f7cd26b32bf76
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 ui_Pages[] = {NULL,NULL,NULL};
30 STATIC CONST_STRPTR ui_DeviceUnits[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,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[] = {
45 "US Letter",
46 "US Legal",
47 "80 Column",
48 "132 Column",
49 "Custom",
50 "A0",
51 "A1",
52 "A2",
53 "A3",
54 "A4",
55 "A5",
56 "A6",
57 "A7",
58 "A8",
59 NULL,
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[] = {
67 "in",
68 "mm",
69 "pt",
70 NULL,
73 STATIC CONST_STRPTR const ui_Pitch[] = {
74 "10 cpi (Pica)",
75 "12 cpi (Elite)",
76 "17.1 cpi (Fine)",
77 NULL,
80 STATIC CONST_STRPTR const ui_Spacing[] = {
81 "6 lpi",
82 "8 lpi",
83 NULL,
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[10];
109 int PrinterDeviceUnit;
111 Object *child;
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)
161 ui_Pages[0] = (STRPTR)__(MSG_PRINTER_DRIVER);
162 ui_Pages[1] = (STRPTR)__(MSG_PRINTER_SETTINGS);
164 ui_DeviceUnits[0] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT0);
165 ui_DeviceUnits[1] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT1);
166 ui_DeviceUnits[2] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT2);
167 ui_DeviceUnits[3] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT3);
168 ui_DeviceUnits[4] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT4);
169 ui_DeviceUnits[5] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT5);
170 ui_DeviceUnits[6] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT6);
171 ui_DeviceUnits[7] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT7);
172 ui_DeviceUnits[8] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT8);
173 ui_DeviceUnits[9] = (STRPTR)__(MSG_PRINTER_DEVICE_UNIT9);
175 ui_Port[0] = (STRPTR)__(MSG_PRINTER_PARALLEL);
176 ui_Port[1] = (STRPTR)__(MSG_PRINTER_SERIAL);
177 ui_Port[2] = (STRPTR)__(MSG_PRINTER_TO_FILE);
178 ui_Port[3] = (STRPTR)__(MSG_PRINTER_USB);
180 ui_PaperTypes[0] = (STRPTR)__(MSG_TISK_FANFOLD);
181 ui_PaperTypes[1] = (STRPTR)__(MSG_TISK_SINGLE);
183 ui_Quality[0] = (STRPTR)__(MSG_TISK_DRAFT);
184 ui_Quality[1] = (STRPTR)__(MSG_TISK_LETTER);
186 ui_Aspect[0] = (STRPTR)__(MSG_TISK_PORTRAIT);
187 ui_Aspect[1] = (STRPTR)__(MSG_TISK_LANDSCAPE);
189 ui_Shade[0] = (STRPTR)__(MSG_TISK_BW);
190 ui_Shade[1] = (STRPTR)__(MSG_TISK_GRAY);
191 ui_Shade[2] = (STRPTR)__(MSG_TISK_COLOR);
192 ui_Shade[3] = (STRPTR)__(MSG_TISK_GRAY2);
194 ui_Image[0] = (STRPTR)__(MSG_TISK_POSITIVE);
195 ui_Image[1] = (STRPTR)__(MSG_TISK_NEGATIVE);
197 ui_Dimensions[0] = (STRPTR)__(MSG_TISK_IGNORE);
198 ui_Dimensions[1] = (STRPTR)__(MSG_TISK_BOUNDED);
199 ui_Dimensions[2] = (STRPTR)__(MSG_TISK_ABSOLUTE);
200 ui_Dimensions[3] = (STRPTR)__(MSG_TISK_PIXEL);
201 ui_Dimensions[4] = (STRPTR)__(MSG_TISK_MULTIPLY);
203 ui_Dithering[0] = (STRPTR)__(MSG_TISK_ORDERED);
204 ui_Dithering[1] = (STRPTR)__(MSG_TISK_HALFTONE);
205 ui_Dithering[2] = (STRPTR)__(MSG_TISK_FLOYDSTEINBERG);
207 int i;
208 #if SHOWICON
209 Object *icon;
210 #endif
211 D(bug("[PrinterEdit class] PrinterEdit Class New\n"));
214 * we create self first and then create the child,
215 * so we have self->data available already
217 self = (Object *) DoSuperNewTags
219 CLASS, self, NULL,
220 MUIA_PrefsEditor_Name, _(MSG_WINTITLE),
221 MUIA_PrefsEditor_Path, (IPTR) "SYS/printer.prefs",
222 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Printer",
224 TAG_DONE
227 if (self)
229 SETUP_INST_DATA;
231 data->PrinterDeviceUnit = 0;
232 for (i = 0; i < 10; i++) {
233 data->UnitLabels[i] = StrDup(ui_DeviceUnits[i]);
236 #if SHOWPIC
237 icon = DtpicObject, MUIA_Dtpic_Name, "PROGDIR:Printer.info", End;
239 if (!icon) icon = HVSpace;
240 #endif
242 data->child =
243 VGroup,
244 /* Unit selection */
245 Child, (IPTR) HGroup,
246 #if SHOWPIC
247 Child, icon,
248 #endif
249 Child, (IPTR) LLabel1(__(MSG_PRINTER_UNIT)),
250 Child, (IPTR) (data->pd_UnitNum = CycleObject,
251 MUIA_Cycle_Entries, (IPTR)data->UnitLabels,
252 End),
253 Child, (IPTR) LLabel1(__(MSG_PRINTER_NAME)),
254 Child, (IPTR) (data->pd_UnitName = StringObject,
255 StringFrame,
256 MUIA_String_MaxLen, UNITNAMESIZE,
257 End),
258 End,
259 /* Pages */
260 Child, (IPTR) RegisterGroup(ui_Pages),
261 /* Driver and Device page */
262 Child, (IPTR) HGroup,
263 Child, (IPTR) VGroup,
264 Child, (IPTR) CLabel(__(MSG_PRINTER_SELECT_DRIVER)),
265 Child, (IPTR) HCenter((ListviewObject,
266 MUIA_Listview_List, (IPTR) (data->pt_DriverList = DirlistObject,
267 InputListFrame,
268 MUIA_List_Format, (IPTR) "COL=0",
269 MUIA_List_AdjustWidth, TRUE,
270 MUIA_Dirlist_Directory, (IPTR)"DEVS:Printers",
271 MUIA_Dirlist_FilesOnly, TRUE,
272 MUIA_Dirlist_RejectIcons, TRUE,
273 End),
274 End)),
275 End,
276 Child, (IPTR) BalanceObject, End,
277 Child, (IPTR) VGroup,
278 Child, (IPTR) (HGroup,
279 Child, (IPTR) (data->pt_Driver = TextObject,
280 MUIA_Text_Contents, (IPTR)"generic",
281 End),
282 End),
283 Child, (IPTR) (HGroup,
284 Child, (IPTR) (data->pt_Port = CycleObject,
285 MUIA_Cycle_Entries, (IPTR) ui_Port,
286 End),
287 Child, (IPTR)HVSpace,
288 Child, (IPTR) Label(__(MSG_PRINTER_PS_UNIT)),
289 Child, (IPTR) (data->pu_UnitNum = StringObject,
290 StringFrame,
291 MUIA_String_Format, MUIV_String_Format_Right,
292 MUIA_String_Accept, (IPTR)"0123456879",
293 MUIA_String_Integer, 0,
294 End),
295 End),
296 Child, (IPTR) HGroup,
297 Child, (IPTR) (data->pu_DeviceNameCustom = CheckMark(FALSE)),
298 Child, (IPTR) Label(__(MSG_PRINTER_CUSTOM_DEVICE)),
299 Child, (IPTR) (data->pu_DeviceName = StringObject,
300 StringFrame,
301 MUIA_String_Format, MUIV_String_Format_Right,
302 MUIA_String_MaxLen, DEVICENAMESIZE,
303 End),
304 End,
305 Child, (IPTR)HVSpace,
306 End,
307 End,
308 /* Settings page */
309 Child, (IPTR) VGroup,
310 Child, (IPTR) HGroup,
311 Child, (IPTR) ColGroup(2),
312 Child, (IPTR) LLabel(__(MSG_TISK_PAPER_TYPE)),
313 Child, (IPTR) (data->pt_PaperType = CycleObject,
314 MUIA_Cycle_Entries, (IPTR) ui_PaperTypes,
315 End),
316 Child, (IPTR) LLabel(__(MSG_TISK_PAPER_SIZE)),
317 Child, (IPTR) (data->pt_PaperSize = CycleObject,
318 MUIA_Cycle_Entries, (IPTR) ui_PaperSize,
319 End),
320 Child, (IPTR) (data->pg_MaxUnits = CycleObject,
321 MUIA_Cycle_Entries, (IPTR) ui_Units,
322 End),
323 Child, (IPTR) HGroup,
324 Child, (IPTR) (data->pg_PrintMaxWidth = StringObject,
325 StringFrame,
326 MUIA_Disabled, TRUE,
327 MUIA_String_Format, MUIV_String_Format_Right,
328 MUIA_String_Accept, (IPTR)".0123456879",
329 MUIA_String_Contents, (IPTR)"0.0",
330 End),
331 Child, (IPTR) CLabel("x"),
332 Child, (IPTR) (data->pg_PrintMaxHeight = StringObject,
333 StringFrame,
334 MUIA_Disabled, TRUE,
335 MUIA_String_Format, MUIV_String_Format_Right,
336 MUIA_String_Accept, (IPTR)".0123456879",
337 MUIA_String_Contents, (IPTR)"0.0",
338 End),
339 End,
340 Child, (IPTR) LLabel(__(MSG_TISK_QUALITY)),
341 Child, (IPTR) (data->pt_Quality = CycleObject,
342 MUIA_Cycle_Entries, (IPTR) ui_Quality,
343 End),
344 Child, (IPTR) LLabel(__(MSG_TISK_PITCH)),
345 Child, (IPTR) (data->pt_Pitch = CycleObject,
346 MUIA_Cycle_Entries, (IPTR) ui_Pitch,
347 End),
348 Child, (IPTR) LLabel(__(MSG_TISK_SPACING)),
349 Child, (IPTR) (data->pt_Spacing = CycleObject,
350 MUIA_Cycle_Entries, (IPTR) ui_Spacing,
351 End),
352 Child, (IPTR) LLabel(__(MSG_TISK_LEFT_MARGIN)),
353 Child, (IPTR) (data->pt_LeftMargin = StringObject,
354 StringFrame,
355 MUIA_String_Format, MUIV_String_Format_Right,
356 MUIA_String_Accept, (IPTR)"0123456879",
357 MUIA_String_Integer, 0,
358 End),
359 Child, (IPTR) LLabel(__(MSG_TISK_RIGHT_MARGIN)),
360 Child, (IPTR) (data->pt_RightMargin = StringObject,
361 StringFrame,
362 MUIA_String_Format, MUIV_String_Format_Right,
363 MUIA_String_Accept, (IPTR)"0123456879",
364 MUIA_String_Integer, 0,
365 End),
366 Child, (IPTR) LLabel(__(MSG_TISK_LINE_PER_PAGE)),
367 Child, (IPTR) (data->pt_PaperLength = StringObject,
368 StringFrame,
369 MUIA_String_Format, MUIV_String_Format_Right,
370 MUIA_String_Accept, (IPTR)"0123456879",
371 MUIA_String_Integer, 0,
372 End),
373 Child, (IPTR) LLabel(__(MSG_TISK_DENSITY)),
374 Child, (IPTR) (data->pg_PrintDensity = SliderObject,
375 SliderFrame,
376 MUIA_Slider_Horiz, TRUE,
377 MUIA_Slider_Level, 1,
378 MUIA_Slider_Min, 1,
379 MUIA_Slider_Max, 7,
380 End),
381 End,
382 Child, (IPTR) ColGroup(2),
383 Child, (IPTR) LLabel(__(MSG_TISK_ASPECT)),
384 Child, (IPTR) (data->pg_Aspect = CycleObject,
385 MUIA_Cycle_Entries, (IPTR) ui_Aspect,
386 End),
387 Child, (IPTR) LLabel(__(MSG_TISK_SHADE)),
388 Child, (IPTR) (data->pg_Shade = CycleObject,
389 MUIA_Cycle_Entries, (IPTR) ui_Shade,
390 End),
391 Child, (IPTR) LLabel(__(MSG_TISK_IMAGE)),
392 Child, (IPTR) (data->pg_Image = CycleObject,
393 MUIA_Cycle_Entries, (IPTR) ui_Image,
394 End),
395 Child, (IPTR) LLabel(__(MSG_TISK_TRESHOLD)),
396 Child, (IPTR) (data->pg_Threshold = SliderObject,
397 MUIA_Slider_Horiz, TRUE,
398 MUIA_Numeric_Min, 1,
399 MUIA_Numeric_Max, 15,
400 End),
401 Child, (IPTR) LLabel(__(MSG_TISK_DITHERING)),
402 Child, (IPTR) (data->pg_Dithering = CycleObject,
403 MUIA_Cycle_Entries, (IPTR) ui_Dithering,
404 End),
405 Child, (IPTR) LLabel(__(MSG_TISK_DIMENSION)),
406 Child, (IPTR) (data->pg_Dimensions = CycleObject,
407 MUIA_Cycle_Entries, (IPTR) ui_Dimensions,
408 End),
409 Child, (IPTR) HGroup,
410 Child, (IPTR) LLabel(__(MSG_TISK_PAPER_OFFSET)),
411 Child, (IPTR) (data->pg_OffsetUnits = LLabel("mm")),
412 Child, (IPTR) LLabel("): "),
413 End,
414 Child, (IPTR) HGroup,
415 Child, (IPTR) (data->pg_PrintXOffset = StringObject,
416 StringFrame,
417 MUIA_String_Format, MUIV_String_Format_Right,
418 MUIA_String_Accept, (IPTR)".0123456879",
419 MUIA_String_Contents, (IPTR)"0.0",
420 End),
421 Child, (IPTR) CLabel("x"),
422 Child, (IPTR) (data->pg_PrintYOffset = StringObject,
423 StringFrame,
424 MUIA_String_Format, MUIV_String_Format_Right,
425 MUIA_String_Accept, (IPTR)".0123456879",
426 MUIA_String_Contents, (IPTR)"0.0",
427 End),
428 End,
429 Child, (IPTR) LLabel(__(MSG_TISK_CENTER_IMAGE)),
430 Child, (IPTR) (data->pg_GraphicFlags_Center = CheckMark(FALSE)),
431 Child, (IPTR) LLabel(__(MSG_TISK_ANTIALIAS)),
432 Child, (IPTR) (data->pg_GraphicFlags_AntiAlias = CheckMark(FALSE)),
433 Child, (IPTR) LLabel(__(MSG_TISK_INTEGER_SCALING)),
434 Child, (IPTR) (data->pg_GraphicFlags_IntScaling = CheckMark(FALSE)),
435 End,
436 End,
437 End,
438 End,
439 End;
441 if (data->child == NULL) {
442 #if SHOWICON
443 MUI_DisposeObject(icon);
444 #endif
445 MUI_DisposeObject(self);
446 return NULL;
450 DoMethod(self, OM_ADDMEMBER, (IPTR) data->child);
452 #define PREF_NOTIFY(x, field) DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
453 (IPTR)self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE)
454 #define PREF_REFRESH(x, field) PREF_NOTIFY(x, field); \
455 DoMethod(data->x, MUIM_Notify, field, MUIV_EveryTime, \
456 (IPTR)self, 1, MUIM_PrinterEditor_Refresh)
458 /* Select a different config file */
459 DoMethod(data->pd_UnitNum, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
460 (IPTR)self, 1, MUIM_PrinterEditor_Sync);
462 PREF_NOTIFY(pd_UnitName, MUIA_String_Contents);
464 PREF_REFRESH(pt_DriverList, MUIA_List_Active);
465 PREF_NOTIFY(pt_Port, MUIA_Cycle_Active);
466 PREF_NOTIFY(pt_PaperType, MUIA_Cycle_Active);
467 PREF_REFRESH(pt_PaperSize, MUIA_Cycle_Active);
468 PREF_NOTIFY(pt_PaperLength, MUIA_String_Integer);
469 PREF_NOTIFY(pt_Pitch, MUIA_Cycle_Active);
470 PREF_NOTIFY(pt_Spacing, MUIA_Cycle_Active);
471 PREF_NOTIFY(pt_LeftMargin, MUIA_String_Integer);
472 PREF_NOTIFY(pt_RightMargin, MUIA_String_Integer);
473 PREF_NOTIFY(pt_Quality, MUIA_Cycle_Active);
475 PREF_NOTIFY(pu_UnitNum, MUIA_String_Integer);
476 PREF_NOTIFY(pu_DeviceName, MUIA_String_Contents);
477 PREF_REFRESH(pu_DeviceNameCustom, MUIA_Selected);
479 PREF_NOTIFY(pg_Aspect, MUIA_Cycle_Active);
480 PREF_NOTIFY(pg_Shade, MUIA_Cycle_Active);
481 PREF_NOTIFY(pg_Image, MUIA_Cycle_Active);
482 PREF_NOTIFY(pg_Threshold, MUIA_Numeric_Value);
483 PREF_NOTIFY(pg_Dimensions, MUIA_Cycle_Active);
484 PREF_NOTIFY(pg_Dithering, MUIA_Cycle_Active);
485 PREF_NOTIFY(pg_PrintDensity, MUIA_Numeric_Value);
486 PREF_NOTIFY(pg_GraphicFlags_Center, MUIA_Selected);
487 PREF_NOTIFY(pg_GraphicFlags_AntiAlias, MUIA_Selected);
488 PREF_NOTIFY(pg_GraphicFlags_IntScaling, MUIA_Selected);
489 PREF_REFRESH(pg_MaxUnits, MUIA_Cycle_Active);
490 PREF_NOTIFY(pg_PrintMaxWidth, MUIA_String_Integer);
491 PREF_NOTIFY(pg_PrintMaxHeight, MUIA_String_Integer);
492 PREF_NOTIFY(pg_PrintXOffset, MUIA_String_Integer);
493 PREF_NOTIFY(pg_PrintYOffset, MUIA_String_Integer);
495 DoMethod(data->pu_DeviceNameCustom, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
496 (IPTR)data->pt_Port, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
497 DoMethod(data->pu_DeviceNameCustom, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
498 (IPTR)data->pu_DeviceName, 3, MUIM_Set, MUIA_Disabled, MUIV_NotTriggerValue);
500 printerprefs.pp_DeviceUnit.pd_UnitNum = -1;
501 DoMethod(self, MUIM_PrinterEditor_Sync);
504 return self;
507 static inline LONG todeci(LONG units, double val)
509 switch (units) {
510 case UI_UNITS_IN: val *= 10.0; break;
511 case UI_UNITS_MM: val /= 2.54; break;
512 case UI_UNITS_PT: val /= 7.2 ; break;
515 return (LONG)val;
518 static inline double fromdeci(LONG units, LONG value)
520 double val = value;
522 switch (units) {
523 case UI_UNITS_IN: val /= 10.0; break;
524 case UI_UNITS_MM: val *= 2.54; break;
525 case UI_UNITS_PT: val *= 7.2 ; break;
528 return val;
531 STATIC void UpdatePrintMax (struct PrinterEditor_DATA *data, int units, BOOL from_prefs)
533 LONG width, height;
534 char buf[64];
535 LONG pt_PaperSize;
537 if (from_prefs) {
538 pt_PaperSize = printerprefs.pp_Txt.pt_PaperSize;
539 } else {
540 pt_PaperSize = XGET(data->pt_PaperSize, MUIA_Cycle_Active) << 4;
543 switch (pt_PaperSize) {
544 /* PaperSize (in deci-inches) */
545 case US_LETTER: width = 85; height = 110; break; /* 8.5"x11" */
546 case US_LEGAL: width = 85; height = 140; break; /* 8.5"x14" */
547 case N_TRACTOR: width = 95; height = 110; break; /* 9.5"x11" */
548 case W_TRACTOR: width = 149; height = 110; break; /* 14.86"x11" */
549 /* European sizes */
550 case EURO_A0: width = 841 * 100 / 254; height = 1189 * 100 / 254; break; /* A0: 841 x 1189 */
551 case EURO_A1: width = 594 * 100 / 254; height = 841 * 100 / 254; break; /* A1: 594 x 841 */
552 case EURO_A2: width = 420 * 100 / 254; height = 594 * 100 / 254; break; /* A2: 420 x 594 */
553 case EURO_A3: width = 297 * 100 / 254; height = 420 * 100 / 254; break; /* A3: 297 x 420 */
554 case EURO_A4: width = 210 * 100 / 254; height = 297 * 100 / 254; break; /* A4: 210 x 297 */
555 case EURO_A5: width = 148 * 100 / 254; height = 210 * 100 / 254; break; /* A5: 148 x 210 */
556 case EURO_A6: width = 105 * 100 / 254; height = 148 * 100 / 254; break; /* A6: 105 x 148 */
557 case EURO_A7: width = 74 * 100 / 254; height = 105 * 100 / 254; break; /* A7: 74 x 105 */
558 case EURO_A8: width = 52 * 100 / 254; height = 74 * 100 / 254; break; /* A8: 52 x 74 */
559 default:
560 width = height = 0;
561 break;
565 NNSET(data->pg_PrintMaxWidth, MUIA_Disabled, (pt_PaperSize == CUSTOM) ? FALSE : TRUE);
566 NNSET(data->pg_PrintMaxHeight, MUIA_Disabled, (pt_PaperSize == CUSTOM) ? FALSE : TRUE);
568 if (pt_PaperSize != CUSTOM) {
569 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, width));
570 NNSET(data->pg_PrintMaxWidth, MUIA_String_Contents, buf);
571 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, height));
572 NNSET(data->pg_PrintMaxHeight, MUIA_String_Contents, buf);
577 * update struct printerprefs with actual data selected in gadgets
579 STATIC void Gadgets2PrinterPrefs (Class *CLASS, Object *self)
581 SETUP_INST_DATA;
583 struct PrinterTxtPrefs *txt = &printerprefs.pp_Txt;
584 struct PrinterGfxPrefs *gfx = &printerprefs.pp_Gfx;
585 struct PrinterUnitPrefs *unit = &printerprefs.pp_Unit;
586 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
588 CONST_STRPTR str;
589 int units;
590 BOOL custom;
592 D(bug("Gadgets2PrinterPrefs\n"));
594 /* Internal scale is deci-inches. Yeah.
596 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
598 switch (XGET(data->pt_Port, MUIA_Cycle_Active)) {
599 case UI_DEVICE_SERIAL:
600 txt->pt_Port = PP_SERIAL;
601 strcpy(unit->pu_DeviceName, "serial");
602 break;
603 case UI_DEVICE_PARALLEL:
604 txt->pt_Port = PP_PARALLEL;
605 strcpy(unit->pu_DeviceName, "parallel");
606 break;
607 case UI_DEVICE_USBPARALLEL:
608 txt->pt_Port = PP_PARALLEL;
609 strcpy(unit->pu_DeviceName, "usbparallel");
610 break;
611 case UI_DEVICE_PRINTTOFILE:
612 txt->pt_Port = PP_PARALLEL;
613 strcpy(unit->pu_DeviceName, "printtofile");
614 break;
617 custom = XGET(data->pu_DeviceNameCustom, MUIA_Selected) ? TRUE : FALSE;
618 if (custom) {
619 str = (CONST_STRPTR)XGET(data->pu_DeviceName, MUIA_String_Contents);
620 strcpy(unit->pu_DeviceName, str);
622 unit->pu_UnitNum = (LONG)XGET(data->pu_UnitNum, MUIA_String_Integer);
624 strcpy(txt->pt_Driver, (CONST_STRPTR)XGET(data->pt_Driver, MUIA_Text_Contents));
626 txt->pt_PaperType = XGET(data->pt_PaperType, MUIA_Cycle_Active);
627 txt->pt_PaperSize = XGET(data->pt_PaperSize, MUIA_Cycle_Active) << 4;
629 UpdatePrintMax(data, units, FALSE);
631 txt->pt_PaperLength = XGET(data->pt_PaperLength, MUIA_String_Integer);
632 txt->pt_Pitch = XGET(data->pt_Pitch, MUIA_Cycle_Active);
633 txt->pt_Spacing = XGET(data->pt_Spacing, MUIA_Cycle_Active);
634 txt->pt_LeftMargin = XGET(data->pt_LeftMargin, MUIA_String_Integer);
635 txt->pt_RightMargin = XGET(data->pt_RightMargin, MUIA_String_Integer);
636 txt->pt_Quality = XGET(data->pt_Quality, MUIA_Cycle_Active);
638 strcpy(devunit->pd_UnitName, (CONST_STRPTR)XGET(data->pd_UnitName, MUIA_String_Contents));
640 gfx->pg_Aspect = XGET(data->pg_Aspect, MUIA_Cycle_Active);
641 gfx->pg_Shade = XGET(data->pg_Shade, MUIA_Cycle_Active);
642 gfx->pg_Image = XGET(data->pg_Image, MUIA_Cycle_Active);
643 gfx->pg_Threshold = XGET(data->pg_Threshold, MUIA_Numeric_Value);
644 gfx->pg_ColorCorrect = 0; /* TODO! */
645 gfx->pg_Dimensions = XGET(data->pg_Dimensions, MUIA_Cycle_Active);
646 gfx->pg_Dithering = XGET(data->pg_Dithering, MUIA_Cycle_Active);
647 gfx->pg_PrintDensity = XGET(data->pg_PrintDensity, MUIA_Numeric_Value);
648 gfx->pg_GraphicFlags =
649 (XGET(data->pg_GraphicFlags_Center, MUIA_Selected) ? PGFF_CENTER_IMAGE : 0) |
650 (XGET(data->pg_GraphicFlags_AntiAlias, MUIA_Selected) ? PGFF_ANTI_ALIAS : 0) |
651 (XGET(data->pg_GraphicFlags_IntScaling, MUIA_Selected) ? PGFF_INTEGER_SCALING : 0);
653 str = (CONST_STRPTR)XGET(data->pg_PrintMaxWidth, MUIA_String_Contents);
654 gfx->pg_PrintMaxWidth = todeci(units, atof(str));
655 str = (CONST_STRPTR)XGET(data->pg_PrintMaxHeight, MUIA_String_Contents);
656 gfx->pg_PrintMaxHeight = todeci(units, atof(str));
658 str = (CONST_STRPTR)XGET(data->pg_PrintXOffset, MUIA_String_Contents);
659 gfx->pg_PrintXOffset = todeci(units, atof(str));
660 str = (CONST_STRPTR)XGET(data->pg_PrintYOffset, MUIA_String_Contents);
661 gfx->pg_PrintYOffset = todeci(units, atof(str));
663 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
665 D(bug("Gadgets2PrinterPrefs left\n"));
669 * update gadgets with values of struct printerprefs
671 STATIC VOID PrinterPrefs2Gadgets(Class *CLASS, Object *self)
673 SETUP_INST_DATA;
675 struct PrinterTxtPrefs *txt = &printerprefs.pp_Txt;
676 struct PrinterGfxPrefs *gfx = &printerprefs.pp_Gfx;
677 struct PrinterUnitPrefs *unit = &printerprefs.pp_Unit;
678 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
679 int units;
680 char buf[64];
682 D(bug("PrinterPrefs2Gadgets: Unit %d\n", devunit->pd_UnitNum));
684 /* Internal scale is deci-inches. Yeah.
686 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
688 NNSET(data->pd_UnitNum, MUIA_Cycle_Active, devunit->pd_UnitNum);
690 NNSET(data->pd_UnitName, MUIA_String_Contents, devunit->pd_UnitName);
692 NNSET(data->pt_DriverList, MUIA_List_Active, MUIV_List_Active_Off);
693 NNSET(data->pt_Driver, MUIA_Text_Contents, txt->pt_Driver);
694 NNSET(data->pt_Port, MUIA_Cycle_Active, txt->pt_Port);
695 NNSET(data->pt_PaperType, MUIA_Cycle_Active, txt->pt_PaperType);
696 NNSET(data->pt_PaperSize, MUIA_Cycle_Active, txt->pt_PaperSize >> 4);
697 NNSET(data->pt_PaperLength, MUIA_String_Integer, txt->pt_PaperLength);
698 NNSET(data->pt_Pitch, MUIA_Cycle_Active, txt->pt_Pitch);
699 NNSET(data->pt_Spacing, MUIA_Cycle_Active, txt->pt_Spacing);
700 NNSET(data->pt_LeftMargin, MUIA_String_Integer, txt->pt_LeftMargin);
701 NNSET(data->pt_RightMargin, MUIA_String_Integer, txt->pt_RightMargin);
702 NNSET(data->pt_Quality, MUIA_Cycle_Active, txt->pt_Quality);
704 NNSET(data->pu_UnitNum, MUIA_String_Integer, unit->pu_UnitNum);
706 if (strcmp(unit->pu_DeviceName, "serial") == 0) {
707 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_SERIAL);
708 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
709 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
710 } else if (strcmp(unit->pu_DeviceName, "parallel") == 0) {
711 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_PARALLEL);
712 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
713 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
714 } else if (strcmp(unit->pu_DeviceName, "printtofile") == 0) {
715 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_PRINTTOFILE);
716 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
717 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
718 } else if (strcmp(unit->pu_DeviceName, "usbparallel") == 0) {
719 NNSET(data->pt_Port, MUIA_Cycle_Active, UI_DEVICE_USBPARALLEL);
720 SET(data->pu_DeviceNameCustom, MUIA_Selected, FALSE);
721 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)"");
722 } else {
723 SET(data->pu_DeviceNameCustom, MUIA_Selected, TRUE);
724 NNSET(data->pu_DeviceName, MUIA_String_Contents, (IPTR)unit->pu_DeviceName);
727 NNSET(data->pg_Aspect, MUIA_Cycle_Active, gfx->pg_Aspect);
728 NNSET(data->pg_Shade, MUIA_Cycle_Active, gfx->pg_Shade);
729 NNSET(data->pg_Image, MUIA_Cycle_Active, gfx->pg_Image);
730 NNSET(data->pg_Threshold, MUIA_Numeric_Value, gfx->pg_Threshold);
731 NNSET(data->pg_Dimensions, MUIA_Cycle_Active, gfx->pg_Dimensions);
732 NNSET(data->pg_Dithering, MUIA_Cycle_Active, gfx->pg_Dithering);
733 NNSET(data->pg_PrintDensity, MUIA_Numeric_Value, gfx->pg_PrintDensity <= 0 ? 1 : gfx->pg_PrintDensity);
734 NNSET(data->pg_GraphicFlags_Center, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_CENTER_IMAGE) ? TRUE : FALSE);
735 NNSET(data->pg_GraphicFlags_AntiAlias, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_ANTI_ALIAS) ? TRUE : FALSE);
736 NNSET(data->pg_GraphicFlags_IntScaling, MUIA_Selected, (gfx->pg_GraphicFlags & PGFF_INTEGER_SCALING) ? TRUE : FALSE);
737 NNSET(data->pg_PrintDensity, MUIA_Cycle_Active, gfx->pg_PrintDensity);
739 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintMaxWidth));
740 NNSET(data->pg_PrintMaxWidth, MUIA_String_Contents, buf);
741 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintMaxHeight));
742 NNSET(data->pg_PrintMaxHeight, MUIA_String_Contents, buf);
744 UpdatePrintMax(data, units, TRUE);
746 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
748 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintXOffset));
749 NNSET(data->pg_PrintXOffset, MUIA_String_Contents, buf);
750 sprintf(buf, "%.*f", (units == UI_UNITS_IN) ? 1 : 0, fromdeci(units, gfx->pg_PrintYOffset));
751 NNSET(data->pg_PrintYOffset, MUIA_String_Contents, buf);
753 DoMethod(self, MUIM_PrinterEditor_Refresh);
755 D(bug("PrinterPrefs2Gadgets: Done\n"));
758 IPTR PrinterEditor__MUIM_PrefsEditor_ImportFH (
759 Class *CLASS, Object *self,
760 struct MUIP_PrefsEditor_ImportFH *message
763 BOOL success = TRUE;
765 D(bug("[PrinterEdit class] PrinterEdit Class Import\n"));
767 success = Prefs_ImportFH(message->fh);
768 if (success) PrinterPrefs2Gadgets(CLASS, self);
770 return success;
773 IPTR PrinterEditor__MUIM_PrefsEditor_ExportFH
775 Class *CLASS, Object *self,
776 struct MUIP_PrefsEditor_ExportFH *message
779 BOOL success = TRUE;
781 D(bug("[PrinterEdit class] PrinterEdit Class Export\n"));
783 Gadgets2PrinterPrefs(CLASS, self);
784 success = Prefs_ExportFH(message->fh);
786 return success;
789 IPTR PrinterEditor__MUIM_PrefsEditor_SetDefaults
791 Class *CLASS, Object *self, Msg message
794 BOOL success = TRUE;
796 D(bug("[PrinterEdit class] PrinterEdit Class SetDefaults\n"));
798 success = Prefs_Default(0);
799 if (success) PrinterPrefs2Gadgets(CLASS, self);
801 return success;
804 /* Re-synchronize with the pd_UnitNum
806 IPTR PrinterEditor__MUIM_PrinterEditor_Sync(Class *CLASS, Object *self, Msg message)
808 SETUP_INST_DATA;
810 struct PrinterDeviceUnitPrefs *devunit = &printerprefs.pp_DeviceUnit;
812 CONST_STRPTR str;
813 LONG unit;
815 unit = XGET(data->pd_UnitNum, MUIA_Cycle_Active);
817 if (unit != devunit->pd_UnitNum) {
818 char buf[64];
819 char path[sizeof(buf) + 7]; /* ENVARC: */
821 D(bug("PrinterEditor_Sync: Unit %d -> %d\n", devunit->pd_UnitNum, unit));
822 sprintf(buf, "SYS/printer%d.prefs", (int)unit);
823 str = (unit ? buf : "SYS/printer.prefs");
824 NNSET(self, MUIA_PrefsEditor_Path, (IPTR) str);
825 /*-- Reload preferences --*/
826 sprintf(path, "ENV:%s", str);
827 if (!DoMethod(self, MUIM_PrefsEditor_Import, path))
829 sprintf(path, "ENVARC:%s", str);
830 if (!DoMethod(self, MUIM_PrefsEditor_Import, path))
832 Prefs_Default(unit);
833 PrinterPrefs2Gadgets(CLASS, self);
834 SET(self, MUIA_PrefsEditor_Changed, TRUE);
835 D(bug("PrinterEditor_Sync: Defaults\n"));
836 return TRUE;
839 NNSET(data->pd_UnitNum, MUIA_Cycle_Active, unit);
840 devunit->pd_UnitNum = unit;
841 D(bug("PrinterEditor_Sync: Loaded\n"));
842 return TRUE;
845 return TRUE;
848 IPTR PrinterEditor__MUIM_PrinterEditor_Refresh(Class *CLASS, Object *self, Msg message)
850 SETUP_INST_DATA;
852 CONST_STRPTR str;
853 int units;
855 D(bug("PrinterEditor_Refresh: Begin\n"));
857 /* Internal scale is deci-inches. Yeah.
859 units = XGET(data->pg_MaxUnits, MUIA_Cycle_Active);
861 if (XGET(data->pt_DriverList, MUIA_List_Active) != MUIV_List_Active_Off) {
862 str = (CONST_STRPTR)XGET(data->pt_DriverList, MUIA_Dirlist_Path);
863 NNSET(data->pt_Driver, MUIA_Text_Contents, FilePart(str));
866 UpdatePrintMax(data, units, FALSE);
868 NNSET(data->pg_OffsetUnits, MUIA_Text_Contents, (IPTR)ui_Units[units]);
870 D(bug("PrinterEditor_Refresh: End\n"));
872 return TRUE;
875 /*** Setup ******************************************************************/
876 ZUNE_CUSTOMCLASS_6
878 PrinterEditor, NULL, MUIC_PrefsEditor, NULL,
879 OM_NEW, struct opSet *,
880 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
881 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
882 MUIM_PrefsEditor_SetDefaults, Msg,
883 MUIM_PrinterEditor_Sync, Msg,
884 MUIM_PrinterEditor_Refresh, Msg