pidgin/gtkstatusbox.c

branch
next.minor
changeset 29686
f9dee36112d0
parent 29217
903157b8f52b
parent 29628
7ba47b28bda9
child 29689
dee2d04f22bb
equal deleted inserted replaced
29285:3180b88b4c1b 29686:f9dee36112d0
1178 status_box->typing = purple_timeout_add_seconds(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box); 1178 status_box->typing = purple_timeout_add_seconds(TYPING_TIMEOUT, (GSourceFunc)remove_typing_cb, status_box);
1179 1179
1180 return FALSE; 1180 return FALSE;
1181 } 1181 }
1182 1182
1183 #if GTK_CHECK_VERSION(2,6,0)
1184 static gboolean 1183 static gboolean
1185 dropdown_store_row_separator_func(GtkTreeModel *model, 1184 dropdown_store_row_separator_func(GtkTreeModel *model,
1186 GtkTreeIter *iter, gpointer data) 1185 GtkTreeIter *iter, gpointer data)
1187 { 1186 {
1188 PidginStatusBoxItemType type; 1187 PidginStatusBoxItemType type;
1192 if (type == PIDGIN_STATUS_BOX_TYPE_SEPARATOR) 1191 if (type == PIDGIN_STATUS_BOX_TYPE_SEPARATOR)
1193 return TRUE; 1192 return TRUE;
1194 1193
1195 return FALSE; 1194 return FALSE;
1196 } 1195 }
1197 #endif
1198 1196
1199 static void 1197 static void
1200 cache_pixbufs(PidginStatusBox *status_box) 1198 cache_pixbufs(PidginStatusBox *status_box)
1201 { 1199 {
1202 GtkIconSize icon_size; 1200 GtkIconSize icon_size;
1303 #endif 1301 #endif
1304 1302
1305 static void 1303 static void
1306 pidgin_status_box_list_position (PidginStatusBox *status_box, int *x, int *y, int *width, int *height) 1304 pidgin_status_box_list_position (PidginStatusBox *status_box, int *x, int *y, int *width, int *height)
1307 { 1305 {
1308 #if GTK_CHECK_VERSION(2,2,0)
1309 GdkScreen *screen; 1306 GdkScreen *screen;
1310 gint monitor_num; 1307 gint monitor_num;
1311 GdkRectangle monitor; 1308 GdkRectangle monitor;
1312 #endif
1313 GtkRequisition popup_req; 1309 GtkRequisition popup_req;
1314 GtkPolicyType hpolicy, vpolicy; 1310 GtkPolicyType hpolicy, vpolicy;
1315 1311
1316 gdk_window_get_origin (GTK_WIDGET(status_box)->window, x, y); 1312 gdk_window_get_origin (GTK_WIDGET(status_box)->window, x, y);
1317 1313
1333 gtk_widget_size_request (status_box->popup_frame, &popup_req); 1329 gtk_widget_size_request (status_box->popup_frame, &popup_req);
1334 } 1330 }
1335 1331
1336 *height = popup_req.height; 1332 *height = popup_req.height;
1337 1333
1338 #if GTK_CHECK_VERSION(2,2,0)
1339 screen = gtk_widget_get_screen (GTK_WIDGET (status_box)); 1334 screen = gtk_widget_get_screen (GTK_WIDGET (status_box));
1340 monitor_num = gdk_screen_get_monitor_at_window (screen, 1335 monitor_num = gdk_screen_get_monitor_at_window (screen,
1341 GTK_WIDGET (status_box)->window); 1336 GTK_WIDGET (status_box)->window);
1342 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); 1337 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1343 1338
1366 vpolicy = GTK_POLICY_ALWAYS; 1361 vpolicy = GTK_POLICY_ALWAYS;
1367 1362
1368 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (status_box->scrolled_window), 1363 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (status_box->scrolled_window),
1369 hpolicy, vpolicy); 1364 hpolicy, vpolicy);
1370 } 1365 }
1371 #endif
1372 } 1366 }
1373 1367
1374 static gboolean 1368 static gboolean
1375 popup_grab_on_window (GdkWindow *window, 1369 popup_grab_on_window (GdkWindow *window,
1376 guint32 activate_time, 1370 guint32 activate_time,
1377 gboolean grab_keyboard) 1371 gboolean grab_keyboard)
1378 { 1372 {
1379 if ((gdk_pointer_grab (window, TRUE, 1373 if ((gdk_pointer_grab (window, TRUE,
1380 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 1374 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1381 GDK_POINTER_MOTION_MASK, 1375 GDK_POINTER_MOTION_MASK,
1382 NULL, NULL, activate_time) == 0)) 1376 NULL, NULL, activate_time) == 0))
1383 { 1377 {
1384 if (!grab_keyboard || 1378 if (!grab_keyboard || gdk_keyboard_grab (window, TRUE, activate_time) == 0)
1385 gdk_keyboard_grab (window, TRUE, 1379 return TRUE;
1386 activate_time) == 0) 1380 else {
1387 return TRUE; 1381 gdk_display_pointer_ungrab (gdk_drawable_get_display (window), activate_time);
1388 else 1382 return FALSE;
1389 { 1383 }
1390 #if GTK_CHECK_VERSION(2,2,0) 1384 }
1391 gdk_display_pointer_ungrab (gdk_drawable_get_display (window), 1385
1392 activate_time); 1386 return FALSE;
1393 #else
1394 gdk_pointer_ungrab(activate_time);
1395 gdk_keyboard_ungrab(activate_time);
1396 #endif
1397 return FALSE;
1398 }
1399 }
1400
1401 return FALSE;
1402 } 1387 }
1403 1388
1404 1389
1405 static void 1390 static void
1406 pidgin_status_box_popup(PidginStatusBox *box) 1391 pidgin_status_box_popup(PidginStatusBox *box)
1791 gtk_container_add(GTK_CONTAINER(status_box->toggle_button), status_box->hbox); 1776 gtk_container_add(GTK_CONTAINER(status_box->toggle_button), status_box->hbox);
1792 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->cell_view, TRUE, TRUE, 0); 1777 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->cell_view, TRUE, TRUE, 0);
1793 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0); 1778 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->vsep, FALSE, FALSE, 0);
1794 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0); 1779 gtk_box_pack_start(GTK_BOX(status_box->hbox), status_box->arrow, FALSE, FALSE, 0);
1795 gtk_widget_show_all(status_box->toggle_button); 1780 gtk_widget_show_all(status_box->toggle_button);
1796 #if GTK_CHECK_VERSION(2,4,0)
1797 gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE); 1781 gtk_button_set_focus_on_click(GTK_BUTTON(status_box->toggle_button), FALSE);
1798 #endif
1799 1782
1800 text_rend = gtk_cell_renderer_text_new(); 1783 text_rend = gtk_cell_renderer_text_new();
1801 icon_rend = gtk_cell_renderer_pixbuf_new(); 1784 icon_rend = gtk_cell_renderer_pixbuf_new();
1802 emblem_rend = gtk_cell_renderer_pixbuf_new(); 1785 emblem_rend = gtk_cell_renderer_pixbuf_new();
1803 status_box->popup_window = gtk_window_new (GTK_WINDOW_POPUP); 1786 status_box->popup_window = gtk_window_new (GTK_WINDOW_POPUP);
1807 gtk_window_set_transient_for (GTK_WINDOW (status_box->popup_window), 1790 gtk_window_set_transient_for (GTK_WINDOW (status_box->popup_window),
1808 GTK_WINDOW (toplevel)); 1791 GTK_WINDOW (toplevel));
1809 } 1792 }
1810 1793
1811 gtk_window_set_resizable (GTK_WINDOW (status_box->popup_window), FALSE); 1794 gtk_window_set_resizable (GTK_WINDOW (status_box->popup_window), FALSE);
1812 #if GTK_CHECK_VERSION(2,10,0)
1813 gtk_window_set_type_hint (GTK_WINDOW (status_box->popup_window), 1795 gtk_window_set_type_hint (GTK_WINDOW (status_box->popup_window),
1814 GDK_WINDOW_TYPE_HINT_POPUP_MENU); 1796 GDK_WINDOW_TYPE_HINT_POPUP_MENU);
1815 #endif
1816 #if GTK_CHECK_VERSION(2,2,0)
1817 gtk_window_set_screen (GTK_WINDOW (status_box->popup_window), 1797 gtk_window_set_screen (GTK_WINDOW (status_box->popup_window),
1818 gtk_widget_get_screen (GTK_WIDGET (status_box))); 1798 gtk_widget_get_screen (GTK_WIDGET (status_box)));
1819 #endif
1820 status_box->popup_frame = gtk_frame_new (NULL); 1799 status_box->popup_frame = gtk_frame_new (NULL);
1821 gtk_frame_set_shadow_type (GTK_FRAME (status_box->popup_frame), 1800 gtk_frame_set_shadow_type (GTK_FRAME (status_box->popup_frame),
1822 GTK_SHADOW_ETCHED_IN); 1801 GTK_SHADOW_ETCHED_IN);
1823 gtk_container_add (GTK_CONTAINER (status_box->popup_window), 1802 gtk_container_add (GTK_CONTAINER (status_box->popup_window),
1824 status_box->popup_frame); 1803 status_box->popup_frame);
1841 status_box->tree_view = gtk_tree_view_new (); 1820 status_box->tree_view = gtk_tree_view_new ();
1842 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (status_box->tree_view)); 1821 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (status_box->tree_view));
1843 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE); 1822 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
1844 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (status_box->tree_view), 1823 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (status_box->tree_view),
1845 FALSE); 1824 FALSE);
1846 #if GTK_CHECK_VERSION(2,6,0)
1847 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (status_box->tree_view), 1825 gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (status_box->tree_view),
1848 TRUE); 1826 TRUE);
1849 #endif
1850 gtk_tree_view_set_model (GTK_TREE_VIEW (status_box->tree_view), 1827 gtk_tree_view_set_model (GTK_TREE_VIEW (status_box->tree_view),
1851 GTK_TREE_MODEL(status_box->dropdown_store)); 1828 GTK_TREE_MODEL(status_box->dropdown_store));
1852 status_box->column = gtk_tree_view_column_new (); 1829 status_box->column = gtk_tree_view_column_new ();
1853 gtk_tree_view_append_column (GTK_TREE_VIEW (status_box->tree_view), 1830 gtk_tree_view_append_column (GTK_TREE_VIEW (status_box->tree_view),
1854 status_box->column); 1831 status_box->column);
1862 gtk_widget_show(status_box->tree_view); 1839 gtk_widget_show(status_box->tree_view);
1863 gtk_tree_view_set_search_column(GTK_TREE_VIEW(status_box->tree_view), TEXT_COLUMN); 1840 gtk_tree_view_set_search_column(GTK_TREE_VIEW(status_box->tree_view), TEXT_COLUMN);
1864 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(status_box->tree_view), 1841 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(status_box->tree_view),
1865 pidgin_tree_view_search_equal_func, NULL, NULL); 1842 pidgin_tree_view_search_equal_func, NULL, NULL);
1866 1843
1867 #if GTK_CHECK_VERSION(2, 6, 0)
1868 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); 1844 g_object_set(text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1869 #endif
1870 1845
1871 status_box->icon_rend = gtk_cell_renderer_pixbuf_new(); 1846 status_box->icon_rend = gtk_cell_renderer_pixbuf_new();
1872 status_box->text_rend = gtk_cell_renderer_text_new(); 1847 status_box->text_rend = gtk_cell_renderer_text_new();
1873 emblem_rend = gtk_cell_renderer_pixbuf_new(); 1848 emblem_rend = gtk_cell_renderer_pixbuf_new();
1874 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE); 1849 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, FALSE);
1875 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE); 1850 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, TRUE);
1876 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, FALSE); 1851 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, FALSE);
1877 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "stock-id", ICON_STOCK_COLUMN, NULL); 1852 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->icon_rend, "stock-id", ICON_STOCK_COLUMN, NULL);
1878 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL); 1853 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), status_box->text_rend, "markup", TEXT_COLUMN, NULL);
1879 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, "pixbuf", EMBLEM_COLUMN, "visible", EMBLEM_VISIBLE_COLUMN, NULL); 1854 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(status_box->cell_view), emblem_rend, "pixbuf", EMBLEM_COLUMN, "visible", EMBLEM_VISIBLE_COLUMN, NULL);
1880 #if GTK_CHECK_VERSION(2, 6, 0)
1881 g_object_set(status_box->text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL); 1855 g_object_set(status_box->text_rend, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
1882 #endif
1883 1856
1884 status_box->vbox = gtk_vbox_new(0, FALSE); 1857 status_box->vbox = gtk_vbox_new(0, FALSE);
1885 status_box->sw = pidgin_create_imhtml(FALSE, &status_box->imhtml, NULL, NULL); 1858 status_box->sw = pidgin_create_imhtml(FALSE, &status_box->imhtml, NULL, NULL);
1886 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE); 1859 gtk_imhtml_set_editable(GTK_IMHTML(status_box->imhtml), TRUE);
1887 1860
1922 g_signal_connect(G_OBJECT(status_box->popup_window), "button_release_event", G_CALLBACK(treeview_button_release_cb), status_box); 1895 g_signal_connect(G_OBJECT(status_box->popup_window), "button_release_event", G_CALLBACK(treeview_button_release_cb), status_box);
1923 g_signal_connect(G_OBJECT(status_box->popup_window), "key_press_event", G_CALLBACK(treeview_key_press_event), status_box); 1896 g_signal_connect(G_OBJECT(status_box->popup_window), "key_press_event", G_CALLBACK(treeview_key_press_event), status_box);
1924 g_signal_connect(G_OBJECT(status_box->tree_view), "cursor-changed", 1897 g_signal_connect(G_OBJECT(status_box->tree_view), "cursor-changed",
1925 G_CALLBACK(treeview_cursor_changed_cb), status_box->dropdown_store); 1898 G_CALLBACK(treeview_cursor_changed_cb), status_box->dropdown_store);
1926 1899
1927 #if GTK_CHECK_VERSION(2,6,0)
1928 gtk_tree_view_set_row_separator_func(GTK_TREE_VIEW(status_box->tree_view), dropdown_store_row_separator_func, NULL, NULL); 1900 gtk_tree_view_set_row_separator_func(GTK_TREE_VIEW(status_box->tree_view), dropdown_store_row_separator_func, NULL, NULL);
1929 #endif
1930 1901
1931 status_box->token_status_account = check_active_accounts_for_identical_statuses(); 1902 status_box->token_status_account = check_active_accounts_for_identical_statuses();
1932 1903
1933 cache_pixbufs(status_box); 1904 cache_pixbufs(status_box);
1934 pidgin_status_box_regenerate(status_box, TRUE); 1905 pidgin_status_box_regenerate(status_box, TRUE);
2208 void 2179 void
2209 pidgin_status_box_add_separator(PidginStatusBox *status_box) 2180 pidgin_status_box_add_separator(PidginStatusBox *status_box)
2210 { 2181 {
2211 /* Don't do anything unless GTK actually supports 2182 /* Don't do anything unless GTK actually supports
2212 * gtk_combo_box_set_row_separator_func */ 2183 * gtk_combo_box_set_row_separator_func */
2213 #if GTK_CHECK_VERSION(2,6,0)
2214 GtkTreeIter iter; 2184 GtkTreeIter iter;
2215 2185
2216 gtk_list_store_append(status_box->dropdown_store, &iter); 2186 gtk_list_store_append(status_box->dropdown_store, &iter);
2217 gtk_list_store_set(status_box->dropdown_store, &iter, 2187 gtk_list_store_set(status_box->dropdown_store, &iter,
2218 TYPE_COLUMN, PIDGIN_STATUS_BOX_TYPE_SEPARATOR, 2188 TYPE_COLUMN, PIDGIN_STATUS_BOX_TYPE_SEPARATOR,
2219 -1); 2189 -1);
2220 #endif
2221 } 2190 }
2222 2191
2223 void 2192 void
2224 pidgin_status_box_set_network_available(PidginStatusBox *status_box, gboolean available) 2193 pidgin_status_box_set_network_available(PidginStatusBox *status_box, gboolean available)
2225 { 2194 {
2239 } 2208 }
2240 2209
2241 static void 2210 static void
2242 pixbuf_size_prepared_cb(GdkPixbufLoader *loader, int width, int height, gpointer data) 2211 pixbuf_size_prepared_cb(GdkPixbufLoader *loader, int width, int height, gpointer data)
2243 { 2212 {
2244 #if GTK_CHECK_VERSION(2,2,0)
2245 int w, h; 2213 int w, h;
2246 GtkIconSize icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_MEDIUM); 2214 GtkIconSize icon_size = gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_MEDIUM);
2247 gtk_icon_size_lookup(icon_size, &w, &h); 2215 gtk_icon_size_lookup(icon_size, &w, &h);
2248 if (height > width) 2216 if (height > width)
2249 w = width * h / height; 2217 w = width * h / height;
2250 else if (width > height) 2218 else if (width > height)
2251 h = height * w / width; 2219 h = height * w / width;
2252 gdk_pixbuf_loader_set_size(loader, w, h); 2220 gdk_pixbuf_loader_set_size(loader, w, h);
2253 #endif
2254 } 2221 }
2255 2222
2256 static void 2223 static void
2257 pidgin_status_box_redisplay_buddy_icon(PidginStatusBox *status_box) 2224 pidgin_status_box_redisplay_buddy_icon(PidginStatusBox *status_box)
2258 { 2225 {

mercurial