changeset 2942:1a59a0ced6a8 trunk

make scrolling stop for second when it reaches end, replace remaining mainwin TextBox with UiSkinnedTextbox
author Tomasz Mon <desowin@gmail.com>
date Sat, 30 Jun 2007 18:44:20 +0200
parents d9a2434375f1
children a8f2c99727eb
files src/audacious/genevent.c src/audacious/ui_main.c src/audacious/ui_main.h src/audacious/ui_skinned_textbox.c src/audacious/ui_skinned_textbox.h
diffstat 5 files changed, 107 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/genevent.c	Fri Jun 29 08:58:32 2007 -0500
+++ b/src/audacious/genevent.c	Sat Jun 30 18:44:20 2007 +0200
@@ -55,6 +55,7 @@
 #include "pluginenum.h"
 #include "ui_main.h"
 #include "ui_playlist.h"
+#include "ui_skinned_textbox.h"
 #include "util.h"
 #include "visualization.h"
 #include "vfs.h"
@@ -91,10 +92,10 @@
             gchar time_str[5];
 
             g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft / 60);
-            textbox_set_text(mainwin_stime_min, time_str);
+            ui_skinned_textbox_set_text(mainwin_stime_min, time_str);
 
             g_snprintf(time_str, sizeof(time_str), "%2.2d", timeleft % 60);
-            textbox_set_text(mainwin_stime_sec, time_str);
+            ui_skinned_textbox_set_text(mainwin_stime_sec, time_str);
         }
 
         playlistwin_set_time(timeleft * 1000, 0, TIMER_ELAPSED);
--- a/src/audacious/ui_main.c	Fri Jun 29 08:58:32 2007 -0500
+++ b/src/audacious/ui_main.c	Sat Jun 30 18:44:20 2007 +0200
@@ -138,9 +138,9 @@
 GtkWidget *mainwin_eq, *mainwin_pl;
 
 GtkWidget *mainwin_info;
-TextBox *mainwin_stime_min, *mainwin_stime_sec;
-
-static TextBox *mainwin_rate_text, *mainwin_freq_text, 
+GtkWidget *mainwin_stime_min, *mainwin_stime_sec;
+
+static GtkWidget *mainwin_rate_text, *mainwin_freq_text, 
     *mainwin_othertext;
 
 PlayStatus *mainwin_playstatus;
@@ -180,7 +180,7 @@
 
 static void set_timer_mode_menu_cb(TimerMode mode);
 static void set_timer_mode(TimerMode mode);
-
+static void change_timer_mode(void);
 static void mainwin_refresh_hints(void);
 
 void mainwin_position_motion_cb(gint pos);
@@ -285,14 +285,14 @@
         if (playback_get_playing())
     {
                 widget_show(WIDGET(mainwin_sposition));
-            widget_show(WIDGET(mainwin_stime_min));
-            widget_show(WIDGET(mainwin_stime_sec));
+            gtk_widget_show(mainwin_stime_min);
+            gtk_widget_show(mainwin_stime_sec);
     }
     else
     {
                 widget_hide(WIDGET(mainwin_sposition));
-            widget_hide(WIDGET(mainwin_stime_min));
-            widget_hide(WIDGET(mainwin_stime_sec));
+            gtk_widget_hide(mainwin_stime_min);
+            gtk_widget_hide(mainwin_stime_sec);
     }
 
     }
@@ -312,8 +312,8 @@
         gtk_widget_hide(mainwin_sfwd);
         gtk_widget_hide(mainwin_seject);
 
-        widget_hide(WIDGET(mainwin_stime_min));
-        widget_hide(WIDGET(mainwin_stime_sec));
+        gtk_widget_hide(mainwin_stime_min);
+        gtk_widget_hide(mainwin_stime_sec);
         widget_hide(WIDGET(mainwin_sposition));
 
         ui_skinned_textbox_set_scroll(mainwin_info, cfg.autoscroll);
@@ -599,11 +599,11 @@
 {
     if (mainwin_info_text_locked != TRUE)
         mainwin_tb_old_text = g_strdup(bmp_active_skin->properties.mainwin_othertext_is_status ?
-        mainwin_othertext->tb_text : UI_SKINNED_TEXTBOX(mainwin_info)->text);
+        UI_SKINNED_TEXTBOX(mainwin_othertext)->text : UI_SKINNED_TEXTBOX(mainwin_info)->text);
 
     mainwin_info_text_locked = TRUE;
     if (bmp_active_skin->properties.mainwin_othertext_is_status)
-        textbox_set_text(mainwin_othertext, text);
+        ui_skinned_textbox_set_text(mainwin_othertext, text);
     else
         ui_skinned_textbox_set_text(mainwin_info, text);
 }
@@ -616,7 +616,7 @@
     if (mainwin_tb_old_text != NULL)
     {
         if (bmp_active_skin->properties.mainwin_othertext_is_status)
-            textbox_set_text(mainwin_othertext, mainwin_tb_old_text);
+            ui_skinned_textbox_set_text(mainwin_othertext, mainwin_tb_old_text);
         else
             ui_skinned_textbox_set_text(mainwin_info, mainwin_tb_old_text);
         g_free(mainwin_tb_old_text);
@@ -651,19 +651,19 @@
     if (bmp_active_skin && bmp_active_skin->properties.mainwin_othertext
     == TRUE)
     {
-    widget_hide(WIDGET(mainwin_rate_text));
-    widget_hide(WIDGET(mainwin_freq_text));
+    gtk_widget_hide(mainwin_rate_text);
+    gtk_widget_hide(mainwin_freq_text);
     widget_hide(WIDGET(mainwin_monostereo));
 
     if (bmp_active_skin->properties.mainwin_othertext_visible)
-        widget_show(WIDGET(mainwin_othertext));
+        gtk_widget_show(mainwin_othertext);
     }
     else
     {
-    widget_show(WIDGET(mainwin_rate_text));
-    widget_show(WIDGET(mainwin_freq_text));
+    gtk_widget_show(mainwin_rate_text);
+    gtk_widget_show(mainwin_freq_text);
     widget_show(WIDGET(mainwin_monostereo));
-    widget_hide(WIDGET(mainwin_othertext));
+    gtk_widget_hide(mainwin_othertext);
     }
 
     /* positioning and size attributes */
@@ -684,7 +684,7 @@
         UI_SKINNED_TEXTBOX(mainwin_info)->height*(1+cfg.doublesize));
 
     if (bmp_active_skin->properties.mainwin_infobar_x && bmp_active_skin->properties.mainwin_infobar_y)
-    widget_move(WIDGET(mainwin_othertext), bmp_active_skin->properties.mainwin_infobar_x,
+    gtk_fixed_move(GTK_FIXED(SKINNED_WINDOW(mainwin)->fixed), GTK_WIDGET(mainwin_othertext), bmp_active_skin->properties.mainwin_infobar_x,
         bmp_active_skin->properties.mainwin_infobar_y);
 
     if (bmp_active_skin->properties.mainwin_number_0_x && bmp_active_skin->properties.mainwin_number_0_y)
@@ -791,9 +791,9 @@
         gtk_widget_hide(mainwin_info);
 
     if (bmp_active_skin->properties.mainwin_othertext_visible)
-        widget_show(WIDGET(mainwin_othertext));
+        gtk_widget_show(mainwin_othertext);
     else
-        widget_hide(WIDGET(mainwin_othertext));
+        gtk_widget_hide(mainwin_othertext);
 
     if (bmp_active_skin->properties.mainwin_vis_visible)
         widget_show(WIDGET(mainwin_vis));
@@ -807,8 +807,8 @@
         gtk_widget_hide(mainwin_sstop);
         gtk_widget_hide(mainwin_sfwd);
         gtk_widget_hide(mainwin_seject);
-        widget_hide(WIDGET(mainwin_stime_min));
-        widget_hide(WIDGET(mainwin_stime_sec));
+        gtk_widget_hide(mainwin_stime_min);
+        gtk_widget_hide(mainwin_stime_sec);
     }
 
     /* window size, mainwinWidth && mainwinHeight properties */
@@ -858,27 +858,27 @@
         if (bitrate < 1000) {
             /* Show bitrate in 1000s */
             g_snprintf(text, sizeof(text), "%3d", bitrate);
-            textbox_set_text(mainwin_rate_text, text);
+            ui_skinned_textbox_set_text(mainwin_rate_text, text);
         }
         else {
             /* Show bitrate in 100,000s */
             g_snprintf(text, sizeof(text), "%2dH", bitrate / 100);
-            textbox_set_text(mainwin_rate_text, text);
+            ui_skinned_textbox_set_text(mainwin_rate_text, text);
         }
     }
     else
-        textbox_set_text(mainwin_rate_text, _("VBR"));
+        ui_skinned_textbox_set_text(mainwin_rate_text, _("VBR"));
 
     /* Show sampling frequency in kHz */
     g_snprintf(text, sizeof(text), "%2d", frequency / 1000);
-    textbox_set_text(mainwin_freq_text, text);
+    ui_skinned_textbox_set_text(mainwin_freq_text, text);
 
     monostereo_set_num_channels(mainwin_monostereo, n_channels);
 
     if (cfg.player_shaded)
     {
-        widget_show(WIDGET(mainwin_stime_min));
-        widget_show(WIDGET(mainwin_stime_sec));
+        gtk_widget_show(mainwin_stime_min);
+        gtk_widget_show(mainwin_stime_sec);
     }
 
     widget_show(WIDGET(mainwin_minus_num));
@@ -914,21 +914,21 @@
             (gfloat) frequency / 1000,
             (n_channels > 1) ? _("stereo") : _("mono"));
 
-        textbox_set_text(mainwin_othertext, text);
-
-        widget_hide(WIDGET(mainwin_rate_text));
-        widget_hide(WIDGET(mainwin_freq_text));
+        ui_skinned_textbox_set_text(mainwin_othertext, text);
+
+        gtk_widget_hide(mainwin_rate_text);
+        gtk_widget_hide(mainwin_freq_text);
         widget_hide(WIDGET(mainwin_monostereo));
 
         if (bmp_active_skin->properties.mainwin_othertext_visible)
-            widget_show(WIDGET(mainwin_othertext));
+            gtk_widget_show(mainwin_othertext);
     }
     else
     {
-        widget_show(WIDGET(mainwin_rate_text));
-        widget_show(WIDGET(mainwin_freq_text));
+        gtk_widget_show(mainwin_rate_text);
+        gtk_widget_show(mainwin_freq_text);
         widget_show(WIDGET(mainwin_monostereo));
-        widget_hide(WIDGET(mainwin_othertext));
+        gtk_widget_hide(mainwin_othertext);
     }
 
     title = playlist_get_info_text(playlist);
@@ -955,8 +955,8 @@
     mainwin_sposition->hs_pressed = FALSE;
 
     /* clear sampling parameter displays */
-    textbox_set_text(mainwin_rate_text, "   ");
-    textbox_set_text(mainwin_freq_text, "  ");
+    ui_skinned_textbox_set_text(mainwin_rate_text, "   ");
+    ui_skinned_textbox_set_text(mainwin_freq_text, "  ");
     monostereo_set_num_channels(mainwin_monostereo, 0);
 
     if (mainwin_playstatus != NULL)
@@ -969,13 +969,13 @@
     widget_hide(WIDGET(mainwin_10sec_num));
     widget_hide(WIDGET(mainwin_sec_num));
 
-    widget_hide(WIDGET(mainwin_stime_min));
-    widget_hide(WIDGET(mainwin_stime_sec));
+    gtk_widget_hide(mainwin_stime_min);
+    gtk_widget_hide(mainwin_stime_sec);
 
     widget_hide(WIDGET(mainwin_position));
     widget_hide(WIDGET(mainwin_sposition));
 
-    widget_hide(WIDGET(mainwin_othertext));
+    gtk_widget_hide(mainwin_othertext);
 
     playlistwin_hide_timer();
     draw_main_window(TRUE);
@@ -1180,14 +1180,11 @@
         widget_contains(WIDGET(mainwin_10min_num), event->x, event->y) ||
         widget_contains(WIDGET(mainwin_min_num), event->x, event->y) ||
         widget_contains(WIDGET(mainwin_10sec_num), event->x, event->y) ||
-        widget_contains(WIDGET(mainwin_sec_num), event->x, event->y) ||
-        widget_contains(WIDGET(mainwin_stime_min), event->x, event->y) ||
-        widget_contains(WIDGET(mainwin_stime_sec), event->x, event->y))
+        widget_contains(WIDGET(mainwin_sec_num), event->x, event->y))// ||
+        //widget_contains(WIDGET(mainwin_stime_min), event->x, event->y) ||
+        //widget_contains(WIDGET(mainwin_stime_sec), event->x, event->y))
     {
-            if (cfg.timer_mode == TIMER_ELAPSED)
-                set_timer_mode(TIMER_REMAINING);
-            else
-                set_timer_mode(TIMER_ELAPSED);
+        change_timer_mode();
         }
     }
 
@@ -1755,17 +1752,17 @@
     if (cfg.timer_mode == TIMER_REMAINING) {
         time = (playlist_get_current_length(playlist) / 1000) - time;
         time_msg = g_strdup_printf("-%2.2d", time / 60);
-        textbox_set_text(mainwin_stime_min, time_msg);
+        ui_skinned_textbox_set_text(mainwin_stime_min, time_msg);
         g_free(time_msg);
     }
     else {
         time_msg = g_strdup_printf(" %2.2d", time / 60);
-        textbox_set_text(mainwin_stime_min, time_msg);
+        ui_skinned_textbox_set_text(mainwin_stime_min, time_msg);
         g_free(time_msg);
     }
 
     time_msg = g_strdup_printf("%2.2d", time % 60);
-    textbox_set_text(mainwin_stime_sec, time_msg);
+    ui_skinned_textbox_set_text(mainwin_stime_sec, time_msg);
     g_free(time_msg);
 }
 
@@ -2529,6 +2526,13 @@
     cfg.timer_mode = mode;
 }
 
+void change_timer_mode(void) {
+    if (cfg.timer_mode == TIMER_ELAPSED)
+        set_timer_mode(TIMER_REMAINING);
+    else
+        set_timer_mode(TIMER_ELAPSED);
+}
+
 static void
 mainwin_playlist_prev(void)
 {
@@ -2841,15 +2845,16 @@
     g_signal_connect(mainwin_info, "double-clicked", mainwin_info_double_clicked_cb, NULL);
     g_signal_connect(mainwin_info, "right-clicked", mainwin_info_right_clicked_cb, NULL);
 
-    mainwin_othertext =
-    create_textbox(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 112, 43, 
-            153, 1, SKIN_TEXT);
-
-    mainwin_rate_text =
-        create_textbox(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 111, 43, 15,
+    mainwin_othertext = ui_skinned_textbox_new();
+    ui_skinned_textbox_setup(mainwin_othertext, SKINNED_WINDOW(mainwin)->fixed, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 112, 43,
+                      153, 1, SKIN_TEXT);
+
+    mainwin_rate_text = ui_skinned_textbox_new();
+    ui_skinned_textbox_setup(mainwin_rate_text, SKINNED_WINDOW(mainwin)->fixed, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 111, 43, 15,
                        0, SKIN_TEXT);
-    mainwin_freq_text =
-        create_textbox(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 156, 43, 10,
+
+    mainwin_freq_text = ui_skinned_textbox_new();
+    ui_skinned_textbox_setup(mainwin_freq_text, SKINNED_WINDOW(mainwin)->fixed, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 156, 43, 10,
                        0, SKIN_TEXT);
 
     mainwin_menurow =
@@ -2926,12 +2931,15 @@
                        mainwin_spos_release_cb, SKIN_TITLEBAR);
     widget_hide(WIDGET(mainwin_sposition));
 
-    mainwin_stime_min =
-        create_textbox(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 130, 4, 15,
+    mainwin_stime_min = ui_skinned_textbox_new();
+    ui_skinned_textbox_setup(mainwin_stime_min, SKINNED_WINDOW(mainwin)->fixed, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 130, 4, 15,
                        FALSE, SKIN_TEXT);
-    mainwin_stime_sec =
-        create_textbox(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 147, 4, 10,
+    g_signal_connect(mainwin_stime_min, "clicked", change_timer_mode, NULL);
+
+    mainwin_stime_sec = ui_skinned_textbox_new();
+    ui_skinned_textbox_setup(mainwin_stime_sec, SKINNED_WINDOW(mainwin)->fixed, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 147, 4, 10,
                        FALSE, SKIN_TEXT);
+    g_signal_connect(mainwin_stime_sec, "clicked", change_timer_mode, NULL);
 
     err = gtk_message_dialog_new(GTK_WINDOW(mainwin), GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_MODAL,
                                  GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error in Audacious."));
@@ -2944,8 +2952,6 @@
 
     /* XXX: eventually update widgetcore API to not need this */
 
-    ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_othertext));
-
     ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_rate_text));
     ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_freq_text));
 
@@ -2968,9 +2974,6 @@
 
     ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_position));
     ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_sposition));
-
-    ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_stime_min));
-    ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_stime_sec));
 }
 
 static void
@@ -3094,11 +3097,11 @@
         gchar *time_str;
 
         time_str = g_strdup_printf("%c%2.2d", stime_prefix, t / 60);
-        textbox_set_text(mainwin_stime_min, time_str);
+        ui_skinned_textbox_set_text(mainwin_stime_min, time_str);
         g_free(time_str);
 
         time_str = g_strdup_printf("%2.2d", t % 60);
-        textbox_set_text(mainwin_stime_sec, time_str);
+        ui_skinned_textbox_set_text(mainwin_stime_sec, time_str);
         g_free(time_str);
     }
 
--- a/src/audacious/ui_main.h	Fri Jun 29 08:58:32 2007 -0500
+++ b/src/audacious/ui_main.h	Sat Jun 30 18:44:20 2007 +0200
@@ -101,7 +101,7 @@
 extern GtkWidget *mainwin_eq, *mainwin_pl;
 extern GtkWidget *mainwin_info;
 
-extern TextBox *mainwin_stime_min, *mainwin_stime_sec;
+extern GtkWidget *mainwin_stime_min, *mainwin_stime_sec;
 
 extern Vis *active_vis;
 extern Vis *mainwin_vis;
--- a/src/audacious/ui_skinned_textbox.c	Fri Jun 29 08:58:32 2007 -0500
+++ b/src/audacious/ui_skinned_textbox.c	Sat Jun 30 18:44:20 2007 +0200
@@ -37,6 +37,7 @@
 typedef struct _UiSkinnedTextboxPrivate UiSkinnedTextboxPrivate;
 
 enum {
+    CLICKED,
     DOUBLE_CLICKED,
     RIGHT_CLICKED,
     DOUBLED,
@@ -143,11 +144,17 @@
 
     container_class->add = ui_skinned_textbox_add;
 
+    klass->clicked = NULL;
     klass->double_clicked = NULL;
     klass->right_clicked = NULL;
     klass->doubled = ui_skinned_textbox_toggle_doublesize;
     klass->redraw = ui_skinned_textbox_redraw;
 
+    textbox_signals[CLICKED] = 
+        g_signal_new ("clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                      G_STRUCT_OFFSET (UiSkinnedTextboxClass, clicked), NULL, NULL,
+                      gtk_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
     textbox_signals[DOUBLE_CLICKED] = 
         g_signal_new ("double-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
                       G_STRUCT_OFFSET (UiSkinnedTextboxClass, double_clicked), NULL, NULL,
@@ -316,12 +323,16 @@
         textbox = UI_SKINNED_TEXTBOX(widget);
 
         if (event->button == 1) {
-            if (priv->scroll_allowed && (priv->pixmap_width > priv->w) && priv->is_scrollable) {
-                priv->is_dragging = TRUE;
-                textbox->redraw = TRUE;
-                priv->drag_off = priv->offset;
-                priv->drag_x = event->x;
-            }
+            if (priv->scroll_allowed) {
+                if ((priv->pixmap_width > priv->w) && priv->is_scrollable) {
+                    priv->is_dragging = TRUE;
+                    textbox->redraw = TRUE;
+                    priv->drag_off = priv->offset;
+                    priv->drag_x = event->x;
+                }
+            } else
+                g_signal_emit(widget, textbox_signals[CLICKED], 0);
+
         } else if (event->button == 3) {
             g_signal_emit(widget, textbox_signals[RIGHT_CLICKED], 0);
         }
@@ -577,8 +588,15 @@
         if (priv->scroll_back) priv->offset -= 1;
         else priv->offset += 1;
 
-        if (priv->offset >= (priv->pixmap_width - priv->w)) priv->scroll_back = TRUE;
-        if (priv->offset <= 0) priv->scroll_back = FALSE;
+        if (priv->offset >= (priv->pixmap_width - priv->w)) {
+            priv->scroll_back = TRUE;
+            /* There are 1 million microseconds per second */
+            g_usleep(1000000);
+        }
+        if (priv->offset <= 0) {
+            priv->scroll_back = FALSE;
+            g_usleep(1000000);
+        }
         ui_skinned_textbox_redraw(textbox);
     }
 
--- a/src/audacious/ui_skinned_textbox.h	Fri Jun 29 08:58:32 2007 -0500
+++ b/src/audacious/ui_skinned_textbox.h	Sat Jun 30 18:44:20 2007 +0200
@@ -44,9 +44,9 @@
 
 struct _UiSkinnedTextboxClass {
     GtkBinClass parent_class;
+    void (* clicked)        (UiSkinnedTextbox *textbox);
     void (* double_clicked) (UiSkinnedTextbox *textbox);
-    void (* right_clicked) (UiSkinnedTextbox *textbox);
-    void (* clicked)        (UiSkinnedTextbox *textbox);
+    void (* right_clicked)  (UiSkinnedTextbox *textbox);
     void (* doubled)        (UiSkinnedTextbox *textbox);
     void (* redraw)         (UiSkinnedTextbox *textbox);
 };