]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
b1058677f0963eabda189603d2a0bb77da184470
[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 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc/vlc.h>
34 #include <vlc_interface.h>
35
36 /* BeOS module headers */
37 #include "InterfaceWindow.h"
38 #include "MessagesWindow.h"
39
40 /*****************************************************************************
41  * MessagesView::Pulse
42  *****************************************************************************/
43 void MessagesView::Pulse()
44 {
45     bool isScrolling = false;
46     if( fScrollBar->LockLooper() )
47     {
48         float min, max;
49         fScrollBar->GetRange( &min, &max );
50         if( fScrollBar->Value() != max )
51             isScrolling = true;
52         fScrollBar->UnlockLooper();
53
54     }
55
56     int i_start, oldLength;
57     char * psz_module_type = NULL;
58     rgb_color red = { 200, 0, 0 };
59     rgb_color gray = { 150, 150, 150 };
60     rgb_color green = { 0, 150, 0 };
61     rgb_color orange = { 230, 180, 00 };
62     rgb_color color;
63
64     vlc_mutex_lock( p_sub->p_lock );
65     int i_stop = *p_sub->pi_stop;
66     vlc_mutex_unlock( p_sub->p_lock );
67
68     if( p_sub->i_start != i_stop )
69     {
70         for( i_start = p_sub->i_start;
71              i_start != i_stop;
72                  i_start = (i_start+1) % VLC_MSG_QSIZE )
73         {
74             /* Add message */
75             switch( p_sub->p_msg[i_start].i_type )
76             {
77                 case VLC_MSG_INFO: color = green; break;
78                 case VLC_MSG_WARN: color = orange; break;
79                 case VLC_MSG_ERR: color = red; break;
80                 case VLC_MSG_DBG: color = gray; break;
81             }
82
83             switch( p_sub->p_msg[i_start].i_object_type )
84             {
85                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
86                 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
87                 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
88                 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
89                 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
90                 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
91                 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
92                 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
93                 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
94                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
95                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
96             }
97
98             if( LockLooper() )
99             {
100                 oldLength = TextLength();
101                 BString string;
102                 string << p_sub->p_msg[i_start].psz_module
103                     << " " << psz_module_type << " : "
104                     << p_sub->p_msg[i_start].psz_msg << "\n";
105                 Insert( TextLength(), string.String(), strlen( string.String() ) );
106                 SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
107                 Draw( Bounds() );
108                 UnlockLooper();
109             }
110         }
111
112         vlc_mutex_lock( p_sub->p_lock );
113         p_sub->i_start = i_start;
114         vlc_mutex_unlock( p_sub->p_lock );
115     }
116
117     /* Scroll at the end unless the is user is scrolling or selecting something */
118     int32 start, end;
119     GetSelection( &start, &end );
120     if( !isScrolling && start == end && fScrollBar->LockLooper() )
121     {
122         float min, max;
123         fScrollBar->GetRange( &min, &max );
124         fScrollBar->SetValue( max );
125         fScrollBar->UnlockLooper();
126     }
127
128     BTextView::Pulse();
129 }
130
131 /*****************************************************************************
132  * MessagesWindow::MessagesWindow
133  *****************************************************************************/
134 MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
135                                 BRect frame, const char * name )
136     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
137                B_NOT_ZOOMABLE ),
138     p_intf(_p_intf)
139 {
140     SetSizeLimits( 400, 2000, 200, 2000 );
141
142     p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
143  
144     BRect rect, textRect;
145
146     rect = Bounds();
147     rect.right -= B_V_SCROLL_BAR_WIDTH;
148     textRect = rect;
149     textRect.InsetBy( 5, 5 );
150     fMessagesView = new MessagesView( p_sub,
151                                       rect, "messages", textRect,
152                                       B_FOLLOW_ALL, B_WILL_DRAW );
153     fMessagesView->MakeEditable( false );
154     fMessagesView->SetStylable( true );
155     fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
156                                    B_FOLLOW_ALL, false, true );
157     fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
158     AddChild( fScrollView );
159  
160     /* start window thread in hidden state */
161     Hide();
162     Show();
163 }
164
165 /*****************************************************************************
166  * MessagesWindow::~MessagesWindow
167  *****************************************************************************/
168 MessagesWindow::~MessagesWindow()
169 {
170      msg_Unsubscribe( p_intf, p_sub );
171 }
172
173 /*****************************************************************************
174  * MessagesWindow::FrameResized
175  *****************************************************************************/
176 void MessagesWindow::FrameResized( float width, float height )
177 {
178     BWindow::FrameResized( width, height );
179     BRect rect = fMessagesView->Bounds();
180     rect.InsetBy( 5, 5 );
181     fMessagesView->SetTextRect( rect );
182 }
183
184 /*****************************************************************************
185  * MessagesWindow::QuitRequested
186  *****************************************************************************/
187 bool MessagesWindow::QuitRequested()
188 {
189     Hide();
190     return false;
191 }
192
193 /*****************************************************************************
194  * MessagesWindow::ReallyQuit
195  *****************************************************************************/
196 void MessagesWindow::ReallyQuit()
197 {
198     Lock();
199     Hide();
200     Quit();
201 }