- Search string now assumed with * at the ends in object browser
[public/netxms.git] / src / console / win32 / ObjectSearchBox.cpp
1 // ObjectSearchBox.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "nxcon.h"
6 #include "ObjectSearchBox.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14
15 //
16 // Constants
17 //
18
19 #define X_MARGIN 4
20 #define Y_MARGIN 4
21
22
23 /////////////////////////////////////////////////////////////////////////////
24 // CObjectSearchBox
25
26 CObjectSearchBox::CObjectSearchBox()
27 {
28 }
29
30 CObjectSearchBox::~CObjectSearchBox()
31 {
32 }
33
34
35 BEGIN_MESSAGE_MAP(CObjectSearchBox, CToolBox)
36 //{{AFX_MSG_MAP(CObjectSearchBox)
37 ON_WM_CREATE()
38 ON_WM_CTLCOLOR()
39 //}}AFX_MSG_MAP
40 ON_COMMAND(ID_FIND_OBJECT, OnFindObject)
41 ON_MESSAGE(WM_EDITBOX_EVENT, OnEditBoxEvent)
42 END_MESSAGE_MAP()
43
44
45 //
46 // WM_CREATE message handler
47 //
48
49 int CObjectSearchBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
50 {
51 RECT rect;
52
53 if (CToolBox::OnCreate(lpCreateStruct) == -1)
54 return -1;
55
56 // Create font
57 m_fontNormal.CreateFont(-MulDiv(7, GetDeviceCaps(GetDC()->m_hDC, LOGPIXELSY), 72),
58 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
59 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
60 VARIABLE_PITCH | FF_DONTCARE, "MS Sans Serif");
61
62 // Create static text
63 GetClientRect(&rect);
64 rect.left += X_MARGIN;
65 rect.right -= X_MARGIN;
66 rect.top += Y_MARGIN;
67 rect.bottom = rect.top + 12;
68 m_wndStatic.Create("Enter object name or IP address:", WS_CHILD | WS_VISIBLE, rect, this);
69 m_wndStatic.SetFont(&m_fontNormal);
70
71 // Create edit box
72 rect.top = rect.bottom + Y_MARGIN;
73 rect.bottom = rect.top + 18;
74 m_wndEditBox.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
75 rect, this, IDC_EDIT_SEARCH_STRING);
76 m_wndEditBox.SetFont(&m_fontNormal);
77 m_wndEditBox.SetLimitText(255);
78
79 // Create button
80 rect.top = rect.bottom + Y_MARGIN * 2;
81 rect.bottom = rect.top + 18;
82 rect.left = rect.right - 70;
83 m_wndButton.Create("&Find", WS_CHILD | WS_VISIBLE, rect, this, ID_FIND_OBJECT);
84 m_wndButton.SetFont(&m_fontNormal);
85
86 return 0;
87 }
88
89
90 //
91 // WM_CTLCOLOR message handler
92 //
93
94 HBRUSH CObjectSearchBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
95 {
96 HBRUSH hbr;
97
98 // Static control
99 if (pWnd->m_hWnd == m_wndStatic.m_hWnd)
100 {
101 hbr = CreateSolidBrush(RGB(255, 255, 255));
102 pDC->SetBkColor(RGB(255, 255, 255));
103 }
104
105 return hbr;
106 }
107
108
109 //
110 // WM_COMMAND::ID_FIND_OBJECT
111 //
112
113 void CObjectSearchBox::OnFindObject()
114 {
115 TCHAR szBuffer[256];
116
117 szBuffer[0] = _T('*');
118 m_wndEditBox.GetWindowText(&szBuffer[1], 255);
119 _tcscat(szBuffer, _T("*"));
120 GetParent()->SendMessage(WM_FIND_OBJECT, 0, (LPARAM)szBuffer);
121 }
122
123
124 //
125 // WM_EDITBOX_EVENT message handler
126 //
127
128 void CObjectSearchBox::OnEditBoxEvent(WPARAM wParam, LPARAM lParam)
129 {
130 if ((wParam == IDC_EDIT_SEARCH_STRING) && (lParam == EDITBOX_ENTER_PRESSED))
131 PostMessage(WM_COMMAND, ID_FIND_OBJECT, 0);
132 }