]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
InsetTabular.cpp: output the caption for docbook
[lyx.git] / src / insets / InsetTabular.cpp
index 3afcc4154995626bc51b1407a72f0592de86330f..daf4a3634b73d9777087592c3becf31e2fc77eb2 100644 (file)
@@ -1750,8 +1750,9 @@ Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
                setBottomLine(i, false);
                setLeftLine(i, false);
                setRightLine(i, false);
-               // FIXME: when a row is set as caption, then also insert a caption
-               // dispatch(FuncRequest(LFUN_CAPTION_INSERT));
+               // When a row is set as caption, then also insert a caption. Otherwise
+               // the LaTeX output is broken, when the user don't add a caption.
+               dispatch(FuncRequest(LFUN_CAPTION_INSERT));
        } else {
                unsetMultiColumn(i);
                // FIXME: when unsetting a caption row, also all existing captions
@@ -2088,44 +2089,55 @@ int Tabular::TeXLongtableHeaderFooter(odocstream & os,
                return 0;
 
        int ret = 0;
-       // output header info
-       if (haveLTHead()) {
-               if (endhead.topDL) {
+       // caption handling
+       // the caption must be output befrore the headers
+       if (haveLTCaption()) {
+               for (row_type i = 0; i < row_info.size(); ++i) {
+                       if (row_info[i].caption) {
+                               ret += TeXRow(os, i, runparams);
+                       }
+               }
+       }
+       // output first header info
+       // first header must be output before the header, otherwise the
+       // correct caption placement becomes really wierd
+       if (haveLTFirstHead()) {
+               if (endfirsthead.topDL) {
                        os << "\\hline\n";
                        ++ret;
                }
                for (row_type i = 0; i < row_info.size(); ++i) {
-                       if (row_info[i].endhead) {
+                       if (row_info[i].endfirsthead) {
                                ret += TeXRow(os, i, runparams);
                        }
                }
-               if (endhead.bottomDL) {
+               if (endfirsthead.bottomDL) {
                        os << "\\hline\n";
                        ++ret;
                }
-               os << "\\endhead\n";
+               os << "\\endfirsthead\n";
                ++ret;
-               if (endfirsthead.empty) {
+       }
+       // output header info
+       if (haveLTHead()) {
+               if (!haveLTFirstHead()) {
                        os << "\\endfirsthead\n";
                        ++ret;
                }
-       }
-       // output firstheader info
-       if (haveLTFirstHead()) {
-               if (endfirsthead.topDL) {
+               if (endhead.topDL) {
                        os << "\\hline\n";
                        ++ret;
                }
                for (row_type i = 0; i < row_info.size(); ++i) {
-                       if (row_info[i].endfirsthead) {
+                       if (row_info[i].endhead) {
                                ret += TeXRow(os, i, runparams);
                        }
                }
-               if (endfirsthead.bottomDL) {
+               if (endhead.bottomDL) {
                        os << "\\hline\n";
                        ++ret;
                }
-               os << "\\endfirsthead\n";
+               os << "\\endhead\n";
                ++ret;
        }
        // output footer info
@@ -2145,7 +2157,7 @@ int Tabular::TeXLongtableHeaderFooter(odocstream & os,
                }
                os << "\\endfoot\n";
                ++ret;
-               if (endlastfoot.empty) {
+               if (!haveLTLastFoot()) {
                        os << "\\endlastfoot\n";
                        ++ret;
                }
@@ -2176,8 +2188,9 @@ bool Tabular::isValidRow(row_type row) const
 {
        if (!is_long_tabular)
                return true;
-       return !row_info[row].endhead && !row_info[row].endfirsthead &&
-                       !row_info[row].endfoot && !row_info[row].endlastfoot;
+       return !row_info[row].endhead && !row_info[row].endfirsthead
+               && !row_info[row].endfoot && !row_info[row].endlastfoot
+               && !row_info[row].caption;
 }
 
 
@@ -2501,11 +2514,12 @@ int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
        //+---------------------------------------------------------------------
 
        // output header info
-       if (haveLTHead() || haveLTFirstHead()) {
+       if (haveLTHead() || haveLTFirstHead()|| haveLTCaption()) {
                os << "<thead>\n";
                ++ret;
                for (row_type i = 0; i < row_info.size(); ++i) {
-                       if (row_info[i].endhead || row_info[i].endfirsthead) {
+                       if (row_info[i].endhead || row_info[i].endfirsthead
+                               || row_info[i].caption) {
                                ret += docbookRow(os, i, runparams);
                        }
                }
@@ -3899,22 +3913,19 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
                        break;
 
-               // when a header/footer/caption is set, no other row can be the same
-               // furthermore, every row can only be one thing:
-               //              either a footer or header or caption
+               // every row can only be one thing:
+               // either a footer or header or caption
                case Tabular::SET_LTFIRSTHEAD:                  
                        status.setEnabled(sel_row_start == sel_row_end
                                && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
-                               && !tabular.ltCaption(sel_row_start)
-                               && (!tabular.haveLTFirstHead()
-                               || tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)));
-                       status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
+                               && !tabular.ltCaption(sel_row_start));
+                       status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
                        break;
 
                case Tabular::UNSET_LTFIRSTHEAD:
-                       status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
+                       status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
                        break;
 
                case Tabular::SET_LTHEAD:
@@ -3922,9 +3933,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                                && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
-                               && !tabular.ltCaption(sel_row_start)
-                               && (!tabular.haveLTHead()
-                               || tabular.getRowOfLTHead(sel_row_start, dummyltt)));
+                               && !tabular.ltCaption(sel_row_start));
                        status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
                        break;
 
@@ -3937,9 +3946,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                                && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
-                               && !tabular.ltCaption(sel_row_start)
-                               && (!tabular.haveLTFoot()
-                               || tabular.getRowOfLTFoot(sel_row_start, dummyltt)));
+                               && !tabular.ltCaption(sel_row_start));
                        status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
                        break;
 
@@ -3952,14 +3959,12 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                                && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
-                               && !tabular.ltCaption(sel_row_start)
-                               && (!tabular.haveLTLastFoot()
-                               || tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)));
-                       status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
+                               && !tabular.ltCaption(sel_row_start));
+                       status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
                        break;
 
                case Tabular::UNSET_LTLASTFOOT:
-                       status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
+                       status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
                        break;
 
                case Tabular::SET_LTNEWPAGE:
@@ -3971,11 +3976,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                                && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
                                && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
-                               && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
-                               // Only the first row can be the caption.
-                               && sel_row_start == 0
-                               && (!tabular.haveLTCaption()
-                               || tabular.ltCaption(sel_row_start)));
+                               && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
                        status.setOnOff(tabular.ltCaption(sel_row_start));
                        break;