]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
Added a window to see vlc messages.
[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.1 2003/01/25 20:15: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
27 /* VLC headers */
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30
31 /* BeOS module headers */
32 #include "VlcWrapper.h"
33 #include "MessagesWindow.h"
34
35 /*****************************************************************************
36  * MessagesWindow::MessagesWindow
37  *****************************************************************************/
38 MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
39                                 BRect frame, const char * name )
40         : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
41                B_NOT_ZOOMABLE )
42 {
43         this->p_intf = p_intf;
44         p_sub = p_intf->p_sys->p_sub;
45         
46         BRect rect, rect2;
47         
48         rect = Bounds();
49         rect.right -= B_V_SCROLL_BAR_WIDTH;
50         rect.bottom -= B_H_SCROLL_BAR_HEIGHT;
51         rect2 = rect;
52         rect2.InsetBy( 5, 5 );
53         fMessagesView = new BTextView( rect, "messages", rect2,
54                                        B_FOLLOW_ALL, B_WILL_DRAW );
55         fMessagesView->MakeEditable( false );
56         fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
57                                        B_FOLLOW_ALL, true, true );
58         fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
59         AddChild( fScrollView );
60         
61     /* start window thread in hidden state */
62     Hide();
63     Show();
64 }
65
66 /*****************************************************************************
67  * MessagesWindow::~MessagesWindow
68  *****************************************************************************/
69 MessagesWindow::~MessagesWindow()
70 {
71 }
72
73 /*****************************************************************************
74  * MessagesWindow::QuitRequested
75  *****************************************************************************/
76 bool MessagesWindow::QuitRequested()
77 {
78     Hide();
79     return false;
80 }
81
82 /*****************************************************************************
83  * MessagesWindow::ReallyQuit
84  *****************************************************************************/
85 void MessagesWindow::ReallyQuit()
86 {
87     Hide();
88     Quit();
89 }
90
91 /*****************************************************************************
92  * MessagesWindow::UpdateMessages
93  *****************************************************************************/
94 void MessagesWindow::UpdateMessages()
95 {
96     int i_start;
97     
98     vlc_mutex_lock( p_sub->p_lock );
99     int i_stop = *p_sub->pi_stop;
100     vlc_mutex_unlock( p_sub->p_lock );
101
102     if( p_sub->i_start != i_stop )
103     {
104         for( i_start = p_sub->i_start;
105              i_start != i_stop;
106              i_start = (i_start+1) % VLC_MSG_QSIZE )
107         {
108             /* Append all messages to log window */
109             /* textctrl->SetDefaultStyle( *dbg_attr );
110             (*textctrl) << p_sub->p_msg[i_start].psz_module; */
111
112             /* switch( p_sub->p_msg[i_start].i_type )
113             {
114             case VLC_MSG_INFO:
115                 (*textctrl) << ": ";
116                 textctrl->SetDefaultStyle( *info_attr );
117                 break;
118             case VLC_MSG_ERR:
119                 (*textctrl) << " error: ";
120                 textctrl->SetDefaultStyle( *err_attr );
121                 break;
122             case VLC_MSG_WARN:
123                 (*textctrl) << " warning: ";
124                 textctrl->SetDefaultStyle( *warn_attr );
125                 break;
126             case VLC_MSG_DBG:
127             default:
128                 (*textctrl) << " debug: ";
129                 break;
130             } */
131
132             /* Add message */
133             fMessagesView->LockLooper();
134             fMessagesView->Insert( p_sub->p_msg[i_start].psz_msg );
135             fMessagesView->Insert( "\n" );
136             fMessagesView->UnlockLooper();
137             
138             /* Scroll at the end */
139             fScrollBar->LockLooper();
140             float min, max;
141             fScrollBar->GetRange( &min, &max );
142             fScrollBar->SetValue( max );
143             fScrollBar->UnlockLooper();
144         }
145
146         vlc_mutex_lock( p_sub->p_lock );
147         p_sub->i_start = i_start;
148         vlc_mutex_unlock( p_sub->p_lock );
149     }
150 }