- LyXFont labelfont;
- LyXParagraph * newpar;
- Row dummyrow;
- LyXLayout const & layout = textclasslist.Style(parameters->textclass,
- row->par->GetLayout());
-
- string parindent = layout.parindent;
-
- /* table stuff -- begin*/
- if (row->par->table)
- parindent.clear();
- /* table stuff -- end*/
-
- int x = LYX_PAPER_MARGIN;
-
- x += textclasslist.TextClass(parameters->textclass).
- defaultfont().signedStringWidth(textclasslist.TextClass(parameters->textclass).leftmargin());
-
- if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(LyXFont::SIZE_SMALL);
- x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
- }
-
- /* this is the way, LyX handles the LaTeX-Environments.
- * I have had this idea very late, so it seems to be a
- * later added hack and this is true */
- if (!row->par->GetDepth()) {
- if (!row->par->GetLayout()) {
- /* find the previous same level paragraph */
- if (row->par->FirstPhysicalPar()->Previous()) {
- newpar = row->par->DepthHook(row->par->GetDepth());
- if (newpar && textclasslist.Style(parameters->textclass,
- newpar->GetLayout()).nextnoindent)
- parindent.clear();
- }
- }
- }
- else {
- /* find the next level paragraph */
-
- newpar = row->par->DepthHook(row->par->GetDepth()-1);
-
- /* make a corresponding row. Needed to call LeftMargin() */
-
- /* check wether it is a sufficent paragraph */
- if (newpar && newpar->footnoteflag == row->par->footnoteflag
- && textclasslist.Style(parameters->textclass,
- newpar->GetLayout()).isEnvironment()) {
- dummyrow.par = newpar;
- dummyrow.pos = newpar->Last();
- x = LeftMargin(&dummyrow);
- }
- else {
- /* this is no longer an error, because this function is used
- * to clear impossible depths after changing a layout. Since there
- * is always a redo, LeftMargin() is always called */
-
- /* printf("LYX_ERROR (text, LeftMargin()) impossible depth \n");*/
- row->par->FirstPhysicalPar()->depth = 0;
- }
-
- if (newpar && !row->par->GetLayout()) {
- if (newpar->FirstPhysicalPar()->noindent)
- parindent.clear();
- else
- parindent = textclasslist.Style(parameters->textclass,
- newpar->GetLayout()).parindent;
- }
-
- }
-
- labelfont = GetFont(row->par, -2);
- switch (layout.margintype) {
- case MARGIN_DYNAMIC:
- if (!layout.leftmargin.empty()) {
- x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin);
- }
- if (!row->par->GetLabestring().empty()) {
- x += labelfont.signedStringWidth(layout.labelindent);
- x += labelfont.stringWidth(row->par->GetLabestring());
- x += labelfont.stringWidth(layout.labelsep);
- }
- break;
- case MARGIN_MANUAL:
- x += labelfont.signedStringWidth(layout.labelindent);
- if (row->pos >= BeginningOfMainBody(row->par)) {
- if (!row->par->GetLabelWidthString().empty()) {
- x += labelfont.stringWidth(row->par->GetLabelWidthString());
- x += labelfont.stringWidth(layout.labelsep);
- }
- }
- break;
- case MARGIN_STATIC:
- x += ( textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin) * 4
- / (row->par->GetDepth() + 4));
- break;
- case MARGIN_FIRST_DYNAMIC:
- if (layout.labeltype == LABEL_MANUAL) {
- if (row->pos >= BeginningOfMainBody(row->par)) {
- x += labelfont.signedStringWidth(layout.leftmargin);
- } else {
- x += labelfont.signedStringWidth(layout.labelindent);
- }
- } else {
- if (row->pos
- // Special case to fix problems with theorems (JMarc)
- || (layout.labeltype == LABEL_STATIC
- && layout.latextype == LATEX_ENVIRONMENT
- && ! row->par->IsFirstInSequence())) {
- x += labelfont.signedStringWidth(layout.leftmargin);
- } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
- && layout.labeltype != LABEL_BIBLIO
- && layout.labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) {
- x += labelfont.signedStringWidth(layout.labelindent);
- x += labelfont.stringWidth(layout.labelsep);
- x += labelfont.stringWidth(row->par->GetLabestring());
- }
- }
- break;
-
- case MARGIN_RIGHT_ADDRESS_BOX:
- {
- /* ok, a terrible hack. The left margin depends on the widest row
- * in this paragraph. Do not care about footnotes, they are *NOT*
- * allowed in the LaTeX realisation of this layout. */
-
- /* find the first row of this paragraph */
- Row * tmprow = row;
- while (tmprow->previous && tmprow->previous->par == row->par)
- tmprow = tmprow->previous;
-
- int minfill = tmprow->fill;
- while (tmprow-> next && tmprow->next->par == row->par) {
- tmprow = tmprow->next;
- if (tmprow->fill < minfill)
- minfill = tmprow->fill;
- }
-
- x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin);
- x += minfill;
- }
- break;
- }
- if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
- if (!row->par->pextra_widthp.empty()) {
- x += paperwidth * atoi(row->par->pextra_widthp.c_str()) / 100;
- } else if (!row->par->pextra_width.empty()) {
- int xx = VSpace(row->par->pextra_width).inPixels();
-
- if (xx > paperwidth)
- xx = paperwidth * 80 / 100;
- x += xx;
- } else { // should not happen
- LyXFont font(LyXFont::ALL_SANE);
- x += font.stringWidth("XXXXXX");
- }
- }
-
- int align;
- if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
- align = layout.align;
- else
- align = row->par->FirstPhysicalPar()->align;
-
- /* set the correct parindent */
- if (row->pos == 0) {
- if ((layout.labeltype == LABEL_NO_LABEL
- || layout.labeltype == LABEL_TOP_ENVIRONMENT
- || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
- || (layout.labeltype == LABEL_STATIC
- && layout.latextype == LATEX_ENVIRONMENT
- && ! row->par->IsFirstInSequence()))
- && row->par == row->par->FirstPhysicalPar()
- && align == LYX_ALIGN_BLOCK
- && !row->par->noindent
- && (row->par->layout ||
- parameters->paragraph_separation == BufferParams::PARSEP_INDENT))
- x += textclasslist.TextClass(parameters->textclass).defaultfont().stringWidth(parindent);
- else
- if (layout.labeltype == LABEL_BIBLIO) { // ale970405 Right width for bibitems
- x += bibitemMaxWidth(textclasslist.TextClass(parameters->textclass).defaultfont());
- }
- }
-
- return x;
+ LyXLayout const & layout = textclasslist.Style(parameters->textclass,
+ row->par->GetLayout());
+
+ string parindent = layout.parindent;
+
+ /* table stuff -- begin */
+ if (row->par->table)
+ parindent.clear();
+ /* table stuff -- end */
+
+ int x = LYX_PAPER_MARGIN;
+
+ x += textclasslist.TextClass(parameters->textclass)
+ .defaultfont()
+ .signedStringWidth(textclasslist
+ .TextClass(parameters->textclass)
+ .leftmargin());
+
+ if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
+ LyXFont font(LyXFont::ALL_SANE);
+ font.setSize(LyXFont::SIZE_SMALL);
+ x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2;
+ }
+
+ // this is the way, LyX handles the LaTeX-Environments.
+ // I have had this idea very late, so it seems to be a
+ // later added hack and this is true
+ if (!row->par->GetDepth()) {
+ if (!row->par->GetLayout()) {
+ // find the previous same level paragraph
+ if (row->par->FirstPhysicalPar()->Previous()) {
+ LyXParagraph * newpar = row->par
+ ->DepthHook(row->par->GetDepth());
+ if (newpar &&
+ textclasslist.Style(parameters->textclass,
+ newpar->GetLayout())
+ .nextnoindent)
+ parindent.clear();
+ }
+ }
+ } else {
+ // find the next level paragraph
+
+ LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1);
+
+ // make a corresponding row. Needed to call LeftMargin()
+
+ // check wether it is a sufficent paragraph
+ if (newpar && newpar->footnoteflag == row->par->footnoteflag
+ && textclasslist
+ .Style(parameters->textclass,
+ newpar->GetLayout()).isEnvironment()) {
+ Row dummyrow;
+ dummyrow.par = newpar;
+ dummyrow.pos = newpar->Last();
+ x = LeftMargin(&dummyrow);
+ } else {
+ // this is no longer an error, because this function
+ // is used to clear impossible depths after changing
+ // a layout. Since there is always a redo,
+ // LeftMargin() is always called
+ row->par->FirstPhysicalPar()->depth = 0;
+ }
+
+ if (newpar && !row->par->GetLayout()) {
+ if (newpar->FirstPhysicalPar()->noindent)
+ parindent.clear();
+ else
+ parindent = textclasslist
+ .Style(parameters->textclass,
+ newpar->GetLayout()).parindent;
+ }
+
+ }
+
+ LyXFont labelfont = GetFont(row->par, -2);
+ switch (layout.margintype) {
+ case MARGIN_DYNAMIC:
+ if (!layout.leftmargin.empty()) {
+ x += textclasslist
+ .TextClass(parameters->textclass)
+ .defaultfont()
+ .signedStringWidth(layout.leftmargin);
+ }
+ if (!row->par->GetLabestring().empty()) {
+ x += labelfont.signedStringWidth(layout.labelindent);
+ x += labelfont.stringWidth(row->par->GetLabestring());
+ x += labelfont.stringWidth(layout.labelsep);
+ }
+ break;
+ case MARGIN_MANUAL:
+ x += labelfont.signedStringWidth(layout.labelindent);
+ if (row->pos >= BeginningOfMainBody(row->par)) {
+ if (!row->par->GetLabelWidthString().empty()) {
+ x += labelfont
+ .stringWidth(row->par
+ ->GetLabelWidthString());
+ x += labelfont.stringWidth(layout.labelsep);
+ }
+ }
+ break;
+ case MARGIN_STATIC:
+ x += textclasslist.TextClass(parameters->textclass)
+ .defaultfont().signedStringWidth(layout.leftmargin) * 4
+ / (row->par->GetDepth() + 4);
+ break;
+ case MARGIN_FIRST_DYNAMIC:
+ if (layout.labeltype == LABEL_MANUAL) {
+ if (row->pos >= BeginningOfMainBody(row->par)) {
+ x += labelfont
+ .signedStringWidth(layout.leftmargin);
+ } else {
+ x += labelfont
+ .signedStringWidth(layout.labelindent);
+ }
+ } else if (row->pos
+ // Special case to fix problems with
+ // theorems (JMarc)
+ || (layout.labeltype == LABEL_STATIC
+ && layout.latextype == LATEX_ENVIRONMENT
+ && ! row->par->IsFirstInSequence())) {
+ x += labelfont.signedStringWidth(layout.leftmargin);
+ } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT
+ && layout.labeltype != LABEL_BIBLIO
+ && layout.labeltype !=
+ LABEL_CENTERED_TOP_ENVIRONMENT) {
+ x += labelfont.signedStringWidth(layout.labelindent);
+ x += labelfont.stringWidth(layout.labelsep);
+ x += labelfont.stringWidth(row->par->GetLabestring());
+ }
+ break;
+
+ case MARGIN_RIGHT_ADDRESS_BOX:
+ {
+ // ok, a terrible hack. The left margin depends on the widest
+ // row in this paragraph. Do not care about footnotes, they
+ // are *NOT* allowed in the LaTeX realisation of this layout.
+
+ // find the first row of this paragraph
+ Row const * tmprow = row;
+ while (tmprow->previous && tmprow->previous->par == row->par)
+ tmprow = tmprow->previous;
+
+ int minfill = tmprow->fill;
+ while (tmprow->next && tmprow->next->par == row->par) {
+ tmprow = tmprow->next;
+ if (tmprow->fill < minfill)
+ minfill = tmprow->fill;
+ }
+
+ x += textclasslist.TextClass(parameters->textclass)
+ .defaultfont().signedStringWidth(layout.leftmargin);
+ x += minfill;
+ }
+ break;
+ }
+ if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) {
+ if (!row->par->pextra_widthp.empty()) {
+ x += paperwidth *
+ atoi(row->par->pextra_widthp.c_str()) / 100;
+ } else if (!row->par->pextra_width.empty()) {
+ int xx = VSpace(row->par->pextra_width).inPixels(owner_);
+
+ if (xx > paperwidth)
+ xx = paperwidth * 80 / 100;
+ x += xx;
+ } else { // should not happen
+ LyXFont font(LyXFont::ALL_SANE);
+ x += font.stringWidth("XXXXXX");
+ }
+ }
+
+ int align; // wrong type
+ if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT)
+ align = layout.align;
+ else
+ align = row->par->FirstPhysicalPar()->align;
+
+ // set the correct parindent
+ if (row->pos == 0) {
+ if ((layout.labeltype == LABEL_NO_LABEL
+ || layout.labeltype == LABEL_TOP_ENVIRONMENT
+ || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
+ || (layout.labeltype == LABEL_STATIC
+ && layout.latextype == LATEX_ENVIRONMENT
+ && ! row->par->IsFirstInSequence()))
+ && row->par == row->par->FirstPhysicalPar()
+ && align == LYX_ALIGN_BLOCK
+ && !row->par->noindent
+ && (row->par->layout ||
+ parameters->paragraph_separation ==
+ BufferParams::PARSEP_INDENT))
+ x += textclasslist.TextClass(parameters->textclass)
+ .defaultfont().signedStringWidth(parindent);
+ else if (layout.labeltype == LABEL_BIBLIO) {
+ // ale970405 Right width for bibitems
+ x += bibitemMaxWidth(owner_->painter(),
+ textclasslist
+ .TextClass(parameters
+ ->textclass)
+ .defaultfont());
+ }
+ }
+ return x;