]> git.lyx.org Git - lyx.git/blob - src/insets/insettabular.C
Fix for the deleteLyXText const problem.
[lyx.git] / src / insets / insettabular.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2000 The LyX Team.
7  *
8  *======================================================
9  */
10
11 #include <config.h>
12
13 #include <fstream>
14 #include <algorithm>
15
16 #include <cstdlib>
17
18 #ifdef __GNUG__
19 #pragma implementation
20 #endif
21
22 #include "insettabular.h"
23
24 #include "buffer.h"
25 #include "commandtags.h"
26 #include "LaTeXFeatures.h"
27 #include "Painter.h"
28 #include "font.h"
29 #include "lyxtext.h"
30 #include "lyx_gui_misc.h"
31 #include "LyXView.h"
32 #include "lyxfunc.h"
33 #include "insets/insettext.h"
34 #include "frontends/Dialogs.h"
35
36 extern void MenuLayoutTabular(bool, InsetTabular *);
37 extern bool UpdateLayoutTabular(bool, InsetTabular *);
38 extern void TabularOptClose();
39
40 const int ADD_TO_HEIGHT = 2;
41 const int ADD_TO_TABULAR_WIDTH = 2;
42
43 using std::ostream;
44 using std::ifstream;
45 using std::max;
46 using std::endl;
47
48 #define cellstart(p) ((p % 2) == 0)
49
50 //#define USE_NEW_LAYOUT 1
51
52 InsetTabular::InsetTabular(Buffer * buf, int rows, int columns)
53 {
54     if (rows <= 0)
55         rows = 1;
56     if (columns <= 0)
57         columns = 1;
58     buffer = buf; // set this first!!!
59     tabular = new LyXTabular(this, rows,columns);
60     // for now make it always display as display() inset
61     // just for test!!!
62     the_locking_inset = 0;
63     locked = no_selection = cursor_visible = false;
64     cursor.x_fix(-1);
65     oldcell = -1;
66     actcell = 0;
67     cursor.pos(0);
68     sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
69     need_update = INIT;
70 }
71
72
73 InsetTabular::InsetTabular(InsetTabular const & tab, Buffer * buf)
74 {
75     buffer = buf; // set this first
76     tabular = new LyXTabular(this, *(tab.tabular));
77     the_locking_inset = 0;
78     locked = no_selection = cursor_visible = false;
79     cursor.x_fix(-1);
80     oldcell = -1;
81     actcell = 0;
82     cursor.pos(0);
83     sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
84     need_update = INIT;
85 }
86
87
88 InsetTabular::~InsetTabular()
89 {
90     delete tabular;
91 #ifdef USE_NEW_LAYOUT
92     if (buffer->getUser())
93         buffer->getUser()->owner()->getDialogs()->hideTabular(this);
94 #endif
95 }
96
97
98 Inset * InsetTabular::Clone() const
99 {
100     InsetTabular * t = new InsetTabular(*this, buffer);
101     delete t->tabular;
102     t->tabular = tabular->Clone(t);
103     return t;
104 }
105
106
107 void InsetTabular::Write(Buffer const * buf, ostream & os) const
108 {
109     os << " Tabular" << endl;
110     tabular->Write(buf, os);
111 }
112
113
114 void InsetTabular::Read(Buffer const * buf, LyXLex & lex)
115 {
116     bool old_format = (lex.GetString() == "\\LyXTable");
117     string token;
118
119     if (tabular)
120         delete tabular;
121     tabular = new LyXTabular(buf, this, lex);
122
123     need_update = INIT;
124
125     if (old_format)
126         return;
127
128     lex.nextToken();
129     token = lex.GetString();
130     while (lex.IsOK() && (token != "\\end_inset")) {
131         lex.nextToken();
132         token = lex.GetString();
133     }
134     if (token != "\\end_inset") {
135         lex.printError("Missing \\end_inset at this point. "
136                        "Read: `$$Token'");
137     }
138 }
139
140
141 int InsetTabular::ascent(BufferView *, LyXFont const &) const
142 {
143     return tabular->GetAscentOfRow(0);
144 }
145
146
147 int InsetTabular::descent(BufferView *, LyXFont const &) const
148 {
149     return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
150 }
151
152
153 int InsetTabular::width(BufferView *, LyXFont const &) const
154 {
155     return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH);
156 }
157
158
159 void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline,
160                         float & x, bool cleared) const
161 {
162     Painter & pain = bv->painter();
163     int i, j, cell=0;
164     int nx;
165     float cx;
166
167     UpdatableInset::draw(bv,font,baseline,x,cleared);
168     if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
169                      (top_x != int(x)) || (top_baseline != baseline))) {
170 #if 1
171         int h = ascent(bv, font) + descent(bv, font);
172         int tx = display()? 0:top_x;
173         int w =  tx? width(bv, font):pain.paperWidth();
174         int ty = baseline - ascent(bv, font);
175         
176         if (ty < 0)
177             ty = 0;
178         if ((ty + h) > pain.paperHeight())
179             h = pain.paperHeight();
180         if ((top_x + w) > pain.paperWidth())
181             w = pain.paperWidth();
182         pain.fillRectangle(tx, ty, w, h);
183         need_update = FULL;
184         cleared = true;
185 #else
186         need_update = FULL;
187         resetPos(pain);
188         if (locked) { // repaint this way as the background was not cleared
189                 if (the_locking_inset)
190                         the_locking_inset->update(bv, font, true);
191                 locked = false;
192                 bv->updateInset(const_cast<InsetTabular*>(this), false);
193                 locked = true;
194                 return;
195         }
196 #endif
197     }
198     top_x = int(x);
199     top_baseline = baseline;
200     bool dodraw;
201     x += ADD_TO_TABULAR_WIDTH;
202     if (cleared || (need_update == FULL) || (need_update == CELL)) {
203         for(i=0;i<tabular->rows();++i) {
204             nx = int(x);
205             dodraw = ((baseline+tabular->GetDescentOfRow(i)) > 0) &&
206                     (baseline-tabular->GetAscentOfRow(i)) < pain.paperHeight();
207             for(j=0;j<tabular->columns();++j) {
208                 if (tabular->IsPartOfMultiColumn(i,j))
209                     continue;
210                 cx = nx + tabular->GetBeginningOfTextInCell(cell);
211                 if (hasSelection())
212                     DrawCellSelection(pain, nx, baseline, i, j, cell);
213                 if (dodraw && !cleared && locked && the_locking_inset) {
214                     if (the_locking_inset == tabular->GetCellInset(cell))
215                         tabular->GetCellInset(cell)->draw(bv, font,
216                                                           baseline, cx,
217                                                           cleared);
218                 } else if (dodraw) {
219                     tabular->GetCellInset(cell)->draw(bv, font, baseline, cx,
220                                                       cleared);
221                     DrawCellLines(pain, nx, baseline, i, cell);
222                 }
223                 nx += tabular->GetWidthOfColumn(cell);
224                 ++cell;
225             }
226             baseline += tabular->GetDescentOfRow(i) +
227                 tabular->GetAscentOfRow(i+1)+
228                 tabular->GetAdditionalHeight(cell+1);
229         }
230     }
231     x += width(bv, font);
232     need_update = NONE;
233 }
234
235
236 void InsetTabular::DrawCellLines(Painter & pain, int x, int baseline,
237                                  int row, int cell) const
238 {
239     int  x2 = x + tabular->GetWidthOfColumn(cell);
240     bool on_off;
241
242     if (!tabular->TopAlreadyDrawed(cell)) {
243         on_off = !tabular->TopLine(cell);
244         pain.line(x, baseline - tabular->GetAscentOfRow(row),
245                   x2, baseline -  tabular->GetAscentOfRow(row),
246                   on_off ? LColor::tabularonoffline:LColor::tabularline,
247                   on_off ? Painter::line_onoffdash:Painter::line_solid);
248     }
249     on_off = !tabular->BottomLine(cell);
250     pain.line(x,baseline +  tabular->GetDescentOfRow(row),
251               x2, baseline +  tabular->GetDescentOfRow(row),
252               on_off ? LColor::tabularonoffline:LColor::tabularline,
253               on_off ? Painter::line_onoffdash:Painter::line_solid);
254     if (!tabular->LeftAlreadyDrawed(cell)) {
255         on_off = !tabular->LeftLine(cell);
256         pain.line(x, baseline -  tabular->GetAscentOfRow(row),
257                   x, baseline +  tabular->GetDescentOfRow(row),
258                   on_off ? LColor::tabularonoffline:LColor::tabularline,
259                   on_off ? Painter::line_onoffdash:Painter::line_solid);
260     }
261     on_off = !tabular->RightLine(cell);
262     pain.line(x2 - tabular->GetAdditionalWidth(cell),
263               baseline -  tabular->GetAscentOfRow(row),
264               x2 - tabular->GetAdditionalWidth(cell),
265               baseline +  tabular->GetDescentOfRow(row),
266               on_off ? LColor::tabularonoffline:LColor::tabularline,
267               on_off ? Painter::line_onoffdash:Painter::line_solid);
268 }
269
270
271 void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
272                                      int row, int column, int cell) const
273 {
274     int tmp;
275
276     int cs = tabular->column_of_cell(sel_cell_start);
277     int ce = tabular->column_of_cell(sel_cell_end);
278     if (cs > ce) {
279         ce = cs;
280         cs = tabular->column_of_cell(sel_cell_end);
281     } else {
282         ce = tabular->right_column_of_cell(sel_cell_end);
283     }
284
285     int rs = tabular->row_of_cell(sel_cell_start);
286     int re = tabular->row_of_cell(sel_cell_end);
287     if (rs > re) {
288         tmp = rs;
289         rs = re;
290         re = tmp;
291     }
292
293     if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
294         int w = tabular->GetWidthOfColumn(cell);
295         int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row);
296         pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row),
297                            w, h, LColor::selection);
298     }
299 }
300
301
302 void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
303 {
304     if (reinit) {
305         need_update = INIT;
306         calculate_dimensions_of_cells(bv, font, true);
307         if (owner())
308             owner()->update(bv, font, true);
309         return;
310     }
311     if (the_locking_inset)
312         the_locking_inset->update(bv, font, reinit);
313     switch(need_update) {
314     case INIT:
315     case FULL:
316     case CELL:
317         if (calculate_dimensions_of_cells(bv, font, false))
318             need_update = INIT;
319         break;
320     case SELECTION:
321         need_update = INIT;
322         break;
323     default:
324         break;
325     }
326 }
327
328
329 char const * InsetTabular::EditMessage() const
330 {
331     return _("Opened Tabular Inset");
332 }
333
334
335 void InsetTabular::Edit(BufferView * bv, int x, int y, unsigned int button)
336 {
337     UpdatableInset::Edit(bv, x, y, button);
338
339     if (!bv->lockInset(this)) {
340         lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
341         return;
342     }
343     locked = true;
344     the_locking_inset = 0;
345     inset_pos = inset_x = inset_y = 0;
346     setPos(bv, x, y);
347     sel_pos_start = sel_pos_end = cursor.pos();
348     sel_cell_start = sel_cell_end = actcell;
349     bv->text->FinishUndo();
350     if (InsetHit(bv, x, y)) {
351         ActivateCellInset(bv, x, y, button);
352     }
353     UpdateLocal(bv, NONE, false);
354 //    bv->getOwner()->getPopups().updateFormTabular();
355 }
356
357
358 void InsetTabular::InsetUnlock(BufferView * bv)
359 {
360     TabularOptClose();
361     if (the_locking_inset) {
362         the_locking_inset->InsetUnlock(bv);
363         the_locking_inset = 0;
364     }
365     HideInsetCursor(bv);
366     if (hasSelection()) {
367         sel_pos_start = sel_pos_end = 0;
368         sel_cell_start = sel_cell_end = 0;
369         UpdateLocal(bv, FULL, false);
370     }
371     no_selection = false;
372     oldcell = -1;
373     locked = false;
374 }
375
376 void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
377                                bool mark_dirty)
378 {
379     need_update = what;
380     bv->updateInset(this, mark_dirty);
381     if (what != NONE)
382         resetPos(bv);
383 }
384
385 bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
386 {
387     lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
388     if (!inset)
389         return false;
390     oldcell = -1;
391     if (inset == tabular->GetCellInset(actcell)) {
392         lyxerr[Debug::INSETS] << "OK" << endl;
393         the_locking_inset = tabular->GetCellInset(actcell);
394         resetPos(bv);
395         inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
396         inset_y = cursor.y();
397         inset_pos = cursor.pos();
398         return true;
399     } else if (the_locking_inset && (the_locking_inset == inset)) {
400         if (cursor.pos() == inset_pos) {
401             lyxerr[Debug::INSETS] << "OK" << endl;
402             resetPos(bv);
403             inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
404             inset_y = cursor.y();
405         } else {
406             lyxerr[Debug::INSETS] << "cursor.pos != inset_pos" << endl;
407         }
408     } else if (the_locking_inset) {
409         lyxerr[Debug::INSETS] << "MAYBE" << endl;
410         return the_locking_inset->LockInsetInInset(bv, inset);
411     }
412     lyxerr[Debug::INSETS] << "NOT OK" << endl;
413     return false;
414 }
415
416 bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
417                                    bool lr)
418 {
419     if (!the_locking_inset)
420         return false;
421     if (the_locking_inset == inset) {
422         the_locking_inset->InsetUnlock(bv);
423         the_locking_inset = 0;
424         if (lr)
425             moveRight(bv, false);
426         UpdateLocal(bv, CELL, false);
427         return true;
428     }
429     if (the_locking_inset->UnlockInsetInInset(bv, inset, lr)) {
430         if ((inset->LyxCode() == TABULAR_CODE) &&
431             !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
432         {
433             UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
434             oldcell = actcell;
435         }
436         return true;
437     }
438     return false;
439 }
440
441 bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
442 {
443     if (!the_locking_inset)
444         return false;
445     if (the_locking_inset != inset)
446         return the_locking_inset->UpdateInsetInInset(bv, inset);
447     UpdateLocal(bv, CELL, false);
448     return true;
449 }
450
451
452 int InsetTabular::InsetInInsetY()
453 {
454     if (!the_locking_inset)
455         return 0;
456
457     return (inset_y + the_locking_inset->InsetInInsetY());
458 }
459
460
461 UpdatableInset * InsetTabular::GetLockingInset()
462 {
463     return the_locking_inset ? the_locking_inset->GetLockingInset() : this;
464 }
465
466
467 UpdatableInset * InsetTabular::GetFirstLockingInsetOfType(Inset::Code c)
468 {
469     if (c == LyxCode())
470         return this;
471     if (the_locking_inset)
472         return the_locking_inset->GetFirstLockingInsetOfType(c);
473     return 0;
474 }
475
476
477 bool InsetTabular::InsertInset(BufferView * bv, Inset * inset)
478 {
479     if (the_locking_inset)
480         return the_locking_inset->InsertInset(bv, inset);
481     return false;
482 }
483
484
485 void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
486 {
487     if (hasSelection()) {
488         sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
489         UpdateLocal(bv, SELECTION, false);
490     }
491     no_selection = false;
492
493     int ocell = actcell;
494
495     setPos(bv, x, y);
496     sel_pos_start = sel_pos_end = cursor.pos();
497     sel_cell_start = sel_cell_end = actcell;
498
499     bool inset_hit = InsetHit(bv, x, y);
500
501     if ((ocell == actcell) && the_locking_inset && inset_hit) {
502         the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
503         return;
504     } else if (the_locking_inset) {
505         the_locking_inset->InsetUnlock(bv);
506     }
507     the_locking_inset = 0;
508     if (inset_hit && bv->the_locking_inset) {
509         ActivateCellInset(bv, x, y, button);
510         the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
511     }
512 }
513
514
515 void InsetTabular::InsetButtonRelease(BufferView * bv,
516                                       int x, int y, int button)
517 {
518     if (button == 3) {
519         if (the_locking_inset) {
520             UpdatableInset * i;
521             if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
522                 i->InsetButtonRelease(bv, x, y, button);
523                 return;
524             }
525         }
526 #ifdef USE_NEW_LAYOUT
527         bv->owner()->getDialogs()->showTabular(this);
528 #if 0
529         else if (ocell != actcell)
530                 bview->getOwner()->getPopups().updateTabular();
531 #endif
532 #else
533         MenuLayoutTabular(true, this);
534 #endif
535         return;
536     }
537     if (the_locking_inset) {
538         the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
539         return;
540     }
541     no_selection = false;
542 }
543
544
545 void InsetTabular::InsetMotionNotify(BufferView * bv, int x, int y, int button)
546 {
547     if (the_locking_inset) {
548         the_locking_inset->InsetMotionNotify(bv, x - inset_x,
549                                              y - inset_y, button);
550         return;
551     }
552     if (!no_selection) {
553             // int ocell = actcell,
554             int old = sel_pos_end;
555
556         setPos(bv, x, y);
557         sel_pos_end = cursor.pos();
558         sel_cell_end = actcell;
559         if (old != sel_pos_end)
560             UpdateLocal(bv, SELECTION, false);
561 #if 0
562         if (ocell != actcell)
563             bview->getOwner()->getPopups().updateFormTabular();
564 #endif
565     }
566     no_selection = false;
567 }
568
569
570 void InsetTabular::InsetKeyPress(XKeyEvent * xke)
571 {
572     if (the_locking_inset) {
573         the_locking_inset->InsetKeyPress(xke);
574         return;
575     }
576 }
577
578
579 UpdatableInset::RESULT InsetTabular::LocalDispatch(BufferView * bv, int action,
580                                                    string const & arg)
581 {
582     UpdatableInset::RESULT 
583         result;
584
585     no_selection = false;
586     if (((result=UpdatableInset::LocalDispatch(bv, action, arg)) == DISPATCHED)
587         || (result == DISPATCHED_NOUPDATE)) {
588
589         resetPos(bv);
590         return result;
591     }
592     result=DISPATCHED;
593
594     if ((action < 0) && arg.empty())
595         return FINISHED;
596
597     if ((action != LFUN_DOWN) && (action != LFUN_UP) &&
598         (action != LFUN_DOWNSEL) && (action != LFUN_UPSEL))
599         cursor.x_fix(-1);
600     if (the_locking_inset) {
601         result=the_locking_inset->LocalDispatch(bv, action, arg);
602         if (result == DISPATCHED_NOUPDATE)
603             return result;
604         else if (result == DISPATCHED) {
605             the_locking_inset->ToggleInsetCursor(bv);
606             UpdateLocal(bv, CELL, false);
607             the_locking_inset->ToggleInsetCursor(bv);
608             return result;
609         } else if (result == FINISHED) {
610             if ((action == LFUN_RIGHT) || (action == -1)) {
611                 cursor.pos(inset_pos + 1);
612                 resetPos(bv);
613             }
614             sel_pos_start = sel_pos_end = cursor.pos();
615             sel_cell_start = sel_cell_end = actcell;
616             the_locking_inset=0;
617             result = DISPATCHED;
618             return result;
619         }
620     }
621
622     bool hs = hasSelection();
623     HideInsetCursor(bv);
624     switch (action) {
625         // Normal chars not handled here
626     case -1:
627         break;
628         // --- Cursor Movements ---------------------------------------------
629     case LFUN_RIGHTSEL:
630         if (tabular->IsLastCellInRow(actcell) && !cellstart(cursor.pos()))
631             break;
632         moveRight(bv, false);
633         sel_pos_end = cursor.pos();
634         if (!cellstart(cursor.pos())) {
635             if (tabular->right_column_of_cell(sel_cell_start) >
636                 tabular->right_column_of_cell(actcell))
637                 sel_cell_end = actcell+1;
638             else
639                 sel_cell_end = actcell;
640         }
641         UpdateLocal(bv, SELECTION, false);
642         break;
643     case LFUN_RIGHT:
644         result = moveRight(bv);
645         sel_pos_start = sel_pos_end = cursor.pos();
646         sel_cell_start = sel_cell_end = actcell;
647         if (hs)
648             UpdateLocal(bv, CURSOR, false);
649         break;
650     case LFUN_LEFTSEL:
651         if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
652             break;
653         moveLeft(bv, false);
654         sel_pos_end = cursor.pos();
655         if (cellstart(cursor.pos())) {
656             if (tabular->column_of_cell(sel_cell_start) >=
657                 tabular->column_of_cell(actcell))
658                 sel_cell_end = actcell;
659             else
660                 sel_cell_end = actcell-1;
661         }
662         UpdateLocal(bv, SELECTION, false);
663         break;
664     case LFUN_LEFT:
665         result = moveLeft(bv);
666         sel_pos_start = sel_pos_end = cursor.pos();
667         sel_cell_start = sel_cell_end = actcell;
668         if (hs)
669             UpdateLocal(bv, CURSOR, false);
670         break;
671     case LFUN_DOWNSEL:
672     {
673         int ocell = actcell;
674         moveDown(bv);
675         sel_pos_end = cursor.pos();
676         if ((ocell == sel_cell_end) ||
677             (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
678             sel_cell_end = tabular->GetCellBelow(sel_cell_end);
679         else
680             sel_cell_end = tabular->GetLastCellBelow(sel_cell_end);
681         UpdateLocal(bv, SELECTION, false);
682     }
683     break;
684     case LFUN_DOWN:
685         result= moveDown(bv);
686         sel_pos_start = sel_pos_end = cursor.pos();
687         sel_cell_start = sel_cell_end = actcell;
688         if (hs)
689             UpdateLocal(bv, CURSOR, false);
690         break;
691     case LFUN_UPSEL:
692     {
693         int ocell = actcell;
694         moveUp(bv);
695         sel_pos_end = cursor.pos();
696         if ((ocell == sel_cell_end) ||
697             (tabular->column_of_cell(ocell)>tabular->column_of_cell(actcell)))
698             sel_cell_end = tabular->GetCellAbove(sel_cell_end);
699         else
700             sel_cell_end = tabular->GetLastCellAbove(sel_cell_end);
701         UpdateLocal(bv, SELECTION, false);
702     }
703     break;
704     case LFUN_UP:
705         result= moveUp(bv);
706         sel_pos_start = sel_pos_end = cursor.pos();
707         sel_cell_start = sel_cell_end = actcell;
708         if (hs)
709             UpdateLocal(bv, CURSOR, false);
710         break;
711     case LFUN_BACKSPACE:
712         break;
713     case LFUN_DELETE:
714         break;
715     case LFUN_HOME:
716         break;
717     case LFUN_END:
718         break;
719     case LFUN_SHIFT_TAB:
720     case LFUN_TAB:
721         if (the_locking_inset) {
722             the_locking_inset->InsetUnlock(bv);
723         }
724         the_locking_inset = 0;
725         if (action == LFUN_TAB)
726             moveNextCell(bv);
727         else
728             movePrevCell(bv);
729         sel_pos_start = sel_pos_end = cursor.pos();
730         sel_cell_start = sel_cell_end = actcell;
731         if (hs)
732             UpdateLocal(bv, CURSOR, false);
733         break;
734     case LFUN_LAYOUT_TABLE:
735     {
736         int flag = (arg == "true");
737         MenuLayoutTabular(flag, this);
738     }
739     break;
740     default:
741         result = UNDISPATCHED;
742         break;
743     }
744     if (result!=FINISHED) {
745         if (!the_locking_inset) {
746 #if 0       
747             if (ocell != actcell)
748                 bview->getOwner()->getPopups().updateFormTabular();
749 #endif
750             ShowInsetCursor(bv);
751         }
752     } else
753         bv->unlockInset(this);
754     return result;
755 }
756
757
758 int InsetTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
759 {
760     return tabular->Latex(buf, os, fragile, fp);
761 }
762
763
764 int InsetTabular::Ascii(Buffer const *, ostream &) const
765 {
766     return 0;
767 }
768
769 int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
770 {
771     return 0;
772 }
773
774
775 int InsetTabular::DocBook(Buffer const *, ostream &) const
776 {
777     return 0;
778 }
779
780
781 void InsetTabular::Validate(LaTeXFeatures & features) const
782 {
783     tabular->Validate(features);
784 }
785
786
787 bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
788                                                  LyXFont const & font,
789                                                  bool reinit) const
790 {
791     int cell = -1;
792     int maxAsc, maxDesc;
793     InsetText * inset;
794     bool changed = false;
795     
796     for(int i = 0; i < tabular->rows(); ++i) {
797         maxAsc = maxDesc = 0;
798         for(int j= 0; j < tabular->columns(); ++j) {
799             if (tabular->IsPartOfMultiColumn(i,j))
800                 continue;
801             ++cell;
802             inset = tabular->GetCellInset(cell);
803             if (!reinit)
804                 inset->update(bv, font, false);
805             maxAsc = max(maxAsc, inset->ascent(bv, font));
806             maxDesc = max(maxDesc, inset->descent(bv, font));
807             changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
808         }
809         changed = tabular->SetAscentOfRow(i, maxAsc + ADD_TO_HEIGHT) || changed;
810         changed = tabular->SetDescentOfRow(i, maxDesc + ADD_TO_HEIGHT) || changed;
811     }
812     return changed;
813 }
814
815
816 void InsetTabular::GetCursorPos(BufferView *, int & x, int & y) const
817 {
818     x = cursor.x() - top_x;
819     y = cursor.y();
820 }
821
822
823 void InsetTabular::ToggleInsetCursor(BufferView * bv)
824 {
825     if (the_locking_inset) {
826         the_locking_inset->ToggleInsetCursor(bv);
827         return;
828     }
829
830     LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
831
832     int asc = lyxfont::maxAscent(font);
833     int desc = lyxfont::maxDescent(font);
834   
835     if (cursor_visible)
836         bv->hideLockedInsetCursor();
837     else
838         bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
839     cursor_visible = !cursor_visible;
840 }
841
842
843 void InsetTabular::ShowInsetCursor(BufferView * bv)
844 {
845     if (!cursor_visible) {
846         LyXFont font; // = GetFont(par, cursor.pos);
847     
848         int asc = lyxfont::maxAscent(font);
849         int desc = lyxfont::maxDescent(font);
850         bv->fitLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
851         bv->showLockedInsetCursor(cursor.x(), cursor.y(), asc, desc);
852         cursor_visible = true;
853     }
854 }
855
856
857 void InsetTabular::HideInsetCursor(BufferView * bv)
858 {
859     if (cursor_visible)
860         ToggleInsetCursor(bv);
861 }
862
863
864 void InsetTabular::setPos(BufferView * bv, int x, int y) const
865 {
866         cursor.y(0);
867         cursor.pos(0);
868         
869         actcell = actrow = actcol = 0;
870     int ly = tabular->GetDescentOfRow(actrow);
871
872     // first search the right row
873     while((ly < y) && (actrow < tabular->rows())) {
874         cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
875             tabular->GetAscentOfRow(actrow+1) +
876             tabular->GetAdditionalHeight(tabular->GetCellNumber(actrow + 1,
877                                                                 actcol)));
878         ++actrow;
879         ly = cursor.y() + tabular->GetDescentOfRow(actrow);
880     }
881     actcell = tabular->GetCellNumber(actrow, actcol);
882
883     // now search the right column
884     int lx = tabular->GetWidthOfColumn(actcell) -
885         tabular->GetAdditionalWidth(actcell);
886     for(; !tabular->IsLastCellInRow(actcell) && (lx < x);
887         ++actcell,lx += tabular->GetWidthOfColumn(actcell) +
888             tabular->GetAdditionalWidth(actcell - 1));
889     cursor.pos(((actcell+1) * 2) - 1);
890     resetPos(bv);
891     if ((lx - (tabular->GetWidthOfColumn(actcell)/2)) < x) {
892         cursor.x(lx + top_x - 2);
893     } else {
894         cursor.pos(cursor.pos() - 1);
895         cursor.x(lx - tabular->GetWidthOfColumn(actcell) + top_x + 2);
896     }
897     resetPos(bv);
898 }
899
900 int InsetTabular::getCellXPos(int cell) const
901 {
902     int c;
903
904     for(c=cell;!tabular->IsFirstCellInRow(c);--c)
905         ;
906     int lx = tabular->GetWidthOfColumn(cell);
907     for(; (c < cell); ++c) {
908         lx += tabular->GetWidthOfColumn(c);
909     }
910     return (lx - tabular->GetWidthOfColumn(cell) + top_x +
911             ADD_TO_TABULAR_WIDTH);
912 }
913
914 void InsetTabular::resetPos(BufferView * bv) const
915 {
916     if (!locked)
917         return;
918     actcol = tabular->column_of_cell(actcell);
919
920     int cell = 0;
921     actrow = 0;
922     cursor.y(0);
923     for(; (cell<actcell) && !tabular->IsLastRow(cell); ++cell) {
924         if (tabular->IsLastCellInRow(cell)) {
925             cursor.y(cursor.y() + tabular->GetDescentOfRow(actrow) +
926                 tabular->GetAscentOfRow(actrow + 1) +
927                 tabular->GetAdditionalHeight(cell + 1));
928             ++actrow;
929         }
930     }
931     cursor.x(getCellXPos(actcell) + 2);
932     if (cursor.pos() % 2) {
933         LyXFont font(LyXFont::ALL_SANE);
934         cursor.x(cursor.x() + tabular->GetCellInset(actcell)->width(bv,font) +
935                 tabular->GetBeginningOfTextInCell(actcell));
936     }
937     if ((!the_locking_inset ||
938          !the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
939         (actcell != oldcell)) {
940         UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
941         oldcell = actcell;
942     }
943 }
944
945
946 UpdatableInset::RESULT InsetTabular::moveRight(BufferView * bv, bool lock)
947 {
948     if (!cellstart(cursor.pos())) {
949         if (tabular->IsLastCell(actcell))
950             return FINISHED;
951         ++actcell;
952         cursor.pos(cursor.pos() + 1);
953     } else if (lock) {
954         if (ActivateCellInset(bv))
955             return DISPATCHED;
956     } else {              // before the inset
957         cursor.pos(cursor.pos() + 1);
958     }
959     resetPos(bv);
960     return DISPATCHED_NOUPDATE;
961 }
962
963
964 UpdatableInset::RESULT InsetTabular::moveLeft(BufferView * bv, bool lock)
965 {
966     if (!cursor.pos()) {
967         if (!actcell)
968             return FINISHED;
969         cursor.pos(2);
970     }
971     cursor.pos(cursor.pos() - 1);
972     if (!cellstart(cursor.pos())) {
973         --actcell;
974     } else if (lock) {       // behind the inset
975         if (ActivateCellInset(bv, 0, 0, 0, true))
976             return DISPATCHED;
977     }
978     resetPos(bv);
979     return DISPATCHED_NOUPDATE;
980 }
981
982
983 UpdatableInset::RESULT InsetTabular::moveUp(BufferView * bv)
984 {
985     int ocell = actcell;
986     actcell = tabular->GetCellAbove(actcell);
987     if (actcell == ocell) // we moved out of the inset
988         return FINISHED;
989     resetPos(bv);
990     return DISPATCHED_NOUPDATE;
991 }
992
993
994 UpdatableInset::RESULT InsetTabular::moveDown(BufferView * bv)
995 {
996     int ocell = actcell;
997     actcell = tabular->GetCellBelow(actcell);
998     if (actcell == ocell) // we moved out of the inset
999         return FINISHED;
1000     resetPos(bv);
1001     return DISPATCHED_NOUPDATE;
1002 }
1003
1004
1005 bool InsetTabular::moveNextCell(BufferView * bv)
1006 {
1007     if (tabular->IsLastCell(actcell))
1008         return false;
1009     ++actcell;
1010     cursor.pos(cursor.pos() + 1);
1011     if (!cellstart(cursor.pos()))
1012         cursor.pos(cursor.pos() + 1);
1013     resetPos(bv);
1014     return true;
1015 }
1016
1017
1018 bool InsetTabular::movePrevCell(BufferView * bv)
1019 {
1020     if (!actcell) // first cell
1021         return false;
1022     --actcell;
1023     cursor.pos(cursor.pos() - 1);
1024     if (cellstart(cursor.pos()))
1025         cursor.pos(cursor.pos() - 1);
1026     resetPos(bv);
1027     return true;
1028 }
1029
1030
1031 bool InsetTabular::Delete()
1032 {
1033     return true;
1034 }
1035
1036
1037 void InsetTabular::SetFont(BufferView * bv, LyXFont const & font, bool tall)
1038 {
1039     if (the_locking_inset)
1040         the_locking_inset->SetFont(bv, font, tall);
1041 }
1042
1043
1044 void InsetTabular::TabularFeatures(BufferView * bv, int feature, string val)
1045 {
1046     int
1047         i, j,
1048         sel_col_start,
1049         sel_col_end,
1050         sel_row_start,
1051         sel_row_end,
1052         setLines = 0,
1053         setAlign = LYX_ALIGN_LEFT,
1054         lineSet;
1055     bool
1056         what;
1057
1058     switch (feature) {
1059       case LyXTabular::ALIGN_LEFT:
1060           setAlign=LYX_ALIGN_LEFT;
1061           break;
1062       case LyXTabular::ALIGN_RIGHT:
1063           setAlign=LYX_ALIGN_RIGHT;
1064           break;
1065       case LyXTabular::ALIGN_CENTER:
1066           setAlign=LYX_ALIGN_CENTER;
1067           break;
1068       default:
1069           break;
1070     }
1071     if (hasSelection()) {
1072         int tmp;
1073         sel_col_start = tabular->column_of_cell(sel_cell_start);
1074         sel_col_end = tabular->column_of_cell(sel_cell_end);
1075         if (sel_col_start > sel_col_end) {
1076             sel_col_end = sel_col_start;
1077             sel_col_start = tabular->column_of_cell(sel_cell_end);
1078         } else {
1079             sel_col_end = tabular->right_column_of_cell(sel_cell_end);
1080         }
1081         
1082         sel_row_start = tabular->row_of_cell(sel_cell_start);
1083         sel_row_end = tabular->row_of_cell(sel_cell_end);
1084         if (sel_row_start > sel_row_end) {
1085             tmp = sel_row_start;
1086             sel_row_start = sel_row_end;
1087             sel_row_end = tmp;
1088         }
1089     } else {
1090         sel_col_start = sel_col_end = tabular->column_of_cell(actcell);
1091         sel_row_start = sel_row_end = tabular->row_of_cell(actcell);
1092     }
1093     bv->text->SetUndo(bv->buffer(), Undo::FINISH, 
1094               bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->previous,
1095               bv->text->cursor.par()->ParFromPos(bv->text->cursor.pos())->next);
1096
1097     int row = tabular->row_of_cell(actcell);
1098     int column = tabular->column_of_cell(actcell);
1099
1100     switch (feature) {
1101     case LyXTabular::SET_PWIDTH:
1102     {
1103         bool update = (tabular->GetPWidth(actcell) != val);
1104         tabular->SetPWidth(actcell,val);
1105         if (update) {
1106             for (int i=0; i < tabular->rows(); ++i) {
1107                 tabular->GetCellInset(tabular->GetCellNumber(i, column))->
1108                     deleteLyXText(bv);
1109             }
1110             UpdateLocal(bv, INIT, true);
1111         }
1112     }
1113     break;
1114     case LyXTabular::SET_SPECIAL_COLUMN:
1115     case LyXTabular::SET_SPECIAL_MULTI:
1116         tabular->SetAlignSpecial(actcell,val,feature);
1117         break;
1118     case LyXTabular::APPEND_ROW:
1119         // append the row into the tabular
1120         UnlockInsetInInset(bv, the_locking_inset);
1121         tabular->AppendRow(actcell);
1122         UpdateLocal(bv, INIT, true);
1123         break;
1124     case LyXTabular::APPEND_COLUMN:
1125         // append the column into the tabular
1126         tabular->AppendColumn(actcell);
1127         actcell = tabular->GetCellNumber(row, column);
1128         UpdateLocal(bv, INIT, true);
1129         break;
1130     case LyXTabular::DELETE_ROW:
1131         tabular->DeleteRow(tabular->row_of_cell(actcell));
1132         if ((row+1) > tabular->rows())
1133             --row;
1134         actcell = tabular->GetCellNumber(row, column);
1135         UpdateLocal(bv, INIT, true);
1136         break;
1137     case LyXTabular::DELETE_COLUMN:
1138         tabular->DeleteColumn(tabular->column_of_cell(actcell));
1139         if ((column+1) > tabular->columns())
1140             --column;
1141         actcell = tabular->GetCellNumber(row, column);
1142         UpdateLocal(bv, INIT, true);
1143         break;
1144     case LyXTabular::TOGGLE_LINE_TOP:
1145         lineSet = !tabular->TopLine(actcell);
1146         for(i=sel_row_start; i<=sel_row_end; ++i)
1147             for(j=sel_col_start; j<=sel_col_end; ++j)
1148                 tabular->SetTopLine(tabular->GetCellNumber(i,j),lineSet);
1149         UpdateLocal(bv, INIT, true);
1150         break;
1151     
1152     case LyXTabular::TOGGLE_LINE_BOTTOM:
1153         lineSet = !tabular->BottomLine(actcell); 
1154         for(i=sel_row_start; i<=sel_row_end; ++i)
1155             for(j=sel_col_start; j<=sel_col_end; ++j)
1156                 tabular->SetBottomLine(tabular->GetCellNumber(i,j),lineSet);
1157         UpdateLocal(bv, INIT, true);
1158         break;
1159                 
1160     case LyXTabular::TOGGLE_LINE_LEFT:
1161         lineSet = !tabular->LeftLine(actcell);
1162         for(i=sel_row_start; i<=sel_row_end; ++i)
1163             for(j=sel_col_start; j<=sel_col_end; ++j)
1164                 tabular->SetLeftLine(tabular->GetCellNumber(i,j),lineSet);
1165         UpdateLocal(bv, INIT, true);
1166         break;
1167
1168     case LyXTabular::TOGGLE_LINE_RIGHT:
1169         lineSet = !tabular->RightLine(actcell);
1170         for(i=sel_row_start; i<=sel_row_end; ++i)
1171             for(j=sel_col_start; j<=sel_col_end; ++j)
1172                 tabular->SetRightLine(tabular->GetCellNumber(i,j),lineSet);
1173         UpdateLocal(bv, INIT, true);
1174         break;
1175     case LyXTabular::ALIGN_LEFT:
1176     case LyXTabular::ALIGN_RIGHT:
1177     case LyXTabular::ALIGN_CENTER:
1178         for(i=sel_row_start; i<=sel_row_end; ++i)
1179             for(j=sel_col_start; j<=sel_col_end; ++j)
1180                 tabular->SetAlignment(tabular->GetCellNumber(i,j),setAlign);
1181         if (hasSelection())
1182             UpdateLocal(bv, INIT, true);
1183         else
1184             UpdateLocal(bv, CELL, true);
1185         break;
1186     case LyXTabular::MULTICOLUMN:
1187     {
1188         if (sel_row_start != sel_row_end) {
1189             WriteAlert(_("Impossible Operation!"), 
1190                        _("Multicolumns can only be horizontally."), 
1191                        _("Sorry."));
1192             return;
1193         }
1194         // just multicol for one Single Cell
1195         if (!hasSelection()) {
1196             // check wether we are completly in a multicol
1197             if (tabular->IsMultiColumn(actcell)) {
1198                 tabular->UnsetMultiColumn(actcell);
1199                 UpdateLocal(bv, INIT, true);
1200             } else {
1201                 tabular->SetMultiColumn(actcell, 1);
1202                 UpdateLocal(bv, CELL, true);
1203             }
1204             return;
1205         }
1206         // we have a selection so this means we just add all this
1207         // cells to form a multicolumn cell
1208         int
1209             s_start, s_end;
1210
1211         if (sel_cell_start > sel_cell_end) {
1212             s_start = sel_cell_end;
1213             s_end = sel_cell_start;
1214         } else {
1215             s_start = sel_cell_start;
1216             s_end = sel_cell_end;
1217         }
1218         tabular->SetMultiColumn(s_start, s_end - s_start + 1);
1219         actcell = s_start;
1220         cursor.pos(0);
1221         sel_cell_end = sel_cell_start;
1222         sel_pos_end = sel_pos_start;
1223         UpdateLocal(bv, INIT, true);
1224         break;
1225     }
1226     case LyXTabular::SET_ALL_LINES:
1227         setLines = 1;
1228     case LyXTabular::UNSET_ALL_LINES:
1229         for(i=sel_row_start; i<=sel_row_end; ++i)
1230             for(j=sel_col_start; j<=sel_col_end; ++j)
1231                 tabular->SetAllLines(tabular->GetCellNumber(i,j), setLines);
1232         UpdateLocal(bv, INIT, true);
1233         break;
1234     case LyXTabular::SET_LONGTABULAR:
1235         tabular->SetLongTabular(true);
1236         UpdateLocal(bv, INIT, true); // because this toggles displayed
1237         break;
1238     case LyXTabular::UNSET_LONGTABULAR:
1239         tabular->SetLongTabular(false);
1240         UpdateLocal(bv, INIT, true); // because this toggles displayed
1241         break;
1242     case LyXTabular::SET_ROTATE_TABULAR:
1243         tabular->SetRotateTabular(true);
1244         break;
1245     case LyXTabular::UNSET_ROTATE_TABULAR:
1246         tabular->SetRotateTabular(false);
1247         break;
1248     case LyXTabular::SET_ROTATE_CELL:
1249         for(i=sel_row_start; i<=sel_row_end; ++i)
1250             for(j=sel_col_start; j<=sel_col_end; ++j)
1251                 tabular->SetRotateCell(tabular->GetCellNumber(i,j),true);
1252         break;
1253     case LyXTabular::UNSET_ROTATE_CELL:
1254         for(i=sel_row_start; i<=sel_row_end; ++i)
1255             for(j=sel_col_start; j<=sel_col_end; ++j)
1256                 tabular->SetRotateCell(tabular->GetCellNumber(i,j),false);
1257         break;
1258     case LyXTabular::SET_LINEBREAKS:
1259         what = !tabular->GetLinebreaks(actcell);
1260         for(i=sel_row_start; i<=sel_row_end; ++i)
1261             for(j=sel_col_start; j<=sel_col_end; ++j)
1262                 tabular->SetLinebreaks(tabular->GetCellNumber(i,j),what);
1263         break;
1264     case LyXTabular::SET_LTFIRSTHEAD:
1265         tabular->SetLTHead(actcell,true);
1266         break;
1267     case LyXTabular::SET_LTHEAD:
1268         tabular->SetLTHead(actcell,false);
1269         break;
1270     case LyXTabular::SET_LTFOOT:
1271         tabular->SetLTFoot(actcell,false);
1272         break;
1273     case LyXTabular::SET_LTLASTFOOT:
1274         tabular->SetLTFoot(actcell,true);
1275         break;
1276     case LyXTabular::SET_LTNEWPAGE:
1277         what = !tabular->GetLTNewPage(actcell);
1278         tabular->SetLTNewPage(actcell,what);
1279         break;
1280     }
1281 }
1282
1283 bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
1284                                      bool behind)
1285 {
1286     // the cursor.pos has to be before the inset so if it isn't now just
1287     // reset the curor pos first!
1288     if (cursor.pos() % 2) { // behind the inset
1289         cursor.pos(cursor.pos() - 1);
1290         resetPos(bv);
1291     }
1292     UpdatableInset * inset =
1293         static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
1294     LyXFont font(LyXFont::ALL_SANE);
1295     if (behind) {
1296         x = inset->x() + inset->width(bv, font);
1297         y = inset->descent(bv, font);
1298     }
1299     inset_x = cursor.x() - top_x + tabular->GetBeginningOfTextInCell(actcell);
1300     inset_y = cursor.y();
1301     inset->Edit(bv, x - inset_x, y - inset_y, button);
1302     if (!the_locking_inset)
1303         return false;
1304     UpdateLocal(bv, CELL, false);
1305     return true;
1306 }
1307
1308 bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
1309 {
1310     InsetText * inset = tabular->GetCellInset(actcell);
1311     int x1 = x + top_x;
1312
1313     if (cursor.pos() % 2) { // behind the inset
1314         return (((x + top_x) < cursor.x()) &&
1315                 ((x + top_x) > (cursor.x() - inset->width(bv,
1316                                                       LyXFont(LyXFont::ALL_SANE)))));
1317     } else {
1318         int x2 = cursor.x() + tabular->GetBeginningOfTextInCell(actcell);
1319         return ((x1 > x2) &&
1320                 (x1 < (x2 + inset->width(bv, LyXFont(LyXFont::ALL_SANE)))));
1321     }
1322 }
1323
1324 // This returns paperWidth() if the cell-width is unlimited or the width
1325 // in pixels if we have a pwidth for this cell.
1326 int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
1327 {
1328     string s = tabular->GetPWidth(cell);
1329
1330     if (s.empty())
1331         return -1;
1332     return VSpace(s).inPixels( 0, 0);
1333 }
1334
1335 int InsetTabular::getMaxWidth(Painter & pain,
1336                               UpdatableInset const * inset) const
1337 {
1338     int cell;
1339     int n = tabular->GetNumberOfCells();
1340     for(cell=0; cell < n; ++cell) {
1341         if (tabular->GetCellInset(cell) == inset)
1342             break;
1343     }
1344     if (cell >= n)
1345         return -1;
1346     int w = GetMaxWidthOfCell(pain, cell);
1347     // this because text insets remove the xpos from the maxwidth because
1348     // otherwise the would not break good!!!
1349 //    w += getCellXPos(cell) + tabular->GetBeginningOfTextInCell(cell);
1350 //    w += inset->x();
1351     return w;
1352 }
1353
1354 void InsetTabular::recomputeTextInsets(BufferView * bv, const LyXFont & font) const
1355 {
1356     InsetText * inset;
1357     int cell;
1358
1359 //    cx = top_x;
1360     for(int j= 0; j < tabular->columns(); ++j) {
1361         for(int i = 0; i < tabular->rows(); ++i) {
1362             if (tabular->IsPartOfMultiColumn(i,j))
1363                 continue;
1364             cell = tabular->GetCellNumber(i,j);
1365             inset = tabular->GetCellInset(cell);
1366             inset->update(bv, font);
1367             tabular->SetWidthOfCell(cell, inset->width(bv, font));
1368         }
1369 //      cell = tabular->GetCellNumber(0, j);
1370 //      cx += tabular->GetWidthOfColumn(cell);
1371     }
1372 }