00001
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,
00015 STATUSCLASSNAME,
00016 "",
00017 WS_CHILD|WS_BORDER|WS_VISIBLE,
00018 -100, -100, 10, 10,
00019 hwndParent,
00020 (HMENU)statusBarID,
00021 (HINSTANCE)GetWindowLong(hwndParent, GWLP_HINSTANCE),
00022 NULL);
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,
00029 STATUSCLASSNAME,
00030 "",
00031 WS_CHILD|WS_BORDER|WS_VISIBLE,
00032 -100, -100, 10, 10,
00033 hwndParent,
00034 (HMENU)statusBarID,
00035 (HINSTANCE)GetWindowLong(hwndParent, GWL_HINSTANCE),
00036 NULL);
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) {
00053 if (text[0] == '\n') {
00054
00055
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 }