2 * Bacula File daemon Status Dialog box
4 * Inspired from the VNC code by ATT.
6 * Copyright (2000) Kern E. Sibbald
10 Copyright (C) 2000-2003 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include "winbacula.h"
32 extern void output_status(void sendit(const char *msg, int len, void *sarg), void *arg);
34 bacStatus::bacStatus()
37 m_hTextDisplay = NULL;
40 bacStatus::~bacStatus()
45 bacStatus::DisplayString(const char *msg, int len, void *context)
47 /* Get class pointer from user data */
48 bacStatus *_this = (bacStatus *)context;
52 for (pStart = msg, pCurrent = msg; ; pCurrent++) {
53 if (*pCurrent == '\n' || *pCurrent == '\0') {
54 int lenSubstring = pCurrent - pStart;
55 if (lenSubstring > 0) {
56 char *pSubString = (char *)alloca(lenSubstring + 1);
57 bstrncpy(pSubString, pStart, lenSubstring + 1);
59 SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
60 SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LPARAM)pSubString);
63 if (*pCurrent == '\n') {
64 SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
65 SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LONG)"\r\n");
68 if (*pCurrent == '\0'){
71 pStart = pCurrent + 1;
77 bacStatus::UpdateDisplay()
79 if (m_hTextDisplay != NULL) {
80 long lHorizontalPos = GetScrollPos(m_hTextDisplay, SB_HORZ);
81 long lVerticalPos = GetScrollPos(m_hTextDisplay, SB_VERT);
82 long selStart, selEnd;
84 SendMessage(m_hTextDisplay, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
86 SetWindowText(m_hTextDisplay, "");
88 output_status(DisplayString, this);
90 SendMessage(m_hTextDisplay, EM_SETSEL, (WPARAM)selStart, (LPARAM)selEnd);
91 SendMessage(m_hTextDisplay, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lHorizontalPos), 0);
92 SendMessage(m_hTextDisplay, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lVerticalPos), 0);
96 /* Dialog box handling functions */
98 bacStatus::Show(BOOL show)
100 if (show && !m_bVisible) {
101 DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
102 (DLGPROC)DialogProc, (LONG)this);
107 bacStatus::ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight)
109 if (m_hTextDisplay != NULL) {
110 HWND hwndButton = GetDlgItem(hDlg, IDOK);
113 GetWindowRect(hwndButton, &rcWindow);
115 LONG lButtonWidth = rcWindow.right - rcWindow.left;
116 LONG lButtonHeight = rcWindow.bottom - rcWindow.top;
118 MoveWindow(m_hTextDisplay, 8, 8, wWidth - lButtonWidth - 24, wHeight - 16, TRUE);
119 MoveWindow(hwndButton, wWidth - lButtonWidth - 8, 8, lButtonWidth, lButtonHeight, TRUE);
125 bacStatus::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
127 /* Get class pointer from user data */
128 bacStatus *_this = (bacStatus *)GetWindowLong(hDlg, GWL_USERDATA);
132 /* Set class pointer in user data */
133 SetWindowLong(hDlg, GWL_USERDATA, lParam);
134 _this = (bacStatus *)lParam;
135 _this->m_hTextDisplay = GetDlgItem(hDlg, IDC_TEXTDISPLAY);
137 /* show the dialog */
138 SetForegroundWindow(hDlg);
140 /* Update every 5 seconds */
141 SetTimer(hDlg, 1, 5000, NULL);
142 _this->m_bVisible = TRUE;
143 _this->UpdateDisplay();
147 _this->UpdateDisplay();
151 _this->ResizeChildren(hDlg, LOWORD(lParam), HIWORD(lParam));
155 switch (LOWORD(wParam)) {
159 EndDialog(hDlg, TRUE);
160 _this->m_bVisible = FALSE;
166 _this->m_hTextDisplay = NULL;
168 EndDialog(hDlg, FALSE);
169 _this->m_bVisible = FALSE;