# HG changeset patch # User John W. Eaton # Date 1232592504 18000 # Node ID 66165de2cc4285857c07812f481b3d6d1c2dbea3 # Parent 5cc594679cdce4482a97baecf6168b4a64599780 add new files for previous changeset diff -r 5cc594679cdc -r 66165de2cc42 src/display.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/display.cc Wed Jan 21 21:48:24 2009 -0500 @@ -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 +. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#if defined (HAVE_X_WINDOWS) +#include +#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: *** +*/ diff -r 5cc594679cdc -r 66165de2cc42 src/display.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/display.h Wed Jan 21 21:48:24 2009 -0500 @@ -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 +. + +*/ + +#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: *** +*/