]> git.sesse.net Git - vlc/blob - modules/gui/beos/MessagesWindow.cpp
contrib: fix link flags for live555 on WinCE
[vlc] / modules / gui / beos / MessagesWindow.cpp
1 /*****************************************************************************
2  * MessagesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /* BeOS headers */
25 #include <InterfaceKit.h>
26 #include <SupportKit.h>
27
28 /* VLC headers */
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_interface.h>
35
36 /* BeOS module headers */
37 #include "InterfaceWindow.h"
38 #include "MessagesWindow.h"
39
40 /*****************************************************************************
41  * MessagesView::Pulse
42  *****************************************************************************/
43 void MessagesView::Pulse()
44 {
45     bool isScrolling = false;
46     if( fScrollBar->LockLooper() )
47     {
48         float min, max;
49         fScrollBar->GetRange( &min, &max );
50         if( fScrollBar->Value() != max )
51             isScrolling = true;
52         fScrollBar->UnlockLooper();
53
54     }
55
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 };
62     rgb_color color;
63
64     vlc_mutex_lock( p_sub->p_lock );
65     int i_stop = *p_sub->pi_stop;
66     vlc_mutex_unlock( p_sub->p_lock );
67
68     if( p_sub->i_start != i_stop )
69     {
70         for( i_start = p_sub->i_start;
71              i_start != i_stop;
72                  i_start = (i_start+1) % VLC_MSG_QSIZE )
73         {
74             /* Add message */
75             switch( p_sub->p_msg[i_start].i_type )
76             {
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;
81             }
82
83             psz_module_type = p_sub->p_msg[i_start].psz_object_type;
84
85             if( LockLooper() )
86             {
87                 oldLength = TextLength();
88                 BString string;
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 );
94                 Draw( Bounds() );
95                 UnlockLooper();
96             }
97         }
98
99         vlc_mutex_lock( p_sub->p_lock );
100         p_sub->i_start = i_start;
101         vlc_mutex_unlock( p_sub->p_lock );
102     }
103
104     /* Scroll at the end unless the is user is scrolling or selecting something */
105     int32 start, end;
106     GetSelection( &start, &end );
107     if( !isScrolling && start == end && fScrollBar->LockLooper() )
108     {
109         float min, max;
110         fScrollBar->GetRange( &min, &max );
111         fScrollBar->SetValue( max );
112         fScrollBar->UnlockLooper();
113     }
114
115     BTextView::Pulse();
116 }
117
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,
124                B_NOT_ZOOMABLE ),
125     p_intf(_p_intf)
126 {
127     SetSizeLimits( 400, 2000, 200, 2000 );
128
129     p_sub = msg_Subscribe( p_intf );
130  
131     BRect rect, textRect;
132
133     rect = Bounds();
134     rect.right -= B_V_SCROLL_BAR_WIDTH;
135     textRect = rect;
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 );
146  
147     /* start window thread in hidden state */
148     Hide();
149     Show();
150 }
151
152 /*****************************************************************************
153  * MessagesWindow::~MessagesWindow
154  *****************************************************************************/
155 MessagesWindow::~MessagesWindow()
156 {
157      msg_Unsubscribe( p_intf, p_sub );
158 }
159
160 /*****************************************************************************
161  * MessagesWindow::FrameResized
162  *****************************************************************************/
163 void MessagesWindow::FrameResized( float width, float height )
164 {
165     BWindow::FrameResized( width, height );
166     BRect rect = fMessagesView->Bounds();
167     rect.InsetBy( 5, 5 );
168     fMessagesView->SetTextRect( rect );
169 }
170
171 /*****************************************************************************
172  * MessagesWindow::QuitRequested
173  *****************************************************************************/
174 bool MessagesWindow::QuitRequested()
175 {
176     Hide();
177     return false;
178 }
179
180 /*****************************************************************************
181  * MessagesWindow::ReallyQuit
182  *****************************************************************************/
183 void MessagesWindow::ReallyQuit()
184 {
185     Lock();
186     Hide();
187     Quit();
188 }