2007-12-30 16:41:49 +00:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gdesktop.cpp
|
|
|
|
|
|
|
|
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
|
2009-08-17 10:41:51 +00:00
|
|
|
|
2007-12-30 16:41:49 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 10:41:51 +00:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 16:41:49 +00:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
2011-06-03 00:51:09 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
2011-12-31 02:39:20 +00:00
|
|
|
MA 02110-1301, USA.
|
2007-12-30 16:41:49 +00:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "widgets.h"
|
|
|
|
#include "widgets_private.h"
|
2008-06-26 09:49:06 +00:00
|
|
|
#include "gb.form.font.h"
|
2007-12-30 16:41:49 +00:00
|
|
|
|
|
|
|
#ifndef GAMBAS_DIRECTFB
|
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
2011-01-17 16:07:50 +00:00
|
|
|
#include "x11.h"
|
2007-12-30 16:41:49 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gapplication.h"
|
|
|
|
#include "gmainwindow.h"
|
|
|
|
#include "gdesktop.h"
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
|
|
|
Desktop
|
|
|
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
gFont *gDesktop::_desktop_font = NULL;
|
|
|
|
int gDesktop::_desktop_scale = 0;
|
|
|
|
|
|
|
|
bool gDesktop::rightToLeft()
|
|
|
|
{
|
|
|
|
return gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gDesktop::init()
|
|
|
|
{
|
|
|
|
_desktop_font = new gFont();
|
|
|
|
_desktop_scale = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gDesktop::exit()
|
|
|
|
{
|
|
|
|
gFont::assign(&_desktop_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
gFont* gDesktop::font()
|
|
|
|
{
|
|
|
|
if (!_desktop_font) gDesktop::init();
|
|
|
|
return _desktop_font;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gDesktop::setFont(gFont *ft)
|
|
|
|
{
|
2008-03-17 15:04:36 +00:00
|
|
|
gFont::set(&_desktop_font, ft->copy());
|
2007-12-30 16:41:49 +00:00
|
|
|
_desktop_scale = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*gControl* gDesktop::activeControl()
|
|
|
|
{
|
|
|
|
gControl *test, *curr=NULL;
|
|
|
|
GList *iter=gControl::controlList();
|
|
|
|
|
|
|
|
if (!iter) return NULL;
|
|
|
|
|
|
|
|
iter=g_list_first(iter);
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
test=(gControl*)iter->data;
|
|
|
|
if (test->hasFocus())
|
|
|
|
{
|
|
|
|
curr=test;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter=iter->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return curr;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
gMainWindow* gDesktop::activeWindow()
|
|
|
|
{
|
|
|
|
return gMainWindow::_active ? gMainWindow::_active->topLevel() : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::buttonfgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkButton", GTK_TYPE_BUTTON);
|
|
|
|
|
|
|
|
if (!st) return 0;
|
|
|
|
return get_gdk_color(&st->fg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::buttonbgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkButton", GTK_TYPE_BUTTON);
|
|
|
|
|
|
|
|
if (!st) return 0xC0C0C0;
|
|
|
|
return get_gdk_color(&st->bg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::fgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkEntry", GTK_TYPE_ENTRY);
|
|
|
|
|
|
|
|
if (!st) return 0;
|
|
|
|
return get_gdk_color(&st->fg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::bgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkLayout", GTK_TYPE_LAYOUT);
|
|
|
|
|
|
|
|
if (!st) return 0xC0C0C0;
|
|
|
|
return get_gdk_color(&st->bg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::textfgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkEntry", GTK_TYPE_ENTRY);
|
|
|
|
|
|
|
|
if (!st) return 0;
|
|
|
|
return get_gdk_color(&st->text[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::textbgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkEntry", GTK_TYPE_ENTRY);
|
|
|
|
|
|
|
|
if (!st) return 0xFFFFFF;
|
|
|
|
return get_gdk_color(&st->base[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::selfgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkEntry", GTK_TYPE_ENTRY);
|
|
|
|
|
|
|
|
if (!st) return 0XFFFFFF;
|
|
|
|
return get_gdk_color(&st->text[GTK_STATE_SELECTED]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::selbgColor()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_style("GtkEntry", GTK_TYPE_ENTRY);
|
|
|
|
|
|
|
|
if (!st) return 0x0000FF;
|
|
|
|
return get_gdk_color(&st->base[GTK_STATE_SELECTED]);
|
|
|
|
}
|
|
|
|
|
2011-10-09 20:27:10 +00:00
|
|
|
gColor gDesktop::tooltipForeground()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_widget_style("gtk-tooltip");
|
|
|
|
|
|
|
|
if (!st) return fgColor();
|
|
|
|
return get_gdk_color(&st->fg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::tooltipBackground()
|
|
|
|
{
|
|
|
|
GtkStyle *st = gt_get_widget_style("gtk-tooltip");
|
|
|
|
|
|
|
|
if (!st) return bgColor();
|
|
|
|
return get_gdk_color(&st->bg[GTK_STATE_NORMAL]);
|
|
|
|
}
|
|
|
|
|
2010-08-25 22:14:27 +00:00
|
|
|
gColor gDesktop::lightbgColor()
|
|
|
|
{
|
2010-09-15 01:49:26 +00:00
|
|
|
uint col = IMAGE.MergeColor(gDesktop::selbgColor(), gDesktop::selfgColor(), 0.2);
|
|
|
|
return col;
|
2010-08-25 22:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gColor gDesktop::lightfgColor()
|
|
|
|
{
|
2010-09-15 01:49:26 +00:00
|
|
|
uint col = IMAGE.MergeColor(gDesktop::bgColor(), gDesktop::fgColor(), 0.2);
|
2010-08-25 22:14:27 +00:00
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2007-12-30 16:41:49 +00:00
|
|
|
int gDesktop::height()
|
|
|
|
{
|
|
|
|
return gdk_screen_get_height(gdk_screen_get_default ());
|
|
|
|
}
|
|
|
|
|
|
|
|
int gDesktop::width()
|
|
|
|
{
|
|
|
|
return gdk_screen_get_width(gdk_screen_get_default ());
|
|
|
|
}
|
|
|
|
|
|
|
|
int gDesktop::resolution()
|
|
|
|
{
|
2009-01-03 22:24:02 +00:00
|
|
|
/*int d_pix=gdk_screen_get_height(gdk_screen_get_default());
|
|
|
|
int d_mm=gdk_screen_get_height_mm(gdk_screen_get_default());
|
2007-12-30 16:41:49 +00:00
|
|
|
|
2009-01-03 22:24:02 +00:00
|
|
|
return (int)(d_pix*25.4)/d_mm;*/
|
|
|
|
return gdk_screen_get_resolution(gdk_screen_get_default());
|
2007-12-30 16:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int gDesktop::scale()
|
|
|
|
{
|
2009-07-22 18:20:25 +00:00
|
|
|
if (!_desktop_scale)
|
|
|
|
{
|
|
|
|
gFont *ft = font();
|
|
|
|
_desktop_scale = GET_DESKTOP_SCALE(ft->size(), resolution());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PangoLanguage *lng=NULL;
|
2007-12-30 16:41:49 +00:00
|
|
|
PangoContext* ct=gdk_pango_context_get();
|
|
|
|
GtkStyle *sty=gtk_widget_get_default_style();
|
|
|
|
PangoFontDescription *ft=sty->font_desc;
|
|
|
|
PangoFontMetrics* fm;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
if (!_desktop_scale)
|
|
|
|
{
|
|
|
|
if (getenv("LANG"))
|
|
|
|
lng = pango_language_from_string(getenv("LANG"));
|
|
|
|
|
|
|
|
fm = pango_context_get_metrics (ct,ft,lng);
|
|
|
|
|
2008-06-26 09:49:06 +00:00
|
|
|
val = 1 + (pango_font_metrics_get_ascent(fm) + pango_font_metrics_get_descent(fm)) / PANGO_SCALE;
|
|
|
|
val = GET_DESKTOP_SCALE(val);
|
2007-12-30 16:41:49 +00:00
|
|
|
pango_font_metrics_unref(fm);
|
|
|
|
g_object_unref(G_OBJECT(ct));
|
|
|
|
|
|
|
|
if (!val) val = 1;
|
|
|
|
_desktop_scale = val;
|
2009-07-22 18:20:25 +00:00
|
|
|
}*/
|
2007-12-30 16:41:49 +00:00
|
|
|
|
|
|
|
return _desktop_scale;
|
|
|
|
}
|
|
|
|
|
2009-09-06 15:57:54 +00:00
|
|
|
gPicture* gDesktop::screenshot(int x, int y, int w, int h)
|
2007-12-30 16:41:49 +00:00
|
|
|
{
|
2009-09-06 15:57:54 +00:00
|
|
|
return gt_grab_window(gdk_get_default_root_window(), x, y, w, h);
|
2007-12-30 16:41:49 +00:00
|
|
|
}
|
|
|
|
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 01:52:40 +00:00
|
|
|
int gDesktop::count()
|
|
|
|
{
|
2012-06-05 07:26:14 +00:00
|
|
|
//return gdk_screen_get_n_monitors(gdk_screen_get_default());
|
|
|
|
return gdk_display_get_n_screens(gdk_display_get_default());
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 01:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gDesktop::geometry(int screen, GdkRectangle *rect)
|
|
|
|
{
|
2012-06-05 07:26:14 +00:00
|
|
|
rect->x = rect->y = rect->width = rect->height = 0;
|
|
|
|
if (screen < 0 || screen >= count())
|
|
|
|
return;
|
|
|
|
|
|
|
|
rect->width = gdk_screen_get_width(gdk_display_get_screen(gdk_display_get_default(), screen));
|
|
|
|
rect->height = gdk_screen_get_height(gdk_display_get_screen(gdk_display_get_default(), screen));
|
|
|
|
//gdk_screen_get_monitor_geometry(gdk_screen_get_default(), screen, rect);
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 01:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gDesktop::availableGeometry(int screen, GdkRectangle *rect)
|
|
|
|
{
|
2012-06-05 07:26:14 +00:00
|
|
|
rect->x = rect->y = rect->width = rect->height = 0;
|
|
|
|
if (screen < 0 || screen >= count())
|
|
|
|
return;
|
|
|
|
|
2011-01-17 16:07:50 +00:00
|
|
|
if (X11_get_available_geometry(screen, &rect->x, &rect->y, &rect->width, &rect->height))
|
|
|
|
geometry(screen, rect);
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 01:52:40 +00:00
|
|
|
}
|
2007-12-30 16:41:49 +00:00
|
|
|
|