]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
6d2a2d342301101e7b355553243d4d75e017f0c6
[vlc] / modules / gui / beos / MessagesWindow.cpp
1 /*****************************************************************************
2  * MessagesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Eric Petit <titer@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /* BeOS headers */
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
27
28 /* VLC headers */
29 #include <vlc/vlc.h>
30 #include <vlc_interface.h>
31
32 /* BeOS module headers */
33 #include "InterfaceWindow.h"
34 #include "MessagesWindow.h"
35
36 /*****************************************************************************
37  * MessagesView::Pulse
38  *****************************************************************************/
39 void MessagesView::Pulse()
40 {
41     bool isScrolling = false;
42     if( fScrollBar->LockLooper() )
43     {
44         float min, max;
45         fScrollBar->GetRange( &min, &max );
46         if( fScrollBar->Value() != max )
47             isScrolling = true;
48         fScrollBar->UnlockLooper();
49
50     }
51
52     int i_start, oldLength;
53     char * psz_module_type = NULL;
54     rgb_color red = { 200, 0, 0 };
55     rgb_color gray = { 150, 150, 150 };
56     rgb_color green = { 0, 150, 0 };
57     rgb_color orange = { 230, 180, 00 };
58     rgb_color color;
59
60     vlc_mutex_lock( p_sub->p_lock );
61     int i_stop = *p_sub->pi_stop;
62     vlc_mutex_unlock( p_sub->p_lock );
63
64     if( p_sub->i_start != i_stop )
65     {
66         for( i_start = p_sub->i_start;
67              i_start != i_stop;
68                  i_start = (i_start+1) % VLC_MSG_QSIZE )
69         {
70             /* Add message */
71             switch( p_sub->p_msg[i_start].i_type )
72             {
73                 case VLC_MSG_INFO: color = green; break;
74                 case VLC_MSG_WARN: color = orange; break;
75                 case VLC_MSG_ERR: color = red; break;
76                 case VLC_MSG_DBG: color = gray; break;
77             }
78
79             switch( p_sub->p_msg[i_start].i_object_type )
80             {
81                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
82                 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
83                 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
84                 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
85                 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
86                 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
87                 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
88                 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
89                 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
90                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
91                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
92             }
93
94             if( LockLooper() )
95             {
96                 oldLength = TextLength();
97                 BString string;
98                 string << p_sub->p_msg[i_start].psz_module
99                     << " " << psz_module_type << " : "
100                     << p_sub->p_msg[i_start].psz_msg << "\n";
101                 Insert( TextLength(), string.String(), strlen( string.String() ) );
102                 SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
103                 Draw( Bounds() );
104                 UnlockLooper();
105             }
106         }
107
108         vlc_mutex_lock( p_sub->p_lock );
109         p_sub->i_start = i_start;
110         vlc_mutex_unlock( p_sub->p_lock );
111     }
112
113     /* Scroll at the end unless the is user is scrolling or selecting something */
114     int32 start, end;
115     GetSelection( &start, &end );
116     if( !isScrolling && start == end && fScrollBar->LockLooper() )
117     {
118         float min, max;
119         fScrollBar->GetRange( &min, &max );
120         fScrollBar->SetValue( max );
121         fScrollBar->UnlockLooper();
122     }
123
124     BTextView::Pulse();
125 }
126
127 /*****************************************************************************
128  * MessagesWindow::MessagesWindow
129  *****************************************************************************/
130 MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
131                                 BRect frame, const char * name )
132     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
133                B_NOT_ZOOMABLE ),
134     p_intf(_p_intf)
135 {
136     SetSizeLimits( 400, 2000, 200, 2000 );
137
138     p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
139     
140     BRect rect, textRect;
141
142     rect = Bounds();
143     rect.right -= B_V_SCROLL_BAR_WIDTH;
144     textRect = rect;
145     textRect.InsetBy( 5, 5 );
146     fMessagesView = new MessagesView( p_sub,
147                                       rect, "messages", textRect,
148                                       B_FOLLOW_ALL, B_WILL_DRAW );
149     fMessagesView->MakeEditable( false );
150     fMessagesView->SetStylable( true );
151     fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
152                                    B_FOLLOW_ALL, false, true );
153     fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
154     AddChild( fScrollView );
155     
156     /* start window thread in hidden state */
157     Hide();
158     Show();
159 }
160
161 /*****************************************************************************
162  * MessagesWindow::~MessagesWindow
163  *****************************************************************************/
164 MessagesWindow::~MessagesWindow()
165 {
166      msg_Unsubscribe( p_intf, p_sub );
167 }
168
169 /*****************************************************************************
170  * MessagesWindow::FrameResized
171  *****************************************************************************/
172 void MessagesWindow::FrameResized( float width, float height )
173 {
174     BWindow::FrameResized( width, height );
175     BRect rect = fMessagesView->Bounds();
176     rect.InsetBy( 5, 5 );
177     fMessagesView->SetTextRect( rect );
178 }
179
180 /*****************************************************************************
181  * MessagesWindow::QuitRequested
182  *****************************************************************************/
183 bool MessagesWindow::QuitRequested()
184 {
185     Hide();
186     return false;
187 }
188
189 /*****************************************************************************
190  * MessagesWindow::ReallyQuit
191  *****************************************************************************/
192 void MessagesWindow::ReallyQuit()
193 {
194     Lock();
195     Hide();
196     Quit();
197 }