core/vgui/impl/wx/vgui_wx_statusbar.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/wx/vgui_wx_statusbar.cxx
00002 //=========================================================================
00003 //:
00004 // \file
00005 // \brief  wxWidgets implementation of vgui_statusbar.
00006 //
00007 // See vgui_wx_statusbar.h for details.
00008 //=========================================================================
00009 
00010 #include "vgui_wx_statusbar.h"
00011 
00012 #include <wx/statusbr.h>
00013 
00014 //-------------------------------------------------------------------------
00015 // vgui_wx_statusbar implementation - construction & destruction.
00016 //-------------------------------------------------------------------------
00017 //: Constructor, creates a wxWidgets status bar and displays it.
00018 vgui_wx_statusbar::vgui_wx_statusbar(void)
00019   : widget_(0)
00020   , statusbuf_(new vgui_statusbuf(this))
00021 {
00022 }
00023 
00024 //: Destructor.
00025 vgui_wx_statusbar::~vgui_wx_statusbar(void)
00026 {
00027   delete statusbuf_;
00028 }
00029 
00030 //-------------------------------------------------------------------------
00031 // vgui_wx_statusbar implementation.
00032 //-------------------------------------------------------------------------
00033 //: Append given text (of given length) to the status bar.
00034 int vgui_wx_statusbar::write(const char* text, int n)
00035 {
00036   if (widget_)
00037   {
00038     if (n == 1)
00039     {
00040       if (text[0] == '\n')
00041       {
00042         // buffer filled, print to wxStatusBar and reset
00043         widget_->SetStatusText(wxString(linebuffer_.c_str(),wxConvUTF8));
00044         linebuffer_ = "";
00045       }
00046       else { linebuffer_ += text[0]; }
00047     }
00048     else
00049     {
00050       linebuffer_.append(text, n);
00051       if (linebuffer_.find('\n') != vcl_string::npos)
00052       {
00053         // buffer filled, print to wxStatusBar and reset
00054         widget_->SetStatusText(wxString(linebuffer_.c_str(),wxConvUTF8));
00055         linebuffer_ = "";
00056       }
00057     }
00058   }
00059   return n;
00060 }
00061 
00062 //: Append given text to the status bar.
00063 int vgui_wx_statusbar::write(const char* text)
00064 {
00065   if (widget_)
00066   {
00067     linebuffer_ = text;
00068     widget_->SetStatusText(wxString(linebuffer_.c_str(),wxConvUTF8));
00069   }
00070 
00071   return 1;
00072 }