changeset 20924:e74e617060cf

Merged C-code of cdisplay.* to C++ display.cc. * libinterp/corefcn/display.cc: merged code from cdisplay.{c/h}. * libinterp/corefcn/display.h: merged code from cdisplay.{c/h}. * libinterp/corefcn/cdisplay.c: removed merged code. * libinterp/corefcn/cdisplay.h: removed no longer needed header. * libinterp/corefcn/module.mk: removed cdisplay.{c/h} from build system.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Thu, 17 Dec 2015 16:14:24 +0100
parents 58263bea2fdf
children 667861ffffab
files libinterp/corefcn/cdisplay.c libinterp/corefcn/cdisplay.h libinterp/corefcn/display.cc libinterp/corefcn/display.h libinterp/corefcn/module.mk
diffstat 5 files changed, 131 insertions(+), 221 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/cdisplay.c	Thu Dec 17 16:04:13 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
-
-Copyright (C) 2009-2014 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
-option) any later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-
-#if defined (OCTAVE_USE_WINDOWS_API)
-#include <windows.h>
-#elif defined (HAVE_FRAMEWORK_CARBON)
-#include <Carbon/Carbon.h>
-#elif defined (HAVE_X_WINDOWS)
-#include <X11/Xlib.h>
-#endif
-
-#include "cdisplay.h"
-
-const char *
-octave_get_display_info (int *ht, int *wd, int *dp, double *rx, double *ry,
-                         int *dpy_avail)
-{
-  const char *msg = 0;
-
-  *dpy_avail = 0;
-
-#if defined (OCTAVE_USE_WINDOWS_API)
-
-  HDC hdc = GetDC (0);
-
-  if (hdc)
-    {
-      *dp = GetDeviceCaps (hdc, BITSPIXEL);
-
-      *ht = GetDeviceCaps (hdc, VERTRES);
-      *wd = GetDeviceCaps (hdc, HORZRES);
-
-      double ht_mm = GetDeviceCaps (hdc, VERTSIZE);
-      double wd_mm = GetDeviceCaps (hdc, HORZSIZE);
-
-      *rx = *wd * 25.4 / wd_mm;
-      *ry = *ht * 25.4 / ht_mm;
-
-      *dpy_avail = 1;
-    }
-  else
-    msg = "no graphical display found";
-
-#elif defined (HAVE_FRAMEWORK_CARBON)
-
-  CGDirectDisplayID display = CGMainDisplayID ();
-
-  if (display)
-    {
-#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)
-
-      *dp = CGDisplayBitsPerPixel (display);
-
-#else
-
-      /* FIXME: This will only work for MacOS > 10.5. For earlier versions
-         this code is not needed (use CGDisplayBitsPerPixel instead).  */
-
-      CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
-      CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);
-
-      if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0)
-        *dp = 32;
-      else if (CFStringCompare (pixelEncoding,
-                                CFSTR (IO16BitDirectPixels), 0) == 0)
-        *dp = 16;
-      else
-        *dp = 8;
-
-#endif
-
-      *ht = CGDisplayPixelsHigh (display);
-      *wd = CGDisplayPixelsWide (display);
-
-      CGSize sz_mm = CGDisplayScreenSize (display);
-
-      /* For MacOS >= 10.6, CGSize is a struct keeping 2 CGFloat
-         values, but the CGFloat typedef is not present on older
-         systems, so use double instead.  */
-
-      double ht_mm = sz_mm.height;
-      double wd_mm = sz_mm.width;
-
-      *rx = *wd * 25.4 / wd_mm;
-      *ry = *ht * 25.4 / ht_mm;
-
-      *dpy_avail = 1;
-    }
-  else
-    msg = "no graphical display found";
-
-#elif defined (HAVE_X_WINDOWS)
-
-  const char *display_name = getenv ("DISPLAY");
-
-  if (display_name && *display_name)
-    {
-      Display *display = XOpenDisplay (display_name);
-
-      if (display)
-        {
-          Screen *screen = DefaultScreenOfDisplay (display);
-
-          if (screen)
-            {
-              *dp = DefaultDepthOfScreen (screen);
-
-              *ht = HeightOfScreen (screen);
-              *wd = WidthOfScreen (screen);
-
-              int screen_number = XScreenNumberOfScreen (screen);
-
-              double ht_mm = DisplayHeightMM (display, screen_number);
-              double wd_mm = DisplayWidthMM (display, screen_number);
-
-              *rx = *wd * 25.4 / wd_mm;
-              *ry = *ht * 25.4 / ht_mm;
-            }
-          else
-            msg = "X11 display has no default screen";
-
-          XCloseDisplay (display);
-
-          *dpy_avail = 1;
-        }
-      else
-        msg = "unable to open X11 DISPLAY";
-    }
-  else
-    msg = "X11 DISPLAY environment variable not set";
-
-#else
-
-  msg = "no graphical display found";
-
-#endif
-
-  return msg;
-}
--- a/libinterp/corefcn/cdisplay.h	Thu Dec 17 16:04:13 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
-
-Copyright (C) 2014-2015 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software; you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
-option) any later version.
-
-Octave is distributed in the hope that it will be useful, but WITHOUT
-ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_cdisplay_h)
-#define octave_cdisplay_h 1
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-OCTINTERP_API extern const char *
-octave_get_display_info (int *ht, int *wd, int *dp, double *rx, double *ry,
-                         int *dpy_avail);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
--- a/libinterp/corefcn/display.cc	Thu Dec 17 16:04:13 2015 +0100
+++ b/libinterp/corefcn/display.cc	Thu Dec 17 16:14:24 2015 +0100
@@ -20,33 +20,140 @@
 
 */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "display.h"
 
-#include "singleton-cleanup.h"
-
-#include "cdisplay.h"
-#include "display.h"
-#include "error.h"
+#if defined (OCTAVE_USE_WINDOWS_API)
+#include <windows.h>
+#elif defined (HAVE_FRAMEWORK_CARBON)
+#include <Carbon/Carbon.h>
+#elif defined (HAVE_X_WINDOWS)
+#include <X11/Xlib.h>
+#endif
 
 display_info *display_info::instance = 0;
 
 void
 display_info::init (bool query)
 {
-  if (query)
+  if (!query)
+    return;
+
+#if defined (OCTAVE_USE_WINDOWS_API)
+
+  HDC hdc = GetDC (0);
+
+  if (hdc)
     {
-      int avail = 0;
+      dp = GetDeviceCaps (hdc, BITSPIXEL);
+
+      ht = GetDeviceCaps (hdc, VERTRES);
+      wd = GetDeviceCaps (hdc, HORZRES);
+
+      double ht_mm = GetDeviceCaps (hdc, VERTSIZE);
+      double wd_mm = GetDeviceCaps (hdc, HORZSIZE);
+
+      rx = wd * 25.4 / wd_mm;
+      ry = ht * 25.4 / ht_mm;
+
+      dpy_avail = true;
+    }
+  else
+    err_msg = "no graphical display found";
+
+#elif defined (HAVE_FRAMEWORK_CARBON)
+
+  CGDirectDisplayID display = CGMainDisplayID ();
+
+  if (display)
+    {
+#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)
+
+      dp = CGDisplayBitsPerPixel (display);
+
+#else
+
+     /* FIXME: This will only work for MacOS > 10.5. For earlier versions
+        this code is not needed (use CGDisplayBitsPerPixel instead).  */
+
+      CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
+      CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);
+
+      if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0)
+        dp = 32;
+      else if (CFStringCompare (pixelEncoding,
+                                CFSTR (IO16BitDirectPixels), 0) == 0)
+        dp = 16;
+      else
+        dp = 8;
+
+#endif
+
+      ht = CGDisplayPixelsHigh (display);
+      wd = CGDisplayPixelsWide (display);
+
+      CGSize sz_mm = CGDisplayScreenSize (display);
 
-      const char *msg = octave_get_display_info (&ht, &wd, &dp, &rx, &ry,
-                                                 &avail);
+      /* For MacOS >= 10.6, CGSize is a struct keeping 2 CGFloat
+         values, but the CGFloat typedef is not present on older
+         systems, so use double instead.  */
+
+      double ht_mm = sz_mm.height;
+      double wd_mm = sz_mm.width;
+
+      rx = wd * 25.4 / wd_mm;
+      ry = ht * 25.4 / ht_mm;
+
+      dpy_avail = true;
+    }
+  else
+    err_msg = "no graphical display found";
+
+#elif defined (HAVE_X_WINDOWS)
+
+  const char *display_name = std::getenv ("DISPLAY");
+
+  if (display_name && *display_name)
+    {
+      Display *display = XOpenDisplay (display_name);
+
+      if (display)
+        {
+          Screen *screen = DefaultScreenOfDisplay (display);
+
+          if (screen)
+            {
+              dp = DefaultDepthOfScreen (screen);
 
-      dpy_avail = avail;
+              ht = HeightOfScreen (screen);
+              wd = WidthOfScreen (screen);
+
+              int screen_number = XScreenNumberOfScreen (screen);
+
+              double ht_mm = DisplayHeightMM (display, screen_number);
+              double wd_mm = DisplayWidthMM (display, screen_number);
+
+              rx = wd * 25.4 / wd_mm;
+              ry = ht * 25.4 / ht_mm;
+            }
+          else
+            err_msg = "X11 display has no default screen";
 
-      if (msg)
-        err_msg = msg;
+          XCloseDisplay (display);
+
+          dpy_avail = true;
+        }
+      else
+        err_msg = "unable to open X11 DISPLAY";
     }
+  else
+    err_msg = "X11 DISPLAY environment variable not set";
+
+#else
+
+  err_msg = "no graphical display found";
+
+#endif
+
 }
 
 bool
--- a/libinterp/corefcn/display.h	Thu Dec 17 16:04:13 2015 +0100
+++ b/libinterp/corefcn/display.h	Thu Dec 17 16:14:24 2015 +0100
@@ -23,9 +23,16 @@
 #if ! defined (octave_display_h)
 #define octave_display_h 1
 
-#include <string>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-class Matrix;
+#include <string>
+#include <cstdlib>
+
+#include "singleton-cleanup.h"
+
+#include "error.h"
 
 class
 OCTINTERP_API
--- a/libinterp/corefcn/module.mk	Thu Dec 17 16:04:13 2015 +0100
+++ b/libinterp/corefcn/module.mk	Thu Dec 17 16:14:24 2015 +0100
@@ -26,7 +26,6 @@
 COREFCN_INC = \
   libinterp/corefcn/Cell.h \
   libinterp/corefcn/c-file-ptr-stream.h \
-  libinterp/corefcn/cdisplay.h \
   libinterp/corefcn/comment-list.h \
   libinterp/corefcn/data.h \
   libinterp/corefcn/debug.h \
@@ -127,7 +126,6 @@
   libinterp/corefcn/bitfcns.cc \
   libinterp/corefcn/bsxfun.cc \
   libinterp/corefcn/c-file-ptr-stream.cc \
-  libinterp/corefcn/cdisplay.c \
   libinterp/corefcn/cellfun.cc \
   libinterp/corefcn/colloc.cc \
   libinterp/corefcn/comment-list.cc \