core/vgui/impl/mfc/vgui_mfc_statusbar.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/mfc/vgui_mfc_statusbar.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief See vgui_mfc_statusbar.h for a description of this file.
00008 // \author  Marko Bacic, RRG, University of Oxford
00009 // \date    10 Aug 2000
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   13-MAR-2001 K.Y.McGaul   Messages are now cleared when a new message
00014 //                            appears, not immediately.
00015 // \endverbatim
00016 //
00017 
00018 #include "vgui_mfc_statusbar.h"
00019 #include "vgui_mfc_mainfrm.h"
00020 
00021 //: Constructor, creates an MFC status bar object and displays it.
00022 vgui_mfc_statusbar::vgui_mfc_statusbar()
00023   : statusbuf(new vgui_statusbuf(this))
00024   , out(statusbuf)
00025 {
00026   statusbar = new CStatusBar();
00027   statusbar->Create(AfxGetApp()->GetMainWnd());
00028   unsigned x = ID_SEPARATOR;
00029   statusbar->SetIndicators(&x,1);
00030   CFrameWnd *fwnd = (CFrameWnd *)AfxGetApp()->GetMainWnd();
00031   fwnd->ShowControlBar(statusbar,TRUE,FALSE);
00032   statusbar->UpdateWindow();
00033   statusbar->ShowWindow(SW_SHOW);
00034 }
00035 
00036 vgui_mfc_statusbar::~vgui_mfc_statusbar()
00037 {
00038   delete statusbar;
00039   delete statusbuf;
00040 }
00041 
00042 static int context_id = 1;
00043 
00044 //: Updates the status bar by calling OnUpdateStatusBar of vgui_mfc_mainfrm
00045 void vgui_mfc_statusbar::update()
00046 {
00047   CCmdUI cui;
00048   cui.m_nID = ID_SEPARATOR;
00049   cui.m_nIndex = 4;
00050   cui.m_pMenu = NULL;
00051   cui.m_pOther = statusbar;
00052 
00053   ((vgui_mfc_mainfrm *)AfxGetApp()->GetMainWnd())->UpdateStatusBar(&cui);
00054 }
00055 
00056 
00057 //: Append given text (of given length) to the status bar
00058 int vgui_mfc_statusbar::write(const char* text, int n)
00059 {
00060   static bool start_new = false;
00061   if (n == 1) {
00062     if (text[0] == '\n') {
00063       // We are at the end of the message. Set a bool so we know next time
00064       // to clear the buffer before we start a new message.
00065       start_new = true;
00066     }
00067     else if (start_new){
00068       statusbar->SetWindowText(linebuffer.c_str());
00069       statusbar->SetPaneText(0,linebuffer.c_str());
00070       linebuffer = "";
00071       linebuffer += text[0];
00072       start_new = false;
00073     }
00074     else
00075       linebuffer += text[0];
00076   }
00077   else {
00078     linebuffer.append(text, n);
00079     if (linebuffer.find('\n')) {
00080       statusbar->SetWindowText(linebuffer.c_str());
00081       statusbar->SetPaneText(0,linebuffer.c_str());
00082       linebuffer = "";
00083     }
00084   }
00085   statusbar->UpdateWindow();
00086   statusbar->ShowWindow(SW_SHOW);
00087   AfxGetApp()->GetMainWnd()->UpdateWindow();
00088   AfxGetApp()->GetMainWnd()->ShowWindow(SW_SHOW);
00089   update();
00090   return n;
00091 }
00092 
00093 //: Write given text to the status bar.
00094 int vgui_mfc_statusbar::write(const char* text)
00095 {
00096   statusbar->SetWindowText(text);
00097   linebuffer = text;
00098   statusbar->SetPaneText(0,linebuffer.c_str());
00099   statusbar->UpdateWindow();
00100   statusbar->ShowWindow(SW_SHOW);
00101   update();
00102 
00103   return 1;
00104 }