]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/prntdlgg.cpp
Fix install_name_tool calls in OS X "make install".
[wxWidgets.git] / src / generic / prntdlgg.cpp
index 25d85900beb2c7048476758c91e1f5025352bcf9..41d3dda771579bbbbf72b9833ef51c1b0a175d92 100644 (file)
@@ -1,10 +1,9 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        prntdlgg.cpp
+// Name:        src/generic/prntdlgg.cpp
 // Purpose:     Generic print dialogs
 // Author:      Julian Smart
 // Modified by:
 // Created:     04/01/98
-// RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "prntdlgg.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -30,6 +25,8 @@
 
 #if wxUSE_PRINTING_ARCHITECTURE && (!defined(__WXMSW__) || wxUSE_POSTSCRIPT_ARCHITECTURE_IN_MSW)
 
+#include "wx/generic/prntdlgg.h"
+
 #ifndef WX_PRECOMP
     #include "wx/utils.h"
     #include "wx/dc.h"
 #endif
 
 #if wxUSE_STATLINE
-  #include "wx/statline.h"
+    #include "wx/statline.h"
 #endif
 
-#include "wx/generic/prntdlgg.h"
-
 #if wxUSE_POSTSCRIPT
     #include "wx/generic/dcpsg.h"
 #endif
 #include <stdlib.h>
 #include <string.h>
 
+#ifndef __WXUNIVERSAL__
+
+#if wxUSE_GTKPRINT
+    #include "wx/link.h"
+    wxFORCE_LINK_MODULE(gtk_print)
+#endif
+
+#endif // !wxUniv
+
 // ----------------------------------------------------------------------------
 // global vars
 // ----------------------------------------------------------------------------
@@ -82,7 +86,7 @@ IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
 
 wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
 {
-    m_previewCommand = wxT("");
+    m_previewCommand = wxEmptyString;
 #ifdef __VMS__
     m_printerCommand = wxT("print");
     m_printerOptions = wxT("/nonotify/queue=psqueue");
@@ -91,14 +95,14 @@ wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
 
 #ifdef __WXMSW__
     m_printerCommand = wxT("print");
-    m_printerOptions = wxT("");
+    m_printerOptions = wxEmptyString;
     m_afmPath = wxT("c:\\windows\\system\\");
 #endif
 
 #if !defined(__VMS__) && !defined(__WXMSW__)
     m_printerCommand = wxT("lpr");
-    m_printerOptions = wxT("");
-    m_afmPath = wxT("");
+    m_printerOptions = wxEmptyString;
+    m_afmPath = wxEmptyString;
 #endif
 
     m_printerScaleX = 1.0;
@@ -135,8 +139,9 @@ END_EVENT_TABLE()
 
 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
                                            wxPrintDialogData* data)
-                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
-                               wxPoint(0, 0), wxSize(600, 600),
+                    : wxPrintDialogBase(GetParentForModalDialog(parent, 0),
+                               wxID_ANY, _("Print"),
+                               wxPoint(0,0), wxSize(600, 600),
                                wxDEFAULT_DIALOG_STYLE |
                                wxTAB_TRAVERSAL)
 {
@@ -148,8 +153,9 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
 
 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
                                            wxPrintData* data)
-                    : wxPrintDialogBase(parent, wxID_ANY, _("Print"),
-                               wxPoint(0, 0), wxSize(600, 600),
+                    : wxPrintDialogBase(GetParentForModalDialog(parent, 0),
+                                wxID_ANY, _("Print"),
+                               wxPoint(0,0), wxSize(600, 600),
                                wxDEFAULT_DIALOG_STYLE |
                                wxTAB_TRAVERSAL)
 {
@@ -161,7 +167,7 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent,
 
 void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
 {
-  //    wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0, 0), wxSize(600, 600),
+  //    wxDialog::Create(parent, wxID_ANY, _("Print"), wxPoint(0,0), wxSize(600, 600),
   //                     wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL);
 
     wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
@@ -196,9 +202,9 @@ void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
     if (factory->HasStatusLine())
     {
         flex->Add( new wxStaticText( this, wxID_ANY, _("Status:") ),
-            0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
+            0, wxALIGN_CENTER_VERTICAL|(wxALL-wxTOP), 5 );
         flex->Add( new wxStaticText( this, wxID_ANY, factory->CreateStatusLine() ),
-            0, wxALIGN_CENTER_VERTICAL|wxALL-wxTOP, 5 );
+            0, wxALIGN_CENTER_VERTICAL|(wxALL-wxTOP), 5 );
     }
 
     mainsizer->Add( topsizer, 0, wxLEFT|wxTOP|wxRIGHT|wxGROW, 10 );
@@ -209,16 +215,15 @@ void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
     choices[0] = _("All");
     choices[1] = _("Pages");
 
-    m_fromText = (wxTextCtrl*)NULL;
-    m_toText = (wxTextCtrl*)NULL;
-    m_rangeRadioBox = (wxRadioBox *)NULL;
+    m_fromText = NULL;
+    m_toText = NULL;
+    m_rangeRadioBox = NULL;
 
     if (m_printDialogData.GetFromPage() != 0)
     {
         m_rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
                                          wxDefaultPosition, wxDefaultSize,
-                                         2, choices,
-                                         1, wxRA_VERTICAL);
+                                         2, choices);
         m_rangeRadioBox->SetSelection(1);
 
         mainsizer->Add( m_rangeRadioBox, 0, wxLEFT|wxTOP|wxRIGHT, 10 );
@@ -245,14 +250,11 @@ void wxGenericPrintDialog::Init(wxWindow * WXUNUSED(parent))
 
     mainsizer->Add( bottomsizer, 0, wxTOP|wxLEFT|wxRIGHT, 12 );
 
-#if wxUSE_STATLINE
-    // 4) static line
-    mainsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
-#endif
-
-    // 5) buttons
+    // 4) buttons
 
-    mainsizer->Add( CreateButtonSizer( wxOK|wxCANCEL), 0, wxEXPAND|wxALL, 10 );
+    wxSizer *sizerBtn = CreateSeparatedButtonSizer( wxOK|wxCANCEL);
+    if ( sizerBtn )
+        mainsizer->Add(sizerBtn, 0, wxEXPAND|wxALL, 10 );
 
     SetAutoLayout( true );
     SetSizer( mainsizer );
@@ -294,7 +296,7 @@ void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
         wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
 
         wxFileDialog dialog( this, _("PostScript file"),
-            fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxSAVE | wxOVERWRITE_PROMPT );
+            fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
         if (dialog.ShowModal() != wxID_OK) return;
 
         m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
@@ -348,14 +350,16 @@ bool wxGenericPrintDialog::TransferDataToWindow()
              m_fromText->Enable(true);
              m_toText->Enable(true);
              if (m_printDialogData.GetFromPage() > 0)
-                m_fromText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetFromPage()));
+                m_fromText->SetValue(wxString::Format(wxT("%d"), m_printDialogData.GetFromPage()));
              if (m_printDialogData.GetToPage() > 0)
-                m_toText->SetValue(wxString::Format(_T("%d"), m_printDialogData.GetToPage()));
+                m_toText->SetValue(wxString::Format(wxT("%d"), m_printDialogData.GetToPage()));
              if(m_rangeRadioBox)
+             {
                 if (m_printDialogData.GetAllPages() || m_printDialogData.GetFromPage() == 0)
                    m_rangeRadioBox->SetSelection(0);
                 else
                    m_rangeRadioBox->SetSelection(1);
+             }
           }
           else
           {
@@ -370,7 +374,7 @@ bool wxGenericPrintDialog::TransferDataToWindow()
        }
     }
     m_noCopiesText->SetValue(
-        wxString::Format(_T("%d"), m_printDialogData.GetNoCopies()));
+        wxString::Format(wxT("%d"), m_printDialogData.GetNoCopies()));
 
     m_printToFileCheckBox->SetValue(m_printDialogData.GetPrintToFile());
     m_printToFileCheckBox->Enable(m_printDialogData.GetEnablePrintToFile());
@@ -442,19 +446,19 @@ BEGIN_EVENT_TABLE(wxGenericPrintSetupDialog, wxDialog)
 END_EVENT_TABLE()
 
 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
-wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
+wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0,0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
 {
     Init(data);
 }
 
 /* XPM */
-static char * check_xpm[] = {
+static const char* const check_xpm[] = {
 /* width height ncolors chars_per_pixel */
 "16 16 3 1",
 /* colors */
-"      s None  c None",
-"X     c #000000",
-".     c #808080",
+"  s None c None",
+"X c #000000",
+". c #808080",
 /* pixels */
 "                ",
 "                ",
@@ -513,13 +517,15 @@ void wxGenericPrintSetupDialog::Init(wxPrintData* data)
         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 );
+    long res = wxExecute( wxT("lpstat -v"), output, errors, wxEXEC_NODISABLE );
     if (res >= 0 && errors.GetCount() == 0)
     {
         size_t i;
@@ -533,8 +539,8 @@ void wxGenericPrintSetupDialog::Init(wxPrintData* data)
             if (tmp != wxT("for"))
                 break;  // the lpstat syntax must have changed.
             tmp = tok.GetNextToken();          // "hp_deskjet930c:"
-            if (tmp[tmp.Len()-1] == wxT(':'))
-                tmp.Remove(tmp.Len()-1,1);
+            if (tmp[tmp.length()-1] == wxT(':'))
+                tmp.Remove(tmp.length()-1,1);
             wxString name = tmp;
             item.SetText( name );
             item.SetId( m_printerListCtrl->InsertItem( item ) );
@@ -549,23 +555,25 @@ void wxGenericPrintSetupDialog::Init(wxPrintData* data)
                 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 );
+            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.Len()-(size_t)pos );
+                    tmp.Remove( (size_t)pos, tmp.length()-(size_t)pos );
                 wxStringTokenizer tok2( tmp, wxT(" ") );
                 tmp = tok2.GetNextToken();  // "printer"
                 tmp = tok2.GetNextToken();  // "hp_deskjet930c"
-                tmp = wxT("");
+                tmp = wxEmptyString;
                 while (tok2.HasMoreTokens())
                 {
                     tmp += tok2.GetNextToken();
@@ -629,7 +637,7 @@ void wxGenericPrintSetupDialog::Init(wxPrintData* data)
 
     item13->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
 
-    m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxT(""), wxDefaultPosition, wxSize(160,wxDefaultCoord) );
+    m_printerCommandText = new wxTextCtrl( this, wxPRINTID_COMMAND, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
     item13->Add( m_printerCommandText, 0, wxALIGN_CENTER|wxALL, 5 );
 
     item10->Add( item13, 0, wxALIGN_CENTER|wxALL, 0 );
@@ -641,7 +649,7 @@ void wxGenericPrintSetupDialog::Init(wxPrintData* data)
 
     item16->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
 
-    m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxT(""), wxDefaultPosition, wxSize(160,wxDefaultCoord) );
+    m_printerOptionsText = new wxTextCtrl( this, wxPRINTID_OPTIONS, wxEmptyString, wxDefaultPosition, wxSize(160,wxDefaultCoord) );
     item16->Add( m_printerOptionsText, 0, wxALIGN_CENTER|wxALL, 5 );
 
     item10->Add( item16, 0, wxALIGN_CENTER|wxALL, 0 );
@@ -678,8 +686,7 @@ wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
 void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
 {
     // Delete check mark
-    long item;
-    for (item = 0; item < m_printerListCtrl->GetItemCount(); item++)
+    for (long item = 0; item < m_printerListCtrl->GetItemCount(); item++)
         m_printerListCtrl->SetItemImage( item, -1 );
 
     m_printerListCtrl->SetItemImage( event.GetIndex(), 0 );
@@ -690,14 +697,12 @@ void wxGenericPrintSetupDialog::OnPrinter(wxListEvent& event)
     }
     else
     {
-        wxString tmp = wxT("lpr -P");
-        wxListItem item;
-        item.SetColumn( 1 );
-        item.SetMask( wxLIST_MASK_TEXT );
-        item.SetId( event.GetIndex() );
-        m_printerListCtrl->GetItem( item );
-        tmp += item.GetText();
-        m_printerCommandText->SetValue( tmp );
+        wxListItem li;
+        li.SetColumn( 1 );
+        li.SetMask( wxLIST_MASK_TEXT );
+        li.SetId( event.GetIndex() );
+        m_printerListCtrl->GetItem( li );
+        m_printerCommandText->SetValue( wxT("lpr -P") + li.GetText() );
     }
 }
 
@@ -706,9 +711,9 @@ bool wxGenericPrintSetupDialog::TransferDataToWindow()
     wxPostScriptPrintNativeData *data =
         (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
 
-    if (m_printerCommandText && data->GetPrinterCommand())
+    if (m_printerCommandText && !data->GetPrinterCommand().empty())
         m_printerCommandText->SetValue(data->GetPrinterCommand());
-    if (m_printerOptionsText && data->GetPrinterOptions())
+    if (m_printerOptionsText && !data->GetPrinterOptions().empty())
         m_printerOptionsText->SetValue(data->GetPrinterOptions());
     if (m_colourCheckBox)
         m_colourCheckBox->SetValue(m_printData.GetColour());
@@ -732,7 +737,7 @@ bool wxGenericPrintSetupDialog::TransferDataFromWindow()
     long id = m_printerListCtrl->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
     if (id == 0)
     {
-        m_printData.SetPrinterName( wxT("") );
+        m_printData.SetPrinterName( wxEmptyString );
     }
     else
     {
@@ -793,7 +798,7 @@ wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice()
 
     wxComboBox *choice = new wxComboBox( this,
                                          wxPRINTID_PAPERSIZE,
-                                         _("Paper Size"),
+                                         _("Paper size"),
                                          wxDefaultPosition,
                                          wxSize(width, wxDefaultCoord),
                                          n, choices );
@@ -820,8 +825,8 @@ wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
                                                     wxPageSetupDialogData* data)
     : wxPageSetupDialogBase( parent,
                 wxID_ANY,
-                _("Page Setup"),
-                wxPoint(0, 0),
+                _("Page setup"),
+                wxPoint(0,0),
                 wxSize(600, 600),
                 wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
 {
@@ -847,7 +852,7 @@ wxGenericPageSetupDialog::wxGenericPageSetupDialog( wxWindow *parent,
 
     m_paperTypeChoice = new wxComboBox( this,
                                         wxPRINTID_PAPERSIZE,
-                                        _("Paper Size"),
+                                        _("Paper size"),
                                         wxDefaultPosition,
                                         wxSize(300, wxDefaultCoord),
                                         n, choices );
@@ -1049,7 +1054,7 @@ wxComboBox *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
 
     wxComboBox *choice = new wxComboBox( this,
                                          wxPRINTID_PAPERSIZE,
-                                         _("Paper Size"),
+                                         _("Paper size"),
                                          wxPoint(*x, *y),
                                          wxSize(300, wxDefaultCoord),
                                          n, choices );
@@ -1095,4 +1100,3 @@ void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
 }
 
 #endif
-