summaryrefslogtreecommitdiff
path: root/common/message.h
blob: dd1f0976bf24f4dbeb4850b0f17db568dbe375b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _MESSAGE_H_
#define _MESSAGE_H_

#include "array.h"

typedef void (*LC_MSG_CALLBACK) (int message, void *data, void *user);

typedef enum
{
  LC_MSG_FOCUS_CHANGED,
  //  LC_MSG_SELECTION_CHANGED,
  LC_MSG_COUNT
} LC_MSG_TYPES;

typedef struct
{
  LC_MSG_CALLBACK func;
  void *user;
} LC_MSG_STRUCT;

class Messenger
{
 public:
  Messenger ();
  ~Messenger ();

  void AddRef ()
    { m_nRef++; };
  void DecRef ()
    { m_nRef--; if (m_nRef == 0) delete this; };

  void Dispatch (int message, void *data);
  void Listen (LC_MSG_CALLBACK func, void *user);

 protected:
  int m_nRef;
  PtrArray<LC_MSG_STRUCT> m_Listeners;
};

#endif // _MESSAGE_H_