ergtklistview.h File Reference

ereader gtk library - GtkTreeView object adapted for ereader system More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _erGtkListView
struct  _erGtkListViewClass

Defines

#define P_(String)   (String)
#define I_(string)   g_intern_static_string (string)
#define ERGTK_TYPE_LIST_VIEW   (ergtk_list_view_get_type())
#define ERGTK_LIST_VIEW(obj)   (G_TYPE_CHECK_INSTANCE_CAST((obj), ERGTK_TYPE_LIST_VIEW, erGtkListView))
#define ERGTK_IS_LIST_VIEW(obj)   (G_TYPE_CHECK_INSTANCE_TYPE((obj), ERGTK_TYPE_LIST_VIEW))
#define ERGTK_LIST_VIEW_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST((klass), ERGTK_TYPE_LIST_VIEW, erGtkListViewClass))
#define ERGTK_LIST_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), ERGTK_TYPE_LIST_VIEW, erGtkListViewClass))
#define ERGTK_IS_LIST_VIEW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), ERGTK_TYPE_LIST_VIEW))

Typedefs

typedef struct _erGtkListView erGtkListView
typedef struct _erGtkListViewClass erGtkListViewClass

Enumerations

enum  erGtkListViewKeyPress {
  ERGTK_LIST_VIEW_PRESS_SHORT_UP, ERGTK_LIST_VIEW_PRESS_SHORT_DOWN, ERGTK_LIST_VIEW_PRESS_LONG_UP, ERGTK_LIST_VIEW_PRESS_LONG_DOWN,
  ERGTK_LIST_VIEW_PRESS_ACTIVATE
}

Functions

GtkWidget * ergtk_list_view_new (void)
GtkWidget * ergtk_list_view_new_with_model (GtkTreeModel *model)
gint ergtk_list_view_append_column (erGtkListView *er_listview, GtkTreeViewColumn *column)
void ergtk_list_view_get_view_size (erGtkListView *er_listview, gint *num_rows, gint *num_items)
void ergtk_list_view_get_cursor (erGtkListView *er_listview, gint *row)
void ergtk_list_view_set_cursor (erGtkListView *er_listview, gint row)
void ergtk_list_view_set_focus_mode (erGtkListView *er_listview, gboolean focus_in, gboolean focus_out)
void ergtk_list_view_set_row_height (erGtkListView *er_listview, gint row_height)
GType ergtk_list_view_get_type (void)

Detailed Description

ereader gtk library - GtkTreeView object adapted for ereader system

Definition in file ergtklistview.h.


Define Documentation

#define ERGTK_IS_LIST_VIEW ( obj   )     (G_TYPE_CHECK_INSTANCE_TYPE((obj), ERGTK_TYPE_LIST_VIEW))
#define ERGTK_IS_LIST_VIEW_CLASS ( klass   )     (G_TYPE_CHECK_CLASS_TYPE((klass), ERGTK_TYPE_LIST_VIEW))

Definition at line 49 of file ergtklistview.h.

#define ERGTK_LIST_VIEW ( obj   )     (G_TYPE_CHECK_INSTANCE_CAST((obj), ERGTK_TYPE_LIST_VIEW, erGtkListView))
#define ERGTK_LIST_VIEW_CLASS ( klass   )     (G_TYPE_CHECK_CLASS_CAST((klass), ERGTK_TYPE_LIST_VIEW, erGtkListViewClass))

Definition at line 47 of file ergtklistview.h.

#define ERGTK_LIST_VIEW_GET_CLASS ( obj   )     (G_TYPE_INSTANCE_GET_CLASS((obj), ERGTK_TYPE_LIST_VIEW, erGtkListViewClass))

Definition at line 48 of file ergtklistview.h.

#define ERGTK_TYPE_LIST_VIEW   (ergtk_list_view_get_type())

Definition at line 43 of file ergtklistview.h.

Referenced by ergtk_list_view_new(), and ergtk_list_view_new_with_model().

#define I_ ( string   )     g_intern_static_string (string)

Definition at line 40 of file ergtklistview.h.

#define P_ ( String   )     (String)

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 36 of file ergtklistview.h.

Referenced by ergtk_icon_view_class_init(), and ergtk_list_view_class_init().


Typedef Documentation

typedef struct _erGtkListView erGtkListView

Definition at line 60 of file ergtklistview.h.

Definition at line 61 of file ergtklistview.h.


Enumeration Type Documentation

Enumerator:
ERGTK_LIST_VIEW_PRESS_SHORT_UP 
ERGTK_LIST_VIEW_PRESS_SHORT_DOWN 
ERGTK_LIST_VIEW_PRESS_LONG_UP 
ERGTK_LIST_VIEW_PRESS_LONG_DOWN 
ERGTK_LIST_VIEW_PRESS_ACTIVATE 

Definition at line 51 of file ergtklistview.h.


Function Documentation

gint ergtk_list_view_append_column ( erGtkListView er_listview,
GtkTreeViewColumn *  column 
)

Definition at line 233 of file ergtklistview.c.

References ERGTK_IS_LIST_VIEW, label, LOGPRINTF, on_column_notify_title(), and widget.

Referenced by create_back_listview(), create_contentview(), create_listview(), and create_settingsview().

00235 {
00236     g_return_val_if_fail( ERGTK_IS_LIST_VIEW(er_listview), 0 );
00237     g_return_val_if_fail( GTK_IS_TREE_VIEW_COLUMN(column), 0 );
00238 
00239     const gchar *title    = gtk_tree_view_column_get_title(column);
00240     GtkTreeView *treeview = (GtkTreeView *) er_listview;
00241 
00242     gint              num_columns    = 0;     // return value
00243     GtkWidget         *widget        = NULL;
00244     GtkWidget         *label         = NULL;
00245     GtkWidget         *event_box     = NULL;
00246     GtkBox            *vbox          = NULL;
00247     const gchar       *listview_name = gtk_widget_get_name( (GtkWidget*)er_listview );
00248     gchar             *header_name   = g_strdup_printf("%s-header", listview_name);
00249 
00250     LOGPRINTF("entry: title [%s]", title);
00251 
00252     // insert filler column for spacing
00253     if ( gtk_tree_view_get_column(treeview, 0) != NULL )
00254     {
00255        GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
00256        g_object_set( G_OBJECT(renderer),
00257                      "xpad", 0,
00258                      "ypad", 0,
00259                      "text", "",
00260                      NULL );
00261        GtkTreeViewColumn *filler_column = gtk_tree_view_column_new_with_attributes( "", renderer, NULL );
00262        gtk_tree_view_column_set_sizing(filler_column, GTK_TREE_VIEW_COLUMN_FIXED);
00263        gtk_tree_view_append_column(treeview, filler_column);
00264     }
00265 
00266     // set custom header for column
00267     if (title)
00268     {
00269         widget = gtk_tree_view_column_get_widget(column);
00270         if (widget == NULL)
00271         {
00272             //   column
00273             //     |-- widget vbox
00274             //           |-- label
00275             //           |-- event_box
00276             //
00277             widget = gtk_vbox_new(FALSE, 0);
00278             vbox = GTK_BOX(widget);
00279             //
00280             label = gtk_label_new( title );
00281             gtk_widget_set_name(label, header_name);
00282             gtk_misc_set_alignment( GTK_MISC(label), 0.0, 0.0);
00283             gtk_box_pack_start(vbox, label, FALSE, FALSE, 0);
00284             //
00285             event_box = gtk_event_box_new();
00286             gtk_widget_set_name(event_box, header_name);
00287             // TODO: replace hardcoded event-box height with a new style property
00288             gtk_widget_set_size_request(event_box, -1, 15);
00289             GTK_WIDGET_UNSET_FLAGS(event_box, GTK_CAN_FOCUS);
00290             gtk_box_pack_start(vbox, event_box, FALSE, FALSE, 0);
00291             //
00292             gtk_widget_show_all(widget);
00293             gtk_tree_view_column_set_widget(column, widget);
00294 
00295             // tell me when column title changes
00296             g_signal_connect(column, "notify::title", G_CALLBACK(on_column_notify_title), label);
00297         }
00298     }
00299 
00300     // add column to tree view
00301     num_columns = gtk_tree_view_append_column(treeview, column);
00302 
00303     // clean up
00304     g_free(header_name);
00305 
00306     return num_columns;
00307 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ergtk_list_view_get_cursor ( erGtkListView er_listview,
gint *  row 
)

Definition at line 596 of file ergtklistview.c.

References ERGTK_LIST_VIEW, LOGPRINTF, and path.

Referenced by get_cursor(), on_listview_navigate_cursor(), and on_pre_move_cursor().

00597 {
00598     GtkTreeView     *treeview = (GtkTreeView*) er_listview;
00599     GtkTreePath     *path = NULL;
00600     gint            *pi;
00601     gint            currow = -1;        // cursor row, return value
00602 
00603     g_return_if_fail(ERGTK_LIST_VIEW(er_listview));
00604 
00605     if (row != NULL)
00606     {
00607         path = gtk_tree_path_new();
00608         gtk_tree_view_get_cursor(treeview, &path, NULL);
00609         if (path == NULL)
00610         {
00611             LOGPRINTF("no cursor set");
00612         }
00613         else
00614         {
00615             pi = gtk_tree_path_get_indices(path);
00616             if (pi)
00617             {
00618                 currow = *pi;
00619             }
00620         }
00621         gtk_tree_path_free(path);
00622 
00623         *row = currow;
00624     }
00625 }

Here is the caller graph for this function:

GType ergtk_list_view_get_type ( void   ) 

get type of erGtkListView widget

Returns:
type

Definition at line 194 of file ergtklistview.c.

References ergtk_list_view_class_init(), and ergtk_list_view_init().

00195 {
00196     static GType class_type = 0;
00197 
00198     if (class_type == 0)
00199     {
00200         static const GTypeInfo class_info =
00201         {
00202             sizeof(erGtkListViewClass),
00203             NULL,               /* base_init */
00204             NULL,               /* base_finalize */
00205             (GClassInitFunc) ergtk_list_view_class_init,
00206             NULL,               /* class_finalize */
00207             NULL,               /* class_data */
00208             sizeof(erGtkListView),
00209             0,                  /* n_preallocs */
00210             (GInstanceInitFunc) ergtk_list_view_init,
00211             NULL                /* *value_table */            
00212             
00213         };
00214         class_type = g_type_register_static(GTK_TYPE_TREE_VIEW, "erGtkListView", &class_info, 0);
00215     }
00216 
00217     return class_type;
00218 }

Here is the call graph for this function:

void ergtk_list_view_get_view_size ( erGtkListView er_listview,
gint *  num_rows,
gint *  num_items 
)

Definition at line 628 of file ergtklistview.c.

References ERGTK_IS_LIST_VIEW, LOGPRINTF, path, and _erGtkListView::row_height.

Referenced by ergtk_list_view_set_cursor(), on_listview_navigate_cursor(), on_pre_move_cursor(), and update_view_size().

00629 {
00630     g_return_if_fail(ERGTK_IS_LIST_VIEW(er_listview));
00631 
00632     GtkTreeView             *treeview = (GtkTreeView*) er_listview;
00633     GdkRectangle            visible_rect;
00634     GtkTreePath             *path = NULL;
00635     gboolean                ok;
00636     gint                    *pi;
00637     gint                    vertical_separator = 0;
00638 
00639     LOGPRINTF("entry");
00640     
00641     // get style properties
00642     gtk_widget_style_get( GTK_WIDGET(er_listview),
00643                           "vertical-separator", &vertical_separator,
00644                           NULL );
00645 
00646     // get maximum number of rows visible
00647     if (num_rows != NULL)
00648     { 
00649         // calculate max. number of items in treeview
00650         gtk_tree_view_get_visible_rect(treeview, &visible_rect);
00651         if (   visible_rect.height     > 0
00652             && er_listview->row_height > 0 )
00653         {
00654             *num_rows = visible_rect.height / (er_listview->row_height + vertical_separator);
00655         }
00656         else
00657         {
00658             *num_rows = 1;
00659         }
00660         LOGPRINTF("num_rows [%d]", *num_rows);
00661     }
00662     
00663     // get current number of items
00664     if (num_items != NULL)
00665     { 
00666         pi   = NULL;
00667         ok   = gtk_tree_view_get_visible_range(treeview, NULL, &path);
00668         if (ok  &&  path)
00669         {
00670             pi = gtk_tree_path_get_indices(path);
00671         }
00672 
00673         if (pi)
00674         {
00675             *num_items = *pi + 1;
00676         }
00677         else
00678         {
00679             *num_items = 0;
00680         }
00681         LOGPRINTF("num_items [%d]", *num_items);
00682 
00683         // clean up
00684         if (path) { gtk_tree_path_free(path); }
00685         path = NULL;
00686     }
00687     LOGPRINTF("leave");
00688 }

Here is the caller graph for this function:

GtkWidget* ergtk_list_view_new ( void   ) 

Definition at line 221 of file ergtklistview.c.

References ERGTK_TYPE_LIST_VIEW.

00222 {
00223     return g_object_new (ERGTK_TYPE_LIST_VIEW, NULL);
00224 }

GtkWidget* ergtk_list_view_new_with_model ( GtkTreeModel *  model  ) 

Definition at line 227 of file ergtklistview.c.

References ERGTK_TYPE_LIST_VIEW.

Referenced by create_back_listview(), create_contentview(), create_listview(), and create_settingsview().

00228 {
00229     return g_object_new (ERGTK_TYPE_LIST_VIEW, "model", model, NULL);
00230 }

Here is the caller graph for this function:

void ergtk_list_view_set_cursor ( erGtkListView er_listview,
gint  row 
)

Definition at line 691 of file ergtklistview.c.

References ERGTK_IS_LIST_VIEW, ergtk_list_view_get_view_size(), LOGPRINTF, path, and widget.

Referenced by on_button_press_event(), on_focus_in(), and on_idle_set_cursor().

00692 {
00693     g_return_if_fail(ERGTK_IS_LIST_VIEW(er_listview));
00694 
00695     GtkTreeView      *treeview  = (GtkTreeView*) er_listview;
00696     GtkWidget        *widget    = (GtkWidget  *) er_listview;
00697     GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
00698     
00699     GtkTreePath *path = NULL;  
00700     gint num_rows = 0;
00701     gint num_items = 0;
00702     
00703     LOGPRINTF("entry: row %d", row);
00704 
00705     ergtk_list_view_get_view_size(er_listview, &num_rows, &num_items); 
00706     LOGPRINTF("num_rows %d, num_items %d", num_rows, num_items);
00707 
00708     // force row within valid range
00709     if (row >= num_items)
00710     {
00711         row = num_items - 1;
00712     }
00713     if (row < 0)
00714     {
00715         row = -1;
00716     }
00717 
00718     // create path from index and set cursor
00719     if (num_items > 0)
00720     {
00721         path = gtk_tree_path_new_from_indices(row, -1);
00722         gtk_widget_grab_focus (widget);
00723         gtk_tree_selection_select_path(selection, path);  
00724         gtk_tree_view_set_cursor(treeview, path, NULL, FALSE);
00725     }
00726 
00727     // clean up
00728     if (path) { gtk_tree_path_free(path); }
00729 
00730     return;
00731 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ergtk_list_view_set_focus_mode ( erGtkListView er_listview,
gboolean  focus_in,
gboolean  focus_out 
)

Definition at line 734 of file ergtklistview.c.

References LOGPRINTF, on_focus_in(), and on_focus_out().

Referenced by create_back_listview(), create_contentview(), create_listview(), and create_settingsview().

00737 {
00738     LOGPRINTF("entry");
00739 
00740     if (!focus_in)
00741     {
00742         // block focus-in events 
00743         g_signal_connect(G_OBJECT(er_listview), "focus-in-event", G_CALLBACK (on_focus_in), NULL);
00744     }
00745     if (!focus_out)
00746     {
00747         // block focus-out events 
00748         g_signal_connect(G_OBJECT(er_listview), "focus-out-event", G_CALLBACK (on_focus_out), NULL);
00749     }
00750 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ergtk_list_view_set_row_height ( erGtkListView er_listview,
gint  row_height 
)

Definition at line 753 of file ergtklistview.c.

References ERGTK_IS_LIST_VIEW, _erGtkListView::is_forced_height, LOGPRINTF, and _erGtkListView::row_height.

Referenced by create_listview().

00754 {
00755     g_return_if_fail(ERGTK_IS_LIST_VIEW(er_listview));
00756 
00757     gint        focus_line_width = 0;
00758 
00759     LOGPRINTF("entry");
00760 
00761     if (row_height > 0)
00762     {
00763         gtk_widget_style_get( GTK_WIDGET(er_listview),
00764                               "focus-line-width", &focus_line_width,
00765                               NULL );
00766         er_listview->row_height       = row_height + (2 * focus_line_width);
00767         er_listview->is_forced_height = TRUE;
00768     }
00769     else
00770     {
00771         er_listview->row_height       = -1;
00772         er_listview->is_forced_height = FALSE;
00773     }
00774 }

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208