1 /*****************************************************************************
2 * MessagesWindow.cpp: beos interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000, 2001 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
34 #include <vlc_interface.h>
36 /* BeOS module headers */
37 #include "InterfaceWindow.h"
38 #include "MessagesWindow.h"
40 /*****************************************************************************
42 *****************************************************************************/
43 void MessagesView::Pulse()
45 bool isScrolling = false;
46 if( fScrollBar->LockLooper() )
49 fScrollBar->GetRange( &min, &max );
50 if( fScrollBar->Value() != max )
52 fScrollBar->UnlockLooper();
56 int i_start, oldLength;
57 const 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 };
64 vlc_mutex_lock( p_sub->p_lock );
65 int i_stop = *p_sub->pi_stop;
66 vlc_mutex_unlock( p_sub->p_lock );
68 if( p_sub->i_start != i_stop )
70 for( i_start = p_sub->i_start;
72 i_start = (i_start+1) % VLC_MSG_QSIZE )
75 switch( p_sub->p_msg[i_start].i_type )
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;
83 psz_module_type = p_sub->p_msg[i_start].psz_object_type;
87 oldLength = TextLength();
89 string << p_sub->p_msg[i_start].psz_module
90 << " " << psz_module_type << " : "
91 << p_sub->p_msg[i_start].psz_msg << "\n";
92 Insert( TextLength(), string.String(), strlen( string.String() ) );
93 SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
99 vlc_mutex_lock( p_sub->p_lock );
100 p_sub->i_start = i_start;
101 vlc_mutex_unlock( p_sub->p_lock );
104 /* Scroll at the end unless the is user is scrolling or selecting something */
106 GetSelection( &start, &end );
107 if( !isScrolling && start == end && fScrollBar->LockLooper() )
110 fScrollBar->GetRange( &min, &max );
111 fScrollBar->SetValue( max );
112 fScrollBar->UnlockLooper();
118 /*****************************************************************************
119 * MessagesWindow::MessagesWindow
120 *****************************************************************************/
121 MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
122 BRect frame, const char * name )
123 : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
127 SetSizeLimits( 400, 2000, 200, 2000 );
129 p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
131 BRect rect, textRect;
134 rect.right -= B_V_SCROLL_BAR_WIDTH;
136 textRect.InsetBy( 5, 5 );
137 fMessagesView = new MessagesView( p_sub,
138 rect, "messages", textRect,
139 B_FOLLOW_ALL, B_WILL_DRAW );
140 fMessagesView->MakeEditable( false );
141 fMessagesView->SetStylable( true );
142 fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
143 B_FOLLOW_ALL, false, true );
144 fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
145 AddChild( fScrollView );
147 /* start window thread in hidden state */
152 /*****************************************************************************
153 * MessagesWindow::~MessagesWindow
154 *****************************************************************************/
155 MessagesWindow::~MessagesWindow()
157 msg_Unsubscribe( p_intf, p_sub );
160 /*****************************************************************************
161 * MessagesWindow::FrameResized
162 *****************************************************************************/
163 void MessagesWindow::FrameResized( float width, float height )
165 BWindow::FrameResized( width, height );
166 BRect rect = fMessagesView->Bounds();
167 rect.InsetBy( 5, 5 );
168 fMessagesView->SetTextRect( rect );
171 /*****************************************************************************
172 * MessagesWindow::QuitRequested
173 *****************************************************************************/
174 bool MessagesWindow::QuitRequested()
180 /*****************************************************************************
181 * MessagesWindow::ReallyQuit
182 *****************************************************************************/
183 void MessagesWindow::ReallyQuit()