]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.C
fix math fonts with LyX/Mac
[lyx.git] / src / frontends / Toolbars.C
1 /**
2  * \file Toolbars.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "Toolbars.h"
15
16 #include "debug.h"
17 #include "funcrequest.h"
18 #include "FuncStatus.h"
19 #include "lyxfunc.h"
20 #include "LyXView.h"
21
22 using std::endl;
23 using std::string;
24
25
26 Toolbars::Toolbars(LyXView & owner)
27         : owner_(owner),
28           layout_(0),
29           last_textclass_(-1)
30 {}
31
32
33 void Toolbars::init()
34 {
35         // extracts the toolbars from the backend
36         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
37         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
38
39         for (; cit != end; ++cit)
40                 add(*cit);
41 }
42
43
44 void Toolbars::display(string const & name, bool show)
45 {
46         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
47         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
48
49         for (; cit != end; ++cit) {
50                 if (cit->name == name) {
51                         displayToolbar(*cit, show);
52                         return;
53                 }
54         }
55
56         lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
57                 << name << endl;
58 }
59
60
61 void Toolbars::update(bool in_math, bool in_table)
62 {
63         update();
64
65         // extracts the toolbars from the backend
66         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
67         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
68
69         for (; cit != end; ++cit) {
70                 if (cit->flags & ToolbarBackend::MATH)
71                         displayToolbar(*cit, in_math);
72                 else if (cit->flags & ToolbarBackend::TABLE)
73                         displayToolbar(*cit, in_table);
74         }
75 }
76
77
78 void Toolbars::setLayout(string const & layout)
79 {
80         if (layout_)
81                 layout_->set(layout);
82 }
83
84
85 bool Toolbars::updateLayoutList(int textclass)
86 {
87         // update the layout display
88         if (last_textclass_ != textclass) {
89                 if (layout_)
90                         layout_->update();
91                 last_textclass_ = textclass;
92                 return true;
93         } else
94                 return false;
95 }
96
97
98 void Toolbars::openLayoutList()
99 {
100         if (layout_)
101                 layout_->open();
102 }
103
104
105 void Toolbars::clearLayoutList()
106 {
107         last_textclass_ = -1;
108         if (layout_)
109                 layout_->clear();
110 }
111
112
113 void Toolbars::add(ToolbarBackend::Toolbar const & tbb)
114 {
115         ToolbarPtr tb_ptr = make_toolbar(tbb, owner_);
116         toolbars_[tbb.name] = tb_ptr;
117
118         if (tbb.flags & ToolbarBackend::ON)
119                 tb_ptr->show(false);
120         else
121                 tb_ptr->hide(false);
122
123         if (tb_ptr->layout())
124                 layout_ = tb_ptr->layout();
125 }
126
127
128 void Toolbars::displayToolbar(ToolbarBackend::Toolbar const & tbb,
129                               bool show_it)
130 {
131         ToolbarsMap::iterator it = toolbars_.find(tbb.name);
132         BOOST_ASSERT(it != toolbars_.end());
133
134         if (show_it)
135                 it->second->show(true);
136         else
137                 it->second->hide(true);
138 }
139
140
141 void Toolbars::update()
142 {
143         ToolbarsMap::const_iterator it = toolbars_.begin();
144         ToolbarsMap::const_iterator const end = toolbars_.end();
145         for (; it != end; ++it)
146                 it->second->update();
147
148         bool const enable = owner_.getLyXFunc().
149                 getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
150
151         if (layout_)
152                 layout_->setEnabled(enable);
153 }