Convert the pager to a GtkOverlay
authorPhilip Chimento <philip.chimento@gmail.com>
Sun, 16 Sep 2012 13:21:08 +0000 (15:21 +0200)
committerPhilip Chimento <philip.chimento@gmail.com>
Sun, 16 Sep 2012 13:21:08 +0000 (15:21 +0200)
libchimara/pager.c
libchimara/window.c
libchimara/window.h

index efb941b46f39bb945e82292539e89c5371d09f02..652a70dd411fe7948bd35a76623eefc795937f91 100644 (file)
@@ -46,7 +46,7 @@ static void
 start_paging(winid_t win)
 {
        win->currently_paging = TRUE;
 start_paging(winid_t win)
 {
        win->currently_paging = TRUE;
-       g_signal_handler_unblock(win->widget, win->pager_expose_handler);
+       gtk_widget_show(win->pager);
        g_signal_handler_unblock(win->widget, win->pager_keypress_handler);
 }
 
        g_signal_handler_unblock(win->widget, win->pager_keypress_handler);
 }
 
@@ -55,7 +55,7 @@ static void
 stop_paging(winid_t win)
 {
        win->currently_paging = FALSE;
 stop_paging(winid_t win)
 {
        win->currently_paging = FALSE;
-       g_signal_handler_block(win->widget, win->pager_expose_handler);
+       gtk_widget_hide(win->pager);
        g_signal_handler_block(win->widget, win->pager_keypress_handler);
 }
 
        g_signal_handler_block(win->widget, win->pager_keypress_handler);
 }
 
@@ -80,7 +80,7 @@ pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win)
 gboolean
 pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win)
 {
 gboolean
 pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win)
 {
-       GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(win->frame) );
+       GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment( GTK_SCROLLED_WINDOW(win->scrolledwindow) );
        gdouble page_size, upper, lower, value;
        g_object_get(adj, 
                "page-size", &page_size,
        gdouble page_size, upper, lower, value;
        g_object_get(adj, 
                "page-size", &page_size,
@@ -104,24 +104,6 @@ pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win)
        return FALSE; /* if the key wasn't handled here, pass it to other handlers */
 }
 
        return FALSE; /* if the key wasn't handled here, pass it to other handlers */
 }
 
-/* Draw the "more" prompt on top of the buffer, after the regular draw event has run */
-gboolean
-pager_on_draw(GtkTextView *textview, cairo_t *cr, winid_t win)
-{
-       /* Calculate the position of the 'more' tag */
-       gint promptwidth, promptheight;
-       pango_layout_get_pixel_size(win->pager_layout, &promptwidth, &promptheight);
-
-       int winwidth = gtk_widget_get_allocated_width( GTK_WIDGET(textview) );
-       int winheight = gtk_widget_get_allocated_height( GTK_WIDGET(textview) );
-
-       /* Draw the 'more' tag */
-       cairo_move_to(cr, winwidth - promptwidth, winheight - promptheight);
-       pango_cairo_show_layout(cr, win->pager_layout);
-
-       return FALSE; /* Propagate event further */
-}
-
 /* Check whether paging should be done. This function is called after the
  * textview has finished validating text positions. */
 void 
 /* Check whether paging should be done. This function is called after the
  * textview has finished validating text positions. */
 void 
@@ -147,7 +129,7 @@ pager_after_size_allocate(GtkTextView *textview, GdkRectangle *allocation, winid
        
        /* Scroll past text already read by user. This is automatic scrolling, so disable the pager_ajustment_handler
         * first, that acts on the belief the scolling is performed by the user. */
        
        /* Scroll past text already read by user. This is automatic scrolling, so disable the pager_ajustment_handler
         * first, that acts on the belief the scolling is performed by the user. */
-       GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(win->frame));
+       GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(win->scrolledwindow));
        g_signal_handler_block(adj, win->pager_adjustment_handler);
        GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
        GtkTextMark *pager_position = gtk_text_buffer_get_mark(buffer, "pager_position");
        g_signal_handler_block(adj, win->pager_adjustment_handler);
        GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
        GtkTextMark *pager_position = gtk_text_buffer_get_mark(buffer, "pager_position");
index 85348f54502ce02de90a88b2406eb363b547cc5e..e302a1eedc06201a79dbf87f40815499db9e169f 100644 (file)
@@ -74,8 +74,6 @@ window_close_common(winid_t win, gboolean destroy_node)
        g_hash_table_destroy(win->hyperlinks);
        g_free(win->current_hyperlink);
 
        g_hash_table_destroy(win->hyperlinks);
        g_free(win->current_hyperlink);
 
-       if(win->pager_layout)
-               g_object_unref(win->pager_layout);
        if(win->backing_store)
                cairo_surface_destroy(win->backing_store);
 
        if(win->backing_store)
                cairo_surface_destroy(win->backing_store);
 
@@ -535,12 +533,20 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                
                case wintype_TextBuffer:
                {
                
                case wintype_TextBuffer:
                {
+                       GtkWidget *overlay = gtk_overlay_new();
                        GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
                        GtkWidget *textview = gtk_text_view_new();
                        GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
                        GtkWidget *textview = gtk_text_view_new();
+                       GtkWidget *pager = gtk_button_new_with_label("More");
+                       GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON);
                        GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(textview) );
 
                        gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
                        GtkTextBuffer *textbuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(textview) );
 
                        gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
-                       
+
+                       gtk_button_set_image( GTK_BUTTON(pager), image );
+                       gtk_widget_set_halign(pager, GTK_ALIGN_END);
+                       gtk_widget_set_valign(pager, GTK_ALIGN_END);
+                       gtk_widget_set_no_show_all(pager, TRUE);
+
                        gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(textview), GTK_WRAP_WORD_CHAR );
                        gtk_text_view_set_editable( GTK_TEXT_VIEW(textview), FALSE );
                        gtk_text_view_set_pixels_inside_wrap( GTK_TEXT_VIEW(textview), 3 );
                        gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(textview), GTK_WRAP_WORD_CHAR );
                        gtk_text_view_set_editable( GTK_TEXT_VIEW(textview), FALSE );
                        gtk_text_view_set_pixels_inside_wrap( GTK_TEXT_VIEW(textview), 3 );
@@ -548,16 +554,19 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        gtk_text_view_set_right_margin( GTK_TEXT_VIEW(textview), 20 );
 
                        gtk_container_add( GTK_CONTAINER(scrolledwindow), textview );
                        gtk_text_view_set_right_margin( GTK_TEXT_VIEW(textview), 20 );
 
                        gtk_container_add( GTK_CONTAINER(scrolledwindow), textview );
-                       gtk_widget_show_all(scrolledwindow);
+                       gtk_container_add( GTK_CONTAINER(overlay), scrolledwindow );
+                       gtk_overlay_add_overlay( GTK_OVERLAY(overlay), pager );
+                       gtk_widget_show_all(overlay);
 
                        win->widget = textview;
 
                        win->widget = textview;
-                       win->frame = scrolledwindow;
-                       
+                       win->scrolledwindow = scrolledwindow;
+                       win->pager = pager;
+                       win->frame = overlay;
+
                        /* Create the styles available to the window stream */
                        style_init_textbuffer(textbuffer);
                        /* Create the styles available to the window stream */
                        style_init_textbuffer(textbuffer);
-                       style_init_more_prompt(win);
                        gtk_widget_modify_font( textview, get_current_font(wintype) );
                        gtk_widget_modify_font( textview, get_current_font(wintype) );
-                       
+
                        /* Determine the size of a "0" character in pixels */
                        PangoLayout *zero = gtk_widget_create_pango_layout(textview, "0");
                        pango_layout_set_font_description( zero, get_current_font(wintype) );
                        /* Determine the size of a "0" character in pixels */
                        PangoLayout *zero = gtk_widget_create_pango_layout(textview, "0");
                        pango_layout_set_font_description( zero, get_current_font(wintype) );
@@ -568,8 +577,6 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        
                        /* Pager */
                        g_signal_connect_after( textview, "size-allocate", G_CALLBACK(pager_after_size_allocate), win );
                        
                        /* Pager */
                        g_signal_connect_after( textview, "size-allocate", G_CALLBACK(pager_after_size_allocate), win );
-                       win->pager_expose_handler = g_signal_connect_after( textview, "draw", G_CALLBACK(pager_on_draw), win );
-                       g_signal_handler_block(textview, win->pager_expose_handler);
                        win->pager_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(pager_on_key_press_event), win );
                        g_signal_handler_block(textview, win->pager_keypress_handler);
                        GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow));
                        win->pager_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(pager_on_key_press_event), win );
                        g_signal_handler_block(textview, win->pager_keypress_handler);
                        GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow));
index 72ee91b529c3e51ebbab3b756373c1c1fbaa678e..4c753c39b587117c598812128bf5513a17e22bb0 100644 (file)
@@ -42,6 +42,10 @@ struct glk_window_struct
        /* "frame" is the widget that is the child of the ChimaraGlk container, such 
        as a scroll window. It may be the same as "widget". */
        GtkWidget *frame;
        /* "frame" is the widget that is the child of the ChimaraGlk container, such 
        as a scroll window. It may be the same as "widget". */
        GtkWidget *frame;
+       /* In text buffer windows, the scrolled window and the pager are extra
+       widgets that are neither "widget" nor "frame" */
+       GtkWidget *scrolledwindow;
+       GtkWidget *pager;
        /* Width and height of the window's size units, in pixels */
        int unit_width;
        int unit_height;
        /* Width and height of the window's size units, in pixels */
        int unit_width;
        int unit_height;
@@ -82,7 +86,6 @@ struct glk_window_struct
        gulong shutdown_keypress_handler;
        gulong button_press_event_handler;
        gulong size_allocate_handler;
        gulong shutdown_keypress_handler;
        gulong button_press_event_handler;
        gulong size_allocate_handler;
-       gulong pager_expose_handler;
        gulong pager_keypress_handler;
        gulong pager_adjustment_handler;
        /* Window buffer */
        gulong pager_keypress_handler;
        gulong pager_adjustment_handler;
        /* Window buffer */