2000-10-18 15:50:13 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2001-05-18 18:30:59 +00:00
|
|
|
#include <stdlib.h>
|
2000-10-18 15:50:13 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
#include <gtk/gtk.h>
|
2004-12-05 12:47:42 +00:00
|
|
|
#include <glib/gstdio.h>
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2008-12-26 21:57:55 +00:00
|
|
|
#include "demos.h"
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2013-02-26 14:55:29 +00:00
|
|
|
static GtkWidget *info_view;
|
|
|
|
static GtkWidget *source_view;
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static gchar *current_file = NULL;
|
|
|
|
|
2012-05-18 04:48:57 +00:00
|
|
|
static GtkWidget *notebook;
|
2013-12-03 01:35:57 +00:00
|
|
|
static GtkWidget *treeview;
|
|
|
|
static GtkWidget *headerbar;
|
2001-11-23 21:46:44 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
enum {
|
2013-01-30 22:16:16 +00:00
|
|
|
NAME_COLUMN,
|
2000-10-26 00:36:47 +00:00
|
|
|
TITLE_COLUMN,
|
|
|
|
FILENAME_COLUMN,
|
|
|
|
FUNC_COLUMN,
|
2006-08-16 23:32:07 +00:00
|
|
|
STYLE_COLUMN,
|
2000-10-26 00:36:47 +00:00
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2000-11-18 23:59:30 +00:00
|
|
|
typedef struct _CallbackData CallbackData;
|
|
|
|
struct _CallbackData
|
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreePath *path;
|
|
|
|
};
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
static void
|
|
|
|
activate_about (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplication *app = user_data;
|
|
|
|
const gchar *authors[] = {
|
|
|
|
"The GTK+ Team",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
gtk_show_about_dialog (GTK_WINDOW (gtk_application_get_active_window (app)),
|
|
|
|
"program-name", "GTK+ Demo",
|
|
|
|
"version", g_strdup_printf ("%s,\nRunning against GTK+ %d.%d.%d",
|
|
|
|
PACKAGE_VERSION,
|
|
|
|
gtk_get_major_version (),
|
|
|
|
gtk_get_minor_version (),
|
|
|
|
gtk_get_micro_version ()),
|
|
|
|
"copyright", "(C) 1997-2013 The GTK+ Team",
|
|
|
|
"license-type", GTK_LICENSE_LGPL_2_1,
|
|
|
|
"website", "http://www.gtk.org",
|
|
|
|
"comments", "Program to demonstrate GTK+ widgets",
|
|
|
|
"authors", authors,
|
|
|
|
"logo-icon-name", "gtk3-demo",
|
|
|
|
"title", "About GTK+ Demo",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
activate_quit (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplication *app = user_data;
|
|
|
|
GtkWidget *win;
|
|
|
|
GList *list, *next;
|
|
|
|
|
|
|
|
list = gtk_application_get_windows (app);
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
win = list->data;
|
|
|
|
next = list->next;
|
|
|
|
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (win));
|
|
|
|
|
|
|
|
list = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-18 23:59:30 +00:00
|
|
|
static void
|
|
|
|
window_closed_cb (GtkWidget *window, gpointer data)
|
|
|
|
{
|
|
|
|
CallbackData *cbdata = data;
|
|
|
|
GtkTreeIter iter;
|
2006-08-16 23:32:07 +00:00
|
|
|
PangoStyle style;
|
2000-11-18 23:59:30 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get_iter (cbdata->model, &iter, cbdata->path);
|
2001-02-17 00:16:08 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (cbdata->model), &iter,
|
2011-09-02 03:55:47 +00:00
|
|
|
STYLE_COLUMN, &style,
|
|
|
|
-1);
|
2006-08-16 23:32:07 +00:00
|
|
|
if (style == PANGO_STYLE_ITALIC)
|
2000-11-18 23:59:30 +00:00
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (cbdata->model), &iter,
|
2011-09-02 03:55:47 +00:00
|
|
|
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
|
|
|
-1);
|
2000-11-18 23:59:30 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (cbdata->path);
|
|
|
|
g_free (cbdata);
|
|
|
|
}
|
|
|
|
|
2013-12-03 01:35:57 +00:00
|
|
|
static void
|
2013-12-13 15:01:18 +00:00
|
|
|
run_example_for_row (GtkWidget *window,
|
|
|
|
GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter)
|
2013-12-03 01:35:57 +00:00
|
|
|
{
|
|
|
|
PangoStyle style;
|
|
|
|
GDoDemoFunc func;
|
|
|
|
GtkWidget *demo;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (model),
|
2013-12-13 15:01:18 +00:00
|
|
|
iter,
|
2013-12-03 01:35:57 +00:00
|
|
|
FUNC_COLUMN, &func,
|
|
|
|
STYLE_COLUMN, &style,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
2013-12-13 15:01:18 +00:00
|
|
|
iter,
|
2013-12-03 01:35:57 +00:00
|
|
|
STYLE_COLUMN, (style == PANGO_STYLE_ITALIC ? PANGO_STYLE_NORMAL : PANGO_STYLE_ITALIC),
|
|
|
|
-1);
|
|
|
|
demo = (func) (window);
|
|
|
|
|
|
|
|
if (demo != NULL)
|
|
|
|
{
|
|
|
|
CallbackData *cbdata;
|
|
|
|
|
|
|
|
cbdata = g_new (CallbackData, 1);
|
|
|
|
cbdata->model = model;
|
2013-12-13 15:01:18 +00:00
|
|
|
cbdata->path = gtk_tree_model_get_path (model, iter);
|
2013-12-03 01:35:57 +00:00
|
|
|
|
2013-12-09 08:55:08 +00:00
|
|
|
if (gtk_widget_is_toplevel (demo))
|
|
|
|
{
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (demo), GTK_WINDOW (window));
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (demo), TRUE);
|
|
|
|
}
|
2013-12-03 02:47:55 +00:00
|
|
|
|
2013-12-03 01:35:57 +00:00
|
|
|
g_signal_connect (demo, "destroy",
|
|
|
|
G_CALLBACK (window_closed_cb), cbdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-13 15:01:18 +00:00
|
|
|
static void
|
|
|
|
activate_run (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *window = user_data;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
|
2015-07-17 19:51:05 +00:00
|
|
|
if (gtk_tree_selection_get_selected (selection, &model, &iter))
|
|
|
|
run_example_for_row (window, model, &iter);
|
2013-12-13 15:01:18 +00:00
|
|
|
}
|
|
|
|
|
2001-05-18 16:28:30 +00:00
|
|
|
/* Stupid syntax highlighting.
|
|
|
|
*
|
|
|
|
* No regex was used in the making of this highlighting.
|
|
|
|
* It should only work for simple cases. This is good, as
|
|
|
|
* that's all we should have in the demos.
|
|
|
|
*/
|
|
|
|
/* This code should not be used elsewhere, except perhaps as an example of how
|
|
|
|
* to iterate through a text buffer.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
STATE_NORMAL,
|
2002-02-23 00:13:17 +00:00
|
|
|
STATE_IN_COMMENT
|
2001-05-18 16:28:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *tokens[] =
|
|
|
|
{
|
|
|
|
"/*",
|
|
|
|
"\"",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *types[] =
|
|
|
|
{
|
|
|
|
"static",
|
|
|
|
"const ",
|
|
|
|
"void",
|
|
|
|
"gint",
|
2008-07-06 07:24:02 +00:00
|
|
|
" int ",
|
|
|
|
" char ",
|
2001-05-18 16:28:30 +00:00
|
|
|
"gchar ",
|
|
|
|
"gfloat",
|
|
|
|
"float",
|
2008-07-06 07:24:02 +00:00
|
|
|
"double",
|
2001-05-18 16:28:30 +00:00
|
|
|
"gint8",
|
|
|
|
"gint16",
|
|
|
|
"gint32",
|
|
|
|
"guint",
|
|
|
|
"guint8",
|
|
|
|
"guint16",
|
|
|
|
"guint32",
|
|
|
|
"guchar",
|
|
|
|
"glong",
|
|
|
|
"gboolean" ,
|
|
|
|
"gshort",
|
|
|
|
"gushort",
|
|
|
|
"gulong",
|
|
|
|
"gdouble",
|
|
|
|
"gldouble",
|
|
|
|
"gpointer",
|
|
|
|
"NULL",
|
|
|
|
"GList",
|
|
|
|
"GSList",
|
|
|
|
"FALSE",
|
|
|
|
"TRUE",
|
|
|
|
"FILE ",
|
|
|
|
"GtkColorSelection ",
|
|
|
|
"GtkWidget ",
|
|
|
|
"GtkButton ",
|
|
|
|
"GdkColor ",
|
|
|
|
"GdkRectangle ",
|
|
|
|
"GdkEventExpose ",
|
|
|
|
"GdkGC ",
|
|
|
|
"GdkPixbufLoader ",
|
|
|
|
"GdkPixbuf ",
|
|
|
|
"GError",
|
|
|
|
"size_t",
|
2008-07-06 07:24:02 +00:00
|
|
|
"GtkAboutDialog ",
|
|
|
|
"GtkAction ",
|
|
|
|
"GtkActionEntry ",
|
|
|
|
"GtkRadioActionEntry ",
|
|
|
|
"GtkIconFactory ",
|
|
|
|
"GtkTextBuffer ",
|
|
|
|
"GtkStatusbar ",
|
|
|
|
"GtkTextIter ",
|
|
|
|
"GtkTextMark ",
|
|
|
|
"GdkEventWindowState ",
|
|
|
|
"GtkActionGroup ",
|
|
|
|
"GtkUIManager ",
|
|
|
|
"GtkRadioAction ",
|
|
|
|
"GtkActionClass ",
|
|
|
|
"GtkToggleActionEntry ",
|
|
|
|
"GtkAssistant ",
|
|
|
|
"GtkBuilder ",
|
|
|
|
"GtkSizeGroup ",
|
|
|
|
"GtkTreeModel ",
|
|
|
|
"GtkTreeSelection ",
|
|
|
|
"GdkDisplay ",
|
|
|
|
"GdkScreen ",
|
2018-03-20 10:40:08 +00:00
|
|
|
"GdkSurface ",
|
2008-07-06 07:24:02 +00:00
|
|
|
"GdkEventButton ",
|
|
|
|
"GdkCursor ",
|
|
|
|
"GtkTreeIter ",
|
|
|
|
"GtkTreeViewColumn ",
|
|
|
|
"GdkDisplayManager ",
|
2017-12-02 13:39:37 +00:00
|
|
|
"GdkClipboard ",
|
2008-07-06 07:24:02 +00:00
|
|
|
"GtkIconSize ",
|
|
|
|
"GtkImage ",
|
|
|
|
"GdkDragContext ",
|
|
|
|
"GtkSelectionData ",
|
|
|
|
"GtkDialog ",
|
|
|
|
"GtkMenuItem ",
|
|
|
|
"GtkListStore ",
|
|
|
|
"GtkCellLayout ",
|
|
|
|
"GtkCellRenderer ",
|
|
|
|
"GtkTreePath ",
|
|
|
|
"GtkTreeStore ",
|
|
|
|
"GtkEntry ",
|
|
|
|
"GtkEditable ",
|
2010-09-11 02:12:42 +00:00
|
|
|
"GtkEditableInterface ",
|
2008-07-06 07:24:02 +00:00
|
|
|
"GdkPixmap ",
|
|
|
|
"GdkEventConfigure ",
|
|
|
|
"GdkEventMotion ",
|
|
|
|
"GdkModifierType ",
|
|
|
|
"GtkEntryCompletion ",
|
|
|
|
"GtkToolItem ",
|
|
|
|
"GDir ",
|
|
|
|
"GtkIconView ",
|
|
|
|
"GtkCellRendererText ",
|
|
|
|
"GtkContainer ",
|
|
|
|
"GtkAccelGroup ",
|
|
|
|
"GtkPaned ",
|
|
|
|
"GtkPrintOperation ",
|
|
|
|
"GtkPrintContext ",
|
|
|
|
"cairo_t ",
|
|
|
|
"PangoLayout "
|
|
|
|
"PangoFontDescription ",
|
|
|
|
"PangoRenderer ",
|
|
|
|
"PangoMatrix ",
|
|
|
|
"PangoContext ",
|
|
|
|
"PangoLayout ",
|
|
|
|
"GtkToggleButton ",
|
|
|
|
"GString ",
|
|
|
|
"GtkIconSize ",
|
|
|
|
"GtkTreeView ",
|
|
|
|
"GtkTextTag ",
|
|
|
|
"GdkEvent ",
|
|
|
|
"GdkEventKey ",
|
|
|
|
"GtkTextView ",
|
|
|
|
"GdkBitmap ",
|
|
|
|
"GtkTextChildAnchor ",
|
|
|
|
"GArray ",
|
|
|
|
"GtkCellEditable ",
|
|
|
|
"GtkCellRendererToggle ",
|
2001-05-18 16:28:30 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static gchar *control[] =
|
|
|
|
{
|
|
|
|
" if ",
|
|
|
|
" while ",
|
|
|
|
" else",
|
|
|
|
" do ",
|
|
|
|
" for ",
|
|
|
|
"?",
|
|
|
|
":",
|
|
|
|
"return ",
|
|
|
|
"goto ",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
void
|
|
|
|
parse_chars (gchar *text,
|
2011-09-02 03:55:47 +00:00
|
|
|
gchar **end_ptr,
|
|
|
|
gint *state,
|
|
|
|
gchar **tag,
|
|
|
|
gboolean start)
|
2001-05-18 16:28:30 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
gchar *next_token;
|
|
|
|
|
|
|
|
/* Handle comments first */
|
|
|
|
if (*state == STATE_IN_COMMENT)
|
|
|
|
{
|
|
|
|
*end_ptr = strstr (text, "*/");
|
|
|
|
if (*end_ptr)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
*end_ptr += 2;
|
|
|
|
*state = STATE_NORMAL;
|
|
|
|
*tag = "comment";
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*tag = NULL;
|
|
|
|
*end_ptr = NULL;
|
|
|
|
|
|
|
|
/* check for comment */
|
|
|
|
if (!strncmp (text, "/*", 2))
|
|
|
|
{
|
|
|
|
*end_ptr = strstr (text, "*/");
|
|
|
|
if (*end_ptr)
|
2011-09-02 03:55:47 +00:00
|
|
|
*end_ptr += 2;
|
2001-05-18 16:28:30 +00:00
|
|
|
else
|
2011-09-02 03:55:47 +00:00
|
|
|
*state = STATE_IN_COMMENT;
|
2001-05-18 16:28:30 +00:00
|
|
|
*tag = "comment";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for preprocessor defines */
|
|
|
|
if (*text == '#' && start)
|
|
|
|
{
|
|
|
|
*end_ptr = NULL;
|
|
|
|
*tag = "preprocessor";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* functions */
|
|
|
|
if (start && * text != '\t' && *text != ' ' && *text != '{' && *text != '}')
|
|
|
|
{
|
|
|
|
if (strstr (text, "("))
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
*end_ptr = strstr (text, "(");
|
|
|
|
*tag = "function";
|
|
|
|
return;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
/* check for types */
|
|
|
|
for (i = 0; types[i] != NULL; i++)
|
2008-07-06 07:24:02 +00:00
|
|
|
if (!strncmp (text, types[i], strlen (types[i])) ||
|
|
|
|
(start && types[i][0] == ' ' && !strncmp (text, types[i] + 1, strlen (types[i]) - 1)))
|
2001-05-18 16:28:30 +00:00
|
|
|
{
|
2011-09-02 03:55:47 +00:00
|
|
|
*end_ptr = text + strlen (types[i]);
|
|
|
|
*tag = "type";
|
|
|
|
return;
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for control */
|
|
|
|
for (i = 0; control[i] != NULL; i++)
|
|
|
|
if (!strncmp (text, control[i], strlen (control[i])))
|
|
|
|
{
|
2011-09-02 03:55:47 +00:00
|
|
|
*end_ptr = text + strlen (control[i]);
|
|
|
|
*tag = "control";
|
|
|
|
return;
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for string */
|
|
|
|
if (text[0] == '"')
|
|
|
|
{
|
|
|
|
gint maybe_escape = FALSE;
|
|
|
|
|
|
|
|
*end_ptr = text + 1;
|
|
|
|
*tag = "string";
|
|
|
|
while (**end_ptr != '\000')
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
if (**end_ptr == '\"' && !maybe_escape)
|
|
|
|
{
|
|
|
|
*end_ptr += 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (**end_ptr == '\\')
|
|
|
|
maybe_escape = TRUE;
|
|
|
|
else
|
|
|
|
maybe_escape = FALSE;
|
|
|
|
*end_ptr += 1;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not at the start of a tag. Find the next one. */
|
|
|
|
for (i = 0; tokens[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
next_token = strstr (text, tokens[i]);
|
|
|
|
if (next_token)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
if (*end_ptr)
|
|
|
|
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
|
|
|
else
|
|
|
|
*end_ptr = next_token;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; types[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
next_token = strstr (text, types[i]);
|
|
|
|
if (next_token)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
if (*end_ptr)
|
|
|
|
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
|
|
|
else
|
|
|
|
*end_ptr = next_token;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; control[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
next_token = strstr (text, control[i]);
|
|
|
|
if (next_token)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
if (*end_ptr)
|
|
|
|
*end_ptr = (*end_ptr<next_token)?*end_ptr:next_token;
|
|
|
|
else
|
|
|
|
*end_ptr = next_token;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* While not as cool as c-mode, this will do as a quick attempt at highlighting */
|
|
|
|
static void
|
2013-02-26 14:55:29 +00:00
|
|
|
fontify (GtkTextBuffer *source_buffer)
|
2001-05-18 16:28:30 +00:00
|
|
|
{
|
|
|
|
GtkTextIter start_iter, next_iter, tmp_iter;
|
|
|
|
gint state;
|
|
|
|
gchar *text;
|
|
|
|
gchar *start_ptr, *end_ptr;
|
|
|
|
gchar *tag;
|
|
|
|
|
2016-02-14 15:49:22 +00:00
|
|
|
gtk_text_buffer_create_tag (source_buffer, "source",
|
|
|
|
"font", "monospace",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "comment",
|
|
|
|
"foreground", "DodgerBlue",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "type",
|
|
|
|
"foreground", "ForestGreen",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "string",
|
|
|
|
"foreground", "RosyBrown",
|
|
|
|
"weight", PANGO_WEIGHT_BOLD,
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "control",
|
|
|
|
"foreground", "purple",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "preprocessor",
|
|
|
|
"style", PANGO_STYLE_OBLIQUE,
|
|
|
|
"foreground", "burlywood4",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_create_tag (source_buffer, "function",
|
|
|
|
"weight", PANGO_WEIGHT_BOLD,
|
|
|
|
"foreground", "DarkGoldenrod4",
|
|
|
|
NULL);
|
|
|
|
|
2014-06-10 22:47:49 +00:00
|
|
|
gtk_text_buffer_get_bounds (source_buffer, &start_iter, &tmp_iter);
|
|
|
|
gtk_text_buffer_apply_tag_by_name (source_buffer, "source", &start_iter, &tmp_iter);
|
|
|
|
|
2001-05-18 16:28:30 +00:00
|
|
|
state = STATE_NORMAL;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_offset (source_buffer, &start_iter, 0);
|
|
|
|
|
|
|
|
next_iter = start_iter;
|
|
|
|
while (gtk_text_iter_forward_line (&next_iter))
|
|
|
|
{
|
|
|
|
gboolean start = TRUE;
|
|
|
|
start_ptr = text = gtk_text_iter_get_text (&start_iter, &next_iter);
|
|
|
|
|
|
|
|
do
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
parse_chars (start_ptr, &end_ptr, &state, &tag, start);
|
|
|
|
|
|
|
|
start = FALSE;
|
|
|
|
if (end_ptr)
|
|
|
|
{
|
|
|
|
tmp_iter = start_iter;
|
|
|
|
gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp_iter = next_iter;
|
|
|
|
}
|
|
|
|
if (tag)
|
|
|
|
gtk_text_buffer_apply_tag_by_name (source_buffer, tag, &start_iter, &tmp_iter);
|
|
|
|
|
|
|
|
start_iter = tmp_iter;
|
|
|
|
start_ptr = end_ptr;
|
|
|
|
}
|
2001-05-18 16:28:30 +00:00
|
|
|
while (end_ptr);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
start_iter = next_iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 22:42:17 +00:00
|
|
|
static GtkWidget *
|
|
|
|
display_image (const char *resource)
|
|
|
|
{
|
|
|
|
GtkWidget *sw, *image;
|
|
|
|
|
|
|
|
image = gtk_image_new_from_resource (resource);
|
|
|
|
gtk_widget_set_halign (image, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (image, GTK_ALIGN_CENTER);
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (sw), image);
|
|
|
|
|
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
display_text (const char *resource)
|
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkWidget *textview, *sw;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
bytes = g_resources_lookup_data (resource, 0, NULL);
|
|
|
|
g_assert (bytes);
|
|
|
|
|
|
|
|
g_assert (g_utf8_validate (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), NULL));
|
|
|
|
|
|
|
|
textview = gtk_text_view_new ();
|
|
|
|
g_object_set (textview,
|
|
|
|
"left-margin", 20,
|
|
|
|
"right-margin", 20,
|
|
|
|
"top-margin", 20,
|
|
|
|
"bottom-margin", 20,
|
|
|
|
NULL);
|
|
|
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE);
|
|
|
|
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE);
|
|
|
|
/* Make it a bit nicer for text. */
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD);
|
|
|
|
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (textview), 2);
|
|
|
|
gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (textview), 2);
|
|
|
|
|
|
|
|
buffer = gtk_text_buffer_new (NULL);
|
|
|
|
gtk_text_buffer_set_text (buffer, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes));
|
|
|
|
if (g_str_has_suffix (resource, ".c"))
|
|
|
|
fontify (buffer);
|
|
|
|
gtk_text_view_set_buffer (GTK_TEXT_VIEW (textview), buffer);
|
|
|
|
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_SHADOW_NONE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (sw), textview);
|
|
|
|
|
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
display_video (const char *resource)
|
|
|
|
{
|
|
|
|
GtkWidget *video;
|
|
|
|
|
|
|
|
video = gtk_video_new_for_resource (resource);
|
|
|
|
gtk_video_set_loop (GTK_VIDEO (video), TRUE);
|
|
|
|
|
|
|
|
return video;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
display_nothing (const char *resource)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = g_strdup_printf ("The lazy GTK developers forgot to add a way to display the resource '%s'", resource);
|
|
|
|
widget = gtk_label_new (str);
|
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char *extension;
|
|
|
|
GtkWidget * (* display_func) (const char *resource);
|
|
|
|
} display_funcs[] = {
|
|
|
|
{ ".gif", display_image },
|
|
|
|
{ ".jpg", display_image },
|
|
|
|
{ ".png", display_image },
|
|
|
|
{ ".c", display_text },
|
|
|
|
{ ".css", display_text },
|
|
|
|
{ ".glsl", display_text },
|
|
|
|
{ ".h", display_text },
|
|
|
|
{ ".txt", display_text },
|
|
|
|
{ ".ui", display_text },
|
|
|
|
{ ".webm", display_video }
|
|
|
|
};
|
2012-05-18 04:48:57 +00:00
|
|
|
|
|
|
|
static void
|
2013-02-01 17:21:56 +00:00
|
|
|
add_data_tab (const gchar *demoname)
|
2012-05-18 04:48:57 +00:00
|
|
|
{
|
2014-08-26 02:18:52 +00:00
|
|
|
gchar *resource_dir, *resource_name;
|
2013-02-01 17:21:56 +00:00
|
|
|
gchar **resources;
|
2012-05-18 04:48:57 +00:00
|
|
|
GtkWidget *widget, *label;
|
2018-04-05 22:42:17 +00:00
|
|
|
guint i, j;
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2013-02-01 17:21:56 +00:00
|
|
|
resource_dir = g_strconcat ("/", demoname, NULL);
|
|
|
|
resources = g_resources_enumerate_children (resource_dir, 0, NULL);
|
|
|
|
if (resources == NULL)
|
|
|
|
{
|
|
|
|
g_free (resource_dir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; resources[i]; i++)
|
|
|
|
{
|
|
|
|
resource_name = g_strconcat (resource_dir, "/", resources[i], NULL);
|
2013-02-26 14:55:29 +00:00
|
|
|
|
2018-04-05 22:42:17 +00:00
|
|
|
for (j = 0; j < G_N_ELEMENTS(display_funcs); j++)
|
2013-02-01 17:21:56 +00:00
|
|
|
{
|
2018-04-05 22:42:17 +00:00
|
|
|
if (g_str_has_suffix (resource_name, display_funcs[j].extension))
|
|
|
|
break;
|
2013-02-01 17:21:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 22:42:17 +00:00
|
|
|
if (j < G_N_ELEMENTS(display_funcs))
|
|
|
|
widget = display_funcs[j].display_func (resource_name);
|
|
|
|
else
|
|
|
|
widget = display_nothing (resource_name);
|
2017-10-07 01:59:34 +00:00
|
|
|
|
2013-02-01 17:21:56 +00:00
|
|
|
label = gtk_label_new (resources[i]);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
|
2013-12-03 01:02:56 +00:00
|
|
|
gtk_container_child_set (GTK_CONTAINER (notebook),
|
2018-04-05 22:42:17 +00:00
|
|
|
widget,
|
2013-12-03 01:02:56 +00:00
|
|
|
"tab-expand", TRUE,
|
|
|
|
NULL);
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2013-02-01 17:21:56 +00:00
|
|
|
g_free (resource_name);
|
|
|
|
}
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2013-02-01 17:21:56 +00:00
|
|
|
g_strfreev (resources);
|
|
|
|
g_free (resource_dir);
|
2012-05-18 04:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_data_tabs (void)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) - 1; i > 1; i--)
|
|
|
|
gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), i);
|
|
|
|
}
|
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
void
|
2013-01-30 22:16:16 +00:00
|
|
|
load_file (const gchar *demoname,
|
|
|
|
const gchar *filename)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2013-02-26 14:55:29 +00:00
|
|
|
GtkTextBuffer *info_buffer, *source_buffer;
|
2000-10-18 15:50:13 +00:00
|
|
|
GtkTextIter start, end;
|
2013-01-29 13:51:06 +00:00
|
|
|
char *resource_filename;
|
2001-11-23 21:46:44 +00:00
|
|
|
GError *err = NULL;
|
2000-10-18 15:50:13 +00:00
|
|
|
int state = 0;
|
|
|
|
gboolean in_para = 0;
|
2013-02-01 17:56:10 +00:00
|
|
|
gchar **lines;
|
2013-01-29 13:51:06 +00:00
|
|
|
GBytes *bytes;
|
2012-05-18 04:48:57 +00:00
|
|
|
gint i;
|
|
|
|
|
2013-02-01 17:56:10 +00:00
|
|
|
if (!g_strcmp0 (current_file, filename))
|
|
|
|
return;
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2013-02-01 17:56:10 +00:00
|
|
|
remove_data_tabs ();
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2013-02-01 17:21:56 +00:00
|
|
|
add_data_tab (demoname);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_free (current_file);
|
2013-02-01 17:56:10 +00:00
|
|
|
current_file = g_strdup (filename);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-02-26 14:55:29 +00:00
|
|
|
info_buffer = gtk_text_buffer_new (NULL);
|
|
|
|
gtk_text_buffer_create_tag (info_buffer, "title",
|
|
|
|
"font", "Sans 18",
|
|
|
|
"pixels-below-lines", 10,
|
|
|
|
NULL);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2013-02-26 14:55:29 +00:00
|
|
|
source_buffer = gtk_text_buffer_new (NULL);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2013-02-01 17:56:10 +00:00
|
|
|
resource_filename = g_strconcat ("/sources/", filename, NULL);
|
2013-01-29 13:51:06 +00:00
|
|
|
bytes = g_resources_lookup_data (resource_filename, 0, &err);
|
|
|
|
g_free (resource_filename);
|
2001-11-23 21:46:44 +00:00
|
|
|
|
2013-01-29 13:51:06 +00:00
|
|
|
if (bytes == NULL)
|
2013-01-29 13:08:47 +00:00
|
|
|
{
|
2016-02-28 17:18:36 +00:00
|
|
|
g_warning ("Cannot open source for %s: %s", filename, err->message);
|
2013-01-29 13:08:47 +00:00
|
|
|
g_error_free (err);
|
2013-02-01 17:56:10 +00:00
|
|
|
return;
|
2013-01-29 13:08:47 +00:00
|
|
|
}
|
2000-11-13 04:36:38 +00:00
|
|
|
|
2013-01-29 13:51:06 +00:00
|
|
|
lines = g_strsplit (g_bytes_get_data (bytes, NULL), "\n", -1);
|
|
|
|
g_bytes_unref (bytes);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0);
|
2013-01-29 13:08:47 +00:00
|
|
|
for (i = 0; lines[i] != NULL; i++)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2013-01-29 13:08:47 +00:00
|
|
|
gchar *p;
|
2000-10-18 15:50:13 +00:00
|
|
|
gchar *q;
|
2001-10-02 18:54:05 +00:00
|
|
|
gchar *r;
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-01-29 13:08:47 +00:00
|
|
|
/* Make sure \r is stripped at the end for the poor windows people */
|
|
|
|
lines[i] = g_strchomp (lines[i]);
|
|
|
|
|
|
|
|
p = lines[i];
|
2000-10-18 15:50:13 +00:00
|
|
|
switch (state)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* Reading title */
|
|
|
|
while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
|
|
|
|
p++;
|
|
|
|
r = p;
|
2012-05-26 00:39:59 +00:00
|
|
|
while (*r != '\0')
|
|
|
|
{
|
|
|
|
while (*r != '/' && *r != ':' && *r != '\0')
|
|
|
|
r++;
|
|
|
|
if (*r == '/')
|
|
|
|
{
|
|
|
|
r++;
|
|
|
|
p = r;
|
|
|
|
}
|
|
|
|
if (r[0] == ':' && r[1] == ':')
|
|
|
|
*r = '\0';
|
|
|
|
}
|
2011-09-02 03:55:47 +00:00
|
|
|
q = p + strlen (p);
|
|
|
|
while (q > p && g_ascii_isspace (*(q - 1)))
|
|
|
|
q--;
|
|
|
|
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
if (q > p)
|
|
|
|
{
|
|
|
|
int len_chars = g_utf8_pointer_to_offset (p, q);
|
|
|
|
|
|
|
|
end = start;
|
|
|
|
|
|
|
|
g_assert (strlen (p) >= q - p);
|
|
|
|
gtk_text_buffer_insert (info_buffer, &end, p, q - p);
|
|
|
|
start = end;
|
|
|
|
|
|
|
|
gtk_text_iter_backward_chars (&start, len_chars);
|
|
|
|
gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);
|
|
|
|
|
|
|
|
start = end;
|
|
|
|
|
2012-05-23 17:39:47 +00:00
|
|
|
while (*p && *p != '\n') p++;
|
2012-05-18 04:48:57 +00:00
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
state++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* Reading body of info section */
|
|
|
|
while (g_ascii_isspace (*p))
|
|
|
|
p++;
|
|
|
|
if (*p == '*' && *(p + 1) == '/')
|
|
|
|
{
|
|
|
|
gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
while (*p == '*' || g_ascii_isspace (*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
len = strlen (p);
|
|
|
|
while (g_ascii_isspace (*(p + len - 1)))
|
|
|
|
len--;
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
if (in_para)
|
|
|
|
gtk_text_buffer_insert (info_buffer, &start, " ", 1);
|
|
|
|
|
|
|
|
g_assert (strlen (p) >= len);
|
|
|
|
gtk_text_buffer_insert (info_buffer, &start, p, len);
|
|
|
|
in_para = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
|
|
|
|
in_para = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
/* Skipping blank lines */
|
|
|
|
while (g_ascii_isspace (*p))
|
|
|
|
p++;
|
2018-10-12 21:09:42 +00:00
|
|
|
|
|
|
|
if (!*p)
|
2011-09-02 03:55:47 +00:00
|
|
|
break;
|
|
|
|
|
2018-10-12 21:09:42 +00:00
|
|
|
p = lines[i];
|
|
|
|
state++;
|
|
|
|
/* Fall through */
|
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
case 3:
|
|
|
|
/* Reading program body */
|
|
|
|
gtk_text_buffer_insert (source_buffer, &start, p, -1);
|
2014-11-12 21:05:49 +00:00
|
|
|
if (lines[i+1] != NULL)
|
|
|
|
gtk_text_buffer_insert (source_buffer, &start, "\n", 1);
|
2011-09-02 03:55:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-12 21:05:49 +00:00
|
|
|
g_strfreev (lines);
|
|
|
|
|
2013-02-26 14:55:29 +00:00
|
|
|
fontify (source_buffer);
|
2001-02-13 05:44:47 +00:00
|
|
|
|
2013-02-26 14:55:29 +00:00
|
|
|
gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), source_buffer);
|
|
|
|
g_object_unref (source_buffer);
|
2014-11-12 21:05:49 +00:00
|
|
|
|
|
|
|
gtk_text_view_set_buffer (GTK_TEXT_VIEW (info_view), info_buffer);
|
|
|
|
g_object_unref (info_buffer);
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static void
|
|
|
|
selection_cb (GtkTreeSelection *selection,
|
2011-09-02 03:55:47 +00:00
|
|
|
GtkTreeModel *model)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
2013-12-03 01:35:57 +00:00
|
|
|
char *name;
|
|
|
|
char *filename;
|
|
|
|
char *title;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
|
2000-10-26 00:36:47 +00:00
|
|
|
return;
|
|
|
|
|
2013-01-30 22:16:16 +00:00
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
NAME_COLUMN, &name,
|
2013-12-03 01:35:57 +00:00
|
|
|
TITLE_COLUMN, &title,
|
2013-01-30 22:16:16 +00:00
|
|
|
FILENAME_COLUMN, &filename,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
load_file (name, filename);
|
|
|
|
|
2013-12-03 01:35:57 +00:00
|
|
|
gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), title);
|
|
|
|
|
2013-01-30 22:16:16 +00:00
|
|
|
g_free (name);
|
2013-12-03 01:35:57 +00:00
|
|
|
g_free (title);
|
2013-01-30 22:16:16 +00:00
|
|
|
g_free (filename);
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
static void
|
|
|
|
populate_model (GtkTreeModel *model)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
2012-01-14 23:22:33 +00:00
|
|
|
Demo *d = gtk_demos;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
/* this code only supports 1 level of children. If we
|
|
|
|
* want more we probably have to use a recursing function.
|
|
|
|
*/
|
|
|
|
while (d->title)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
2001-10-02 18:54:05 +00:00
|
|
|
Demo *children = d->children;
|
2013-12-03 00:42:04 +00:00
|
|
|
GtkTreeIter iter;
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
|
|
|
|
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
2011-09-02 03:55:47 +00:00
|
|
|
&iter,
|
2013-01-30 22:16:16 +00:00
|
|
|
NAME_COLUMN, d->name,
|
2011-09-02 03:55:47 +00:00
|
|
|
TITLE_COLUMN, d->title,
|
|
|
|
FILENAME_COLUMN, d->filename,
|
|
|
|
FUNC_COLUMN, d->func,
|
|
|
|
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
|
|
|
-1);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
d++;
|
|
|
|
|
|
|
|
if (!children)
|
2011-09-02 03:55:47 +00:00
|
|
|
continue;
|
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
while (children->title)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
|
|
|
|
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
|
|
|
&child_iter,
|
2013-01-30 22:16:16 +00:00
|
|
|
NAME_COLUMN, children->name,
|
2011-09-02 03:55:47 +00:00
|
|
|
TITLE_COLUMN, children->title,
|
|
|
|
FILENAME_COLUMN, children->filename,
|
|
|
|
FUNC_COLUMN, children->func,
|
|
|
|
STYLE_COLUMN, PANGO_STYLE_NORMAL,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
children++;
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
}
|
remove validation idle
2001-02-08 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (gtk_text_view_destroy_layout): remove
validation idle
* demos/gtk-demo/main.c (create_tree): adjust to changes in text
cell renderer
* demos/pixbuf-demo.c (timeout): remove deprecated
gtk_widget_draw
* demos/testpixbuf-save.c (main): remove deprecated
gtk_drawing_area_size
* gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate
buttons even if the model isn't setup. gtk_tree_view_check_dirty()
at the start of the allocation.
(gtk_tree_view_check_dirty): handle column->button == NULL, handle
unsetup or NULL model.
* gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the
even/odd/sorted cells in the tree view.
* gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all):
bugfixes
* gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row
backgrounds with draw_flat_box using different detail for even/odd
rows.
* gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each
row, so we can draw the alternating colors thing
* gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a
property from a synonym property, notify for the synonym.
Also, nuke the background_gdk_set and foreground_gdk_set synonyms
(gtk_text_tag_get_property): Always return the font, even if
all its fields aren't set
* gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't
store the attr list; it leaves us with no way to change attributes
in _render according to the render flags, and no way to implement
get_property. Instead store all the specific text attributes.
Separate whether an attribute is enabled from its value. Sync all
properties with GtkTextTag, make them all consistent, etc.
* gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so
renderers can highlight the sort row/column
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use
accessor functions to get values; this has the side effect of
showing up which accessor functions were missing. Added those.
* gtk/gtktreeviewcolumn.h: Replace set_justification with
set_alignment, to be consistent with GtkLabel, GtkMisc
* gtk/gtktreeviewcolumn.c: Added code to display sort indicator
arrow.
* gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h
* gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
static void
|
|
|
|
startup (GApplication *app)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GMenuModel *appmenu;
|
2014-09-26 03:57:34 +00:00
|
|
|
gchar *ids[] = { "appmenu", NULL };
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
builder = gtk_builder_new ();
|
2016-02-28 04:43:06 +00:00
|
|
|
gtk_builder_add_objects_from_resource (builder, "/ui/appmenu.ui", ids, NULL);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
appmenu = (GMenuModel *)gtk_builder_get_object (builder, "appmenu");
|
2005-06-28 03:42:55 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
gtk_application_set_app_menu (GTK_APPLICATION (app), appmenu);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
g_object_unref (builder);
|
|
|
|
}
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-12-13 15:01:18 +00:00
|
|
|
static void
|
|
|
|
row_activated_cb (GtkWidget *tree_view,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *column)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
window = gtk_widget_get_toplevel (tree_view);
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
|
|
|
run_example_for_row (window, model, &iter);
|
|
|
|
}
|
|
|
|
|
2015-07-29 03:48:10 +00:00
|
|
|
static void
|
|
|
|
start_cb (GtkMenuItem *item, GtkWidget *scrollbar)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
2017-10-07 23:54:47 +00:00
|
|
|
adj = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (scrollbar));
|
2015-07-29 03:48:10 +00:00
|
|
|
gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
end_cb (GtkMenuItem *item, GtkWidget *scrollbar)
|
|
|
|
{
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
|
2017-10-07 23:54:47 +00:00
|
|
|
adj = gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (scrollbar));
|
2015-07-29 03:48:10 +00:00
|
|
|
gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
scrollbar_popup (GtkWidget *scrollbar, GtkWidget *menu)
|
|
|
|
{
|
2016-07-12 18:08:36 +00:00
|
|
|
gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
|
2015-07-29 03:48:10 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
static void
|
|
|
|
activate (GApplication *app)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GtkWindow *window;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GError *error = NULL;
|
2015-07-29 03:48:10 +00:00
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *scrollbar;
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
|
|
|
|
2013-12-03 01:35:57 +00:00
|
|
|
static GActionEntry win_entries[] = {
|
|
|
|
{ "run", activate_run, NULL, NULL, NULL }
|
|
|
|
};
|
2005-06-28 03:42:55 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
builder = gtk_builder_new ();
|
|
|
|
gtk_builder_add_from_resource (builder, "/ui/main.ui", &error);
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_critical ("%s", error->message);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
window = (GtkWindow *)gtk_builder_get_object (builder, "window");
|
|
|
|
gtk_application_add_window (GTK_APPLICATION (app), window);
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (window),
|
|
|
|
win_entries, G_N_ELEMENTS (win_entries),
|
|
|
|
window);
|
|
|
|
|
|
|
|
notebook = (GtkWidget *)gtk_builder_get_object (builder, "notebook");
|
2005-06-28 03:42:55 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
info_view = (GtkWidget *)gtk_builder_get_object (builder, "info-textview");
|
|
|
|
source_view = (GtkWidget *)gtk_builder_get_object (builder, "source-textview");
|
2013-12-03 01:35:57 +00:00
|
|
|
headerbar = (GtkWidget *)gtk_builder_get_object (builder, "headerbar");
|
2013-12-03 00:42:04 +00:00
|
|
|
treeview = (GtkWidget *)gtk_builder_get_object (builder, "treeview");
|
|
|
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
|
|
|
|
|
2015-07-29 03:48:10 +00:00
|
|
|
sw = (GtkWidget *)gtk_builder_get_object (builder, "source-scrolledwindow");
|
|
|
|
scrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
|
|
|
|
|
|
|
|
menu = gtk_menu_new ();
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label ("Start");
|
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (start_cb), scrollbar);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_label ("End");
|
|
|
|
g_signal_connect (item, "activate", G_CALLBACK (end_cb), scrollbar);
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
|
|
|
|
|
|
|
|
g_signal_connect (scrollbar, "popup-menu", G_CALLBACK (scrollbar_popup), menu);
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
load_file (gtk_demos[0].name, gtk_demos[0].filename);
|
2005-06-28 03:42:55 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
populate_model (model);
|
2005-06-28 03:42:55 +00:00
|
|
|
|
2013-12-13 15:01:18 +00:00
|
|
|
g_signal_connect (treeview, "row-activated", G_CALLBACK (row_activated_cb), model);
|
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
widget = (GtkWidget *)gtk_builder_get_object (builder, "treeview-selection");
|
|
|
|
g_signal_connect (widget, "changed", G_CALLBACK (selection_cb), model);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter_first (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)), &iter);
|
|
|
|
gtk_tree_selection_select_iter (GTK_TREE_SELECTION (widget), &iter);
|
|
|
|
|
|
|
|
gtk_tree_view_collapse_all (GTK_TREE_VIEW (treeview));
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (window));
|
2013-12-03 00:42:04 +00:00
|
|
|
|
|
|
|
g_object_unref (builder);
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 02:36:00 +00:00
|
|
|
static gboolean
|
|
|
|
auto_quit (gpointer data)
|
|
|
|
{
|
|
|
|
g_application_quit (G_APPLICATION (data));
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2015-09-09 14:14:17 +00:00
|
|
|
static void
|
|
|
|
list_demos (void)
|
|
|
|
{
|
|
|
|
Demo *d, *c;
|
|
|
|
|
|
|
|
d = gtk_demos;
|
|
|
|
|
|
|
|
while (d->title)
|
|
|
|
{
|
|
|
|
c = d->children;
|
|
|
|
if (d->name)
|
|
|
|
g_print ("%s\n", d->name);
|
|
|
|
d++;
|
|
|
|
while (c && c->title)
|
|
|
|
{
|
|
|
|
if (c->name)
|
|
|
|
g_print ("%s\n", c->name);
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 10:28:51 +00:00
|
|
|
static gint
|
2015-09-06 02:36:00 +00:00
|
|
|
command_line (GApplication *app,
|
|
|
|
GApplicationCommandLine *cmdline)
|
|
|
|
{
|
|
|
|
GVariantDict *options;
|
|
|
|
const gchar *name = NULL;
|
2015-09-09 12:07:20 +00:00
|
|
|
gboolean autoquit = FALSE;
|
2015-09-09 14:14:17 +00:00
|
|
|
gboolean list = FALSE;
|
2015-09-06 02:36:00 +00:00
|
|
|
Demo *d, *c;
|
|
|
|
GDoDemoFunc func = 0;
|
|
|
|
GtkWidget *window, *demo;
|
|
|
|
|
|
|
|
activate (app);
|
|
|
|
|
|
|
|
options = g_application_command_line_get_options_dict (cmdline);
|
|
|
|
g_variant_dict_lookup (options, "run", "&s", &name);
|
2015-09-09 12:07:20 +00:00
|
|
|
g_variant_dict_lookup (options, "autoquit", "b", &autoquit);
|
2015-09-09 14:14:17 +00:00
|
|
|
g_variant_dict_lookup (options, "list", "b", &list);
|
|
|
|
|
|
|
|
if (list)
|
|
|
|
{
|
|
|
|
list_demos ();
|
|
|
|
g_application_quit (app);
|
2015-09-28 10:28:51 +00:00
|
|
|
return 0;
|
2015-09-09 14:14:17 +00:00
|
|
|
}
|
2015-09-06 02:36:00 +00:00
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
window = gtk_application_get_windows (GTK_APPLICATION (app))->data;
|
|
|
|
|
|
|
|
d = gtk_demos;
|
|
|
|
|
|
|
|
while (d->title)
|
|
|
|
{
|
|
|
|
c = d->children;
|
|
|
|
if (g_strcmp0 (d->name, name) == 0)
|
|
|
|
{
|
|
|
|
func = d->func;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
d++;
|
|
|
|
while (c && c->title)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (c->name, name) == 0)
|
|
|
|
{
|
|
|
|
func = c->func;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (func)
|
|
|
|
{
|
|
|
|
demo = (func) (window);
|
|
|
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (demo), GTK_WINDOW (window));
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (demo), TRUE);
|
|
|
|
}
|
|
|
|
|
2015-09-09 12:07:20 +00:00
|
|
|
if (autoquit)
|
|
|
|
g_timeout_add_seconds (1, auto_quit, app);
|
2015-09-28 10:28:51 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-09-06 02:36:00 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 15:04:40 +00:00
|
|
|
static void
|
|
|
|
print_version (void)
|
|
|
|
{
|
|
|
|
g_print ("gtk3-demo %d.%d.%d\n",
|
|
|
|
gtk_get_major_version (),
|
|
|
|
gtk_get_minor_version (),
|
|
|
|
gtk_get_micro_version ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
local_options (GApplication *app,
|
|
|
|
GVariantDict *options,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean version = FALSE;
|
|
|
|
|
|
|
|
g_variant_dict_lookup (options, "version", "b", &version);
|
|
|
|
|
|
|
|
if (version)
|
|
|
|
{
|
|
|
|
print_version ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-10-18 15:50:13 +00:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2013-12-03 00:42:04 +00:00
|
|
|
GtkApplication *app;
|
|
|
|
static GActionEntry app_entries[] = {
|
|
|
|
{ "about", activate_about, NULL, NULL, NULL },
|
|
|
|
{ "quit", activate_quit, NULL, NULL, NULL },
|
|
|
|
};
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2001-05-07 15:58:47 +00:00
|
|
|
/* Most code in gtk-demo is intended to be exemplary, but not
|
|
|
|
* these few lines, which are just a hack so gtk-demo will work
|
|
|
|
* in the GTK tree without installing it.
|
|
|
|
*/
|
2012-01-14 23:22:33 +00:00
|
|
|
if (g_file_test ("../../modules/input/immodules.cache", G_FILE_TEST_EXISTS))
|
2001-05-07 15:58:47 +00:00
|
|
|
{
|
2010-05-18 23:23:06 +00:00
|
|
|
g_setenv ("GTK_IM_MODULE_FILE", "../../modules/input/immodules.cache", TRUE);
|
2001-05-07 15:58:47 +00:00
|
|
|
}
|
|
|
|
/* -- End of hack -- */
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2015-09-06 02:36:00 +00:00
|
|
|
app = gtk_application_new ("org.gtk.Demo", G_APPLICATION_NON_UNIQUE|G_APPLICATION_HANDLES_COMMAND_LINE);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
|
|
|
app_entries, G_N_ELEMENTS (app_entries),
|
|
|
|
app);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2016-09-11 15:04:40 +00:00
|
|
|
g_application_add_main_option (G_APPLICATION (app), "version", 0, 0, G_OPTION_ARG_NONE, "Show program version", NULL);
|
2015-09-06 02:36:00 +00:00
|
|
|
g_application_add_main_option (G_APPLICATION (app), "run", 0, 0, G_OPTION_ARG_STRING, "Run an example", "EXAMPLE");
|
2015-09-09 14:14:17 +00:00
|
|
|
g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", NULL);
|
2015-09-09 12:07:20 +00:00
|
|
|
g_application_add_main_option (G_APPLICATION (app), "autoquit", 0, 0, G_OPTION_ARG_NONE, "Quit after a delay", NULL);
|
2015-09-06 02:36:00 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
g_signal_connect (app, "startup", G_CALLBACK (startup), NULL);
|
|
|
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
2015-09-06 02:36:00 +00:00
|
|
|
g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
|
2016-09-11 15:04:40 +00:00
|
|
|
g_signal_connect (app, "handle-local-options", G_CALLBACK (local_options), NULL);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-12-03 00:42:04 +00:00
|
|
|
g_application_run (G_APPLICATION (app), argc, argv);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|