2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
23
#ifndef WINDOWTHREAD_H
24
#define WINDOWTHREAD_H
26
#include "TimerProc.h"
36
class WindowCompositor;
41
struct ClientAreaDraw;
43
#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))
44
gboolean nux_event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data);
45
gboolean nux_timeout_dispatch (gpointer user_data);
48
class WindowThread: public AbstractThread
50
NUX_DECLARE_OBJECT_TYPE (WindowThread, AbstractThread);
52
WindowThread (const TCHAR *WindowTitle, unsigned int width, unsigned int height, AbstractThread *Parent, bool Modal);
55
//! Set the main layout for this window user interface.
57
@param layout The layout of the user interface.
59
void SetLayout (Layout *layout);
61
//! Compute the layout of this window.
63
Reconfigure the layout of this window. Start by setting the size of the layout to the size of this window.
65
void ReconfigureLayout();
67
void TerminateThread();
69
//! Start running the user interface
70
void RunUserInterface();
73
virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo);
74
void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw);
75
void SetWindowTitle (const TCHAR *WindowTitle)
77
m_WindowTitle = WindowTitle;
80
GLWindowImpl &GetWindow() const
84
GraphicsEngine &GetGraphicsEngine() const
86
return *m_GLWindow->GetGraphicsEngine();
88
BasePainter &GetPainter() const
92
TimerHandler &GetTimerHandler() const
94
return *m_TimerHandler;
96
UXTheme &GetTheme() const
101
void SetWindowSize (int width, int height);
103
void SetWindowBackgroundPaintLayer (AbstractPaintLayer *bkg);
105
void RequestRedraw();
107
void ClearRedrawFlag()
109
m_RedrawRequested = false;
111
bool IsRedrawNeeded() const
113
return m_RedrawRequested;
117
Returns the main layout, a BaseWindow object or 0 as the parent of the area.
118
A BaseWindow has no parent so 0 is returned. Also for objects that have not been
119
added to the rendering tree, 0 is returned.
121
Area* GetTopRenderingParent(Area* area);
123
void AddToDrawList (View *view);
125
void ClearDrawList ();
127
std::vector<Geometry> GetDrawList ();
131
//! This list contains the layout that need to be recomputed following the resizing of one of the sub element.
133
This list contains the layout that need to be recomputed following the resizing of one of the sub element.
135
void AddObjectToRefreshList (Area *bo);
136
void RemoveObjectFromRefreshList (Area *bo);
138
//! Empty the list that contains the layout that need to be recomputed following the resizing of one of the sub element.
140
Empty the list that contains the layout that need to be recomputed following the resizing of one of the sub element.
142
void EmptyLayoutRefreshList();
144
void RefreshLayout();
146
//! Return true if we are computing any layout that is part of this window.
148
Return true if we are computing any layout that is part of this window.
150
bool IsComputingLayout() const
152
return m_IsComputingMainLayout;
154
void SetComputingLayout (bool b)
156
m_IsComputingMainLayout = b;
159
bool IsMainLayoutDrawDirty() const;
161
//! Compute the layout of a specific element
162
void ComputeElementLayout(Area* bo, bool RecurseToTopLevelLayout = false);
164
bool IsWaitingforModalWindow()
166
return m_bWaitForModalWindow;
171
return m_bWaitForModalWindow;
174
void SetWindowStyle(WindowStyle wstyle)
176
m_WindowStyle = wstyle;
179
WindowStyle GetWindowStyle() const
181
return m_WindowStyle;
184
virtual ThreadState Start( void* arg = NULL );
186
WindowCompositor& GetWindowCompositor()
188
return *m_window_compositor;
192
float GetFrameRate() const;
193
t_u32 GetFrameCounter() const;
194
t_u32 GetFramePeriodeCounter() const;
196
bool IsEmbeddedWindow();
198
#if defined(NUX_OS_WINDOWS)
199
bool ProcessForeignEvent (HWND hWnd, MSG msg, WPARAM wParam, LPARAM lParam, void *data);
200
#elif defined(NUX_OS_LINUX)
201
bool ProcessForeignEvent (XEvent *event, void *data);
204
void RenderInterfaceFromForeignCmd();
207
virtual unsigned int Run (void *);
210
Constructor-like function for the thread.
211
Will be called by EntryPoint before executing the thread body.
212
For the main window, ThreadCtor is called in nux::CreateMainWindow.
213
ThreadCtor creates and initialize the following elements:
219
After ThreadCtor is called, m_ThreadCtorCalled is set to true;
221
virtual bool ThreadCtor();
223
#if defined(NUX_OS_WINDOWS)
225
Constructor-like function for the thread.
226
Will be called by EntryPoint before executing the thread body.
227
For the main window, ThreadCtor is called in nux::CreateMainWindow.
228
ThreadCtor creates and initialize the following elements:
229
- Graphics Window (from the externally created window)
234
After ThreadCtor is called, m_ThreadCtorCalled is set to true;
238
virtual bool ThreadCtor (HWND WindowHandle, HDC WindowDCHandle, HGLRC OpenGLRenderingContext);
239
#elif defined(NUX_OS_LINUX)
241
Constructor-like function for the thread.
242
Will be called by EntryPoint before executing the thread body.
243
For the main window, ThreadCtor is called in nux::CreateMainWindow.
244
ThreadCtor creates and initialize the following elements:
245
- Graphics Window (from the externally created window)
250
After ThreadCtor is called, m_ThreadCtorCalled is set to true;
254
virtual bool ThreadCtor (Display *X11Display, Window X11Window, GLXContext OpenGLContext);
258
Destructor-like function for the thread.
259
Will be called by EntryPoint after executing the thread body.
260
After ThreadDtor is called, m_ThreadDtorCalled is set to true.
261
ThreadDtor is also called in the destructor of the WindowThread but is protected by m_ThreadDtorCalled so it is not called twice.
262
In the case of the main window, ThreadDtor is called in the destructor of WindowThread.
264
virtual bool ThreadDtor();
266
//! Get the main layout of this thread.
268
@return The main layout of this thread.
270
Layout* GetMainLayout();
273
This pointer maybe set by the user in ThreadInitFunc and reused in ThreadExitFunc
278
sigc::signal<void> RedrawRequested;
280
bool _inside_main_loop;
281
bool _inside_timer_loop;
282
bool _pending_wake_up_timer;
284
TimerFunctor *_async_wake_up_functor;
285
TimerHandle _async_wake_up_timer;
289
void AsyncWakeUpCallback (void*);
290
//void SetModalWindow(bool b) {m_bIsModal = b;}
293
Suspend Win32 Mouse and Keyboard inputs for this window thread and its child thread that are also window (not SystemThread).
295
void EnableMouseKeyboardInput();
298
Enable Win32 Mouse and Keyboard inputs for this window thread and its child thread that are also window (not SystemThread).
300
void DisableMouseKeyboardInput();
302
#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))
303
t_u32 ExecutionLoop (t_u32 timer_id);
305
t_u32 ExecutionLoop();
308
virtual ThreadState StartChildThread (NThread *thread, bool Modal);
309
virtual void AddChildThread (NThread *);
310
virtual void RemoveChildThread (NThread *);
311
virtual void ChildHasFinished (NThread *app);
312
virtual void TerminateAllChildThread();
313
virtual ThreadState SuspendChildGraphics (WindowThread *app);
315
bool m_bWaitForModalWindow;
316
WindowThread *m_ModalWindowThread;
318
//typedef Loki::Functor< void, LOKI_TYPELIST_1(void*) > ChildThreadExitCallback;
323
std::list< sigc::signal<void, void *> > ChildThreadExitCallback;
326
//std::list<NThread*> m_ChildThread;
327
std::list< ThreadInfo * > m_ChildThreadInfo;
331
WindowThread (const WindowThread &);
332
// Does not make sense for a singleton. This is a self assignment.
333
WindowThread &operator= (const WindowThread &);
334
// Declare operator address-of as private
335
WindowThread *operator &();
338
//! This list contains the layout that need to be recomputed following the resizing of one of the sub element.
340
This list contains the layout that need to be recomputed following the resizing of one of the sub element.
342
std::list<Area *> m_LayoutRefreshList;
343
std::vector<Geometry> m_dirty_areas;
345
//! This variable is true while we are computing the layout the starting from the outmost layout (the Main Layout);
346
bool m_IsComputingMainLayout;
350
t_u32 m_FrameCounter;
351
t_u32 m_FramePeriodeCounter;
354
bool m_bFirstDrawPass;
355
unsigned int m_StartupWidth;
356
unsigned int m_StartupHeight;
357
NString m_WindowTitle;
359
bool m_RedrawRequested;
363
BasePainter *m_Painter;
364
TimerHandler *m_TimerHandler;
366
GLWindowImpl *m_GLWindow;
367
GraphicsEngine *m_GraphicsContext;
368
WindowCompositor *m_window_compositor;
369
std::list<NThread *> m_ThreadList;
370
bool m_WidgetInitialized;
371
WindowStyle m_WindowStyle;
374
bool m_ThreadCtorCalled; //!< True is the thread constructor has been called.
376
bool m_ThreadDtorCalled; //!< True is the thread destructor has been called.
378
bool m_embedded_window; //!< Flag to run the interface in embedded mode.
381
Record if there was a configuration nux_event (NUX_SIZE_CONFIGURATION) that requires a full redraw.
382
Used in the case where event processing and rendering are decoupled (with foreign windows).
384
bool m_size_configuration_event;
388
friend class BasePainter;
389
friend class SystemThread;
391
#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))
392
GMainLoop *m_GLibLoop;
393
GMainContext *m_GLibContext;
394
friend gboolean nux_event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data);
395
friend gboolean nux_timeout_dispatch (gpointer user_data);
398
t_u32 AddGLibTimeout (t_u32 duration);
400
friend class TimerHandler;
402
friend WindowThread *CreateGUIThread (const TCHAR *WindowTitle,
405
WindowThread *Parent,
406
ThreadUserInitFunc UserInitFunc,
409
friend WindowThread *CreateWindowThread (WindowStyle WndStyle,
410
const TCHAR *WindowTitle,
413
WindowThread *Parent,
414
ThreadUserInitFunc UserInitFunc,
417
friend WindowThread *CreateModalWindowThread (WindowStyle WndStyle,
418
const TCHAR *WindowTitle,
421
WindowThread *Parent,
422
ThreadUserInitFunc UserInitFunc,
425
#if defined(NUX_OS_WINDOWS)
426
friend WindowThread *CreateFromForeignWindow (HWND WindowHandle, HDC WindowDCHandle, HGLRC OpenGLRenderingContext,
427
ThreadUserInitFunc UserInitFunc,
429
#elif defined(NUX_OS_LINUX)
430
friend WindowThread *CreateFromForeignWindow (Window X11Window, GLXContext OpenGLContext,
431
ThreadUserInitFunc UserInitFunc,
435
SystemThread *CreateSimpleThread (AbstractThread *Parent, ThreadUserInitFunc UserInitFunc, void *InitData);
441
#endif // WINDOWTHREAD_H