1 // This file has been adapted to the Win32 version of Apcupsd
2 // by Kern E. Sibbald. Many thanks to ATT and James Weatherall,
3 // the original author, for providing an excellent template.
5 // Rewrite/Refactoring by Adam Kropelin
7 // Copyright (2009) Adam D. Kropelin
8 // Copyright (2000) Kern E. Sibbald
11 // Implementation of the Events dialogue
14 #include "winevents.h"
20 // Constructor/destructor
21 upsEvents::upsEvents(HINSTANCE appinst
, upsMenu
*menu
) :
28 upsEvents::~upsEvents()
32 // Dialog box handling functions
33 void upsEvents::Show()
37 DialogBoxParam(_appinst
,
38 MAKEINTRESOURCE(IDD_EVENTS
),
45 BOOL CALLBACK
upsEvents::DialogProc(
53 // Retrieve virtual 'this' pointer. When we come in here the first time for
54 // the WM_INITDIALOG message, the pointer is in lParam. We then store it in
55 // the user data so it can be retrieved on future calls.
56 if (uMsg
== WM_INITDIALOG
)
58 // Set dialog user data to our "this" pointer which comes in via lParam.
59 // On subsequent calls, this will be retrieved by the code below.
60 SetWindowLong(hwnd
, GWL_USERDATA
, lParam
);
61 _this
= (upsEvents
*)lParam
;
65 // We've previously been initialized, so retrieve pointer from user data
66 _this
= (upsEvents
*)GetWindowLong(hwnd
, GWL_USERDATA
);
69 // Call thru to non-static member function
70 return _this
->DialogProcess(hwnd
, uMsg
, wParam
, lParam
);
73 BOOL
upsEvents::DialogProcess(
81 // Silly: Save initial window size for use as minimum size. There's
82 // probably some programmatic way to fetch this from the resource when
83 // we need it, but I can't find it. So we'll save it at runtime.
84 GetWindowRect(hwnd
, &_rect
);
86 // Initialize control wrappers
87 _events
= new ListView(hwnd
, IDC_LIST
, 1);
89 // Save a copy of our window handle for later use.
90 // Important to do this AFTER everything needed by Update() is
91 // initialized and ready to go since that function may be called at any
92 // time from the wintray timer thread.
97 SetForegroundWindow(hwnd
);
100 case WM_GETMINMAXINFO
:
101 // Restrict minimum size to initial window size
102 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
103 mmi
->ptMinTrackSize
.x
= _rect
.right
- _rect
.left
;
104 mmi
->ptMinTrackSize
.y
= _rect
.bottom
- _rect
.top
;
109 // Fetch new window size (esp client area size)
111 wininfo
.cbSize
= sizeof(wininfo
);
112 GetWindowInfo(hwnd
, &wininfo
);
114 // Fetch current listview position
115 HWND ctrl
= GetDlgItem(hwnd
, IDC_LIST
);
117 GetWindowRect(ctrl
, &gridrect
);
119 // Calculate new position and size of listview
120 int left
= gridrect
.left
- wininfo
.rcClient
.left
;
121 int top
= gridrect
.top
- wininfo
.rcClient
.top
;
122 int width
= wininfo
.rcClient
.right
- wininfo
.rcClient
.left
- 2*left
;
123 int height
= wininfo
.rcClient
.bottom
- wininfo
.rcClient
.top
- top
- left
;
127 ctrl
, NULL
, left
, top
, width
, height
, SWP_NOZORDER
| SWP_SHOWWINDOW
);
133 switch (LOWORD(wParam
)) {
137 EndDialog(hwnd
, TRUE
);
153 void upsEvents::Update(StatMgr
*statmgr
)
155 // Bail if window is not open
163 // Fetch events from apcupsd
164 alist
<astring
> events
;
165 if (!statmgr
->GetEvents(events
) || events
.empty())
172 alist
<astring
> *data
[] = {&events
};
173 _events
->UpdateAll(data
);