tag_win.cpp

Go to the documentation of this file.
00001 #ifndef TAG_WIN_IMPLEMENTATION_FILE
00002 #define TAG_WIN_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : Chris Koeritz                                                     *
00007 *  Author : tag & tagged_window                                               *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1996-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "tag_win.h"
00019 
00020 #include <basis/convert_utf.h>
00021 
00022 tag::tag(const istring &name)
00023 #ifdef __WIN32__
00024 : atom(NIL)
00025 #else
00026 : atom_l(NIL), atom_h(NIL)
00027 #endif
00028 { create(name); }
00029 
00030 tag::tag(const tag &to_copy)
00031 #ifdef __WIN32__
00032 : atom(NIL)
00033 #else
00034 : atom_l(NIL), atom_h(NIL)
00035 #endif
00036 { *this = to_copy; }
00037 
00038 tag::~tag() { whack(); }
00039 
00040 tag &tag::operator = (const tag &to_copy)
00041 {
00042   if (this == &to_copy) return *this;
00043   whack();
00044   create(to_copy.name());
00045   return *this;
00046 }
00047 
00048 void tag::create(const istring &name)
00049 {
00050   my_name = name;
00051 #ifdef __WIN32__
00052   atom = AddAtom(to_unicode_temp(name));
00053 #else
00054   atom_h = AddAtom(to_unicode_temp(name + "_h"));
00055   atom_l = AddAtom(to_unicode_temp(name + "_l"));
00056 #endif
00057 }
00058 
00059 void tag::whack()
00060 {
00061 #ifdef __WIN32__
00062   if (atom) DeleteAtom(atom);
00063 #else
00064   if (atom_l) DeleteAtom(atom_l);
00065   if (atom_h) DeleteAtom(atom_h);
00066 #endif
00067 }
00068 
00070 
00071 tagged_window::tagged_window(const tag &_name_tag)
00072 : name_tag(_name_tag),
00073   window(NIL),
00074   attached(false)
00075 {}
00076 
00077 void tagged_window::attach(window_handle _window)
00078 {
00079   window = _window;
00080 #ifdef __WIN32__
00081   SetProp(window, to_unicode_temp((char *)name_tag.atom), (HANDLE)this);
00082 #else
00083   SetProp(window, to_unicode_temp((char *)name_tag.atom_h), (HANDLE)HIWORD((DWORD)this));
00084   SetProp(window, to_unicode_temp((char *)name_tag.atom_l), (HANDLE)LOWORD((DWORD)this));
00085 #endif
00086   attached = true;
00087 }
00088 
00089 tagged_window::~tagged_window() { detach(); }
00090 
00091 void tagged_window::detach()
00092 {
00093   if (!attached) return;
00094 #ifdef __WIN32__
00095   RemoveProp(window, to_unicode_temp((char *)name_tag.atom));
00096 #else
00097   RemoveProp(window, to_unicode_temp((char *)name_tag.atom_l));
00098   RemoveProp(window, to_unicode_temp((char *)name_tag.atom_h));
00099 #endif
00100   window = NIL;
00101   attached = false;
00102 }
00103 
00104 const tagged_window *tagged_window::find(window_handle window,
00105     const tag &name_tag)
00106 {
00107 #ifdef __WIN32__
00108   HANDLE h = GetProp(window, to_unicode_temp((char *)name_tag.atom));
00109   return (tagged_window *)h;
00110 #else
00111   return (tagged_window *)MAKELONG(GetProp(window, to_unicode_temp((char *)name_tag.atom_l)),
00112       GetProp(window, to_unicode_temp((char *)name_tag.atom_h)));
00113 #endif
00114 }
00115 
00116 
00117 #endif //TAG_WIN_IMPLEMENTATION_FILE
00118 

Generated on Fri Nov 28 04:29:00 2008 for HOOPLE Libraries by  doxygen 1.5.1