1 /*****************************************************************************
2 * MessagesWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 VideoLAN (Centrale Réseaux) and its contributors
7 * Authors: Eric Petit <titer@videolan.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
32 /* BeOS module headers */
33 #include "InterfaceWindow.h"
34 #include "MessagesWindow.h"
36 /*****************************************************************************
38 *****************************************************************************/
39 void MessagesView::Pulse()
41 bool isScrolling = false;
42 if( fScrollBar->LockLooper() )
45 fScrollBar->GetRange( &min, &max );
46 if( fScrollBar->Value() != max )
48 fScrollBar->UnlockLooper();
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 };
60 vlc_mutex_lock( p_sub->p_lock );
61 int i_stop = *p_sub->pi_stop;
62 vlc_mutex_unlock( p_sub->p_lock );
64 if( p_sub->i_start != i_stop )
66 for( i_start = p_sub->i_start;
68 i_start = (i_start+1) % VLC_MSG_QSIZE )
71 switch( p_sub->p_msg[i_start].i_type )
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;
79 switch( p_sub->p_msg[i_start].i_object_type )
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;
96 oldLength = TextLength();
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 );
108 vlc_mutex_lock( p_sub->p_lock );
109 p_sub->i_start = i_start;
110 vlc_mutex_unlock( p_sub->p_lock );
113 /* Scroll at the end unless the is user is scrolling or selecting something */
115 GetSelection( &start, &end );
116 if( !isScrolling && start == end && fScrollBar->LockLooper() )
119 fScrollBar->GetRange( &min, &max );
120 fScrollBar->SetValue( max );
121 fScrollBar->UnlockLooper();
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,
136 SetSizeLimits( 400, 2000, 200, 2000 );
138 p_sub = msg_Subscribe( p_intf );
140 BRect rect, textRect;
143 rect.right -= B_V_SCROLL_BAR_WIDTH;
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 );
156 /* start window thread in hidden state */
161 /*****************************************************************************
162 * MessagesWindow::~MessagesWindow
163 *****************************************************************************/
164 MessagesWindow::~MessagesWindow()
166 msg_Unsubscribe( p_intf, p_sub );
169 /*****************************************************************************
170 * MessagesWindow::FrameResized
171 *****************************************************************************/
172 void MessagesWindow::FrameResized( float width, float height )
174 BWindow::FrameResized( width, height );
175 BRect rect = fMessagesView->Bounds();
176 rect.InsetBy( 5, 5 );
177 fMessagesView->SetTextRect( rect );
180 /*****************************************************************************
181 * MessagesWindow::QuitRequested
182 *****************************************************************************/
183 bool MessagesWindow::QuitRequested()
189 /*****************************************************************************
190 * MessagesWindow::ReallyQuit
191 *****************************************************************************/
192 void MessagesWindow::ReallyQuit()