Console compiles on UNIX with UNICODE
[public/netxms.git] / src / client / console / plugins / ObjectBrowser / overview.cpp
CommitLineData
f2a439ef
VK
1/*
2** NetXMS - Network Management System
3** Portable management console - Object Browser plugin
4** Copyright (C) 2007 Victor Kirhenshtein
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
20** File: overview.cpp
21**
22**/
23
24#include "object_browser.h"
25
26
27//
28// Header's event table
29//
30
31BEGIN_EVENT_TABLE(nxObjOverviewHeader, wxWindow)
32 EVT_PAINT(nxObjOverviewHeader::OnPaint)
33END_EVENT_TABLE()
34
35
36//
37// Header's constructor
38//
39
40nxObjOverviewHeader::nxObjOverviewHeader(wxWindow *parent)
41 : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(100, 40))
42{
43 m_object = NULL;
ab7d2f14 44 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
f2a439ef
VK
45}
46
47
48//
49// Set current object
50//
51
52void nxObjOverviewHeader::SetObject(NXC_OBJECT *object)
53{
54 m_object = object;
55 Refresh();
56}
57
58
59//
60// Paint header
61//
62
63void nxObjOverviewHeader::OnPaint(wxPaintEvent &event)
64{
65 wxPaintDC dc(this);
66
e44986e5
VK
67 if (m_object == NULL)
68 return;
69
c17b35ef 70 dc.SetFont(GetFont());
f2a439ef
VK
71 dc.DrawText(m_object->szName, 40, 3);
72}
73
74
45c2dc8b
VK
75//
76// Event table
77//
78
79BEGIN_EVENT_TABLE(nxObjectOverview, wxWindow)
80 EVT_SIZE(nxObjectOverview::OnSize)
e1ebe70d 81 EVT_TEXT_URL(wxID_TEXT_CTRL, nxObjectOverview::OnTextURL)
45c2dc8b
VK
82END_EVENT_TABLE()
83
84
f2a439ef
VK
85//
86// Constructor
87//
88
e44986e5 89nxObjectOverview::nxObjectOverview(wxWindow *parent, NXC_OBJECT *object)
45c2dc8b 90 : wxWindow(parent, wxID_ANY)
f2a439ef
VK
91{
92 wxBoxSizer *sizer;
93
f2a439ef
VK
94 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
95
f2a439ef
VK
96 m_header = new nxObjOverviewHeader(this);
97
98 sizer = new wxBoxSizer(wxVERTICAL);
99 sizer->Add(m_header, 0, wxALL | wxEXPAND, 7);
45c2dc8b 100 sizer->Add(new nxHeading(this, _T("Attributes"), wxDefaultPosition, wxSize(100, 20)), 0, wxALL | wxEXPAND, 7);
f2a439ef 101
45c2dc8b
VK
102 m_attrList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER | wxNO_BORDER);
103 m_attrList->InsertColumn(0, _T("Name"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
104 m_attrList->InsertColumn(1, _T("Value"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
f2a439ef
VK
105 sizer->Add(m_attrList, 1, wxALL | wxEXPAND, 7);
106
45c2dc8b 107 sizer->Add(new nxHeading(this, _T("Comments"), wxDefaultPosition, wxSize(100, 20)), 0, wxALL | wxEXPAND, 7);
e1ebe70d 108 m_comments = new wxTextCtrl(this, wxID_TEXT_CTRL, wxEmptyString, wxDefaultPosition,
45c2dc8b
VK
109 wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP | wxTE_RICH | wxTE_AUTO_URL | wxNO_BORDER);
110 sizer->Add(m_comments, 1, wxALL | wxEXPAND, 7);
111
f2a439ef
VK
112 SetSizer(sizer);
113 sizer->SetSizeHints(this);
45c2dc8b
VK
114
115 SetObject(object);
f2a439ef
VK
116}
117
118
119//
120// Set current object
121//
122
123void nxObjectOverview::SetObject(NXC_OBJECT *object)
124{
125 TCHAR temp[32];
126
127 m_object = object;
128 m_header->SetObject(object);
129
130 m_attrList->DeleteAllItems();
131 InsertItem(_T("ID"), m_object->dwId);
132 InsertItem(_T("Class"), NXMCGetClassName(m_object->iClass));
c17b35ef 133 InsertItem(_T("Status"), NXMCGetStatusText(m_object->iStatus));
f2a439ef
VK
134 if (m_object->dwIpAddr != 0)
135 InsertItem(_T("IP Address"), IpToStr(m_object->dwIpAddr, temp));
136
137 // Class-specific information
138 switch(m_object->iClass)
139 {
140 case OBJECT_SUBNET:
141 InsertItem(_T("Network Mask"), IpToStr(m_object->subnet.dwIpNetMask, temp));
142 break;
143 case OBJECT_NODE:
144 if (m_object->node.dwFlags & NF_IS_NATIVE_AGENT)
145 {
146 InsertItem(_T("NetXMS Agent"), _T("Active"));
147 InsertItem(_T("Agent Version"), m_object->node.szAgentVersion);
148 InsertItem(_T("Platform Name"), m_object->node.szPlatformName);
149 }
150 else
151 {
152 InsertItem(_T("NetXMS Agent"), _T("Inactive"));
153 }
154 if (m_object->node.dwFlags & NF_IS_SNMP)
155 {
156 InsertItem(_T("SNMP Agent"), _T("Active"));
157 InsertItem(_T("SNMP OID"), m_object->node.szObjectId);
158 }
159 else
160 {
161 InsertItem(_T("SNMP Agent"), _T("Inactive"));
162 }
163 InsertItem(_T("Node Type"), NXMCGetNodeTypeName(m_object->node.dwNodeType));
164 break;
165 case OBJECT_INTERFACE:
166 if (m_object->dwIpAddr != 0)
167 InsertItem(_T("IP Netmask"), IpToStr(m_object->iface.dwIpNetMask, temp));
168 InsertItem(_T("Index"), m_object->iface.dwIfIndex);
169 InsertItem(_T("Type"), NXMCGetIfTypeName((int)m_object->iface.dwIfType));
170 BinToStr(m_object->iface.bMacAddr, MAC_ADDR_LENGTH, temp);
171 InsertItem(_T("MAC Address"), temp);
172 break;
173 default:
174 break;
175 }
45c2dc8b
VK
176
177 m_comments->SetValue(CHECK_NULL_EX(object->pszComments));
178
fc5e6cb9
VK
179 NXMCAdjustListColumn(m_attrList, 0);
180 NXMCAdjustListColumn(m_attrList, 1);
f2a439ef
VK
181}
182
183
184//
185// Insert item into attributes list
186//
187
188void nxObjectOverview::InsertItem(const TCHAR *name, const TCHAR *value)
189{
190 long item;
191
192 item = m_attrList->InsertItem(0x7FFFFFFF, name);
193 m_attrList->SetItem(item, 1, value);
194}
195
196void nxObjectOverview::InsertItem(const TCHAR *name, DWORD value)
197{
198 TCHAR buffer[32];
199
273da39a 200 _sntprintf(buffer, 32, _T("%d"), value);
f2a439ef
VK
201 InsertItem(name, buffer);
202}
45c2dc8b
VK
203
204
205//
206// Resize handler
207//
208
209void nxObjectOverview::OnSize(wxSizeEvent &event)
210{
211 Layout();
212}
213
214
e1ebe70d
VK
215//
216// URL event handler
217//
218
219void nxObjectOverview::OnTextURL(wxTextUrlEvent &event)
220{
221 if (event.GetMouseEvent().LeftDown())
222 {
223 wxString url = m_comments->GetRange(event.GetURLStart(), event.GetURLEnd());
224 wxLogDebug(_T("Opening URL: %s"), url.c_str());
225 wxLaunchDefaultBrowser(url, wxBROWSER_NEW_WINDOW);
226 }
227}