292 lines
5.9 KiB
C++
Raw Normal View History

/***************************************************************************
gdesktop.cpp
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
Gtkmae "GTK+ made easy" classes
Realizado para la Junta de Extremadura.
Consejería de Educación Ciencia y Tecnología.
Proyecto gnuLinEx
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
the Free Software Foundation; either version 1, or (at your option)
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
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#include "widgets.h"
#include "widgets_private.h"
#include "gb.form.font.h"
#ifndef GAMBAS_DIRECTFB
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#endif
#endif
#include "gapplication.h"
#include "gmainwindow.h"
#include "gdesktop.h"
/***********************************************************************
Cursor
************************************************************************/
gCursor::gCursor(gPicture *pic,int px,int py)
{
GdkPixbuf *buf;
GdkDisplay *dp=gdk_display_get_default();
x=px;
y=py;
cur=NULL;
if (!pic) return;
if (!pic->pic) return;
if (pic->width()<=x) x=pic->width()-1;
if (pic->height()<=y) y=pic->height()-1;
buf=pic->getPixbuf();
cur=gdk_cursor_new_from_pixbuf(dp,buf,x,y);
}
gCursor::gCursor(gCursor *cursor)
{
cur=NULL;
if (!cursor) return;
if (!cursor->cur) return;
cur=cursor->cur;
x=cursor->x;
y=cursor->y;
if (cur) gdk_cursor_ref(cur);
}
gCursor::~gCursor()
{
if (cur) gdk_cursor_unref(cur);
}
int gCursor::left()
{
return x;
}
int gCursor::top()
{
return y;
}
/***********************************************************************
Desktop
************************************************************************/
gControl *gDesktop::_active_control = NULL;
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)
{
gFont::set(&_desktop_font, ft->copy());
_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;
}*/
void gDesktop::setActiveControl(gControl *control)
{
_active_control = control;
}
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]);
}
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()
{
[INFORMER] * BUG: The informer algorithm was redesigned. Now a sub-process is launched for each component that should be analyzed, and LD_PRELOAD is used to load the component shared library before the process is launched. Otherwise, some component may crash. [GB.DRAW] * BUG: Correctly initialize color properties of the Draw class at Draw.Begin(). * NEW: Draw.FillRect() is a new method to draw a filled rectangle with the specified color. * NEW: Draw.Clear() is a new method that clears the drawing device with its background color. [GB.FORM.MDI] * NEW: Do not use BackColor and ForeColor properties anymore. [GB.GTK] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * BUG: Desktop.Resolution now uses the accurate GTK+ API. * BUG: Setting the ListBox.List to NULL property does not lock the ListBox control anymore. * BUG: Fix the Font object management. Using Font properties should not crash anymore. * BUG: Image.Save() and Picture.Save() now understand the "~" shortcut in path names. [GB.QT] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: Do not check if we should quit too often. * NEW: Allow windows to be closed during a WAIT instruction as in other components. I do not know why it was forbidden before. * NEW: Prevent a crash in arrangement routines if a child widget is not associated with a Gambas control anymore. [GB.QT4] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: The source code is now up to date with gb.qt. But many things do not work as expected! [GB.QT4.EXT] * NEW: The source code is now up to date with gb.qt.ext. But many things do not work as expected! git-svn-id: svn://localhost/gambas/trunk@1776 867c0c6c-44f3-4631-809d-bfa615b0a4ec
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());
[INFORMER] * BUG: The informer algorithm was redesigned. Now a sub-process is launched for each component that should be analyzed, and LD_PRELOAD is used to load the component shared library before the process is launched. Otherwise, some component may crash. [GB.DRAW] * BUG: Correctly initialize color properties of the Draw class at Draw.Begin(). * NEW: Draw.FillRect() is a new method to draw a filled rectangle with the specified color. * NEW: Draw.Clear() is a new method that clears the drawing device with its background color. [GB.FORM.MDI] * NEW: Do not use BackColor and ForeColor properties anymore. [GB.GTK] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * BUG: Desktop.Resolution now uses the accurate GTK+ API. * BUG: Setting the ListBox.List to NULL property does not lock the ListBox control anymore. * BUG: Fix the Font object management. Using Font properties should not crash anymore. * BUG: Image.Save() and Picture.Save() now understand the "~" shortcut in path names. [GB.QT] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: Do not check if we should quit too often. * NEW: Allow windows to be closed during a WAIT instruction as in other components. I do not know why it was forbidden before. * NEW: Prevent a crash in arrangement routines if a child widget is not associated with a Gambas control anymore. [GB.QT4] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: The source code is now up to date with gb.qt. But many things do not work as expected! [GB.QT4.EXT] * NEW: The source code is now up to date with gb.qt.ext. But many things do not work as expected! git-svn-id: svn://localhost/gambas/trunk@1776 867c0c6c-44f3-4631-809d-bfa615b0a4ec
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());
}
int gDesktop::scale()
{
if (!_desktop_scale)
{
gFont *ft = font();
_desktop_scale = GET_DESKTOP_SCALE(ft->size(), resolution());
}
/* PangoLanguage *lng=NULL;
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);
val = 1 + (pango_font_metrics_get_ascent(fm) + pango_font_metrics_get_descent(fm)) / PANGO_SCALE;
val = GET_DESKTOP_SCALE(val);
pango_font_metrics_unref(fm);
g_object_unref(G_OBJECT(ct));
if (!val) val = 1;
_desktop_scale = val;
}*/
return _desktop_scale;
}
gPicture* gDesktop::grab()
{
return Grab_gdkWindow(gdk_get_default_root_window());
}