summaryrefslogtreecommitdiff
path: root/message_notify/mywindowlist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'message_notify/mywindowlist.cpp')
-rw-r--r--message_notify/mywindowlist.cpp149
1 files changed, 23 insertions, 126 deletions
diff --git a/message_notify/mywindowlist.cpp b/message_notify/mywindowlist.cpp
index 72a82e7..873d579 100644
--- a/message_notify/mywindowlist.cpp
+++ b/message_notify/mywindowlist.cpp
@@ -1,146 +1,43 @@
#include "common.h"
#include "mywindowlist.h"
+#include "collection.h"
-class WindowList {
+class WindowList: public LinkedList<HWND> {
public:
- struct ListNode {
- HWND hwnd;
- ListNode *next;
- };
-
- WindowList(): head(0), count(0) {}
- ~WindowList() {clear();}
-
- void clear() {
- ListNode *n;
- while(head) {
- n = head;
- head = head->next;
- delete n;
- }
- }
-
- void AddWindow(HWND hwnd) {
- if(HasWindow(hwnd)) return;
-
- ListNode *n = new ListNode;
- n->hwnd = hwnd;
- n->next = head;
- head = n;
- count++;
- }
-
- void RemoveWindow(HWND hwnd) {
- ListNode *n = head, *prev = 0;
- while(n) {
- if(n->hwnd == hwnd) {
- if(prev) prev->next = n->next;
- else head = n->next;
- delete n;
- count--;
- break;
- }
- prev = n;
- n = n->next;
- }
- }
+ WindowList(): LinkedList<HWND>() {}
+ virtual ~WindowList() {}
void PostListMessage(UINT msg, WPARAM wParam, LPARAM lParam) {
- ListNode *n = head;
- while(n) {
- PostMessage(n->hwnd, msg, wParam, lParam);
- n = n->next;
- }
- }
-
- bool HasWindow(HWND hwnd) {
- ListNode *n = head;
+ ListNode<HWND> *n = head;
while(n) {
- if(n->hwnd == hwnd)
- return true;
+ PostMessage(n->val, msg, wParam, lParam);
n = n->next;
}
- return false;
- }
-
- int GetCount() {
- return count;
}
-
-protected:
- ListNode *head;
- int count;
};
-class WindowMap {
+class WindowMap: public Map<HANDLE, WindowList> {
public:
- struct ListNode {
- HANDLE hContact;
- WindowList list;
- ListNode *next;
- };
-
- WindowMap(): head(0) {}
- ~WindowMap() {clear();}
-
- void clear() {
- ListNode *n = head;
- while(head) {
- n = head;
- head = head->next;
- delete n;
- }
- }
-
- WindowList *FindList(HANDLE hContact) {
- ListNode *n = head;
- while(n) {
- if(n->hContact == hContact)
- return &n->list;
- n = n->next;
- }
- return 0;
- }
+ WindowMap(): Map<HANDLE, WindowList>() {}
+ virtual ~WindowMap() {}
void Add(HANDLE hContact, HWND hWnd) {
- WindowList *l = FindList(hContact);
- if(l) l->AddWindow(hWnd);
- else {
- ListNode *n = new ListNode;
- n->hContact = hContact;
- n->list.AddWindow(hWnd);
- n->next = head;
- head = n;
- }
+ (*this)[hContact].add(hWnd);
}
void Remove(HANDLE hContact, HWND hWnd) {
- ListNode *n = head, *prev = 0;
- while(n) {
- if(n->hContact == hContact) {
- n->list.RemoveWindow(hWnd);
- if(n->list.GetCount() == 0) {
- if(prev) prev->next = n->next;
- else head = n->next;
- delete n;
- }
- break;
- }
- prev = n;
- n = n->next;
+ if(contains(hContact)) {
+ (*this)[hContact].remove(hWnd);
+ if((*this)[hContact].size() == 0)
+ remove(hContact);
}
}
void PostMapMessage(UINT msg, WPARAM wParam, LPARAM lParam) {
- ListNode *n = head;
- while(n) {
- n->list.PostListMessage(msg, wParam, lParam);
- n = n->next;
- }
+ for(Iterator i = start(); i.has_val();i.next())
+ i.val().second.PostListMessage(msg, wParam, lParam);
}
-protected:
- ListNode *head;
};
WindowMap window_map;
@@ -174,8 +71,8 @@ void PostMessageWindowList(UINT msg, WPARAM wParam, LPARAM lParam) {
void PostMessageWindowListContact(HANDLE hContact, UINT msg, WPARAM wParam, LPARAM lParam) {
EnterCriticalSection(&list_cs);
- WindowList *l = window_map.FindList(hContact);
- if(l) l->PostListMessage(msg, wParam, lParam);
+ if(window_map.contains(hContact))
+ window_map[hContact].PostListMessage(msg, wParam, lParam);
LeaveCriticalSection(&list_cs);
}
@@ -184,8 +81,8 @@ bool InList(HANDLE hContact, HWND hWnd) {
bool ret = false;
EnterCriticalSection(&list_cs);
- WindowList *l = window_map.FindList(hContact);
- if(l) ret = l->HasWindow(hWnd);
+ if(window_map.contains(hContact) && window_map[hContact].contains(hWnd))
+ ret = true;
LeaveCriticalSection(&list_cs);
return ret;
@@ -195,8 +92,8 @@ int CountList(HANDLE hContact) {
int count = 0;
EnterCriticalSection(&list_cs);
- WindowList *l = window_map.FindList(hContact);
- if(l) count = l->GetCount();
+ if(window_map.contains(hContact))
+ count = window_map[hContact].size();
LeaveCriticalSection(&list_cs);
return count;
@@ -205,7 +102,7 @@ int CountList(HANDLE hContact) {
bool EmptyList(HANDLE hContact) {
EnterCriticalSection(&list_cs);
- bool ret = (window_map.FindList(hContact) == 0);
+ bool ret = !window_map.contains(hContact);
LeaveCriticalSection(&list_cs);
return ret;