Fixed some Linux compatibility issues
[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;
44}
45
46
47//
48// Set current object
49//
50
51void nxObjOverviewHeader::SetObject(NXC_OBJECT *object)
52{
53 m_object = object;
54 Refresh();
55}
56
57
58//
59// Paint header
60//
61
62void nxObjOverviewHeader::OnPaint(wxPaintEvent &event)
63{
64 wxPaintDC dc(this);
65
e44986e5
VK
66 if (m_object == NULL)
67 return;
68
f2a439ef
VK
69 dc.DrawText(m_object->szName, 40, 3);
70}
71
72
73//
74// Constructor
75//
76
e44986e5 77nxObjectOverview::nxObjectOverview(wxWindow *parent, NXC_OBJECT *object)
f2a439ef
VK
78 : wxPanel(parent, wxID_ANY)
79{
80 wxBoxSizer *sizer;
81
f2a439ef
VK
82 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
83
e44986e5 84 m_object = object;
f2a439ef
VK
85
86 m_header = new nxObjOverviewHeader(this);
e44986e5 87 m_header->SetObject(object);
f2a439ef
VK
88
89 sizer = new wxBoxSizer(wxVERTICAL);
90 sizer->Add(m_header, 0, wxALL | wxEXPAND, 7);
91 sizer->Add(new nxHeading(this, _T("Attributes"), wxDefaultPosition, wxSize(500, 20)), 0, wxALL | wxEXPAND, 7);
92
93 m_attrList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
94 m_attrList->InsertColumn(0, _T("Name"), wxLIST_FORMAT_LEFT, 100);
95 m_attrList->InsertColumn(1, _T("Value"), wxLIST_FORMAT_LEFT, -1);
96 sizer->Add(m_attrList, 1, wxALL | wxEXPAND, 7);
97
98 SetSizer(sizer);
99 sizer->SetSizeHints(this);
100}
101
102
103//
104// Set current object
105//
106
107void nxObjectOverview::SetObject(NXC_OBJECT *object)
108{
109 TCHAR temp[32];
110
111 m_object = object;
112 m_header->SetObject(object);
113
114 m_attrList->DeleteAllItems();
115 InsertItem(_T("ID"), m_object->dwId);
116 InsertItem(_T("Class"), NXMCGetClassName(m_object->iClass));
117 if (m_object->dwIpAddr != 0)
118 InsertItem(_T("IP Address"), IpToStr(m_object->dwIpAddr, temp));
119
120 // Class-specific information
121 switch(m_object->iClass)
122 {
123 case OBJECT_SUBNET:
124 InsertItem(_T("Network Mask"), IpToStr(m_object->subnet.dwIpNetMask, temp));
125 break;
126 case OBJECT_NODE:
127 if (m_object->node.dwFlags & NF_IS_NATIVE_AGENT)
128 {
129 InsertItem(_T("NetXMS Agent"), _T("Active"));
130 InsertItem(_T("Agent Version"), m_object->node.szAgentVersion);
131 InsertItem(_T("Platform Name"), m_object->node.szPlatformName);
132 }
133 else
134 {
135 InsertItem(_T("NetXMS Agent"), _T("Inactive"));
136 }
137 if (m_object->node.dwFlags & NF_IS_SNMP)
138 {
139 InsertItem(_T("SNMP Agent"), _T("Active"));
140 InsertItem(_T("SNMP OID"), m_object->node.szObjectId);
141 }
142 else
143 {
144 InsertItem(_T("SNMP Agent"), _T("Inactive"));
145 }
146 InsertItem(_T("Node Type"), NXMCGetNodeTypeName(m_object->node.dwNodeType));
147 break;
148 case OBJECT_INTERFACE:
149 if (m_object->dwIpAddr != 0)
150 InsertItem(_T("IP Netmask"), IpToStr(m_object->iface.dwIpNetMask, temp));
151 InsertItem(_T("Index"), m_object->iface.dwIfIndex);
152 InsertItem(_T("Type"), NXMCGetIfTypeName((int)m_object->iface.dwIfType));
153 BinToStr(m_object->iface.bMacAddr, MAC_ADDR_LENGTH, temp);
154 InsertItem(_T("MAC Address"), temp);
155 break;
156 default:
157 break;
158 }
159}
160
161
162//
163// Insert item into attributes list
164//
165
166void nxObjectOverview::InsertItem(const TCHAR *name, const TCHAR *value)
167{
168 long item;
169
170 item = m_attrList->InsertItem(0x7FFFFFFF, name);
171 m_attrList->SetItem(item, 1, value);
172}
173
174void nxObjectOverview::InsertItem(const TCHAR *name, DWORD value)
175{
176 TCHAR buffer[32];
177
178 _stprintf(buffer, _T("%d"), value);
179 InsertItem(name, buffer);
180}