- Finished migration to new client library model
[public/netxms.git] / src / console / win32 / ObjectSelDlg.cpp
CommitLineData
ef44d5ea
VK
1// ObjectSelDlg.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "nxcon.h"
6#include "ObjectSelDlg.h"
7
8#ifdef _DEBUG
9#define new DEBUG_NEW
10#undef THIS_FILE
11static char THIS_FILE[] = __FILE__;
12#endif
13
14/////////////////////////////////////////////////////////////////////////////
15// CObjectSelDlg dialog
16
17
18CObjectSelDlg::CObjectSelDlg(CWnd* pParent /*=NULL*/)
19 : CDialog(CObjectSelDlg::IDD, pParent)
20{
21 //{{AFX_DATA_INIT(CObjectSelDlg)
22 // NOTE: the ClassWizard will add member initialization here
23 //}}AFX_DATA_INIT
24 m_dwNumObjects = 0;
25 m_pdwObjectList = NULL;
6849d9be 26 m_dwAllowedClasses = 0xFFFF; // Allow all classes by default
dbba623c 27 m_bSingleSelection = FALSE;
ef44d5ea
VK
28}
29
30
31CObjectSelDlg::~CObjectSelDlg()
32{
33 safe_free(m_pdwObjectList);
34}
35
36
37void CObjectSelDlg::DoDataExchange(CDataExchange* pDX)
38{
39 CDialog::DoDataExchange(pDX);
40 //{{AFX_DATA_MAP(CObjectSelDlg)
41 DDX_Control(pDX, IDC_LIST_OBJECTS, m_wndListCtrl);
42 //}}AFX_DATA_MAP
43}
44
45
46BEGIN_MESSAGE_MAP(CObjectSelDlg, CDialog)
47 //{{AFX_MSG_MAP(CObjectSelDlg)
48 ON_NOTIFY(NM_DBLCLK, IDC_LIST_OBJECTS, OnDblclkListObjects)
49 //}}AFX_MSG_MAP
50END_MESSAGE_MAP()
51
52/////////////////////////////////////////////////////////////////////////////
53// CObjectSelDlg message handlers
54
55
56//
57// WM_INITDIALOG message handler
58//
59
60BOOL CObjectSelDlg::OnInitDialog()
61{
62 RECT rect;
63 NXC_OBJECT_INDEX *pIndex;
64 DWORD i, dwNumObjects;
65 int iItem;
66 CBitmap bmp;
6849d9be
VK
67 static DWORD dwClassMask[8] = { 0, SCL_SUBNET, SCL_NODE, SCL_INTERFACE,
68 SCL_NETWORK, SCL_CONTAINER, SCL_ZONE,
69 SCL_SERVICEROOT };
ef44d5ea
VK
70
71 CDialog::OnInitDialog();
72
73 // Prepare image list
2a41a4b5 74 m_imageList.Create(g_pObjectSmallImageList);
ef44d5ea
VK
75
76 // Setup list control
77 m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
78 m_wndListCtrl.GetClientRect(&rect);
79 m_wndListCtrl.InsertColumn(0, "Name", LVCFMT_LEFT, 150);
80 m_wndListCtrl.InsertColumn(1, "Class", LVCFMT_LEFT,
81 rect.right - 150 - GetSystemMetrics(SM_CXVSCROLL));
82 m_wndListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
dbba623c
VK
83 if (m_bSingleSelection)
84 {
85 ::SetWindowLong(m_wndListCtrl.m_hWnd, GWL_STYLE,
86 ::GetWindowLong(m_wndListCtrl.m_hWnd, GWL_STYLE) | LVS_SINGLESEL);
87 }
ef44d5ea
VK
88
89 // Fill in object list
babb8280
VK
90 NXCLockObjectIndex(g_hSession);
91 pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(g_hSession, &dwNumObjects);
ef44d5ea 92 for(i = 0; i < dwNumObjects; i++)
6849d9be 93 if (dwClassMask[pIndex[i].pObject->iClass] & m_dwAllowedClasses)
ef44d5ea
VK
94 {
95 iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pIndex[i].pObject->szName,
2a41a4b5 96 GetObjectImageIndex(pIndex[i].pObject));
ef44d5ea
VK
97 m_wndListCtrl.SetItemText(iItem, 1, g_szObjectClass[pIndex[i].pObject->iClass]);
98 m_wndListCtrl.SetItemData(iItem, pIndex[i].pObject->dwId);
99 }
babb8280 100 NXCUnlockObjectIndex(g_hSession);
ef44d5ea
VK
101
102 return TRUE;
103}
104
105
106//
107// Handle OK button
108//
109
110void CObjectSelDlg::OnOK()
111{
112 int iItem;
113 DWORD i;
114
115 m_dwNumObjects = m_wndListCtrl.GetSelectedCount();
116 if (m_dwNumObjects > 0)
117 {
118 // Build list of selected objects
119 m_pdwObjectList = (DWORD *)malloc(sizeof(DWORD) * m_dwNumObjects);
120 iItem = m_wndListCtrl.GetNextItem(-1, LVIS_SELECTED);
121 for(i = 0; iItem != -1; i++)
122 {
123 m_pdwObjectList[i] = m_wndListCtrl.GetItemData(iItem);
124 iItem = m_wndListCtrl.GetNextItem(iItem, LVIS_SELECTED);
125 }
126 CDialog::OnOK();
127 }
128 else
129 {
130 MessageBox("You should select at least one object", "Warning", MB_OK | MB_ICONEXCLAMATION);
131 }
132}
133
134
135//
136// Handler for doble click in list control
137//
138
139void CObjectSelDlg::OnDblclkListObjects(NMHDR* pNMHDR, LRESULT* pResult)
140{
141 if (m_wndListCtrl.GetSelectedCount() > 0)
142 PostMessage(WM_COMMAND, IDOK, 0);
143 *pResult = 0;
144}