tag_win.h

Go to the documentation of this file.
00001 #ifndef TAGGED_WINDOW_SUPPORT
00002 #define TAGGED_WINDOW_SUPPORT
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : Chris Koeritz                                                     *
00007 *  Author : tag & tagged_window                                               *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Provides a way to associate an object with a window.  One creates a tag  *
00012 *    to represent the name of the object, then uses the tag to attach the     *
00013 *    tagged_window class to the window.  Subsequently, the tagged_window can  *
00014 *    be retrieved given the tag to search for.  Probably the most effective   *
00015 *    way to use it is to derive your object from a tagged_window and then use *
00016 *    the find() function and dynamic_cast<> to get back to your original      *
00017 *    object.                                                                  *
00018 *                                                                             *
00019 *******************************************************************************
00020 * Copyright (c) 1996-$now By Author.  This program is free software; you can  *
00021 * redistribute it and/or modify it under the terms of the GNU General Public  *
00022 * License as published by the Free Software Foundation; either version 2 of   *
00023 * the License or (at your option) any later version.  This is online at:      *
00024 *     http://www.fsf.org/copyleft/gpl.html                                    *
00025 * Please send any updates to: fred@gruntose.com                               *
00026 \*****************************************************************************/
00027 
00028 #include "winexdll.h"
00029 
00030 #include <basis/istring.h>
00031 #include <basis/portable.h>
00032 
00033 class WINDOWS_EXTENSIONS_CLASS_STYLE tag
00034 {
00035 public:
00036   tag(const istring &name = istring());
00037     // creates a tag using the "name" as the unique identifier for an atom
00038     // (the "name" should probably be the name of the class that wants to
00039     // create a tagged_window, providing the name is unique).
00040   tag(const tag &to_copy);
00041   ~tag();
00042     // releases the atom.
00043 
00044   istring name() const { return my_name; }
00045 
00046   tag &operator = (const tag &to_copy);
00047 
00048 private:
00049   friend class tagged_window;
00050   istring my_name;  // the name of the atom(s).
00051 #ifdef __WIN32__
00052   ATOM atom;  // atom used to hold pointer as a property.
00053 #else
00054   ATOM atom_l;  // win16 needs two atoms for a 32 bit pointer.
00055   ATOM atom_h;
00056 #endif
00057 
00058   void create(const istring &name);  // creates the atom(s) for "name".
00059   void whack();  // releases the atom(s).
00060 };
00061 
00063 
00064 class WINDOWS_EXTENSIONS_CLASS_STYLE tagged_window
00065 {
00066 public:
00067   tagged_window(const tag &name_tag);
00068     // creates an unattached tagged_window.
00069 
00070   ~tagged_window();
00071     // removes the tag from the window, if it was ever attached.
00072 
00073   void attach(window_handle window);
00074     // attaches this object to the "window" specified by using the unique name
00075     // passed to the constructor.  this tagged_window can later be retrieved
00076     // by looking up the tag with find().
00077 
00078   void detach();
00079     // removes the property from our window and forgets the window's handle.
00080 
00081   static const tagged_window *find(window_handle window, const tag &to_find);
00082     // returns the tagged_window associated with the "window" that had
00083     // a tag equivalent to "to_find" attached to it.  if the tagged_window
00084     // cannot be found, then NIL is returned.
00085 
00086   const tag &name() const { return name_tag; }
00087     // returns the name tag for this window.
00088 
00089 private:
00090   window_handle window;  // the window of interest.
00091   tag name_tag;  // what to use as a tag for the window.
00092   bool attached;  // are we currently connected to the window?
00093 
00094   // prohibited: copy constructor and assignment.
00095   tagged_window(const tagged_window &to_copy);
00096   tagged_window &operator = (const tagged_window &to_copy);
00097 };
00098 
00099 #endif
00100 

Generated on Fri Nov 21 04:29:26 2008 for HOOPLE Libraries by  doxygen 1.5.1