fixed snapshot command (-s). more needed.
git-svn-id: http://tint2.googlecode.com/svn/trunk@404 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
788cfce122
commit
a26a3e4635
6 changed files with 112 additions and 326 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <pango/pangocairo.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "config.h"
|
||||
#include "window.h"
|
||||
#include "task.h"
|
||||
#include "panel.h"
|
||||
|
@ -190,8 +191,8 @@ void init_panel()
|
|||
//printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
|
||||
set_panel_properties(p);
|
||||
set_panel_background(p);
|
||||
if (i >= old_nb_panel) {
|
||||
// map new panel
|
||||
if (i >= old_nb_panel && snapshot_path == 0) {
|
||||
// if we are not in 'snapshot' mode then map new panel
|
||||
XMapWindow (server.dsp, p->main_win);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "config.h"
|
||||
#include "task.h"
|
||||
#include "window.h"
|
||||
|
||||
|
@ -385,7 +386,7 @@ void server_init_visual()
|
|||
server.colormap32 = XCreateColormap(server.dsp, server.root_win, visual, AllocNone);
|
||||
}
|
||||
|
||||
if (visual && server.composite_manager != None) {
|
||||
if (visual && server.composite_manager != None && snapshot_path == 0) {
|
||||
XSetWindowAttributes attrs;
|
||||
attrs.event_mask = StructureNotifyMask;
|
||||
XChangeWindowAttributes (server.dsp, server.composite_manager, CWEventMask, &attrs);
|
||||
|
@ -397,6 +398,7 @@ void server_init_visual()
|
|||
server.visual = visual;
|
||||
}
|
||||
else {
|
||||
// no composite manager or snapshot mode => fake transparency
|
||||
real_transparency = 0;
|
||||
server.depth = DefaultDepth(server.dsp, server.screen);
|
||||
printf("real transparency off.... depth: %d\n", server.depth);
|
||||
|
|
|
@ -166,7 +166,9 @@ void get_snapshot(const char *path)
|
|||
{
|
||||
Panel *panel = &panel1[0];
|
||||
|
||||
if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
|
||||
if (panel->area.width > server.monitor[0].width)
|
||||
panel->area.width = server.monitor[0].width;
|
||||
|
||||
panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
|
||||
|
||||
refresh(&panel->area);
|
||||
|
|
|
@ -35,9 +35,9 @@
|
|||
|
||||
|
||||
// default config file and directory
|
||||
char *g_path_config = 0;
|
||||
char *g_path_dir = 0;
|
||||
char *g_default_theme = 0;
|
||||
char *g_path_config = NULL;
|
||||
char *g_path_dir = NULL;
|
||||
char *g_default_theme = NULL;
|
||||
int g_width;
|
||||
int g_height;
|
||||
|
||||
|
@ -51,13 +51,13 @@ static void menuAddWidget (GtkUIManager *, GtkWidget *, GtkContainer *);
|
|||
|
||||
// action on menus
|
||||
static void menuAdd (GtkWindow * parent);
|
||||
//static void menuSaveAs (GtkWindow *parent);
|
||||
static void menuSaveAs (GtkWindow *parent);
|
||||
static void menuDelete (void);
|
||||
static void menuProperties (void);
|
||||
static void menuRename (void);
|
||||
static void menuQuit (void);
|
||||
static void menuRefresh (void);
|
||||
static void menuRefreshAll (void);
|
||||
static void menuPreferences (void);
|
||||
static void menuApply (void);
|
||||
static void menuAbout(GtkWindow * parent);
|
||||
|
||||
|
@ -79,32 +79,31 @@ static const char *global_ui =
|
|||
" <menubar name='MenuBar'>"
|
||||
" <menu action='ThemeMenu'>"
|
||||
" <menuitem action='ThemeAdd'/>"
|
||||
// " <menuitem action='ThemeSaveAs'/>"
|
||||
" <menuitem action='ThemeSaveAs'/>"
|
||||
" <separator/>"
|
||||
" <menuitem action='ThemeDelete'/>"
|
||||
" <separator/>"
|
||||
" <menuitem action='ThemeProperties'/>"
|
||||
" <menuitem action='ThemeRename'/>"
|
||||
" <separator/>"
|
||||
" <menuitem action='ThemeQuit'/>"
|
||||
" </menu>"
|
||||
" <menu action='ViewMenu'>"
|
||||
" <menuitem action='ViewRefresh'/>"
|
||||
" <menuitem action='ViewRefreshAll'/>"
|
||||
" <menu action='EditMenu'>"
|
||||
" <menuitem action='EditRefresh'/>"
|
||||
" <menuitem action='EditRefreshAll'/>"
|
||||
// " <separator/>"
|
||||
// " <menuitem action='EditPreferences'/>"
|
||||
" </menu>"
|
||||
" <menu action='HelpMenu'>"
|
||||
" <menuitem action='HelpAbout'/>"
|
||||
" </menu>"
|
||||
" </menubar>"
|
||||
" <toolbar name='ToolBar'>"
|
||||
" <toolitem action='ViewRefreshAll'/>"
|
||||
" <separator/>"
|
||||
" <toolitem action='ThemeProperties'/>"
|
||||
" <toolitem action='ViewApply'/>"
|
||||
" <toolitem action='ThemeProperties'/>"
|
||||
" </toolbar>"
|
||||
" <popup name='ThemePopup'>"
|
||||
" <menuitem action='ViewApply'/>"
|
||||
" <menuitem action='ThemeProperties'/>"
|
||||
" <menuitem action='ThemeRename'/>"
|
||||
" <separator/>"
|
||||
" <menuitem action='ThemeDelete'/>"
|
||||
" </popup>"
|
||||
|
@ -115,14 +114,14 @@ static const char *global_ui =
|
|||
static GtkActionEntry entries[] = {
|
||||
{"ThemeMenu", NULL, "Theme", NULL, NULL, NULL},
|
||||
{"ThemeAdd", GTK_STOCK_ADD, "_Add...", "<Control>N", "Add theme", G_CALLBACK (menuAdd)},
|
||||
// {"ThemeSaveAs", GTK_STOCK_SAVE_AS, "_Save as...", NULL, "Save theme as", G_CALLBACK (menuSaveAs)},
|
||||
{"ThemeSaveAs", GTK_STOCK_SAVE_AS, "_Save as...", NULL, "Save theme as", G_CALLBACK (menuSaveAs)},
|
||||
{"ThemeDelete", GTK_STOCK_DELETE, "_Delete", NULL, "Delete theme", G_CALLBACK (menuDelete)},
|
||||
{"ThemeProperties", GTK_STOCK_PROPERTIES, "_Properties...", NULL, "Show properties", G_CALLBACK (menuProperties)},
|
||||
{"ThemeRename", NULL, "_Rename...", NULL, "Rename theme", G_CALLBACK (menuRename)},
|
||||
{"ThemeQuit", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Quit", G_CALLBACK (menuQuit)},
|
||||
{"ViewMenu", NULL, "View", NULL, NULL, NULL},
|
||||
{"ViewRefresh", GTK_STOCK_REFRESH, "Refresh", NULL, "Refresh", G_CALLBACK (menuRefresh)},
|
||||
{"ViewRefreshAll", GTK_STOCK_REFRESH, "Refresh all", NULL, "Refresh all", G_CALLBACK (menuRefreshAll)},
|
||||
{"EditMenu", NULL, "Edit", NULL, NULL, NULL},
|
||||
{"EditRefresh", GTK_STOCK_REFRESH, "Refresh", NULL, "Refresh", G_CALLBACK (menuRefresh)},
|
||||
{"EditRefreshAll", GTK_STOCK_REFRESH, "Refresh all", NULL, "Refresh all", G_CALLBACK (menuRefreshAll)},
|
||||
// {"EditPreferences", GTK_STOCK_PREFERENCES, "Preferences", NULL, "Preferences", G_CALLBACK (menuPreferences)},
|
||||
{"ViewApply", GTK_STOCK_APPLY, "Apply", NULL, "Apply theme", G_CALLBACK (menuApply)},
|
||||
{"HelpMenu", NULL, "Help", NULL, NULL, NULL},
|
||||
{"HelpAbout", GTK_STOCK_ABOUT, "_About", "<Control>A", "About", G_CALLBACK (menuAbout)}
|
||||
|
@ -161,7 +160,7 @@ int main (int argc, char ** argv)
|
|||
gtk_box_pack_start(GTK_BOX(vBox), scrollbar, TRUE, TRUE, 0);
|
||||
|
||||
// define theme view
|
||||
g_theme_view = create_view_and_model();
|
||||
g_theme_view = create_view();
|
||||
gtk_container_add(GTK_CONTAINER(scrollbar), g_theme_view);
|
||||
gtk_widget_show(g_theme_view);
|
||||
g_signal_connect(g_theme_view, "button-press-event", (GCallback)view_onButtonPressed, NULL);
|
||||
|
@ -232,16 +231,11 @@ static void menuAdd (GtkWindow *parent)
|
|||
if (pt1) {
|
||||
pt1++;
|
||||
if (*pt1) {
|
||||
name = strdup(pt1);
|
||||
name = g_strdup(pt1);
|
||||
path = g_build_filename (g_get_user_config_dir(), "tint2", name, NULL);
|
||||
copy_file(file, path);
|
||||
add_to_list(g_theme_view, path);
|
||||
g_free(path);
|
||||
pt1 = strstr(name, ".tint2rc");
|
||||
if (pt1) {
|
||||
file = strndup(name, pt1-name);
|
||||
add_to_list(g_theme_view, file);
|
||||
g_free(file);
|
||||
}
|
||||
g_free(name);
|
||||
}
|
||||
}
|
||||
|
@ -253,7 +247,7 @@ static void menuAdd (GtkWindow *parent)
|
|||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static void menuSaveAs (GtkWindow *parent)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
@ -274,28 +268,23 @@ static void menuSaveAs (GtkWindow *parent)
|
|||
}
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static void menuDelete (void)
|
||||
{
|
||||
GtkTreeSelection *sel;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
char *value, *name1, *name2;
|
||||
char *value;
|
||||
|
||||
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
|
||||
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, COL_TEXT, &value, -1);
|
||||
gtk_tree_selection_unselect_all(sel);
|
||||
// remove from the gui
|
||||
|
||||
// remove (gui and disk)
|
||||
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
|
||||
|
||||
name1 = g_build_filename (g_get_user_config_dir(), "tint2", value, NULL);
|
||||
name2 = g_strdup_printf("%s.tint2rc", name1);
|
||||
g_remove(name2);
|
||||
|
||||
g_free(name1);
|
||||
g_free(name2);
|
||||
g_remove(value);
|
||||
g_free(value);
|
||||
}
|
||||
}
|
||||
|
@ -306,33 +295,21 @@ static void menuProperties (void)
|
|||
GtkTreeSelection *sel;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
char *value, *name1, *name2, *cmd;
|
||||
char *value, *cmd;
|
||||
|
||||
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
|
||||
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, COL_TEXT, &value, -1);
|
||||
|
||||
name1 = g_build_filename ("\'", g_get_user_config_dir(), "tint2", value, NULL);
|
||||
name2 = g_strdup_printf("%s.tint2rc\'", name1);
|
||||
|
||||
cmd = g_strdup_printf("tintwizard.py %s", name2);
|
||||
cmd = g_strdup_printf("tintwizard.py \'%s\'", value);
|
||||
system(cmd);
|
||||
g_free(cmd);
|
||||
|
||||
g_free(name1);
|
||||
g_free(name2);
|
||||
g_free(cmd);
|
||||
g_free(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void menuRename (void)
|
||||
{
|
||||
printf("menuRename\n");
|
||||
// g_rename
|
||||
}
|
||||
|
||||
|
||||
static void menuQuit (void)
|
||||
{
|
||||
write_config();
|
||||
|
@ -354,24 +331,25 @@ static void menuRefreshAll (void)
|
|||
}
|
||||
|
||||
|
||||
static void menuPreferences (void)
|
||||
{
|
||||
printf("menuPreferences\n");
|
||||
}
|
||||
|
||||
|
||||
static void menuApply (void)
|
||||
{
|
||||
GtkTreeSelection *sel;
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
char *value, *name1, *name2;
|
||||
char *value;
|
||||
|
||||
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_theme_view));
|
||||
if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(sel), &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, COL_TEXT, &value, -1);
|
||||
name1 = g_build_filename (g_get_user_config_dir(), "tint2", value, NULL);
|
||||
name2 = g_strdup_printf("%s.tint2rc", name1);
|
||||
g_free(name1);
|
||||
|
||||
copy_file(name2, g_path_config);
|
||||
write_config();
|
||||
copy_file(value, g_path_config);
|
||||
g_free(value);
|
||||
g_free(name2);
|
||||
|
||||
// restart panel
|
||||
system("killall -SIGUSR1 tint2");
|
||||
|
@ -430,23 +408,34 @@ static void load_theme(GtkWidget *list)
|
|||
{
|
||||
GDir *dir;
|
||||
gchar *file, *pt1, *name;
|
||||
int found_theme = FALSE;
|
||||
|
||||
dir = g_dir_open(g_path_dir, 0, NULL);
|
||||
if (dir == NULL) return;
|
||||
while ((file = g_dir_read_name(dir))) {
|
||||
pt1 = strstr(file, ".tint2rc");
|
||||
if (pt1) {
|
||||
name = strndup(file, pt1-file);
|
||||
found_theme = TRUE;
|
||||
name = g_build_filename (g_path_dir, file, NULL);
|
||||
add_to_list(list, name);
|
||||
g_free(name);
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
|
||||
if (!found_theme) {
|
||||
// create default theme file
|
||||
file = g_build_filename (g_get_user_config_dir(), "tint2", "default.tint2rc", NULL);
|
||||
copy_file(g_path_config, file);
|
||||
add_to_list(list, file);
|
||||
g_free(file);
|
||||
}
|
||||
|
||||
// search default theme
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
if (g_default_theme) {
|
||||
printf("defaultTheme %s\n", g_default_theme);
|
||||
if (g_default_theme != NULL) {
|
||||
printf("loadTheme : defaultTheme %s\n", g_default_theme);
|
||||
//gtk_tree_selection_select_iter(GtkTreeSelection *selection, GtkTreeIter *iter);
|
||||
}
|
||||
}
|
||||
|
@ -457,8 +446,10 @@ void read_config()
|
|||
{
|
||||
char *path;
|
||||
|
||||
if (g_default_theme)
|
||||
if (g_default_theme != NULL) {
|
||||
g_free(g_default_theme);
|
||||
g_default_theme = NULL;
|
||||
}
|
||||
|
||||
g_width = 600;
|
||||
g_height = 350;
|
||||
|
@ -484,6 +475,8 @@ void read_config()
|
|||
}
|
||||
}
|
||||
g_free(path);
|
||||
if (g_default_theme != NULL)
|
||||
printf("readConfig : defaultTheme %s\n", g_default_theme);
|
||||
}
|
||||
|
||||
|
||||
|
@ -518,7 +511,10 @@ void write_config()
|
|||
if (fp != NULL) {
|
||||
fputs("#---------------------------------------------\n", fp);
|
||||
fputs("# TINT2CONF CONFIG FILE\n", fp);
|
||||
fprintf(fp, "default_theme = %s\n", g_default_theme);
|
||||
if (g_default_theme != NULL) {
|
||||
fprintf(fp, "default_theme = %s\n", g_default_theme);
|
||||
printf("default_theme %s\n", g_default_theme);
|
||||
}
|
||||
fprintf(fp, "width = %d\n", g_width);
|
||||
fprintf(fp, "height = %d\n", g_height);
|
||||
fputs("\n", fp);
|
||||
|
|
|
@ -4,53 +4,41 @@
|
|||
|
||||
GtkListStore *g_store;
|
||||
|
||||
// Some boring function declarations: GObject type system stuff
|
||||
static void custom_cell_renderer_theme_init(CustomCellRendererTheme *cellprogress);
|
||||
static void custom_cell_renderer_theme_class_init(CustomCellRendererThemeClass *klass);
|
||||
static void custom_cell_renderer_theme_finalize(GObject *gobject);
|
||||
static void custom_cell_renderer_theme_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *pspec);
|
||||
static void custom_cell_renderer_theme_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec);
|
||||
|
||||
|
||||
// These functions are the heart of our custom cell renderer:
|
||||
static void custom_cell_renderer_theme_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height);
|
||||
static void custom_cell_renderer_theme_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags);
|
||||
|
||||
|
||||
static gpointer parent_class;
|
||||
|
||||
enum { PROP_TITLE = 1, };
|
||||
|
||||
|
||||
|
||||
|
||||
GtkWidget *create_view_and_model(void)
|
||||
GtkWidget *create_view(void)
|
||||
{
|
||||
GtkTreeViewColumn *col;
|
||||
GtkCellRenderer *renderer;
|
||||
GtkWidget *view;
|
||||
GtkTreeSelection *sel;
|
||||
GtkTreeIter iter;
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *col;
|
||||
GtkTreeSelection *sel;
|
||||
GtkListStore *liststore;
|
||||
GtkWidget *view;
|
||||
|
||||
g_store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
|
||||
g_store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, GDK_TYPE_PIXBUF);
|
||||
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(g_store));
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
|
||||
//gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
|
||||
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
|
||||
//gtk_tree_view_set_fixed_height_mode(GTK_TREE_VIEW(view), TRUE);
|
||||
|
||||
g_object_unref(g_store); // destroy store automatically with view
|
||||
/*
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
col = gtk_tree_view_column_new_with_attributes("Deb", renderer, "title", COL_TEXT, NULL);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
*/
|
||||
renderer = g_object_new(CUSTOM_TYPE_CELL_RENDERER_THEME, NULL);
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_pack_start (col, renderer, TRUE);
|
||||
gtk_tree_view_column_add_attribute (col, renderer, "title", COL_TEXT);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view),col);
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_TEXT);
|
||||
gtk_tree_view_column_set_title(col, " items 1 ");
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
|
||||
renderer = gtk_cell_renderer_pixbuf_new();
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
gtk_tree_view_column_add_attribute(col, renderer, "pixbuf", COL_PIX);
|
||||
gtk_tree_view_column_set_title(col, " image ");
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
|
||||
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
|
||||
gtk_tree_selection_set_mode(GTK_TREE_SELECTION(sel), GTK_SELECTION_SINGLE);
|
||||
g_signal_connect(sel, "changed", G_CALLBACK(on_changed), NULL);
|
||||
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
|
||||
g_signal_connect(sel, "changed", G_CALLBACK(on_changed), g_store);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -67,206 +55,32 @@ void on_changed(GtkWidget *widget, gpointer label)
|
|||
//gtk_label_set_text(GTK_LABEL(label), value);
|
||||
g_free(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void add_to_list(GtkWidget *list, const gchar *str)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gchar *cmd, *name, *snapshot;
|
||||
GdkPixbuf *icon;
|
||||
GError *error = NULL;
|
||||
|
||||
//printf(" %s\n", str);
|
||||
snapshot = g_build_filename (g_get_user_config_dir(), "tint2", "snap.jpg", NULL);
|
||||
cmd = g_strdup_printf("tint2 -c \'%s\' -s \'%s\'", str, snapshot, NULL);
|
||||
system(cmd);
|
||||
|
||||
icon = gdk_pixbuf_new_from_file(snapshot, &error);
|
||||
g_free(snapshot);
|
||||
if (error) {
|
||||
g_warning ("Could not load icon: %s\n", error->message);
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_list_store_append(g_store, &iter);
|
||||
gtk_list_store_set(g_store, &iter, COL_TEXT, str, -1);
|
||||
//gtk_list_store_set (g_store, &iter, COL_TEXT, buf, -1);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* custom_cell_renderer_theme_get_type: here we register our type with
|
||||
* the GObject type system if we
|
||||
* haven't done so yet. Everything
|
||||
* else is done in the callbacks.
|
||||
***************************************************************************/
|
||||
|
||||
GType custom_cell_renderer_theme_get_type (void)
|
||||
{
|
||||
static GType cell_type = 0;
|
||||
|
||||
if (cell_type == 0) {
|
||||
static const GTypeInfo cell_info =
|
||||
{
|
||||
sizeof (CustomCellRendererThemeClass),
|
||||
NULL, // base_init
|
||||
NULL, // base_finalize
|
||||
(GClassInitFunc) custom_cell_renderer_theme_class_init,
|
||||
NULL, // class_finalize
|
||||
NULL, // class_data
|
||||
sizeof (CustomCellRendererTheme),
|
||||
0, // n_preallocs
|
||||
(GInstanceInitFunc) custom_cell_renderer_theme_init,
|
||||
};
|
||||
|
||||
// Derive from GtkCellRenderer
|
||||
cell_type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "CustomCellRendererTheme", &cell_info, 0);
|
||||
}
|
||||
|
||||
return cell_type;
|
||||
}
|
||||
|
||||
|
||||
static void custom_cell_renderer_theme_init(CustomCellRendererTheme *celltheme)
|
||||
{
|
||||
// set some default properties
|
||||
GTK_CELL_RENDERER(celltheme)->mode = GTK_CELL_RENDERER_MODE_INERT;
|
||||
GTK_CELL_RENDERER(celltheme)->xpad = 2;
|
||||
GTK_CELL_RENDERER(celltheme)->ypad = 2;
|
||||
celltheme->title = 0;
|
||||
printf("custom_cell_renderer_theme_init\n\n");
|
||||
gtk_list_store_set(g_store, &iter, COL_TEXT, str, COL_PIX, icon, -1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* custom_cell_renderer_theme_class_init:
|
||||
*
|
||||
* set up our own get_property and set_property functions, and
|
||||
* override the parent's functions that we need to implement.
|
||||
* And make our new "percentage" property known to the type system.
|
||||
* If you want cells that can be activated on their own (ie. not
|
||||
* just the whole row selected) or cells that are editable, you
|
||||
* will need to override 'activate' and 'start_editing' as well.
|
||||
***************************************************************************/
|
||||
|
||||
static void custom_cell_renderer_theme_class_init(CustomCellRendererThemeClass *klass)
|
||||
{
|
||||
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
object_class->finalize = custom_cell_renderer_theme_finalize;
|
||||
|
||||
object_class->get_property = custom_cell_renderer_theme_get_property;
|
||||
object_class->set_property = custom_cell_renderer_theme_set_property;
|
||||
|
||||
// Override the two crucial functions that are the heart of a cell renderer in the parent class
|
||||
cell_class->get_size = custom_cell_renderer_theme_get_size;
|
||||
cell_class->render = custom_cell_renderer_theme_render;
|
||||
|
||||
printf("custom_class_init\n\n");
|
||||
|
||||
// Install our very own properties
|
||||
g_object_class_install_property (object_class, PROP_TITLE, g_param_spec_string("title", "Title", "Theme's title", 0, G_PARAM_READWRITE));
|
||||
// g_object_class_install_property (object_class, PROP_PERCENTAGE, g_param_spec_double ("percentage", "Percentage", "The fractional progress to display", 0, 1, 0, G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
|
||||
static void custom_cell_renderer_theme_finalize(GObject *object)
|
||||
{
|
||||
CustomCellRendererTheme *celltheme = CUSTOM_CELL_RENDERER_THEME(object);
|
||||
|
||||
// free any resources here
|
||||
//if (celltheme->title)
|
||||
//g_free(celltheme->title);
|
||||
|
||||
// Free any dynamically allocated resources here
|
||||
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
|
||||
}
|
||||
|
||||
|
||||
static void custom_cell_renderer_theme_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *psec)
|
||||
{
|
||||
CustomCellRendererTheme *celltheme = CUSTOM_CELL_RENDERER_THEME(object);
|
||||
|
||||
switch (param_id) {
|
||||
case PROP_TITLE:
|
||||
g_value_set_string(value, celltheme->title);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void custom_cell_renderer_theme_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
CustomCellRendererTheme *cellprogress = CUSTOM_CELL_RENDERER_THEME(object);
|
||||
|
||||
switch (param_id) {
|
||||
case PROP_TITLE:
|
||||
//printf("set_property**************************************\n");
|
||||
cellprogress->title = g_value_get_string(value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define FIXED_WIDTH 100
|
||||
#define FIXED_HEIGHT 20
|
||||
|
||||
static void custom_cell_renderer_theme_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height)
|
||||
{
|
||||
gint calc_width;
|
||||
gint calc_height;
|
||||
|
||||
// calculate the size of our cell, taking into account
|
||||
// padding and alignment properties of parent.
|
||||
calc_width = (gint) cell->xpad * 2 + FIXED_WIDTH;
|
||||
calc_height = (gint) cell->ypad * 2 + FIXED_HEIGHT;
|
||||
|
||||
if (width)
|
||||
*width = calc_width;
|
||||
|
||||
if (height)
|
||||
*height = calc_height;
|
||||
|
||||
if (cell_area) {
|
||||
if (x_offset) {
|
||||
*x_offset = cell->xalign * (cell_area->width - calc_width);
|
||||
*x_offset = MAX (*x_offset, 0);
|
||||
}
|
||||
|
||||
if (y_offset) {
|
||||
*y_offset = cell->yalign * (cell_area->height - calc_height);
|
||||
*y_offset = MAX (*y_offset, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void custom_cell_renderer_theme_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags)
|
||||
{
|
||||
CustomCellRendererTheme *celltheme = CUSTOM_CELL_RENDERER_THEME(cell);
|
||||
GtkStateType state;
|
||||
gint width, height, x_offset, y_offset;
|
||||
PangoLayout *layout;
|
||||
|
||||
// do the rendering.
|
||||
custom_cell_renderer_theme_get_size(cell, widget, cell_area, &x_offset, &y_offset, &width, &height);
|
||||
|
||||
if (GTK_WIDGET_HAS_FOCUS (widget))
|
||||
state = GTK_STATE_ACTIVE;
|
||||
else
|
||||
state = GTK_STATE_NORMAL;
|
||||
|
||||
width -= cell->xpad*2;
|
||||
height -= cell->ypad*2;
|
||||
|
||||
layout = gtk_widget_create_pango_layout(widget, "");
|
||||
pango_layout_set_text(layout, celltheme->title, strlen(celltheme->title));
|
||||
gtk_paint_layout (widget->style, widget->window, state, FALSE, NULL, widget, NULL, x_offset, y_offset, layout);
|
||||
//pango_layout_get_size (layout, &width, &height);
|
||||
g_object_unref (layout);
|
||||
|
||||
//gtk_paint_layout
|
||||
//gtk_paint_box (widget->style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, "title", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width - 1, height - 1);
|
||||
|
||||
printf("custom_cell_renderer_theme_render\n");
|
||||
//gtk_paint_box (widget->style, window, state, GTK_SHADOW_OUT, NULL, widget, "bar", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width * cellprogress->progress, height - 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,42 +3,13 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
// Some boilerplate GObject type check and type cast macros.
|
||||
// 'klass' is used here instead of 'class', because 'class' is a c++ keyword
|
||||
|
||||
#define CUSTOM_TYPE_CELL_RENDERER_THEME (custom_cell_renderer_theme_get_type())
|
||||
#define CUSTOM_CELL_RENDERER_THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CUSTOM_TYPE_CELL_RENDERER_THEME, CustomCellRendererTheme))
|
||||
#define CUSTOM_CELL_RENDERER_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CUSTOM_TYPE_CELL_RENDERER_THEME, CustomCellRendererThemeClass))
|
||||
#define CUSTOM_IS_CELL_PROGRESS_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CUSTOM_TYPE_CELL_RENDERER_THEME))
|
||||
#define CUSTOM_IS_CELL_PROGRESS_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CUSTOM_TYPE_CELL_RENDERER_THEME))
|
||||
#define CUSTOM_CELL_RENDERER_THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CUSTOM_TYPE_CELL_RENDERER_THEME, CustomCellRendererThemeClass))
|
||||
|
||||
extern GtkListStore *g_store;
|
||||
|
||||
enum { COL_TEXT = 0, N_COLUMNS };
|
||||
|
||||
typedef struct _CustomCellRendererTheme CustomCellRendererTheme;
|
||||
typedef struct _CustomCellRendererThemeClass CustomCellRendererThemeClass;
|
||||
enum { COL_TEXT = 0, COL_PIX, N_COLUMNS };
|
||||
|
||||
|
||||
struct _CustomCellRendererTheme
|
||||
{
|
||||
GtkCellRenderer parent;
|
||||
|
||||
gchar *title;
|
||||
gdouble progress;
|
||||
};
|
||||
|
||||
|
||||
struct _CustomCellRendererThemeClass
|
||||
{
|
||||
GtkCellRendererClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GtkWidget *create_view_and_model(void);
|
||||
|
||||
GType custom_cell_renderer_theme_get_type(void);
|
||||
GtkWidget *create_view(void);
|
||||
|
||||
void on_changed(GtkWidget *widget, gpointer label);
|
||||
|
||||
|
|
Loading…
Reference in a new issue