2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of -*- C++ -*-
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-07-24 21:49:58 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
* This file is Copyright 1999
|
|
|
|
* Jean-Marc Lasgouttes
|
|
|
|
*
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
#ifndef MENUBACKEND_H
|
|
|
|
#define MENUBACKEND_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
2000-07-25 10:46:18 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-07-24 13:53:19 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class LyXLex;
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
class MenuItem {
|
|
|
|
public:
|
2000-07-24 21:49:58 +00:00
|
|
|
/// The type of elements that can be in a menu
|
|
|
|
enum Kind {
|
|
|
|
///
|
|
|
|
Command,
|
|
|
|
///
|
|
|
|
Submenu,
|
|
|
|
///
|
|
|
|
Separator,
|
|
|
|
/** This is the list of last opened file,
|
|
|
|
typically for the File menu. */
|
|
|
|
Lastfiles,
|
|
|
|
/** This is the list of opened Documents,
|
|
|
|
typically for the Documents menu. */
|
|
|
|
Documents
|
2000-07-24 13:53:19 +00:00
|
|
|
};
|
2000-07-24 21:49:58 +00:00
|
|
|
/// Create a Command type MenuItem
|
2000-07-25 10:46:18 +00:00
|
|
|
MenuItem(Kind kind,
|
|
|
|
string const & label = string(),
|
|
|
|
string const & command = string(),
|
|
|
|
bool optional = false);
|
2000-07-24 21:49:58 +00:00
|
|
|
/// The label of a given menuitem
|
2000-07-25 10:46:18 +00:00
|
|
|
string label() const { return token(label_, '|', 0); }
|
|
|
|
///
|
|
|
|
string shortcut() const { return token(label_, '|', 1); }
|
2000-07-24 21:49:58 +00:00
|
|
|
/// The kind of entry
|
2000-07-24 13:53:19 +00:00
|
|
|
Kind kind() const { return kind_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
/// the action (if relevant)
|
2000-07-24 13:53:19 +00:00
|
|
|
int action() const { return action_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
/// the description of the submenu (if relevant)
|
2000-07-24 13:53:19 +00:00
|
|
|
string const & submenu() const { return submenu_; }
|
2000-07-25 10:46:18 +00:00
|
|
|
/// returns true if the entry should be ommited when disabled
|
|
|
|
bool optional() const { return optional_; }
|
2000-07-24 13:53:19 +00:00
|
|
|
private:
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
Kind kind_;
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
string label_;
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
int action_;
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
string submenu_;
|
2000-07-25 10:46:18 +00:00
|
|
|
///
|
|
|
|
bool optional_;
|
2000-07-24 13:53:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
class Menu {
|
|
|
|
public:
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
typedef std::vector<MenuItem> ItemList;
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
typedef ItemList::const_iterator const_iterator;
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
explicit Menu(string const & name, bool mb = false)
|
|
|
|
: menubar_(mb), name_(name) {}
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
|
|
|
Menu & add(MenuItem const &);
|
|
|
|
///
|
2000-07-26 14:08:09 +00:00
|
|
|
Menu & read(LyXLex &);
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
bool menubar() const { return menubar_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
string const & name() const { return name_; }
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
bool empty() const { return items_.empty(); }
|
|
|
|
///
|
|
|
|
const_iterator begin() const {
|
|
|
|
return items_.begin();
|
|
|
|
}
|
|
|
|
///
|
|
|
|
const_iterator end() const {
|
|
|
|
return items_.end();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
ItemList items_;
|
|
|
|
///
|
|
|
|
bool menubar_;
|
|
|
|
///
|
|
|
|
string name_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
class MenuBackend {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
typedef std::vector<Menu> MenuList;
|
|
|
|
///
|
|
|
|
typedef MenuList::const_iterator const_iterator;
|
|
|
|
///
|
|
|
|
void read(LyXLex &);
|
|
|
|
/// Set default values for menu structure.
|
|
|
|
void defaults();
|
|
|
|
///
|
|
|
|
void add(Menu const &);
|
|
|
|
///
|
|
|
|
bool hasMenu (string const &) const;
|
|
|
|
///
|
2000-07-26 14:08:09 +00:00
|
|
|
Menu & getMenu (string const &);
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
Menu const & getMenu (string const &) const;
|
|
|
|
//
|
|
|
|
bool empty() const { return menulist_.empty(); }
|
|
|
|
///
|
|
|
|
const_iterator begin() const {
|
|
|
|
return menulist_.begin();
|
|
|
|
}
|
|
|
|
///
|
|
|
|
const_iterator end() const {
|
|
|
|
return menulist_.end();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
MenuList menulist_;
|
|
|
|
};
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
extern MenuBackend menubackend;
|
|
|
|
|
|
|
|
#endif /* MENUBACKEND_H */
|