]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/prntdlgg.cpp
Read was not copying back the buffers contents into the string parameter
[wxWidgets.git] / src / generic / prntdlgg.cpp
index d68b9d4d11ce3a12a1bd9598f641696161e30715..b1ff434de5cb718bd0b0cd53b92cc625b2f2af8f 100644 (file)
 
 #include "wx/defs.h"
 
-#define WINDOWS_PRINTING    (wxTheApp->GetPrintMode() == wxPRINT_WINDOWS)
-
 #ifndef WX_PRECOMP
 #include "wx/utils.h"
 #include "wx/dc.h"
 #include "wx/app.h"
 #include "wx/frame.h"
 #include "wx/stattext.h"
+#include "wx/statbox.h"
 #include "wx/button.h"
 #include "wx/checkbox.h"
 #include "wx/textctrl.h"
 #endif
 
 #include "wx/generic/prntdlgg.h"
+
+#if wxUSE_POSTSCRIPT
+#include "wx/generic/dcpsg.h"
+#endif
+
 #include "wx/printdlg.h"
 
+// For print paper things
+#include "wx/prntbase.h"
+
 #include <stdlib.h>
 #include <string.h>
 
+#if wxUSE_POSTSCRIPT
+
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_CLASS(wxGenericPrintDialog, wxDialog)
 IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
@@ -69,27 +78,17 @@ extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
 
 
 wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data):
-  wxDialog(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
+  wxDialog(parent, -1, _("Print"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
 {
   if ( data )
     printData = *data;
   
-  int buttonWidth = 65;
-  int buttonHeight = 25;
-  int spacing = 5;
-  int yPos = 5;
-  int xPos = 5;
-
-  wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(5, yPos), wxSize(buttonWidth, buttonHeight));
-  (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(buttonWidth + 5 + spacing, yPos), wxSize(buttonWidth, buttonHeight));
-
-  setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(buttonWidth*2 + 5 + 2*spacing, yPos), wxSize(buttonWidth, buttonHeight));
-
-  okButton->SetDefault();
-  okButton->SetFocus();
-
-  yPos += 35;
+  (void)new wxStaticBox( this, -1, _( "Printer options" ), wxPoint( 5, 5), wxSize( 300, 60 ) );
 
+  printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(20, 25) );
+  
+  setupButton = new wxButton(this, wxPRINTID_SETUP, _("Setup..."), wxPoint(160, 25), wxSize(100, -1));
+  
   wxString *choices = new wxString[2];
   choices[0] = _("All");
   choices[1] = _("Pages");
@@ -99,41 +98,30 @@ wxGenericPrintDialog::wxGenericPrintDialog(wxWindow *parent, wxPrintData* data):
   if(printData.GetFromPage() != 0)
   {
      rangeRadioBox = new wxRadioBox(this, wxPRINTID_RANGE, _("Print Range"),
-                                    wxPoint(5, yPos), wxSize(-1, -1), 2, choices, 2);
+                                    wxPoint(5, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL);
      rangeRadioBox->SetSelection(1);
   }
   
-  yPos += 60;
-  xPos = 5;
-  int staticWidth = 45;
-  int textWidth = 40;
-  spacing = 10;
-
   if(printData.GetFromPage() != 0)
   {
-     (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(xPos, yPos));
-     xPos += staticWidth;
+     (void) new wxStaticText(this, wxPRINTID_STATIC, _("From:"), wxPoint(5, 135));
 
-     fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
-     xPos += spacing + textWidth;
+     fromText = new wxTextCtrl(this, wxPRINTID_FROM, "", wxPoint(45, 130), wxSize(40, -1));
      
-     (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(xPos, yPos));
-     xPos += staticWidth;
+     (void) new wxStaticText(this, wxPRINTID_STATIC, _("To:"), wxPoint(100, 135));
      
-     toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
-     xPos += spacing + textWidth;
+     toText = new wxTextCtrl(this, wxPRINTID_TO, "", wxPoint(133, 130), wxSize(40, -1));
   }
   
-  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(xPos, yPos));
-  xPos += spacing + staticWidth;
+  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Copies:"), wxPoint(200, 135));
 
-  noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
+  noCopiesText = new wxTextCtrl(this, wxPRINTID_COPIES, "", wxPoint(252, 130), wxSize(40, -1));
 
-  yPos += 30;
-  xPos = 5;
-
-  printToFileCheckBox = new wxCheckBox(this, wxPRINTID_PRINTTOFILE, _("Print to File"), wxPoint(xPos, yPos));
+  wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(40, 180), wxSize(100, -1));
+  (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(180, 180), wxSize(100, -1));
 
+  okButton->SetDefault();
+  okButton->SetFocus();
   Fit();
   Centre(wxBOTH);
 
@@ -178,14 +166,14 @@ void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
   {
     wxThePrintSetupData->SetPrinterMode(PS_FILE);
 
-    char *f = wxFileSelector(_("PostScript file"),
-        wxPathOnly(wxThePrintSetupData->GetPrinterFile()),
-        wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()),
-        "ps", "*.ps", 0, this);
-    if (f)
-      wxThePrintSetupData->SetPrinterFile(f);
-    else
-      return;
+    wxString f = wxFileSelector(_("PostScript file"),
+                                wxPathOnly(wxThePrintSetupData->GetPrinterFile()),
+                                wxFileNameFromPath(wxThePrintSetupData->GetPrinterFile()),
+                                "ps", "*.ps", 0, this);
+    if ( f.IsEmpty() )
+        return;
+
+    wxThePrintSetupData->SetPrinterFile(f);
   }
   else
     wxThePrintSetupData->SetPrinterMode(PS_PRINTER);
@@ -197,12 +185,12 @@ void wxGenericPrintDialog::OnRange(wxCommandEvent& event)
 {
   if (!fromText) return;
 
-  if (event.GetInt() == 1)
+  if (event.GetInt() == 0)
   {
     fromText->Enable(FALSE);
     toText->Enable(FALSE);
   }
-  else if (event.GetInt() == 0)
+  else if (event.GetInt() == 1)
   {
     fromText->Enable(TRUE);
     toText->Enable(TRUE);
@@ -295,27 +283,15 @@ wxDC *wxGenericPrintDialog::GetPrintDC(void)
  */
 
 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSetupData* data):
-  wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL)
+  wxDialog(parent, -1, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
 {
   if ( data )
     printData = *data;
 
-  int buttonWidth = 65;
-  int buttonHeight = 25;
-  int spacing = 5;
-  int yPos = 5;
-  int xPos = 5;
-
-  wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(xPos, yPos), wxSize(buttonWidth, buttonHeight));
-  xPos += buttonWidth + spacing;
-  (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(xPos, yPos), wxSize(buttonWidth, buttonHeight));
-
-  okButton->SetDefault();
-  okButton->SetFocus();
-
-  yPos += 35;
-  xPos = 5;
+  (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(10, 10), wxSize(200,60) );
 
+  int xPos = 20;
+  int yPos = 30;
   paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
 
   wxString *choices =  new wxString[2];
@@ -323,30 +299,35 @@ wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintSe
   choices[1] = _("Landscape");
 
   orientationRadioBox = new wxRadioBox(this, wxPRINTID_ORIENTATION, _("Orientation"),
-    wxPoint(xPos, yPos), wxSize(-1, -1), 2, choices, 2);
+    wxPoint(10, 80), wxSize(-1, -1), 2, choices, 1, wxRA_VERTICAL );
   orientationRadioBox->SetSelection(0);
 
-  xPos += 200;
+  (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Options"), wxPoint(10, 130), wxSize(200,50) );
 
-  colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(xPos, yPos));
+  int colourXPos = 145;
 
-  xPos = 5;
-  yPos += 60;
+#ifdef __WXMOTIF__
+  colourXPos = 150;
+#endif
+  
+  colourCheckBox = new wxCheckBox(this, wxPRINTID_PRINTCOLOUR, _("Print in colour"), wxPoint(15, colourXPos));
+  
 
-  int staticWidth = 100;
-  int textWidth = 120;
-  spacing = 10;
+  (void) new wxStaticBox(this, wxPRINTID_STATIC, _("Print spooling"), wxPoint(230, 10), wxSize(200,170) );
+  
+  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(240, 30));
 
-  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer command:"), wxPoint(xPos, yPos));
-  xPos += staticWidth;
+  printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(260, 55), wxSize(150, -1));
 
-  printerCommandText = new wxTextCtrl(this, wxPRINTID_COMMAND, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
-  xPos += textWidth + spacing;
+  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(240, 110));
 
-  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Printer options:"), wxPoint(xPos, yPos));
-  xPos += staticWidth;
+  printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(260, 135), wxSize(150, -1));
 
-  printerOptionsText = new wxTextCtrl(this, wxPRINTID_OPTIONS, "", wxPoint(xPos, yPos), wxSize(textWidth, -1));
+  wxButton *okButton = new wxButton(this, wxID_OK, _("OK"), wxPoint(80, 200), wxSize(100, -1));
+  (void) new wxButton(this, wxID_CANCEL, _("Cancel"), wxPoint(270, 200), wxSize(100, -1));
+
+  okButton->SetDefault();
+  okButton->SetFocus();
 
   Fit();
   Centre(wxBOTH);
@@ -400,6 +381,7 @@ bool wxGenericPrintSetupDialog::TransferDataFromWindow(void)
     if (!val.IsNull() && val != "")
       printData.SetPaperName((char *)(const char *)val);
   }
+  *wxThePrintSetupData = GetPrintData();
   return TRUE;
 }
 
@@ -422,17 +404,21 @@ wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
       sel = i;
   }
 
-  (void) new wxStaticText(this, wxPRINTID_STATIC, _("Paper size"), wxPoint(*x, *y));
-  *y += 25;
+  int width = 170;
+#ifdef __WXMOTIF__
+  width = 150;
+#endif
 
-  wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(300, -1), n,
+  wxChoice *choice = new wxChoice(this, wxPRINTID_PAPERSIZE, wxPoint(*x, *y), wxSize(width, -1), n,
     choices);
-  *y += 35;
+    
   delete[] choices;
 
   choice->SetSelection(sel);
   return choice;
 }
+#endif
+  // wxUSE_POSTSCRIPT
 
 /*
  * Generic page setup dialog
@@ -440,29 +426,24 @@ wxChoice *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
 
 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
 {
-  if (wxTheApp->GetPrintMode() == wxPRINT_POSTSCRIPT)
-  {
-    wxGenericPrintSetupDialog *genericPrintSetupDialog =
-          new wxGenericPrintSetupDialog(this, wxThePrintSetupData);
-    int ret = genericPrintSetupDialog->ShowModal();
-    if (ret == wxID_OK)
-      *wxThePrintSetupData = genericPrintSetupDialog->GetPrintData();
+    // We no longer query GetPrintMode, so we can eliminate the need
+    // to call SetPrintMode.
+    // This has the limitation that we can't explicitly call the PostScript
+    // print setup dialog from the generic Page Setup dialog under Windows,
+    // but since this choice would only happen when trying to do PostScript
+    // printing under Windows (and only in 16-bit Windows which
+    // doesn't have a Windows-specific page setup dialog) it's worth it.
 
-    genericPrintSetupDialog->Close(TRUE);
-  }
-#ifdef __WXMSW__
-  else
-  {
     wxPrintData data;
     data.SetSetupDialog(TRUE);
-    wxPrintDialog printDialog(this, & data);
-    printDialog.Show(TRUE);
-  }
-#endif
+    wxPrintDialog *printDialog = new wxPrintDialog(this, & data);
+    printDialog->ShowModal();
+
+    printDialog->Destroy();
 }
 
 wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetupData* data):
-  wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE)
+  wxDialog(parent, -1, _("Page Setup"), wxPoint(0, 0), wxSize(600, 600), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
 {
   if ( data )
     pageData = *data;
@@ -470,6 +451,10 @@ wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetup
   int buttonWidth = 75;
   int buttonHeight = 25;
   int spacing = 5;
+#ifdef __WXMOTIF__
+  spacing = 15;
+#endif
+
   int yPos = 5;
   int xPos = 5;
 
@@ -490,6 +475,10 @@ wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetup
   xPos = 5;
   yPos += 35;
 
+#ifdef __WXMOTIF__
+  yPos += 10;
+#endif
+
   paperTypeChoice = CreatePaperTypeChoice(&xPos, &yPos);
 
   xPos = 5;
@@ -505,6 +494,10 @@ wxGenericPageSetupDialog::wxGenericPageSetupDialog(wxWindow *parent, wxPageSetup
   yPos += 60;
 
   int staticWidth = 110;
+#ifdef __WXMOTIF__
+  staticWidth += 20;
+#endif
+
   int textWidth = 60;
   spacing = 10;
 
@@ -578,12 +571,16 @@ bool wxGenericPageSetupDialog::TransferDataFromWindow(void)
     int sel = orientationRadioBox->GetSelection();
     if (sel == 0)
     {
+#if wxUSE_POSTSCRIPT
       wxThePrintSetupData->SetPrinterOrientation(wxPORTRAIT);
+#endif
       pageData.SetOrientation(wxPORTRAIT);
     }
     else
     {
+#if wxUSE_POSTSCRIPT
       wxThePrintSetupData->SetPrinterOrientation(wxLANDSCAPE);
+#endif
       pageData.SetOrientation(wxLANDSCAPE);
     }
   }
@@ -599,6 +596,7 @@ bool wxGenericPageSetupDialog::TransferDataFromWindow(void)
         }
     }
   }
+
   return TRUE;
 }
 
@@ -633,4 +631,3 @@ wxChoice *wxGenericPageSetupDialog::CreatePaperTypeChoice(int *x, int *y)
   return choice;
 }
 
-