]> git.sesse.net Git - vlc/blobdiff - modules/gui/beos/MessagesWindow.cpp
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / beos / MessagesWindow.cpp
index 716b56891083a95bb79c00ab347047011f3ac391..7884d55da7f681d5dc3ef7ba770b770c274251f6 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * MessagesWindow.cpp: beos interface
  *****************************************************************************
- * Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: MessagesWindow.cpp,v 1.5 2003/01/31 06:45:00 titer Exp $
+ * Copyright (C) 1999, 2000, 2001 the VideoLAN team
+ * $Id$
  *
  * Authors: Eric Petit <titer@videolan.org>
  *
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /* BeOS headers */
 
 /* VLC headers */
 #include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <vlc_interface.h>
 
 /* BeOS module headers */
-#include "VlcWrapper.h"
+#include "InterfaceWindow.h"
 #include "MessagesWindow.h"
 
 /*****************************************************************************
- * MessagesWindow::MessagesWindow
- *****************************************************************************/
-MessagesWindow::MessagesWindow( intf_thread_t * p_intf,
-                                BRect frame, const char * name )
-       : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
-               B_NOT_ZOOMABLE )
-{
-       this->p_intf = p_intf;
-       p_sub = p_intf->p_sys->p_sub;
-       
-       BRect rect, textRect;
-       
-       rect = Bounds();
-       rect.right -= B_V_SCROLL_BAR_WIDTH;
-       textRect = rect;
-       textRect.InsetBy( 5, 5 );
-       fMessagesView = new BTextView( rect, "messages", textRect,
-                                      B_FOLLOW_ALL, B_WILL_DRAW );
-       fMessagesView->MakeEditable( false );
-       fMessagesView->SetStylable( true );
-       fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
-                                      B_FOLLOW_ALL, false, true );
-       fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
-       AddChild( fScrollView );
-       
-    /* start window thread in hidden state */
-    Hide();
-    Show();
-}
-
-/*****************************************************************************
- * MessagesWindow::~MessagesWindow
- *****************************************************************************/
-MessagesWindow::~MessagesWindow()
-{
-}
-
-/*****************************************************************************
- * MessagesWindow::FrameResized
- *****************************************************************************/
-void MessagesWindow::FrameResized( float, float )
-{
-    BRect rect = fMessagesView->Bounds();
-    rect.InsetBy( 5, 5 );
-    fMessagesView->SetTextRect( rect );
-}
-
-/*****************************************************************************
- * MessagesWindow::QuitRequested
+ * MessagesView::Pulse
  *****************************************************************************/
-bool MessagesWindow::QuitRequested()
+void MessagesView::Pulse()
 {
-    Hide();
-    return false;
-}
+    bool isScrolling = false;
+    if( fScrollBar->LockLooper() )
+    {
+        float min, max;
+        fScrollBar->GetRange( &min, &max );
+        if( fScrollBar->Value() != max )
+            isScrolling = true;
+        fScrollBar->UnlockLooper();
 
-/*****************************************************************************
- * MessagesWindow::ReallyQuit
- *****************************************************************************/
-void MessagesWindow::ReallyQuit()
-{
-    Lock();
-    Hide();
-    Quit();
-}
+    }
 
-/*****************************************************************************
- * MessagesWindow::UpdateMessages
- *****************************************************************************/
-void MessagesWindow::UpdateMessages()
-{
     int i_start, oldLength;
     char * psz_module_type = NULL;
     rgb_color red = { 200, 0, 0 };
@@ -112,7 +56,7 @@ void MessagesWindow::UpdateMessages()
     rgb_color green = { 0, 150, 0 };
     rgb_color orange = { 230, 180, 00 };
     rgb_color color;
-    
+
     vlc_mutex_lock( p_sub->p_lock );
     int i_stop = *p_sub->pi_stop;
     vlc_mutex_unlock( p_sub->p_lock );
@@ -121,7 +65,7 @@ void MessagesWindow::UpdateMessages()
     {
         for( i_start = p_sub->i_start;
              i_start != i_stop;
-             i_start = (i_start+1) % VLC_MSG_QSIZE )
+                 i_start = (i_start+1) % VLC_MSG_QSIZE )
         {
             /* Add message */
             switch( p_sub->p_msg[i_start].i_type )
@@ -131,7 +75,7 @@ void MessagesWindow::UpdateMessages()
                 case VLC_MSG_ERR: color = red; break;
                 case VLC_MSG_DBG: color = gray; break;
             }
-            
+
             switch( p_sub->p_msg[i_start].i_object_type )
             {
                 case VLC_OBJECT_ROOT: psz_module_type = "root"; break;
@@ -146,26 +90,18 @@ void MessagesWindow::UpdateMessages()
                 case VLC_OBJECT_AOUT: psz_module_type = "audio output"; break;
                 case VLC_OBJECT_SOUT: psz_module_type = "stream output"; break;
             }
-            
-            fMessagesView->LockLooper();
-            oldLength = fMessagesView->TextLength();
-            BString string;
-            string << p_sub->p_msg[i_start].psz_module << " " << psz_module_type << " : " <<
-                p_sub->p_msg[i_start].psz_msg << "\n";
-            fMessagesView->Insert( string.String() );
-            fMessagesView->SetFontAndColor( oldLength,
-                                            fMessagesView->TextLength(),
-                                            NULL, 0, &color );
-            fMessagesView->Draw( fMessagesView->Bounds() );
-            fMessagesView->UnlockLooper();
-            
-            /* Scroll at the end */
-            if( fScrollBar->LockLooper() )
+
+            if( LockLooper() )
             {
-                float min, max;
-                fScrollBar->GetRange( &min, &max );
-                fScrollBar->SetValue( max );
-                fScrollBar->UnlockLooper();
+                oldLength = TextLength();
+                BString string;
+                string << p_sub->p_msg[i_start].psz_module
+                    << " " << psz_module_type << " : "
+                    << p_sub->p_msg[i_start].psz_msg << "\n";
+                Insert( TextLength(), string.String(), strlen( string.String() ) );
+                SetFontAndColor( oldLength, TextLength(), NULL, 0, &color );
+                Draw( Bounds() );
+                UnlockLooper();
             }
         }
 
@@ -173,4 +109,89 @@ void MessagesWindow::UpdateMessages()
         p_sub->i_start = i_start;
         vlc_mutex_unlock( p_sub->p_lock );
     }
+
+    /* Scroll at the end unless the is user is scrolling or selecting something */
+    int32 start, end;
+    GetSelection( &start, &end );
+    if( !isScrolling && start == end && fScrollBar->LockLooper() )
+    {
+        float min, max;
+        fScrollBar->GetRange( &min, &max );
+        fScrollBar->SetValue( max );
+        fScrollBar->UnlockLooper();
+    }
+
+    BTextView::Pulse();
+}
+
+/*****************************************************************************
+ * MessagesWindow::MessagesWindow
+ *****************************************************************************/
+MessagesWindow::MessagesWindow( intf_thread_t * _p_intf,
+                                BRect frame, const char * name )
+    : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
+               B_NOT_ZOOMABLE ),
+    p_intf(_p_intf)
+{
+    SetSizeLimits( 400, 2000, 200, 2000 );
+
+    p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
+    BRect rect, textRect;
+
+    rect = Bounds();
+    rect.right -= B_V_SCROLL_BAR_WIDTH;
+    textRect = rect;
+    textRect.InsetBy( 5, 5 );
+    fMessagesView = new MessagesView( p_sub,
+                                      rect, "messages", textRect,
+                                      B_FOLLOW_ALL, B_WILL_DRAW );
+    fMessagesView->MakeEditable( false );
+    fMessagesView->SetStylable( true );
+    fScrollView = new BScrollView( "scrollview", fMessagesView, B_WILL_DRAW,
+                                   B_FOLLOW_ALL, false, true );
+    fMessagesView->fScrollBar = fScrollView->ScrollBar( B_VERTICAL );
+    AddChild( fScrollView );
+    /* start window thread in hidden state */
+    Hide();
+    Show();
+}
+
+/*****************************************************************************
+ * MessagesWindow::~MessagesWindow
+ *****************************************************************************/
+MessagesWindow::~MessagesWindow()
+{
+     msg_Unsubscribe( p_intf, p_sub );
+}
+
+/*****************************************************************************
+ * MessagesWindow::FrameResized
+ *****************************************************************************/
+void MessagesWindow::FrameResized( float width, float height )
+{
+    BWindow::FrameResized( width, height );
+    BRect rect = fMessagesView->Bounds();
+    rect.InsetBy( 5, 5 );
+    fMessagesView->SetTextRect( rect );
+}
+
+/*****************************************************************************
+ * MessagesWindow::QuitRequested
+ *****************************************************************************/
+bool MessagesWindow::QuitRequested()
+{
+    Hide();
+    return false;
+}
+
+/*****************************************************************************
+ * MessagesWindow::ReallyQuit
+ *****************************************************************************/
+void MessagesWindow::ReallyQuit()
+{
+    Lock();
+    Hide();
+    Quit();
 }