1 /*
2  * Audacious - a cross-platform multimedia player
3  * Copyright (c) 2007 Tomasz Moń
4  * Copyright (c) 2009-2011 John Lindgren
5  *
6  * Based on:
7  * BMP - Cross-platform multimedia player
8  * Copyright (C) 2003-2004  BMP development team.
9  * XMMS:
10  * Copyright (C) 1998-2003  XMMS development team.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; under version 3 of the License.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses>.
23  *
24  * The Audacious team does not consider modular code linking to
25  * Audacious or using our public API to be a derived work.
26  */
27 
28 #ifndef SKINS_UI_SKINNED_PLAYLIST_H
29 #define SKINS_UI_SKINNED_PLAYLIST_H
30 
31 #include <libaudcore/hook.h>
32 #include <libaudcore/mainloop.h>
33 #include <libaudcore/playlist.h>
34 
35 #include "widget.h"
36 
37 class PlaylistSlider;
38 
39 typedef SmartPtr<PangoFontDescription, pango_font_description_free> PangoFontDescPtr;
40 
41 class PlaylistWidget : public Widget
42 {
43 public:
44     PlaylistWidget (int width, int height, const char * font);
~PlaylistWidget()45     ~PlaylistWidget () { cancel_all (); }
46 
set_slider(PlaylistSlider * slider)47     void set_slider (PlaylistSlider * slider) { m_slider = slider; }
48     void resize (int width, int height);
49     void set_font (const char * m_font);
50     void refresh ();
51     bool handle_keypress (GdkEventKey * event);
52     void row_info (int * m_rows, int * m_first);
53     void scroll_to (int row);
54     void set_focused (int row);
55     void hover (int x, int y);
56     int hover_end ();
57 
58 private:
59     void draw (cairo_t * cr);
60     bool button_press (GdkEventButton * event);
61     bool button_release (GdkEventButton * event);
62     bool motion (GdkEventMotion * event);
63     bool leave ();
64 
65     void update_title ();
66     void calc_layout ();
67 
68     int calc_position (int y) const;
69     int adjust_position (bool relative, int position) const;
70 
71     void ensure_visible (int position);
72     void select_single (bool relative, int position);
73     void select_extend (bool relative, int position);
74     void select_slide (bool relative, int position);
75     void select_toggle (bool relative, int position);
76     void select_move (bool relative, int position);
77     void delete_selected ();
78 
79     void cancel_all ();
80     void scroll_timeout ();
81     void popup_trigger (int pos);
82     void popup_show ();
83     void popup_hide ();
84 
85     const Timer<PlaylistWidget>
86      scroll_timer {TimerRate::Hz10, this, & PlaylistWidget::scroll_timeout};
87 
88     PlaylistSlider * m_slider = nullptr;
89     PangoFontDescPtr m_font;
90     String m_title_text;
91 
92     Playlist m_playlist;
93     int m_length = 0;
94     int m_width = 0, m_height = 0, m_row_height = 1, m_offset = 0, m_rows = 0, m_first = 0;
95     int m_scroll = 0, m_hover = -1, m_drag = 0, m_popup_pos = -1;
96     QueuedFunc m_popup_timer;
97 };
98 
99 #endif
100