]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/libwin32/statusDialog.cpp
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / libwin32 / statusDialog.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2018 Kern Sibbald
5
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.
8
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.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * Bacula File daemon Status Dialog box
21  *
22  * Kern Sibbald, August 2007
23  *
24  */
25
26 #include "bacula.h"
27 #include "win32.h"
28 #include "statusDialog.h"
29 #include "lib/status.h"
30
31 static BOOL CALLBACK dialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
32 {
33    /* Get class pointer from user data */
34    statusDialog *statDlg = (statusDialog *)GetWindowLong(hDlg, GWL_USERDATA);
35
36    switch (uMsg) {
37    case WM_INITDIALOG:
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);
42
43       /* show the dialog */
44       SetForegroundWindow(hDlg);
45
46       /* Update every 5 seconds */
47       SetTimer(hDlg, 1, 5000, NULL); 
48       statDlg->m_visible = true;
49       statDlg->display();
50       return true;
51
52    case WM_TIMER:
53       statDlg->display();
54       return true;
55
56    case WM_SIZE:
57       statDlg->resize(hDlg, LOWORD(lParam), HIWORD(lParam));
58       return true;
59
60    case WM_COMMAND:
61       switch (LOWORD(wParam)) {
62       case IDCANCEL:
63       case IDOK:
64          statDlg->m_visible = false;
65          KillTimer(hDlg, 1);
66          EndDialog(hDlg, true);
67          return true;
68       }
69       break;
70
71    case WM_DESTROY:
72       statDlg->m_textWin = NULL;
73       statDlg->m_visible = false;
74       KillTimer(hDlg, 1);
75       EndDialog(hDlg, false);
76       return true;
77    }
78    return false;
79 }
80
81
82 static void displayString(const char *msg, int len, void *context)
83 {
84    /* Get class pointer from user data */
85    statusDialog *statDlg = (statusDialog *)context;
86    const char *start = msg;
87    const char *p;
88    char *str;
89
90    for (p=start; *p; p++) {
91       if (*p == '\n') {
92          int len = p - start;
93          if (len > 0) {
94             str = (char *)alloca(len + 1);
95             bstrncpy(str, start, len + 1);
96
97             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
98             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)str);
99          }
100          
101          if (*p == '\n') {
102             SendMessage(statDlg->m_textWin, EM_SETSEL, (WPARAM)-1, (LPARAM)-1);
103             SendMessage(statDlg->m_textWin, EM_REPLACESEL, 0, (LPARAM)"\r\n");
104          }
105
106          if (*p == '\0'){
107             break;
108          }
109          start = p + 1;
110       }
111    }
112 }
113
114 void statusDialog::display()
115 {
116    if (m_textWin != NULL) {
117       STATUS_PKT sp;
118       long hPos = GetScrollPos(m_textWin, SB_HORZ);
119       long vPos = GetScrollPos(m_textWin, SB_VERT);
120       long selStart;
121       long selEnd;
122
123       SendMessage(m_textWin, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
124
125       SetWindowText(m_textWin, "");
126       sp.bs = NULL;
127       sp.context = this;
128       sp.callback = displayString;
129       output_status(&sp);
130
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);
134    }
135 }
136
137 /* Dialog box handling functions */
138 void statusDialog::show(bool show)
139 {
140    if (show && !m_visible) {
141       DialogBoxParam(appInstance, MAKEINTRESOURCE(IDD_STATUS), NULL,
142           (DLGPROC)dialogProc, (LPARAM)this);
143    }
144 }
145
146 /*
147  * Make sure OK button is positioned in the right place
148  */
149 void statusDialog::resize(HWND dWin, int dWidth, int dHeight)
150 {
151    int bWidth, bHeight;   
152    RECT bRect;
153    HWND bWin;
154
155    if (m_textWin != NULL) {
156       bWin = GetDlgItem(dWin, IDOK);  /* get size of OK button */
157
158       GetWindowRect(bWin, &bRect);
159       bWidth = bRect.right - bRect.left;
160       bHeight = bRect.bottom - bRect.top;
161
162       MoveWindow(m_textWin, 8, 8, dWidth-bWidth-24, dHeight-16, true);
163       MoveWindow(bWin, dWidth - bWidth-8, 8, bWidth, bHeight, true);
164    }
165 }