changeset 8561:66165de2cc42

add new files for previous changeset
author John W. Eaton <jwe@octave.org>
date Wed, 21 Jan 2009 21:48:24 -0500
parents 5cc594679cdc
children a6edd5c23cb5
files src/display.cc src/display.h
diffstat 2 files changed, 209 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/src/display.cc
@@ -0,0 +1,113 @@
+/*
+
+Copyright (C) 2009 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 <cstdlib>
+
+#if defined (HAVE_X_WINDOWS)
+#include <X11/Xlib.h>
+#endif
+
+#include "display.h"
+#include "error.h"
+
+display_info *display_info::instance = 0;
+
+void
+display_info::init (void)
+{
+#if defined (OCTAVE_USE_WINDOWS_API)
+
+  warning ("code to find screen properties is missing");
+
+#elif defined (OCTAVE_USE_COCOA_API)  // FIXME -- what should this be called?
+
+  warning ("code to find screen properties is missing");
+
+#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
+	    warning ("X11 display has no default screen");
+	}
+      else
+	warning ("unable to open X11 DISPLAY");
+    }
+  else
+    warning ("X11 DISPLAY environment variable not set");
+#else
+
+  warning ("no graphical display found");
+
+#endif
+}
+
+bool
+display_info::instance_ok (void)
+{
+  bool retval = true;
+
+  if (! instance)
+    instance = new display_info ();
+
+  if (! instance)
+    {
+      ::error ("unable to create display_info object!");
+
+      retval = false;
+    }
+
+  return retval;
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/
new file mode 100644
--- /dev/null
+++ b/src/display.h
@@ -0,0 +1,96 @@
+/*
+
+Copyright (C) 2009 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_display_h)
+#define octave_display_h 1
+
+class Matrix;
+
+class display_info
+{
+protected:
+
+  display_info (void)
+    : ht (1), wd (1), dp (0), rx (72), ry (72)
+  {
+    init ();
+  }
+
+public:
+
+  static int height (void)
+  {
+    return instance_ok () ? instance->do_height () : 0;
+  }
+
+  static int width (void)
+  {
+    return instance_ok () ? instance->do_width () : 0;
+  }
+
+  static int depth (void)
+  {
+    return instance_ok () ? instance->do_depth () : 0;
+  }
+
+  static double x_dpi (void)
+  {
+    return instance_ok () ? instance->do_x_dpi () : 0;
+  }
+
+  static double y_dpi (void)
+  {
+    return instance_ok () ? instance->do_y_dpi () : 0;
+  }
+
+private:
+
+  static display_info *instance;
+
+  // Height, width, and depth of the display.
+  int ht;
+  int wd;
+  int dp;
+
+  // X- and Y- Resolution of the display in dots (pixels) per inch.
+  double rx;
+  double ry;
+
+  int do_height (void) const { return ht; }
+  int do_width (void) const { return wd; }
+  int do_depth (void) const { return dp; }
+
+  double do_x_dpi (void) const { return rx; }
+  double do_y_dpi (void) const { return ry; }
+
+  void init (void);
+
+  static bool instance_ok (void);
+};
+
+#endif
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/