Implemented Search/Replace functionality for Insets. Cleaned up a bit.

Small fixes.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2296 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2001-07-20 14:18:48 +00:00
parent 7b14e7d3a8
commit 7c0dad35b3
55 changed files with 1213 additions and 293 deletions

View File

@ -256,9 +256,16 @@ bool BufferView::Pimpl::fitCursor(LyXText * text)
{
lyx::Assert(screen_.get());
bv_->owner()->getDialogs()->updateParagraph();
bool ret;
bool const ret = screen_->fitCursor(text, bv_);
if (bv_->theLockingInset()) {
bv_->theLockingInset()->fitInsetCursor(bv_);
ret = true;
} else {
ret = screen_->fitCursor(text, bv_);
}
bv_->owner()->getDialogs()->updateParagraph();
if (ret)
updateScrollbar();
return ret;
@ -1004,14 +1011,15 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f)
text->fullRebreak(bv_);
if (text->inset_owner) {
text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
updateInset(text->inset_owner, true);
} else
} else {
update();
}
if ((f & FITCUR)) {
fitCursor(text);
}
}
if ((f & CHANGE)) {
buffer_->markDirty();
@ -1252,15 +1260,23 @@ bool BufferView::Pimpl::belowMouse() const
void BufferView::Pimpl::showCursor()
{
if (screen_.get())
screen_->showCursor(bv_->text, bv_);
if (screen_.get()) {
if (bv_->theLockingInset())
bv_->theLockingInset()->showInsetCursor(bv_);
else
screen_->showCursor(bv_->text, bv_);
}
}
void BufferView::Pimpl::hideCursor()
{
if (screen_.get())
screen_->hideCursor();
if (screen_.get()) {
if (!bv_->theLockingInset())
// bv_->theLockingInset()->hideInsetCursor(bv_);
// else
screen_->hideCursor();
}
}
@ -1467,7 +1483,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
} else {
// this is need because you don't use a inset->Edit()
updateInset(new_inset, true);
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
}
break;
}
@ -1814,15 +1830,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
&& lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
int y = 0;
if (is_rtl) {
LyXFont const font =
lt->getFont(buffer_,
lt->cursor.par(),
lt->cursor.pos());
y = tmpinset->descent(bv_,font);
}
tmpinset->edit(bv_, 0, y, 0);
if (is_rtl)
tmpinset->edit(bv_, false);
else
tmpinset->edit(bv_);
break;
}
if (!is_rtl)
@ -1855,15 +1866,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
LyXFont const font = lt->getFont(buffer_,
lt->cursor.par(),
lt->cursor.pos());
int y = is_rtl ? 0
: tmpinset->descent(bv_,font);
tmpinset->edit(bv_,
tmpinset->x() +
tmpinset->width(bv_,font),
y, 0);
if (is_rtl)
tmpinset->edit(bv_);
else
tmpinset->edit(bv_, false);
break;
}
if (is_rtl)
@ -2686,7 +2692,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetText * new_inset = new InsetText;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2696,7 +2702,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetERT * new_inset = new InsetERT;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2706,7 +2712,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetExternal * new_inset = new InsetExternal;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2716,7 +2722,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetFoot * new_inset = new InsetFoot;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2726,7 +2732,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetMarginal * new_inset = new InsetMarginal;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2736,7 +2742,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetMinipage * new_inset = new InsetMinipage;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2748,7 +2754,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
if (floatList.typeExist(argument)) {
InsetFloat * new_inset = new InsetFloat(argument);
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
} else {
@ -2766,7 +2772,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
InsetFloat * new_inset = new InsetFloat(argument);
new_inset->wide(true);
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
} else {
@ -2781,7 +2787,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetList * new_inset = new InsetList;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2791,7 +2797,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
{
InsetTheorem * new_inset = new InsetTheorem;
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2809,7 +2815,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
new_inset->setDrawFrame(0, InsetText::LOCKED);
new_inset->setFrameColor(0, LColor::captionframe);
if (insertInset(new_inset))
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_);
else
delete new_inset;
}
@ -2980,7 +2986,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
if (insertInset(inset)) {
if (argument.empty())
inset->edit(bv_, 0, 0, 0);
inset->edit(bv_);
} else
delete inset;
}
@ -3263,6 +3269,7 @@ void BufferView::Pimpl::protectedBlank(LyXText * lt)
}
}
void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
{
if (available()) {
@ -3281,7 +3288,7 @@ void BufferView::Pimpl::insertNote()
{
Inset * inset = new InsetNote;
insertInset(inset);
inset->edit(bv_, 0, 0, 0);
inset->edit(bv_);
}
@ -3296,11 +3303,7 @@ bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
delete new_inset;
return false;
}
if (behind) {
LyXFont & font = lt->real_current_font;
new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
} else
new_inset->edit(bv_, 0, 0, 0);
new_inset->edit(bv_, !behind);
return true;
}

View File

@ -1,3 +1,29 @@
2001-07-20 Juergen Vigna <jug@sad.it>
* lyxfunc.C (dispatch): use always LyXFind now!
* text2.C (init): add a reinit flag so that the LyXText can be
reinited instead of deleted and reallocated (used in InsetText).
* BufferView_pimpl.C: use the new Inset::edit(BV, bool) where needed.
* text.C: ditto
* text2.C: ditto
2001-07-18 Juergen Vigna <jug@sad.it>
* text.C (selectNextWord): handle insets inside inset by calling
always the bv->text functions so that we can go up the_locking_inset!
* BufferView_pimpl.C (show/hideCursor): fixed cursor showing up
in strange locations when inside an inset!
* lyxfind.[Ch]: give all functions a LyXText * parameter and implement
handling to include insets.
* lyxfunc.C (dispatch): changes to calls SearchBackward/Forward.
2001-07-20 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* LyXAction.C (init):

View File

@ -1,3 +1,7 @@
2001-07-18 Juergen Vigna <jug@sad.it>
* ControlSearch.C (replace): changes to lyxfind.h function calls.
2001-07-19 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* biblio.C (getInfo): add a .c_str() to handle the usual

View File

@ -46,8 +46,8 @@ ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
void ControlSearch::find(string const & search,
bool casesensitive, bool matchword, bool forward) const
{
bool const found = LyXFind(lv_.view(), search, casesensitive,
matchword, forward);
bool const found = LyXFind(lv_.view(), search,
forward, false, casesensitive, matchword);
if (!found)
setMinibuffer(&lv_, _("String not found!"));
@ -58,8 +58,8 @@ void ControlSearch::replace(string const & search, string const & replace,
bool casesensitive, bool matchword, bool all) const
{
int const replace_count = LyXReplace(lv_.view(),
search, replace, casesensitive,
matchword, true, all);
search, replace, true, casesensitive,
matchword, all);
if (replace_count == 0) {
setMinibuffer(&lv_, _("String not found!"));

View File

@ -61,8 +61,8 @@ void FormSearch::show()
void FormSearch::find(string const & searchstr, bool const & casesensitive,
bool const & matchword, bool const & searchback)
{
bool found = LyXFind(lv_->view(), searchstr, casesensitive, matchword,
searchback);
bool found = LyXFind(lv_->view(), searchstr, searchback,
casesensitive, matchword);
if (!found)
setMinibuffer(lv_, _("String not found!"));
@ -73,7 +73,7 @@ void FormSearch::replace(string const & searchstr, string const & replacestr,
bool const & searchback, bool const & replaceall)
{
int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
casesensitive, matchword, searchback,
searchback, casesensitive, matchword,
replaceall);
if (replace_count == 0) {

View File

@ -1,3 +1,24 @@
2001-07-20 Juergen Vigna <jug@sad.it>
* insetcollapsable.C (update): recoded hopefully works now!
2001-07-19 Juergen Vigna <jug@sad.it>
* most files: implemented the below new introduced function.
* inset.h: added new edit(BufferView *, bool front) method to be able
to enter an inset from the front/back without knowing x/y positions
and baselines inside the inset. So I just can tell the inset activate
me and set the cursor on the front/back of yourself.
2001-07-18 Juergen Vigna <jug@sad.it>
* insetcollapsable.C (edit): fixed hopefully the y parameter which
is givven to the InsetText.
(insetButtonPress): ditto
(insetButtonRelease): ditto
(insetMotionNotify): ditto
2001-07-20 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* insetspecialchar.[Ch]: change HYPHENATION_BREAK to
@ -63,6 +84,8 @@
* insettabular.C (selectNextWord): fixed spellchecking for the
first cell of a tabular (wasn't entered!)
(getLyXText): changed to enter automatically insettext and return
it's LyXText if we're locked.
2001-07-17 Juergen Vigna <jug@sad.it>

View File

@ -1240,6 +1240,12 @@ void InsetFig::edit(BufferView * bv, int, int, unsigned int)
}
void InsetFig::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
Inset * InsetFig::clone(Buffer const & buffer, bool) const
{
InsetFig * tmp = new InsetFig(100, 100, buffer);

View File

@ -53,6 +53,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const;
///
bool deletable() const;

View File

@ -65,6 +65,10 @@ void Inset::edit(BufferView *, int, int, unsigned int)
{}
void Inset::edit(BufferView *, bool)
{}
LyXFont const Inset::convertFont(LyXFont const & font) const
{
return LyXFont(font);
@ -150,10 +154,18 @@ void UpdatableInset::hideInsetCursor(BufferView *)
{}
void UpdatableInset::fitInsetCursor(BufferView *) const
{}
void UpdatableInset::edit(BufferView *, int, int, unsigned int)
{}
void UpdatableInset::edit(BufferView *, bool)
{}
void UpdatableInset::draw(BufferView *, LyXFont const &,
int /* baseline */, float & x,
bool/*cleared*/) const
@ -266,3 +278,19 @@ string UpdatableInset::selectNextWord(BufferView *bv, float & value) const
value = 0;
return string();
}
bool UpdatableInset::searchForward(BufferView * bv, string const &,
bool const &, bool const &)
{
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<UpdatableInset *>(this));
return false;
}
bool UpdatableInset::searchBackward(BufferView * bv, string const &,
bool const &, bool const &)
{
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<UpdatableInset *>(this));
return false;
}

View File

@ -148,6 +148,8 @@ public:
///
virtual void edit(BufferView *, int x, int y, unsigned int button);
///
virtual void edit(BufferView *, bool front = true);
///
virtual EDITABLE editable() const;
/// This is called when the user clicks inside an inset
virtual void insetButtonPress(BufferView *, int, int, int) {}
@ -353,6 +355,8 @@ public:
///
virtual void hideInsetCursor(BufferView *);
///
virtual void fitInsetCursor(BufferView *) const;
///
virtual void getCursorPos(BufferView *, int &, int &) const {}
///
virtual void insetButtonPress(BufferView *, int x, int y, int button);
@ -368,6 +372,8 @@ public:
///
virtual void edit(BufferView *, int x, int y, unsigned int button);
///
virtual void edit(BufferView *, bool front = true);
///
virtual void draw(BufferView *, LyXFont const &,
int baseline, float & x, bool cleared) const;
///
@ -423,6 +429,13 @@ public:
virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {
return;
}
///
// needed for search/replace functionality
///
virtual bool searchForward(BufferView *, string const &,
bool const & = true, bool const & = false);
virtual bool searchBackward(BufferView *, string const &,
bool const & = true, bool const & = false);
protected:
///

View File

@ -113,6 +113,12 @@ void InsetBibKey::edit(BufferView * bv, int, int, unsigned int)
}
void InsetBibKey::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
InsetBibtex::InsetBibtex(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}
@ -217,6 +223,12 @@ void InsetBibtex::edit(BufferView * bv, int, int, unsigned int)
}
void InsetBibtex::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
bool InsetBibtex::addDatabase(string const & db)
{
string contents(getContents());
@ -253,6 +265,7 @@ bool InsetBibtex::delDatabase(string const & db)
int bibitemMaxWidth(BufferView * bv, LyXFont const & font)
{
int w = 0;
#warning Ha, now we are mainly at 1.2.0 and it is still here (Jug)
// Does look like a hack? It is! (but will change at 0.13)
Paragraph * par = bv->buffer()->paragraph;

View File

@ -42,9 +42,11 @@ public:
void read(Buffer const *, LyXLex & lex);
///
virtual string const getScreenLabel() const;
///
///
void edit(BufferView *, int x, int y, unsigned int button);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const {
return IS_EDITABLE;
}
@ -52,10 +54,10 @@ public:
bool deletable() const {
return false;
}
///
void setCounter(int);
///
int getCounter() const { return counter; }
///
void setCounter(int);
///
int getCounter() const { return counter; }
///
string const getBibLabel() const;
///
@ -66,7 +68,7 @@ public:
private:
///
int counter;
int counter;
///
Holder holder;
///
@ -94,15 +96,17 @@ public:
Inset::Code lyxCode() const { return Inset::BIBTEX_CODE; }
///
void edit(BufferView *, int x, int y, unsigned int button);
///
void edit(BufferView * bv, bool front = true);
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool freespace) const;
bool fragile, bool freespace) const;
///
std::vector<std::pair<string,string> > const getKeys(Buffer const *) const;
///
bool addDatabase(string const &);
///
bool delDatabase(string const &);
///
bool addDatabase(string const &);
///
bool delDatabase(string const &);
///
bool display() const { return true; }
///

View File

@ -63,6 +63,11 @@ void InsetCitation::edit(BufferView * bv, int, int, unsigned int)
bv->owner()->getDialogs()->showCitation(this);
}
void InsetCitation::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
int InsetCitation::ascii(Buffer const *, std::ostream & os, int) const
{
os << "[" << getContents() << "]";
@ -96,4 +101,3 @@ void InsetCitation::validate(LaTeXFeatures & features) const
if (getCmdName() != "cite" && features.bufferParams().use_natbib)
features.natbib = true;
}

View File

@ -33,9 +33,11 @@ public:
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset::Code lyxCode() const { return Inset::CITE_CODE; }
///
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///
int latex(Buffer const *, std::ostream &, bool, bool) const;

View File

@ -225,7 +225,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
unsigned int button)
unsigned int button)
{
UpdatableInset::edit(bv, xp, yp, button);
@ -238,7 +238,30 @@ void InsetCollapsable::edit(BufferView * bv, int xp, int yp,
} else {
if (!bv->lockInset(this))
return;
inset.edit(bv, xp, yp + (top_baseline - inset.y()), button);
LyXFont font(LyXFont::ALL_SANE);
int yy = ascent(bv, font) + yp -
(ascent_collapsed(bv->painter(), font) +
descent_collapsed(bv->painter(), font) +
inset.ascent(bv, font));
inset.edit(bv, xp, yy, button);
}
}
void InsetCollapsable::edit(BufferView * bv, bool front)
{
UpdatableInset::edit(bv, front);
if (collapsed_) {
collapsed_ = false;
if (!bv->lockInset(this))
return;
bv->updateInset(this, false);
inset.edit(bv, front);
} else {
if (!bv->lockInset(this))
return;
inset.edit(bv, front);
}
}
@ -267,8 +290,12 @@ void InsetCollapsable::insetButtonPress(BufferView * bv, int x, int y,
int button)
{
if (!collapsed_ && (y > button_bottom_y)) {
inset.insetButtonPress(bv, x, y + (top_baseline - inset.y()),
button);
LyXFont font(LyXFont::ALL_SANE);
int yy = ascent(bv, font) + y -
(ascent_collapsed(bv->painter(), font) +
descent_collapsed(bv->painter(), font) +
inset.ascent(bv, font));
inset.insetButtonPress(bv, x, yy, button);
}
}
@ -288,8 +315,12 @@ void InsetCollapsable::insetButtonRelease(BufferView * bv,
bv->updateInset(this, false);
}
} else if (!collapsed_ && (y > button_top_y)) {
inset.insetButtonRelease(bv, x, y + (top_baseline-inset.y()),
button);
LyXFont font(LyXFont::ALL_SANE);
int yy = ascent(bv, font) + y -
(ascent_collapsed(bv->painter(), font) +
descent_collapsed(bv->painter(), font) +
inset.ascent(bv, font));
inset.insetButtonRelease(bv, x, yy, button);
}
}
@ -298,8 +329,12 @@ void InsetCollapsable::insetMotionNotify(BufferView * bv,
int x, int y, int state)
{
if (x > button_bottom_y) {
inset.insetMotionNotify(bv, x, y + (top_baseline - inset.y()),
state);
LyXFont font(LyXFont::ALL_SANE);
int yy = ascent(bv, font) + y -
(ascent_collapsed(bv->painter(), font) +
descent_collapsed(bv->painter(), font) +
inset.ascent(bv, font));
inset.insetMotionNotify(bv, x, yy, state);
}
}
@ -335,6 +370,7 @@ int InsetCollapsable::getMaxWidth(BufferView * bv,
void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
bool reinit)
{
#if 0
if (reinit) {
need_update = FULL;
if (owner())
@ -359,7 +395,11 @@ void InsetCollapsable::update(BufferView * bv, LyXFont const & font,
return;
}
}
inset.update(bv, font);
#else
if (!widthCollapsed)
widthCollapsed = width_collapsed(bv->painter(), font);
inset.update(bv, font, reinit);
#endif
}
@ -425,6 +465,18 @@ void InsetCollapsable::toggleInsetCursor(BufferView * bv)
}
void InsetCollapsable::showInsetCursor(BufferView * bv, bool show)
{
inset.showInsetCursor(bv, show);
}
void InsetCollapsable::hideInsetCursor(BufferView * bv)
{
inset.hideInsetCursor(bv);
}
UpdatableInset * InsetCollapsable::getLockingInset() const
{
UpdatableInset * in = inset.getLockingInset();

View File

@ -60,6 +60,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView *, bool front = true);
///
EDITABLE editable() const;
///
bool insertInset(BufferView *, Inset * inset);
@ -111,6 +113,13 @@ public:
///
void toggleInsetCursor(BufferView *);
///
void showInsetCursor(BufferView *, bool show = true);
///
void hideInsetCursor(BufferView *);
///
void fitInsetCursor(BufferView * bv) const {
inset.fitInsetCursor(bv);
}
UpdatableInset * getLockingInset() const;
///
UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
@ -166,6 +175,15 @@ public:
void toggleSelection(BufferView * bv, bool kill_selection) {
inset.toggleSelection(bv, kill_selection);
}
///
bool searchForward(BufferView * bv, string const & str,
bool const & cs = true, bool const & mw = false) {
return inset.searchForward(bv, str, cs, mw);
}
bool searchBackward(BufferView * bv, string const & str,
bool const & cs = true, bool const & mw = false) {
return inset.searchBackward(bv, str, cs, mw);
}
protected:
///

View File

@ -89,3 +89,9 @@ void InsetError::edit(BufferView * bv, int, int, unsigned int)
{
bv->owner()->getDialogs()->showError( this );
}
void InsetError::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}

View File

@ -59,6 +59,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset * clone(Buffer const &, bool same_id = false) const {

View File

@ -114,6 +114,12 @@ void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
}
void InsetERT::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
bool /*free_spc*/) const
{

View File

@ -43,15 +43,17 @@ public:
virtual bool insetAllowed(Inset::Code) const { return false; }
///
virtual void setFont(BufferView *, LyXFont const &,
bool toggleall = false, bool selectall = false);
bool toggleall = false, bool selectall = false);
///
virtual void edit(BufferView *, int, int, unsigned int);
///
virtual void edit(BufferView * bv, bool front = true);
///
virtual int latex(Buffer const *, std::ostream &, bool fragile,
bool free_spc) const;
bool free_spc) const;
///
virtual int ascii(Buffer const *,
std::ostream &, int linelen = 0) const;
std::ostream &, int linelen = 0) const;
///
virtual int linuxdoc(Buffer const *, std::ostream &) const;
///

View File

@ -77,6 +77,12 @@ void InsetExternal::edit(BufferView * bv,
}
void InsetExternal::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
void InsetExternal::write(Buffer const *, std::ostream & os) const
{
os << "External " << params_.templ.lyxName << ",\"" << params_.filename

View File

@ -46,6 +46,8 @@ public:
///
virtual void edit(BufferView *, int x, int y, unsigned int button);
///
virtual void edit(BufferView * bv, bool front = true);
///
virtual EDITABLE editable() const { return IS_EDITABLE; }
///
virtual void write(Buffer const *, std::ostream &) const;
@ -59,7 +61,7 @@ public:
is in a free-spacing paragraph.
*/
virtual int latex(Buffer const *, std::ostream &, bool fragile,
bool free_spc) const;
bool free_spc) const;
/// write ASCII output to the ostream
virtual int ascii(Buffer const *, std::ostream &, int linelen) const;
/// write LinuxDoc output to the ostream

View File

@ -68,6 +68,12 @@ void InsetFloatList::edit(BufferView *, int, int, unsigned int)
}
void InsetFloatList::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
int InsetFloatList::latex(Buffer const *, std::ostream & os, bool, bool) const
{
FloatList::const_iterator cit = floatList[float_type];

View File

@ -31,11 +31,13 @@ public:
Inset * clone(Buffer const &, bool = false) const {
return new InsetFloatList(*this);
}
///
///
string const getScreenLabel() const;
///
void edit(BufferView * bv, int, int, unsigned int);
///
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
bool display() const { return true; }

View File

@ -316,6 +316,12 @@ void InsetGraphics::edit(BufferView *bv, int, int, unsigned int)
}
void InsetGraphics::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
Inset::EDITABLE InsetGraphics::editable() const
{
return IS_EDITABLE;

View File

@ -52,6 +52,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const;
///
void write(Buffer const *, std::ostream &) const;

View File

@ -127,6 +127,12 @@ void InsetInclude::edit(BufferView * bv, int, int, unsigned int)
}
void InsetInclude::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
void InsetInclude::write(Buffer const *, ostream & os) const
{
os << "Include " << params_.cparams.getCommand() << "\n";

View File

@ -79,17 +79,19 @@ public:
///
void edit(BufferView *, int x, int y, unsigned int button);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const
{
return IS_EDITABLE;
}
/// With lyx3 we won't overload these 3 methods
void write(Buffer const *, std::ostream &) const;
///
/// With lyx3 we won't overload these 3 methods
void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex &);
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///

View File

@ -28,6 +28,12 @@ void InsetIndex::edit(BufferView * bv, int, int, unsigned int)
}
void InsetIndex::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool)
: InsetCommand(p)
{}

View File

@ -36,6 +36,8 @@ public:
EDITABLE editable() const { return IS_EDITABLE; }
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
};
@ -52,6 +54,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int) {}
///
void edit(BufferView * bv, bool front = true) {}
///
EDITABLE editable() const{ return NOT_EDITABLE; }
///
bool display() const { return true; }

261
src/insets/insetinfo.C Normal file
View File

@ -0,0 +1,261 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
#include <config.h>
#include <cctype>
#ifdef __GNUG__
#pragma implementation
#endif
#include "insetinfo.h"
#include "paragraph.h"
#include "debug.h"
#include "gettext.h"
#include "lyx_gui_misc.h" // CancelCloseBoxCB
#include "buffer.h"
#include "support/lstrings.h"
#include "Painter.h"
#include "font.h"
#include "BufferView.h"
using std::ostream;
using std::endl;
/* Info, used for the Info boxes */
extern BufferView * current_view;
InsetInfo::InsetInfo()
: form(0), labelfont(LyXFont::ALL_SANE)
{
labelfont.decSize().decSize()
.setColor(LColor::note)
#ifndef NO_LATEX
.setLatex(LyXFont::OFF)
#endif
;
}
InsetInfo::InsetInfo(string const & str)
: contents(str), form(0), labelfont(LyXFont::ALL_SANE)
{
labelfont.decSize().decSize()
.setColor(LColor::note)
#ifndef NO_LATEX
.setLatex(LyXFont::OFF)
#endif
;
}
InsetInfo::~InsetInfo()
{
if (form) {
fl_hide_form(form);
fl_free_form(form);
form = 0;
}
}
int InsetInfo::ascent(BufferView *, LyXFont const &) const
{
return lyxfont::maxAscent(labelfont) + 1;
}
int InsetInfo::descent(BufferView *, LyXFont const &) const
{
return lyxfont::maxDescent(labelfont) + 1;
}
int InsetInfo::width(BufferView *, LyXFont const &) const
{
return 6 + lyxfont::width(_("Note"), labelfont);
}
void InsetInfo::draw(BufferView * bv, LyXFont const &,
int baseline, float & x, bool) const
{
Painter & pain = bv->painter();
// Draw as "Note" in a yellow box
x += 1;
pain.fillRectangle(int(x), baseline - ascent(bv, labelfont),
width(bv, labelfont) - 2,
ascent(bv, labelfont) + descent(bv, labelfont) - 2,
LColor::notebg);
pain.rectangle(int(x), baseline - ascent(bv, labelfont),
width(bv, labelfont) - 2,
ascent(bv, labelfont) + descent(bv, labelfont) - 2,
LColor::noteframe);
pain.text(int(x + 2), baseline, _("Note"), labelfont);
x += width(bv, labelfont) - 1;
}
void InsetInfo::write(Buffer const *, ostream & os) const
{
os << "Info\n" << contents;
}
void InsetInfo::read(Buffer const *, LyXLex & lex)
{
string tmp = lex.GetString(); // should be "Info"
if (tmp != "Info")
lyxerr << "ERROR (InsetInfo::Read): "
"consistency check 1 failed." << endl;
while (lex.IsOK()) {
if (!lex.EatLine())
// blank line in the file being read
// should we skip blank lines?
continue;
string const token = strip(lex.GetString());
lyxerr[Debug::PARSER] << "Note: " << token << endl;
if (token != "\\end_inset") {
contents += token + '\n';
}
else // token == "\\end_inset"
break;
}
// now remove the last '\n's
contents = strip(contents, '\n');
}
int InsetInfo::latex(Buffer const *, ostream &,
bool /*fragile*/, bool /*free_spc*/) const
{
return 0;
}
int InsetInfo::ascii(Buffer const *, ostream &, int) const
{
return 0;
}
int InsetInfo::linuxdoc(Buffer const *, ostream &) const
{
return 0;
}
int InsetInfo::docBook(Buffer const *, ostream &) const
{
return 0;
}
Inset::EDITABLE InsetInfo::editable() const
{
return IS_EDITABLE;
}
void InsetInfo::closeInfoCB(FL_OBJECT * ob, long)
{
InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
string tmp = fl_get_input(inset->strobj);
Buffer * buffer = current_view->buffer();
if (tmp != inset->contents && !(buffer->isReadonly())) {
buffer->markDirty();
inset->contents = tmp;
}
if (inset->form) {
fl_hide_form(inset->form);
fl_free_form(inset->form);
inset->form = 0;
}
}
// This is just a wrapper.
extern "C"
void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
{
InsetInfo::closeInfoCB(ob, data);
}
string const InsetInfo::editMessage() const
{
return _("Opened note");
}
void InsetInfo::edit(BufferView *bv, int, int, unsigned int)
{
static int ow = -1;
static int oh;
if (bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
if (!form) {
FL_OBJECT *obj;
form = fl_bgn_form(FL_UP_BOX, 400, 180);
strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
fl_set_object_resize(obj, FL_RESIZE_ALL);
fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
fl_set_object_resize(obj, FL_RESIZE_NONE);
fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
obj->u_vdata = this;
fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
fl_end_form();
fl_set_form_atclose(form, CancelCloseBoxCB, 0);
}
fl_set_input(strobj, contents.c_str());
if (form->visible) {
fl_raise_form(form);
} else {
fl_show_form(form,
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
_("Note"));
if (ow < 0) {
ow = form->w;
oh = form->h;
}
fl_set_form_minsize(form, ow, oh);
}
}
void InsetInfo::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
Inset * InsetInfo::clone(Buffer const &, bool) const
{
return new InsetInfo(contents);
}
Inset::Code InsetInfo::lyxCode() const
{
return Inset::IGNORE_CODE;
}

86
src/insets/insetinfo.h Normal file
View File

@ -0,0 +1,86 @@
// -*- C++ -*-
/* This file is part of*
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 the LyX Team.
*
* ====================================================== */
#ifndef INSET_INFO_H
#define INSET_INFO_H
#ifdef __GNUG__
#pragma interface
#endif
#include "inset.h"
#include FORMS_H_LOCATION
#include "LString.h"
#include "lyxfont.h"
/** Info. Handles the note insets.
This class handles the note insets. The edit operation bringes up
a dialog, where the user can type a note about life or something
else of interest. When collapsed, the inset is displayed as "Note"
in a yellow box. Currently, the Read-function is a terrible hack.
Some day in the distant future, this will hopefully be obsoleted by
a true comment-environment. */
class InsetInfo : public Inset {
public:
///
InsetInfo();
///
explicit
InsetInfo(string const & string);
///
~InsetInfo();
///
int ascent(BufferView *, LyXFont const &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
///
void draw(BufferView *, LyXFont const &, int, float &, bool) const;
///
void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex & lex);
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///
int linuxdoc(Buffer const *, std::ostream &) const;
///
int docBook(Buffer const *, std::ostream &) const;
/// what appears in the minibuffer when opening
string const editMessage() const;
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const;
///
Inset::Code lyxCode() const;
///
virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
static void closeInfoCB(FL_OBJECT *, long data);
private:
///
string contents;
///
FL_FORM * form;
///
FL_OBJECT * strobj;
///
LyXFont labelfont;
};
#endif

View File

@ -69,6 +69,12 @@ void InsetLabel::edit(BufferView * bv, int, int, unsigned int)
}
void InsetLabel::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
int InsetLabel::latex(Buffer const *, ostream & os,
bool /*fragile*/, bool /*fs*/) const
{

View File

@ -35,10 +35,12 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
std::vector<string> const getLabelList() const;
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///

View File

@ -329,7 +329,7 @@ void InsetMinipage::width(string const & ll)
bool InsetMinipage::showInsetDialog(BufferView * bv) const
{
if (!inset.showInsetDialog(bv))
bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
return true;
}
@ -338,8 +338,8 @@ void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
int button)
{
if (button == 3) {
showInsetDialog(bv);
return;
showInsetDialog(bv);
return;
}
InsetCollapsable::insetButtonRelease(bv, x, y, button);
}
@ -349,7 +349,7 @@ int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
const
{
if (!width_.empty())
return VSpace(width_).inPixels(bv);
return VSpace(width_).inPixels(bv);
// this should not happen!
return InsetCollapsable::getMaxWidth(bv, inset);
}

View File

@ -50,6 +50,12 @@ void InsetParent::edit(BufferView * bv, int, int, unsigned int)
}
void InsetParent::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
// LaTeX must just ignore this command
int InsetParent::latex(Buffer const * buf, ostream & os,
bool fragile, bool free_spc) const

View File

@ -32,18 +32,20 @@ public:
virtual Inset * clone(Buffer const & buffer, bool same_id = false) const {
return new InsetParent(params(), buffer, same_id);
}
///
///
string const getScreenLabel() const;
///
///
EDITABLE editable() const { return IS_EDITABLE; }
///
Inset::Code lyxCode() const { return Inset::PARENT_CODE; }
///
///
Inset::Code lyxCode() const { return Inset::PARENT_CODE; }
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
void setParent(string fn) { setContents(fn); }
bool fragile, bool free_spc) const;
///
void setParent(string fn) { setContents(fn); }
};
#endif

View File

@ -33,6 +33,11 @@ void InsetRef::edit(BufferView * bv, int, int, unsigned int button)
}
void InsetRef::edit(BufferView * bv, bool)
{
}
string const InsetRef::getScreenLabel() const
{
string temp;

View File

@ -51,11 +51,13 @@ public:
Inset::Code lyxCode() const { return Inset::REF_CODE; }
///
void edit(BufferView *, int, int, unsigned int);
///
///
void edit(BufferView * bv, bool front = true);
///
bool display() const { return false; }
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///

View File

@ -510,8 +510,28 @@ void InsetTabular::edit(BufferView * bv, int x, int y, unsigned int button)
if (insetHit(bv, x, y) && (button != 3)) {
activateCellInsetAbs(bv, x, y, button);
}
// UpdateLocal(bv, NONE, false);
// bv->getOwner()->getPopups().updateFormTabular();
}
void InsetTabular::edit(BufferView * bv, bool front)
{
UpdatableInset::edit(bv, front);
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "InsetTabular::Cannot lock inset" << endl;
return;
}
locked = true;
the_locking_inset = 0;
inset_x = 0;
inset_y = 0;
if (front)
actcell = 0;
else
actcell = tabular->GetNumberOfCells() - 1;
sel_cell_start = sel_cell_end = actcell;
resetPos(bv);
finishUndo();
}
@ -1969,10 +1989,19 @@ void InsetTabular::resizeLyXText(BufferView * bv, bool force) const
LyXText * InsetTabular::getLyXText(BufferView const * bv,
bool const recursive) const
bool const recursive) const
{
if (the_locking_inset)
return the_locking_inset->getLyXText(bv, recursive);
#if 0
// if we're locked lock the actual insettext and return it's LyXText!!!
if (locked) {
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(const_cast<BufferView *>(bv), 0, 0, 0);
return the_locking_inset->getLyXText(bv, recursive);
}
#endif
return Inset::getLyXText(bv, recursive);
}
@ -2498,3 +2527,51 @@ void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
the_locking_inset->toggleSelection(bv, kill_selection);
}
}
bool InsetTabular::searchForward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
{
if (the_locking_inset) {
if (the_locking_inset->searchForward(bv, str, cs, mw))
return true;
if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this));
return false;
}
++actcell;
}
nodraw(true);
// otherwise we have to lock the next inset and search there
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv);
bool res = searchForward(bv, str, cs, mw);
updateLocal(bv, NONE, false);
nodraw(false);
bv->updateInset(const_cast<InsetTabular *>(this), false);
return res;
}
bool InsetTabular::searchBackward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
{
if (the_locking_inset) {
if (the_locking_inset->searchBackward(bv, str, cs, mw))
return true;
if (!actcell) { // we are already in the first cell
bv->unlockInset(const_cast<InsetTabular *>(this));
return false;
}
--actcell;
}
nodraw(true);
// otherwise we have to lock the next inset and search there
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(actcell));
inset->edit(bv, false);
bool res = searchBackward(bv, str, cs, mw);
nodraw(false);
bv->updateInset(const_cast<InsetTabular *>(this), false);
return res;
}

View File

@ -102,6 +102,8 @@ public:
///
void edit(BufferView *, int x, int y, unsigned int);
///
void edit(BufferView * bv, bool front = true);
///
bool doClearArea() const;
///
void insetUnlock(BufferView *);
@ -213,6 +215,11 @@ public:
string selectNextWord(BufferView *, float & value) const;
void selectSelectedWord(BufferView *);
void toggleSelection(BufferView *, bool kill_selection);
///
bool searchForward(BufferView *, string const &,
bool const & = true, bool const & = false);
bool searchBackward(BufferView *, string const &,
bool const & = true, bool const & = false);
//
// Public structures and variables

View File

@ -50,6 +50,7 @@
#include "lyxfunc.h"
#include "ParagraphParameters.h"
#include "undo_funcs.h"
#include "lyxfind.h"
using std::ostream;
using std::ifstream;
@ -540,7 +541,7 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
}
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty) const
{
bool clear = false;
if (!lt) {
@ -552,7 +553,7 @@ void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
if ((need_update != CURSOR) || (lt->status() != LyXText::UNCHANGED) ||
lt->selection.set())
{
bv->updateInset(this, mark_dirty);
bv->updateInset(const_cast<InsetText *>(this), mark_dirty);
}
bv->owner()->showState();
if (old_par != cpar(bv)) {
@ -572,7 +573,6 @@ string const InsetText::editMessage() const
void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
{
// par->SetInsetOwner(this);
UpdatableInset::edit(bv, x, y, button);
if (!bv->lockInset(this)) {
@ -595,7 +595,52 @@ void InsetText::edit(BufferView * bv, int x, int y, unsigned int button)
if (!checkAndActivateInset(bv, x, tmp_y, button))
lt->setCursorFromCoordinates(bv, x - drawTextXOffset,
y + insetAscent);
lt->selection.cursor = lt->cursor;
lt->clearSelection(bv);
finishUndo();
showInsetCursor(bv);
updateLocal(bv, CURSOR, false);
// If the inset is empty set the language of the current font to the
// language to the surronding text (if different).
if (par->size() == 0 && !par->next() &&
bv->getParentLanguage(this) != lt->current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);
}
if (clear)
lt = 0;
}
void InsetText::edit(BufferView * bv, bool front)
{
UpdatableInset::edit(bv, front);
if (!bv->lockInset(this)) {
lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
return;
}
locked = true;
the_locking_inset = 0;
inset_pos = inset_x = inset_y = 0;
inset_boundary = false;
inset_par = 0;
old_par = 0;
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
if (front)
lt->setCursor(bv, par, 0);
else {
Paragraph * p = par;
while(p->next())
p = p->next();
lt->setCursor(bv, p, p->size()-1);
}
lt->clearSelection(bv);
finishUndo();
showInsetCursor(bv);
updateLocal(bv, CURSOR, false);
@ -1308,7 +1353,7 @@ void InsetText::toggleInsetCursor(BufferView * bv)
void InsetText::showInsetCursor(BufferView * bv, bool show)
{
if (the_locking_inset) {
the_locking_inset->showInsetCursor(bv);
the_locking_inset->showInsetCursor(bv, show);
return;
}
if (!isCursorVisible()) {
@ -1337,6 +1382,22 @@ void InsetText::hideInsetCursor(BufferView * bv)
}
void InsetText::fitInsetCursor(BufferView * bv) const
{
if (the_locking_inset) {
the_locking_inset->fitInsetCursor(bv);
return;
}
LyXFont const font =
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
int const asc = lyxfont::maxAscent(font);
int const desc = lyxfont::maxDescent(font);
bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
}
UpdatableInset::RESULT
InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
{
@ -1791,24 +1852,27 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
}
lyx::Assert(it->second.text.get());
deleteLyXText(bv, (the_locking_inset == 0) || force);
if (bv->screen()) {
LyXText * t = getLyXText(bv);
t->first = bv->screen()->topCursorVisible(t);
LyXText * t = it->second.text.get();
saveLyXTextState(t);
for (Paragraph * p = par; p; p = p->next()) {
p->resizeInsetsLyXText(bv);
}
// this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
t->init(bv, true);
restoreLyXTextState(bv, t);
if (the_locking_inset) {
/// then resize all LyXText in text-insets
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_y = cy(bv) + drawTextYOffset;
for (Paragraph * p = par; p; p = p->next()) {
p->resizeInsetsLyXText(bv);
}
}
need_update = FULL;
if (bv->screen()) {
t->first = bv->screen()->topCursorVisible(t);
}
if (!owner())
updateLocal(bv, FULL, false);
else
need_update = FULL;
// this will scroll the screen such that the cursor becomes visible
bv->updateScrollbar();
}
@ -2026,7 +2090,38 @@ void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
if (y_offset < 0)
y_offset = y;
if (need_update & SELECTION)
need_update = NONE;
bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
if (clear)
lt = 0;
}
bool InsetText::searchForward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
{
if (the_locking_inset)
if (the_locking_inset->searchForward(bv, str, cs, mw))
return true;
if (LyXFind(bv, str, true, true, cs , mw)) {
return true;
}
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<InsetText *>(this));
return false;
}
bool InsetText::searchBackward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
{
if (the_locking_inset)
if (the_locking_inset->searchBackward(bv, str, cs, mw))
return true;
if (LyXFind(bv, str, false, true, cs, mw)) {
return true;
}
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<InsetText *>(this));
return false;
}

View File

@ -107,6 +107,8 @@ public:
///
void edit(BufferView *, int, int, unsigned int);
///
void edit(BufferView *, bool front = true);
///
bool isTextInset() const { return true; }
///
bool doClearArea() const;
@ -150,6 +152,12 @@ public:
///
void toggleInsetCursor(BufferView *);
///
void showInsetCursor(BufferView *, bool show=true);
///
void hideInsetCursor(BufferView *);
///
void fitInsetCursor(BufferView *) const;
///
bool insertInset(BufferView *, Inset *);
///
bool insetAllowed(Inset::Code) const;
@ -221,11 +229,19 @@ public:
void selectSelectedWord(BufferView *);
void toggleSelection(BufferView *, bool kill_selection);
///
bool searchForward(BufferView *, string const &,
bool const & = true, bool const & = false);
bool searchBackward(BufferView *, string const &,
bool const & = true, bool const & = false);
//
// Public structures and variables
///
mutable int need_update;
protected:
///
void updateLocal(BufferView *, int what, bool mark_dirty);
void updateLocal(BufferView *, int what, bool mark_dirty) const;
///
mutable int drawTextXOffset;
///
@ -251,10 +267,6 @@ private:
///
int beginningOfMainBody(Buffer const *, Paragraph * par) const;
///
void showInsetCursor(BufferView *, bool show=true);
///
void hideInsetCursor(BufferView *);
///
UpdatableInset::RESULT moveRight(BufferView *,
bool activate_inset = true,
bool selecting = false);
@ -344,7 +356,7 @@ private:
///
UpdatableInset * the_locking_inset;
///
Paragraph * old_par;
mutable Paragraph * old_par;
/// The cache.
mutable Cache cache;
///

View File

@ -39,6 +39,12 @@ void InsetTOC::edit(BufferView * bv, int, int, unsigned int)
}
void InsetTOC::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
int InsetTOC::ascii(Buffer const * buffer, std::ostream & os, int) const
{
os << getScreenLabel() << "\n\n";

View File

@ -29,11 +29,13 @@ public:
virtual Inset * clone(Buffer const &, bool same_id = false) const {
return new InsetTOC(params(), same_id);
}
///
///
string const getScreenLabel() const;
///
void edit(BufferView * bv, int, int, unsigned int);
///
///
void edit(BufferView * bv, bool front = true);
///
EDITABLE editable() const { return IS_EDITABLE; }
///
bool display() const { return true; }

View File

@ -26,6 +26,12 @@ void InsetUrl::edit(BufferView * bv, int, int, unsigned int)
}
void InsetUrl::edit(BufferView * bv, bool)
{
edit(bv, 0, 0, 0);
}
string const InsetUrl::getScreenLabel() const
{
string temp;

View File

@ -26,7 +26,7 @@ public:
///
explicit
InsetUrl(InsetCommandParams const &, bool same_id = false);
///
///
virtual Inset * clone(Buffer const &, bool same_id = false) const {
return new InsetUrl(params(), same_id);
}
@ -40,11 +40,13 @@ public:
EDITABLE editable() const { return IS_EDITABLE; }
///
void edit(BufferView *, int, int, unsigned int);
///
///
void edit(BufferView * bv, bool front = true);
///
bool display() const { return false; }
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///

View File

@ -14,97 +14,147 @@
#include "buffer.h"
#include "gettext.h"
// declare local prototypes here so they cannot be used without hack
// externally and also we won't see them in the lyxfind.h file so we
// know this are internal files!
///
// locally used enum
///
enum SearchResult {
//
SR_NOT_FOUND = 0,
//
SR_FOUND,
//
SR_FOUND_NOUPDATE
};
/// returns true if the specified string is at the specified position
bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
string const & str, bool const & = true,
bool const & = false);
/// if the string is found: return true and set the cursor to the new position
SearchResult SearchForward(BufferView *, LyXText * text, string const & str,
bool const & = true, bool const & = false);
///
SearchResult SearchBackward(BufferView *, LyXText * text, string const & str,
bool const & = true, bool const & = false);
int LyXReplace(BufferView * bv,
string const & searchstr,
string const & replacestr,
bool const & casesens,
bool const & matchwrd,
bool const & forward,
bool const & replaceall)
string const & searchstr, string const & replacestr,
bool const & forward, bool const & casesens,
bool const & matchwrd, bool const & replaceall)
{
int replace_count = 0;
if (!bv->available() || bv->buffer()->isReadonly())
return replace_count;
if (!bv->available() || bv->buffer()->isReadonly())
return 0;
// CutSelection cannot cut a single space, so we have to stop
// in order to avoid endless loop :-(
if (searchstr.length() == 0
|| (searchstr.length() == 1 && searchstr[0] == ' ')) {
WriteAlert(_("Sorry!"), _("You cannot replace a single space, "
"nor an empty character."));
return replace_count;
}
// now we can start searching for the first
// start at top if replaceall
bool fw = forward;
if (replaceall) {
bv->text->clearSelection(bv);
bv->text->cursorTop(bv);
// override search direction because we search top to bottom
fw = true;
}
// CutSelection cannot cut a single space, so we have to stop
// in order to avoid endless loop :-(
if (searchstr.length() == 0
|| (searchstr.length() == 1 && searchstr[0] == ' '))
{
WriteAlert(_("Sorry!"), _("You cannot replace a single space, "
"nor an empty character."));
return 0;
}
LyXText * text = bv->getLyXText();
// if nothing selected or selection does not equal search string
// search and select next occurance and return if no replaceall
if (searchstr!=bv->text->selectionAsString(bv->buffer())) {
LyXFind(bv, searchstr, casesens, matchwrd, fw);
if (!replaceall)
// now we can start searching for the first
// start at top if replaceall
bool fw = forward;
if (replaceall) {
text->clearSelection(bv);
if (text->inset_owner) {
bv->unlockInset(bv->theLockingInset());
text = bv->text;
}
text->cursorTop(bv);
// override search direction because we search top to bottom
fw = true;
}
// if nothing selected or selection does not equal search string
// search and select next occurance and return if no replaceall
if (searchstr!=text->selectionAsString(bv->buffer())) {
if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) ||
!replaceall)
{
return 0;
}
}
bool found;
int replace_count = 0;
do {
bv->hideCursor();
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection(false);
bv->getLyXText()->replaceSelectionWithString(bv, replacestr);
bv->getLyXText()->setSelectionOverString(bv, replacestr);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
++replace_count;
found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
} while (replaceall && found);
if (bv->focus())
bv->showCursor();
return replace_count;
}
bool found;
do {
bv->hideCursor();
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection(false);
bv->text->replaceSelectionWithString(bv, replacestr);
bv->text->setSelectionOverString(bv, replacestr);
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
++replace_count;
found = LyXFind(bv, searchstr, casesens, matchwrd, fw);
} while (replaceall && found);
if (bv->focus())
bv->showCursor();
return replace_count;
}
bool LyXFind(BufferView * bv,
string const & searchstr,
bool const & casesens,
bool const & matchwrd,
bool const & forward)
string const & searchstr, bool const & forward,
bool const & frominset,
bool const & casesens, bool const & matchwrd)
{
bool found = false;
if (!bv->available() || searchstr.empty())
return found;
if (!bv->available() || searchstr.empty())
return false;
LyXText * text = bv->getLyXText();
bv->hideCursor();
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
LyXText * ltCur = bv->text;
if (ltCur->selection.set())
ltCur->cursor = forward ? ltCur->selection.end
: ltCur->selection.start;
bv->hideCursor();
bv->update(text, BufferView::SELECT|BufferView::FITCUR);
if (text->selection.set())
text->cursor = forward ?
text->selection.end : text->selection.start;
if (forward
? SearchForward(bv, searchstr, casesens, matchwrd)
: SearchBackward(bv, searchstr, casesens, matchwrd)) {
bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection();
bv->text->clearSelection(bv);
bv->text->setSelectionOverString(bv, searchstr);
bv->toggleSelection(false);
found = true;
};
SearchResult result = SR_NOT_FOUND;
if (!frominset && bv->theLockingInset()) {
bool found = forward ?
bv->theLockingInset()->searchForward(bv, searchstr, casesens, matchwrd) :
bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
if (found)
result = SR_FOUND_NOUPDATE;
} else {
result = forward ?
SearchForward(bv, text, searchstr, casesens, matchwrd) :
SearchBackward(bv, text, searchstr, casesens, matchwrd);
}
bool found = true;
if (result == SR_FOUND) {
// the actual text pointer could have changed!
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection();
bv->getLyXText()->clearSelection(bv);
bv->getLyXText()->setSelectionOverString(bv, searchstr);
bv->toggleSelection(false);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
} else if (result == SR_NOT_FOUND)
found = false;
if (bv->focus())
bv->showCursor();
if (bv->focus())
bv->showCursor();
return found;
return found;
}
@ -121,18 +171,20 @@ bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
while (((pos + i) < par->size())
&& (string::size_type(i) < size)
&& (cs ? (str[i] == par->getChar(pos + i))
: (toupper(str[i]) == toupper(par->getChar(pos + i)))))
: (toupper(str[i]) == toupper(par->getChar(pos + i)))))
{
++i;
}
if (size == string::size_type(i)) {
// if necessary, check whether string matches word
if (!mw ||
(mw && ((pos <= 0 || !IsLetterCharOrDigit(par->getChar(pos - 1)))
&& (pos + Paragraph::size_type(size) >= par->size()
|| !IsLetterCharOrDigit(par->getChar(pos + size))))
))
return true;
// if necessary, check whether string matches word
if (!mw ||
(mw && ((pos <= 0 || !IsLetterCharOrDigit(par->getChar(pos - 1)))
&& (pos + Paragraph::size_type(size) >= par->size()
|| !IsLetterCharOrDigit(par->getChar(pos + size))))
))
{
return true;
}
}
return false;
}
@ -140,13 +192,25 @@ bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
// forward search:
// if the string can be found: return true and set the cursor to
// the new position, cs = casesensitive, mw = matchword
bool SearchForward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
bool const & cs, bool const & mw)
{
Paragraph * par = bv->text->cursor.par();
Paragraph::size_type pos = bv->text->cursor.pos();
Paragraph * par = text->cursor.par();
Paragraph::size_type pos = text->cursor.pos();
UpdatableInset * inset;
while (par && !IsStringInText(par, pos, str, cs, mw)) {
if (par->isInset(pos) &&
(inset = (UpdatableInset *)par->getInset(pos)) &&
(inset->isTextInset()))
{
// lock the inset!
text->setCursor(bv, par, pos);
inset->edit(bv);
if (inset->searchForward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE;
text = bv->getLyXText();
}
if (pos < par->size() - 1)
++pos;
else {
@ -155,22 +219,39 @@ bool SearchForward(BufferView * bv, string const & str,
}
}
if (par) {
bv->text->setCursor(bv, par, pos);
return true;
}
else
return false;
text->setCursor(bv, par, pos);
return SR_FOUND;
} else if (text->inset_owner) {
// test if we're inside an inset if yes unlock the inset
// and recall us with the outside LyXText!
bv->unlockInset((UpdatableInset *)text->inset_owner);
text = bv->getLyXText();
par = text->cursor.par();
pos = text->cursor.pos();
if (pos < par->size() - 1)
++pos;
else {
pos = 0;
par = par->next();
}
if (!par)
return SR_NOT_FOUND;
text->setCursor(bv, par, pos);
return SearchForward(bv, text, str, cs, mw);
} else
return SR_NOT_FOUND;
}
// backward search:
// if the string can be found: return true and set the cursor to
// the new position, cs = casesensitive, mw = matchword
bool SearchBackward(BufferView * bv, string const & str,
bool const & cs, bool const & mw)
SearchResult SearchBackward(BufferView * bv, LyXText * text,
string const & str,
bool const & cs, bool const & mw)
{
Paragraph * par = bv->text->cursor.par();
Paragraph::size_type pos = bv->text->cursor.pos();
Paragraph * par = text->cursor.par();
Paragraph::size_type pos = text->cursor.pos();
do {
if (pos > 0)
@ -183,12 +264,30 @@ bool SearchBackward(BufferView * bv, string const & str,
pos = par->size() - 1;
} while (par && pos < 0);
}
UpdatableInset * inset;
if (par && par->isInset(pos) &&
(inset = (UpdatableInset *)par->getInset(pos)) &&
(inset->isTextInset()))
{
// lock the inset!
text->setCursor(bv, par, pos);
inset->edit(bv, false);
if (inset->searchBackward(bv, str, cs, mw))
return SR_FOUND_NOUPDATE;
text = bv->getLyXText();
}
} while (par && !IsStringInText(par, pos, str, cs, mw));
if (par) {
bv->text->setCursor(bv, par, pos);
return true;
} else
return false;
text->setCursor(bv, par, pos);
return SR_FOUND;
} else if (text->inset_owner) {
// test if we're inside an inset if yes unlock the inset
// and recall us with the outside LyXText!
bv->unlockInset((UpdatableInset *)text->inset_owner);
return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
} else {
return SR_NOT_FOUND;
}
}

View File

@ -12,22 +12,12 @@
class BufferView;
int LyXReplace(BufferView * bv, string const &, string const &,
bool const &, bool const &, bool const &, bool const & = false);
bool LyXFind(BufferView * bv, string const &, bool const &, bool const &,
bool const &);
/// returns true if the specified string is at the specified position
bool IsStringInText(Paragraph * par, Paragraph::size_type pos,
string const & str, bool const & = true,
bool const & = false);
/// if the string is found: return true and set the cursor to the new position
bool SearchForward(BufferView *, string const & str, bool const & = true,
bool const & = false);
///
bool SearchBackward(BufferView *, string const & str, bool const & = true,
bool const & = false);
bool const &, bool const & = true, bool const & = false,
bool const & = false);
bool LyXFind(BufferView *,
string const & searchstr, bool const & forward,
bool const & frominset = false,
bool const & casesens = true, bool const & matchwrd = false);
#endif

View File

@ -918,34 +918,11 @@ string const LyXFunc::dispatch(int ac,
} else {
searched_string = last_search;
}
if (!searched_string.empty() &&
((action == LFUN_WORDFINDBACKWARD) ?
SearchBackward(owner->view(), searched_string) :
SearchForward(owner->view(), searched_string))) {
// ??? What is that ???
owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
// ??? Needed ???
// clear the selection (if there is any)
owner->view()->toggleSelection();
TEXT()->clearSelection(owner->view());
// Move cursor so that successive C-s 's will not stand in place.
if (action == LFUN_WORDFINDFORWARD )
TEXT()->cursorRightOneWord(owner->view());
finishUndo();
moveCursorUpdate(true, false);
// ??? Needed ???
// set the new selection
// SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected);
owner->view()->toggleSelection(false);
bool fw = (action == LFUN_WORDFINDBACKWARD);
if (!searched_string.empty()) {
LyXFind(owner->view(), searched_string, fw);
}
// REMOVED : if (owner->view()->getWorkArea()->focus)
owner->view()->showCursor();
// owner->view()->showCursor();
}
break;

View File

@ -63,7 +63,7 @@ public:
/// Destructor
~LyXText();
void init(BufferView *);
void init(BufferView *, bool reinit = false);
///
mutable int number_of_rows;
///

View File

@ -318,6 +318,13 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int)
}
void InsetFormulaBase::edit(BufferView * bv, bool front)
{
#warning Please have a look if this is right (Jug)
edit(bv, front ? 0 : 1, 0, 0);
}
void InsetFormulaBase::insetUnlock(BufferView * bv)
{
if (mathcursor) {

View File

@ -87,6 +87,7 @@ public:
virtual string const editMessage() const;
///
virtual void edit(BufferView *, int x, int y, unsigned int button);
virtual void edit(BufferView *, bool front = true);
///
virtual void toggleInsetCursor(BufferView *);
///

View File

@ -763,7 +763,7 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
.textclass)
.defaultfont());
else if (layout.labeltype == LABEL_BIBLIO) {
// ale970405 Right width for bibitems
// ale970405 Right width for bibitems
x += bibitemMaxWidth(bview,textclasslist
.TextClass(bview->buffer()->params
.textclass)
@ -2276,9 +2276,10 @@ string const LyXText::selectNextWord(BufferView * bview,
cursor.par()->isInset(cursor.pos()))
{
// lock the inset!
cursor.par()->getInset(cursor.pos())->edit(bview, 0, 0, 0);
cursor.par()->getInset(cursor.pos())->edit(bview);
// now call us again to do the above trick
return selectNextWord(bview, value);
// but obviously we have to start from down below ;)
return bview->text->selectNextWord(bview, value);
}
// Update the value if we changed paragraphs
@ -3626,7 +3627,7 @@ int LyXText::getColumnNearX(BufferView * bview, Row * row, int & x,
// returns pointer to a specified row
Row * LyXText::getRow(Paragraph * par,
Paragraph::size_type pos, int & y) const
Paragraph::size_type pos, int & y) const
{
if (!firstrow)
return 0;

View File

@ -65,9 +65,21 @@ LyXText::LyXText(InsetText * inset)
copylayouttype(0)
{}
void LyXText::init(BufferView * bview)
void LyXText::init(BufferView * bview, bool reinit)
{
if (firstrow)
if (reinit) {
// Delete all rows, this does not touch the paragraphs!
Row * tmprow = firstrow;
while (firstrow) {
tmprow = firstrow->next();
delete firstrow;
firstrow = tmprow;
}
lastrow = refresh_row = need_break_row = 0;
width = height = copylayouttype = 0;
number_of_rows = first = refresh_y = 0;
status_ = LyXText::UNCHANGED;
} else if (firstrow)
return;
Paragraph * par = ownerParagraph();
@ -271,7 +283,7 @@ void LyXText::setCharFont(Buffer const * buf, Paragraph * par,
// inserts a new row behind the specified row, increments
// the touched counters
void LyXText::insertRow(Row * row, Paragraph * par,
Paragraph::size_type pos) const
Paragraph::size_type pos) const
{
Row * tmprow = new Row;
if (!row) {
@ -343,10 +355,10 @@ void LyXText::removeParagraph(Row * row) const
// insert the specified paragraph behind the specified row
void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
Row * row) const
Row * row) const
{
insertRow(row, par, 0); /* insert a new row, starting
* at postition 0 */
insertRow(row, par, 0); /* insert a new row, starting
* at postition 0 */
setCounter(bview->buffer(), par); // set the counters
@ -363,7 +375,7 @@ void LyXText::insertParagraph(BufferView * bview, Paragraph * par,
Inset * LyXText::getInset() const
{
Inset * inset = 0;
if (cursor.pos() == 0 && cursor.par()->bibkey){
if (cursor.pos() == 0 && cursor.par()->bibkey) {
inset = cursor.par()->bibkey;
} else if (cursor.pos() < cursor.par()->size()
&& cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
@ -953,7 +965,7 @@ void LyXText::clearSelection(BufferView * /*bview*/) const
{
selection.set(false);
selection.mark(false);
selection.end = selection.start = cursor;
selection.end = selection.start = selection.cursor = cursor;
}