+ Init(data);
+}
+
+/* XPM */
+static const char * check_xpm[] = {
+/* width height ncolors chars_per_pixel */
+"16 16 3 1",
+/* colors */
+" s None c None",
+"X c #000000",
+". c #808080",
+/* pixels */
+" ",
+" ",
+" ",
+" .. ",
+" XX ",
+" XX. ",
+" .XX ",
+" XX ",
+" X XX. ",
+" XX .XX ",
+" XX XX ",
+" XXXX. ",
+" XX. ",
+" . ",
+" ",
+" "
+};
+
+
+void wxGenericPrintSetupDialog::Init(wxPrintData* data)
+{
+ if ( data )
+ m_printData = *data;
+
+ m_targetData = data;
+
+ wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
+
+ // printer selection
+
+ wxStaticBoxSizer *printer_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Printer") ), wxVERTICAL );
+ main_sizer->Add( printer_sizer, 0, wxALL|wxGROW, 10 );
+
+ m_printerListCtrl = new wxListCtrl( this, wxPRINTID_PRINTER,
+ wxDefaultPosition, wxSize(wxDefaultCoord,100), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
+ wxImageList *image_list = new wxImageList;
+ image_list->Add( wxBitmap(check_xpm) );
+ m_printerListCtrl->AssignImageList( image_list, wxIMAGE_LIST_SMALL );
+
+ m_printerListCtrl->InsertColumn( 0, wxT(" "), wxLIST_FORMAT_LEFT, 20 );
+ m_printerListCtrl->InsertColumn( 1, wxT("Printer"), wxLIST_FORMAT_LEFT, 150 );
+ m_printerListCtrl->InsertColumn( 2, wxT("Device"), wxLIST_FORMAT_LEFT, 150 );
+ m_printerListCtrl->InsertColumn( 3, wxT("Status"), wxLIST_FORMAT_LEFT, 80 );
+
+ wxListItem item;
+ item.SetMask( wxLIST_MASK_TEXT );
+ item.SetColumn( 1 );
+ item.SetText( _("Default printer") );
+ item.SetId( m_printerListCtrl->InsertItem( item ) );
+
+ if (data->GetPrinterName().empty())
+ {
+ wxListItem item2;
+ item2.SetId( item.GetId() );
+ item2.SetMask( wxLIST_MASK_IMAGE );
+ item2.SetImage( 0 );
+ m_printerListCtrl->SetItem( item2 );
+ // also select item
+ m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
+ }
+
+ item.SetId( 1+ item.GetId() );
+
+ wxArrayString errors;
+ wxArrayString output;
+ long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
+ if (res >= 0 && errors.GetCount() == 0)
+ {
+ size_t i;
+ for (i = 0; i < output.GetCount(); i++)
+ {
+ wxStringTokenizer tok( output[i], wxT(" ") );
+ wxString tmp = tok.GetNextToken(); // "device"
+ if (tmp != wxT("device"))
+ break; // the lpstat syntax must have changed.
+ tmp = tok.GetNextToken(); // "for"
+ if (tmp != wxT("for"))
+ break; // the lpstat syntax must have changed.
+ tmp = tok.GetNextToken(); // "hp_deskjet930c:"
+ if (tmp[tmp.length()-1] == wxT(':'))
+ tmp.Remove(tmp.length()-1,1);
+ wxString name = tmp;
+ item.SetText( name );
+ item.SetId( m_printerListCtrl->InsertItem( item ) );
+ tmp = tok.GetNextToken(); // "parallel:/dev/lp0"
+ item.SetColumn( 2 );
+ item.SetText( tmp );
+ m_printerListCtrl->SetItem( item );
+ if (data->GetPrinterName() == name)
+ {
+ wxListItem item2;
+ item2.SetId( item.GetId() );
+ item2.SetMask( wxLIST_MASK_IMAGE );
+ item2.SetImage( 0 );
+ m_printerListCtrl->SetItem( item2 );
+ // also select item
+ m_printerListCtrl->SetItemState( item.GetId(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
+ }
+
+ wxString command = wxT("lpstat -p ");
+ command += name;
+ wxArrayString errors2;
+ wxArrayString output2;
+ res = wxExecute( command, output2, errors2, wxEXEC_NODISABLE );
+ if (res >= 0 && errors2.GetCount() == 0 && output2.GetCount() > 0)
+ {
+ tmp = output2[0]; // "printer hp_deskjet930c is idle. enable since ..."
+ int pos = tmp.Find( wxT('.') );
+ if (pos != wxNOT_FOUND)
+ tmp.Remove( (size_t)pos, tmp.length()-(size_t)pos );
+ wxStringTokenizer tok2( tmp, wxT(" ") );
+ tmp = tok2.GetNextToken(); // "printer"
+ tmp = tok2.GetNextToken(); // "hp_deskjet930c"
+ tmp = wxEmptyString;
+ while (tok2.HasMoreTokens())
+ {
+ tmp += tok2.GetNextToken();
+ tmp += wxT(" ");
+ }
+ item.SetColumn( 3 );
+ item.SetText( tmp );
+ m_printerListCtrl->SetItem( item );
+ }
+
+ item.SetColumn( 1 );
+ item.SetId( 1+ item.GetId() );
+ }
+ }
+
+
+ printer_sizer->Add( m_printerListCtrl, 0, wxALL|wxGROW, 5 );
+
+ wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
+ main_sizer->Add( item1, 0, wxALL, 5 );
+
+ // printer options (on the left)
+
+ wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
+
+ wxStaticBox *item4 = new wxStaticBox( this, wxPRINTID_STATIC, _("Paper size") );
+ wxStaticBoxSizer *item3 = new wxStaticBoxSizer( item4, wxVERTICAL );
+
+ m_paperTypeChoice = CreatePaperTypeChoice();
+ item3->Add( m_paperTypeChoice, 0, wxALIGN_CENTER|wxALL, 5 );
+
+ item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );