The Pedigree Project  0.1
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Widget Class Referenceabstract

#include <Widget.h>

+ Inheritance diagram for Widget:
+ Collaboration diagram for Widget:

Public Member Functions

uint64_t getHandle () const
 
bool construct (const char *endpoint, const char *title, widgetCallback_t cb, PedigreeGraphics::Rect &dimensions)
 
bool setTitle (const std::string &newTitle)
 
virtual bool render (PedigreeGraphics::Rect &rt, PedigreeGraphics::Rect &dirty)=0
 
bool redraw (PedigreeGraphics::Rect &rt)
 
bool visibility (bool vis)
 
void destroy ()
 
void * getRawFramebuffer ()
 
int getSocket () const
 

Static Public Member Functions

static void checkForEvents (bool bAsync=false)
 

Private Member Functions

widgetCallback_t getCallback () const
 

Static Private Member Functions

static void checkForMessage (size_t which, bool bResponse=false)
 
static void handleMessage (const char *pMessageBuffer)
 
static bool handlePendingMessages ()
 

Private Attributes

bool m_bConstructed
 
PedigreeGraphics::Framebufferm_pFramebuffer
 
uint64_t m_Handle
 
widgetCallback_t m_EventCallback
 
int m_Socket
 
PedigreeIpc::SharedIpcMessagem_SharedFramebuffer
 

Static Private Attributes

static std::map< uint64_t, Widget * > s_KnownWidgets
 
static std::queue< char * > s_PendingMessages
 
static size_t s_NumWidgets
 

Detailed Description

Base class for all GUI widgets in the system. Defines the interface for all widgets to use.

Definition at line 63 of file Widget.h.

Member Function Documentation

void Widget::checkForEvents ( bool  bAsync = false)
static

Handles emptying the pending event queue and dispatch to callbacks for an application automatically.

Definition at line 339 of file Widget.cc.

References getSocket(), handleMessage(), and handlePendingMessages().

Referenced by construct(), getSocket(), Tui::initialise(), TestWidget::render(), PedigreeTerminalEmulator::render(), Gears::render(), and Tui::run().

+ Here is the caller graph for this function:

void Widget::checkForMessage ( size_t  which,
bool  bResponse = false 
)
staticprivate

Waits for a message of the given type, queuing other messages along the way.

Definition at line 391 of file Widget.cc.

References getSocket(), LibUiProtocol::WindowManagerMessage::isResponse, and LibUiProtocol::WindowManagerMessage::messageCode.

Referenced by construct(), destroy(), getSocket(), and redraw().

+ Here is the caller graph for this function:

bool Widget::construct ( const char *  endpoint,
const char *  title,
widgetCallback_t  cb,
PedigreeGraphics::Rect dimensions 
)

Constructs the internal state of the widget. This involves talking to the window manager via IPC to obtain a framebuffer for rendering, as well as notifying the window manager that this widget now exists. No other calls are valid until this call has returned successfully.

Parameters
endpointUnique IPC endpoint name to listen on for this widget
cbEvent handler callback.
dimensionsDimensions of the widget to be created.
Note
The window manager may elect to override the requested dimensions for the purpose of rendering. Handling a Reposition event in the event handler callback will reveal the assigned dimensions.
Returns
True if the widget was successfully constructed, False otherwise.
Todo:
Maybe we can get a decent way of having a default handler?

Definition at line 90 of file Widget.cc.

References checkForEvents(), checkForMessage(), LibUiProtocol::CreateMessage::endpoint, LibUiProtocol::WindowManagerMessage::isResponse, LibUiProtocol::WindowManagerMessage::messageCode, LibUiProtocol::WindowManagerMessage::messageSize, LibUiProtocol::CreateMessage::minWidth, LibUiProtocol::CreateMessage::rigid, LibUiProtocol::CreateMessage::title, and LibUiProtocol::WindowManagerMessage::widgetHandle.

Referenced by getHandle(), TestWidget::render(), PedigreeTerminalEmulator::render(), and Gears::render().

+ Here is the caller graph for this function:

void Widget::destroy ( )

Destroys the widget and all internal state.

Todo:
do we care if the send fails? We probably do??

Definition at line 301 of file Widget.cc.

References checkForMessage(), LibUiProtocol::WindowManagerMessage::isResponse, LibUiProtocol::WindowManagerMessage::messageCode, LibUiProtocol::WindowManagerMessage::messageSize, and LibUiProtocol::WindowManagerMessage::widgetHandle.

Referenced by getHandle(), and Gears::render().

+ Here is the caller graph for this function:

widgetCallback_t Widget::getCallback ( ) const
inlineprivate

Get the Widget's callback.

Definition at line 179 of file Widget.h.

References m_EventCallback.

Referenced by handleMessage().

+ Here is the caller graph for this function:

uint64_t Widget::getHandle ( ) const
inline

Obtains a handle for this widget. The handle is only usable by the window manager, and is determined by the following formula during widget construction in construct():

Note
(PID << 32) | ((WidgetPointer >> 32) | (WidgetPointer & 0xFFFFFFFF)) If the system is not capable of 64-bit addressing, the 32-bit right shift is not necessary. The PID is assumed to never exceed the limits of a 32-bit unsigned integer. Should this happen, the PID should be folded in the same way as the widget pointer.

Definition at line 79 of file Widget.h.

References construct(), destroy(), m_Handle, redraw(), render(), setTitle(), and visibility().

Referenced by TestWidget::render().

+ Here is the caller graph for this function:

void* Widget::getRawFramebuffer ( )
inline

Gets the raw framebuffer for the window. This will be in ARGB32 format.

Definition at line 142 of file Widget.h.

References m_SharedFramebuffer.

Referenced by PedigreeTerminalEmulator::render(), and Gears::render().

+ Here is the caller graph for this function:

int Widget::getSocket ( ) const
inline

Gets a raw socket that can be used for select() or poll().

An application can take all widgets it is aware of and select() on them; when they are readable, a call to Widget::checkForEvents will clear the queued events that arrived.

Definition at line 154 of file Widget.h.

References checkForEvents(), checkForMessage(), handleMessage(), handlePendingMessages(), and m_Socket.

Referenced by checkForEvents(), checkForMessage(), and Tui::run().

+ Here is the caller graph for this function:

void Widget::handleMessage ( const char *  pMessageBuffer)
staticprivate
bool Widget::handlePendingMessages ( )
staticprivate

Clear out pending messages.

Definition at line 562 of file Widget.cc.

References handleMessage().

Referenced by checkForEvents(), and getSocket().

+ Here is the caller graph for this function:

bool Widget::redraw ( PedigreeGraphics::Rect rt)

Called to begin a redraw of the widget by the window manager.

Parameters
rtRect defining the redraw area.
Returns
True if the redraw was successful, False otherwise.

Definition at line 225 of file Widget.cc.

References checkForMessage(), LibUiProtocol::WindowManagerMessage::isResponse, LibUiProtocol::WindowManagerMessage::messageCode, LibUiProtocol::WindowManagerMessage::messageSize, and LibUiProtocol::WindowManagerMessage::widgetHandle.

Referenced by getHandle(), Tui::redraw(), TestWidget::render(), and Gears::render().

+ Here is the caller graph for this function:

virtual bool Widget::render ( PedigreeGraphics::Rect rt,
PedigreeGraphics::Rect dirty 
)
pure virtual

Called to actually render the widget. Would normally be called by the RepaintNeeded handler by application code.

Parameters
rtArea that needs to be rendered.
dirtyObject containing a dirty rectangle for redrawing.
Returns
True if the render succeeded, False otherwise.

Implemented in Gears, PedigreeTerminalEmulator, and TestWidget.

Referenced by getHandle(), and TestWidget::render().

+ Here is the caller graph for this function:

bool Widget::setTitle ( const std::string &  newTitle)

Sets the title of the widget.

Parameters
titleNew title for the widget.
Returns
True is the new title was set, False otherwise.

Definition at line 189 of file Widget.cc.

References LibUiProtocol::WindowManagerMessage::isResponse, LibUiProtocol::WindowManagerMessage::messageCode, LibUiProtocol::WindowManagerMessage::messageSize, and LibUiProtocol::WindowManagerMessage::widgetHandle.

Referenced by getHandle().

+ Here is the caller graph for this function:

bool Widget::visibility ( bool  vis)

Sets the visibility of the widget.

Note
Be sure to redraw the parent widget after hiding a widget.
Parameters
visTrue if the widget is to be made visible, False otherwise.
Returns
True if successful, False otherwise.

Definition at line 269 of file Widget.cc.

References LibUiProtocol::WindowManagerMessage::isResponse, LibUiProtocol::WindowManagerMessage::messageCode, LibUiProtocol::WindowManagerMessage::messageSize, and LibUiProtocol::WindowManagerMessage::widgetHandle.

Referenced by getHandle(), and TestWidget::render().

+ Here is the caller graph for this function:

Member Data Documentation

bool Widget::m_bConstructed
private

Has this widget been constructed yet?

Definition at line 185 of file Widget.h.

widgetCallback_t Widget::m_EventCallback
private

Widget event handler.

Definition at line 194 of file Widget.h.

Referenced by getCallback().

uint64_t Widget::m_Handle
private

Widget handle.

Definition at line 191 of file Widget.h.

Referenced by getHandle().

PedigreeGraphics::Framebuffer* Widget::m_pFramebuffer
private

Framebuffer for all rendering.

Definition at line 188 of file Widget.h.

PedigreeIpc::SharedIpcMessage* Widget::m_SharedFramebuffer
private

IPC shared message that handles our framebuffer.

Definition at line 205 of file Widget.h.

Referenced by getRawFramebuffer(), and handleMessage().

int Widget::m_Socket
private

IPC socket for window manager communication (supercedes IPC enpdoint).

Definition at line 198 of file Widget.h.

Referenced by getSocket().

std::map< uint64_t, Widget * > Widget::s_KnownWidgets
staticprivate

Handle -> Callback mapping. For event handler.

Definition at line 209 of file Widget.h.

size_t Widget::s_NumWidgets
staticprivate

of Widgets currently active.

Definition at line 215 of file Widget.h.

std::queue< char * > Widget::s_PendingMessages
staticprivate

Queue of messages that have not yet been delivered to a callback.

Definition at line 212 of file Widget.h.


The documentation for this class was generated from the following files: