/*
* iconmenu.cc
* Copyright (C) 2000 Frank Hale
* frankhale@yahoo.com
* http://sapphire.sourceforge.net/
*
* Updated: 1 Nov 2001
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "aewm.hh"
IconMenu::IconMenu() : GenericMenu()
{
gotoDesktopMenu = new IconMenu(this);
gotoDesktopMenu->updateMenu();
char *temp = new char[wm->getMaxDesktops()];
for(int i=0; i<wm->getMaxDesktops(); i++)
{
sprintf(temp, "%d", i);
gotoDesktopMenu->insert(temp, "", GOTO_DESKTOP);
}
delete [] temp;
initialSetup();
}
IconMenu::IconMenu(IconMenu *parentMenu) : GenericMenu(parentMenu)
{
}
IconMenu::~IconMenu()
{
}
void IconMenu::initialSetup()
{
stringstream desktopNumber;
desktopNumber << "Desktop " << wm->getCurrentDesktop();
insert("separator", desktopNumber.str().c_str(), -1);
insert("Go to desktop", "", gotoDesktopMenu, -1);
gotoDesktopMenu->updateMenu();
addToMenuList(gotoDesktopMenu);
updateMenu();
addToMenuList(this);
updateIconMenu();
}
void IconMenu::updateIconMenu()
{
gotoDesktopMenu->updateMenu();
addToMenuList(gotoDesktopMenu);
updateMenu();
addToMenuList(this);
}
void IconMenu::handle_button_release_event(XButtonEvent *e)
{
GenericMenu::handle_button_release_event(e);
switch (e->button)
{
case Button1:
if (curr)
{
switch( curr->function )
{
case UNICONIFY:
curr->client->unhide();
hideAllVisibleSubmenus();
break;
case GOTO_DESKTOP:
wm->goToDesktop(atoi(curr->name.c_str()));
hideAllVisibleSubmenus();
break;
}
}
break;
case Button2:
case Button3:
break;
}
}
void IconMenu::addThisClient(Client *c)
{
BaseMenuItem *item = new BaseMenuItem();
if(c)
{
item->client = c;
item->name=c->getClientIconName(); // name showing on menu.
item->function=UNICONIFY;
insert(item);
}
}
void IconMenu::removeClientFromIconMenu(Client *c)
{
list<BaseMenuItem *>::iterator mit;
mit = getMenuItemList()->begin();
BaseMenuItem *item = NULL;
for(mit = getMenuItemList()->begin(); mit != getMenuItemList()->end(); mit++)
{
if((*mit)->client == c)
{
item = (*mit);
break;
}
}
if(item) remove(item);
}
syntax highlighted by Code2HTML, v. 0.9.1