Some GTK fixes
[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)
81END_EVENT_TABLE()
82
83
f2a439ef
VK
84//
85// Constructor
86//
87
e44986e5 88nxObjectOverview::nxObjectOverview(wxWindow *parent, NXC_OBJECT *object)
45c2dc8b 89 : wxWindow(parent, wxID_ANY)
f2a439ef
VK
90{
91 wxBoxSizer *sizer;
92
f2a439ef
VK
93 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
94
f2a439ef
VK
95 m_header = new nxObjOverviewHeader(this);
96
97 sizer = new wxBoxSizer(wxVERTICAL);
98 sizer->Add(m_header, 0, wxALL | wxEXPAND, 7);
45c2dc8b 99 sizer->Add(new nxHeading(this, _T("Attributes"), wxDefaultPosition, wxSize(100, 20)), 0, wxALL | wxEXPAND, 7);
f2a439ef 100
45c2dc8b
VK
101 m_attrList = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER | wxNO_BORDER);
102 m_attrList->InsertColumn(0, _T("Name"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
103 m_attrList->InsertColumn(1, _T("Value"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
f2a439ef
VK
104 sizer->Add(m_attrList, 1, wxALL | wxEXPAND, 7);
105
45c2dc8b
VK
106 sizer->Add(new nxHeading(this, _T("Comments"), wxDefaultPosition, wxSize(100, 20)), 0, wxALL | wxEXPAND, 7);
107 m_comments = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
108 wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP | wxTE_RICH | wxTE_AUTO_URL | wxNO_BORDER);
109 sizer->Add(m_comments, 1, wxALL | wxEXPAND, 7);
110
f2a439ef
VK
111 SetSizer(sizer);
112 sizer->SetSizeHints(this);
45c2dc8b
VK
113
114 SetObject(object);
f2a439ef
VK
115}
116
117
118//
119// Set current object
120//
121
122void nxObjectOverview::SetObject(NXC_OBJECT *object)
123{
124 TCHAR temp[32];
125
126 m_object = object;
127 m_header->SetObject(object);
128
129 m_attrList->DeleteAllItems();
130 InsertItem(_T("ID"), m_object->dwId);
131 InsertItem(_T("Class"), NXMCGetClassName(m_object->iClass));
c17b35ef 132 InsertItem(_T("Status"), NXMCGetStatusText(m_object->iStatus));
f2a439ef
VK
133 if (m_object->dwIpAddr != 0)
134 InsertItem(_T("IP Address"), IpToStr(m_object->dwIpAddr, temp));
135
136 // Class-specific information
137 switch(m_object->iClass)
138 {
139 case OBJECT_SUBNET:
140 InsertItem(_T("Network Mask"), IpToStr(m_object->subnet.dwIpNetMask, temp));
141 break;
142 case OBJECT_NODE:
143 if (m_object->node.dwFlags & NF_IS_NATIVE_AGENT)
144 {
145 InsertItem(_T("NetXMS Agent"), _T("Active"));
146 InsertItem(_T("Agent Version"), m_object->node.szAgentVersion);
147 InsertItem(_T("Platform Name"), m_object->node.szPlatformName);
148 }
149 else
150 {
151 InsertItem(_T("NetXMS Agent"), _T("Inactive"));
152 }
153 if (m_object->node.dwFlags & NF_IS_SNMP)
154 {
155 InsertItem(_T("SNMP Agent"), _T("Active"));
156 InsertItem(_T("SNMP OID"), m_object->node.szObjectId);
157 }
158 else
159 {
160 InsertItem(_T("SNMP Agent"), _T("Inactive"));
161 }
162 InsertItem(_T("Node Type"), NXMCGetNodeTypeName(m_object->node.dwNodeType));
163 break;
164 case OBJECT_INTERFACE:
165 if (m_object->dwIpAddr != 0)
166 InsertItem(_T("IP Netmask"), IpToStr(m_object->iface.dwIpNetMask, temp));
167 InsertItem(_T("Index"), m_object->iface.dwIfIndex);
168 InsertItem(_T("Type"), NXMCGetIfTypeName((int)m_object->iface.dwIfType));
169 BinToStr(m_object->iface.bMacAddr, MAC_ADDR_LENGTH, temp);
170 InsertItem(_T("MAC Address"), temp);
171 break;
172 default:
173 break;
174 }
45c2dc8b
VK
175
176 m_comments->SetValue(CHECK_NULL_EX(object->pszComments));
177
178 AdjustAttrList();
f2a439ef
VK
179}
180
181
182//
183// Insert item into attributes list
184//
185
186void nxObjectOverview::InsertItem(const TCHAR *name, const TCHAR *value)
187{
188 long item;
189
190 item = m_attrList->InsertItem(0x7FFFFFFF, name);
191 m_attrList->SetItem(item, 1, value);
192}
193
194void nxObjectOverview::InsertItem(const TCHAR *name, DWORD value)
195{
196 TCHAR buffer[32];
197
198 _stprintf(buffer, _T("%d"), value);
199 InsertItem(name, buffer);
200}
45c2dc8b
VK
201
202
203//
204// Resize handler
205//
206
207void nxObjectOverview::OnSize(wxSizeEvent &event)
208{
209 Layout();
210}
211
212
213//
214// Adjust attribute list
215//
216
217void nxObjectOverview::AdjustAttrList()
218{
219 int i, count, w, h, width;
220 wxListItem item;
221
222 count = m_attrList->GetItemCount();
223 for(i = 0, width = 0; i < count; i++)
224 {
225 item.SetId(i);
226 item.SetColumn(1);
227 item.SetMask(wxLIST_MASK_TEXT);
228 m_attrList->GetItem(item);
229 m_attrList->GetTextExtent(item.GetText(), &w, &h);
230 if (width < w)
231 width = w;
232 }
233 m_attrList->SetColumnWidth(1, width + 20);
234}