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