Various improvements
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 23 Jul 2007 22:38:06 +0000 (22:38 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 23 Jul 2007 22:38:06 +0000 (22:38 +0000)
12 files changed:
.gitattributes
src/client/console/include/nxmc_api.h
src/client/console/libnxmc/alarms.cpp
src/client/console/nxmc/mainfrm.cpp
src/client/console/nxmc/rc/icons/small/Makefile.am
src/client/console/nxmc/rc/icons/small/sort_down.xpm [new file with mode: 0644]
src/client/console/nxmc/rc/icons/small/sort_up.xpm [new file with mode: 0644]
src/client/console/nxmc/rc/manual.xrc
src/client/console/plugins/AlarmBrowser/alarm_browser.h
src/client/console/plugins/AlarmBrowser/view.cpp
src/client/console/plugins/ObjectBrowser/object_browser.h
src/client/console/plugins/ObjectBrowser/overview.cpp

index 3d28a5d..dcdbfea 100644 (file)
@@ -492,6 +492,8 @@ src/client/console/nxmc/rc/icons/small/node.xpm -text
 src/client/console/nxmc/rc/icons/small/normal.xpm -text
 src/client/console/nxmc/rc/icons/small/outstanding.xpm -text
 src/client/console/nxmc/rc/icons/small/service_root.xpm -text
+src/client/console/nxmc/rc/icons/small/sort_down.xpm -text
+src/client/console/nxmc/rc/icons/small/sort_up.xpm -text
 src/client/console/nxmc/rc/icons/small/subnet.xpm -text
 src/client/console/nxmc/rc/icons/small/template.xpm -text
 src/client/console/nxmc/rc/icons/small/template_group.xpm -text
index 690c837..de94a44 100644 (file)
@@ -195,6 +195,7 @@ typedef struct
 #define wxID_TREE_CTRL         (wxID_HIGHEST + 500)
 #define wxID_NOTEBOOK_CTRL     (wxID_HIGHEST + 501)
 #define wxID_LIST_CTRL         (wxID_HIGHEST + 502)
+#define wxID_TEXT_CTRL         (wxID_HIGHEST + 503)
 
 
 //
@@ -272,10 +273,10 @@ struct CODE_TO_TEXT
 
 
 //
-// Additional array types
+// Additional array and hash types
 //
 
-WX_DEFINE_ARRAY(NXC_ALARM*, nxArrayOfAlarms);
+WX_DECLARE_HASH_MAP(DWORD, NXC_ALARM*, wxIntegerHash, wxIntegerEqual, nxAlarmList);
 
 
 //
@@ -326,7 +327,7 @@ wxImageList LIBNXMC_EXPORTABLE *NXMCGetImageListCopy(int list);
 
 void LIBNXMC_EXPORTABLE NXMCInitAlarms(DWORD count, NXC_ALARM *list);
 void LIBNXMC_EXPORTABLE NXMCUpdateAlarms(DWORD code, NXC_ALARM *data);
-nxArrayOfAlarms LIBNXMC_EXPORTABLE *NXMCGetAlarmList();
+nxAlarmList LIBNXMC_EXPORTABLE *NXMCGetAlarmList();
 void LIBNXMC_EXPORTABLE NXMCUnlockAlarmList();
 
 TCHAR LIBNXMC_EXPORTABLE *NXMCFormatTimeStamp(time_t timeStamp, TCHAR *buffer, int type);
index c68873b..be2cb52 100644 (file)
@@ -28,7 +28,7 @@
 // Static data
 //
 
-static nxArrayOfAlarms s_alarmList;
+static nxAlarmList s_alarmList;
 static MUTEX s_mutexAlarmAccess = INVALID_MUTEX_HANDLE;
 
 
@@ -42,22 +42,7 @@ void LIBNXMC_EXPORTABLE NXMCInitAlarms(DWORD count, NXC_ALARM *list)
 
        s_mutexAlarmAccess = MutexCreate();
        for(i = 0; i < count; i++)
-               s_alarmList.Add((NXC_ALARM *)nx_memdup(&list[i], sizeof(NXC_ALARM)));
-}
-
-
-//
-// Find alarm in list
-//
-
-static int FindAlarm(DWORD id)
-{
-       int i;
-
-       for(i = 0; i < (int)s_alarmList.GetCount(); i++)
-               if (s_alarmList[i]->dwAlarmId == id)
-                       return i;
-       return wxNOT_FOUND;
+               s_alarmList[list[i].dwAlarmId] = (NXC_ALARM *)nx_memdup(&list[i], sizeof(NXC_ALARM));
 }
 
 
@@ -67,32 +52,32 @@ static int FindAlarm(DWORD id)
 
 void LIBNXMC_EXPORTABLE NXMCUpdateAlarms(DWORD code, NXC_ALARM *data)
 {
-       int index;
+       nxAlarmList::iterator it;
 
        MutexLock(s_mutexAlarmAccess, INFINITE);
        switch(code)
        {
                case NX_NOTIFY_NEW_ALARM:
-                       s_alarmList.Add((NXC_ALARM *)nx_memdup(data, sizeof(NXC_ALARM)));
+                       s_alarmList[data->dwAlarmId] = (NXC_ALARM *)nx_memdup(data, sizeof(NXC_ALARM));
                        break;
       case NX_NOTIFY_ALARM_DELETED:
       case NX_NOTIFY_ALARM_TERMINATED:
-                       index = FindAlarm(data->dwAlarmId);
-                       if (index != wxNOT_FOUND)
+                       it = s_alarmList.find(data->dwAlarmId);
+                       if (it != s_alarmList.end())
                        {
-                               free(s_alarmList[index]);
-                               s_alarmList.RemoveAt(index);
+                               free(it->second);
+                               s_alarmList.erase(it);
                        }
                        break;
       case NX_NOTIFY_ALARM_CHANGED:
-                       index = FindAlarm(data->dwAlarmId);
-                       if (index != wxNOT_FOUND)
+                       it = s_alarmList.find(data->dwAlarmId);
+                       if (it != s_alarmList.end())
                        {
-                               memcpy(s_alarmList[index], data, sizeof(NXC_ALARM));
+                               memcpy(it->second, data, sizeof(NXC_ALARM));
                        }
                        else
                        {
-                               s_alarmList.Add((NXC_ALARM *)nx_memdup(data, sizeof(NXC_ALARM)));
+                               s_alarmList[data->dwAlarmId] = (NXC_ALARM *)nx_memdup(data, sizeof(NXC_ALARM));
                        }
                        break;
        }
@@ -104,7 +89,7 @@ void LIBNXMC_EXPORTABLE NXMCUpdateAlarms(DWORD code, NXC_ALARM *data)
 // Get alarm list
 //
 
-nxArrayOfAlarms LIBNXMC_EXPORTABLE *NXMCGetAlarmList()
+nxAlarmList LIBNXMC_EXPORTABLE *NXMCGetAlarmList()
 {
        MutexLock(s_mutexAlarmAccess, INFINITE);
        return &s_alarmList;
index f8729d7..3fa43d9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mainfrm.cpp,v 1.6 2007-07-23 06:39:12 victor Exp $ */
+/* $Id: mainfrm.cpp,v 1.7 2007-07-23 22:38:06 victor Exp $ */
 /* 
 ** NetXMS - Network Management System
 ** Portable management console
@@ -97,11 +97,6 @@ wxAuiNotebook *nxMainFrame::CreateNotebook()
    m_notebook = new nxAuiNotebook(this,
                                   wxPoint(clientSize.x, clientSize.y),
                                   wxSize(430,200));
-   
-   wxBitmap bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
-   m_notebook->AddPage(new wxTextCtrl(m_notebook, wxID_ANY, wxT("Some text"),
-                wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER) , wxT("wxTextCtrl 1"), false, bmp);
-
        return m_notebook;
 }
 
index 634dfa0..a946615 100644 (file)
@@ -25,6 +25,8 @@ EXTRA_DIST = \
        normal.xpm \
        outstanding.xpm \
        service_root.xpm \
+       sort_down.xpm \
+       sort_up.xpm \
        subnet.xpm \
        template.xpm \
        template_group.xpm \
diff --git a/src/client/console/nxmc/rc/icons/small/sort_down.xpm b/src/client/console/nxmc/rc/icons/small/sort_down.xpm
new file mode 100644 (file)
index 0000000..8ea3d0d
--- /dev/null
@@ -0,0 +1,24 @@
+/* XPM */
+static char *sort_down[] = {
+/* columns rows colors chars-per-pixel */
+"16 16 2 1",
+"  c black",
+". c None",
+/* pixels */
+"................",
+"................",
+"................",
+"................",
+"................",
+"...          ...",
+"....        ....",
+".....      .....",
+"......    ......",
+".......  .......",
+"................",
+"................",
+"................",
+"................",
+"................",
+"................"
+};
diff --git a/src/client/console/nxmc/rc/icons/small/sort_up.xpm b/src/client/console/nxmc/rc/icons/small/sort_up.xpm
new file mode 100644 (file)
index 0000000..185d6f6
--- /dev/null
@@ -0,0 +1,24 @@
+/* XPM */
+static char *sort_up[] = {
+/* columns rows colors chars-per-pixel */
+"16 16 2 1",
+"  c black",
+". c None",
+/* pixels */
+"................",
+"................",
+"................",
+"................",
+"................",
+".......  .......",
+"......    ......",
+".....      .....",
+"....        ....",
+"...          ...",
+"................",
+"................",
+"................",
+"................",
+"................",
+"................"
+};
index 94d60c7..6e1e7ae 100644 (file)
@@ -35,6 +35,8 @@
 
        <!-- Miscellanious small icons -->
        <object class="wxIcon" name="icoSmallInformation">icons/small/information.xpm</object>
+       <object class="wxIcon" name="icoSortDown">icons/small/sort_down.xpm</object>
+       <object class="wxIcon" name="icoSortUp">icons/small/sort_up.xpm</object>
 
        <!-- Busy dialog -->
        <object class="wxDialog" name="nxBusyDialog">
index 64fac96..dbab455 100644 (file)
@@ -37,7 +37,9 @@
 class nxAlarmView : public wxWindow
 {
 private:
-       wxListCtrl *m_wndListCtrl;
+       wxListView *m_wndListCtrl;
+       long m_sortMode;
+       long m_sortDir;
 
        void AddAlarm(NXC_ALARM *alarm);
        void UpdateAlarm(long item, NXC_ALARM *alarm);
@@ -51,6 +53,7 @@ public:
 protected:
        void OnSize(wxSizeEvent &event);
        void OnListItemRightClick(wxListEvent &event);
+       void OnListColumnClick(wxListEvent &event);
 
        DECLARE_EVENT_TABLE()
 };
index 72eda28..479f74e 100644 (file)
@@ -31,6 +31,7 @@
 BEGIN_EVENT_TABLE(nxAlarmView, wxWindow)
        EVT_SIZE(nxAlarmView::OnSize)
        EVT_LIST_ITEM_RIGHT_CLICK(wxID_LIST_CTRL, nxAlarmView::OnListItemRightClick)
+       EVT_LIST_COL_CLICK(wxID_LIST_CTRL, nxAlarmView::OnListColumnClick)
 END_EVENT_TABLE()
 
 
@@ -41,7 +42,10 @@ END_EVENT_TABLE()
 nxAlarmView::nxAlarmView(wxWindow *parent)
             : wxWindow(parent, wxID_ANY)
 {
-       m_wndListCtrl = new wxListCtrl(this, wxID_LIST_CTRL, wxDefaultPosition, wxDefaultSize,
+       wxConfig::Get()->Read(_T("/AlarmView/SortMode"), &m_sortMode, 0);
+       wxConfig::Get()->Read(_T("/AlarmView/SortDir"), &m_sortDir, -1);
+
+       m_wndListCtrl = new wxListView(this, wxID_LIST_CTRL, wxDefaultPosition, wxDefaultSize,
                                       wxLC_REPORT | wxLC_HRULES | wxLC_VRULES);
        m_wndListCtrl->InsertColumn(0, _T("Severity"), wxLIST_FORMAT_LEFT, 70);
        m_wndListCtrl->InsertColumn(1, _T("State"), wxLIST_FORMAT_LEFT, 70);
@@ -54,6 +58,8 @@ nxAlarmView::nxAlarmView(wxWindow *parent)
        imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallOutstanding")));
        imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallAcknowledged")));
        imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSmallTerminated")));
+       imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSortUp")));
+       imgList->Add(wxXmlResource::Get()->LoadIcon(_T("icoSortDown")));
        m_wndListCtrl->AssignImageList(imgList, wxIMAGE_LIST_SMALL);
 }
 
@@ -75,15 +81,15 @@ void nxAlarmView::OnSize(wxSizeEvent &event)
 
 void nxAlarmView::RefreshView()
 {
-       nxArrayOfAlarms *list;
-       size_t i;
+       nxAlarmList *list;
+       nxAlarmList::iterator it;
 
        m_wndListCtrl->DeleteAllItems();
        list = NXMCGetAlarmList();
-
-       for(i = 0; i < list->GetCount(); i++)
+       
+       for(it = list->begin(); it != list->end(); it++)
        {
-               AddAlarm((*list)[i]);
+               AddAlarm(it->second);
        }
 
        NXMCUnlockAlarmList();
@@ -154,3 +160,68 @@ void nxAlarmView::OnListItemRightClick(wxListEvent &event)
                delete menu;
        }
 }
+
+
+//
+// Alarm comparision callback
+//
+
+static nxAlarmList *s_alarmList;
+
+static int wxCALLBACK CompareAlarms(long item1, long item2, long sortData)
+{
+       long mode = sortData & 0x7FFF;
+       int rc;
+       nxAlarmList::iterator it1, it2;
+
+       it1 = s_alarmList->find(item1);
+       it2 = s_alarmList->find(item2);
+       if ((it1 == s_alarmList->end()) || (it2 == s_alarmList->end()))
+       {
+               wxLogWarning(_T("CompareAlarms: invalid iterator returned"));
+               return 0;       // Shouldn't happen
+       }
+
+       switch(mode)
+       {
+               case 0:         // Severity
+                       rc = COMPARE_NUMBERS(it1->second->nCurrentSeverity, it2->second->nCurrentSeverity);
+                       break;
+               case 1:         // State
+                       rc = COMPARE_NUMBERS(it1->second->nState, it2->second->nState);
+                       break;
+               case 3:         // Message
+                       rc = _tcsicmp(it1->second->szMessage, it2->second->szMessage);
+                       break;
+               default:
+                       rc = 0;
+                       break;
+       }
+
+       return (sortData & 0x8000) ? rc : -rc;
+}
+
+
+//
+// Handler for column click
+//
+
+void nxAlarmView::OnListColumnClick(wxListEvent &event)
+{
+       m_wndListCtrl->ClearColumnImage(m_sortMode);
+
+       if (m_sortMode == event.GetColumn())
+       {
+               m_sortDir = -m_sortDir;
+       }
+       else
+       {
+               m_sortMode = event.GetColumn();
+       }
+
+       s_alarmList = NXMCGetAlarmList();
+       m_wndListCtrl->SortItems(CompareAlarms, m_sortMode | ((m_sortDir == 1) ? 0x8000 : 0));
+       NXMCUnlockAlarmList();
+
+       m_wndListCtrl->SetColumnImage(m_sortMode, STATUS_TESTING + ((m_sortDir == 1) ? 4 : 5));
+}
index bee965e..2012fc1 100644 (file)
@@ -86,6 +86,7 @@ public:
        // Event handlers
 protected:
        void OnSize(wxSizeEvent &event);
+       void OnTextURL(wxTextUrlEvent &event);
 
        DECLARE_EVENT_TABLE()
 };
index fd3b6ca..694d519 100644 (file)
@@ -78,6 +78,7 @@ void nxObjOverviewHeader::OnPaint(wxPaintEvent &event)
 
 BEGIN_EVENT_TABLE(nxObjectOverview, wxWindow)
        EVT_SIZE(nxObjectOverview::OnSize)
+       EVT_TEXT_URL(wxID_TEXT_CTRL, nxObjectOverview::OnTextURL)
 END_EVENT_TABLE()
 
 
@@ -104,7 +105,7 @@ nxObjectOverview::nxObjectOverview(wxWindow *parent, NXC_OBJECT *object)
        sizer->Add(m_attrList, 1, wxALL | wxEXPAND, 7);
 
        sizer->Add(new nxHeading(this, _T("Comments"), wxDefaultPosition, wxSize(100, 20)), 0, wxALL | wxEXPAND, 7);
-       m_comments = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
+       m_comments = new wxTextCtrl(this, wxID_TEXT_CTRL, wxEmptyString, wxDefaultPosition,
                                    wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP | wxTE_RICH | wxTE_AUTO_URL | wxNO_BORDER);
        sizer->Add(m_comments, 1, wxALL | wxEXPAND, 7);
 
@@ -232,3 +233,18 @@ void nxObjectOverview::AdjustAttrList()
        }
        m_attrList->SetColumnWidth(1, width + 20);
 }
+
+
+//
+// URL event handler
+//
+
+void nxObjectOverview::OnTextURL(wxTextUrlEvent &event)
+{
+       if (event.GetMouseEvent().LeftDown())
+       {
+               wxString url = m_comments->GetRange(event.GetURLStart(), event.GetURLEnd());
+               wxLogDebug(_T("Opening URL: %s"), url.c_str());
+               wxLaunchDefaultBrowser(url, wxBROWSER_NEW_WINDOW);
+       }
+}