The Pedigree Project  0.1
Widget.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _WIDGET_H
21 #define _WIDGET_H
22 
23 #ifdef TARGET_LINUX
24 #include <stdint.h>
25 #include <unistd.h>
26 
27 #include <util.h>
28 #else
29 #include "pedigree/native/ipc/Ipc.h"
30 #include "pedigree/native/types.h"
31 #endif
32 
33 #include "pedigree/native/graphics/Graphics.h"
34 
35 #include <map>
36 #include <queue>
37 #include <string>
38 
43 enum WidgetMessages
44 {
45  RepaintNeeded,
46  Reposition,
47  MouseMove,
48  MouseDown,
49  MouseUp,
50  KeyDown,
51  KeyUp,
52  RawKeyDown,
53  RawKeyUp,
54  Focus,
55  NoFocus,
56  Terminate,
57 };
58 
59 typedef bool (*widgetCallback_t)(WidgetMessages, size_t, const void *);
60 
63 class Widget
64 {
65  public:
66  Widget();
67  virtual ~Widget();
68 
79  inline uint64_t getHandle() const
80  {
81  return m_Handle;
82  }
83 
97  bool construct(
98  const char *endpoint, const char *title, widgetCallback_t cb,
99  PedigreeGraphics::Rect &dimensions);
100 
106  bool setTitle(const std::string &newTitle);
107 
115  virtual bool
117 
123  bool redraw(PedigreeGraphics::Rect &rt);
124 
131  bool visibility(bool vis);
132 
136  void destroy();
137 
143  {
144  return m_SharedFramebuffer ? m_SharedFramebuffer->getBuffer() : 0;
145  }
146 
154  int getSocket() const
155  {
156  return m_Socket;
157  }
158 
163  static void checkForEvents(bool bAsync = false);
164 
165  private:
170  static void checkForMessage(size_t which, bool bResponse = false);
171 
173  static void handleMessage(const char *pMessageBuffer);
174 
176  static bool handlePendingMessages();
177 
179  widgetCallback_t getCallback() const
180  {
181  return m_EventCallback;
182  }
183 
186 
189 
191  uint64_t m_Handle;
192 
194  widgetCallback_t m_EventCallback;
195 
198  int m_Socket;
199 
200 #ifdef TARGET_LINUX
201 
203 #else
204 
206 #endif
207 
209  static std::map<uint64_t, Widget *> s_KnownWidgets;
210 
212  static std::queue<char *> s_PendingMessages;
213 
215  static size_t s_NumWidgets;
216 };
217 
220 #endif
static bool handlePendingMessages()
Definition: Widget.cc:562
virtual bool render(PedigreeGraphics::Rect &rt, PedigreeGraphics::Rect &dirty)=0
uint64_t getHandle() const
Definition: Widget.h:79
static void checkForEvents(bool bAsync=false)
Definition: Widget.cc:339
bool m_bConstructed
Definition: Widget.h:185
void * getRawFramebuffer()
Definition: Widget.h:142
static void checkForMessage(size_t which, bool bResponse=false)
Definition: Widget.cc:391
widgetCallback_t getCallback() const
Definition: Widget.h:179
Abstracts a buffer shared between multiple processes.
Definition: util.h:33
static std::map< uint64_t, Widget * > s_KnownWidgets
Definition: Widget.h:209
static size_t s_NumWidgets
Definition: Widget.h:215
bool redraw(PedigreeGraphics::Rect &rt)
Definition: Widget.cc:225
PedigreeGraphics::Framebuffer * m_pFramebuffer
Definition: Widget.h:188
bool visibility(bool vis)
Definition: Widget.cc:269
PedigreeIpc::SharedIpcMessage * m_SharedFramebuffer
Definition: Widget.h:205
void destroy()
Definition: Widget.cc:301
static std::queue< char * > s_PendingMessages
Definition: Widget.h:212
Definition: Widget.h:63
bool construct(const char *endpoint, const char *title, widgetCallback_t cb, PedigreeGraphics::Rect &dimensions)
Definition: Widget.cc:90
static void handleMessage(const char *pMessageBuffer)
Definition: Widget.cc:476
int m_Socket
Definition: Widget.h:198
bool setTitle(const std::string &newTitle)
Definition: Widget.cc:189
widgetCallback_t m_EventCallback
Definition: Widget.h:194
int getSocket() const
Definition: Widget.h:154
uint64_t m_Handle
Definition: Widget.h:191