+2000-07-18 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * src/insets/lyxinset.h: add caption code
+
+ * src/insets/insetfloat.C (type): new method
+
+ * src/insets/insetcaption.C (Write): new method
+ (Read): new method
+ (LyxCode): new method
+
+ * src/text2.C (SetCounter): revert Jürgens code, but use his idea
+ to get it right together with using the FloatList.
+
+ * src/commandtags.h: add LFUN_INSET_CAPTION
+ * src/lyxfunc.C (Dispatch): handle it
+
+ * src/buffer.C (parseSingleLyXformat2Token): add code to read a
+ caption inset.
+
+ * src/Variables.[Ch]: make expand take a const reference, remove
+ the destructor, some whitespace changes.
+
+ * src/LyXAction.C (init): add caption-inset-insert
+
+ * src/FloatList.C (FloatList): update the default floats a bit.
+
2000-07-17 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/Variables.[Ch]: new files. Intended to be used for language
// Insert the latex builtin float-types
Floating table;
table.type = "table";
- table.placement = "";
+ table.placement = "htbp";
table.ext = "lot";
table.within = "";
- table.style = "";
- table.name = "";
+ table.style = "plain";
+ table.name = "Table";
table.builtin = true;
list[table.type] = table;
Floating figure;
figure.type = "figure";
- figure.placement = "";
+ figure.placement = "htbp";
figure.ext = "lof";
figure.within = "";
- figure.style = "";
- figure.name = "";
+ figure.style = "plain";
+ figure.name = "Figure";
figure.builtin = true;
list[figure.type] = figure;
// And we add algorithm too since LyX has
{ LFUN_INSET_FLOAT, "float-inset-insert", "", Noop },
{ LFUN_INSET_LIST, "list-inset-insert", "", Noop },
{ LFUN_INSET_THEOREM, "theorem-inset-insert", "", Noop },
+ { LFUN_INSET_CAPTION, "caption-inset-insert", "", Noop },
{ LFUN_NOACTION, "", "", Noop }
};
#include "Variables.h"
#include "support/LRegex.h"
-void Variables::set(string const &var, string const &val)
+
+void Variables::set(string const & var, string const & val)
{
Vars::const_iterator cit = vars_.find(var);
if (cit != vars_.end())
}
-string Variables::get(string const &var) const
+string Variables::get(string const & var) const
{
Vars::const_iterator cit = vars_.find(var);
if (cit != vars_.end())
return string();
}
+
bool Variables::isset(string const & var) const
{
Vars::const_iterator cit = vars_.find(var);
return (cit != vars_.end());
}
-string Variables::expand(string str) const
+
+string Variables::expand(string const & s) const
{
+ string str(s);
LRegex reg("\\$\\{\\(.*\\)\\}");
if (!reg.exact_match(str))
#include <map>
+///
class Variables {
public:
- virtual ~Variables() { };
- //
+ ///
void set(string const &, string const &);
- //
+ ///
virtual string get(string const &) const;
- //
+ ///
bool isset(string const & var) const;
- //
- string expand(string) const;
+ ///
+ string expand(string const &) const;
private:
- //
- typedef std::map<string,string> Vars;
- //
+ ///
+ typedef std::map<string, string> Vars;
+ ///
Vars vars_;
};
#include "insets/insetlist.h"
#include "insets/insettabular.h"
#include "insets/insettheorem.h"
+#include "insets/insetcaption.h"
#include "support/filetools.h"
#include "support/path.h"
#include "LaTeX.h"
inset->Read(this, lex);
par->InsertInset(pos, inset, font);
++pos;
+ } else if (tmptok == "Caption") {
+ Inset * inset = new InsetCaption;
+ inset->Read(this, lex);
+ par->InsertInset(pos, inset, font);
+ ++pos;
} else if (tmptok == "GRAPHICS") {
Inset * inset = new InsetGraphics;
//inset->Read(this, lex);
LFUN_INSET_LIST, // Lgb 20000627
LFUN_INSET_THEOREM, // Lgb 20000630
LFUN_CREATE_CITATION, // Angus 20000705
+ LFUN_INSET_CAPTION, // Lgb 20000718
LFUN_LASTACTION /* this marks the end of the table */
};
#endif
#include "insetcaption.h"
+#include "debug.h"
+
+void InsetCaption::Write(Buffer const * buf, ostream & os) const
+{
+ os << "Caption\n";
+ WriteParagraphData(buf, os);
+}
+
+
+
+void InsetCaption::Read(Buffer const * buf, LyXLex & lex)
+{
+ string token = lex.GetString();
+ if (token != "Caption") {
+ lyxerr << "InsetCaption::Read: consistency check failed."
+ << endl;
+ }
+ InsetText::Read(buf, lex);
+}
*/
class InsetCaption : public InsetText {
public:
+ ///
+ void Write(Buffer const * buf, std::ostream & os) const;
+ ///
+ void Read(Buffer const * buf, LyXLex & lex);
+ ///
+ Inset::Code LyxCode() const {
+ return CAPTION_CODE;
+ }
protected:
private:
};
}
+string const & InsetFloat::type() const
+{
+ return floatType;
+}
+
+
void InsetFloat::wide(bool w)
{
wide_ = w;
///
void InsetButtonRelease(BufferView * bv, int x, int y, int button);
///
+ string const & type() const;
+ ///
void wide(bool w);
///
bool wide() const;
UpdatableInset * inset = 0;
if (the_locking_inset) {
- the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
+ the_locking_inset->InsetButtonRelease(bv,
+ x - inset_x, y - inset_y,
+ button);
} else {
if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
// LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
///
LyXText * getLyXText(BufferView *) const;
+ ///
void deleteLyXText(BufferView *, bool recursive=true) const;
+ ///
void resizeLyXText(BufferView *) const;
-
+ ///
LyXParagraph * par;
///
mutable UpdateCodes need_update;
protected:
///
void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
-
+ ///
mutable int drawTextXOffset;
+ ///
mutable int drawTextYOffset;
///
bool autoBreakRows;
+ ///
DrawFrame drawFrame;
///
LColor::color frame_color;
string getText(int);
///
bool checkAndActivateInset(BufferView * bv, bool behind);
+ ///
bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
int button = 0);
///
int cx(BufferView *) const;
+ ///
int cy(BufferView *) const;
+ ///
int cpos(BufferView *) const;
+ ///
LyXParagraph * cpar(BufferView *) const;
+ ///
Row * crow(BufferView *) const;
/// This instead of a macro
mutable bool locked;
///
mutable int insetAscent;
+ ///
mutable int insetDescent;
+ ///
mutable int insetWidth;
+ ///
mutable int last_width;
+ ///
mutable int last_height;
+ ///
mutable int top_y;
///
LyXParagraph * inset_par;
///
TOC_CODE, // do these insets really need a code? (ale)
///
- LOF_CODE,
+ LOF_CODE, // 2
///
LOT_CODE,
///
LOA_CODE,
///
- QUOTE_CODE,
+ QUOTE_CODE, // 5
///
MARK_CODE,
///
///
HTMLURL_CODE,
///
- SEPARATOR_CODE,
+ SEPARATOR_CODE, // 10
///
ENDING_CODE,
///
///
ACCENT_CODE,
///
- MATH_CODE,
+ MATH_CODE, // 15
///
INDEX_CODE,
///
///
PARENT_CODE,
///
- BIBTEX_CODE,
+ BIBTEX_CODE, // 20
///
TEXT_CODE,
///
///
MARGIN_CODE,
///
- FLOAT_CODE,
+ FLOAT_CODE, // 25
///
MINIPAGE_CODE,
///
///
EXTERNAL_CODE,
///
- THEOREM_CODE
+ THEOREM_CODE, // 30
+ ///
+ CAPTION_CODE
};
///
#include "insets/insetlist.h"
#include "insets/insettabular.h"
#include "insets/insettheorem.h"
+#include "insets/insetcaption.h"
#include "mathed/formulamacro.h"
#include "toolbar.h"
#include "spellchecker.h" // RVDK_PATCH_5
}
break;
+ case LFUN_INSET_CAPTION:
+ {
+ // Do we have a locking inset...
+ if (owner->view()->the_locking_inset) {
+ lyxerr << "Locking inset code: "
+ << owner->view()->the_locking_inset->LyxCode();
+ InsetCaption * new_inset = new InsetCaption;
+ new_inset->setOwner(owner->view()->the_locking_inset);
+ new_inset->SetAutoBreakRows(true);
+ new_inset->SetDrawFrame(0, InsetText::LOCKED);
+ new_inset->SetFrameColor(0, LColor::footnoteframe);
+ if (owner->view()->insertInset(new_inset))
+ new_inset->Edit(owner->view(), 0, 0, 0);
+ else
+ delete new_inset;
+ }
+ }
+ break;
+
case LFUN_INSET_TABULAR:
{
int r = 2, c = 2;
if (!argument.empty())
- sscanf(argument.c_str(),"%d%d",&r,&c);
- InsetTabular * new_inset = new InsetTabular(owner->buffer(),r,c);
+ sscanf(argument.c_str(),"%d%d", &r, &c);
+ InsetTabular * new_inset =
+ new InsetTabular(owner->buffer(), r, c);
if (owner->view()->insertInset(new_inset))
new_inset->Edit(owner->view(), 0, 0, 0);
else
#include "insets/insetbib.h"
#include "insets/insetspecialchar.h"
#include "insets/insettext.h"
+#include "insets/insetfloat.h"
#include "layout.h"
#include "LyXView.h"
#include "support/textutils.h"
#include "font.h"
#include "debug.h"
#include "lyxrc.h"
+#include "FloatList.h"
//#define USE_OLD_CUT_AND_PASTE 1
char par_depth = par->GetDepth();
// We specialize the 95% common case:
- if (par->footnoteflag == LyXParagraph::NO_FOOTNOTE && !par_depth) {
+ if (
+#ifndef NEW_INSETS
+ par->footnoteflag == LyXParagraph::NO_FOOTNOTE &&
+#endif
+ !par_depth) {
if (pos >= 0){
// 95% goes here
if (layout.labeltype == LABEL_MANUAL
{
if (cursor.pos() == 0 && cursor.par()->bibkey){
cursor.par()->bibkey->Edit(bview, 0, 0, 0);
- }
- else if (cursor.pos() < cursor.par()->Last()
+ } else if (cursor.pos() < cursor.par()->Last()
&& cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
&& cursor.par()->GetInset(cursor.pos())->Editable()) {
bview->owner()->getMiniBuffer()
if (cursor.par()->GetInset(cursor.pos())->Editable() != Inset::HIGHLY_EDITABLE)
SetCursorParUndo(bview->buffer());
cursor.par()->GetInset(cursor.pos())->Edit(bview, 0, 0, 0);
- } else {
+ }
+#ifndef NEW_INSETS
+ else {
ToggleFootnote(bview);
}
+#endif
}
textclasslist.Style(bview->buffer()->params.textclass, layout);
while (cur.par() != send_cur.par()) {
+#ifndef NEW_INSETS
if (cur.par()->footnoteflag == sstart_cur.par()->footnoteflag) {
+#endif
cur.par()->SetLayout(bview->buffer()->params, layout);
MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
LyXParagraph * fppar = cur.par()->FirstPhysicalPar();
delete fppar->bibkey;
fppar->bibkey = 0;
}
+#ifndef NEW_INSETS
}
+#endif
cur.par(cur.par()->Next());
}
+#ifndef NEW_INSETS
if (cur.par()->footnoteflag == sstart_cur.par()->footnoteflag) {
+#endif
cur.par()->SetLayout(bview->buffer()->params, layout);
MakeFontEntriesLayoutSpecific(bview->buffer(), cur.par());
LyXParagraph * fppar = cur.par()->FirstPhysicalPar();
delete fppar->bibkey;
fppar->bibkey = 0;
}
+#ifndef NEW_INSETS
}
+#endif
return endpar;
}
return 'a' + n - 1;
}
+
char alphaCounter(int n)
{
if (n < 1 || n > 26)
return 'A' + n - 1;
}
+
char hebrewCounter(int n)
{
static const char hebrew[22] = {
return hebrew[n-1];
}
-static char const * romanCounter(int n)
+
+static
+char const * romanCounter(int n)
{
static char const * roman[20] = {
"i", "ii", "iii", "iv", "v",
return roman[n-1];
}
+
// set the counter of a paragraph. This includes the labels
void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
{
// this is only relevant for the beginning of paragraph
par = par->FirstPhysicalPar();
-
+
LyXLayout const & layout =
textclasslist.Style(buf->params.textclass,
par->GetLayout());
}
par->enumdepth = par->Previous()->FirstPhysicalPar()->enumdepth;
par->itemdepth = par->Previous()->FirstPhysicalPar()->itemdepth;
- }
- else {
+ } else {
for (int i = 0; i < 10; ++i) {
par->setCounter(i, 0);
}
par->Previous()->GetLayout()
).labeltype == LABEL_COUNTER_ENUMI
&& par->enumdepth < 3
+#ifndef NEW_INSETS
&& !(par->Previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE
&& par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
&& par->footnotekind == LyXParagraph::FOOTNOTE)
+#endif
&& layout.labeltype != LABEL_BIBLIO) {
par->enumdepth++;
}
/* Maybe we have to decrement the enumeration depth, see note above */
if (par->Previous()
&& par->Previous()->GetDepth() > par->GetDepth()
+#ifndef NEW_INSETS
&& !(par->Previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE
&& par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
&& par->footnotekind == LyXParagraph::FOOTNOTE)
+#endif
&& layout.labeltype != LABEL_BIBLIO) {
par->enumdepth = par->DepthHook(par->GetDepth())->enumdepth;
par->setCounter(6 + par->enumdepth,
// the caption hack:
if (layout.labeltype == LABEL_SENSITIVE) {
- bool isOK = (par->InInset() && par->InInset()->owner() &&
- (par->InInset()->owner()->LyxCode()==Inset::FLOAT_CODE));
- if ((isOK && (par->InInset()->owner()->getInsetName() == "figure")) ||
- (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
+ bool isOK (par->InInset() && par->InInset()->owner() &&
+ (par->InInset()->owner()->LyxCode() == Inset::FLOAT_CODE));
+#ifndef NEW_INSETS
+ if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
&& (par->footnotekind == LyXParagraph::FIG
- || par->footnotekind == LyXParagraph::WIDE_FIG)))
+ || par->footnotekind == LyXParagraph::WIDE_FIG)) {
s = (par->getParLanguage(buf->params)->lang() == "hebrew")
? ":øåéà" : "Figure:";
- else if ((isOK && (par->InInset()->owner()->getInsetName() == "table")) ||
- (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
+ } else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
&& (par->footnotekind == LyXParagraph::TAB
- || par->footnotekind == LyXParagraph::WIDE_TAB)))
+ || par->footnotekind == LyXParagraph::WIDE_TAB)) {
s = (par->getParLanguage(buf->params)->lang() == "hebrew")
? ":äìáè" : "Table:";
- else if ((isOK && (par->InInset()->owner()->getInsetName() == "algorithm")) ||
- (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
- && par->footnotekind == LyXParagraph::ALGORITHM))
+ } else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE
+ && par->footnotekind == LyXParagraph::ALGORITHM) {
s = (par->getParLanguage(buf->params)->lang() == "hebrew")
? ":íúéøåâìà" : "Algorithm:";
- else {
+ }
+#endif
+ else if (isOK) {
+ InsetFloat * tmp = static_cast<InsetFloat*>(par->InInset()->owner());
+ Floating const & fl
+ = floatList.getType(tmp->type());
+ // We should get the correct number here too.
+ s = fl.name + " #:";
+ } else {
/* par->SetLayout(0);
s = layout->labelstring; */
s = (par->getParLanguage(buf->params)->lang() == "hebrew")
if (!row) {
row = firstrow;
par = row->par();
- }
- else {
+ } else {
if (row->par()->next
- && row->par()->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) {
+#ifndef NEW_INSETS
+ && row->par()->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE)
+#endif
+ {
par = row->par()->LastPhysicalPar()->Next();
} else {
par = row->par()->next;
LyXParagraph * par = FirstParagraph();
do {
+#ifndef NEW_INSETS
// make sure the paragraph is open
if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
+#endif
pos = par->GetPositionOfInset(inset);
if (pos != -1){
CheckParagraph(bview, par, pos);
return true;
}
+#ifndef NEW_INSETS
}
+#endif
par = par->Next();
} while (par);
else
OwnerParagraph(tmppar3);
tmppar3->previous = before;
- }
- else {
+ } else {
if (!before)
OwnerParagraph(behind);
}
// Set the cursor for redoing
if (before) {
SetCursorIntern(bview, before->FirstSelfrowPar(), 0);
+#ifndef NEW_INSETS
// check wether before points to a closed float and open it if necessary
if (before && before->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
&& before->next && before->next->footnoteflag != LyXParagraph::NO_FOOTNOTE){
tmppar4 = tmppar4->next;
}
}
+#endif
}
-
+
+#ifndef NEW_INSETS
// open a cosed footnote at the end if necessary
if (behind && behind->previous &&
behind->previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
behind = behind->next;
}
}
+#endif
// calculate the endpar for redoing the paragraphs.
if (behind) {
+#ifndef NEW_INSETS
if (behind->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
+#endif
endpar = behind->LastPhysicalPar()->Next();
+#ifndef NEW_INSETS
else
endpar = behind->NextAfterFootnote()->LastPhysicalPar()->Next();
+#endif
} else
endpar = behind;
SetCursor(bview, cursor.par(), cursor.pos());
}
+
LyXParagraph * LyXText::OwnerParagraph() const
{
if (inset_owner)