1 /* treewm - an X11 window manager. 2 * Copyright (c) 2001-2002 Thomas J�ger <TheHunter2000 at web dot de> 3 * This code is released under the terms of the GNU GPL. 4 * See the included file LICENSE for details. 5 */ 6 7 #include "menuinfo.h" 8 #include "action.h" 9 10 struct MenuItemList { 11 MenuItem mi; 12 MenuItemList *next; 13 }; 14 MenuInfo(Section * section)15MenuInfo::MenuInfo(Section *section) { 16 s = section; 17 } 18 Init()19void MenuInfo::Init() { 20 n = 0; 21 MenuItemList *actions=0,*last=0; 22 for (Entry *e=s->fe;e;e=e->next) 23 if (e->tag) { 24 // lower(e->value); // why? (RP) 25 if (last) { 26 last->next = new MenuItemList; 27 last = last->next; 28 } else { 29 actions = new MenuItemList; 30 last = actions; 31 } 32 last->mi.text = strdup(e->tag); 33 last->mi.key = strdup(e->value); 34 last->mi.client = 0; 35 last->mi.flags = 0; 36 last->mi.submenu = 0; 37 last->next = 0; 38 ++n; 39 } 40 if (!n) { 41 menu = 0; 42 return; 43 } 44 menu = new MenuItem[n]; 45 int k=0; 46 while (actions) { 47 menu[k] = actions->mi; 48 last = actions; 49 actions = actions->next; 50 delete last; 51 ++k; 52 } 53 } 54 ~MenuInfo()55MenuInfo::~MenuInfo() { 56 for (int i=0; i!=n; ++i) { 57 free(menu[i].text); 58 free(menu[i].key); 59 } 60 if (menu) 61 delete [] menu; 62 } 63