comparison gtk/gtkstatusbox.c @ 15115:6cb9996fcc97

[gaim-migrate @ 17901] Rename gtkblist.c:_search_func to gtkutils.c:gaim_gtk_tree_view_search_equal_func. Use this in the buddylist, the statusbox dropdown and in the plugins dialog. This can also be used in the smiley-theme-list. Process Escape and Return key-presses in the statusbox dropdown. seanegan: I hope I didn't step on your toes O:-) committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 06 Dec 2006 07:24:41 +0000
parents c18c02aeb366
children 4bf1777efb1f
comparison
equal deleted inserted replaced
15114:c18c02aeb366 15115:6cb9996fcc97
1011 add_account_statuses(status_box, status_box->account); 1011 add_account_statuses(status_box, status_box->account);
1012 update_to_reflect_account_status(status_box, status_box->account, 1012 update_to_reflect_account_status(status_box, status_box->account,
1013 gaim_account_get_active_status(status_box->account)); 1013 gaim_account_get_active_status(status_box->account));
1014 } 1014 }
1015 gtk_tree_view_set_model(GTK_TREE_VIEW(status_box->tree_view), status_box->dropdown_store); 1015 gtk_tree_view_set_model(GTK_TREE_VIEW(status_box->tree_view), status_box->dropdown_store);
1016 gtk_tree_view_set_search_column(GTK_TREE_VIEW(status_box->tree_view), TEXT_COLUMN);
1016 } 1017 }
1017 1018
1018 static gboolean combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml) 1019 static gboolean combo_box_scroll_event_cb(GtkWidget *w, GdkEventScroll *event, GtkIMHtml *imhtml)
1019 { 1020 {
1020 gaim_gtk_status_box_popup(GTK_GAIM_STATUS_BOX(w)); 1021 gaim_gtk_status_box_popup(GTK_GAIM_STATUS_BOX(w));
1395 gconstpointer value, gpointer data) 1396 gconstpointer value, gpointer data)
1396 { 1397 {
1397 buddy_icon_set_cb(value, (GtkGaimStatusBox*) data); 1398 buddy_icon_set_cb(value, (GtkGaimStatusBox*) data);
1398 } 1399 }
1399 1400
1401 static void
1402 treeview_activate_current_selection(GtkGaimStatusBox *status_box, GtkTreePath *path)
1403 {
1404 if (status_box->active_row)
1405 gtk_tree_row_reference_free(status_box->active_row);
1406
1407 status_box->active_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(status_box->dropdown_store), path);
1408
1409 gaim_gtk_status_box_popdown (status_box);
1410 gtk_gaim_status_box_changed(status_box);
1411 }
1412
1400 static gboolean 1413 static gboolean
1401 treeview_button_release_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *status_box) 1414 treeview_button_release_cb(GtkWidget *widget, GdkEventButton *event, GtkGaimStatusBox *status_box)
1402 { 1415 {
1403 GtkTreePath *path = NULL; 1416 GtkTreePath *path = NULL;
1404 int ret; 1417 int ret;
1424 1437
1425 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (status_box->tree_view), 1438 ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (status_box->tree_view),
1426 event->x, event->y, 1439 event->x, event->y,
1427 &path, 1440 &path,
1428 NULL, NULL, NULL); 1441 NULL, NULL, NULL);
1429 1442
1430
1431 if (!ret) 1443 if (!ret)
1432 return TRUE; /* clicked outside window? */ 1444 return TRUE; /* clicked outside window? */
1433 1445
1434 if (status_box->active_row) 1446 treeview_activate_current_selection(status_box, path);
1435 gtk_tree_row_reference_free(status_box->active_row);
1436
1437 status_box->active_row = gtk_tree_row_reference_new(GTK_TREE_MODEL(status_box->dropdown_store), path);
1438 gtk_tree_path_free (path); 1447 gtk_tree_path_free (path);
1439
1440 gaim_gtk_status_box_popdown (status_box);
1441 gtk_gaim_status_box_changed(status_box);
1442 1448
1443 return TRUE; 1449 return TRUE;
1450 }
1451
1452 static gboolean
1453 treeview_key_press_event(GtkWidget *widget,
1454 GdkEventKey *event, GtkGaimStatusBox *box)
1455 {
1456 if (box->popup_in_progress) {
1457 if (event->keyval == GDK_Escape) {
1458 gaim_gtk_status_box_popdown(box);
1459 return TRUE;
1460 } else if (event->keyval == GDK_Return) {
1461 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(box->tree_view));
1462 GtkTreeIter iter;
1463 GtkTreePath *path;
1464
1465 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) {
1466 path = gtk_tree_model_get_path(GTK_TREE_MODEL(box->dropdown_store), &iter);
1467 treeview_activate_current_selection(box, path);
1468 gtk_tree_path_free (path);
1469 return TRUE;
1470 }
1471 }
1472 }
1473 return FALSE;
1444 } 1474 }
1445 1475
1446 static void 1476 static void
1447 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box) 1477 gtk_gaim_status_box_init (GtkGaimStatusBox *status_box)
1448 { 1478 {
1526 status_box->column = gtk_tree_view_column_new (); 1556 status_box->column = gtk_tree_view_column_new ();
1527 gtk_tree_view_append_column (GTK_TREE_VIEW (status_box->tree_view), 1557 gtk_tree_view_append_column (GTK_TREE_VIEW (status_box->tree_view),
1528 status_box->column); 1558 status_box->column);
1529 gtk_tree_view_column_pack_start(status_box->column, icon_rend, FALSE); 1559 gtk_tree_view_column_pack_start(status_box->column, icon_rend, FALSE);
1530 gtk_tree_view_column_pack_start(status_box->column, text_rend, TRUE); 1560 gtk_tree_view_column_pack_start(status_box->column, text_rend, TRUE);
1531 gtk_tree_view_column_set_attributes(GTK_CELL_LAYOUT(status_box->column), icon_rend, "pixbuf", ICON_COLUMN, NULL); 1561 gtk_tree_view_column_set_attributes(status_box->column, icon_rend, "pixbuf", ICON_COLUMN, NULL);
1532 gtk_tree_view_column_set_attributes(GTK_CELL_LAYOUT(status_box->column), text_rend, "markup", TEXT_COLUMN, NULL); 1562 gtk_tree_view_column_set_attributes(status_box->column, text_rend, "markup", TEXT_COLUMN, NULL);
1533 gtk_container_add(GTK_CONTAINER(status_box->scrolled_window), status_box->tree_view); 1563 gtk_container_add(GTK_CONTAINER(status_box->scrolled_window), status_box->tree_view);
1534 gtk_widget_show(status_box->tree_view); 1564 gtk_widget_show(status_box->tree_view);
1565 gtk_tree_view_set_search_column(GTK_TREE_VIEW(status_box->tree_view), TEXT_COLUMN);
1566 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(status_box->tree_view),
1567 gaim_gtk_tree_view_search_equal_func, NULL, NULL);
1535 1568
1536 #if GTK_CHECK_VERSION(2, 6, 0) 1569 #if GTK_CHECK_VERSION(2, 6, 0)
1537 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); 1570 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1538 #endif 1571 #endif
1539 1572
1580 1613
1581 g_signal_connect(G_OBJECT(status_box), "scroll_event", G_CALLBACK(combo_box_scroll_event_cb), NULL); 1614 g_signal_connect(G_OBJECT(status_box), "scroll_event", G_CALLBACK(combo_box_scroll_event_cb), NULL);
1582 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event", 1615 g_signal_connect(G_OBJECT(status_box->imhtml), "scroll_event",
1583 G_CALLBACK(imhtml_scroll_event_cb), status_box->imhtml); 1616 G_CALLBACK(imhtml_scroll_event_cb), status_box->imhtml);
1584 g_signal_connect(G_OBJECT(status_box->popup_window), "button_release_event", G_CALLBACK(treeview_button_release_cb), status_box); 1617 g_signal_connect(G_OBJECT(status_box->popup_window), "button_release_event", G_CALLBACK(treeview_button_release_cb), status_box);
1618 g_signal_connect(G_OBJECT(status_box->popup_window), "key_press_event", G_CALLBACK(treeview_key_press_event), status_box);
1585 1619
1586 #if GTK_CHECK_VERSION(2,6,0) 1620 #if GTK_CHECK_VERSION(2,6,0)
1587 gtk_tree_view_set_row_separator_func(GTK_TREE_VIEW(status_box->tree_view), dropdown_store_row_separator_func, NULL, NULL); 1621 gtk_tree_view_set_row_separator_func(GTK_TREE_VIEW(status_box->tree_view), dropdown_store_row_separator_func, NULL, NULL);
1588 #endif 1622 #endif
1589 1623