]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTabular.C
fix bug 850 (fix confirmed by John)
[lyx.git] / src / frontends / controllers / ControlTabular.C
1 // -*- C++ -*-
2 /**
3  * \file ControlTabular.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include "ControlTabular.h"
13
14 #include "ButtonControllerBase.h"
15 #include "ViewBase.h"
16 #include "support/LAssert.h"
17
18 #include "frontends/LyXView.h"
19 #include "BufferView.h"
20 #include "buffer.h"
21 #include "lyxrc.h"
22 #include "insets/insettabular.h"
23
24 #include <boost/bind.hpp>
25
26 ControlTabular::ControlTabular(LyXView & lv, Dialogs & d)
27         : ControlConnectBD(lv, d),
28           inset_(0), dialog_built_(false)
29 {}
30
31
32 void ControlTabular::showInset(InsetTabular * inset)
33 {
34         lyx::Assert(inset);
35
36         connectInset(inset);
37         show(inset);
38
39         // The widgets may not be valid, so refresh the button controller
40         // FIXME: needed ?
41         bc().refresh();
42 }
43
44
45 void ControlTabular::updateInset(InsetTabular * inset)
46 {
47         if (!view().isVisible())
48                 return;
49         lyx::Assert(inset);
50         connectInset(inset);
51         update();
52 }
53
54
55 void ControlTabular::show(InsetTabular * inset)
56 {
57         inset_ = inset;
58
59         if (emergency_exit_) {
60                 hide();
61                 return;
62         }
63
64         if (!dialog_built_) {
65                 view().build();
66                 dialog_built_ = true;
67         }
68
69         bc().readOnly(bufferIsReadonly());
70         view().show();
71 }
72
73
74 void ControlTabular::update()
75 {
76         if (emergency_exit_) {
77                 hide();
78                 return;
79         }
80
81         bc().readOnly(bufferIsReadonly());
82         view().update();
83
84         // The widgets may not be valid, so refresh the button controller
85         // FIXME: needed ?
86         bc().refresh();
87 }
88
89
90 void ControlTabular::hide()
91 {
92         emergency_exit_ = false;
93         inset_ = 0;
94
95         ih_.disconnect();
96         disconnect();
97         view().hide();
98 }
99
100
101 void ControlTabular::updateSlot(bool switched)
102 {
103         if (switched)
104                 hide();
105         else
106                 update();
107 }
108
109
110 void ControlTabular::connectInset(InsetTabular * inset)
111 {
112         // If connected to another inset, disconnect from it.
113         if (inset_) {
114                 ih_.disconnect();
115                 inset_ = 0;
116         }
117
118         if (inset) {
119                 inset_ = inset;
120                 ih_ = inset->hideDialog.connect(
121                         boost::bind(&ControlTabular::hide, this));
122         }
123         connect();
124 }
125
126
127 InsetTabular * ControlTabular::inset() const
128 {
129         lyx::Assert(inset_);
130         return inset_;
131 }
132
133
134 LyXTabular * ControlTabular::tabular() const
135 {
136         lyx::Assert(inset_);
137         return inset_->tabular.get();
138 }
139
140
141 void ControlTabular::set(LyXTabular::Feature f, string const & arg)
142 {
143         lyx::Assert(inset_);
144         inset_->tabularFeatures(lv_.view().get(), f, arg);
145 }
146
147
148 bool ControlTabular::metric() const
149 {
150         return lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER;
151 }
152
153 bool ControlTabular::isMulticolumnCell() const
154 {
155         int cell(inset()->getActCell());
156         return tabular()->IsMultiColumn(cell);
157 }