From f947c73420b3a3b59c38e714b703f05b4954e980 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 15 Jan 2005 13:14:13 +0000 Subject: testing menu theme and parser --- src/tests/menutest.cc | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/tests/menutest.cc diff --git a/src/tests/menutest.cc b/src/tests/menutest.cc new file mode 100644 index 0000000..07add9f --- /dev/null +++ b/src/tests/menutest.cc @@ -0,0 +1,155 @@ +// menutest.cc a test app for Menus +// Copyright (c) 2005 Henrik Kinnunen (fluxgenfluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +// $Id: menutest.cc 3700 2004-11-19 11:37:27Z mathias $ + +#include "App.hh" +#include "FbWindow.hh" +#include "Font.hh" +#include "EventHandler.hh" +#include "EventManager.hh" +#include "GContext.hh" +#include "Color.hh" +#include "Menu.hh" +#include "MenuItem.hh" +#include "MenuSeparator.hh" +#include "StringUtil.hh" +#include "ImageControl.hh" + +#include "../FbMenuParser.hh" + +#include +#include + +#include +#include +using namespace std; + +void doSubmenu(Parser &parser, FbTk::Menu &menu, + FbTk::MenuTheme &theme, + FbTk::ImageControl &image_ctrl, + const std::string labelstr) { + + Parser::Item key, label, cmd, icon; + + FbTk::Menu *submenu = new FbTk::Menu(theme, image_ctrl); + submenu->setLabel(labelstr.c_str()); + menu.insert(labelstr.c_str(), submenu); + // skip submenu items + if (key.second == "begin") { + while (key.second != "end") { + parser>>key>>label>>cmd>>icon; + if (key.second == "begin") + doSubmenu(parser, *submenu, + theme, image_ctrl, + label.second); + } + } +} + +class App:public FbTk::App, public FbTk::EventHandler { +public: + App(const char *displayname, const std::string &stylefile, const std::string &menufile): + FbTk::App(displayname), + m_image_ctrl(DefaultScreen(display())), + m_menu_theme(DefaultScreen(display())), + m_menu(m_menu_theme, m_image_ctrl) { + + m_menu_theme.frameFont().setAntialias(true); + m_menu_theme.titleFont().setAntialias(true); + + cerr<<"Loading menu: "<>key>>label>>cmd>>icon; + if (key.second == "begin") + break; + + } + + m_menu.setLabel(label.second.c_str()); + + while (!parser.eof()) { + parser>>key>>label>>cmd>>icon; + if (key.second == "end") + break; + + string iconfile = icon.second; + if (key.second == "separator") + m_menu.insert(new FbTk::MenuSeparator()); + else if (key.second == "begin") { // new submenu + doSubmenu(parser, m_menu, + m_menu_theme, + m_image_ctrl, + label.second); + } else if (key.second != "styles" && + key.second != "stylesdir") + m_menu.insert(label.second.c_str()); + + + // set icon on items + if (!iconfile.empty()) { + FbTk::MenuItem *item = m_menu.find(m_menu.numberOfItems() - 1); + item->setIcon(iconfile, m_menu.screenNumber()); + } + } + + } + + cerr<<"Loading style: "<