On Tue, Aug 13, 2002 at 10:45:05AM +0100, Angus Leeming wrote:
 
> Martin Vermeer wrote:

...

> Looks great. It means that InsetShortTitle is working fine.
> 
> > I have experimented by creating the inset as a
> > standalone, in an arbitrary text location, using a
> > minibuffer command; that works great. But now I want
> > it tied to section etc. and make the label the
> > section number. But that seems to be an entirely
> > different thing. I use insetbib/bibkey as my model,
> > but it appears not suitable.
> > 
> > What am I missing?
> 
> How the core code creates Section titles at the moment.
> 
> You are attempting to go from a hard-wired Section-environment to a Section 
> inset. You have to link the two approaches together!
> 
> Presumably when I create a Section I want the Paragraph to insert a Section 
> Inset for me automatically. In fact, /only/ this piece of code could do 
> that. I can imagine generalising this to a generic Caption class that would 
> provide the interface to Paragraph.
> 
> Perhaps. Perhaps not.
> 
> You should scream loudly and get the knowledgable among us to give you some 
> advice ;-)
> 
> Angus
 
Ok Angus, thanks for the encouragement.

I attach here the patch containing my current work-in-progress, so you
can get an idea, also functionally, what I managed and where I am stuck.

I have now a shorttitle inset that is attached to the start of a section
header. It displays correctly on screen; it picks up the counter label
and counts correctly, re-counting if you edit. So far so good.

Things wrong with it:

1) The cursor is in the wrong place in the section header. It still 
believes in locations that are obtained without the shorttitle inset.

2) The inset doesn't actually catch mouse clicks or respond to them.
So collapsing/uncollapsing does not work. Also no way to insert the
short title text into the inset. The whole inset seems to be dead for
the mouse.

3) I haven't even looked yet (very seriously) into the LaTeX output, 
or document save/load. As you say, this will probably require some
integration with the section header handling (like a section inset?
There is an attempt at that in CVS but is very, very vague to me. And I
would prefer to keep the main title as "just" a \layout.) 

I have also independently implemented a shorttitle inset that can be
inserted at arbitrary places. It loads and saves correctly, but LaTeX is
of course meaningless here. It's just a demonstration of the inset
itself. (Un)collapsing and writing into it work.

The minibuffer command is M-x shorttitle-inset <RET>. 

So, any good suggestions to get further ahead? Dummy level please!

Martin
 
Index: BufferView_pimpl.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.279
diff -u -p -r1.279 BufferView_pimpl.C
--- BufferView_pimpl.C  2002/08/12 09:35:51     1.279
+++ BufferView_pimpl.C  2002/08/13 18:53:35
@@ -67,6 +67,7 @@
 #include "insets/insetcaption.h"
 #include "insets/insetfloatlist.h"
 #include "insets/insetspecialchar.h"
+#include "insets/insetshorttitle.h"
 
 #include "mathed/formulabase.h"
 
@@ -2761,6 +2768,10 @@ bool BufferView::Pimpl::dispatch(FuncReq
                insertAndEditInset(new InsetNote(buffer_->params));
                break;
 
+       case LFUN_INSET_SHORTTITLE:
+               insertAndEditInset(new InsetShortTitle(buffer_->params));
+               break;
+
        case LFUN_INSET_FLOAT:
                // check if the float type exist
                if (floatList.typeExist(ev.argument)) {
Index: LyXAction.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/LyXAction.C,v
retrieving revision 1.129
diff -u -p -r1.129 LyXAction.C
--- LyXAction.C 2002/08/08 22:03:27     1.129
+++ LyXAction.C 2002/08/13 18:53:36
@@ -249,6 +249,8 @@ void LyXAction::init()
                  ReadOnly },
                { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"),
                  Noop },
+               { LFUN_INSET_SHORTTITLE, "shorttitle-insert", N_("Insert Short Title"),
+                 Noop },
                { LFUN_LANGUAGE, "language", N_("Change language"), Noop },
                { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"),
                  ReadOnly },
Index: ParagraphParameters.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ParagraphParameters.C,v
retrieving revision 1.9
diff -u -p -r1.9 ParagraphParameters.C
--- ParagraphParameters.C       2002/05/08 12:58:14     1.9
+++ ParagraphParameters.C       2002/08/13 18:53:36
Index: buffer.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v
retrieving revision 1.367
diff -u -p -r1.367 buffer.C
--- buffer.C    2002/08/12 00:15:16     1.367
+++ buffer.C    2002/08/13 18:53:39
@@ -70,6 +70,7 @@
 #include "insets/insetgraphics.h"
 #include "insets/insetfoot.h"
 #include "insets/insetmarginal.h"
+#include "insets/insetshorttitle.h"
 #include "insets/insetminipage.h"
 #include "insets/insetfloat.h"
 #include "insets/insettabular.h"
@@ -1631,6 +1635,8 @@ void Buffer::readInset(LyXLex & lex, Par
                        inset = new InsetFoot(params);
                } else if (tmptok == "Marginal") {
                        inset = new InsetMarginal(params);
+               } else if (tmptok == "ShortTitle") {
+                       inset = new InsetShortTitle(params);
                } else if (tmptok == "Minipage") {
                        inset = new InsetMinipage(params);
                } else if (tmptok == "Float") {
 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
        : par(paragraph)
Index: commandtags.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/commandtags.h,v
retrieving revision 1.96
diff -u -p -r1.96 commandtags.h
--- commandtags.h       2002/08/12 09:53:03     1.96
+++ commandtags.h       2002/08/13 18:53:40
@@ -289,6 +289,7 @@ enum kb_action {
        LFUN_FORKS_SHOW,                // Angus 16 Feb 2002
        LFUN_FORKS_KILL,                // Angus 16 Feb 2002
        LFUN_TOOLTIPS_TOGGLE,           // Angus 8 Mar 2002
+       LFUN_INSET_SHORTTITLE,                  // Martin 12 Aug 2002
        LFUN_MOUSE_PRESS,               // André 9 Aug 2002
        LFUN_MOUSE_MOTION,              // André 9 Aug 2002
        LFUN_MOUSE_RELEASE,             // André 9 Aug 2002
Index: lyxfunc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.364
diff -u -p -r1.364 lyxfunc.C
--- lyxfunc.C   2002/08/11 16:27:09     1.364
+++ lyxfunc.C   2002/08/13 18:53:41
@@ -542,6 +542,9 @@ FuncStatus LyXFunc::getStatus(FuncReques
        case LFUN_INSERT_LABEL:
                code = Inset::LABEL_CODE;
                break;
+       case LFUN_INSET_SHORTTITLE:
+               code = Inset::SHORTTITLE_CODE;
+               break;
        case LFUN_REF_INSERT:
                code = Inset::REF_CODE;
                break;
Index: paragraph.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/paragraph.C,v
retrieving revision 1.219
diff -u -p -r1.219 paragraph.C
--- paragraph.C 2002/08/11 20:34:20     1.219
+++ paragraph.C 2002/08/13 18:53:43
@@ -32,6 +32,7 @@
 #include "insets/insetinclude.h"
 #include "insets/insetbib.h"
 #include "insets/insettext.h"
+#include "insets/insetshorttitle.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -81,6 +84,7 @@ Paragraph::Paragraph()
        enumdepth = 0;
        itemdepth = 0;
        bibkey = 0; // ale970302
+       shorttitle = 0;
        params().clear();
 }
 
@@ -101,6 +105,7 @@ Paragraph::Paragraph(Paragraph * par)
        // end
 
        bibkey = 0; // ale970302
+       shorttitle = 0;
        params().clear();
 }
 
@@ -125,6 +130,13 @@ Paragraph::Paragraph(Paragraph const & l
                bibkey = 0;
        }
 
+       if (lp.shorttitle) {
+               shorttitle = static_cast<InsetShortTitle *>
+                       (lp.shorttitle->clone(*current_view->buffer()));
+       } else {
+               shorttitle = 0;
+       }
+
        // copy everything behind the break-position to the new paragraph
        insetlist = lp.insetlist;
        for (InsetList::iterator it = insetlist.begin();
@@ -147,6 +159,7 @@ Paragraph::~Paragraph()
 
        // ale970302
        delete bibkey;
+       delete shorttitle;
 
        delete pimpl_;
        //
@@ -232,6 +253,8 @@ void Paragraph::writeFile(Buffer const *
        // bibitem  ale970302
        if (bibkey)
                bibkey->write(buf, os);
+       if (shorttitle)
+               shorttitle->write(buf, os);
 
        LyXFont font1(LyXFont::ALL_INHERIT, bparams.language);
 
@@ -817,8 +842,10 @@ void Paragraph::breakParagraph(BufferPar
                tmp->params().pagebreakTop(params().pagebreakTop());
                tmp->params().spaceTop(params().spaceTop());
                tmp->bibkey = bibkey;
+               tmp->shorttitle = shorttitle;
 
                bibkey = 0;
+               shorttitle = 0;
                params().clear();
 
                layout(bparams.getLyXTextClass().defaultLayout());
@@ -1108,7 +1149,7 @@ int Paragraph::getPositionOfInset(Inset 
                        return it.getPos();
                }
        }
-       if (inset == bibkey)
+       if (inset == bibkey || inset == shorttitle)
                return 0;
 
        return -1;
Index: paragraph.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/paragraph.h,v
retrieving revision 1.43
diff -u -p -r1.43 paragraph.h
--- paragraph.h 2002/08/11 20:34:20     1.43
+++ paragraph.h 2002/08/13 18:53:43
@@ -27,6 +27,7 @@ class BufferParams;
 class BufferView;
 class Counters;
 class InsetBibKey;
+class InsetShortTitle;
 class Language;
 class LaTeXFeatures;
 class ParagraphParameters;
@@ -180,6 +181,8 @@ public:
 
        ///
        InsetBibKey * bibkey;  // ale970302
+       ///
+       InsetShortTitle * shorttitle;  // mv020809
 
        ///
        void next(Paragraph *);
Index: text.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text.C,v
retrieving revision 1.265
diff -u -p -r1.265 text.C
--- text.C      2002/08/10 15:21:03     1.265
+++ text.C      2002/08/13 18:53:49
@@ -30,6 +30,7 @@
 #include "undo_funcs.h"
 
 #include "insets/insetbib.h"
+#include "insets/insetshorttitle.h"
 #include "insets/insettext.h"
 
 #include "support/textutils.h"
@@ -3519,6 +3520,24 @@ void LyXText::paintFirstRow(DrawRowParam
                }
                par->bibkey->draw(p.bv, font, p.yo + p.row->baseline(), x, p.cleared);
        }
+
+       if (layout->labeltype >= LABEL_COUNTER_CHAPTER && par->shorttitle) {
+               LyXFont font = getLayoutFont(buffer, par);
+               float x;
+               if (is_rtl) {
+                       x = ww - leftMargin(p.bv, p.row)
+                               + font_metrics::width(layout->labelsep, font);
+               } else {
+                       x = p.x /*- font_metrics::width(layout->labelsep, font)
+                               - par->shorttitle->width_collapsed()*/;
+               }
+               //drawInset(p, p.row->pos());
+               par->shorttitle->draw(p.bv, font, p.yo + p.row->baseline(), x, 
+p.cleared);
+               p.x += font_metrics::width(layout->labelsep, font)
+                               + par->shorttitle->width_collapsed();
+               setCursor(p.bv, cursor.par(), cursor.pos());
+       }
+
 }
 
 
Index: text2.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text2.C,v
retrieving revision 1.246
diff -u -p -r1.246 text2.C
--- text2.C     2002/08/12 00:15:17     1.246
+++ text2.C     2002/08/13 18:53:50
@@ -39,6 +39,7 @@
 #include "insets/insetspecialchar.h"
 #include "insets/insettext.h"
 #include "insets/insetfloat.h"
+#include "insets/insetshorttitle.h"
 
 #include "support/LAssert.h"
 #include "support/textutils.h"
@@ -408,6 +409,8 @@ Inset * LyXText::getInset() const
        Inset * inset = 0;
        if (cursor.pos() == 0 && cursor.par()->bibkey) {
                inset = cursor.par()->bibkey;
+       } else if (cursor.pos()== 0 && cursor.par()->shorttitle) {
+               inset = cursor.par()->shorttitle;
        } else if (cursor.pos() < cursor.par()->size()
                   && cursor.par()->isInset(cursor.pos())) {
                inset = cursor.par()->getInset(cursor.pos());
@@ -1310,10 +1313,16 @@ void LyXText::setCounter(Buffer const * 
                                        langtype = "latin";
                        }
 
                        s << buf->counters().numberLabel(buf->counters().sects[i],
                                numbertype, langtype, head);
 
-                       par->params().labelString(par->params().labelString() 
+s.str().c_str());
+                       if (!par->shorttitle) {
+                               par->shorttitle = new InsetShortTitle(buf->params);
+                               par->shorttitle->parOwner(par);
+                       }
+                       par->shorttitle->setLabel(s.str());
+
+                       //par->params().labelString(par->params().labelString() + 
+s.str().c_str());
                        // We really want to remove the c_str as soon as
                        // possible...
 
Index: insets/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/Makefile.am,v
retrieving revision 1.47
diff -u -p -r1.47 Makefile.am
--- insets/Makefile.am  2002/07/04 13:54:28     1.47
+++ insets/Makefile.am  2002/08/13 18:53:57
@@ -69,6 +69,8 @@ libinsets_la_SOURCES = \
        insetquotes.h \
        insetref.C \
        insetref.h \
+       insetshorttitle.C \
+       insetshorttitle.h \
        insetspecialchar.C \
        insetspecialchar.h \
        insettabular.C \
Index: insets/inset.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/inset.h,v
retrieving revision 1.53
diff -u -p -r1.53 inset.h
--- insets/inset.h      2002/08/07 08:11:38     1.53
+++ insets/inset.h      2002/08/13 18:53:57
@@ -115,7 +115,9 @@ public:
                ///
                FLOAT_LIST_CODE,
                ///
-               INDEX_PRINT_CODE
+               INDEX_PRINT_CODE,
+               ///
+               SHORTTITLE_CODE
        };
 
        ///
Index: insets/insetcollapsable.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.85
diff -u -p -r1.85 insetcollapsable.h
--- insets/insetcollapsable.h   2002/08/07 08:11:38     1.85
+++ insets/insetcollapsable.h   2002/08/13 18:53:57
@@ -193,13 +193,13 @@ public:
        ///
        void addPreview(grfx::PreviewLoader &) const;
 
+       ///
+       int width_collapsed() const;
 protected:
        ///
        int ascent_collapsed() const;
        ///
        int descent_collapsed() const;
-       ///
-       int width_collapsed() const;
        ///
        void draw_collapsed(Painter & pain, int , float &) const;
        ///

Attachment: msg42696/pgp00000.pgp
Description: PGP signature

Reply via email to