From 904a68b6f648fc7802b41a8d176c78394252a4b7 Mon Sep 17 00:00:00 2001
From: Ron Lee <ron@debian.org>
Date: Mon, 25 Sep 2000 08:51:35 +0000
Subject: [PATCH] implemented wxDisplaySizeMM for gtk, msw & motif. used
 wxDisplaySize and wxDisplaySizeMM to calculate real screen PPI in
 wxPostScriptPrinter. documented wxDisplaySize and wxDisplaySizeMM.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8414 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex | 16 ++++++++++++++++
 include/wx/gdicmn.h        |  4 +++-
 src/common/gdicmn.cpp      |  7 +++++++
 src/generic/printps.cpp    | 31 +++++++++++--------------------
 src/gtk/utilsgtk.cpp       |  6 ++++++
 src/gtk1/utilsgtk.cpp      |  6 ++++++
 src/motif/utils.cpp        | 10 ++++++++++
 src/msw/utils.cpp          |  9 +++++++++
 8 files changed, 68 insertions(+), 21 deletions(-)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 5975b0250d..c48237402e 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -849,6 +849,22 @@ Returns TRUE if the display is colour, FALSE otherwise.
 
 Returns the depth of the display (a value of 1 denotes a monochrome display).
 
+\membersection{::wxDisplaySize}
+
+\func{void}{wxDisplaySize}{\param{int *}{width}, \param{int *}{height}}
+
+\func{wxSize}{wxGetDisplaySize}{\void}
+
+Returns the display size in pixels.
+
+\membersection{::wxDisplaySizeMM}
+
+\func{void}{wxDisplaySizeMM}{\param{int *}{width}, \param{int *}{height}}
+
+\func{wxSize}{wxGetDisplaySizeMM}{\void}
+
+Returns the display size in millimeters.
+
 \membersection{::wxMakeMetafilePlaceable}\label{wxmakemetafileplaceable}
 
 \func{bool}{wxMakeMetafilePlaceable}{\param{const wxString\& }{filename}, \param{int }{minX}, \param{int }{minY},
diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h
index b06e329c45..0633285338 100644
--- a/include/wx/gdicmn.h
+++ b/include/wx/gdicmn.h
@@ -496,9 +496,11 @@ extern bool WXDLLEXPORT wxColourDisplay();
 extern int WXDLLEXPORT wxDisplayDepth();
 #define wxGetDisplayDepth wxDisplayDepth
 
-// get the diaplay size
+// get the display size
 extern void WXDLLEXPORT wxDisplaySize(int *width, int *height);
 extern wxSize WXDLLEXPORT wxGetDisplaySize();
+extern void WXDLLEXPORT wxDisplaySizeMM(int *width, int *height);
+extern wxSize WXDLLEXPORT wxGetDisplaySizeMM();
 
 // set global cursor
 extern void WXDLLEXPORT wxSetCursor(const wxCursor& cursor);
diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp
index e7dc5831e0..cdce7ecaba 100644
--- a/src/common/gdicmn.cpp
+++ b/src/common/gdicmn.cpp
@@ -691,6 +691,13 @@ wxSize wxGetDisplaySize()
     return wxSize(x, y);
 }
 
+wxSize wxGetDisplaySizeMM()
+{
+    int x, y;
+    wxDisplaySizeMM(& x, & y);
+    return wxSize(x, y);
+}
+
 wxResourceCache::~wxResourceCache ()
 {
     wxNode *node = First ();
diff --git a/src/generic/printps.cpp b/src/generic/printps.cpp
index 9a97d9cc6e..adf67bf80f 100644
--- a/src/generic/printps.cpp
+++ b/src/generic/printps.cpp
@@ -148,25 +148,13 @@ bool wxPostScriptPrinter::Print(wxWindow *parent, wxPrintout *printout, bool pro
         return FALSE;
     }
 
-    int logPPIScreenX = 0;
-    int logPPIScreenY = 0;
-    int logPPIPrinterX = 0;
-    int logPPIPrinterY = 0;
+    wxSize ScreenPixels = wxGetDisplaySize();
+    wxSize ScreenMM = wxGetDisplaySizeMM();
 
-    logPPIScreenX = 100;
-    logPPIScreenY = 100;
-
-    /*
-    // Correct values for X/PostScript?
-    logPPIPrinterX = 100;
-    logPPIPrinterY = 100;
-    */
-
-    logPPIPrinterX = wxPostScriptDC::GetResolution();
-    logPPIPrinterY = wxPostScriptDC::GetResolution();
-
-    printout->SetPPIScreen(logPPIScreenX, logPPIScreenY);
-    printout->SetPPIPrinter(logPPIPrinterX, logPPIPrinterY);
+    printout->SetPPIScreen( (ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth(),
+                            (ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight() );
+    printout->SetPPIPrinter( wxPostScriptDC::GetResolution(),
+                             wxPostScriptDC::GetResolution() );
 
     // Set printout parameters
     printout->SetDC(dc);
@@ -348,8 +336,11 @@ void wxPostScriptPrintPreview::DetermineScaling()
 
     if (paper)
     {
-        m_previewPrintout->SetPPIScreen(100, 100);
-        //      m_previewPrintout->SetPPIPrinter(100, 100);
+        wxSize ScreenPixels = wxGetDisplaySize();
+        wxSize ScreenMM = wxGetDisplaySizeMM();
+
+        m_previewPrintout->SetPPIScreen( (ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth(),
+                                         (ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight() );
         m_previewPrintout->SetPPIPrinter(wxPostScriptDC::GetResolution(), wxPostScriptDC::GetResolution()); 
 
         wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp
index 1f985793be..6d27531b26 100644
--- a/src/gtk/utilsgtk.cpp
+++ b/src/gtk/utilsgtk.cpp
@@ -88,6 +88,12 @@ void wxDisplaySize( int *width, int *height )
     if (height) *height = gdk_screen_height();
 }
 
+void wxDisplaySizeMM( int *width, int *height )
+{
+    if (width) *width = gdk_screen_width_mm();
+    if (height) *height = gdk_screen_height_mm();
+}
+
 void wxGetMousePosition( int* x, int* y )
 {
     gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp
index 1f985793be..6d27531b26 100644
--- a/src/gtk1/utilsgtk.cpp
+++ b/src/gtk1/utilsgtk.cpp
@@ -88,6 +88,12 @@ void wxDisplaySize( int *width, int *height )
     if (height) *height = gdk_screen_height();
 }
 
+void wxDisplaySizeMM( int *width, int *height )
+{
+    if (width) *width = gdk_screen_width_mm();
+    if (height) *height = gdk_screen_height_mm();
+}
+
 void wxGetMousePosition( int* x, int* y )
 {
     gdk_window_get_pointer( (GdkWindow*) NULL, x, y, (GdkModifierType*) NULL );
diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp
index 0dab1add9b..bbd87c8772 100644
--- a/src/motif/utils.cpp
+++ b/src/motif/utils.cpp
@@ -648,6 +648,16 @@ void wxDisplaySize(int *width, int *height)
         *height = DisplayHeight (dpy, DefaultScreen (dpy));
 }
 
+void wxDisplaySizeMM(int *width, int *height)
+{
+    Display *dpy = (Display*) wxGetDisplay();
+
+    if ( width )
+        *width = DisplayWidthMM(dpy, DefaultScreen (dpy));
+    if ( height )
+        *height = DisplayHeightMM(dpy, DefaultScreen (dpy));
+}
+
 // Configurable display in Motif
 static WXDisplay *gs_currentDisplay = NULL;
 static wxString gs_displayName;
diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp
index 3f4b7e649c..e191b5aacd 100644
--- a/src/msw/utils.cpp
+++ b/src/msw/utils.cpp
@@ -986,6 +986,15 @@ void wxDisplaySize(int *width, int *height)
     if ( height ) *height = GetDeviceCaps(dc, VERTRES);
 }
 
+void wxDisplaySizeMM(int *width, int *height)
+{
+    ScreenHDC dc;
+
+    if ( width ) *width = GetDeviceCaps(dc, HORZSIZE);
+    if ( height ) *height = GetDeviceCaps(dc, VERTSIZE);
+}
+
+
 // ---------------------------------------------------------------------------
 // window information functions
 // ---------------------------------------------------------------------------
-- 
2.50.0

