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