home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-25 | 10.8 KB | 181 lines | [TEXT/MMCC] |
- //------------------------------------------------------------------------------
- // File: widget.cp
- // Date: 7/17/94
- // Author: Bretton Wade
- //
- // Description: this file contains the methods widget class. a widget is a
- // user interface item that handles clicks and keys and other
- // forms of interraction.
- //
- //------------------------------------------------------------------------------
-
- #include "event.h"
- #include "widget.h"
-
- //------------------------------------------------------------------------------
- // constructor
- //------------------------------------------------------------------------------
- widget::widget (void) // constructor
- { // begin
- region = NewRgn (); // create a new region (empty)
- next = 0; // no pointer to next widget in the list
- children = 0; // no pointer to child widgets
- parent = 0; // no pointer to a parent widget
- enabled = TRUE; // all widgets start enabled
- } // end
-
- //------------------------------------------------------------------------------
- // destructor
- //------------------------------------------------------------------------------
- widget::~widget (void) // destructor
- { // begin
- if (region) DisposeRgn (region); // release the region, if any
- while (children) // for all the child widgets
- { // begin
- widget *current = children; // get a copy of the current child pointer
- children = children->next; // advance to the next child widget
- delete current; // kill the current child
- } // end
- } // end
-
- //------------------------------------------------------------------------------
- // Adjust the cursor if it is inside the region
- //------------------------------------------------------------------------------
- widget *widget::AdjustCursor (EventRecord &event) // method to adjust the cursor appropriately
- { // begin
- widget *current = FindWidget (event); // find the widget under the mouse
- if (current) // if it is a valid widget
- { // begin
- MouseRegion (current->region); // copy its region to the mouse region
- current->SetCursor (); // set the cursor to what it wants
- } // end
- return current; // return the widget
- } // end
-
- //------------------------------------------------------------------------------
- // Set the cursor to what is appropriate for the widget
- //------------------------------------------------------------------------------
- void widget::SetCursor (void) // method to set the cursor to the correct shape
- { // begin
- InitCursor (); // default is to set the cursor to an arrow
- } // end
-
- //------------------------------------------------------------------------------
- // Handle a mouse down event in the widget
- //------------------------------------------------------------------------------
- void widget::HandleClick (EventRecord &event) // handle mouse down/up
- { // begin
- widget *current = FindWidget (event); // find the owner of the click
- if (current && (current != this)) // if the current widget is valid
- current->HandleClick (event); // let it handle the click
- } // end
-
- //------------------------------------------------------------------------------
- // Handle a key event in the widget
- //------------------------------------------------------------------------------
- void widget::HandleKey (EventRecord&) // handle key press events
- { // begin
- } // end
-
- //------------------------------------------------------------------------------
- // update the widget
- //------------------------------------------------------------------------------
- void widget::Update (EventRecord &event) // method to update the widget and all of its children
- { // begin
- if (children) // if this widget has a child
- children->Update (event); // tell it to update
- if (next) // if this widget has a sibling
- next->Update (event); // tell it to update
- Draw (); // draw the widget
- } // end
-
- //------------------------------------------------------------------------------
- // activate the widget and all the children accordingly
- //------------------------------------------------------------------------------
- void widget::Activate (EventRecord &event) // activate/deactivate the widget
- { // begin
- if (children) // if this widget has a child
- children->Activate (event); // tell it to activate
- if (next) // if this widget has a sibling
- next->Activate (event); // tell it to activate
- } // end
-
- //------------------------------------------------------------------------------
- // resize the widget and all the children accordingly
- //------------------------------------------------------------------------------
- void widget::Resize (EventRecord &event) // method to recompute sizing information from parent
- { // begin
- if (parent) // if the widget has a parent
- DiffRgn (parent->region, region, parent->region); // subtract this region from the parent region
- if (children) // if this widget has a child
- children->Resize (event); // tell it to resize
- if (next) // if this widget has a sibling
- next->Resize (event); // tell it to resize
- } // end
-
- //------------------------------------------------------------------------------
- // add a child widget to this widget
- //------------------------------------------------------------------------------
- void widget::AddChild (widget *w) // add a child widget to this one
- { // begin
- w->next = children; // put the current child list into the new child
- children = w; // put the new child at the front of the list
- w->parent = this; // assign the parent to the new widget
- } // end
-
- //------------------------------------------------------------------------------
- // Find the widget that owns the current interface event
- //------------------------------------------------------------------------------
- widget *widget::FindWidget (EventRecord &event) // return a pointer to the widget that owns the location of the mouse
- { // begin
- if (PtInRgn (event.where, region)) // if the point is actually in the widget
- return this; // return, we've found it
- widget *current = children; // get the child list
- while (current) // loop over all the children
- { // begin
- widget *w = current->FindWidget (event); // try to find the owner in this child
- if (w) // if successful
- return w; // return the results
- current = current->next; // skip to the next child
- } // end
- return 0; // return the failure
- } // end
-
- //------------------------------------------------------------------------------
- // Set the enabled state of the widget
- //------------------------------------------------------------------------------
- void widget::Enable (bool enable) // set the enable state of the widget
- { // begin
- enabled = enable; // set the currently enabled state
- widget *current = children; // get the first child
- while (current) // as long as there are children
- { // begin
- current->Enable (enable); // tell it to enable
- current = current->next; // skip to the next child
- } // end
- Draw (); // redraw the widget in its new state
- } // end
-
- //------------------------------------------------------------------------------
- // an action command
- //------------------------------------------------------------------------------
- void widget::Action (int code) // an action command
- { // begin
- widget *current = children; // get the first child
- while (current) // as long as there are children
- { // begin
- current->Action (code); // tell it to perform the action
- current = current->next; // skip to the next child
- } // end
- } // end
-
- //------------------------------------------------------------------------------
- // draw the widget
- //------------------------------------------------------------------------------
- void widget::Draw (void) // draw the widget
- { // begin
- // set the clipping region to the widget region??
- } // end
-
- //------------------------------------------------------------------------------
-