core/vgui/impl/win32/vgui_win32_statusbar.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32_statusbar.cxx
00002 
00003 #include "vgui_win32_statusbar.h"
00004 #include <commctrl.h>
00005 
00006 int vgui_win32_statusbar::statusBarID = 200;
00007 
00008 vgui_win32_statusbar::vgui_win32_statusbar(HWND hwndParent, int numPanes)
00009   : statusbuf(new vgui_statusbuf(this)), out(statusbuf),
00010      hwndParent_(hwndParent), numPanes_(numPanes)
00011 {
00012 #ifdef _WIN64
00013   hwnd_ = CreateWindowEx(
00014          0L,                                       // no extended styles
00015          STATUSCLASSNAME,                          // status bar
00016          "",                                       // no text
00017          WS_CHILD|WS_BORDER|WS_VISIBLE,            // styles
00018          -100, -100, 10, 10,                       // x, y, cx, cy
00019          hwndParent,                               // parent window
00020          (HMENU)statusBarID,                       // window ID
00021          (HINSTANCE)GetWindowLong(hwndParent, GWLP_HINSTANCE), // instance
00022          NULL);                                    // window data
00023   if ( hwnd_ == NULL )
00024     MessageBox(NULL, TEXT("Fail to create status bar"), TEXT("Error"),
00025                MB_ICONERROR | MB_OK);
00026 #else
00027   hwnd_ = CreateWindowEx(
00028          0L,                                       // no extended styles
00029          STATUSCLASSNAME,                          // status bar
00030          "",                                       // no text
00031          WS_CHILD|WS_BORDER|WS_VISIBLE,            // styles
00032          -100, -100, 10, 10,                       // x, y, cx, cy
00033          hwndParent,                               // parent window
00034          (HMENU)statusBarID,                       // window ID
00035          (HINSTANCE)GetWindowLong(hwndParent, GWL_HINSTANCE), // instance
00036          NULL);                                    // window data
00037   if ( hwnd_ == NULL )
00038     MessageBox(NULL, TEXT("Fail to create status bar"), TEXT("Error"),
00039                MB_ICONERROR | MB_OK);
00040 #endif //_WIN64
00041 }
00042 
00043 vgui_win32_statusbar::~vgui_win32_statusbar()
00044 {
00045   delete statusbuf;
00046   DestroyWindow(hwnd_);
00047 }
00048 
00049 int vgui_win32_statusbar::write(const char* text, int n)
00050 {
00051   static bool start_new = false;
00052   if (n == 1) { // If user appends one char, we cache it unless it's a  '\n'
00053     if (text[0] == '\n') {
00054       // We are at the end of the message. Set a bool so we know next time
00055       // to clear the buffer before we start a new message.
00056       start_new = true;
00057     }
00058     else if (start_new == true){
00059       SendMessage(hwnd_, SB_SETTEXT, 0, (LPARAM)(LPSTR)linebuffer.c_str());
00060       linebuffer = "";
00061       linebuffer += text[0];
00062       start_new = false;
00063     }
00064     else
00065       linebuffer += text[0];
00066   }
00067   else {
00068     linebuffer.append(text, n);
00069     if (linebuffer.find('\n')) {
00070       SendMessage(hwnd_, SB_SETTEXT, 0, (LPARAM)(LPSTR)linebuffer.c_str());
00071       linebuffer = "";
00072     }
00073   }
00074 
00075   return n;
00076 }
00077 
00078 int vgui_win32_statusbar::write(const char* text)
00079 {
00080   linebuffer = text;
00081   SendMessage(hwnd_, SB_SETTEXT, 0, (LPARAM)(LPSTR)linebuffer.c_str());
00082 
00083   return 1;
00084 }