Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

MenuHandler.cpp

Go to the documentation of this file.
00001 00005 /* 00006 Copyright (C) 2004 Anders Hedström (grymse@alhem.net) 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 #include <stdio.h> 00023 #include "Menu.h" 00024 #include "MenuHandler.h" 00025 00026 #define ID_START 20000 00027 #define ID_SPAN 10000 00028 // id = (ID_START .. ID_START + ID_SPAN - 1) 00029 00030 #ifdef _DEBUG 00031 #define D2(x) { \ 00032 { \ 00033 FILE *fil = fopen("c:\\deb.log","at"); \ 00034 x; \ 00035 fclose(fil); \ 00036 } \ 00037 } 00038 #else 00039 #define D2(x) 00040 #endif 00041 00042 00043 00044 // statics 00045 int MenuHandler::m_next_id = 0; 00046 00047 00048 MenuHandler::MenuHandler() 00049 { 00050 } 00051 00052 00053 MenuHandler::~MenuHandler() 00054 { 00055 } 00056 00057 00058 void MenuHandler::Add(Menu *p) 00059 { 00060 m_menulist.push_back(p); 00061 } 00062 00063 00064 void MenuHandler::Remove(Menu *p) 00065 { 00066 for (menu_v::iterator it = m_menulist.begin(); it != m_menulist.end(); it++) 00067 { 00068 Menu *p0 = *it; 00069 if (p0 == p) 00070 { 00071 m_menulist.erase(it); 00072 break; 00073 } 00074 } 00075 } 00076 00077 00078 void MenuHandler::OnInitMenu(HMENU h) 00079 { 00080 for (menu_v::iterator it = m_menulist.begin(); it != m_menulist.end(); it++) 00081 { 00082 Menu *p0 = *it; 00083 if (p0->Handle() == h) 00084 { 00085 p0->OnInitMenu(); 00086 break; 00087 } 00088 } 00089 } 00090 00091 00092 void MenuHandler::OnInitPopupMenu(HMENU h,int relpos,bool winmenu) 00093 { 00094 for (menu_v::iterator it = m_menulist.begin(); it != m_menulist.end(); it++) 00095 { 00096 Menu *p0 = *it; 00097 if (p0->Handle() == h) 00098 { 00099 p0->OnInitPopupMenu(relpos, winmenu); 00100 break; 00101 } 00102 } 00103 } 00104 00105 00106 void MenuHandler::OnMenuSelect(HMENU h,int index,int flags) 00107 { 00108 for (menu_v::iterator it = m_menulist.begin(); it != m_menulist.end(); it++) 00109 { 00110 Menu *p0 = *it; 00111 if (p0->Handle() == h) 00112 { 00113 p0->OnMenuSelect(index, flags); 00114 break; 00115 } 00116 } 00117 } 00118 00119 00120 int MenuHandler::get_next_id(Menu *p) 00121 { 00122 // %! lock 00123 int id = ID_START + (++m_next_id % ID_SPAN); 00124 m_id[id] = p; 00125 D2(fprintf(fil,"new menu id: %d ptr: %08lx\n",id,(unsigned long)p);) 00126 return id; 00127 } 00128 00129 00130 bool MenuHandler::Valid(Menu *p) 00131 { 00132 for (menu_v::iterator it = m_menulist.begin(); it != m_menulist.end(); it++) 00133 { 00134 Menu *p0 = *it; 00135 if (p0 == p) 00136 { 00137 return true; 00138 } 00139 } 00140 D2(fprintf(fil,"ptr %08lx is not valid\n",(unsigned long)p);) 00141 return false; 00142 } 00143 00144 00145 bool MenuHandler::OnCommand(int id) 00146 { 00147 Menu *p = m_id[id]; 00148 if (p && Valid(p)) 00149 { 00150 D2(fprintf(fil,"OnCommand(%d) for menu %08lx\n",id,(unsigned long)p);) 00151 p->OnCommand( id ); 00152 return true; // %! not exactly true 00153 } 00154 return false; 00155 } 00156 00157

Generated on Thu Feb 10 22:42:34 2005 for Distributed URL Classification Tool by doxygen 1.3.7