home *** CD-ROM | disk | FTP | other *** search
- /*
- ***********************************************************************
- *
- * Generic Dialog Class
- *
- * to handle a modeless dialog: a window with controls
- *
- * We call it a dialog because we want to take advantage of DialogManager
- * functionality to figure out which items needs to be redrawn, etc. chores
- *
- * Note the dialog is derived from the ScreenWindow, and it considers
- * ScreenWindow::this_window to be a DialogPtr
- *
- * Note, ModelessDialog::Item etc objects contain a dialog item handle, etc. information,
- * which is only valid as long as the corresponding dialog is still there. Therefore,
- * there is a danger of keeping and using an Item object after the dialog itself gets
- * disposed of. Declaring the Item class within the Modeless dialog _protected_ scope,
- * although does not remove that danger, certainly decreases chances of that
- * happening: this declaration makes sure that the Items are going to be used only
- * within dialog member functions, the only place it makes sense.
- *
- ***********************************************************************
- */
-
- #pragma once
- #include "window.h"
- #include "mymenv.h"
-
- class ModelessDialog : public ScreenWindow
- {
- friend class BasicControl;
- friend class UserItem;
-
- virtual void draw_user_item(const int item_no) {}
- virtual Boolean handle_item_hit(const int item_no) = 0;
- virtual Boolean handle_activate(Boolean onoff); // Handle suspend/resume events
- virtual void draw(void) {} // DialogSelect does all the drawing for us
-
- virtual void destroy_it(void); // Virtual destructor kludge
-
- Boolean generic_item_hit(const int item_no); // Return FALSE if additional attention needed
- protected:
- // Item control utilities
- // void draw_default_item_border(const int item_no);
-
- // Generic dialog items and more specialized ones
- class Item
- {
- protected:
- Handle item_handle;
- short item_type;
- Rect item_rect;
- public:
- Item(const ModelessDialog& the_dialog, const int item_no);
- operator const Rect * (void) const { return &item_rect; }
- };
-
- friend class ModelessDialog::Item;
-
- class ControlItem : public Item
- {
- public:
- ControlItem(const ModelessDialog& the_dialog, const int item_no);
- operator ControlHandle (void) const { return (ControlHandle)item_handle; }
- void set_title(const Str255 new_title) { SetControlTitle((ControlHandle)item_handle,new_title); }
- };
-
- class TextItem : public Item
- {
- public:
- TextItem(const ModelessDialog& the_dialog, const int item_no);
- void draw(const Str255 str); // Draw a new text in an item
- };
-
- public:
- // Create a color dialog from a resource template
- ModelessDialog(const short resource_id);
-
- // ModelessDialog event dispatch entry points
- // Return FALSE if this object doesn't want any
- // more events
- virtual Boolean handle_null_event(const long event_time);
- virtual Boolean handle_event(const EventRecord& the_event);
- };
-
-
- // Basic control object
- // It's assumed that a pointer to this object
- // is placed into RefCon of a control
- // This object handles some specific
- // click and highlighting features
- // Thus it's a way of implementing custom
- // control by slightly modifying a standard
- // control, and all without messing with
- // custom CDEF
- class BasicControl
- {
- friend class ModelessDialog;
- const int signature; // To make sure we are who we are
- enum { valid_sig = 0x43785 };
- ControlHandle this_control;
-
-
- static ControlDefProcPtr * real_defproc_handle; // original ScrollBar CDEF handle
- static ControlDefProcPtr * patch_defproc_handle; // handle to our patch, see below
- static ControlDefUPP defproc_patch_upp; // Universal pointer to our patch
- static pascal SInt32 defproc_patch // our patch itself
- (SInt16 var_code, ControlRef the_control, ControlDefProcMessage message, SInt32 param);
- //static pascal void track_action_relay(ControlHandle the_control, unsigned short part_no);
- //static ControlActionUPP track_action_relay_upp; // Universal pointer to the action_relay
- virtual void track_action(const int part_no) {}
-
- // Custom handle a mouse-click within this
- // control. Return TRUE if it's _completely_
- // handled, return FALSE if additional attention
- // needed (say, control value was changed)
- virtual Boolean handle_click(void) { return FALSE;}
- Boolean is_our_control(void) const { return signature == valid_sig; }
- protected:
- BasicControl(void) : signature(valid_sig), this_control(0) {}
- ControlHandle our_control(void) const
- { assert( this_control != nil ); return this_control; }
- void bind(const ModelessDialog::ControlItem& item); // Late constructor
- void set_value(const int new_value); // Set a new value of a control, clipped to
- // its [min,max] range
- };
-
- class UserItem
- {
- static pascal void user_item_relay_handler(WindowPtr the_dialog, short the_item);
- static UserItemUPP user_item_relay_handler_upp; // Universal pointer to the user_item_univ_handler
- protected:
- Rect rect;
- public:
- UserItem(void) {}
- void bind(const ModelessDialog& the_dialog, const int item_no); // Late constructor
- void force_redraw(void) { InvalRect(&rect); }
- };
-