diff options
author | Murray Cumming <murrayc@src.gnome.org> | 2003-01-07 16:59:16 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2003-01-07 16:59:16 +0000 |
commit | 78e5bf1313f67e4cbc67fe01a408d27de7383abd (patch) | |
tree | f832445dad23cd0dcc2a116fcc1469d35316d995 /tools/extra_defs_gen | |
download | glibmm-78e5bf1313f67e4cbc67fe01a408d27de7383abd.tar.gz |
Initial revision
Diffstat (limited to 'tools/extra_defs_gen')
-rw-r--r-- | tools/extra_defs_gen/.cvsignore | 3 | ||||
-rw-r--r-- | tools/extra_defs_gen/Makefile.am | 29 | ||||
-rw-r--r-- | tools/extra_defs_gen/generate_defs_gtk.cc | 159 | ||||
-rw-r--r-- | tools/extra_defs_gen/generate_extra_defs.cc | 213 | ||||
-rw-r--r-- | tools/extra_defs_gen/generate_extra_defs.h | 33 |
5 files changed, 437 insertions, 0 deletions
diff --git a/tools/extra_defs_gen/.cvsignore b/tools/extra_defs_gen/.cvsignore new file mode 100644 index 00000000..9a811404 --- /dev/null +++ b/tools/extra_defs_gen/.cvsignore @@ -0,0 +1,3 @@ +Makefile +Makefile.in +generate_extra_defs diff --git a/tools/extra_defs_gen/Makefile.am b/tools/extra_defs_gen/Makefile.am new file mode 100644 index 00000000..e856f159 --- /dev/null +++ b/tools/extra_defs_gen/Makefile.am @@ -0,0 +1,29 @@ +# Build the library, to be installed and used by other defs-generating code: + +files_h = generate_extra_defs.h +files_cc = generate_extra_defs.cc + +if PLATFORM_WIN32 +no_undefined = -no-undefined +else +no_undefined = +endif + +lib_LTLIBRARIES = libgtkmm_generate_extra_defs-2.0.la +libgtkmm_generate_extra_defs_2_0_la_SOURCES = $(files_h) $(files_cc) +libgtkmm_generate_extra_defs_2_0_la_LDFLAGS = $(no_undefined) -version-info $(LIBGTKMM_SO_VERSION) $(LIBSTDCPP_LIBS) +libgtkmm_generate_extra_defs_2_0_la_LIBADD = $(GLIBMM_LIBS) + +sublib_includedir = $(includedir)/gtkmm-2.0/gtkmm_generate_extra_defs +sublib_include_HEADERS = $(files_h) + + +# Build the generate_properties_defs utility executable. +# This is not used to build the rest of gtkmm. + +INCLUDES = $(GTKMM_CFLAGS) +LIBS = $(GTKMM_LIBS) + +noinst_PROGRAMS = generate_extra_defs +generate_extra_defs_SOURCES = generate_defs_gtk.cc +generate_extra_defs_LDADD = libgtkmm_generate_extra_defs-2.0.la diff --git a/tools/extra_defs_gen/generate_defs_gtk.cc b/tools/extra_defs_gen/generate_defs_gtk.cc new file mode 100644 index 00000000..060d487a --- /dev/null +++ b/tools/extra_defs_gen/generate_defs_gtk.cc @@ -0,0 +1,159 @@ +/* $Id$ */ + +/* generate_defs_gtk.cc + * + * Copyright (C) 2001 The Free Software Foundation + * + * This library 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 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "generate_extra_defs.h" +#include <gdk/gdk.h> +#include <gtk/gtk.h> + +int main (int argc, char *argv[]) +{ + gtk_init(&argc, &argv); + + void *const g_class_atk_no_op_object = g_type_class_ref(ATK_TYPE_NO_OP_OBJECT); + + std::cout << get_defs( ATK_TYPE_HYPERLINK ) + << get_defs( ATK_TYPE_OBJECT ) + << get_defs( ATK_TYPE_COMPONENT ) + << get_defs( ATK_TYPE_ACTION ) + << get_defs( ATK_TYPE_EDITABLE_TEXT ) + << get_defs( ATK_TYPE_IMAGE ) + << get_defs( ATK_TYPE_SELECTION ) + << get_defs( ATK_TYPE_TABLE ) + << get_defs( ATK_TYPE_TEXT ) + << get_defs( ATK_TYPE_VALUE ) + << get_defs( ATK_TYPE_REGISTRY ) + << get_defs( ATK_TYPE_RELATION ) + << get_defs( ATK_TYPE_RELATION_SET ) + << get_defs( ATK_TYPE_STATE_SET ); + + g_type_class_unref(g_class_atk_no_op_object); + + std::cout << get_defs( GDK_TYPE_COLORMAP ) + << get_defs( GDK_TYPE_DRAG_CONTEXT ) + << get_defs( GDK_TYPE_DISPLAY ) + << get_defs( GDK_TYPE_DISPLAY_MANAGER ) + << get_defs( GDK_TYPE_DRAWABLE ) + << get_defs( GDK_TYPE_GC ) + << get_defs( GDK_TYPE_IMAGE ) + << get_defs( GDK_TYPE_PIXBUF ) + << get_defs( GDK_TYPE_PIXBUF_ANIMATION ) + << get_defs( GDK_TYPE_PIXBUF_LOADER ) + << get_defs( GDK_TYPE_PIXMAP ) + << get_defs( GDK_TYPE_SCREEN ) + << get_defs( GDK_TYPE_VISUAL ) + << get_defs( GDK_TYPE_WINDOW ) + + << get_defs( GTK_TYPE_ACCEL_GROUP ) + << get_defs( GTK_TYPE_ACCEL_LABEL ) + << get_defs( GTK_TYPE_ADJUSTMENT ) + << get_defs( GTK_TYPE_ALIGNMENT) + << get_defs( GTK_TYPE_ARROW ) + << get_defs( GTK_TYPE_ASPECT_FRAME ) + << get_defs( GTK_TYPE_BIN ) + << get_defs( GTK_TYPE_BOX ) + << get_defs( GTK_TYPE_BUTTON ) + << get_defs( GTK_TYPE_BUTTON_BOX ) + << get_defs( GTK_TYPE_CALENDAR ) + << get_defs( GTK_TYPE_CHECK_BUTTON ) + << get_defs( GTK_TYPE_CHECK_MENU_ITEM ) + << get_defs( GTK_TYPE_CLIST ) + << get_defs( GTK_TYPE_CELL_RENDERER ) + << get_defs( GTK_TYPE_CELL_RENDERER_TEXT ) + << get_defs( GTK_TYPE_CELL_RENDERER_TOGGLE ) + << get_defs( GTK_TYPE_CELL_RENDERER_PIXBUF ) + << get_defs( GTK_TYPE_COLOR_SELECTION ) + << get_defs( GTK_TYPE_COMBO ) + << get_defs( GTK_TYPE_CONTAINER ) + << get_defs( GTK_TYPE_CTREE ) + << get_defs( GTK_TYPE_CURVE ) + << get_defs( GTK_TYPE_DIALOG ) + << get_defs( GTK_TYPE_DRAWING_AREA ) + << get_defs( GTK_TYPE_ENTRY ) + << get_defs( GTK_TYPE_EVENT_BOX ) + << get_defs( GTK_TYPE_FILE_SELECTION ) + << get_defs( GTK_TYPE_FIXED ) + << get_defs( GTK_TYPE_FONT_SELECTION ) + << get_defs( GTK_TYPE_FONT_SELECTION_DIALOG ) + << get_defs( GTK_TYPE_FRAME ) + << get_defs( GTK_TYPE_HANDLE_BOX ) + << get_defs( GTK_TYPE_IMAGE ) + << get_defs( GTK_TYPE_INPUT_DIALOG ) + << get_defs( GTK_TYPE_INVISIBLE ) + << get_defs( GTK_TYPE_ITEM ) + << get_defs( GTK_TYPE_LABEL ) + << get_defs( GTK_TYPE_LAYOUT ) + << get_defs( GTK_TYPE_LIST ) + << get_defs( GTK_TYPE_LIST_ITEM ) + << get_defs( GTK_TYPE_MENU ) + << get_defs( GTK_TYPE_MENU_BAR ) + << get_defs( GTK_TYPE_MENU_ITEM ) + << get_defs( GTK_TYPE_MENU_SHELL ) + << get_defs( GTK_TYPE_MESSAGE_DIALOG ) + << get_defs( GTK_TYPE_MISC ) + << get_defs( GTK_TYPE_NOTEBOOK ) + << get_defs( GTK_TYPE_OBJECT ) + << get_defs( GTK_TYPE_OPTION_MENU ) + << get_defs( GTK_TYPE_PANED ) + << get_defs( GTK_TYPE_PIXMAP ) +#if !defined(_WIN32) + << get_defs( GTK_TYPE_PLUG ) +#endif + << get_defs( GTK_TYPE_PREVIEW ) + << get_defs( GTK_TYPE_PROGRESS ) + << get_defs( GTK_TYPE_PROGRESS_BAR ) + << get_defs( GTK_TYPE_RADIO_BUTTON ) + << get_defs( GTK_TYPE_RADIO_MENU_ITEM ) + << get_defs( GTK_TYPE_RANGE ) + << get_defs( GTK_TYPE_RULER ) + << get_defs( GTK_TYPE_SCALE ) + << get_defs( GTK_TYPE_SCROLLBAR ) + << get_defs( GTK_TYPE_SCROLLED_WINDOW ) + << get_defs( GTK_TYPE_SEPARATOR ) + << get_defs( GTK_TYPE_SETTINGS ) + << get_defs( GTK_TYPE_SIZE_GROUP ) +#if !defined(_WIN32) + << get_defs( GTK_TYPE_SOCKET ) +#endif + << get_defs( GTK_TYPE_SPIN_BUTTON ) + << get_defs( GTK_TYPE_STATUSBAR ) + << get_defs( GTK_TYPE_STYLE ) + << get_defs( GTK_TYPE_TABLE ) + << get_defs( GTK_TYPE_TEAROFF_MENU_ITEM ) + << get_defs( GTK_TYPE_TIPS_QUERY ) + << get_defs( GTK_TYPE_TOGGLE_BUTTON ) + << get_defs( GTK_TYPE_TOOLBAR ) + << get_defs( GTK_TYPE_TEXT_BUFFER ) + << get_defs( GTK_TYPE_TEXT_MARK ) + << get_defs( GTK_TYPE_TEXT_TAG ) + << get_defs( GTK_TYPE_TEXT_TAG_TABLE ) + << get_defs( GTK_TYPE_TEXT_VIEW ) + << get_defs( GTK_TYPE_TOOLTIPS ) + << get_defs( GTK_TYPE_TREE_SELECTION ) + << get_defs( GTK_TYPE_TREE_STORE ) + << get_defs( GTK_TYPE_TREE_VIEW ) + << get_defs( GTK_TYPE_TREE_VIEW_COLUMN ) + << get_defs( GTK_TYPE_VIEWPORT ) + << get_defs( GTK_TYPE_WIDGET ) + << get_defs( GTK_TYPE_WINDOW ); + + + return 0; +} diff --git a/tools/extra_defs_gen/generate_extra_defs.cc b/tools/extra_defs_gen/generate_extra_defs.cc new file mode 100644 index 00000000..3dbf5031 --- /dev/null +++ b/tools/extra_defs_gen/generate_extra_defs.cc @@ -0,0 +1,213 @@ +/* $Id$ */ + +/* generate_extra_defs.cc + * + * Copyright (C) 2001 The Free Software Foundation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include "generate_extra_defs.h" + +std::string get_properties(GType gtype) +{ + std::string strResult; + std::string strObjectName = g_type_name(gtype); + + //Get the list of properties: + GObjectClass* pGClass = G_OBJECT_CLASS(g_type_class_ref(gtype)); + + guint iCount = 0; + GParamSpec** ppParamSpec = g_object_class_list_properties (pGClass, &iCount); + + for(guint i = 0; i < iCount; i++) + { + GParamSpec* pParamSpec = ppParamSpec[i]; + if(pParamSpec) + { + //Name and type: + std::string strName = g_param_spec_get_name(pParamSpec); + std::string strTypeName = G_PARAM_SPEC_TYPE_NAME(pParamSpec); + + strResult += "(define-property " + strName + "\n"; + strResult += " (of-object \"" + strObjectName + "\")\n"; + strResult += " (prop-type \"" + strTypeName + "\")\n"; + + //Flags: + GParamFlags flags = pParamSpec->flags; + bool bReadable = (flags & G_PARAM_READABLE) == G_PARAM_READABLE; + bool bWritable = (flags & G_PARAM_WRITABLE) == G_PARAM_WRITABLE; + bool bConstructOnly = (flags & G_PARAM_CONSTRUCT_ONLY) == G_PARAM_CONSTRUCT_ONLY; + + //#t and #f aren't documented, but I guess that it's correct based on the example in the .defs spec. + const std::string strTrue = "#t"; + const std::string strFalse = "#f"; + + strResult += " (readable " + (bReadable ? strTrue : strFalse) + ")\n"; + strResult += " (writable " + (bWritable ? strTrue : strFalse) + ")\n"; + strResult += " (construct-only " + (bConstructOnly ? strTrue : strFalse) + ")\n"; + + strResult += ")\n\n"; //close (define-property + } + } + + g_free(ppParamSpec); + g_type_class_unref(pGClass); //to match the g_type_class_ref() above. + + return strResult; +} + +std::string get_type_name(GType gtype) //Adds a * if necessary. +{ + std::string strTypeName = g_type_name(gtype); + + if( g_type_is_a(gtype, G_TYPE_OBJECT) || g_type_is_a(gtype, G_TYPE_BOXED) ) + strTypeName += "*"; //Add * to show that it's a pointer. + else if( g_type_is_a(gtype, G_TYPE_STRING) ) + strTypeName = "gchar*"; //g_type_name() returns "gchararray". + + return strTypeName; +} + +std::string get_type_name_parameter(GType gtype) +{ + std::string strTypeName = get_type_name(gtype); + + //All signal parameters that are registered as GTK_TYPE_STRING are actually const gchar*. + if(strTypeName == "gchar*") + strTypeName = "const-gchar*"; + + return strTypeName; +} + +std::string get_type_name_signal(GType gtype) +{ + return get_type_name_parameter(gtype); //At the moment, it needs the same stuff. +} + + +std::string get_signals(GType gtype) +{ + std::string strResult; + std::string strObjectName = g_type_name(gtype); + + gpointer gclass_ref = 0; + + if(G_TYPE_IS_OBJECT(gtype)) + gclass_ref = g_type_class_ref(gtype); //Ensures that class_init() is called. + + //Get the list of signals: + guint iCount = 0; + guint* pIDs = g_signal_list_ids (gtype, &iCount); + + //Loop through the list of signals: + if(pIDs) + { + for(guint i = 0; i < iCount; i++) + { + guint signal_id = pIDs[i]; + + //Name: + std::string strName = g_signal_name(signal_id); + strResult += "(define-signal " + strName + "\n"; + strResult += " (of-object \"" + strObjectName + "\")\n"; + + + + //Other information about the signal: + GSignalQuery signalQuery = { 0, 0, 0, GSignalFlags(0), 0, 0, 0, }; + g_signal_query(signal_id, &signalQuery); + + //Return type: + std::string strReturnTypeName = get_type_name_signal( signalQuery.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE ); //The type is mangled with a flag. Hacky. + //bool bReturnTypeHasStaticScope = (signalQuery.return_type & G_SIGNAL_TYPE_STATIC_SCOPE) == G_SIGNAL_TYPE_STATIC_SCOPE; + strResult += " (return-type \"" + strReturnTypeName + "\")\n"; + + + //When: + { + bool bWhenFirst = (signalQuery.signal_flags & G_SIGNAL_RUN_FIRST) == G_SIGNAL_RUN_FIRST; + bool bWhenLast = (signalQuery.signal_flags & G_SIGNAL_RUN_LAST) == G_SIGNAL_RUN_LAST; + + std::string strWhen = "unknown"; + + if(bWhenFirst && bWhenLast) + strWhen = "both"; + else if(bWhenFirst) + strWhen = "first"; + else if(bWhenLast) + strWhen = "last"; + + strResult += " (when \"" + strWhen + "\")\n"; + } + + + //Loop through the list of parameters: + const GType* pParameters = signalQuery.param_types; + if(pParameters) + { + strResult += " (parameters\n"; + + for(unsigned i = 0; i < signalQuery.n_params; i++) + { + GType typeParamMangled = pParameters[i]; + + //Parameter name: + //TODO: How can we get the real parameter name? + gchar* pchNum = g_strdup_printf("%d", i); + std::string strParamName = "p" + std::string(pchNum); + g_free(pchNum); + pchNum = 0; + + //Just like above, for the return type: + std::string strTypeName = get_type_name_signal( typeParamMangled & ~G_SIGNAL_TYPE_STATIC_SCOPE ); //The type is mangled with a flag. Hacky. + //bool bReturnTypeHasStaticScope = (typeParamMangled & G_SIGNAL_TYPE_STATIC_SCOPE) == G_SIGNAL_TYPE_STATIC_SCOPE; + + strResult += " '(\"" + strTypeName + "\" \"" + strParamName + "\")\n"; + } + + strResult += " )\n"; //close (properties + } + + strResult += ")\n\n"; //close (define=signal + } + } + + g_free(pIDs); + + if(gclass_ref) + g_type_class_unref(gclass_ref); //to match the g_type_class_ref() above. + + return strResult; +} + + + +std::string get_defs(GType gtype) +{ + std::string strObjectName = g_type_name(gtype); + std::string strDefs = ";; From " + strObjectName + "\n\n"; + + strDefs += get_signals(gtype); + + if(G_TYPE_IS_OBJECT(gtype)) + strDefs += get_properties(gtype); + + return strDefs; +} + + + diff --git a/tools/extra_defs_gen/generate_extra_defs.h b/tools/extra_defs_gen/generate_extra_defs.h new file mode 100644 index 00000000..5f209451 --- /dev/null +++ b/tools/extra_defs_gen/generate_extra_defs.h @@ -0,0 +1,33 @@ +/* $Id$ */ + +/* generate_extra_defs.h + * + * Copyright (C) 2001 The Free Software Foundation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include <glib-object.h> +#include <iostream> +#include <string> + +std::string get_defs(GType gtype); + +std::string get_properties(GType gtype); +std::string get_type_name(GType gtype); +std::string get_type_name_parameter(GType gtype); +std::string get_type_name_signal(GType gtype); +std::string get_signals(GType gtype); |