home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
yacl-012.zip
/
ui
/
cntroler.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-08
|
13KB
|
419 lines
#ifndef _controller_h_
#define _controller_h_
/*
*
* Copyright (C) 1994, M. A. Sridhar
*
*
* This software is Copyright M. A. Sridhar, 1994. You are free
* to copy, modify or distribute this software as you see fit,
* and to use it for any purpose, provided this copyright
* notice and the following disclaimer are included with all
* copies.
*
* DISCLAIMER
*
* The author makes no warranties, either expressed or implied,
* with respect to this software, its quality, performance,
* merchantability, or fitness for any particular purpose. This
* software is distributed AS IS. The user of this software
* assumes all risks as to its quality and performance. In no
* event shall the author be liable for any direct, indirect or
* consequential damages, even if the author has been advised
* as to the possibility of such damages.
*
*/
// Authors: M. A. Sridhar
// N. Bhowmik
#if defined(__GNUC__)
#pragma interface
#endif
#include "base/tree.h"
#include "base/objset.h"
#include "ui/visualob.h"
#include "ui/rectangl.h"
#include "ui/event.h"
#include "ui/applic.h"
#include "ui/cursor.h"
// The Controller class encapsulates the object creation/disposal, event
// capturing/dispatching details of a YACL application. In any YACL
// application, there can be only one instance of the class
// UI_Controller. This class owns and manages the central event queue. All
// hard events are captured and added to the queue by this class while soft
// events generated by other YACL objects are also added by it. All event
// dispatching and disposal is taken care of by this class. In other words,
// any YACL object is free to create an event and add it to the queue via
// the controller. The disposal of this event, after it has been processed
// is the controller's responsibility. Similarly, all object disposal is
// also taken care of by the controller. As documented elsewhere, YACL does
// not allow static objects. Nor does it allow explicit deletion. Any
// object that needs to be destroyed must be sent an
// Event_Destroy or Event_Quit. The controller ensures that the object and ALL
// its children are then destroyed. It does so by maintaining a tree of
// all visual objects in the application.
//
// In addition to event and object management, the controller also provides
// methods for handling the mouse and keyboard.
class CL_EXPORT UI_MenuItem;
class CL_EXPORT UI_Controller: public CL_Object {
public:
UI_Controller (UI_Application* appl);
~UI_Controller ();
//
//----------Controller Services/events provided to a VisualObject
//
//
// -------------Mouse Control----------------------------
//
void GiveMouseTo (const UI_VisualObject& aView);
// Direct all mouse events to aView irrespective of cursor position.
void ReleaseMouse ();
// Stop directing all mouse events to a particular view.
//
//--------------KeyBoard Control-------------------
//
void GiveFocusTo (const UI_VisualObject& v);
// Direct all keyboard events to v.
// ----------------------- Cursor display -----------------------
void BeginWait ();
// Begin a ``wait state'' by displaying the platform-specific wait
// cursor. Until {\tt EndWait} is called, the mouse cursor will not change.
void EndWait ();
// End the wait state begun by {\tt BeginWait}.
//
//----------------Modal Input--------------------------
//
void Beep ();
// Provide a short beep.
// ----------------- Event methods -------------------
void EventLoop (CL_AbstractBinding* termination = NULL,
CL_AbstractBinding* eventFilter = NULL);
// A generalized event loop that does the following: retrieve an event,
// invoke eventFilter on that event, and dispatch the event if
// eventFilter returns TRUE. Then consult the termination binding with
// the event as parameter, and stop the loop if it returns TRUE.
//
// The default value of both parameters is NULL; a NULL termination
// binding is assumed to always return FALSE, while a NULL eventFilter
// binding is assumed to always return TRUE.
void Run ();
// The {\tt Run} method is simply a convenient way of running the
// {\tt EventLoop} until the app gets a Quit event.
void DispatchPendingEvents ();
// Dispatch all pending hard events. Must be called periodically when in
// long processing loops when a progress dialog needs to be maintained.
void AddEvent (UI_Event* );
// Add an event to the event queue.
// ----------------------- View methods ----------------------
UI_CompositeVObject* Root () {return _root;};
// Return the root of the view tree.
CL_ObjectSequence ChildrenOf (const UI_VObjCollection& o);
// Return the children of the given VObjCollection as an
// ObjectSequence. Each cell in this sequence can be cast down to {\tt
// UI_VisualObject*}.
CL_IntegerTree* ViewTree ();
// Return a pointer to the view tree.
UI_VisualObject* operator[] (UI_ViewHandle);
// Return the visual object with the given handle.
UI_VisualObject* VObjUnderMouse() const {return _current;};
// Return the visual object over which the mouse is currently
// positioned.
void MakeTopWindow (UI_CompositeVObject* root);
// Make {\tt root} the main window of the application. Must be called
// only once, at the beginning of the application.
bool Destroy (UI_VisualObject* aView);
// Invoke the destructor of the view and those of the subtree rooted
// at it, if any.
long GetNextWidgetCount ();
UI_VisualObject* Focus () {return _focus;};
// Return the VisualObject that currently has focus.
#if defined(__MS_WINDOWS__)
short Initialize (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdln,
short nCmdShow);
// [MS/Windows-specific method]
#elif defined(__OS2__)
short Initialize ();
// [OS/2-specific method]
#elif defined(__X_MOTIF__)
short Initialize (int& argc,char *argv[]);
// [X-windows-specific method]
struct _WidgetRec* ShellWidget () { return _shell; };
// [X-windows-specific method] For YACL internal use only.
Display* AppDisplay ();
// [X-windows-specific method] For YACL internal use only.
#endif
const char* ClassName () const { return "UI_Controller";};
protected:
// ------- General event methods --------------
bool ProcessSoftEvent (UI_Event* e);
bool DispatchEvent (UI_Event* e);
bool ProcessNativeEvents ();
// ProcessNativeEvent: retrieve an event from the underlying window
// system and process it if the eventFilter allows the processing.
// Return TRUE if an event was available to
// process, and FALSE if not.
void DispatchSoftEvents ();
UI_Event* RemoveEvent ();
// Remove an event from the queue and return it.
//
// Instance variables:
//
UI_CompositeVObject* _root;
CL_IntegerTree* _viewTree; // Maintains all views in their proper
// hierarchical order
CL_ObjectSequence* _eventQueue; // Queue of events
UI_VisualObject* _current; // Object that is currently under the
// mouse (not necessarily has focus)
CL_IntPtrMap _visualObjMap;
UI_VisualObject* _focus; // The object currently in focus
#if defined(__MS_WINDOWS__)
HANDLE hInst;
HANDLE hPrevInst;
#elif defined(__X_MOTIF__)
struct _WidgetRec* _shell;
ulong _grabWindow;
CL_ObjectSet _uninitedObjs; // Uninitialized windows
#endif
short widgetCount;
private:
void _InitController ();
void FlushEventQueue ();
// Eat all the pending events that the platform has sent.
bool DisposeNode (const CL_Object&, long);
// Destroy a view (used for traversing the view tree).
bool RootDestroyed (CL_Object&, long);
// Are we finished? (The parameters are dummy, needed in order to use
// this method in a binding.)
bool TranslateNativeEvent (NativeEventStruct& msg, UI_Event& event);
// Translate the native even into a YACL event. Return TRUE if a knwon
// event, FALSE otherwise.
bool DispatchNativeEvent (UI_Event& e);
// Dispatch the event. Return FALSE if default processing must be done
// after this, TRUE otherwise. Most events require default processing
// to be done; the one exception is when a window refuses to be closed.
#if defined(__MS_WINDOWS__)
bool _DoOneEvent (NativeEventStruct&, UI_Event&);
// [MS-Windows-specific, internal use only]
void _MakeWindowsInterface (const UI_Event& e);
// [MS-Windows-specific, internal use only]
friend long FAR PASCAL YACLWindowProc (HWND ,unsigned, WORD, LONG);
// [MS-Windows-specific]
friend long FAR PASCAL YACLDialogProc (HWND ,unsigned, WORD, LONG);
// [MS-Windows-specific]
friend long FAR PASCAL _export YACLBtnGroupProc
(HWND hwnd, unsigned msg, WORD wParam, LONG lp);
// [MS-Windows-specific]
long WindowProc (HWND hwnd, unsigned msg, WORD wParam, LONG lp);
// [MS-Windows-specific]
long DialogProc (HWND hwnd, unsigned msg, WORD wParam, LONG lp);
// [MS-Windows-specific]
long BtnGroupProc (HWND hwnd, unsigned msg, WORD wParam, LONG lp);
// [MS-Windows-specific]
CL_PtrIntMap _menuMap;
ulong _buttonFaceBrush;
#elif defined(__OS2__)
HAB _hab;
HMQ _hmq;
void _AbortPMApp (const char* errMsg);
bool _DoOneEvent (NativeEventStruct&);
// [OS/2-specific, internal use only]
void _MakeOS2Interface (const UI_Event& e);
// [OS/2-specific, internal use only]
friend MRESULT EXPENTRY YACLWindowProc (HWND hWnd, ULONG msg, MPARAM p1,
MPARAM p2);
#elif defined(__X_MOTIF__)
bool _DoOneEvent (NativeEventStruct&);
// [X-windows-specific, internal use only]
void _MakeXInterface (const UI_Event& e);
// [X-Windows-specific, internal use only]
#endif
UI_Cursor _defaultCursor;
bool _inWaitState;
CL_AbstractBinding* _eventFilter;
CL_AbstractBinding* _termination;
public:
void Register (UI_VisualObject* view);
// [Internal use only]
// Add a view to the visual object tree as child of view->Parent(). If
// parent is NULL, this method assumes that the root is being created,
// and that the parameter is a composite.
bool SetCurrentCursor (UI_Cursor&);
// [Internal use only] Set the current cursor being shown. Return TRUE
// if a cursor was set, FALSE otherwise.
#if defined(__MS_WINDOWS__)
bool MenuItemCreated (UI_MenuItem* item);
// [MS-Windows-specific, for internal use only]
bool MenuItemDestroyed (UI_MenuItem* item);
// [MS-Windows-specific, for internal use only]
#elif defined(__OS2__)
HAB AnchorBlockHandle () const;
// [OS/2-specific, for internal use only]
HMQ MessageQueueHandle() const;
// [OS/2-specific, for internal use only]
#elif defined(__X_MOTIF__)
typedef char* String;
static void XEventHandler (struct _WidgetRec* w, void *, XEvent* xevent,
char *);
// [X-windows-specific; internal use only]
static void LButtonDouble (struct _WidgetRec*,
XEvent*, String*, unsigned int*);
// [X-windows-specific; internal use only]
static void MButtonDouble (struct _WidgetRec*,
XEvent*, String*, unsigned int*);
// [X-windows-specific; internal use only]
static void RButtonDouble (struct _WidgetRec*,
XEvent*, String*, unsigned int*);
// [X-windows-specific; internal use only]
ulong RegisterTimeOut (long msec, void (*function) (void*, ulong*),
void* client_data);
// [X-windows-specific; internal use only]
void UnregisterTimeOut (ulong);
// [X-windows-specific; internal use only]
#endif
};
inline CL_IntegerTree* UI_Controller::ViewTree ()
{
return _viewTree;
}
#if defined(__OS2__)
inline HAB UI_Controller::AnchorBlockHandle () const
{
return _hab;
}
inline HMQ UI_Controller::MessageQueueHandle () const
{
return _hmq;
}
#endif
#endif