(Up to LGI Documentation)

GView

The GView object forms the basis of all the windows in an LGI application. All the events, data access and member functions are defined as virtuals in this class. All the default behaviour is also defined here.

When creating new windows, they are almost always based in some way on GWindow.


The GView object is implemented as a HWND in Win32. Although you have the option of declaring GView derived objects as virtual and as such they don't have a HWND. If you do this then somewhere up the parent chain there has to be a real HWND GWindow derived class that handles the message processing for you.

Ok so to implement a GView derived object for Win32 you need to first declare and initialize the window's class. If you are deriving from GLayout this is taken care for you and you don't need to do this:

class GButton
{
	static GWin32Class WndClass;
public:
};
Then in your constructor you initialize the GWin32Class variable. You can either define a new win32 class or subclass an existing one. To define a new class:
WndClass = NewStr("MyNewClass");
WndClass.Create(Class());
If you want to implement custom message processing then implement the OnEvent function in your class like this:
int GButton::OnEvent(GMessage *Msg)
{
	switch (Message(Msg))
	{
		case WM_ACTIVATE:
			break;
	}

	return GWindow::OnEvent(Msg);
}

To subclass an existing class:

WndClass = NewStr("MyNewSubClass");
WndClass.SubClass(Class(), "CLASS");
Where "CLASS" is the class your subclassing.

When subclassing you need to implement the virtual int OnEvent(...) function and call the CallParent member function of the class, like this:

int GButton::OnEvent(GMessage *Msg)
{
	return WndClass.CallParent(Handle(), Msg->Msg, Msg->a, Msg->b);
}

The GView object is implemented as a BView object in BeOS.

To correctly implement a GView that inherits from a BView derived class you need to create a redirector class that pumps information from the BeAPI object into the handlers of the GView derived object. Now you can do this be multiple inheritance but it's better to produce different objects so that you don't have member function name conflicts (ie Invalidate).

To do this you can either use BViewRedir or roll your own subclass. The BViewRedir is a redirector for the BView class directly, it's useful for building a generic window from scratch. However if you want to subclass a existing BeOS control then you'll need to use a templated version of BViewRedir, which I will quote here:

template <class b>
class BRedir : public b
{
	GView *View;

public:
	BRedir(GView *v) : b(BRect(0, 0, 1, 1), "")
	{
		View = v;
	}

	void AttachedToWindow() { if (View) View->OnCreate(); }
	void DetachedFromWindow() { if (View) View->OnDestroy(); }
	void FrameMoved(BPoint Point) {	if (View) View->OnPosChange(Point); }
	void FrameResized(float width, float height) {	if (View) View->OnPosChange(Point); }
	void Pulse() { if (View) View->OnPulse(); }
	void MessageReceived(BMessage *message) { if (View) View->OnEvent(message); }
	void MakeFocus(bool f) { BView::MakeFocus(f); if (View) View->OnFocus(f); }
	void KeyDown(const char *bytes, int32 numBytes) { if (View) View->Sys_KeyDown(bytes, numBytes); }
	void KeyUp(const char *bytes, int32 numBytes) { if (View) View->Sys_KeyUp(bytes, numBytes); }
	void MouseDown(BPoint point) { if (View) View->Sys_MouseDown(point); }
	void MouseMoved(BPoint point, uint32 transit, const BMessage *message)
		{ if (View) View->Sys_MouseMoved(point, transit, message); }
	void Draw(BRect UpdateRect)
	{
		if (View)
		{
			GdcViewDC DC(this);
			View->_Paint(&DC);
			Window()->Sync();
		}
	}
	bool QuitRequested()
	{
		GWindow *App = dynamic_cast(View);
		if (App)
		{
			return App->QuitRequested();
		}
		return true;
	}
};

You can then instantiate a redirector subclass to pass into the GView constructor like this:

MyButton::MyButton(char *Text) :
	GView(new BRedir<BButton>(this))
{
	// ...
}

You may be able to use a generic redirector like the one above for the class you have in mind, as their constructors are usually pretty similar. But for more specific class constructors you should roll your own redirector from the code above.


GView based classes:
class GView
{
public:
    // _Constructor
    GWindow()
    virtual ~GWindow()

    // Attaching windows
    virtual bool Attach(GWindow *Parent)
    virtual bool AttachChildren()
    virtual bool Detach()

    // Events
    virtual bool OnRequestClose()
    virtual int OnCommand(int Cmd, int Event, GWndRef hWnd)
    virtual int OnEvent(GMessage *Msg)
    virtual int OnHitTest(int x, int y)
    virtual int OnNotify(GWindow *Ctrl, int Flags)
    virtual void OnChildrenChanged(GWindow *Wnd, bool Attaching)
    virtual void OnCreate()
    virtual void OnDestroy()
    virtual void OnFocus(bool f)
    virtual void OnKey(VKey &k)
    virtual void OnMouseClick(VMouse &m)
    virtual void OnMouseEnter(VMouse &m)
    virtual void OnMouseExit(VMouse &m)
    virtual void OnMouseMove(VMouse &m)
    virtual void OnPaint(GdcBasePrimitives *pDC)
    virtual void OnPosChange()
    virtual void OnPulse()

    // Flags
    virtual bool Enabled()
    virtual bool Flat()
    virtual bool Focus()
    virtual bool Raised()
    virtual bool Sunken()
    virtual bool Visible()
    virtual void Enabled(bool i)
    virtual void Flat(bool i)
    virtual void Focus(bool i)
    virtual void Raised(bool i)
    virtual void Sunken(bool i)
    virtual void Visible(bool i)

    // Other
    GdcRegion *FindLargest(GdcComplexRegion &r)
    GdcRegion *FindLargestEdge(GdcComplexRegion &r, int Edge)
    GdcRegion *FindSmallestFit(GdcComplexRegion &r, int Sx, int Sy)
    virtual bool Pour(GdcComplexRegion &r)
    // Win32 API
    operator GWndRef()
    virtual GWndRef Handle()
    // BeOS Api
    virtual BView *GetBView()
    virtual BWindow *GetBWindow()
  };

GView::GWindow

GWindow()

Initializes the object.


GView::~GWindow

virtual ~GWindow()

Inside the destructor the children are detached and deleted.


GView::Attach

virtual bool Attach(GWindow *Parent)

Argument Description
GWindow *Parent The parent window that your attaching

Attaches the window to a parent.

Under windows this can have 2 effects. Firstly if a window returns something from the virtual char *Class(); function then the Attach function will call CreateWindow to create a HWND for your instance. Otherwise the window is attached virtually, and has no handle. All mouse, key and paint events are handled by the parent window and passed down to the instance.

Under BeOS this function calles the AddChild function to insert the window in the heirarchy.


GView::AttachChildren

virtual bool AttachChildren()

This function attaches all the children currently in the member variable:

List<GWindow> Children;

If they are not already attached.


GView::Detach

virtual bool Detach()

Breaks the connection between the parent and the child.


GView::OnRequestClose

virtual bool OnRequestClose()

Return true if you want to close, or false if you don't.

Good for "Do you want to save?" type dialogs.


GView::OnCommand

virtual int OnCommand(int Cmd, int Event, GWndRef hWnd)

Argument Description
int Cmd Command ID being processed.
int Event Command specify info
GWndRef hWnd Reference to calling window. May be NULL if not known.

Called to process WM_COMMAND type messages.


GView::OnEvent

virtual int OnEvent(GMessage *Msg)

Argument Description
GMessage *Msg The message parameters.

Use these #defines to access the values:

  • #define Message(GMessage *m)
  • #define MessageA(GMessage *m)
  • #define MessageB(GMessage *m)
Under windows the 'a' parameter is the wParam and the 'b' parameter is the lParam. For other platforms they aren't defined.

This function receives all the messages passed to the window.

Under Win32 this is the equivilant of the MessageProc for the window. Receiving all windows messages. You can put custom processing of messages in here, but most of the time you should just pass the message into the default handler, GWindow::OnEvent.

Under BeOS this function receives all the messages that the BView::MessageReceived receives. The GMessage is defined as a BMessage under BeOS so that you can retrieve any attributes of the message via the normal BMessage API.


GView::OnHitTest

virtual int OnHitTest(int x, int y)

Argument Description
int x Location of mouse over window
int y Location of mouse over window

Only really relevent under Win32. Called in response to the WM_NCHITTEST message.


GView::OnNotify

virtual int OnNotify(GWindow *Ctrl, int Flags)

Argument Description
GWindow *Ctrl Control that changed
int Flags New value. Control specific.

Called when a child control has changed value.


GView::OnChildrenChanged

virtual void OnChildrenChanged(GWindow *Wnd, bool Attaching)

Argument Description
GWindow *Wnd The window in question
bool Attaching true if the window is being attached and false if it's being detached.

Called when a window has been Attached or Detached from this object.


GView::OnCreate

virtual void OnCreate()

Under Win32 this is called when the window has has a HWND.

Under BeOS this is called when the BView is attached to something.


GView::OnDestroy

virtual void OnDestroy()

Called when the window is being destroyed.


GView::OnFocus

virtual void OnFocus(bool f)

Argument Description
bool f New focus state

Called when the window receives or loses focus.


GView::OnKey

virtual void OnKey(VKey &k)

Argument Description
VKey &k The key that was hit. See VKey for more information.

Called when the window has the focus and the user hits a key.


GView::OnMouseClick

virtual void OnMouseClick(VMouse &m)

Argument Description
VMouse &m Event information. See VMouse

Called when the user clicks a mouse button down.


GView::OnMouseEnter

virtual void OnMouseEnter(VMouse &m)

Argument Description
VMouse &m Event information. See VMouse

Called when the mouse enters the area of the screen the window occupies.


GView::OnMouseExit

virtual void OnMouseExit(VMouse &m)

Argument Description
VMouse &m Event information. See VMouse

Called when the mouse exits the area of the screen the window occupies.


GView::OnMouseMove

virtual void OnMouseMove(VMouse &m)

Argument Description
VMouse &m Event information. See VMouse

Called when the mouse moves within the area of the screen the window occupies.


GView::OnPaint

virtual void OnPaint(GdcBasePrimitives *pDC)

Argument Description
GdcBasePrimitives *pDC A pointer to the device context to draw on. See GdcBasePrimitives for more info.

Called when the window needs to be drawn on the screen. Use the pDC variable to do drawing. You should draw in all the space of the window. To find the region to draw in you can use code like this:

GdcRegion r(0, 0, X()-1, Y()-1);

The rectangle 'r' will contain the top-left and bottom-right of where this window should paint.


GView::OnPosChange

virtual void OnPosChange()

Called when the window's position changes. The position can be retreived by calling GetPos().


GView::OnPulse

virtual void OnPulse()

If you need to execute some code at regular intervals then you can call SetPulse(Milliseconds) to start getting events. OnPulse is the function called every time the timeout expires. When you don't need the events any more call SetPulse().


GView::Enabled

virtual bool Enabled()

Returns true if the window is enabled.


GView::Flat

virtual bool Flat()

Returns true if the window has a flat border.


GView::Focus

virtual bool Focus()

Returns true if the window has the keyboard focus.


GView::Raised

virtual bool Raised()

Returns true if the window has a raised border.


GView::Sunken

virtual bool Sunken()

Returns true if the window has a sunken border.


GView::Visible

virtual bool Visible()

Returns true if the window is visible.


GView::Enabled

virtual void Enabled(bool i)

Argument Description
bool i New state

Enables or disables a window. Windows that are disabled can't receive input and are typically greyed out.


GView::Flat

virtual void Flat(bool i)

Argument Description
bool i

Call to set the border style.


GView::Focus

virtual void Focus(bool i)

Argument Description
bool i


GView::Raised

virtual void Raised(bool i)

Argument Description
bool i

Call to set a raised border.


GView::Sunken

virtual void Sunken(bool i)

Argument Description
bool i

Call to set the border style.


GView::Visible

virtual void Visible(bool i)

Argument Description
bool i true - Visible
false - Invisible

Makes the window visible or invisible.


GView::FindLargest

GdcRegion *FindLargest(GdcComplexRegion &r)

Argument Description
GdcComplexRegion &r The remaining region available for allocation to windows.

This function returns the largest rectangle in the region specified.


GView::FindLargestEdge

GdcRegion *FindLargestEdge(GdcComplexRegion &r, int Edge)

Argument Description
GdcComplexRegion &r The remaining region available for allocation
int Edge The edge you want to stick to. Can be one of:
  • GV_EDGE_TOP
  • GV_EDGE_RIGHT
  • GV_EDGE_BOTTOM
  • GV_EDGE_LEFT

Finds the largest rectangle on the requested edge.


GView::FindSmallestFit

GdcRegion *FindSmallestFit(GdcComplexRegion &r, int Sx, int Sy)

Argument Description
GdcComplexRegion &r The region left for allocation.
int Sx The minimum width of the rectangle needed
int Sy The minimum height of the rectangle needed

This function returns the smallest rectangle that will fit the size specified.


GView::Pour

virtual bool Pour(GdcComplexRegion &r)

Argument Description
GdcComplexRegion &r The available space the parent window has for allocating to child windows.

This function needs to be implemented in all GView derived classes. But can be implemented in GWindow derived classes that want to be used in poured environments.

In your implementation of this function you should decide how big you want to be, find where in the available space you can fit and then set your position to that location.

return true if everything worked out and you got your space. false if there wasn't enough space available.


GView::GWndRef

(Platform: Win32)
operator GWndRef()

Returns the HWND for the window


GView::Handle

(Platform: Win32)
virtual GWndRef Handle()

Returns the HWND for the window.


GView::GetBView

(Platform: BeOS)
virtual BView *GetBView()

Returns the pointer to the BView that this object is = to.


GView::GetBWindow

(Platform: BeOS)
virtual BWindow *GetBWindow()

Returns the BWindow that the object is attached to.


Built: 13/9/2001 2:28:29 PM
© 2001 Matthew Allen
Lgi HomePage