// generated by Fast Light User Interface Designer (fluid) version 1.0110

#include "mainwindow.h"
#define WRITE_UNCOND 1
#define FIX_UNCOND 1 << 1

void xppMainWindow::cb_fileList_i(Fl_Input* o, void*) {
  const char *tmpstr1;
tmpstr1 = (char *)((Fl_Input *)o)->value();
free(print->filelist);
print->filelist = strdup(tmpstr1);
}
void xppMainWindow::cb_fileList(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_fileList_i(o,v);
}

void xppMainWindow::cb_Browse_i(Fl_Button*, void*) {
  const char *chosen_file;
const char *oldfilelist;
chosen_file = fl_file_chooser("File to print","*","");
if (chosen_file)
{
  oldfilelist=fileList->value();
  free(print->filelist);
  int has_space = 0;
  if (strchr(chosen_file, ' ') != NULL) has_space = 2;
  print->filelist = (char *)malloc(strlen(oldfilelist)+strlen(chosen_file)+has_space+2);
  *(print->filelist) = '\0';
  strcat(print->filelist,oldfilelist);
  strcat(print->filelist," ");
  if (has_space) strcat(print->filelist,"\"");
  strcat(print->filelist,chosen_file);
  if (has_space) strcat(print->filelist,"\"");
  fileList->value(print->filelist);
};
}
void xppMainWindow::cb_Browse(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_Browse_i(o,v);
}

void xppMainWindow::cb_numCopies_i(Fl_Counter* o, void*) {
  print->num_copies=(int)((Fl_Counter *)o)->value();
}
void xppMainWindow::cb_numCopies(Fl_Counter* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_numCopies_i(o,v);
}

void xppMainWindow::cb_priority_i(Fl_Counter* o, void*) {
  print->priority=(int)((Fl_Counter *)o)->value();
}
void xppMainWindow::cb_priority(Fl_Counter* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_priority_i(o,v);
}

void xppMainWindow::cb_Options_i(Fl_Button*, void*) {
  xppOptionDialog();
}
void xppMainWindow::cb_Options(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_Options_i(o,v);
}

void xppMainWindow::cb_Instances_i(Fl_Button*, void*) {
  xppInstanceDialog();
}
void xppMainWindow::cb_Instances(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_Instances_i(o,v);
}

void xppMainWindow::cb_Close_i(Fl_Button*, void*) {
  if (instanceDialog) instanceDialog->hide();
if (optionDialog) optionDialog->hide();
mainWindow->hide();
}
void xppMainWindow::cb_Close(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_Close_i(o,v);
}

void xppMainWindow::cb_Print_i(Fl_Return_Button*, void*) {
  print->print(printstat);
if (printstat == 0) {
  if (optionDialog) optionDialog->hide();
  mainWindow->hide();
};
}
void xppMainWindow::cb_Print(Fl_Return_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->user_data()))->cb_Print_i(o,v);
}

void xppMainWindow::cb_papersource_i(Fl_Choice* o, void*) {
  xppUpdatePaperSizeOption(o,WRITE_UNCOND);
}
void xppMainWindow::cb_papersource(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_papersource_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_papersource[] = {
 {"Upper tray", 0,  0, (void*)("Upper"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Middle tray", 0,  0, (void*)("Middle"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Lower tray", 0,  0, (void*)("Lower"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Multi purpose", 0,  0, (void*)("MultiPurpose"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Large capacity", 0,  0, (void*)("LargeCapacity"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Manual Feeder", 0,  0, (void*)("Manual"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_papersize_i(Fl_Choice* o, void*) {
  xppUpdatePaperSizeOption(o,WRITE_UNCOND);
}
void xppMainWindow::cb_papersize(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_papersize_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_papersize[] = {
 {"Letter", 0,  0, (void*)("Letter"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Legal", 0,  0, (void*)("Legal"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"A4", 0,  0, (void*)("A4"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"A3", 0,  0, (void*)("A3"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"COM10", 0,  0, (void*)("COM10"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"DL-ISO", 0,  0, (void*)("DL"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_papertype_i(Fl_Choice* o, void*) {
  xppUpdatePaperSizeOption(o,WRITE_UNCOND);
}
void xppMainWindow::cb_papertype(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_papertype_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_papertype[] = {
 {"Paper", 0,  0, (void*)("Paper"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Transparency", 0,  0, (void*)("Transparency"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_orientation_i(Fl_Choice* o, void*) {
  print->num_changed_options=print->removeOptions("landscape",print->num_changed_options,&(print->changed_options));
if (o->value() != 0) {
  char str[256];
  sprintf(str,"%d",o->value()+3);
  print->num_changed_options=cupsAddOption("orientation-requested",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("orientation-requested",print->num_changed_options,&(print->changed_options));
print->refreshOptionWidgets();
}
void xppMainWindow::cb_orientation(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_orientation_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_orientation[] = {
 {"Portrait", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Landscape", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Reverse Landscape", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Reverse Portrait", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_custom_size_i(Fl_Group*, void*) {
  xppRecalculCustom(0);
xppSetPaperSizeOption(papersize,0);
}
void xppMainWindow::cb_custom_size(Fl_Group* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_custom_size_i(o,v);
}

void xppMainWindow::cb_custom_width_i(Fl_Value_Input* o, void*) {
  print->custom_width_pspt 
	= xppdtopspt(o->value(),
		(custom_unit_t)custom_unit->value());
xppSetPaperSizeOption(papersize,FIX_UNCOND);
o->cursor_color(FL_RED);
}
void xppMainWindow::cb_custom_width(Fl_Value_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_custom_width_i(o,v);
}

void xppMainWindow::cb_custom_height_i(Fl_Value_Input* o, void*) {
  print->custom_height_pspt 
	= xppdtopspt(o->value(),(custom_unit_t)custom_unit->value());
xppSetPaperSizeOption(papersize,FIX_UNCOND);
o->cursor_color(FL_RED);
}
void xppMainWindow::cb_custom_height(Fl_Value_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_custom_height_i(o,v);
}

void xppMainWindow::cb_custom_unit_i(Fl_Menu_Button* o, void*) {
  xppRecalculCustom(1); 
switch ((custom_unit_t)o->value()) {
  case U_MM:
	o->label("mm");
	break;
  case U_IN:
	o->label("  in");
	break;
  case U_PT:
	o->label("  pt");
	break;
  case U_CM:
	o->label(" cm");
	break;
  case U_DIDOT:
        o->label(" dd");
        break;
  case U_PICA:
	o->label(" pc");
	break;
  case U_CICERO:
	o->label(" cc");
	break;
  case U_BIGPT:
	o->label(" bp");
	break;
  default:
	break;
};
}
void xppMainWindow::cb_custom_unit(Fl_Menu_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->parent()->user_data()))->cb_custom_unit_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_custom_unit[] = {
 {"mm", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"in", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"pt", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"cm", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"pc", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"dd", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"cc", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {"bp", 0,  0, 0, 4, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_Mirror_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("mirror","True",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("mirror",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Mirror(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Mirror_i(o,v);
}

void xppMainWindow::cb_Fit_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("fitplot","",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("fitplot",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Fit(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Fit_i(o,v);
}

void xppMainWindow::cb_Page_i(Fl_Input* o, void*) {
  if (strlen(o->value()) != 0)
  print->num_changed_options=cupsAddOption("page-ranges",o->value(),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("page-ranges",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Page(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Page_i(o,v);
}

void xppMainWindow::cb_Reverse_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("OutputOrder","Reverse",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("OutputOrder",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Reverse(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Reverse_i(o,v);
}

void xppMainWindow::cb_Collate_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("Collate","True",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("Collate",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Collate(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Collate_i(o,v);
}

void xppMainWindow::cb_pageset_i(Fl_Choice* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("page-set",(char *)(menu_pageset[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("page-set",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_pageset(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_pageset_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_pageset[] = {
 {"All pages", 0,  0, (void*)("all"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Even pages only", 0,  0, (void*)("even"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Odd pages only", 0,  0, (void*)("odd"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_duplex_i(Fl_Choice* o, void*) {
  print->num_changed_options=print->removeOptions("sides",print->num_changed_options,&(print->changed_options));
print->num_changed_options=cupsAddOption((char*)(o->user_data()),(char *)((o->menu())[o->value()].user_data_),print->num_changed_options,&(print->changed_options));
print->refreshOptionWidgets();
}
void xppMainWindow::cb_duplex(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_duplex_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_duplex[] = {
 {"Single sided", 0,  0, (void*)("one-sided"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Double-sided long-edge", 0,  0, (void*)("two-sided-long-edge"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Double-sided short-edge", 0,  0, (void*)("two-sided-short-edge"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_numberup_i(Fl_Choice* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("number-up",(char *)(menu_numberup[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("number-up",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_numberup(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_numberup_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_numberup[] = {
 {"1", 0,  0, (void*)("1"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"2", 0,  0, (void*)("2"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"3", 0,  0, (void*)("3"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"4", 0,  0, (void*)("4"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"6", 0,  0, (void*)("6"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"9", 0,  0, (void*)("9"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"16", 0,  0, (void*)("16"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_layout_i(Fl_Choice* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("number-up-layout",(char *)(menu_layout[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("number-up-layout",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_layout(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_layout_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_layout[] = {
 {"Left to right, top to bottom", 0,  0, (void*)("lrtb"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Left to right, bottom to top", 0,  0, (void*)("lrbt"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Top to bottom, left to right", 0,  0, (void*)("tblr"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Top to bottom, right to left", 0,  0, (void*)("tbrl"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Right to left, top to bottom", 0,  0, (void*)("rltb"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Right to left, bottom to top", 0,  0, (void*)("rlbt"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Bottom to top, left to right", 0,  0, (void*)("btlr"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Bottom to top, right to left", 0,  0, (void*)("btrl"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_border_i(Fl_Choice* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("page-border",(char *)(menu_border[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("page-border",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_border(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_border_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_border[] = {
 {"None", 0,  0, (void*)("none"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Single", 0,  0, (void*)("single"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Single, Thick", 0,  0, (void*)("single-thick"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Double", 0,  0, (void*)("double"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Double, Thick", 0,  0, (void*)("double-thick"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_Characters_i(Fl_Counter* o, void*) {
  char str[6];
sprintf(str,"%d",(int)o->value());
print->num_changed_options=cupsAddOption("cpi",str,print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Characters(Fl_Counter* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Characters_i(o,v);
}

void xppMainWindow::cb_Lines_i(Fl_Counter* o, void*) {
  char str[6];
sprintf(str,"%d",(int)o->value());
print->num_changed_options=cupsAddOption("lpi",str,print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Lines(Fl_Counter* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Lines_i(o,v);
}

void xppMainWindow::cb_Columns_i(Fl_Counter* o, void*) {
  char str[6];
if (o->value() != 1) {
  sprintf(str,"%d",(int)o->value());
  print->num_changed_options=cupsAddOption("columns",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("columns",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Columns(Fl_Counter* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Columns_i(o,v);
}

void xppMainWindow::cb_Pretty_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("prettyprint","",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("prettyprint",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Pretty(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Pretty_i(o,v);
}

void xppMainWindow::cb_Wrap_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("wrap","",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("wrap",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Wrap(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Wrap_i(o,v);
}

void xppMainWindow::cb_defaultmargins_i(Fl_Light_Button* o, void*) {
  if (o->value()) {
  print->num_changed_options=print->removeOptions("page-top",print->num_changed_options,&(print->changed_options));
  print->num_changed_options=print->removeOptions("page-bottom",print->num_changed_options,&(print->changed_options));
  print->num_changed_options=print->removeOptions("page-left",print->num_changed_options,&(print->changed_options));
  print->num_changed_options=print->removeOptions("page-right",print->num_changed_options,&(print->changed_options));
  print->refreshOptionWidgets();
};
}
void xppMainWindow::cb_defaultmargins(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_defaultmargins_i(o,v);
}

void xppMainWindow::cb_topmargin_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
sprintf(str,"%d",(int)clval);
print->num_changed_options=cupsAddOption("page-top",str,print->num_changed_options,&(print->changed_options));
defaultmargins->value(0);
}
void xppMainWindow::cb_topmargin(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_topmargin_i(o,v);
}

void xppMainWindow::cb_bottommargin_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
sprintf(str,"%d",(int)clval);
print->num_changed_options=cupsAddOption("page-bottom",str,print->num_changed_options,&(print->changed_options));
defaultmargins->value(0);
}
void xppMainWindow::cb_bottommargin(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_bottommargin_i(o,v);
}

void xppMainWindow::cb_leftmargin_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
sprintf(str,"%d",(int)clval);
print->num_changed_options=cupsAddOption("page-left",str,print->num_changed_options,&(print->changed_options));
defaultmargins->value(0);
}
void xppMainWindow::cb_leftmargin(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_leftmargin_i(o,v);
}

void xppMainWindow::cb_rightmargin_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
sprintf(str,"%d",(int)clval);
print->num_changed_options=cupsAddOption("page-right",str,print->num_changed_options,&(print->changed_options));
defaultmargins->value(0);
}
void xppMainWindow::cb_rightmargin(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_rightmargin_i(o,v);
}

void xppMainWindow::cb_Brightness_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
if (clval != 100) {
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption("brightness",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("brightness",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Brightness(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Brightness_i(o,v);
}

void xppMainWindow::cb_Gamma_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
if (clval != 1000) {
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption("gamma",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("gamma",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Gamma(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Gamma_i(o,v);
}

void xppMainWindow::cb_imagepos_i(Fl_Choice* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("position",(char *)(menu_imagepos[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("position",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_imagepos(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_imagepos_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_imagepos[] = {
 {"Center", 0,  0, (void*)("center"), 128, FL_NORMAL_LABEL, 0, 14, 0},
 {"Top", 0,  0, (void*)("top"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Bottom", 0,  0, (void*)("bottom"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Left", 0,  0, (void*)("left"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Right", 0,  0, (void*)("right"), 128, FL_NORMAL_LABEL, 0, 14, 0},
 {"Top-left", 0,  0, (void*)("top-left"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Top-right", 0,  0, (void*)("top-right"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Bottom-left", 0,  0, (void*)("bottom-left"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Bottom-right", 0,  0, (void*)("bottom-right"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_imagesizetype_i(Fl_Choice* o, void*) {
  char str[6];
print->num_changed_options=print->removeOptions("scaling",print->num_changed_options,&(print->changed_options));
print->num_changed_options=print->removeOptions("natural-scaling",print->num_changed_options,&(print->changed_options));
print->num_changed_options=print->removeOptions("ppi",print->num_changed_options,&(print->changed_options));
if (strcasecmp((char *)(menu_imagesizetype[o->value()].user_data()),"default") != 0) {
  imagesize->activate();
  sprintf(str,"%d",(int)imagesize->value());
  print->num_changed_options=cupsAddOption((char *)(menu_imagesizetype[o->value()].user_data()),str,print->num_changed_options,&(print->changed_options));
} else {
  imagesize->deactivate();
};
}
void xppMainWindow::cb_imagesizetype(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_imagesizetype_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_imagesizetype[] = {
 {"Default", 0,  0, (void*)("default"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Scaling: ", 0,  0, (void*)("scaling"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Natural Scaling: ", 0,  0, (void*)("natural-scaling"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"ppi: ", 0,  0, (void*)("ppi"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_imagesize_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
print->num_changed_options=print->removeOptions("scaling",print->num_changed_options,&(print->changed_options));
print->num_changed_options=print->removeOptions("natural-scaling",print->num_changed_options,&(print->changed_options));
print->num_changed_options=print->removeOptions("ppi",print->num_changed_options,&(print->changed_options));
if (strcasecmp((char *)(menu_imagesizetype[imagesizetype->value()].user_data()),"default") != 0) {
  o->activate();
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption((char *)(menu_imagesizetype[imagesizetype->value()].user_data()),str,print->num_changed_options,&(print->changed_options));
} else {
  o->deactivate();
};
}
void xppMainWindow::cb_imagesize(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_imagesize_i(o,v);
}

void xppMainWindow::cb_Saturation_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
if (clval != 100) {
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption("saturation",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("saturation",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Saturation(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Saturation_i(o,v);
}

void xppMainWindow::cb_Hue_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
if (clval != 0) {
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption("hue",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("hue",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Hue(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Hue_i(o,v);
}

void xppMainWindow::cb_Plot_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("blackplot","",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("blackplot",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Plot(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Plot_i(o,v);
}

void xppMainWindow::cb_Pen_i(Input_Slider* o, void*) {
  char str[20];
double clval = o->clamp(o->value());
if (clval != 1000) {
  sprintf(str,"%d",(int)clval);
  print->num_changed_options=cupsAddOption("penwidth",str,print->num_changed_options,&(print->changed_options));
} else
  print->num_changed_options=print->removeOptions("penwidth",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Pen(Input_Slider* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Pen_i(o,v);
}

void xppMainWindow::cb_job_hold_until_i(Fl_Choice* o, void*) {
  if (o->value() != 0) {
  print->num_changed_options=cupsAddOption("job-hold-until",(char *)(menu_job_hold_until[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
  if (o->value() == 8) {
    job_sched_hours->activate();
    job_sched_minutes->activate();
    job_sched_seconds->activate();
    char timestr[9];
    snprintf(timestr, 9, "%02d:%02d:%02d", (int)job_sched_hours->value(), (int)job_sched_minutes->value(), (int)job_sched_seconds->value());
    print->num_changed_options=cupsAddOption("job-hold-until",timestr,print->num_changed_options,&(print->changed_options));
  } else {
    job_sched_hours->deactivate();
    job_sched_minutes->deactivate();
    job_sched_seconds->deactivate();
    print->num_changed_options=cupsAddOption("job-hold-until",(char *)(menu_job_hold_until[o->value()].user_data()),print->num_changed_options,&(print->changed_options));
  }
} else {
  print->num_changed_options=print->removeOptions("job-hold-until",print->num_changed_options,&(print->changed_options));
  job_sched_hours->deactivate();
  job_sched_minutes->deactivate();
  job_sched_seconds->deactivate();
};
}
void xppMainWindow::cb_job_hold_until(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_job_hold_until_i(o,v);
}

Fl_Menu_Item xppMainWindow::menu_job_hold_until[] = {
 {"Immediately", 0,  0, (void*)("no-hold"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Never (Hold Indefinitely)", 0,  0, (void*)("indefinite"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Daytime (6am - 6pm)", 0,  0, (void*)("day-time"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Evening (6pm - 6am)", 0,  0, (void*)("evening"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Night (6pm - 6am)", 0,  0, (void*)("night"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Weekend", 0,  0, (void*)("weekend"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Second Shift (4pm - 12am)", 0,  0, (void*)("second-shift"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Third Shift (12am - 8am)", 0,  0, (void*)("third-shift"), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {"Specified time:", 0,  0, (void*)(""), 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

void xppMainWindow::cb_job_sched_hours_i(Fl_Value_Input*, void*) {
  char timestr[9];
snprintf(timestr, 9, "%02d:%02d:%02d", (int)job_sched_hours->value(), (int)job_sched_minutes->value(), (int)job_sched_seconds->value());
print->num_changed_options=cupsAddOption("job-hold-until",timestr,print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_job_sched_hours(Fl_Value_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_job_sched_hours_i(o,v);
}

void xppMainWindow::cb_job_sched_minutes_i(Fl_Value_Input*, void*) {
  char timestr[9];
snprintf(timestr, 9, "%02d:%02d:%02d", (int)job_sched_hours->value(), (int)job_sched_minutes->value(), (int)job_sched_seconds->value());
print->num_changed_options=cupsAddOption("job-hold-until",timestr,print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_job_sched_minutes(Fl_Value_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_job_sched_minutes_i(o,v);
}

void xppMainWindow::cb_job_sched_seconds_i(Fl_Value_Input*, void*) {
  char timestr[9];
snprintf(timestr, 9, "%02d:%02d:%02d", (int)job_sched_hours->value(), (int)job_sched_minutes->value(), (int)job_sched_seconds->value());
print->num_changed_options=cupsAddOption("job-hold-until",timestr,print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_job_sched_seconds(Fl_Value_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_job_sched_seconds_i(o,v);
}

void xppMainWindow::cb_Billing_i(Fl_Input* o, void*) {
  if (strlen(o->value()) != 0)
  print->num_changed_options=cupsAddOption("job-billing",o->value(),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("job-billing",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_Billing(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Billing_i(o,v);
}

void xppMainWindow::cb_Job_i(Fl_Input* o, void*) {
  print->title = o->value();
}
void xppMainWindow::cb_Job(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_Job_i(o,v);
}

void xppMainWindow::cb_beforejob_i(Fl_Choice*, void*) {
  print->setBannerChanges(beforejob,afterjob);
}
void xppMainWindow::cb_beforejob(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_beforejob_i(o,v);
}

void xppMainWindow::cb_afterjob_i(Fl_Choice*, void*) {
  print->setBannerChanges(beforejob,afterjob);
}
void xppMainWindow::cb_afterjob(Fl_Choice* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_afterjob_i(o,v);
}

void xppMainWindow::cb__i(Fl_Input* o, void*) {
  if (strlen(o->value()) != 0)
  print->num_changed_options=cupsAddOption("page-label",o->value(),print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("page-label",print->num_changed_options,&(print->changed_options));
}
void xppMainWindow::cb_(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb__i(o,v);
}

void xppMainWindow::cb_1_i(Fl_Input* o, void*) {
  print->extra_options = o->value();
}
void xppMainWindow::cb_1(Fl_Input* o, void* v) {
  ((xppMainWindow*)(o->parent()->parent()->parent()->parent()->user_data()))->cb_1_i(o,v);
}

void xppMainWindow::cb_OK_i(Fl_Return_Button*, void*) {
  // Check whether there are conflicting option, advise user and return
if (print->conflicting) {
   fl_alert("Cannot print with these settings, there is a conflict between the options marked in red, please correct them!");
   return;
}
// Mark changes in PPD to restore widgets correctly
ppdMarkDefaults(print->ppds[print->dest_pos]);
cupsMarkOptions(print->ppds[print->dest_pos],print->num_changed_options,print->changed_options);
// Delete old options
cupsFreeOptions(print->dests[print->dest_pos].num_options,
  print->dests[print->dest_pos].options);
// Link new options
print->dests[print->dest_pos].options = print->changed_options;
print->dests[print->dest_pos].num_options=print->num_changed_options;
// Delete pointer to the new options
print->changed_options = NULL;
print->num_changed_options = 0;
// close dialog
optionDialog->hide();
}
void xppMainWindow::cb_OK(Fl_Return_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_OK_i(o,v);
}

void xppMainWindow::cb_Cancel_i(Fl_Button*, void*) {
  // Mark changes in PPD to restore widgets to the old settings
ppdMarkDefaults(print->ppds[print->dest_pos]);
cupsMarkOptions(print->ppds[print->dest_pos],print->dests[print->dest_pos].num_options,print->dests[print->dest_pos].options);
// Free memory used for option entries
cupsFreeOptions(print->num_changed_options, print->changed_options);
// Close Dialog
optionDialog->hide();
}
void xppMainWindow::cb_Cancel(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_Cancel_i(o,v);
}

void xppMainWindow::cb_Save_i(Fl_Button*, void*) {
  int num_dests = 0; int old_num_dests = 0;
cups_dest_t *dests = NULL;
// Check whether there are conflicting options, advise user and return
if (print->conflicting) {
   fl_alert("Cannot save these settings, there is a conflict between the options marked in red, please correct them!");
   return;
}
print->refreshOptionWidgets();
// Save the options in ~/.lpoptions
// Get a copy of the options as currently stored
num_dests = cupsGetDests(&dests);
// Find the current dataset in the data from the file
cups_dest_t *dest_to_save = NULL;
dest_to_save = cupsGetDest
               (print->dests[print->dest_pos].name, 
                print->dests[print->dest_pos].instance, num_dests, dests);
if (!dest_to_save) {
  num_dests = cupsAddDest
              (print->dests[print->dest_pos].name, 
               print->dests[print->dest_pos].instance,
               num_dests, &dests);
  dest_to_save = cupsGetDest
                 (print->dests[print->dest_pos].name, 
                  print->dests[print->dest_pos].instance,
                  num_dests, dests);
}
// Delete old options
cupsFreeOptions(dest_to_save->num_options, dest_to_save->options);
// Link new options
dest_to_save->options = print->changed_options;
dest_to_save->num_options = print->num_changed_options;
// save the options in '~/.lpotions'
cupsSetDests(num_dests,dests);
// Unlink new options
dest_to_save->options = NULL;
dest_to_save->num_options = 0;
// Remove temporary destination list
cupsFreeDests(num_dests,dests);
// Update the options of the printer as one had pressed OK
// Mark changes in PPD to restore widgets correctly
ppdMarkDefaults(print->ppds[print->dest_pos]);
cupsMarkOptions(print->ppds[print->dest_pos],print->num_changed_options,print->changed_options);
// Delete old options
cupsFreeOptions(print->dests[print->dest_pos].num_options,
print->dests[print->dest_pos].options);
// Get a new copy of the options as currently stored (with the ones saved here)
old_num_dests = num_dests;
num_dests = cupsGetDests(&dests);
// cupsSetDests() only saves instances in ~/.lpoptions when at least
// one option differs from the default settings. Thus we may not see the
// new instance. Catch this here so that we don't barf later. 
// This should really be fixed in cups/dest.c:457 but maybe it's a
// feature...
if (num_dests == old_num_dests) {
// Link new options
print->dests[print->dest_pos].options = dests[print->dest_pos].options;
print->dests[print->dest_pos].num_options = dests[print->dest_pos].num_options;
// Unlink new options
dests[print->dest_pos].options = NULL;
dests[print->dest_pos].num_options = 0;
} else {
print->dests[print->dest_pos].options = NULL;
print->dests[print->dest_pos].num_options = 0; 
}
// Remove temporary destination list
cupsFreeDests(num_dests,dests);
}
void xppMainWindow::cb_Save(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_Save_i(o,v);
}

void xppMainWindow::cb_This_i(Fl_Button*, void*) {
  int j;
int num_dests = 0;
cups_dest_t *dests = NULL;
// Get a copy of the options as currently stored
num_dests = cupsGetDests(&dests);
// Set current printer as the default one
for (j = 0; j < num_dests; j ++)
  if (j == print->dest_pos) dests[j].is_default = 1;
  else dests[j].is_default = 0;
// save the options in '~/.lpotions'
cupsSetDests(num_dests,dests);
// Remove temporary destination list
cupsFreeDests(num_dests,dests);
}
void xppMainWindow::cb_This(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_This_i(o,v);
}

void xppMainWindow::cb_Raw_i(Fl_Light_Button* o, void*) {
  if (o->value() != 0)
  print->num_changed_options=cupsAddOption("raw","",print->num_changed_options,&(print->changed_options));
else
  print->num_changed_options=print->removeOptions("raw",print->num_changed_options,&(print->changed_options));
if (o->value()) optionGroups->deactivate(); else optionGroups->activate();
}
void xppMainWindow::cb_Raw(Fl_Light_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_Raw_i(o,v);
}

void xppMainWindow::cb_copybutton_i(Fl_Round_Button*, void*) {
  newname->activate();
}
void xppMainWindow::cb_copybutton(Fl_Round_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_copybutton_i(o,v);
}

void xppMainWindow::cb_renamebutton_i(Fl_Round_Button*, void*) {
  newname->activate();
}
void xppMainWindow::cb_renamebutton(Fl_Round_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_renamebutton_i(o,v);
}

void xppMainWindow::cb_deletebutton_i(Fl_Round_Button*, void*) {
  newname->deactivate();
}
void xppMainWindow::cb_deletebutton(Fl_Round_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_deletebutton_i(o,v);
}

void xppMainWindow::cb_Apply_i(Fl_Return_Button*, void*) {
  int result1 = -1, result2 = -1, val;
if (deletebutton->value()) {
  char buffer[1024];
  char *s = print->dests[instancelist->value()].name;
  char *t = print->dests[instancelist->value()].instance;
  if (t) {
    sprintf(buffer,"Do you really want to delete the instance \"%s\" of the queue \"%s\"?",t,s);
  } else {
    sprintf(buffer,"Do you really want to delete default instance of the queue \"%s\"?",s);
  }
  if (!fl_ask(buffer)) return;
}
val=instancelist->value();
if ((copybutton->value()) || (renamebutton->value())) {
  result1 = print->copyInstance(instancelist->value(),newname->value());
  if (result1 >= 0) {
    if (val >= print->num_dests) {
      val = print->num_dests - 1;
    } else {
      if (val >= result1) val ++;
    }
  }
}
if (result1 >= 0) {
  print->setupDestinationList(instancelist);
  instancelist->value(val);
}
if ((deletebutton->value()) || (renamebutton->value())) {
  if (result1 > -2)
    result2 = print->deleteInstance(instancelist->value());
  if (result2 >= 0) {
    if (val >= print->num_dests) {
      val = print->num_dests - 1;
    } else {
      if ((val > result2) && (val > 0)) val --;
    }
  }
}
if ((result1 >= 0) || (result2 >= 0)) {
  print->setupDestinationList(instancelist);
  instancelist->value(val);
  instancelist->redraw();
};
}
void xppMainWindow::cb_Apply(Fl_Return_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_Apply_i(o,v);
}

void xppMainWindow::cb_Close1_i(Fl_Button*, void*) {
  // Close Dialog
instanceDialog->hide();
}
void xppMainWindow::cb_Close1(Fl_Button* o, void* v) {
  ((xppMainWindow*)(o->parent()->user_data()))->cb_Close1_i(o,v);
}

xppMainWindow::xppMainWindow(int  argc, char *argv[], int &exitstat) {
  exitstat = 0;
optionDialog=NULL;
instanceDialog=NULL;
print=new printFiles(argc,argv,exitstat);
if (exitstat != 0) return;
  { mainWindow = new Fl_Double_Window(520, 365, "X Printing Panel");
    mainWindow->user_data((void*)(this));
    { Fl_Group* o = new Fl_Group(5, 5, 510, 55);
      o->box(FL_UP_BOX);
      { Fl_Box* o = new Fl_Box(10, 10, 500, 30, "X Printing Panel");
        o->labeltype(FL_SHADOW_LABEL);
        o->labelfont(3);
        o->labelsize(24);
        o->labelcolor((Fl_Color)FL_DARK_BLUE);
      } // Fl_Box* o
      { Fl_Box* o = new Fl_Box(10, 40, 500, 15, "Version 1.5 by Till Kamppeter (December 2004)");
        o->labelsize(12);
      } // Fl_Box* o
      o->end();
    } // Fl_Group* o
    { Fl_Group* o = new Fl_Group(5, 65, 510, 295);
      o->box(FL_UP_BOX);
      { Fl_Input* o = fileList = new Fl_Input(190, 75, 245, 25, "File(s) (blank = std. input): ");
        fileList->callback((Fl_Callback*)cb_fileList);
        fileList->when(FL_WHEN_CHANGED);
        o->value(print->filelist);
      } // Fl_Input* fileList
      { Fl_Button* o = new Fl_Button(440, 75, 65, 25, "&Browse...");
        o->down_box(FL_DOWN_BOX);
        o->shortcut(0x80062);
        o->callback((Fl_Callback*)cb_Browse);
        o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
      } // Fl_Button* o
      { Fl_Scroll* o = printerList = new Fl_Scroll(15, 120, 490, 170, "Printers:");
        printerList->box(FL_DOWN_BOX);
        printerList->align(FL_ALIGN_TOP_LEFT);
        printerList->when(FL_WHEN_CHANGED);
        print->insertPrinterList(o);
        printerList->end();
        Fl_Group::current()->resizable(printerList);
      } // Fl_Scroll* printerList
      { Fl_Counter* o = numCopies = new Fl_Counter(70, 295, 65, 25, "Copies: ");
        numCopies->minimum(1);
        numCopies->maximum(100);
        numCopies->step(1);
        numCopies->value(1);
        numCopies->callback((Fl_Callback*)cb_numCopies);
        numCopies->align(FL_ALIGN_LEFT);
        o->value(print->num_copies);
        o->lstep(10);
      } // Fl_Counter* numCopies
      { Fl_Counter* o = priority = new Fl_Counter(200, 295, 50, 25, "Priority: ");
        priority->type(1);
        priority->minimum(1);
        priority->maximum(100);
        priority->step(10);
        priority->value(50);
        priority->callback((Fl_Callback*)cb_priority);
        priority->align(FL_ALIGN_LEFT);
        o->value(print->priority);
      } // Fl_Counter* priority
      { Fl_Button* o = new Fl_Button(265, 295, 115, 25, "&Options...");
        o->down_box(FL_DOWN_BOX);
        o->shortcut(0x8006f);
        o->callback((Fl_Callback*)cb_Options);
      } // Fl_Button* o
      { Fl_Button* o = new Fl_Button(390, 295, 115, 25, "&Instances...");
        o->shortcut(0x80069);
        o->callback((Fl_Callback*)cb_Instances);
      } // Fl_Button* o
      { Fl_Button* o = new Fl_Button(235, 325, 130, 25, "Close");
        o->down_box(FL_DOWN_BOX);
        o->shortcut(0xff1b);
        o->callback((Fl_Callback*)cb_Close);
      } // Fl_Button* o
      { Fl_Return_Button* o = new Fl_Return_Button(375, 325, 130, 25, "Print");
        o->down_box(FL_DOWN_BOX);
        o->shortcut(0xff0d);
        o->callback((Fl_Callback*)cb_Print);
      } // Fl_Return_Button* o
      o->end();
      Fl_Group::current()->resizable(o);
    } // Fl_Group* o
    mainWindow->end();
  } // Fl_Double_Window* mainWindow
  int width=mainWindow->w();
mainWindow->size_range(width, 200, 0, 0, 0, 0, 0);
}

void xppMainWindow::show() {
  mainWindow->show();
}

xppMainWindow::~xppMainWindow() {
  delete print;
}

Fl_Double_Window* xppMainWindow::xppOptionDialog() {
  int i;
const char *str;
print->setDest();
if (print->ppds[print->dest_pos] == 0) {
  // Try to load the PPD file
  str = cupsGetPPD(print->dests[print->dest_pos].name);
  if (str) {
      print->ppds[print->dest_pos] = ppdOpenFile(str);
      unlink(str);
  }
  if (print->ppds[print->dest_pos] != NULL) {
    // Load the Foomatic numerical/string/password options (if present)
    print->num_special_opts[print->dest_pos] = 
      print->getSpecialOptions(&((print->special_opts)[print->dest_pos]));
    // Mark the default options in the PPD file
    ppdMarkDefaults(print->ppds[print->dest_pos]);
    // Mark all given options (~/.lpoptions and command line) in the PPD file
    cupsMarkOptions(print->ppds[print->dest_pos],print->dests[print->dest_pos].num_options,print->dests[print->dest_pos].options);
  }
}
print->changed_options = NULL;
print->inited = print->custom_set = 0;
print->num_changed_options = 0;
for (i = 0; i < print->dests[print->dest_pos].num_options; i ++)
  print->num_changed_options =
    cupsAddOption(
      print->dests[print->dest_pos].options[i].name,
      print->dests[print->dest_pos].options[i].value,
      print->num_changed_options,
      &(print->changed_options));
  { Fl_Double_Window* o = optionDialog = new Fl_Double_Window(540, 495, "Printing Options");
    optionDialog->user_data((void*)(this));
    { optionGroups = new Fl_Tabs(5, 5, 530, 450);
      optionGroups->align(FL_ALIGN_TOP_LEFT);
      { basicOpts = new Fl_Group(5, 30, 530, 425, "Basic");
        basicOpts->hide();
        { Fl_Group* o = new Fl_Group(10, 35, 520, 170, "Media Settings");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Choice* o = papersource = new Fl_Choice(310, 50, 210, 25, "Media source: ");
            papersource->down_box(FL_BORDER_BOX);
            papersource->callback((Fl_Callback*)cb_papersource, (void*)("media"));
            papersource->menu(menu_papersource);
            o->value(print->getChosenValue((char *)(o->user_data()),"media",o->menu()));
          } // Fl_Choice* papersource
          { Fl_Choice* o = papersize = new Fl_Choice(310, 80, 210, 25, "Media size: ");
            papersize->down_box(FL_BORDER_BOX);
            papersize->callback((Fl_Callback*)cb_papersize, (void*)("media"));
            papersize->menu(menu_papersize);
            o->value(print->getChosenValue((char *)(o->user_data()),"media",o->menu()));
          } // Fl_Choice* papersize
          { Fl_Choice* o = papertype = new Fl_Choice(310, 140, 210, 25, "Media type: ");
            papertype->down_box(FL_BORDER_BOX);
            papertype->callback((Fl_Callback*)cb_papertype, (void*)("media"));
            papertype->menu(menu_papertype);
            o->value(print->getChosenValue((char *)(o->user_data()),"media",o->menu()));
          } // Fl_Choice* papertype
          { Fl_Choice* o = orientation = new Fl_Choice(310, 170, 210, 25, "Orientation: ");
            orientation->down_box(FL_BORDER_BOX);
            orientation->callback((Fl_Callback*)cb_orientation);
            orientation->menu(menu_orientation);
            if (print->getOptionValue("landscape")) o->value(1);
            else if (print->getOptionValue("orientation-requested")) o->value(atoi(print->getOptionValue("orientation-requested"))-3);
            else o->value(0);
          } // Fl_Choice* orientation
          { custom_size = new Fl_Group(260, 110, 260, 25, "Custom Size");
            custom_size->labeltype(FL_NO_LABEL);
            custom_size->callback((Fl_Callback*)cb_custom_size);
            custom_size->deactivate();
            { custom_width = new Fl_Value_Input(310, 110, 50, 25, "Width: ");
              custom_width->maximum(5000);
              custom_width->step(0.01);
              custom_width->callback((Fl_Callback*)cb_custom_width);
            } // Fl_Value_Input* custom_width
            { custom_height = new Fl_Value_Input(410, 110, 50, 25, "Height: ");
              custom_height->maximum(5000);
              custom_height->step(0.01);
              custom_height->callback((Fl_Callback*)cb_custom_height);
            } // Fl_Value_Input* custom_height
            { custom_unit = new Fl_Menu_Button(495, 110, 25, 25, "mm");
              custom_unit->down_box(FL_UP_BOX);
              custom_unit->callback((Fl_Callback*)cb_custom_unit, (void*)(NULL));
              custom_unit->align(FL_ALIGN_LEFT);
              custom_unit->when(3);
              custom_unit->menu(menu_custom_unit);
            } // Fl_Menu_Button* custom_unit
            custom_size->end();
          } // Fl_Group* custom_size
          { Fl_Light_Button* o = new Fl_Light_Button(25, 170, 70, 25, "Mirror");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Mirror);
            if ((print->getOptionValue("mirror")) && (strcasecmp(print->getOptionValue("mirror"),"True") == 0)) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          { Fl_Light_Button* o = new Fl_Light_Button(25, 140, 160, 25, "Fit PDF/plot to page");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Fit);
            if (print->getOptionValue("fitplot")) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 210, 520, 240, "Page Ordering");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Input* o = new Fl_Input(310, 230, 210, 25, "Page selection (blank = all; ex: 1, 2, 4-10): ");
            o->callback((Fl_Callback*)cb_Page);
            o->when(FL_WHEN_CHANGED);
            o->value(print->getOptionValue("page-ranges"));
          } // Fl_Input* o
          { Fl_Light_Button* o = new Fl_Light_Button(25, 415, 125, 25, "Reverse output");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Reverse);
            if ((print->getOptionValue("OutputOrder")) && (strcasecmp(print->getOptionValue("OutputOrder"),"Reverse") == 0)) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          { Fl_Light_Button* o = new Fl_Light_Button(25, 385, 75, 25, "Collate");
            o->box(FL_NO_BOX);
            o->value(1);
            o->callback((Fl_Callback*)cb_Collate);
            if ((print->getOptionValue("Collate")) && (strcasecmp(print->getOptionValue("Collate"),"True") == 0)) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          { Fl_Choice* o = pageset = new Fl_Choice(310, 290, 210, 25, "Page set (for double-sided w/o duplex unit): ");
            pageset->down_box(FL_BORDER_BOX);
            pageset->callback((Fl_Callback*)cb_pageset);
            pageset->menu(menu_pageset);
            o->value(print->getChosenValue("page-set",NULL,menu_pageset));
          } // Fl_Choice* pageset
          { Fl_Choice* o = duplex = new Fl_Choice(310, 260, 210, 25, "Duplex printing: ");
            duplex->down_box(FL_BORDER_BOX);
            duplex->callback((Fl_Callback*)cb_duplex, (void*)("sides"));
            duplex->menu(menu_duplex);
            o->value(print->getChosenValue((char*)(o->user_data()),"sides",o->menu()));
          } // Fl_Choice* duplex
          { Fl_Choice* o = numberup = new Fl_Choice(310, 320, 45, 25, "Pages/Sheet: ");
            numberup->down_box(FL_BORDER_BOX);
            numberup->callback((Fl_Callback*)cb_numberup);
            numberup->menu(menu_numberup);
            o->value(print->getChosenValue("number-up",NULL,menu_numberup));
          } // Fl_Choice* numberup
          { Fl_Choice* o = layout = new Fl_Choice(355, 320, 165, 25);
            layout->down_box(FL_BORDER_BOX);
            layout->callback((Fl_Callback*)cb_layout);
            layout->menu(menu_layout);
            o->value(print->getChosenValue("number-up-layout",NULL,menu_layout));
          } // Fl_Choice* layout
          { Fl_Choice* o = border = new Fl_Choice(310, 350, 210, 25, "Border: ");
            border->down_box(FL_BORDER_BOX);
            border->callback((Fl_Callback*)cb_border);
            border->menu(menu_border);
            o->value(print->getChosenValue("page-border",NULL,menu_border));
          } // Fl_Choice* border
          o->end();
        } // Fl_Group* o
        basicOpts->end();
      } // Fl_Group* basicOpts
      { textOpts = new Fl_Group(5, 30, 530, 425, "Text/Margins");
        textOpts->hide();
        { Fl_Group* o = new Fl_Group(10, 35, 520, 100, "Text Printing");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Counter* o = new Fl_Counter(205, 70, 70, 25, "Characters per inch: ");
            o->minimum(1);
            o->maximum(50);
            o->step(1);
            o->value(10);
            o->callback((Fl_Callback*)cb_Characters);
            o->align(FL_ALIGN_LEFT);
            const char *val;
            if ((val = (print->getOptionValue("cpi")))) o->value(atoi(val)); else o->value(10);
            o->lstep(5);
          } // Fl_Counter* o
          { Fl_Counter* o = new Fl_Counter(205, 100, 70, 25, "Lines per inch: ");
            o->minimum(1);
            o->maximum(50);
            o->step(1);
            o->value(6);
            o->callback((Fl_Callback*)cb_Lines);
            o->align(FL_ALIGN_LEFT);
            const char *val;
            if ((val = (print->getOptionValue("lpi")))) o->value(atoi(val)); else o->value(6);
            o->lstep(5);
          } // Fl_Counter* o
          { Fl_Counter* o = new Fl_Counter(205, 40, 70, 25, "Columns: ");
            o->type(1);
            o->minimum(1);
            o->maximum(10);
            o->step(1);
            o->value(1);
            o->callback((Fl_Callback*)cb_Columns);
            o->align(FL_ALIGN_LEFT);
            const char *val;
            if ((val = (print->getOptionValue("columns")))) o->value(atoi(val)); else o->value(1);
          } // Fl_Counter* o
          { Fl_Light_Button* o = new Fl_Light_Button(315, 100, 210, 25, "Pretty printing");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Pretty);
            if (print->getOptionValue("prettyprint")) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          { Fl_Light_Button* o = new Fl_Light_Button(315, 70, 210, 25, "Wrap long lines");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Wrap);
            if (print->getOptionValue("wrap")) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 140, 520, 310, "Margins");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Light_Button* o = defaultmargins = new Fl_Light_Button(440, 410, 75, 25, "Default");
            defaultmargins->box(FL_NO_BOX);
            defaultmargins->callback((Fl_Callback*)cb_defaultmargins);
            int top, bottom, left, right, length, width;
            o->value(1 - print->getPageMargins(top, bottom, left, right, length, width));
          } // Fl_Light_Button* defaultmargins
          { Input_Slider* o = topmargin = new Input_Slider(95, 185, 30, 250, "Top:");
            topmargin->type(4);
            topmargin->box(FL_FLAT_BOX);
            topmargin->color((Fl_Color)FL_BACKGROUND_COLOR);
            topmargin->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            topmargin->labeltype(FL_NORMAL_LABEL);
            topmargin->labelfont(0);
            topmargin->labelsize(14);
            topmargin->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            topmargin->maximum(792);
            topmargin->step(4);
            topmargin->callback((Fl_Callback*)cb_topmargin);
            topmargin->align(FL_ALIGN_TOP);
            topmargin->when(FL_WHEN_CHANGED);
            int top, bottom, left, right, length, width; print->getPageMargins(top, bottom, left, right, length, width);
            o->maximum(length); o->value(top);
          } // Input_Slider* topmargin
          { Input_Slider* o = bottommargin = new Input_Slider(150, 185, 30, 250, "Bottom:");
            bottommargin->type(4);
            bottommargin->box(FL_FLAT_BOX);
            bottommargin->color((Fl_Color)FL_BACKGROUND_COLOR);
            bottommargin->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            bottommargin->labeltype(FL_NORMAL_LABEL);
            bottommargin->labelfont(0);
            bottommargin->labelsize(14);
            bottommargin->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            bottommargin->minimum(792);
            bottommargin->maximum(0);
            bottommargin->step(4);
            bottommargin->callback((Fl_Callback*)cb_bottommargin);
            bottommargin->align(FL_ALIGN_TOP);
            bottommargin->when(FL_WHEN_CHANGED);
            int top, bottom, left, right, length, width; print->getPageMargins(top, bottom, left, right, length, width);
            o->minimum(length); o->value(bottom);
          } // Input_Slider* bottommargin
          { Input_Slider* o = leftmargin = new Input_Slider(265, 250, 250, 25, "Left: ");
            leftmargin->type(5);
            leftmargin->box(FL_FLAT_BOX);
            leftmargin->color((Fl_Color)FL_BACKGROUND_COLOR);
            leftmargin->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            leftmargin->labeltype(FL_NORMAL_LABEL);
            leftmargin->labelfont(0);
            leftmargin->labelsize(14);
            leftmargin->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            leftmargin->maximum(612);
            leftmargin->step(4);
            leftmargin->callback((Fl_Callback*)cb_leftmargin);
            leftmargin->align(FL_ALIGN_LEFT);
            leftmargin->when(FL_WHEN_CHANGED);
            int top, bottom, left, right, length, width; print->getPageMargins(top, bottom, left, right, length, width);
            o->maximum(width); o->value(left);
          } // Input_Slider* leftmargin
          { Input_Slider* o = rightmargin = new Input_Slider(265, 285, 250, 25, "Right: ");
            rightmargin->type(5);
            rightmargin->box(FL_FLAT_BOX);
            rightmargin->color((Fl_Color)FL_BACKGROUND_COLOR);
            rightmargin->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            rightmargin->labeltype(FL_NORMAL_LABEL);
            rightmargin->labelfont(0);
            rightmargin->labelsize(14);
            rightmargin->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            rightmargin->minimum(612);
            rightmargin->maximum(0);
            rightmargin->step(4);
            rightmargin->callback((Fl_Callback*)cb_rightmargin);
            rightmargin->align(FL_ALIGN_LEFT);
            rightmargin->when(FL_WHEN_CHANGED);
            int top, bottom, left, right, length, width; print->getPageMargins(top, bottom, left, right, length, width);
            o->minimum(width); o->value(right);
          } // Input_Slider* rightmargin
          { Fl_Box* o = new Fl_Box(225, 145, 290, 25, "Margin widths in points (pt),");
            o->labelsize(10);
            o->align(FL_ALIGN_RIGHT|FL_ALIGN_INSIDE);
          } // Fl_Box* o
          { Fl_Box* o = new Fl_Box(225, 160, 290, 25, "1 pt = 1/72\" = 0.35 mm");
            o->labelsize(10);
            o->align(FL_ALIGN_RIGHT|FL_ALIGN_INSIDE);
          } // Fl_Box* o
          o->end();
        } // Fl_Group* o
        textOpts->end();
      } // Fl_Group* textOpts
      { advancedOpts = new Fl_Group(10, 35, 520, 415, "Advanced");
        advancedOpts->hide();
        { Fl_Group* o = new Fl_Group(10, 35, 520, 105, "Printout Appearance");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Input_Slider* o = new Input_Slider(100, 70, 425, 25, "Brightness: ");
            o->type(5);
            o->box(FL_FLAT_BOX);
            o->color((Fl_Color)FL_BACKGROUND_COLOR);
            o->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            o->maximum(200);
            o->step(1);
            o->value(100);
            o->callback((Fl_Callback*)cb_Brightness);
            o->align(FL_ALIGN_LEFT);
            o->when(FL_WHEN_CHANGED);
            const char *val;
            if ((val = (print->getOptionValue("brightness")))) o->value(atoi(val)); else o->value(100);
          } // Input_Slider* o
          { Input_Slider* o = new Input_Slider(100, 105, 425, 25, "Gamma: ");
            o->type(5);
            o->box(FL_FLAT_BOX);
            o->color((Fl_Color)FL_BACKGROUND_COLOR);
            o->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            o->maximum(10000);
            o->step(25);
            o->value(1000);
            o->callback((Fl_Callback*)cb_Gamma);
            o->align(FL_ALIGN_LEFT);
            o->when(FL_WHEN_CHANGED);
            const char *val;
            if ((val = (print->getOptionValue("gamma")))) o->value(atoi(val)); else o->value(1000);
          } // Input_Slider* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 145, 520, 175, "Image Printing");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Choice* o = imagepos = new Fl_Choice(100, 180, 185, 25, "Image pos.: ");
            imagepos->down_box(FL_BORDER_BOX);
            imagepos->callback((Fl_Callback*)cb_imagepos);
            imagepos->menu(menu_imagepos);
            o->value(print->getChosenValue("position",NULL,menu_imagepos));
          } // Fl_Choice* imagepos
          { Fl_Choice* o = imagesizetype = new Fl_Choice(100, 215, 130, 25, "Image size: ");
            imagesizetype->down_box(FL_BORDER_BOX);
            imagesizetype->callback((Fl_Callback*)cb_imagesizetype);
            imagesizetype->menu(menu_imagesizetype);
            if (print -> getOptionValue("ppi")) o->value(3);
            else if (print -> getOptionValue("scaling")) o->value(1);
            else if (print -> getOptionValue("natural-scaling")) o->value(2); else o->value(0);
          } // Fl_Choice* imagesizetype
          { Input_Slider* o = imagesize = new Input_Slider(235, 215, 290, 25);
            imagesize->type(5);
            imagesize->box(FL_FLAT_BOX);
            imagesize->color((Fl_Color)FL_BACKGROUND_COLOR);
            imagesize->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            imagesize->labeltype(FL_NORMAL_LABEL);
            imagesize->labelfont(0);
            imagesize->labelsize(14);
            imagesize->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            imagesize->minimum(1);
            imagesize->maximum(1200);
            imagesize->step(5);
            imagesize->value(100);
            imagesize->callback((Fl_Callback*)cb_imagesize);
            imagesize->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
            imagesize->when(FL_WHEN_CHANGED);
            const char *val; if ((val = (print->getOptionValue((char *)(menu_imagesizetype[imagesizetype->value()].user_data()))))) o->value(atoi(val)); else o->value(100);
            if (strcasecmp((char *)(menu_imagesizetype[imagesizetype->value()].user_data()),"default") == 0) o->deactivate();
          } // Input_Slider* imagesize
          { Input_Slider* o = new Input_Slider(100, 250, 425, 25, "Saturation: ");
            o->type(5);
            o->box(FL_FLAT_BOX);
            o->color((Fl_Color)FL_BACKGROUND_COLOR);
            o->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            o->maximum(200);
            o->step(1);
            o->value(100);
            o->callback((Fl_Callback*)cb_Saturation);
            o->align(FL_ALIGN_LEFT);
            o->when(FL_WHEN_CHANGED);
            const char *val;
            if ((val = (print->getOptionValue("saturation")))) o->value(atoi(val)); else o->value(100);
          } // Input_Slider* o
          { Input_Slider* o = new Input_Slider(100, 285, 425, 25, "Hue: ");
            o->type(5);
            o->box(FL_FLAT_BOX);
            o->color((Fl_Color)FL_BACKGROUND_COLOR);
            o->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            o->minimum(-180);
            o->maximum(180);
            o->step(1);
            o->callback((Fl_Callback*)cb_Hue);
            o->align(FL_ALIGN_LEFT);
            o->when(FL_WHEN_CHANGED);
            const char *val;
            if ((val = (print->getOptionValue("hue")))) o->value(atoi(val)); else o->value(0);
          } // Input_Slider* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 325, 520, 125, "HP-GL/2 Printing");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Light_Button* o = new Fl_Light_Button(125, 380, 160, 25, "Plot all in black");
            o->box(FL_NO_BOX);
            o->callback((Fl_Callback*)cb_Plot);
            if (print->getOptionValue("blackplot")) o->value(1); else o->value(0);
          } // Fl_Light_Button* o
          { Input_Slider* o = new Input_Slider(125, 415, 400, 25, "Pen width [\265m]: ");
            o->type(5);
            o->box(FL_FLAT_BOX);
            o->color((Fl_Color)FL_BACKGROUND_COLOR);
            o->selection_color((Fl_Color)FL_BACKGROUND_COLOR);
            o->labeltype(FL_NORMAL_LABEL);
            o->labelfont(0);
            o->labelsize(14);
            o->labelcolor((Fl_Color)FL_FOREGROUND_COLOR);
            o->maximum(10000);
            o->step(25);
            o->value(1000);
            o->callback((Fl_Callback*)cb_Pen);
            o->align(FL_ALIGN_LEFT);
            o->when(FL_WHEN_CHANGED);
            const char *val;
            if ((val = (print->getOptionValue("penwidth")))) o->value(atoi(val)); else o->value(1000);
          } // Input_Slider* o
          o->end();
        } // Fl_Group* o
        advancedOpts->end();
      } // Fl_Group* advancedOpts
      { otherOpts = new Fl_Group(10, 35, 520, 415, "Job/Others");
        { Fl_Group* o = new Fl_Group(10, 35, 520, 120, "Job Control");
          o->box(FL_ENGRAVED_FRAME);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Choice* o = job_hold_until = new Fl_Choice(220, 60, 210, 25, "Schedule printing: ");
            job_hold_until->down_box(FL_BORDER_BOX);
            job_hold_until->callback((Fl_Callback*)cb_job_hold_until);
            job_hold_until->menu(menu_job_hold_until);
            int x; const char *timestr = print->getOptionValue("job-hold-until");
            if (timestr) {if (sscanf(timestr,"%d:%d:%d",&x,&x,&x) == 3) {o->value(8);} else {o->value(print->getChosenValue("job-hold-until",NULL,menu_job_hold_until));}} else {o->value(0);}
          } // Fl_Choice* job_hold_until
          { Fl_Value_Input* o = job_sched_hours = new Fl_Value_Input(435, 60, 25, 25);
            job_sched_hours->maximum(23);
            job_sched_hours->step(1);
            job_sched_hours->callback((Fl_Callback*)cb_job_sched_hours);
            job_sched_hours->deactivate();
            int h,m,s; const char *timestr = print->getOptionValue("job-hold-until");
            if ((timestr) && (sscanf(print->getOptionValue("job-hold-until"),"%d:%d:%d",&h,&m,&s) == 3)) {o->value(h); o->activate();} else {h = 0; o->value(0);}
            if (h < 0) {h = 0; o->value(h);}; if (h > 23) {h = 23; o->value(h);}
          } // Fl_Value_Input* job_sched_hours
          { Fl_Value_Input* o = job_sched_minutes = new Fl_Value_Input(465, 60, 25, 25, ":");
            job_sched_minutes->maximum(59);
            job_sched_minutes->step(1);
            job_sched_minutes->callback((Fl_Callback*)cb_job_sched_minutes);
            job_sched_minutes->deactivate();
            int h,m,s; const char *timestr = print->getOptionValue("job-hold-until");
            if ((timestr) && (sscanf(print->getOptionValue("job-hold-until"),"%d:%d:%d",&h,&m,&s) == 3)) {o->value(m); o->activate();} else {m = 0; o->value(0);}
            if (m < 0) {m = 0; o->value(m);}; if (m > 59) {m = 59; o->value(m);}
          } // Fl_Value_Input* job_sched_minutes
          { Fl_Value_Input* o = job_sched_seconds = new Fl_Value_Input(495, 60, 25, 25, ":");
            job_sched_seconds->maximum(59);
            job_sched_seconds->step(1);
            job_sched_seconds->callback((Fl_Callback*)cb_job_sched_seconds);
            job_sched_seconds->deactivate();
            int h,m,s; const char *timestr = print->getOptionValue("job-hold-until");
            if ((timestr) && (sscanf(print->getOptionValue("job-hold-until"),"%d:%d:%d",&h,&m,&s) == 3)) {o->value(s); o->activate();} else {s = 0; o->value(0);}
            if (s < 0) {s = 0; o->value(s);}; if (s > 59) {s = 59; o->value(s);}
          } // Fl_Value_Input* job_sched_seconds
          { Fl_Input* o = new Fl_Input(310, 90, 210, 25, "Billing information: ");
            o->callback((Fl_Callback*)cb_Billing);
            o->when(FL_WHEN_CHANGED);
            o->value(print->getOptionValue("job-billing"));
          } // Fl_Input* o
          { Fl_Input* o = new Fl_Input(310, 120, 210, 25, "Job name: ");
            o->callback((Fl_Callback*)cb_Job);
            o->when(FL_WHEN_CHANGED);
            o->value(print->title);
          } // Fl_Input* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 160, 520, 60, "Banner Pages");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { beforejob = new Fl_Choice(110, 185, 165, 25, "Before job: ");
            beforejob->down_box(FL_BORDER_BOX);
            beforejob->callback((Fl_Callback*)cb_beforejob);
          } // Fl_Choice* beforejob
          { afterjob = new Fl_Choice(355, 185, 165, 25, "After job: ");
            afterjob->down_box(FL_BORDER_BOX);
            afterjob->callback((Fl_Callback*)cb_afterjob);
            print->initBannerMenues(beforejob,afterjob);
          } // Fl_Choice* afterjob
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 225, 520, 60, "Page Label");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Input* o = new Fl_Input(110, 250, 410, 25);
            o->callback((Fl_Callback*)cb_);
            o->when(FL_WHEN_CHANGED);
            o->value(print->getOptionValue("page-label"));
          } // Fl_Input* o
          o->end();
        } // Fl_Group* o
        { Fl_Group* o = new Fl_Group(10, 290, 520, 160, "Extra Options");
          o->box(FL_ENGRAVED_BOX);
          o->labelfont(1);
          o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
          { Fl_Input* o = new Fl_Input(110, 320, 410, 120);
            o->type(4);
            o->callback((Fl_Callback*)cb_1);
            o->when(FL_WHEN_CHANGED);
            o->value(print->extra_options);
          } // Fl_Input* o
          o->end();
        } // Fl_Group* o
        otherOpts->end();
      } // Fl_Group* otherOpts
      optionGroups->end();
      Fl_Group::current()->resizable(optionGroups);
    } // Fl_Tabs* optionGroups
    { Fl_Return_Button* o = new Fl_Return_Button(470, 460, 65, 25, "OK");
      o->shortcut(0xff0d);
      o->callback((Fl_Callback*)cb_OK);
    } // Fl_Return_Button* o
    { Fl_Button* o = new Fl_Button(400, 460, 65, 25, "Cancel");
      o->shortcut(0xff1b);
      o->callback((Fl_Callback*)cb_Cancel);
    } // Fl_Button* o
    { Fl_Button* o = new Fl_Button(290, 460, 105, 25, "Save settings");
      o->down_box(FL_DOWN_BOX);
      o->callback((Fl_Callback*)cb_Save);
    } // Fl_Button* o
    { Fl_Button* o = new Fl_Button(125, 460, 160, 25, "This printer as default");
      o->callback((Fl_Callback*)cb_This);
    } // Fl_Button* o
    { Fl_Light_Button* o = new Fl_Light_Button(20, 460, 100, 25, "Raw output");
      o->callback((Fl_Callback*)cb_Raw);
      if ((print->getOptionValue("raw")) && (strcasecmp(print->getOptionValue("raw"),"False") != 0)) o->value(1); else o->value(0);
      if (o->value()) optionGroups->deactivate(); else optionGroups->activate();
    } // Fl_Light_Button* o
    char str[256];
    sprintf(str,"Options for %s",print->menu_strs[print->dest_pos]);
    o->label(str);
    optionDialog->set_modal();
    optionDialog->end();
  } // Fl_Double_Window* optionDialog
  print->tabgroup=optionGroups;
print->papersizewidget=papersize;
print->papersourcewidget=papersource;
print->papertypewidget=papertype;
print->duplexwidget=duplex;
print->topmargin=topmargin;
print->bottommargin=bottommargin;
print->leftmargin=leftmargin;
print->rightmargin=rightmargin;
print->papercustomsizewidget = custom_size;
print->buildOptionWidgets(); 
optionDialog->show();
print->refreshOptionWidgets();
  return optionDialog;
}

Fl_Double_Window* xppMainWindow::xppInstanceDialog() {
  { instanceDialog = new Fl_Double_Window(364, 275, "Instances");
    instanceDialog->user_data((void*)(this));
    { Fl_Box* o = new Fl_Box(5, 5, 355, 65);
      o->box(FL_ENGRAVED_FRAME);
      o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { Fl_Box* o = new Fl_Box(10, 10, 345, 25, "Current instance:");
      o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { Fl_Choice* o = instancelist = new Fl_Choice(15, 35, 335, 25);
      instancelist->down_box(FL_BORDER_BOX);
      instancelist->labeltype(FL_NO_LABEL);
      instancelist->align(FL_ALIGN_CENTER);
      print->setupDestinationList(o);
      print->setDest();
      o->value(print->dest_pos);
    } // Fl_Choice* instancelist
    { Fl_Box* o = new Fl_Box(5, 75, 355, 125);
      o->box(FL_ENGRAVED_FRAME);
      o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { copybutton = new Fl_Round_Button(10, 80, 60, 25, "&Copy");
      copybutton->type(102);
      copybutton->down_box(FL_ROUND_DOWN_BOX);
      copybutton->value(1);
      copybutton->shortcut(0x80063);
      copybutton->callback((Fl_Callback*)cb_copybutton);
    } // Fl_Round_Button* copybutton
    { renamebutton = new Fl_Round_Button(75, 80, 80, 25, "&Rename");
      renamebutton->type(102);
      renamebutton->down_box(FL_ROUND_DOWN_BOX);
      renamebutton->shortcut(0x80072);
      renamebutton->callback((Fl_Callback*)cb_renamebutton);
    } // Fl_Round_Button* renamebutton
    { Fl_Box* o = new Fl_Box(15, 105, 335, 25, "this instance to (blank = Default instance):");
      o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { newname = new Fl_Input(15, 130, 335, 25);
      newname->labeltype(FL_NO_LABEL);
      newname->align(FL_ALIGN_CENTER);
    } // Fl_Input* newname
    { Fl_Box* o = new Fl_Box(15, 160, 335, 25, "To add a new instance, copy an instance of the");
      o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { Fl_Box* o = new Fl_Box(15, 175, 335, 25, "desired printer.");
      o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { Fl_Box* o = new Fl_Box(5, 205, 355, 35);
      o->box(FL_ENGRAVED_FRAME);
      o->align(FL_ALIGN_TOP_LEFT|FL_ALIGN_INSIDE);
    } // Fl_Box* o
    { deletebutton = new Fl_Round_Button(10, 210, 175, 25, "&Delete this instance");
      deletebutton->type(102);
      deletebutton->down_box(FL_ROUND_DOWN_BOX);
      deletebutton->shortcut(0x80064);
      deletebutton->callback((Fl_Callback*)cb_deletebutton);
    } // Fl_Round_Button* deletebutton
    { Fl_Return_Button* o = new Fl_Return_Button(270, 245, 90, 25, "Apply");
      o->shortcut(0xff0d);
      o->callback((Fl_Callback*)cb_Apply);
    } // Fl_Return_Button* o
    { Fl_Button* o = new Fl_Button(175, 245, 90, 25, "Close");
      o->shortcut(0xff1b);
      o->callback((Fl_Callback*)cb_Close1);
    } // Fl_Button* o
    instanceDialog->set_modal();
    instanceDialog->end();
  } // Fl_Double_Window* instanceDialog
  instanceDialog->show();
  return instanceDialog;
}

void xppMainWindow::xppRecalculCustom(int refresh) {
  custom_unit_t what = (custom_unit_t)custom_unit->value();
custom_width->value(xpppspttod(print->custom_width_pspt, what));
custom_height->value(xpppspttod(print->custom_height_pspt, what));
custom_width->cursor_color(FL_BLACK);
custom_width->when(FL_WHEN_CHANGED);
custom_width->soft(0);
custom_height->soft(0);
custom_height->cursor_color(FL_BLACK);
custom_height->when(FL_WHEN_CHANGED);
if (refresh)
   print->refreshOptionWidgets();
}

double xppMainWindow::xpppspttod(int val, custom_unit_t what) {
  switch(what) {
      case U_PICA:
	  return (double)(val / 11.956);
	  break;
      case U_DIDOT:
	  return (double)(val / 1.066);
	  break;
      case U_CICERO:
	  return (double)(val / 12.792);
	  break;
      case U_BIGPT:
	  return (double)(val);
	  break;
      case U_MM:
	  return (double)(val / 2.835);
	  break;
      case U_IN:
	  return (double)(val / 72.0);
	  break;
      case U_PT:
	  return (double)(val / 0.995);
	  break;
      case U_CM:
	  return (double)(val / 28.346);
	  break;
      default:
          return (double)val;
	  break;
}
}

int xppMainWindow::xppdtopspt(double val, custom_unit_t what) {
  switch(what) {
      case U_PICA:
	  return (int)(val * 11.956);
	  break;
      case U_DIDOT:
	  return (int)(val * 1.066);
	  break;
      case U_CICERO:
	  return (int)(val * 12.792);
	  break;
      case U_BIGPT:
	  return (int)(val);
	  break;
      case U_MM:
	  return (int)(val * 2.835);
	  break;
      case U_IN:
	  return (int)(val * 72.0);
	  break;
      case U_PT:
	  return (int)(val * 0.995);
	  break;
      case U_CM:
	  return (int)(val * 28.346);
	  break;
      default:
          return (int)val;
	  break;
}
}

void xppMainWindow::xppUpdatePaperSizeOption(Fl_Widget *o, int flags) {
  xppSetPaperSizeOption(o,flags);
          print->refreshOptionWidgets();
}

void xppMainWindow::xppSetPaperSizeOption(Fl_Widget *o, unsigned int flags) {
  #define CUSTOM "Custom"
#define LEN_CUSTOM strlen(CUSTOM)

char *paper_size, *paper_source, *paper_type;
char str[256];
int fixed = 0;
if (papersize->menu()) {
    paper_size = (char *)
           ((papersize->menu())[papersize->value()].user_data());
    if (strncasecmp(paper_size,CUSTOM,LEN_CUSTOM) != 0) {
   	if (custom_size->active())
           custom_size->deactivate();
    } else {	
       	if (!custom_size->active()) {
	   custom_size->activate();
       	   xppRecalculCustom(0);
        }
        if (flags & FIX_UNCOND || strlen(paper_size) == LEN_CUSTOM) {
           snprintf(str,255, CUSTOM".%ix%i\n",
           print->custom_width_pspt,
           print->custom_height_pspt);
           paper_size = str;
           fixed = 1;
	   /* saved or command line "Custom" setting: mark as set */
	   if (!print->inited)
	      print->custom_set = 1;
        }
    }
}
print->inited = 1;
if (fixed || flags & WRITE_UNCOND) {
    if (papersource->menu()) 
       paper_source = (char *)((papersource->menu())
		[papersource->value()].user_data());
    if (papertype->menu()) 
       paper_type = (char *)((papertype->menu())
		[papertype->value()].user_data());
    print->num_changed_options=
    print->removeOptions("media",print->num_changed_options,
	   &(print->changed_options));
    if (strcasecmp((char *)(o->user_data()),"media") == 0) {
        char str[256];
        sprintf(str,"%s,%s,%s",paper_source,paper_size,paper_type);
        print->num_changed_options=
	   cupsAddOption("media",str,print->num_changed_options,
	     &(print->changed_options));
    } else {
       if (papersource->menu()) 
           print->num_changed_options
	       =cupsAddOption((char *)(papersource->user_data()),
		   paper_source,print->num_changed_options,
		   &(print->changed_options));
       if (papersize->menu()) 
           print->num_changed_options
	       =cupsAddOption((char *)(papersize->user_data()),
		   paper_size,print->num_changed_options,
		   &(print->changed_options));
       if (papertype->menu()) 
           print->num_changed_options
               =cupsAddOption((char *)(papertype->user_data()),
		   paper_type,print->num_changed_options,
		   &(print->changed_options));
   }
}
}
