]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
+ src/libvlc.h: use KEY_SPACE instead of ' '
[vlc] / modules / gui / beos / MessagesWindow.cpp
1 /*****************************************************************************
2  * MessagesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
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., 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 "InterfaceWindow.h"
34 #include "MessagesWindow.h"
35
36 /*****************************************************************************
37  * MessagesView::Pulse
38  *****************************************************************************/
39 void MessagesView::Pulse()
40 {
41 #if 0
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 #endif
127 }
128
129 /*****************************************************************************
130  * MessagesWindow::MessagesWindow
131  *****************************************************************************/
132 MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
133                                 BRect frame, const char * name )
134         : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
135                B_NOT_ZOOMABLE )
136 {
137         this->p_intf = p_intf;
138
139     SetSizeLimits( 400, 2000, 200, 2000 );
140         
141         BRect rect, textRect;
142
143         rect = Bounds();
144         rect.right -= B_V_SCROLL_BAR_WIDTH;
145         textRect = rect;
146         textRect.InsetBy( 5, 5 );
147         fMessagesView = new MessagesView( p_intf,
148                                           rect, "messages", textRect,
149                                           B_FOLLOW_ALL, B_WILL_DRAW );
150         fMessagesView->MakeEditable( false );
151         fMessagesView->SetStylable( true );
152         fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
153                                        B_FOLLOW_ALL, false, true );
154         fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
155         AddChild( fScrollView );
156         
157     /* start window thread in hidden state */
158     Hide();
159     Show();
160 }
161
162 /*****************************************************************************
163  * MessagesWindow::~MessagesWindow
164  *****************************************************************************/
165 MessagesWindow::~MessagesWindow()
166 {
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 }