285 lines
6.0 KiB
C++
Raw Normal View History

/***************************************************************************
CScreen.cpp
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
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 2, 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.
***************************************************************************/
#define __CSCREEN_CPP
#include "CWindow.h"
#include "CPicture.h"
#include "CFont.h"
#include "CScreen.h"
#include "gapplication.h"
#include "gmainwindow.h"
extern int CWINDOW_Embedder;
extern bool CWINDOW_Embedded;
extern int MAIN_scale;
char *CAPPLICATION_Theme = 0;
static int _busy = 0;
BEGIN_PROPERTY(CSCREEN_width)
GB.ReturnInteger(gDesktop::width());
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_height)
GB.ReturnInteger(gDesktop::height());
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_resolution)
GB.ReturnInteger(gDesktop::resolution());
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_charset)
GB.ReturnConstZeroString("UTF-8");
END_PROPERTY
BEGIN_METHOD(CSCREEN_grab, GB_INTEGER x; GB_INTEGER y; GB_INTEGER width; GB_INTEGER height)
CPICTURE *pic;
gPicture *buf = gDesktop::screenshot(VARGOPT(x,0), VARGOPT(y, 0), VARGOPT(width, 0), VARGOPT(height, 0));
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
GB.New(POINTER(&pic), GB.FindClass("Picture"), 0, 0);
if (pic->picture) pic->picture->unref();
pic->picture = buf;
GB.ReturnObject(pic);
END_METHOD
static void set_font(gFont *font, void *object = 0)
{
gDesktop::setFont(font);
MAIN_scale = gDesktop::scale();
}
static void set_tooltip_font(gFont *font, void *object = 0)
{
gApplication::setToolTipsFont(font);
}
BEGIN_PROPERTY(CAPP_font)
if (READ_PROPERTY)
[DEVELOPMENT ENVIRONMENT] * BUG: The button that switches between form and class editor is not shown anymore when a module or a class is edited. [GB.GTK] * BUG: Font management was redesigned. It does not leak memory anymore, and now behaves like in gb.qt. * BUG: Tristate CheckBox controls now work as expected. * BUG: Destroy pending deleted controls before entering the event loop, to avoid some memory leaks if the event loop is immediately aborted. * BUG: Detach destroyed controls from their event listener, as in gb.qt. * BUG: Now menu shortcuts are active even if the menu bar is hidden. But the menu must be visible. To create an hidden active top-level menu, just set its Text property to NULL, but keep it visible. * NEW: Top-level menus with a void Text property are not shown anymore. * BUG: Showing and hiding top-level menu now work correctly. [GB.QT] * BUG: Font properties are correctly inherited between containers and children controls. * BUG: Showing a tray icon does not eat focus events anymore. * NEW: Top-level menus with a void Text property are not shown anymore. [GB.QT4] * BUG: Font properties are correctly inherited between containers and children controls. * BUG: Shortcut management was fixed. * BUG: Now menu shortcuts are active even if the menu bar is hidden. But the menu must be visible. To create an hidden active top-level menu, just set its Text property to NULL, but keep it visible. * NEW: Top-level menus with a void Text property are not shown anymore. * BUG: Showing and hiding top-level menu now work correctly. git-svn-id: svn://localhost/gambas/trunk@2034 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-06-22 11:16:34 +00:00
GB.ReturnObject(CFONT_create(gDesktop::font()->copy(), set_font));
else if (VPROP(GB_OBJECT))
set_font(((CFONT*)VPROP(GB_OBJECT))->font);
END_PROPERTY
BEGIN_PROPERTY(CAPP_tooltip_font)
if (READ_PROPERTY)
[DEVELOPMENT ENVIRONMENT] * BUG: The button that switches between form and class editor is not shown anymore when a module or a class is edited. [GB.GTK] * BUG: Font management was redesigned. It does not leak memory anymore, and now behaves like in gb.qt. * BUG: Tristate CheckBox controls now work as expected. * BUG: Destroy pending deleted controls before entering the event loop, to avoid some memory leaks if the event loop is immediately aborted. * BUG: Detach destroyed controls from their event listener, as in gb.qt. * BUG: Now menu shortcuts are active even if the menu bar is hidden. But the menu must be visible. To create an hidden active top-level menu, just set its Text property to NULL, but keep it visible. * NEW: Top-level menus with a void Text property are not shown anymore. * BUG: Showing and hiding top-level menu now work correctly. [GB.QT] * BUG: Font properties are correctly inherited between containers and children controls. * BUG: Showing a tray icon does not eat focus events anymore. * NEW: Top-level menus with a void Text property are not shown anymore. [GB.QT4] * BUG: Font properties are correctly inherited between containers and children controls. * BUG: Shortcut management was fixed. * BUG: Now menu shortcuts are active even if the menu bar is hidden. But the menu must be visible. To create an hidden active top-level menu, just set its Text property to NULL, but keep it visible. * NEW: Top-level menus with a void Text property are not shown anymore. * BUG: Showing and hiding top-level menu now work correctly. git-svn-id: svn://localhost/gambas/trunk@2034 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-06-22 11:16:34 +00:00
GB.ReturnObject(CFONT_create(gApplication::toolTipsFont()->copy(), set_tooltip_font));
else if (VPROP(GB_OBJECT))
set_tooltip_font(((CFONT*)VPROP(GB_OBJECT))->font);
END_PROPERTY
#if 0
BEGIN_PROPERTY(CSCREEN_font)
CFONT *Font;
if (READ_PROPERTY)
{
GB.New((void **)&Font, GB.FindClass("Font"), 0, 0);
Font->font->unref();
Font->font=gDesktop::font();
Font->font->ref();
GB.ReturnObject(Font);
return;
}
Font=(CFONT*)VPROP(GB_OBJECT);
if (!Font) return;
if (!Font->font) return;
gDesktop::setFont(Font->font);
END_PROPERTY
#endif
BEGIN_PROPERTY(CSCREEN_active_window)
GB.ReturnObject(CWINDOW_Active);
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_active_control)
gControl *win=gDesktop::activeControl();
if (!win) { GB.ReturnNull(); return; }
GB.ReturnObject(GetObject(win));
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_busy)
int busy;
if (READ_PROPERTY)
GB.ReturnInteger(_busy);
else
{
busy = VPROP(GB_INTEGER);
if (_busy == 0 && busy != 0)
gApplication::setBusy(true);
else if (_busy > 0 && busy == 0)
gApplication::setBusy(false);
_busy = busy;
}
END_PROPERTY
BEGIN_PROPERTY(CSCREEN_scale)
GB.ReturnInteger(MAIN_scale);
END_PROPERTY
BEGIN_PROPERTY(CAPP_tooltip_enabled)
if (READ_PROPERTY) { GB.ReturnBoolean(gApplication::toolTips()); return; }
gApplication::enableTooltips(VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(CAPP_tooltip_delay)
if (READ_PROPERTY)
GB.ReturnInteger(gApplication::toolTipsDelay());
else
gApplication::setToolTipsDelay(VPROP(GB_INTEGER));
END_PROPERTY
BEGIN_PROPERTY(CAPP_main_window)
GB.ReturnObject(WINDOW_get_main());
END_PROPERTY
BEGIN_METHOD_VOID(CAPP_exit)
GB.FreeString(&CAPPLICATION_Theme);
END_METHOD
BEGIN_PROPERTY(CAPP_theme)
if (READ_PROPERTY) { GB.ReturnString(CAPPLICATION_Theme); return; }
GB.StoreString(PROP(GB_STRING), &CAPPLICATION_Theme);
END_PROPERTY
GB_DESC CDesktopDesc[] =
{
GB_DECLARE("Desktop", 0), GB_VIRTUAL_CLASS(),
GB_STATIC_PROPERTY_READ("W", "i", CSCREEN_width),
GB_STATIC_PROPERTY_READ("H", "i", CSCREEN_height),
GB_STATIC_PROPERTY_READ("Width", "i", CSCREEN_width),
GB_STATIC_PROPERTY_READ("Height", "i", CSCREEN_height),
GB_STATIC_PROPERTY_READ("Charset", "s", CSCREEN_charset),
GB_STATIC_PROPERTY_READ("Resolution", "i", CSCREEN_resolution),
GB_STATIC_PROPERTY_READ("Scale","i",CSCREEN_scale),
GB_STATIC_METHOD("Screenshot", "Picture", CSCREEN_grab, "[(X)i(Y)i(Width)i(Height)i]"),
GB_END_DECLARE
};
GB_DESC CApplicationTooltipDesc[] =
{
GB_DECLARE(".ApplicationTooltip", 0), GB_VIRTUAL_CLASS(),
GB_STATIC_PROPERTY("Enabled", "b", CAPP_tooltip_enabled),
GB_STATIC_PROPERTY("Font", "Font", CAPP_tooltip_font),
//GB_STATIC_PROPERTY("Delay", "i", CAPP_tooltip_delay),
GB_END_DECLARE
};
BEGIN_PROPERTY(CAPP_embedder)
if (READ_PROPERTY)
GB.ReturnInteger(CWINDOW_Embedder);
else
{
if (CWINDOW_Embedded)
{
GB.Error("Application is already embedded");
return;
}
CWINDOW_Embedder = VPROP(GB_INTEGER);
}
END_PROPERTY
GB_DESC CApplicationDesc[] =
{
GB_DECLARE("Application", 0), GB_VIRTUAL_CLASS(),
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
GB_STATIC_METHOD("_exit", NULL, CAPP_exit, 0),
GB_STATIC_PROPERTY("Font", "Font", CAPP_font),
GB_STATIC_PROPERTY_READ("ActiveControl","Control",CSCREEN_active_control),
GB_STATIC_PROPERTY_READ("ActiveWindow", "Window", CSCREEN_active_window),
GB_STATIC_PROPERTY_READ("MainWindow", "Window", CAPP_main_window),
GB_STATIC_PROPERTY("Busy", "i", CSCREEN_busy),
GB_STATIC_PROPERTY_SELF("ToolTip", ".ApplicationTooltip"),
GB_STATIC_PROPERTY("Embedder", "i", CAPP_embedder),
GB_STATIC_PROPERTY("Theme", "s", CAPP_theme),
GB_END_DECLARE
};