]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/libwin32/statusDialog.cpp
kes Implement 'MaxFullInterval' and start 'MaxDiffInterval' based on
[bacula/bacula] / bacula / src / win32 / libwin32 / statusDialog.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Bacula File daemon Status Dialog box
30  *
31  * Kern Sibbald, August 2007
32  *
33  * Version $Id$
34  */
35
36 #include "bacula.h"
37 #include "win32.h"
38 #include "statusDialog.h"
39
40 static BOOL CALLBACK dialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
41 {
42    /* Get class pointer from user data */
43    statusDialog *statDlg = (statusDialog *)GetWindowLong(hDlg, GWL_USERDATA);
44
45    switch (uMsg) {
46    case WM_INITDIALOG:
47       /* Set class pointer in user data */
48       SetWindowLong(hDlg, GWL_USERDATA, lParam);
49       statDlg = (statusDialog *)lParam;
50       statDlg->m_textWin = GetDlgItem(hDlg, IDC_TEXTDISPLAY);
51
52       /* show the dialog */
53       SetForegroundWindow(hDlg);
54
55       /* Update every 5 seconds */
56       SetTimer(hDlg, 1, 5000, NULL); 
57       statDlg->m_visible = true;
58       statDlg->display();
59       return true;
60
61    case WM_TIMER:
62       statDlg->display();
63       return true;
64
65    case WM_SIZE:
66       statDlg->resize(hDlg, LOWORD(lParam), HIWORD(lParam));
67       return true;
68
69    case WM_COMMAND:
70       switch (LOWORD(wParam)) {
71       case IDCANCEL:
72       case IDOK:
73          statDlg->m_visible = false;
74          KillTimer(hDlg, 1);
75          EndDialog(hDlg, true);
76          return true;
77       }
78       break;
79
80    case WM_DESTROY:
81       statDlg->m_textWin = NULL;
82       statDlg->m_visible = false;
83       KillTimer(hDlg, 1);
84       EndDialog(hDlg, false);
85       return true;
86    }
87    return false;
88 }
89
90
91 static void displayString(const char *msg, int len, void *context)
92 {
93    /* Get class pointer from user data */
94    statusDialog *statDlg = (statusDialog *)context;
95    const char *start = msg;
96    const char *p;
97    char *str;
98
99    for (p=start; *p; p++) {
100       if (*p == '\n') {
101          int len = p - start;
102          if (len > 0) {
103             str = (char *)alloca(len + 1);
104             bstrncpy(str, start, len + 1);
105
106             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
107             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)str);
108          }
109          
110          if (*p == '\n') {
111             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
112             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LONG)"\r\n");
113          }
114
115          if (*p == '\0'){
116             break;
117          }
118          start = p + 1;
119       }
120    }
121 }
122
123 void statusDialog::display()
124 {
125    if (m_textWin != NULL) {
126       long hPos = GetScrollPos(m_textWin, SB_HORZ);
127       long vPos = GetScrollPos(m_textWin, SB_VERT);
128       long selStart;
129       long selEnd;
130
131       SendMessage(m_textWin, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
132
133       SetWindowText(m_textWin, "");
134       output_status(displayString, this);
135
136       SendMessage(m_textWin, EM_SETSEL, selStart, selEnd);
137       SendMessage(m_textWin, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, hPos), 0);
138       SendMessage(m_textWin, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, vPos), 0);
139    }
140 }
141
142 /* Dialog box handling functions */
143 void statusDialog::show(bool show)
144 {
145    if (show && !m_visible) {
146       DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
147           (DLGPROC)dialogProc, (LONG)this);
148    }
149 }
150
151 /*
152  * Make sure OK button is positioned in the right place
153  */
154 void statusDialog::resize(HWND dWin, int dWidth, int dHeight)
155 {
156    int bWidth, bHeight;   
157    RECT bRect;
158    HWND bWin;
159
160    if (m_textWin != NULL) {
161       bWin = GetDlgItem(dWin, IDOK);  /* get size of OK button */
162
163       GetWindowRect(bWin, &bRect);
164       bWidth = bRect.right - bRect.left;
165       bHeight = bRect.bottom - bRect.top;
166
167       MoveWindow(m_textWin, 8, 8, dWidth-bWidth-24, dHeight-16, true);
168       MoveWindow(bWin, dWidth - bWidth-8, 8, bWidth, bHeight, true);
169    }
170 }