comparison pidgin/gtkconv.c @ 27743:2961a316058c

revive resizable input widget. without this, input area shrinks to one line!
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 28 Nov 2007 14:38:43 +0000
parents 6befd211e707
children b9197011ddd6
comparison
equal deleted inserted replaced
27742:2443ea74b0f4 27743:2961a316058c
265 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/chat/userlist_width", allocation->width == 1 ? 0 : allocation->width); 265 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/chat/userlist_width", allocation->width == 1 ? 0 : allocation->width);
266 266
267 return FALSE; 267 return FALSE;
268 } 268 }
269 269
270 static gboolean
271 size_allocate_cb(GtkWidget *w, GtkAllocation *allocation, PidginConversation *gtkconv)
272 {
273 PurpleConversation *conv = gtkconv->active_conv;
274
275 if (!GTK_WIDGET_VISIBLE(w))
276 return FALSE;
277
278 if (!PIDGIN_IS_PIDGIN_CONVERSATION(conv))
279 return FALSE;
280 if (gtkconv->auto_resize) {
281 return FALSE;
282 }
283
284 if (gdk_window_get_state(gtkconv->win->window->window) & GDK_WINDOW_STATE_MAXIMIZED) {
285 return FALSE;
286 }
287
288 /* I find that I resize the window when it has a bunch of conversations in it, mostly so that the
289 * tab bar will fit, but then I don't want new windows taking up the entire screen. I check to see
290 * if there is only one conversation in the window. This way we'll be setting new windows to the
291 * size of the last resized new window. */
292 /* I think that the above justification is not the majority, and that the new tab resizing should
293 * negate it anyway. --luke */
294 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
295 {
296 if (w == gtkconv->lower_hbox)
297 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/im/entry_height", allocation->height);
298 }
299 else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
300 {
301 if (w == gtkconv->lower_hbox)
302 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/conversations/chat/entry_height", allocation->height);
303 }
304 return FALSE;
305 }
306
270 static void 307 static void
271 default_formatize(PidginConversation *c) 308 default_formatize(PidginConversation *c)
272 { 309 {
273 PurpleConversation *conv = c->active_conv; 310 PurpleConversation *conv = c->active_conv;
274 gtk_imhtml_setup_entry(GTK_IMHTML(c->entry), conv->features); 311 gtk_imhtml_setup_entry(GTK_IMHTML(c->entry), conv->features);
412 449
413 first = g_list_first(gtkconv->send_history); 450 first = g_list_first(gtkconv->send_history);
414 g_free(first->data); 451 g_free(first->data);
415 first->data = g_strdup(message); 452 first->data = g_strdup(message);
416 gtkconv->send_history = g_list_prepend(first, NULL); 453 gtkconv->send_history = g_list_prepend(first, NULL);
454 }
455
456 static void
457 reset_default_size(PidginConversation *gtkconv)
458 {
459 PurpleConversation *conv = gtkconv->active_conv;
460 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
461 gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
462 purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/chat/entry_height"));
463 else
464 gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
465 purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/im/entry_height"));
417 } 466 }
418 467
419 static gboolean 468 static gboolean
420 check_for_and_do_command(PurpleConversation *conv) 469 check_for_and_do_command(PurpleConversation *conv)
421 { 470 {
523 572
524 account = purple_conversation_get_account(conv); 573 account = purple_conversation_get_account(conv);
525 574
526 if (check_for_and_do_command(conv)) { 575 if (check_for_and_do_command(conv)) {
527 if (gtkconv->entry_growing) { 576 if (gtkconv->entry_growing) {
577 reset_default_size(gtkconv);
528 gtkconv->entry_growing = FALSE; 578 gtkconv->entry_growing = FALSE;
529 } 579 }
530 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); 580 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
531 return; 581 return;
532 } 582 }
582 g_free(clean); 632 g_free(clean);
583 g_free(buf); 633 g_free(buf);
584 634
585 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry)); 635 gtk_imhtml_clear(GTK_IMHTML(gtkconv->entry));
586 if (gtkconv->entry_growing) { 636 if (gtkconv->entry_growing) {
637 reset_default_size(gtkconv);
587 gtkconv->entry_growing = FALSE; 638 gtkconv->entry_growing = FALSE;
588 } 639 }
589 gtkconv_set_unseen(gtkconv, PIDGIN_UNSEEN_NONE); 640 gtkconv_set_unseen(gtkconv, PIDGIN_UNSEEN_NONE);
590 } 641 }
591 642
4341 menuitem = gtk_separator_menu_item_new(); 4392 menuitem = gtk_separator_menu_item_new();
4342 gtk_widget_show(menuitem); 4393 gtk_widget_show(menuitem);
4343 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 1); 4394 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 1);
4344 } 4395 }
4345 4396
4346 static gboolean resize_imhtml_cb(PidginConversation *gtkconv) 4397 static void resize_imhtml_cb(PidginConversation *gtkconv)
4347 { 4398 {
4348 GtkTextBuffer *buffer; 4399 GtkTextBuffer *buffer;
4349 GtkTextIter iter; 4400 GtkTextIter iter;
4350 int wrapped_lines; 4401 int wrapped_lines;
4351 int lines; 4402 int lines;
4378 gtkconv->auto_resize = TRUE; 4429 gtkconv->auto_resize = TRUE;
4379 g_idle_add(reset_auto_resize_cb, gtkconv); 4430 g_idle_add(reset_auto_resize_cb, gtkconv);
4380 4431
4381 diff = height - gtkconv->entry->allocation.height; 4432 diff = height - gtkconv->entry->allocation.height;
4382 4433
4383 gtk_widget_size_request(gtkconv->lower_hbox, &sr); 4434 if (diff > 0) {
4384 gtkconv->entry_growing = TRUE; 4435 gtk_widget_size_request(gtkconv->lower_hbox, &sr);
4385 4436 gtkconv->entry_growing = TRUE;
4386 gtk_widget_set_size_request(gtkconv->lower_hbox, -1, 4437
4387 diff + gtkconv->lower_hbox->allocation.height); 4438 /* uncomment this to auto resize even after the user manually
4388 return FALSE; 4439 resizes
4440 gtk_paned_set_position(GTK_PANED(gtkconv->lower_hbox->parent->parent),
4441 -1);
4442 */
4443 gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
4444 diff + gtkconv->lower_hbox->allocation.height);
4445 }
4389 } 4446 }
4390 4447
4391 static void 4448 static void
4392 setup_chat_topic(PidginConversation *gtkconv, GtkWidget *vbox) 4449 setup_chat_topic(PidginConversation *gtkconv, GtkWidget *vbox)
4393 { 4450 {
4653 } 4710 }
4654 4711
4655 static GtkWidget * 4712 static GtkWidget *
4656 setup_common_pane(PidginConversation *gtkconv) 4713 setup_common_pane(PidginConversation *gtkconv)
4657 { 4714 {
4658 GtkWidget *vbox, *frame, *imhtml_sw, *event_box; 4715 GtkWidget *paned, *vbox, *frame, *imhtml_sw, *event_box;
4659 GtkCellRenderer *rend; 4716 GtkCellRenderer *rend;
4660 GtkTreePath *path; 4717 GtkTreePath *path;
4661 PurpleConversation *conv = gtkconv->active_conv; 4718 PurpleConversation *conv = gtkconv->active_conv;
4662 gboolean chat = (conv->type == PURPLE_CONV_TYPE_CHAT); 4719 gboolean chat = (conv->type == PURPLE_CONV_TYPE_CHAT);
4663 GtkPolicyType imhtml_sw_hscroll; 4720 GtkPolicyType imhtml_sw_hscroll;
4664 4721
4722 paned = gtk_vpaned_new();
4723 gtk_widget_show(paned);
4724
4665 /* Setup the top part of the pane */ 4725 /* Setup the top part of the pane */
4666 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); 4726 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
4727 gtk_paned_pack1(GTK_PANED(paned), vbox, TRUE, TRUE);
4667 gtk_widget_show(vbox); 4728 gtk_widget_show(vbox);
4668 4729
4669 /* Setup the info pane */ 4730 /* Setup the info pane */
4670 event_box = gtk_event_box_new(); 4731 event_box = gtk_event_box_new();
4671 #if GTK_CHECK_VERSION(2,4,0) 4732 #if GTK_CHECK_VERSION(2,4,0)
4756 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event", 4817 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_press_event",
4757 G_CALLBACK(refocus_entry_cb), gtkconv); 4818 G_CALLBACK(refocus_entry_cb), gtkconv);
4758 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event", 4819 g_signal_connect(G_OBJECT(gtkconv->imhtml), "key_release_event",
4759 G_CALLBACK(refocus_entry_cb), gtkconv); 4820 G_CALLBACK(refocus_entry_cb), gtkconv);
4760 4821
4822 /* Setup the bottom half of the conversation window */
4823 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
4824 gtk_paned_pack2(GTK_PANED(paned), vbox, FALSE, TRUE);
4825 gtk_widget_show(vbox);
4826
4761 gtkconv->lower_hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); 4827 gtkconv->lower_hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
4762 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->lower_hbox, FALSE, FALSE, 0); 4828 gtk_box_pack_start(GTK_BOX(vbox), gtkconv->lower_hbox, TRUE, TRUE, 0);
4763 gtk_widget_show(gtkconv->lower_hbox); 4829 gtk_widget_show(gtkconv->lower_hbox);
4830
4831 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
4832 gtk_box_pack_end(GTK_BOX(gtkconv->lower_hbox), vbox, TRUE, TRUE, 0);
4833 gtk_widget_show(vbox);
4764 4834
4765 /* Setup the toolbar, entry widget and all signals */ 4835 /* Setup the toolbar, entry widget and all signals */
4766 frame = pidgin_create_imhtml(TRUE, &gtkconv->entry, &gtkconv->toolbar, NULL); 4836 frame = pidgin_create_imhtml(TRUE, &gtkconv->entry, &gtkconv->toolbar, NULL);
4767 gtk_box_pack_start(GTK_BOX(gtkconv->lower_hbox), frame, TRUE, TRUE, 0); 4837 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
4768 gtk_widget_show(frame); 4838 gtk_widget_show(frame);
4769 4839
4770 gtk_widget_set_name(gtkconv->entry, "pidgin_conv_entry"); 4840 gtk_widget_set_name(gtkconv->entry, "pidgin_conv_entry");
4771 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry), 4841 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
4772 purple_account_get_protocol_name(conv->account)); 4842 purple_account_get_protocol_name(conv->account));
4843 gtk_widget_set_size_request(gtkconv->lower_hbox, -1,
4844 chat ? purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/chat/entry_height") :
4845 purple_prefs_get_int(PIDGIN_PREFS_ROOT "/conversations/im/entry_height"));
4773 4846
4774 g_signal_connect(G_OBJECT(gtkconv->entry), "populate-popup", 4847 g_signal_connect(G_OBJECT(gtkconv->entry), "populate-popup",
4775 G_CALLBACK(entry_popup_menu_cb), gtkconv); 4848 G_CALLBACK(entry_popup_menu_cb), gtkconv);
4776 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event", 4849 g_signal_connect(G_OBJECT(gtkconv->entry), "key_press_event",
4777 G_CALLBACK(entry_key_press_cb), gtkconv); 4850 G_CALLBACK(entry_key_press_cb), gtkconv);
4778 g_signal_connect_after(G_OBJECT(gtkconv->entry), "message_send", 4851 g_signal_connect_after(G_OBJECT(gtkconv->entry), "message_send",
4779 G_CALLBACK(send_cb), gtkconv); 4852 G_CALLBACK(send_cb), gtkconv);
4780 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event", 4853 g_signal_connect_after(G_OBJECT(gtkconv->entry), "button_press_event",
4781 G_CALLBACK(entry_stop_rclick_cb), NULL); 4854 G_CALLBACK(entry_stop_rclick_cb), NULL);
4855 g_signal_connect(G_OBJECT(gtkconv->lower_hbox), "size-allocate",
4856 G_CALLBACK(size_allocate_cb), gtkconv);
4782 4857
4783 gtkconv->entry_buffer = 4858 gtkconv->entry_buffer =
4784 gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry)); 4859 gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
4785 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", gtkconv); 4860 g_object_set_data(G_OBJECT(gtkconv->entry_buffer), "user_data", gtkconv);
4786 4861
4799 G_CALLBACK(resize_imhtml_cb), gtkconv); 4874 G_CALLBACK(resize_imhtml_cb), gtkconv);
4800 4875
4801 default_formatize(gtkconv); 4876 default_formatize(gtkconv);
4802 g_signal_connect_after(G_OBJECT(gtkconv->entry), "format_function_clear", 4877 g_signal_connect_after(G_OBJECT(gtkconv->entry), "format_function_clear",
4803 G_CALLBACK(clear_formatting_cb), gtkconv); 4878 G_CALLBACK(clear_formatting_cb), gtkconv);
4804 return vbox; 4879 return paned;
4805 } 4880 }
4806 4881
4807 static void 4882 static void
4808 conv_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, 4883 conv_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
4809 GtkSelectionData *sd, guint info, guint t, 4884 GtkSelectionData *sd, guint info, guint t,