Re: Image resizing
On Sat, Jun 8, 2013 at 10:27 PM, Kip Warner k...@thevertigo.com wrote: The banner image should automatically resize as the window is resized. It should use the full width available in the parent page (GtkBox), but the image's height should be calculated as a function of the aspect ratio to keep it from being distorted. I don't want the scrollbars to ever appear and the full image to always be visible. Any help appreciated. One approach is ditching the ScrolledWindow and overriding the get_preferred_width_for_height/width() vfuncs to return the full image width, and then in size_allocate() set the image to a scaled pixbuf of the allocated width. This involves making a subclass which is a little bit of work if you've never done it before (especially in straight C). The only example I have on hand [1] is in Gtkmm and does quite a bit more than you need (Animated image support, toggling between thumbnail and full size). But overriding these functions should be enough: size_allocate() get_preferred_height() get_preferred_width_for_height() get_preferred_width() get_preferred_height_for_width() [1] https://github.com/talisein/Horizon/blob/master/src/horizon_image.cpp ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
GtkScrolledWindow containing GtkTextView containing a TextBuffer can't keep at bottom of Buffer
I see a lot of questions about this and I have not found an answer that works for me. I create the chat window like this: CHAT *ChatNew(char *player) { CHAT *chatlog; GtkBox *chat; GtkTextBuffer *buf; GtkTextView *text; GtkEntry *entry; GtkScrolledWindow *scroll; GtkTextIter endit; text = (GtkTextView *)gtk_text_view_new(); gtk_text_view_set_editable(text, FALSE); gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD_CHAR); gtk_text_view_set_cursor_visible(text, FALSE); buf = gtk_text_buffer_new(NULL); printf(New TextBuffer %x\r\n, (int)buf); gtk_text_view_set_buffer(text, buf); scroll = (GtkScrolledWindow *)gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(scroll, GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_scrolled_window_add_with_viewport(scroll, GTK_WIDGET(text)); entry = (GtkEntry *)gtk_entry_new(); gtk_widget_set_size_request(GTK_WIDGET(entry), -1, 30); chat = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0)); gtk_box_pack_start(chat, GTK_WIDGET(scroll), TRUE, TRUE, 0); gtk_box_pack_end(chat, (GtkWidget *)entry, FALSE, TRUE, 0); chatlog = g_malloc0(sizeof(CHAT)); if (chatlog == NULL) return NULL; strcpy(chatlog-player, player); chatlog-scroll = scroll; chatlog-box = chat; chatlog-text = text; chatlog-entry = entry; g_signal_connect(G_OBJECT(entry), activate, G_CALLBACK(Enter_Chat), (gpointer)chatlog); //buf = gtk_text_view_get_buffer(chatlog-text); gtk_text_buffer_get_end_iter(buf, endit); gtk_text_buffer_create_mark(buf, eob, endit, FALSE); g_signal_connect(G_OBJECT(buf), changed, G_CALLBACK(Chat_scroll_to_end), (gpointer)text); //g_signal_connect(G_OBJECT(buf), key_press_event, G_CALLBACK(Chat_keys), (gpointer)chatlog); return chatlog; } The caller adds it to a GtkNotebook if (item == NULL) { chatlog = ChatNew(name); label = (GtkLabel *)gtk_label_new(name); g_queue_insert_sorted(gfibs.chats, chatlog, chatNB_sort_chat, 0); n = gtk_notebook_insert_page(nb, (GtkWidget *)chatlog-box, (GtkWidget *)label, 2); buf = gtk_text_view_get_buffer(chatlog-text); textv = chatlog-text; gtk_widget_show((GtkWidget *)chatlog-scroll); gtk_widget_show((GtkWidget *)chatlog-box); gtk_widget_show((GtkWidget *)chatlog-text); gtk_widget_show((GtkWidget *)chatlog-entry); gtk_widget_show((GtkWidget *)label); printf(chat inserted at %d\r\n, n); } else { chatlog = (CHAT *)item-data; buf = NULL; if (chatlog != NULL chatlog-text != NULL) { buf = gtk_text_view_get_buffer(chatlog-text); textv = chatlog-text; n = gtk_notebook_page_num(nb, GTK_WIDGET(chatlog-box)); } } if (buf != NULL) { GtkTextIter endit; gtk_text_buffer_get_end_iter(buf, endit); gtk_text_buffer_insert_with_tags(buf, endit, line, -1, NULL, NULL); return TRUE; } and then to make sure it is visible void Chat_scroll_to_end(GtkTextBuffer *buf, GtkTextView *text) { GtkTextMark *mark; printf(Chat_scroll_to_end arg %x text %x parent %x\r\n, (int)buf, (int)text, (int)gtk_widget_get_parent(GTK_WIDGET(buf)));fflush(stdout); mark = gtk_text_buffer_get_mark(buf, eob); gtk_text_view_scroll_mark_onscreen(text, mark); } The printf above at times tells me the objects are not valid, but the addresses have not changed. Also the TextBuffer has a parent of 0! I even allocated and set the buffer manually. If there it no anything obvious wrong here I will strip it down to a simpler test case Tom ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Hiding scrollbars for GtkScrolledWindow
On Fri, 2013-06-07 at 19:05 +0200, Felix Möller wrote: Sorry for being unprecise. GTK3 in combination with C. If I set the scrollbars' policy to never, the scrollbar is not displayed, but the window is not as small as it should be, but as big as its content. I want it to have the same size as with scrollbars, but without displaying them. Have you got any helpful advice already? I think that using a GtkScrolledWindow may be not a good choice if you do not want the visible scrollbars -- a GtkViewport may be what you want? But still I wonder why hiding the Scrollbars of a GtkScrolledWindow is not possible. Of course there may exists good reasons for that. Would be nice to know them. I have not found a C example code for GTK3 GtkScrolledWindow, so I have not examined that problem (Ruby bindings work not really well for GTK3 yet) -- maybe when I have more time. Best regards Stefan Salewski ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Image resizing
On Sun, 2013-06-09 at 00:12 -0700, Andrew Potter wrote: One approach is ditching the ScrolledWindow and overriding the get_preferred_width_for_height/width() vfuncs to return the full image width, and then in size_allocate() set the image to a scaled pixbuf of the allocated width. This involves making a subclass which is a little bit of work if you've never done it before (especially in straight C). The only example I have on hand [1] is in Gtkmm and does quite a bit more than you need (Animated image support, toggling between thumbnail and full size). But overriding these functions should be enough: size_allocate() get_preferred_height() get_preferred_width_for_height() get_preferred_width() get_preferred_height_for_width() [1] https://github.com/talisein/Horizon/blob/master/src/horizon_image.cpp Hey Andrew, Sadly I haven't really much experience with Gtk+ in C or Gtkmm with C++. I think it might be easier at this point if I just fixed the Python code I've written thus far rather than refactoring it with custom overrides. The code mostly works, it's just the scrollbar issue that's really annoying. Any help really appreciated. -- Kip Warner -- Software Engineer OpenPGP encrypted/signed mail preferred http://www.thevertigo.com ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkScrolledWindow containing GtkTextView containing a TextBuffer can't keep at bottom of Buffer
On 06/09/2013 09:21 AM, Thomas A. Moulton wrote: I see a lot of questions about this and I have not found an answer that works for me. I create the chat window like this: The printf above at times tells me the objects are not valid, but the addresses have not changed. Also the TextBuffer has a parent of 0! I even allocated and set the buffer manually. If there it no anything obvious wrong here I will strip it down to a simpler test case Tom Ok here is a single file example of my code... it works the same way it does in my larger project Any suggestions would be GREATLY appreciated! tom /* Name: Scrolled.c Author : Tom Moulton Version : Copyright : (c) 2013 Thoomas A. Moulton, Public Domain Description : Hello World in GTK+ */ #include gtk/gtk.h GtkNotebook *nb; void Enter_Chat(GtkEntry *entry, GtkTextBuffer *buf) { char line[512]; const gchar *cmd; GtkTextIter endit; cmd = gtk_entry_get_text(entry); strcpy(line, cmd); gtk_entry_set_text(entry, ); gtk_text_buffer_get_end_iter(buf, endit); gtk_text_buffer_insert_with_tags(buf, endit, line, -1, NULL, NULL); } void Chat_scroll_to_end(GtkTextBuffer *buf, GtkTextView *text) { GtkTextMark *mark; mark = gtk_text_buffer_get_mark(buf, eob); gtk_text_view_scroll_mark_onscreen(text, mark); } void ChatNew(void) { GtkBox *chat; GtkTextBuffer *buf; GtkTextView *text; GtkEntry *entry; GtkScrolledWindow *scroll; GtkTextIter endit; GtkLabel *label; text = (GtkTextView *)gtk_text_view_new(); gtk_text_view_set_editable(text, FALSE); gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD_CHAR); gtk_text_view_set_cursor_visible(text, FALSE); buf = gtk_text_buffer_new(NULL); gtk_text_view_set_buffer(text, buf); scroll = (GtkScrolledWindow *)gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(scroll, GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_scrolled_window_add_with_viewport(scroll, GTK_WIDGET(text)); entry = (GtkEntry *)gtk_entry_new(); gtk_widget_set_size_request(GTK_WIDGET(entry), -1, 30); chat = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0)); gtk_box_pack_start(chat, GTK_WIDGET(scroll), TRUE, TRUE, 0); gtk_box_pack_end(chat, (GtkWidget *)entry, FALSE, TRUE, 0); g_signal_connect(G_OBJECT(entry), activate, G_CALLBACK(Enter_Chat), (gpointer)buf); gtk_text_buffer_get_end_iter(buf, endit); gtk_text_buffer_create_mark(buf, eob, endit, FALSE); g_signal_connect(G_OBJECT(buf), changed, G_CALLBACK(Chat_scroll_to_end), (gpointer)text); label = (GtkLabel *)gtk_label_new(Test Scroll); gtk_notebook_append_page(nb, GTK_WIDGET(chat), GTK_WIDGET(label)); } int main (int argc, char *argv[]) { GtkWidget *window; gtk_init (argc, argv); /* create the main, top level, window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* give it the title */ gtk_window_set_title (GTK_WINDOW (window), Hello World); /* Connect the destroy signal of the window to gtk_main_quit * When the window is about to be destroyed we get a notification and * stop the main GTK+ loop */ g_signal_connect (window, destroy, G_CALLBACK (gtk_main_quit), NULL); nb = (GtkNotebook *)gtk_notebook_new(); ChatNew(); /* and insert it into the main window */ gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(nb)); /* make sure that everything, window and label, are visible */ gtk_widget_show_all (window); /* start the main loop, and let it rest there until the application is closed */ gtk_main (); return 0; } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list