]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/libwin32/statusDialog.cpp
ebl use LPARAM instead of LONG for cast
[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 Kern Sibbald.
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 #include "lib/status.h"
40
41 static BOOL CALLBACK dialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
42 {
43    /* Get class pointer from user data */
44    statusDialog *statDlg = (statusDialog *)GetWindowLong(hDlg, GWL_USERDATA);
45
46    switch (uMsg) {
47    case WM_INITDIALOG:
48       /* Set class pointer in user data */
49       SetWindowLong(hDlg, GWL_USERDATA, lParam);
50       statDlg = (statusDialog *)lParam;
51       statDlg->m_textWin = GetDlgItem(hDlg, IDC_TEXTDISPLAY);
52
53       /* show the dialog */
54       SetForegroundWindow(hDlg);
55
56       /* Update every 5 seconds */
57       SetTimer(hDlg, 1, 5000, NULL); 
58       statDlg->m_visible = true;
59       statDlg->display();
60       return true;
61
62    case WM_TIMER:
63       statDlg->display();
64       return true;
65
66    case WM_SIZE:
67       statDlg->resize(hDlg, LOWORD(lParam), HIWORD(lParam));
68       return true;
69
70    case WM_COMMAND:
71       switch (LOWORD(wParam)) {
72       case IDCANCEL:
73       case IDOK:
74          statDlg->m_visible = false;
75          KillTimer(hDlg, 1);
76          EndDialog(hDlg, true);
77          return true;
78       }
79       break;
80
81    case WM_DESTROY:
82       statDlg->m_textWin = NULL;
83       statDlg->m_visible = false;
84       KillTimer(hDlg, 1);
85       EndDialog(hDlg, false);
86       return true;
87    }
88    return false;
89 }
90
91
92 static void displayString(const char *msg, int len, void *context)
93 {
94    /* Get class pointer from user data */
95    statusDialog *statDlg = (statusDialog *)context;
96    const char *start = msg;
97    const char *p;
98    char *str;
99
100    for (p=start; *p; p++) {
101       if (*p == '\n') {
102          int len = p - start;
103          if (len > 0) {
104             str = (char *)alloca(len + 1);
105             bstrncpy(str, start, len + 1);
106
107             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
108             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)str);
109          }
110          
111          if (*p == '\n') {
112             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
113             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)"\r\n");
114          }
115
116          if (*p == '\0'){
117             break;
118          }
119          start = p + 1;
120       }
121    }
122 }
123
124 void statusDialog::display()
125 {
126    if (m_textWin != NULL) {
127       STATUS_PKT sp;
128       long hPos = GetScrollPos(m_textWin, SB_HORZ);
129       long vPos = GetScrollPos(m_textWin, SB_VERT);
130       long selStart;
131       long selEnd;
132
133       SendMessage(m_textWin, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
134
135       SetWindowText(m_textWin, "");
136       sp.bs = NULL;
137       sp.context = this;
138       sp.callback = displayString;
139       output_status(&sp);
140
141       SendMessage(m_textWin, EM_SETSEL, selStart, selEnd);
142       SendMessage(m_textWin, WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, hPos), 0);
143       SendMessage(m_textWin, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, vPos), 0);
144    }
145 }
146
147 /* Dialog box handling functions */
148 void statusDialog::show(bool show)
149 {
150    if (show && !m_visible) {
151       DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
152           (DLGPROC)dialogProc, (LPARAM)this);
153    }
154 }
155
156 /*
157  * Make sure OK button is positioned in the right place
158  */
159 void statusDialog::resize(HWND dWin, int dWidth, int dHeight)
160 {
161    int bWidth, bHeight;   
162    RECT bRect;
163    HWND bWin;
164
165    if (m_textWin != NULL) {
166       bWin = GetDlgItem(dWin, IDOK);  /* get size of OK button */
167
168       GetWindowRect(bWin, &bRect);
169       bWidth = bRect.right - bRect.left;
170       bHeight = bRect.bottom - bRect.top;
171
172       MoveWindow(m_textWin, 8, 8, dWidth-bWidth-24, dHeight-16, true);
173       MoveWindow(bWin, dWidth - bWidth-8, 8, bWidth, bHeight, true);
174    }
175 }