2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula File daemon Status Dialog box
22 * Kern Sibbald, August 2007
28 #include "statusDialog.h"
29 #include "lib/status.h"
31 static BOOL CALLBACK dialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
33 /* Get class pointer from user data */
34 statusDialog *statDlg = (statusDialog *)GetWindowLong(hDlg, GWL_USERDATA);
38 /* Set class pointer in user data */
39 SetWindowLong(hDlg, GWL_USERDATA, lParam);
40 statDlg = (statusDialog *)lParam;
41 statDlg->m_textWin = GetDlgItem(hDlg, IDC_TEXTDISPLAY);
44 SetForegroundWindow(hDlg);
46 /* Update every 5 seconds */
47 SetTimer(hDlg, 1, 5000, NULL);
48 statDlg->m_visible = true;
57 statDlg->resize(hDlg, LOWORD(lParam), HIWORD(lParam));
61 switch (LOWORD(wParam)) {
64 statDlg->m_visible = false;
66 EndDialog(hDlg, true);
72 statDlg->m_textWin = NULL;
73 statDlg->m_visible = false;
75 EndDialog(hDlg, false);
82 static void displayString(const char *msg, int len, void *context)
84 /* Get class pointer from user data */
85 statusDialog *statDlg = (statusDialog *)context;
86 const char *start = msg;
90 for (p=start; *p; p++) {
94 str = (char *)alloca(len + 1);
95 bstrncpy(str, start, len + 1);
97 SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
98 SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)str);
102 SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
103 SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)"\r\n");
114 void statusDialog::display()
116 if (m_textWin != NULL) {
118 long hPos = GetScrollPos(m_textWin, SB_HORZ);
119 long vPos = GetScrollPos(m_textWin, SB_VERT);
123 SendMessage(m_textWin, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
125 SetWindowText(m_textWin, "");
128 sp.callback = displayString;
131 SendMessage(m_textWin, EM_SETSEL, selStart, selEnd);
132 SendMessage(m_textWin, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, hPos), 0);
133 SendMessage(m_textWin, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, vPos), 0);
137 /* Dialog box handling functions */
138 void statusDialog::show(bool show)
140 if (show && !m_visible) {
141 DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
142 (DLGPROC)dialogProc, (LPARAM)this);
147 * Make sure OK button is positioned in the right place
149 void statusDialog::resize(HWND dWin, int dWidth, int dHeight)
155 if (m_textWin != NULL) {
156 bWin = GetDlgItem(dWin, IDOK); /* get size of OK button */
158 GetWindowRect(bWin, &bRect);
159 bWidth = bRect.right - bRect.left;
160 bHeight = bRect.bottom - bRect.top;
162 MoveWindow(m_textWin, 8, 8, dWidth-bWidth-24, dHeight-16, true);
163 MoveWindow(bWin, dWidth - bWidth-8, 8, bWidth, bHeight, true);