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
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 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"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class LyXLex;
|
2000-10-04 09:54:31 +00:00
|
|
|
class Buffer;
|
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 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. */
|
2000-08-30 03:40:51 +00:00
|
|
|
Documents,
|
2000-08-31 11:51:59 +00:00
|
|
|
///
|
|
|
|
Toc,
|
2000-08-30 03:40:51 +00:00
|
|
|
/** This is a list of viewable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
typically for the File->View menu. */
|
2000-08-30 03:40:51 +00:00
|
|
|
ViewFormats,
|
|
|
|
/** This is a list of updatable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
typically for the File->Update menu. */
|
2000-08-30 03:40:51 +00:00
|
|
|
UpdateFormats,
|
|
|
|
/** This is a list of exportable formats
|
2000-10-04 09:54:31 +00:00
|
|
|
typically for the File->Export menu. */
|
2000-11-06 11:20:22 +00:00
|
|
|
ExportFormats,
|
|
|
|
/** This is a list of importable formats
|
|
|
|
typically for the File->Export menu. */
|
2001-05-04 10:36:36 +00:00
|
|
|
ImportFormats,
|
|
|
|
/** This is the list of floats that we can
|
|
|
|
insert a list for. */
|
|
|
|
FloatListInsert,
|
|
|
|
/** This is the list of floats that we can
|
|
|
|
insert. */
|
|
|
|
FloatInsert
|
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-10-04 09:54:31 +00:00
|
|
|
MenuItem(Kind kind,
|
|
|
|
string const & label,
|
|
|
|
int action,
|
|
|
|
bool optional = false)
|
|
|
|
: kind_(kind), label_(label),
|
|
|
|
action_(action), submenu_(), optional_(optional) {}
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
/// The label of a given menuitem
|
2001-07-29 17:39:01 +00:00
|
|
|
string const label() const;
|
2000-11-03 13:26:55 +00:00
|
|
|
/// The keyboard shortcut (usually underlined in the entry)
|
2001-07-29 17:39:01 +00:00
|
|
|
string const shortcut() const;
|
2000-11-03 13:26:55 +00:00
|
|
|
/// The complete label, with label and shortcut separated by a '|'
|
|
|
|
string const fulllabel() const { return label_;}
|
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-10-04 09:54:31 +00:00
|
|
|
explicit Menu(string const & name = string(), bool mb = false)
|
2000-07-24 13:53:19 +00:00
|
|
|
: 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-10-04 09:54:31 +00:00
|
|
|
/// Expands some special entries of the menu
|
2000-11-03 13:26:55 +00:00
|
|
|
/** The entries with the following kind are expanded to a
|
2000-10-04 09:54:31 +00:00
|
|
|
sequence of Command MenuItems: Lastfiles, Documents,
|
|
|
|
ViewFormats, ExportFormats, UpdateFormats
|
|
|
|
*/
|
|
|
|
void expand(Menu & tomenu, Buffer *) const;
|
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(); }
|
2000-08-31 11:51:59 +00:00
|
|
|
///
|
|
|
|
ItemList::size_type size() const { return items_.size(); }
|
2000-12-06 13:41:44 +00:00
|
|
|
///
|
|
|
|
bool hasSubmenu(string const &) const;
|
2000-07-24 13:53:19 +00:00
|
|
|
///
|
|
|
|
const_iterator begin() const {
|
|
|
|
return items_.begin();
|
|
|
|
}
|
|
|
|
///
|
|
|
|
const_iterator end() const {
|
|
|
|
return items_.end();
|
|
|
|
}
|
2000-11-03 13:26:55 +00:00
|
|
|
|
|
|
|
// Check whether the menu shortcuts are unique
|
|
|
|
void checkShortcuts() const;
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
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 &);
|
|
|
|
///
|
2000-12-06 13:41:44 +00:00
|
|
|
bool hasMenu(string const &) const;
|
2000-07-24 13:53:19 +00:00
|
|
|
///
|
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 */
|