]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlTabular.C
Juergen S's tabular patch. Good stuff !
[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         lyx::Assert(inset);
48
49         connectInset(inset);
50
51         if (!dialog_built_) {
52                 view().build();
53                 dialog_built_ = true;
54         }
55  
56         update();
57 }
58
59  
60 void ControlTabular::show(InsetTabular * inset)
61 {
62         inset_ = inset;
63
64         if (emergency_exit_) {
65                 hide();
66                 return;
67         }
68
69         if (!dialog_built_) {
70                 view().build();
71                 dialog_built_ = true;
72         }
73
74         bc().readOnly(bufferIsReadonly());
75         view().show();
76 }
77
78
79 void ControlTabular::update()
80 {
81         if (emergency_exit_) {
82                 hide();
83                 return;
84         }
85
86         bc().readOnly(bufferIsReadonly());
87         view().update();
88
89         // The widgets may not be valid, so refresh the button controller
90         // FIXME: needed ? 
91         bc().refresh();
92 }
93
94
95 void ControlTabular::hide()
96 {
97         emergency_exit_ = false;
98         inset_ = 0;
99
100         ih_.disconnect();
101         disconnect();
102         view().hide();
103 }
104
105
106 void ControlTabular::updateSlot(bool switched)
107 {
108         if (switched)
109                 hide();
110         else
111                 update();
112 }
113
114
115 void ControlTabular::connectInset(InsetTabular * inset)
116 {
117         // If connected to another inset, disconnect from it.
118         if (inset_) {
119                 ih_.disconnect();
120                 inset_ = 0;
121         }
122
123         if (inset) {
124                 inset_ = inset;
125                 ih_ = inset->hideDialog.connect(
126                         boost::bind(&ControlTabular::hide, this));
127         }
128         connect();
129 }
130  
131  
132 InsetTabular * ControlTabular::inset() const
133 {
134         lyx::Assert(inset_);
135         return inset_;
136 }
137
138
139 LyXTabular * ControlTabular::tabular() const
140 {
141         lyx::Assert(inset_);
142         return inset_->tabular.get();
143 }
144
145  
146 void ControlTabular::set(LyXTabular::Feature f, string const & arg)
147 {
148         lyx::Assert(inset_);
149         inset_->tabularFeatures(lv_.view().get(), f, arg);
150 }
151
152  
153 bool ControlTabular::metric() const
154 {
155         return lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER;
156 }
157
158 bool ControlTabular::isMulticolumnCell() const
159 {
160         int cell(inset()->getActCell());
161         return tabular()->IsMultiColumn(cell);
162 }