fluxbox/src/FbTk/MenuItem.hh

149 lines
5 KiB
C++
Raw Normal View History

2003-01-12 17:06:07 +00:00
// MenuItem.hh for FbTk - Fluxbox Toolkit
2005-01-24 18:02:34 +00:00
// Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at fluxbox dot org)
2003-01-12 17:06:07 +00:00
//
// 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.
2004-11-19 11:37:27 +00:00
// $Id$
2003-01-12 17:06:07 +00:00
#ifndef FBTK_MENUITEM_HH
#define FBTK_MENUITEM_HH
#include "RefCount.hh"
#include "Command.hh"
2004-06-10 17:31:39 +00:00
#include "PixmapWithMask.hh"
2003-01-12 17:06:07 +00:00
2004-06-10 11:40:43 +00:00
#include <string>
#include <memory>
2004-06-10 17:31:39 +00:00
2003-01-12 17:06:07 +00:00
namespace FbTk {
class Menu;
class MenuTheme;
class FbDrawable;
2003-01-12 17:06:07 +00:00
/// An interface for a menu item in Menu
class MenuItem {
public:
MenuItem()
: m_label(""),
2005-05-03 13:53:25 +00:00
m_menu(0),
m_submenu(0),
m_enabled(true),
m_selected(false),
m_toggle_item(false)
{ }
explicit MenuItem(
2003-01-12 17:06:07 +00:00
const char *label)
: m_label(label ? label : ""),
2005-05-03 13:53:25 +00:00
m_menu(0),
m_submenu(0),
m_enabled(true),
m_selected(false),
m_toggle_item(false)
{ }
MenuItem(const char *label, Menu &host_menu)
: m_label(label ? label : ""),
m_menu(&host_menu),
2003-08-27 14:18:02 +00:00
m_submenu(0),
m_enabled(true),
m_selected(false),
m_toggle_item(false)
2003-01-12 17:06:07 +00:00
{ }
/// create a menu item with a specific command to be executed on click
2005-05-03 13:53:25 +00:00
MenuItem(const char *label, RefCount<Command> &cmd, Menu *menu = 0):
2003-01-12 17:06:07 +00:00
m_label(label ? label : ""),
2005-05-03 13:53:25 +00:00
m_menu(menu),
2003-01-12 17:06:07 +00:00
m_submenu(0),
m_command(cmd),
m_enabled(true),
2003-08-27 14:18:02 +00:00
m_selected(false),
m_toggle_item(false) {
2003-01-12 17:06:07 +00:00
}
2005-05-03 13:53:25 +00:00
MenuItem(const char *label, Menu *submenu, Menu *host_menu = 0)
2003-01-12 17:06:07 +00:00
: m_label(label ? label : "")
2005-05-03 13:53:25 +00:00
, m_menu(host_menu)
2003-01-12 17:06:07 +00:00
, m_submenu(submenu)
, m_enabled(true)
2003-08-27 14:18:02 +00:00
, m_selected(false),
m_toggle_item(false)
2003-01-12 17:06:07 +00:00
{ }
virtual ~MenuItem() { }
inline void setCommand(RefCount<Command> &cmd) { m_command = cmd; }
virtual inline void setSelected(bool selected) { m_selected = selected; }
virtual inline void setEnabled(bool enabled) { m_enabled = enabled; }
virtual inline void setLabel(const char *label) { m_label = (label ? label : ""); }
virtual inline void setToggleItem(bool val) { m_toggle_item = val; }
2004-06-10 11:40:43 +00:00
void setIcon(const std::string &filename, int screen_num);
2003-01-12 17:06:07 +00:00
Menu *submenu() { return m_submenu; }
/**
@name accessors
*/
//@{
virtual inline const std::string &label() const { return m_label; }
inline const Menu *submenu() const { return m_submenu; }
virtual inline bool isEnabled() const { return m_enabled; }
virtual inline bool isSelected() const { return m_selected; }
virtual inline bool isToggleItem() const { return m_toggle_item; }
virtual unsigned int width(const MenuTheme &theme) const;
virtual unsigned int height(const MenuTheme &theme) const;
virtual void draw(FbDrawable &drawable,
const MenuTheme &theme,
bool highlight,
// "foreground" is the transient bits - more likely to change
bool draw_foreground, bool draw_background,
int x, int y,
unsigned int width, unsigned int height) const;
2004-06-10 11:40:43 +00:00
virtual void updateTheme(const MenuTheme &theme);
2003-01-12 17:06:07 +00:00
/**
Called when the item was clicked with a specific button
@param button the button number
@param time the time stamp
2003-08-27 14:18:02 +00:00
*/
2003-01-12 17:06:07 +00:00
virtual void click(int button, int time);
RefCount<Command> &command() { return m_command; }
const RefCount<Command> &command() const { return m_command; }
//@}
2005-05-03 13:53:25 +00:00
void setMenu(Menu &menu) { m_menu = &menu; }
Menu *menu() { return m_menu; }
2003-01-12 17:06:07 +00:00
private:
std::string m_label; ///< label of this item
2005-05-03 13:53:25 +00:00
Menu *m_menu; ///< the menu we live in
2003-01-12 17:06:07 +00:00
Menu *m_submenu; ///< a submenu, 0 if we don't have one
RefCount<Command> m_command; ///< command to be executed
bool m_enabled, m_selected;
2003-08-27 14:18:02 +00:00
bool m_toggle_item;
2004-06-10 11:40:43 +00:00
struct Icon {
std::auto_ptr<PixmapWithMask> pixmap;
std::string filename;
};
std::auto_ptr<Icon> m_icon;
2005-05-03 13:53:25 +00:00
2003-01-12 17:06:07 +00:00
};
2003-12-16 17:06:52 +00:00
} // end namespace FbTk
2003-01-12 17:06:07 +00:00
#endif // FBTK_MENUITEM_HH