]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.C
some tabular fixes for the problems reported by Helge
[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 "buffer.h"
17 #include "bufferparams.h"
18 #include "debug.h"
19 #include "funcrequest.h"
20 #include "FuncStatus.h"
21 #include "gettext.h"
22 #include "lyxfunc.h"
23 #include "lyxtextclass.h"
24 #include "LyXView.h"
25
26 using std::endl;
27 using std::string;
28
29
30 Toolbars::Toolbars(LyXView & owner)
31         : owner_(owner),
32           layout_(0),
33           last_textclass_(-1)
34 {}
35
36
37 void Toolbars::init()
38 {
39         // extracts the toolbars from the backend
40         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
41         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
42
43         for (; cit != end; ++cit)
44                 add(*cit);
45 }
46
47
48 void Toolbars::display(string const & name, bool show)
49 {
50         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
51         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
52
53         for (; cit != end; ++cit) {
54                 if (cit->name == name) {
55                         displayToolbar(*cit, show);
56                         return;
57                 }
58         }
59
60         lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
61                 << name << endl;
62 }
63
64
65 void Toolbars::update(bool in_math, bool in_table)
66 {
67         update();
68
69         // extracts the toolbars from the backend
70         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
71         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
72
73         for (; cit != end; ++cit) {
74                 if (cit->flags & ToolbarBackend::MATH)
75                         displayToolbar(*cit, in_math);
76                 else if (cit->flags & ToolbarBackend::TABLE)
77                         displayToolbar(*cit, in_table);
78         }
79 }
80
81
82 void Toolbars::setLayout(string const & layout)
83 {
84         if (layout_)
85                 layout_->set(layout);
86 }
87
88
89 bool Toolbars::updateLayoutList(int textclass)
90 {
91         // update the layout display
92         if (last_textclass_ != textclass) {
93                 if (layout_)
94                         layout_->update();
95                 last_textclass_ = textclass;
96                 return true;
97         } else
98                 return false;
99 }
100
101
102 void Toolbars::openLayoutList()
103 {
104         if (layout_)
105                 layout_->open();
106 }
107
108
109 void Toolbars::clearLayoutList()
110 {
111         last_textclass_ = -1;
112         if (layout_)
113                 layout_->clear();
114 }
115
116
117 void Toolbars::add(ToolbarBackend::Toolbar const & tbb)
118 {
119         ToolbarPtr tb_ptr = make_toolbar(tbb, owner_);
120         toolbars_[tbb.name] = tb_ptr;
121
122         if (tbb.flags & ToolbarBackend::ON)
123                 tb_ptr->show(false);
124         else
125                 tb_ptr->hide(false);
126
127         if (tb_ptr->layout())
128                 layout_ = tb_ptr->layout();
129 }
130
131
132 void Toolbars::displayToolbar(ToolbarBackend::Toolbar const & tbb,
133                               bool show_it)
134 {
135         ToolbarsMap::iterator it = toolbars_.find(tbb.name);
136         BOOST_ASSERT(it != toolbars_.end());
137
138         if (show_it)
139                 it->second->show(true);
140         else
141                 it->second->hide(true);
142 }
143
144
145 void Toolbars::update()
146 {
147         ToolbarsMap::const_iterator it = toolbars_.begin();
148         ToolbarsMap::const_iterator const end = toolbars_.end();
149         for (; it != end; ++it)
150                 it->second->update();
151
152         bool const enable = owner_.getLyXFunc().
153                 getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
154
155         if (layout_)
156                 layout_->setEnabled(enable);
157 }
158
159
160 void layoutSelected(LyXView & lv, string const & name)
161 {
162         LyXTextClass const & tc = lv.buffer()->params().getLyXTextClass();
163
164         LyXTextClass::const_iterator it  = tc.begin();
165         LyXTextClass::const_iterator const end = tc.end();
166         for (; it != end; ++it) {
167                 string const & itname = (*it)->name();
168                 // Yes, the _() is correct
169                 if (_(itname) == name) {
170                         FuncRequest const func(LFUN_LAYOUT, itname,
171                                                FuncRequest::UI);
172                         lv.getLyXFunc().dispatch(func);
173                         return;
174                 }
175         }
176         lyxerr << "ERROR (layoutSelected): layout not found!"
177                << endl;
178 }
179
180