]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
modules/gui/beos/MessagesWindow.cpp : fixed a minor scrolling issue
[vlc] / modules / gui / beos / MessagesWindow.cpp
1 /*****************************************************************************
2  * MessagesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: MessagesWindow.cpp,v 1.11 2003/05/18 22:30:33 titer Exp $
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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/intf.h>
31
32 /* BeOS module headers */
33 #include "VlcWrapper.h"
34 #include "InterfaceWindow.h"
35 #include "MessagesWindow.h"
36
37 /*****************************************************************************
38  * MessagesView::Pulse
39  *****************************************************************************/
40 void MessagesView::Pulse()
41 {
42     bool isScrolling = false;
43     if( fScrollBar->LockLooper() )
44     {
45         float min, max;
46         fScrollBar->GetRange( &min, &max );
47         if( fScrollBar->Value() != max )
48             isScrolling = true;
49         fScrollBar->UnlockLooper();
50         
51     }
52
53     int i_start, oldLength;
54     char * psz_module_type = NULL;
55     rgb_color red = { 200, 0, 0 };
56     rgb_color gray = { 150, 150, 150 };
57     rgb_color green = { 0, 150, 0 };
58     rgb_color orange = { 230, 180, 00 };
59     rgb_color color;
60
61     vlc_mutex_lock( p_sub->p_lock );
62     int i_stop = *p_sub->pi_stop;
63     vlc_mutex_unlock( p_sub->p_lock );
64
65     if( p_sub->i_start != i_stop )
66     {
67         for( i_start = p_sub->i_start;
68              i_start != i_stop;
69                  i_start = (i_start+1) % VLC_MSG_QSIZE )
70         {
71             /* Add message */
72             switch( p_sub->p_msg[i_start].i_type )
73             {
74                 case VLC_MSG_INFO: color = green; break;
75                 case VLC_MSG_WARN: color = orange; break;
76                 case VLC_MSG_ERR: color = red; break;
77                 case VLC_MSG_DBG: color = gray; break;
78             }
79
80             switch( p_sub->p_msg[i_start].i_object_type )
81             {
82                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
83                 case VLC_OBJECT_VLC: psz_module_type = "vlc"; break;
84                 case VLC_OBJECT_MODULE: psz_module_type = "module"; break;
85                 case VLC_OBJECT_INTF: psz_module_type = "interface"; break;
86                 case VLC_OBJECT_PLAYLIST: psz_module_type = "playlist"; break;
87                 case VLC_OBJECT_ITEM: psz_module_type = "item"; break;
88                 case VLC_OBJECT_INPUT: psz_module_type = "input"; break;
89                 case VLC_OBJECT_DECODER: psz_module_type = "decoder"; break;
90                 case VLC_OBJECT_VOUT: psz_module_type = "video output"; break;
91                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
92                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
93             }
94
95             if( LockLooper() )
96             {
97                 oldLength = TextLength();
98                 BString string;
99                 string << p_sub->p_msg[i_start].psz_module
100                     << " " << psz_module_type << " : "
101                     << p_sub->p_msg[i_start].psz_msg << "\n";
102                 Insert( TextLength(), string.String(), strlen( string.String() ) );
103                 SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
104                 Draw( Bounds() );
105                     UnlockLooper();
106             }
107         }
108
109         vlc_mutex_lock( p_sub->p_lock );
110         p_sub->i_start = i_start;
111         vlc_mutex_unlock( p_sub->p_lock );
112     }
113
114     /* Scroll at the end unless the is user is scrolling or selecting something */
115     int32 start, end;
116     GetSelection( &start, &end );
117     if( !isScrolling && start == end && fScrollBar->LockLooper() )
118     {
119         float min, max;
120         fScrollBar->GetRange( &min, &max );
121         fScrollBar->SetValue( max );
122         fScrollBar->UnlockLooper();
123     }
124
125     BTextView::Pulse();
126 }
127
128 /*****************************************************************************
129  * MessagesWindow::MessagesWindow
130  *****************************************************************************/
131 MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
132                                 BRect frame, const char * name )
133         : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
134                B_NOT_ZOOMABLE )
135 {
136         this->p_intf = p_intf;
137
138     SetSizeLimits( 400, 2000, 200, 2000 );
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_intf,
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 }
167
168 /*****************************************************************************
169  * MessagesWindow::FrameResized
170  *****************************************************************************/
171 void MessagesWindow::FrameResized( float width, float height )
172 {
173     BWindow::FrameResized( width, height );
174     BRect rect = fMessagesView->Bounds();
175     rect.InsetBy( 5, 5 );
176     fMessagesView->SetTextRect( rect );
177 }
178
179 /*****************************************************************************
180  * MessagesWindow::QuitRequested
181  *****************************************************************************/
182 bool MessagesWindow::QuitRequested()
183 {
184     Hide();
185     return false;
186 }
187
188 /*****************************************************************************
189  * MessagesWindow::ReallyQuit
190  *****************************************************************************/
191 void MessagesWindow::ReallyQuit()
192 {
193     Lock();
194     Hide();
195     Quit();
196 }