378 lines
7.6 KiB
C++
Raw Normal View History

/***************************************************************************
CFont.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 __CFONT_CPP
#include <math.h>
#include "CFont.h"
#include "gdesktop.h"
#include "ggambastag.h"
#include "gb.form.font.h"
CFONT *CFONT_create(gFont *font, FONT_FUNC func, void *object)
{
CFONT *fnt;
if (font && font->getTag())
return (CFONT *)font->getTagValue();
GB.New((void **)POINTER(&fnt), GB.FindClass("Font"), 0, 0);
if (font)
{
fnt->font->unref();
fnt->font = font;
[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
//font->ref();
font->setTag(new gGambasTag((void *)fnt));
}
fnt->func = func;
fnt->object = object;
if (object)
GB.Ref(object);
return fnt;
}
BEGIN_METHOD(CFONT_new, GB_STRING font)
if (!MISSING(font))
FONT = new gFont(GB.ToZeroString(ARG(font)));
else
FONT = gDesktop::font()->copy();
END_METHOD
BEGIN_METHOD_VOID(CFONT_free)
GB.Unref(POINTER(&THIS->object));
gFont::assign(&THIS->font);
END_METHOD
static void CFONT_manage(int prop, CFONT *_object, void *_param)
{
gFont *f = FONT;
[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
if (!f)
{
THIS->font = ((CWIDGET *)THIS->object)->widget->font()->copy();
f = FONT;
}
if (READ_PROPERTY)
{
switch(prop)
{
case CFONT::Name: GB.ReturnNewZeroString(f->name()); break;
case CFONT::Size: GB.ReturnFloat(f->size()); break;
case CFONT::Grade: GB.ReturnInteger(f->grade()); break;
case CFONT::Bold: GB.ReturnBoolean(f->bold()); break;
case CFONT::Italic: GB.ReturnBoolean(f->italic()); break;
case CFONT::Underline: GB.ReturnBoolean(f->underline()); break;
case CFONT::StrikeOut: GB.ReturnBoolean(f->strikeOut()); break;
}
}
else
{
switch (prop)
{
case CFONT::Name: f->setName(GB.ToZeroString(PROP(GB_STRING))); break;
case CFONT::Size: f->setSize(VPROP(GB_FLOAT)); break;
case CFONT::Grade: f->setGrade(VPROP(GB_INTEGER)); break;
case CFONT::Bold: f->setBold(VPROP(GB_BOOLEAN)); break;
case CFONT::Italic: f->setItalic(VPROP(GB_BOOLEAN)); break;
case CFONT::Underline: f->setUnderline(VPROP(GB_BOOLEAN)); break;
case CFONT::StrikeOut: f->setStrikeOut(VPROP(GB_BOOLEAN)); break;
}
if (THIS->func)
(*(THIS->func))(f, THIS->object);
else if (THIS->object)
{
// THIS->control->widget->setFont(*f); - Not needed anymore
// TODO Make a Gambas API to call SetProperty faster
//fprintf(stderr, "applying font to (%s %p)\n", GB.GetClassName(THIS->object), THIS->object);
GB_FUNCTION func;
GB.GetFunction(&func, (void *)GB.FindClass("Object"), "SetProperty", NULL, NULL);
GB.Push(3,
GB_T_OBJECT, THIS->object,
GB_T_STRING, "Font", 4,
GB_T_OBJECT, THIS
);
GB.Call(&func, 3, TRUE);
}
}
}
BEGIN_PROPERTY(CFONT_name)
CFONT_manage(CFONT::Name, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_size)
CFONT_manage(CFONT::Size, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_grade)
CFONT_manage(CFONT::Grade, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_bold)
CFONT_manage(CFONT::Bold, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_italic)
CFONT_manage(CFONT::Italic, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_underline)
CFONT_manage(CFONT::Underline, OBJECT(CFONT), _param);
END_PROPERTY
BEGIN_PROPERTY(CFONT_strikeout)
CFONT_manage(CFONT::StrikeOut, OBJECT(CFONT), _param);
END_PROPERTY
#if 0
BEGIN_PROPERTY(CFONT_name)
const char *buf;
if (READ_PROPERTY)
{
buf=FONT->name();
GB.ReturnNewString(buf,0);
return;
}
FONT->setName(GB.ToZeroString(PROP(GB_STRING)));
END_PROPERTY
BEGIN_PROPERTY(CFONT_size)
if (READ_PROPERTY) { GB.ReturnFloat(FONT->size()); return; }
FONT->setSize(VPROP(GB_FLOAT));
END_PROPERTY
BEGIN_PROPERTY(CFONT_bold)
if (READ_PROPERTY){ GB.ReturnBoolean(FONT->bold()); return; }
FONT->setBold(VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(CFONT_italic)
if (READ_PROPERTY){ GB.ReturnBoolean(FONT->italic()); return; }
FONT->setItalic(VPROP(GB_BOOLEAN));
END_PROPERTY
#endif
BEGIN_METHOD_VOID(CFONT_to_string)
GB.ReturnNewString(FONT->toString(), 0);
END_METHOD
BEGIN_METHOD(CFONT_get, GB_STRING str)
CFONT *font;
gFont *fnt;
[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
fnt = new gFont(GB.ToZeroString(ARG(str)));
font = CFONT_create(fnt);
//gFont::assign(&fnt);
GB.ReturnObject(font);
END_METHOD
BEGIN_METHOD(CFONT_width, GB_STRING text)
GB.ReturnInteger( FONT->width( STRING(text), LENGTH(text) ) );
END_METHOD
BEGIN_PROPERTY(CFONT_ascent)
GB.ReturnInteger(FONT->ascent());
END_PROPERTY
BEGIN_PROPERTY(CFONT_descent)
GB.ReturnInteger(FONT->descent());
END_PROPERTY
BEGIN_METHOD(CFONT_height, GB_STRING text)
if (MISSING(text))
GB.ReturnInteger(FONT->height());
else
GB.ReturnInteger(FONT->height(STRING(text), LENGTH(text)));
END_METHOD
BEGIN_PROPERTY(CFONT_fixed)
GB.ReturnBoolean(FONT->fixed());
END_PROPERTY
#if 0
BEGIN_PROPERTY(CFONT_resolution)
END_PROPERTY
#endif
BEGIN_METHOD_VOID(CFONTS_next)
long *pos;
pos=(long*)GB.GetEnum();
if ( pos[0]>=gFont::count() )
{
GB.StopEnum ();
return;
}
GB.ReturnNewString ( gFont::familyItem(pos[0]++),0 );
END_METHOD
BEGIN_PROPERTY(CFONTS_count)
GB.ReturnInteger(gFont::count());
END_PROPERTY
BEGIN_PROPERTY(CFONT_styles)
stub("CFONT_styles");
END_PROPERTY
BEGIN_PROPERTY(CFONT_scalable)
GB.ReturnBoolean(FONT->scalable());
END_PROPERTY
#if 0
BEGIN_PROPERTY(CFONT_underline)
if (READ_PROPERTY) { GB.ReturnBoolean(FONT->underline()); return; }
FONT->setUnderline(VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(CFONT_strikeout)
if (READ_PROPERTY) { GB.ReturnBoolean(FONT->strikeOut()); return; }
FONT->setStrikeOut(VPROP(GB_BOOLEAN));
END_PROPERTY
#endif
GB_DESC CFontsDesc[] =
{
GB_DECLARE("Fonts", 0),
GB_NOT_CREATABLE(),
******** 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("_next", "s", CFONTS_next, 0),
GB_STATIC_PROPERTY_READ("Count", "i", CFONTS_count),
GB_END_DECLARE
};
GB_DESC CFontDesc[] =
{
GB_DECLARE("Font", sizeof(CFONT)),
******** 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_METHOD("_new", 0, CFONT_new, "[(Font)s]"),
GB_METHOD("_free", 0, CFONT_free, 0),
GB_PROPERTY("Name", "s", CFONT_name),
GB_PROPERTY("Size", "f", CFONT_size),
GB_PROPERTY("Bold", "b", CFONT_bold),
GB_PROPERTY("Italic", "b", CFONT_italic),
GB_PROPERTY("Underline", "b", CFONT_underline),
GB_PROPERTY("StrikeOut", "b", CFONT_strikeout),
GB_PROPERTY("Grade", "i", CFONT_grade),
******** 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_METHOD("ToString", "s", CFONT_to_string, 0),
GB_METHOD("Width", "i", CFONT_width, "(Text)s"),
GB_METHOD("Height", "i", CFONT_height, "[(Text)s]"),
GB_STATIC_METHOD("_get", "Font", CFONT_get, "(Font)s"),
#if 0
GB_STATIC_PROPERTY("Resolution", "i", CFONT_resolution),
#endif
GB_PROPERTY_READ("Ascent", "i", CFONT_ascent),
GB_PROPERTY_READ("Descent", "i", CFONT_descent),
GB_PROPERTY_READ("Fixed", "b", CFONT_fixed),
GB_PROPERTY_READ("Scalable", "b", CFONT_scalable),
GB_PROPERTY_READ("Styles", "String[]", CFONT_styles),
GB_END_DECLARE
};