]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/libwin32/winstat.cpp
kes Reapply my bat.conf install script in qt-console. I think I
[bacula/bacula] / bacula / src / win32 / libwin32 / winstat.cpp
1 /*
2  * Bacula File daemon Status Dialog box
3  *
4  *  Inspired from the VNC code by ATT.
5  *
6  * Copyright (2000) Kern E. Sibbald
7  *
8  */
9 /*
10    Bacula® - The Network Backup Solution
11
12    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
13
14    The main author of Bacula is Kern Sibbald, with contributions from
15    many others, a complete list can be found in the file AUTHORS.
16    This program is Free Software; you can redistribute it and/or
17    modify it under the terms of version two of the GNU General Public
18    License as published by the Free Software Foundation plus additions
19    that are listed in the file LICENSE.
20
21    This program is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24    General Public License for more details.
25
26    You should have received a copy of the GNU General Public License
27    along with this program; if not, write to the Free Software
28    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29    02110-1301, USA.
30
31    Bacula® is a registered trademark of John Walker.
32    The licensor of Bacula is the Free Software Foundation Europe
33    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34    Switzerland, email:ftf@fsfeurope.org.
35 */
36
37 #include "bacula.h"
38 #include "winbacula.h"
39 #include "winstat.h"
40 #include "winres.h"
41
42 extern void output_status(void sendit(const char *msg, int len, void *sarg), void *arg);
43
44 bacStatus::bacStatus()
45 {
46    m_bVisible = FALSE;
47    m_hTextDisplay = NULL;
48 }
49
50 bacStatus::~bacStatus()
51 {
52 }
53
54 void
55 bacStatus::DisplayString(const char *msg, int len, void *context)
56 {
57    /* Get class pointer from user data */
58    bacStatus *_this = (bacStatus *)context;
59    const char *pStart;
60    const char *pCurrent;
61
62    for (pStart = msg, pCurrent = msg; ; pCurrent++) {
63       if (*pCurrent == '\n' || *pCurrent == '\0') {
64          int lenSubstring = pCurrent - pStart;
65          if (lenSubstring > 0) {
66             char *pSubString = (char *)alloca(lenSubstring + 1);
67             bstrncpy(pSubString, pStart, lenSubstring + 1);
68
69             SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
70             SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LPARAM)pSubString);
71          }
72          
73          if (*pCurrent == '\n') {
74             SendMessage(_this->m_hTextDisplay, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
75             SendMessage(_this->m_hTextDisplay, EM_REPLACESEL, 0, (LONG)"\r\n");
76          }
77
78          if (*pCurrent == '\0'){
79             break;
80          }
81          pStart = pCurrent + 1;
82       }
83    }
84 }
85
86 void 
87 bacStatus::UpdateDisplay()
88 {
89    if (m_hTextDisplay != NULL) {
90       long  lHorizontalPos = GetScrollPos(m_hTextDisplay, SB_HORZ);
91       long  lVerticalPos = GetScrollPos(m_hTextDisplay, SB_VERT);
92       long  selStart, selEnd;
93
94       SendMessage(m_hTextDisplay, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
95
96       SetWindowText(m_hTextDisplay, "");
97
98       output_status(DisplayString, this);
99
100       SendMessage(m_hTextDisplay, EM_SETSEL, (WPARAM)selStart, (LPARAM)selEnd);
101       SendMessage(m_hTextDisplay, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lHorizontalPos), 0);
102       SendMessage(m_hTextDisplay, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, lVerticalPos), 0);
103    }
104 }
105
106 /* Dialog box handling functions */
107 void
108 bacStatus::Show(BOOL show)
109 {
110    if (show && !m_bVisible) {
111       DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
112           (DLGPROC)DialogProc, (LONG)this);
113    }
114 }
115
116 void
117 bacStatus::ResizeChildren(HWND hDlg, WORD wWidth, WORD wHeight)
118 {
119    if (m_hTextDisplay != NULL) {
120       HWND  hwndButton = GetDlgItem(hDlg, IDOK);
121       RECT  rcWindow;
122
123       GetWindowRect(hwndButton, &rcWindow);
124
125       LONG  lButtonWidth = rcWindow.right - rcWindow.left;
126       LONG  lButtonHeight = rcWindow.bottom - rcWindow.top;
127
128       MoveWindow(m_hTextDisplay, 8, 8, wWidth - lButtonWidth - 24, wHeight - 16, TRUE);
129       MoveWindow(hwndButton, wWidth - lButtonWidth - 8, 8, lButtonWidth, lButtonHeight, TRUE);
130    }
131 }
132
133
134 BOOL CALLBACK
135 bacStatus::DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
136 {
137    /* Get class pointer from user data */
138    bacStatus *_this = (bacStatus *)GetWindowLong(hDlg, GWL_USERDATA);
139
140    switch (uMsg) {
141    case WM_INITDIALOG:
142       /* Set class pointer in user data */
143       SetWindowLong(hDlg, GWL_USERDATA, lParam);
144       _this = (bacStatus *)lParam;
145       _this->m_hTextDisplay = GetDlgItem(hDlg, IDC_TEXTDISPLAY);
146
147       /* show the dialog */
148       SetForegroundWindow(hDlg);
149
150       /* Update every 5 seconds */
151       SetTimer(hDlg, 1, 5000, NULL); 
152       _this->m_bVisible = TRUE;
153       _this->UpdateDisplay();
154       return TRUE;
155
156    case WM_TIMER:
157       _this->UpdateDisplay();
158       return TRUE;
159
160    case WM_SIZE:
161       _this->ResizeChildren(hDlg, LOWORD(lParam), HIWORD(lParam));
162       return TRUE;
163
164    case WM_COMMAND:
165       switch (LOWORD(wParam)) {
166       case IDCANCEL:
167       case IDOK:
168          KillTimer(hDlg, 1);
169          EndDialog(hDlg, TRUE);
170          _this->m_bVisible = FALSE;
171          return TRUE;
172       }
173       break;
174
175    case WM_DESTROY:
176       _this->m_hTextDisplay = NULL;
177       KillTimer(hDlg, 1);
178       EndDialog(hDlg, FALSE);
179       _this->m_bVisible = FALSE;
180       return TRUE;
181    }
182    return 0;
183 }