nux-1.16.0
nux::WindowThread Class Reference
Inheritance diagram for nux::WindowThread:
nux::AbstractThread nux::NThread

List of all members.

Classes

struct  _EventInspectorStorage
struct  ThreadInfo

Public Member Functions

 WindowThread (const TCHAR *WindowTitle, unsigned int width, unsigned int height, AbstractThread *Parent, bool Modal)
void SetLayout (Layout *layout)
 Set the layout for this window thread.
void TerminateThread ()
void RunUserInterface ()
 Start running the user interface.
virtual long ProcessEvent (IEvent &event, long TraverseInfo, long ProcessEventInfo)
void ProcessDraw (GraphicsEngine &GfxContext, bool force_draw)
void SetWindowTitle (const TCHAR *WindowTitle)
GraphicsDisplayGetWindow () const
GraphicsEngineGetGraphicsEngine () const
BasePainterGetPainter () const
TimerHandlerGetTimerHandler () const
UXThemeGetTheme () const
void SetWindowSize (int width, int height)
void SetWindowBackgroundPaintLayer (AbstractPaintLayer *bkg)
void RequestRedraw ()
void ClearRedrawFlag ()
bool IsRedrawNeeded () const
void AddToDrawList (View *view)
void ClearDrawList ()
std::vector< GeometryGetDrawList ()
void QueueMainLayout ()
 Causes the Main layout to be recomputed.
bool QueueObjectLayout (Area *area)
 Schedule a size computation cycle on an area before the rendering is performed.
void AddObjectToRefreshList (Area *area)
 Deprecated. Replace with QueueObjectLayout.
bool RemoveObjectFromLayoutQueue (Area *area)
 Remove an area from the list of object whose size was scheduled to be computed before the rendering cycle.
bool RemoveObjectFromRefreshList (Area *area)
 Deprecated. Use RemoveObjectFromLayoutQueue.
void RemoveQueuedLayout ()
 Empty the queue of objects set for layout computation.
void ComputeElementLayout (Area *bo, bool recurse_to_top_level_layout=false)
 Compute the layout of a specific element.
bool IsInsideLayoutCycle () const
 Return true if the process is inside a layout cycle.
bool IsComputingLayout () const
 Deprecated. Replace with IsInsideLayoutCycle.
bool IsWaitingforModalWindow ()
bool IsModalWindow ()
void SetWindowStyle (WindowStyle wstyle)
WindowStyle GetWindowStyle () const
virtual ThreadState Start (void *arg=NULL)
WindowCompositorGetWindowCompositor ()
float GetFrameRate () const
t_u32 GetFrameCounter () const
t_u32 GetFramePeriodeCounter () const
bool IsEmbeddedWindow ()
void RenderInterfaceFromForeignCmd (nux::Geometry *clip)
virtual unsigned int Run (void *)
virtual bool ThreadCtor ()
virtual bool ThreadDtor ()
LayoutGetMainLayout ()
 Get the main layout of this thread.
void AddTimeline (Timeline *timeline)
void RemoveTimeline (Timeline *timeline)
bool ProcessTimelines (GTimeVal *frame_time)
void StartMasterClock ()
void StopMasterClock ()
void NuxMainLoopQuit ()
void SetFakeEventMode (bool enable)
bool InFakeEventMode () const
void ReadyFakeEventProcessing (void *)
bool ReadyForNextFakeEvent () const
int InstallEventInspector (EventInspector function, void *data)
 Set an event inspector function.
bool RemoveEventInspector (int event_inspector_id)
 Remove an event inspector.
bool RemoveEventInspector (EventInspector function)
 Remove an event inspector.
bool CallEventInspectors (Event *event)
 Call event inspectors.
void SetFocusedArea (Area *focused_area)

Public Attributes

long _last_timeline_frame_time_sec
long _last_timeline_frame_time_usec
void * m_InitData
void * m_ExitData
sigc::signal< void > RedrawRequested
bool _inside_main_loop
bool _inside_timer_loop
bool _pending_wake_up_timer
TimerFunctor_async_wake_up_functor
TimerHandle _async_wake_up_timer
bool _ready_for_next_fake_event
bool _processing_fake_event
bool _fake_event_mode
TimerFunctor_fake_event_call_back
TimerHandle _fake_event_timer

Protected Member Functions

void ReconfigureLayout ()
 Compute the layout of this window thread.
void AsyncWakeUpCallback (void *)
void EnableMouseKeyboardInput ()
void DisableMouseKeyboardInput ()
t_u32 ExecutionLoop ()
virtual ThreadState StartChildThread (NThread *thread, bool Modal)
virtual void AddChildThread (NThread *)
virtual void RemoveChildThread (NThread *)
virtual void ChildHasFinished (NThread *app)
virtual void TerminateAllChildThread ()
virtual ThreadState SuspendChildGraphics (WindowThread *app)

Protected Attributes

bool m_bWaitForModalWindow
WindowThreadm_ModalWindowThread
std::list< ThreadInfo * > m_ChildThreadInfo

Friends

class BasePainter
class SystemThread
class TimerHandler
WindowThreadCreateGUIThread (const TCHAR *WindowTitle, t_u32 width, t_u32 height, WindowThread *Parent, ThreadUserInitFunc UserInitFunc, void *InitData)
 Create a main graphics thread. This thread has a window and no parent window (The Parent parameter should always be null).
WindowThreadCreateWindowThread (WindowStyle WndStyle, const TCHAR *WindowTitle, t_u32 width, t_u32 height, WindowThread *Parent, ThreadUserInitFunc UserInitFunc, void *InitData)
WindowThreadCreateModalWindowThread (WindowStyle WndStyle, const TCHAR *WindowTitle, t_u32 width, t_u32 height, WindowThread *Parent, ThreadUserInitFunc UserInitFunc, void *InitData)
SystemThreadCreateSystemThread (AbstractThread *Parent, ThreadUserInitFunc UserInitFunc, void *InitData)

Detailed Description

Definition at line 57 of file WindowThread.h.


Member Function Documentation

void nux::WindowThread::AddTimeline ( Timeline timeline)

Add a timeline to our window

Definition at line 820 of file WindowThread.cpp.

  {
    _Timelines->push_back (timeline);
    _Timelines->unique ();
    StartMasterClock ();
  }
bool nux::WindowThread::CallEventInspectors ( Event event)

Call event inspectors.

Call event inspectors to have a look at the event.

Returns:
True if the event should be discarded.
void nux::WindowThread::ComputeElementLayout ( Area bo,
bool  recurse_to_top_level_layout = false 
)

Compute the layout of a specific element.

Immediate size negotiation for a View or a layout.

Definition at line 788 of file WindowThread.cpp.

References IsInsideLayoutCycle(), nux::Layout::QueueDraw(), and nux::View::QueueDraw().

Referenced by nux::FloatingWindow::LayoutWindowElements().

  {
    NUX_RETURN_IF_NULL (area);

    bool alreadyComputingLayout = IsInsideLayoutCycle();

    if ((!alreadyComputingLayout) && (!recurse_to_top_level_layout))
    {
      // When computing the layout, setting the size of widgets may cause the system to recurse 
      // upward an look for the up most container which size is affected by its this area.
      // This happens in Area::InitiateResizeLayout ();
      // The search upward is not done if we are already in a layout cycle.
      StartLayoutCycle ();
    }

    if (area->Type().IsDerivedFromType (View::StaticObjectType))
    {
      View *ic = NUX_STATIC_CAST (View *, area);
      ic->QueueDraw ();
    }
    else if (area->Type().IsDerivedFromType (Layout::StaticObjectType))
    {
      Layout *layout = NUX_STATIC_CAST (Layout *, area);
      layout->QueueDraw ();
    }

    area->ComputeLayout2();

    if (!alreadyComputingLayout)
      StopLayoutCycle ();
  }
void nux::WindowThread::DisableMouseKeyboardInput ( ) [protected]

Enable Win32 Mouse and Keyboard inputs for this window thread and its child thread that are also window (not SystemThread).

Definition at line 1390 of file WindowThread.cpp.

  {
    std::list<NThread *>::iterator it;

    for (it = m_ChildThread.begin(); it != m_ChildThread.end(); it++)
    {
      if (NUX_STATIC_CAST (WindowThread *, *it)->Type().IsObjectType (WindowThread::StaticObjectType) )
      {
        NUX_STATIC_CAST (WindowThread *, *it)->DisableMouseKeyboardInput();
      }
    }

    // WIN32: Disable Mouse and Keyboard inputs for all windows child of this window
#if defined(NUX_OS_WINDOWS)
    ::EnableWindow (_graphics_display->GetWindowHandle(), FALSE);
#elif defined(NUX_OS_LINUX)

#endif
    m_bWaitForModalWindow = true;
  }
void nux::WindowThread::EnableMouseKeyboardInput ( ) [protected]

Suspend Win32 Mouse and Keyboard inputs for this window thread and its child thread that are also window (not SystemThread).

Definition at line 1369 of file WindowThread.cpp.

  {
    std::list<NThread *>::iterator it;

    for (it = m_ChildThread.begin(); it != m_ChildThread.end(); it++)
    {
      if (NUX_STATIC_CAST (WindowThread *, *it)->Type().IsObjectType (WindowThread::StaticObjectType) )
      {
        NUX_STATIC_CAST (WindowThread *, *it)->EnableMouseKeyboardInput();
      }
    }

    // WIN32: Enable Mouse and Keyboard inputs for all windows child of this window
#if defined(NUX_OS_WINDOWS)
    ::EnableWindow (_graphics_display->GetWindowHandle(), TRUE);
#elif defined(NUX_OS_LINUX)

#endif
    m_bWaitForModalWindow = false;
  }
Layout * nux::WindowThread::GetMainLayout ( )

Get the main layout of this thread.

Returns:
The main layout of this thread.

Definition at line 638 of file WindowThread.cpp.

  {
    return _main_layout;
  }
bool nux::WindowThread::InFakeEventMode ( ) const

Return True if the system is in accepting fake events.

Returns:
True if the fake event mode is active.

Definition at line 517 of file WindowThread.cpp.

  {
    return _fake_event_mode;
  }
int nux::WindowThread::InstallEventInspector ( EventInspector  function,
void *  data 
)

Set an event inspector function.

Inspect all events and returns the action to be taken for the event (process or discard).

If function as already been added, return its unique id.
If function is null, return 0.

Parameters:
functionEvent inspector function callback.
dataUser defined data.
Returns:
Unique id for the event inspector callback.
bool nux::WindowThread::IsInsideLayoutCycle ( ) const

Return true if the process is inside a layout cycle.

Returns:
True if the process is inside a layout cycle.

Definition at line 783 of file WindowThread.cpp.

Referenced by ComputeElementLayout(), and IsComputingLayout().

  {
    return _inside_layout_cycle;
  }
void nux::WindowThread::QueueMainLayout ( )

Causes the Main layout to be recomputed.

Causes the main layout to be recomputed. This will happen just before the next draw cycle.

Definition at line 665 of file WindowThread.cpp.

  {
    _queue_main_layout = true;
    RequestRedraw ();
  }
bool nux::WindowThread::QueueObjectLayout ( Area area)

Schedule a size computation cycle on an area before the rendering is performed.

This list contains the area whose size need to be computed.

Parameters:
areaThe object that will perform a size computation cycle.
See also:
RefreshLayout.

Definition at line 689 of file WindowThread.cpp.

Referenced by AddObjectToRefreshList(), nux::Area::QueueRelayout(), and nux::View::SetLayout().

  {
    NUX_RETURN_VALUE_IF_NULL (area, false);

    std::list<Area *>::iterator it;
    it = find (_queued_layout_list.begin(), _queued_layout_list.end(), area);
    if (it == _queued_layout_list.end() )
    {
      _queued_layout_list.push_back (area);
    }

    return true;
  }
void nux::WindowThread::ReadyFakeEventProcessing ( void *  data)

Called when the timer set in PumpFakeEventIntoPipe expires.This is the signal that the main thread is ready to process the fake event.

Definition at line 571 of file WindowThread.cpp.

  {
    nuxDebugMsg (TEXT("[WindowThread::ReadyFakeEventProcessing] Ready to process fake event."));
    _processing_fake_event = true;
  }
bool nux::WindowThread::ReadyForNextFakeEvent ( ) const

Fake events are processed one after the other. While this function return false, PumpFakeEventIntoPipe should not be called.

Definition at line 522 of file WindowThread.cpp.

  {
    return _ready_for_next_fake_event;
  }
void nux::WindowThread::ReconfigureLayout ( ) [protected]

Compute the layout of this window thread.

Reconfigure the layout of this window. Start by setting the size of the layout to the size of this window. ReconfigureLayout is executed following an event of type NUX_SIZE_CONFIGURATION or a call to QueueMainLayout.

See also:
QueueMainLayout.

Definition at line 671 of file WindowThread.cpp.

References RemoveQueuedLayout(), and nux::Area::SetGeometry().

  {
    int w = _graphics_display->GetGraphicsEngine()->GetWindowWidth();
    int h = _graphics_display->GetGraphicsEngine()->GetWindowHeight();

    if (_main_layout)
    {
      StartLayoutCycle ();
      _main_layout->SetGeometry (0, 0, w, h);
      _main_layout->ComputeLayout2();
      _main_layout->ComputePosition2 (0, 0);
      StopLayoutCycle ();
    }

    RemoveQueuedLayout ();
    _queue_main_layout = false;
  }
bool nux::WindowThread::RemoveEventInspector ( int  event_inspector_id)

Remove an event inspector.

Remove the event inspector identified by the provided unique id.

Parameters:
event_inspector_idUnique id for the event inspector.
Returns:
True If the event inspector exists and has been removed.
bool nux::WindowThread::RemoveEventInspector ( EventInspector  function)

Remove an event inspector.

Remove the event inspector identified by the provided function.

Parameters:
functionEvent inspector function callback.
Returns:
True If the event inspector exists and has been removed.
bool nux::WindowThread::RemoveObjectFromLayoutQueue ( Area area)

Remove an area from the list of object whose size was scheduled to be computed before the rendering cycle.

Parameters:
areaThe object to remove form the list.
Returns:
True if the object was in the _queued_layout_list and has been removed.
See also:
RefreshLayout, QueueObjectLayout.

Definition at line 708 of file WindowThread.cpp.

Referenced by RemoveObjectFromRefreshList().

  {
    NUX_RETURN_VALUE_IF_NULL (area, false);

    std::list<Area *>::iterator it;
    it = find (_queued_layout_list.begin(), _queued_layout_list.end(), area);

    if (it != _queued_layout_list.end() )
    {
      _queued_layout_list.erase (it);
      return true;
    }
    return false;
  }
void nux::WindowThread::RemoveQueuedLayout ( )

Empty the queue of objects set for layout computation.

The queue was filled with calls to QueueObjectLayout.

Definition at line 728 of file WindowThread.cpp.

Referenced by ReconfigureLayout(), SetLayout(), and ThreadDtor().

  {
    _queued_layout_list.clear();
  }
unsigned int nux::WindowThread::Run ( void *  ) [virtual]

Info: Override this method.

This function should contain the body/code of your thread. Notice the signature is similar to that of any worker thread function except for the calling convention.

Implements nux::AbstractThread.

Definition at line 836 of file WindowThread.cpp.

References m_InitData, and RunUserInterface().

  {
    if (m_UserInitFunc && (m_WidgetInitialized == false) )
    {
      (*m_UserInitFunc) (this, m_InitData);
      m_WidgetInitialized = true;
    }

    RunUserInterface();

    return 0;
  }
void nux::WindowThread::SetFakeEventMode ( bool  enable)

Enable the processing of fake events set through PumpFakeEventIntoPipe. Disable the processing of mouse up/down events coming from the display server. Process other mouse events normaly.

Parameters:
enableTrue to enable fake events.
See also:
InFakeEventMode

Definition at line 512 of file WindowThread.cpp.

  {
    _fake_event_mode = enable;
  }
void nux::WindowThread::SetFocusedArea ( Area focused_area)

Sets the focused item on the screen

Definition at line 477 of file WindowThread.cpp.

References nux::Object::object_destroyed.

  {
    if (focused_area == _focused_area)
      return; 
    
    if (_focused_area != NULL)
    {
      _focused_area->SetFocused (false);

      if (_focused_area_destroyed_con.empty () == false)
      {
        _focused_area_destroyed_con.disconnect ();
      }

    }
    
    _focused_area = focused_area;
    _focused_area_destroyed_con = focused_area->object_destroyed.connect (sigc::mem_fun (this, &WindowThread::OnFocusedAreaDestroyed));
    
  }
void nux::WindowThread::SetLayout ( Layout layout)

Set the layout for this window thread.

Parameters:
layoutThe layout of the user interface.

Definition at line 643 of file WindowThread.cpp.

References nux::Object::Reference(), RemoveQueuedLayout(), and nux::Area::SetGeometry().

  {
    _main_layout = layout;

    if (_main_layout)
    {
      int w = _graphics_display->GetGraphicsEngine()->GetContextWidth();
      int h = _graphics_display->GetGraphicsEngine()->GetContextHeight();

      _main_layout->Reference();
      _main_layout->SetStretchFactor (1);

      StartLayoutCycle ();
      _main_layout->SetGeometry (0, 0, w, h);
      _main_layout->ComputeLayout2();
      _main_layout->ComputePosition2 (0, 0);
      StopLayoutCycle ();

      RemoveQueuedLayout ();
    }
  }
ThreadState nux::WindowThread::Start ( void *  arg = NULL) [virtual]

Info: Starts the thread.

This function starts the thread pointed by m_pThreadFunc with default attributes

Reimplemented from nux::NThread.

Definition at line 1228 of file WindowThread.cpp.

  {
    if (!m_Parent)
    {
      return NThread::Start();
    }
    else
    {
      if (m_Parent->Type().IsObjectType (SystemThread::StaticObjectType) )
        return static_cast<SystemThread *> (m_Parent)->StartChildThread (this, true);
      else if (m_Parent->Type().IsObjectType (WindowThread::StaticObjectType) )
        return static_cast<WindowThread *> (m_Parent)->StartChildThread (this, true);

      nuxAssertMsg (0, TEXT ("[WindowThread::Start] This should not happen.") );
      return THREAD_START_ERROR;
    }
  }
bool nux::WindowThread::ThreadCtor ( ) [virtual]

Constructor-like function for the thread. Will be called by EntryPoint before executing the thread body. For the main window, ThreadCtor is called in nux::CreateMainWindow. ThreadCtor creates and initialize the following elements:

  • Graphics Window
  • Timer
  • Painter
  • Compositor
  • Theme engine After ThreadCtor is called, m_ThreadCtorCalled is set to true;

Reimplemented from nux::NThread.

Definition at line 1416 of file WindowThread.cpp.

Referenced by nux::CreateGUIThread().

  {
    nuxAssertMsg (m_ThreadCtorCalled == false, TEXT ("[WindowThread::ThreadCtor] ThreadCtor should not be called more than once.") );
    NUX_RETURN_VALUE_IF_TRUE (m_ThreadCtorCalled, true);

#if defined(NUX_OS_WINDOWS)
    SetWin32ThreadName (GetThreadId(), m_WindowTitle.GetTCharPtr() );
#endif

    if (RegisterNuxThread (this) == FALSE)
    {
      nuxDebugMsg (TEXT ("[WindowThread::ThreadCtor] Failed to register the WindowThread.") );
      return false;
    }

    inlSetThreadLocalStorage (ThreadLocal_InalogicAppImpl, this);
    GraphicsDisplay *ParentWindow = 0;

    if (m_Parent && static_cast<WindowThread *> (m_Parent)->Type().IsObjectType (WindowThread::StaticObjectType) )
    {
      ParentWindow = &static_cast<WindowThread *> (m_Parent)->GetWindow();
    }
    else
    {
      ParentWindow = 0;
    }

    _graphics_display = gGLWindowManager.CreateGLWindow (m_WindowTitle.GetTCharPtr(), m_StartupWidth, m_StartupHeight, m_WindowStyle, ParentWindow, false);

    if (_graphics_display == 0)
    {
      nuxDebugMsg (TEXT ("[WindowThread::ThreadCtor] Failed to create the window.") );
      return false;
    }

    if (m_Parent && m_Parent->Type().IsObjectType (WindowThread::StaticObjectType) )
    {
      // Cancel the effect of PauseThreadGraphicsRendering on the parent window.
      //PostThreadMessage(m_Parent->GetThreadId(), NUX_THREADMSG_START_RENDERING, (UINT_PTR)((void*)this), 0);
    }

    m_Painter = new BasePainter();
    m_TimerHandler = new TimerHandler();
    m_window_compositor = new WindowCompositor;

    SetThreadState (THREADRUNNING);
    m_ThreadCtorCalled = true;

    return true;
  }
bool nux::WindowThread::ThreadDtor ( ) [virtual]

Destructor-like function for the thread. Will be called by EntryPoint after executing the thread body. After ThreadDtor is called, m_ThreadDtorCalled is set to true. ThreadDtor is also called in the destructor of the WindowThread but is protected by m_ThreadDtorCalled so it is not called twice. In the case of the main window, ThreadDtor is called in the destructor of WindowThread.

Reimplemented from nux::NThread.

Definition at line 1584 of file WindowThread.cpp.

References RemoveQueuedLayout(), and nux::Object::UnReference().

  {
    NUX_RETURN_VALUE_IF_TRUE (m_ThreadDtorCalled, true);

    // Cleanup
    RemoveQueuedLayout ();

    if (_main_layout)
    {
      _main_layout->UnReference();
    }

    NUX_SAFE_DELETE (m_window_compositor);
    NUX_SAFE_DELETE (m_TimerHandler);
    NUX_SAFE_DELETE (m_Painter);
    NUX_SAFE_DELETE (m_Theme);
    NUX_SAFE_DELETE (_graphics_display);

#if defined(NUX_OS_WINDOWS)
    PostThreadMessage (NUX_GLOBAL_OBJECT_INSTANCE (NProcess).GetMainThreadID(),
                       NUX_THREADMSG_THREAD_TERMINATED,
                       NUX_GLOBAL_OBJECT_INSTANCE (NProcess).GetCurrentThreadID(),
                       0);
#elif defined(NUX_OS_LINUX)

#else
#error PostThreadMessage not implemented for this platform.
#endif

    inlSetThreadLocalStorage (ThreadLocal_InalogicAppImpl, 0);
    UnregisterNuxThread (this);
    m_ThreadDtorCalled = true;
    return true;
  }

Member Data Documentation

This pointer maybe set by the user in ThreadInitFunc and reused in ThreadExitFunc

Reimplemented from nux::AbstractThread.

Definition at line 298 of file WindowThread.h.

Referenced by nux::CreateGUIThread(), and Run().


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends