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 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. |
Initializes the object.
Inside the destructor the children are detached and deleted.
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.
This function attaches all the children currently in the member variable:
List<GWindow> Children;
If they are not already attached.
Breaks the connection between the parent and the child.
Return true if you want to close, or false if you don't.
Good for "Do you want to save?" type dialogs.
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.
Argument | Description |
GMessage *Msg |
The message parameters.
Use these #defines to access the values:
|
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.
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.
Argument | Description |
GWindow *Ctrl | Control that changed |
int Flags | New value. Control specific. |
Called when a child control has changed value.
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.
Under Win32 this is called when the window has has a HWND.
Under BeOS this is called when the BView is attached to something.
Called when the window is being destroyed.
Argument | Description |
bool f | New focus state |
Called when the window receives or loses focus.
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.
Argument | Description |
VMouse &m | Event information. See VMouse |
Called when the user clicks a mouse button down.
Argument | Description |
VMouse &m | Event information. See VMouse |
Called when the mouse enters the area of the screen the window occupies.
Argument | Description |
VMouse &m | Event information. See VMouse |
Called when the mouse exits the area of the screen the window occupies.
Argument | Description |
VMouse &m | Event information. See VMouse |
Called when the mouse moves within the area of the screen the window occupies.
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.
Called when the window's position changes. The position can be retreived by calling GetPos().
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().
Returns true if the window is enabled.
Returns true if the window has a flat border.
Returns true if the window has the keyboard focus.
Returns true if the window has a raised border.
Returns true if the window has a sunken border.
Returns true if the window is visible.
Argument | Description |
bool i | New state |
Enables or disables a window. Windows that are disabled can't receive input and are typically greyed out.
Argument | Description |
bool i |
Call to set the border style.
Argument | Description |
bool i |
Argument | Description |
bool i |
Call to set a raised border.
Argument | Description |
bool i |
Call to set the border style.
Argument | Description |
bool i |
true - Visible false - Invisible |
Makes the window visible or invisible.
Argument | Description |
GdcComplexRegion &r | The remaining region available for allocation to windows. |
This function returns the largest rectangle in the region specified.
Argument | Description |
GdcComplexRegion &r | The remaining region available for allocation |
int Edge |
The edge you want to stick to. Can be one of:
|
Finds the largest rectangle on the requested edge.
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.
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.
Returns the HWND for the window
Returns the HWND for the window.
Returns the pointer to the BView that this object is = to.
Returns the BWindow that the object is attached to.