Back to index

plt-scheme  4.2.1
TypeTree.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: type tree
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "TypeTree.h"
00029 #endif
00030 
00031 #define  Uses_wxTypeTree
00032 #include "wx.h"
00033 
00034 wxTypeDef::wxTypeDef()
00035 : wxObject(FALSE) 
00036 { 
00037   name = NULL; 
00038   __type = wxTYPE_TYPEDEF;
00039 }
00040 
00041 typedef struct {
00042     WXTYPE my_type;
00043     WXTYPE parent_type;
00044     char   *my_name;
00045 } wxInitType;
00046 
00047 static wxInitType init_types[] = {
00048 
00049     { wxTYPE_WINDOW,        wxTYPE_ANY,          "window"},
00050 
00051     { wxTYPE_PANEL,         wxTYPE_WINDOW,              "panel"},
00052     { wxTYPE_FRAME,         wxTYPE_PANEL,        "frame"},
00053     { wxTYPE_DIALOG_BOX,    wxTYPE_FRAME,        "dialog-box"},
00054 
00055     { wxTYPE_BUTTON,        wxTYPE_ITEM,         "button"},
00056     { wxTYPE_CHECK_BOX,            wxTYPE_ITEM,         "check-box"},
00057     { wxTYPE_CHOICE,        wxTYPE_ITEM,         "choice"},
00058     { wxTYPE_CANVAS,        wxTYPE_ITEM,         "canvas"},
00059     { wxTYPE_GAUGE,         wxTYPE_ITEM,         "gauge"},
00060     { wxTYPE_GROUP_BOX,            wxTYPE_ITEM,         "group-box"},
00061     { wxTYPE_ITEM,          wxTYPE_WINDOW,              "item"},
00062     { wxTYPE_LIST_BOX,             wxTYPE_ITEM,         "list-box"},
00063     { wxTYPE_MENU,          wxTYPE_ANY,          "menu"},
00064     { wxTYPE_MENU_BAR,             wxTYPE_ITEM,         "menu-bar"},
00065     { wxTYPE_MESSAGE,              wxTYPE_ITEM,         "message"},
00066     { wxTYPE_RADIO_BOX,            wxTYPE_ITEM,         "radio-box"},
00067     { wxTYPE_SCROLL_BAR,    wxTYPE_ITEM,         "scrollbar"},
00068     { wxTYPE_SLIDER,        wxTYPE_ITEM,         "slider"},
00069 
00070     { wxTYPE_EVENT,         wxTYPE_ANY,          "event"},
00071     { wxTYPE_COMMAND_EVENT, wxTYPE_EVENT,        "command-event"},
00072     { wxTYPE_KEY_EVENT,            wxTYPE_EVENT,        "key-event"},
00073     { wxTYPE_MOUSE_EVENT,   wxTYPE_EVENT,        "mouse-event"},
00074 
00075     { wxTYPE_DC,            wxTYPE_ANY,          "device-context"},
00076     { wxTYPE_DC_WINDOW,            wxTYPE_DC,           "window-device-context"},
00077     { wxTYPE_DC_MEMORY,            wxTYPE_DC_CANVAS,    "memory-device-context"},
00078     { wxTYPE_DC_METAFILE,   wxTYPE_DC,           "metafile-device-context"},
00079     { wxTYPE_DC_POSTSCRIPT, wxTYPE_DC,           "PostScript-device-context"},
00080     { wxTYPE_DC_PRINTER,    wxTYPE_DC,           "printer-device-context"},
00081 
00082     { wxTYPE_BITMAP,        wxTYPE_ANY,          "bitmap"},
00083     { wxTYPE_BRUSH,         wxTYPE_ANY,          "brush"},
00084     { wxTYPE_COLOUR,        wxTYPE_ANY,          "colour"},
00085     { wxTYPE_COLOURMAP,         wxTYPE_ANY,             "colourmap"},
00086     { wxTYPE_CURSOR,        wxTYPE_BITMAP,              "cursor"},
00087     { wxTYPE_PEN,           wxTYPE_ANY,          "pen"},
00088     { wxTYPE_FONT,          wxTYPE_ANY,          "font"},
00089     { wxTYPE_ICON,          wxTYPE_BITMAP,              "icon"},
00090     { wxTYPE_METAFILE,             wxTYPE_ANY,          "metafile"},
00091     { wxTYPE_TIMER,         wxTYPE_ANY,          "timer"},
00092 
00093     { wxTYPE_APP,           wxTYPE_ANY,          "application"},
00094 
00095     { wxTYPE_HASH_TABLE,    wxTYPE_ANY,          "hash-table"},
00096     { wxTYPE_LIST,          wxTYPE_ANY,          "list"},
00097     { wxTYPE_NODE,          wxTYPE_ANY,          "node"},
00098     { wxTYPE_STRING_LIST,   wxTYPE_LIST,         "string-list"},
00099 
00100     { wxTYPE_CONSTRAINTS,   wxTYPE_ANY,          "constraint-set"},
00101     { wxTYPE_TYPEDEF,              wxTYPE_ANY,          "type-record"},
00102 
00103 };
00104 
00105 //-----------------------------------------------------------------------------
00106 // wxTypeTree implementation
00107 //-----------------------------------------------------------------------------
00108 
00109 wxTypeTree::wxTypeTree(void) : wxHashTable(wxKEY_INTEGER)
00110 {
00111   unsigned int i;
00112 
00113   // Define explicit type hierarchy
00114   for (i = 0; i < wxNumberOf(init_types); i++) {
00115     AddType(init_types[i].my_type,
00116            init_types[i].parent_type,
00117            init_types[i].my_name);
00118   }
00119 }
00120 
00121 wxTypeTree::~wxTypeTree(void)
00122 {
00123 }
00124 
00125 void wxTypeTree::AddType(WXTYPE type, WXTYPE parent, char *name)
00126 {
00127     wxTypeDef *typ;
00128     typ = DEBUG_NEW wxTypeDef;
00129     typ->type   = type;
00130     typ->parent = parent;
00131     typ->name   = copystring(name);
00132     Put((long)type, (wxObject*)typ);
00133 }
00134 
00135 //-----------------------------------------------------------------------------
00136 // global functions to get type infos
00137 //-----------------------------------------------------------------------------
00138 
00139 Bool wxSubType(WXTYPE type1, WXTYPE type2)
00140 {
00141   WXTYPE t;
00142 
00143   if (type1 == type2)
00144     return TRUE;
00145   
00146   t = type1;
00147   while (TRUE) {
00148     wxTypeDef *typ;
00149     typ = (wxTypeDef*)wxAllTypes->Get((long)t);
00150     if (!typ)
00151       return FALSE;
00152     if (type2 == typ->parent)
00153       return TRUE;
00154     t = typ->parent;
00155   }
00156 }
00157 
00158 char *wxGetTypeName(WXTYPE type)
00159 {
00160   wxTypeDef *typ;
00161 
00162   if (type == wxTYPE_ANY)
00163     return "any";
00164   typ = (wxTypeDef *)wxAllTypes->Get((long)type);
00165   if (!typ)
00166     return NULL;
00167   return typ->name;
00168 }