Commit Graph

3125 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
5d7dae9e38 Set cursor properly after double/triple click in mathed
Without this setCurrentFont() is not correctly called on the
BufferView cursor and the cursor could appear in L-form.

Fixes bug #10686.
2017-06-12 18:02:39 +02:00
Jean-Marc Lasgouttes
95c6781112 Improvements to inset edit markers
Draw also upper markers when editing macros in MACRO_EDIT_INLINE_BOX mode.

Use MARKER2 for inline editing of macros.
2017-06-12 17:09:58 +02:00
Jean-Marc Lasgouttes
f6b0ccf99c Use proper markers for display version of the math macro template.
This avoids ghost white corners when the macro does not have a display
version.

Part of bug #8883.
2017-06-12 15:15:55 +02:00
Jean-Marc Lasgouttes
183c97d8a8 Give a 2 pixels space for markers around math objects
This is necessary when markers are nested. Ideally this should only be
done when there is risk of nesting.

Fixes (part of?) bug #10688.
2017-06-09 11:58:26 +02:00
Jean-Marc Lasgouttes
1538a8352c Revert "Give a 2 pixels space for markers around math objects"
This is not ready yet.

This reverts commit 5a3962958f.
2017-06-08 16:46:19 +02:00
Jean-Marc Lasgouttes
29fbd062cc Properly use top/bottom edit marker for grid inset
This was an oversight when marker() was introduced.

Fixes part of #10688.
2017-06-08 16:03:14 +02:00
Jean-Marc Lasgouttes
5a3962958f Give a 2 pixels space for markers around math objects 2017-06-08 15:22:03 +02:00
Jean-Marc Lasgouttes
b58dcff836 Let command inset honor inheritFont() on screen
The RenderButton object now has a inherit_font_ property. It is set
depending on the value of Inset::inheritFont().

This is a better fix than 55533804, which caused bugs #10682 and #10677.

Fixes bug #10258
2017-05-24 11:33:52 +02:00
Jean-Marc Lasgouttes
3f34ebbaf9 Revert "Add possibility for command inset to inherit enclosing font"
The new method was badly named, it was not supposed to override the
existing inheritFont.

Fixes bug #10682.

This reverts commit 555338048d.
2017-05-24 11:25:14 +02:00
Jean-Marc Lasgouttes
f1dd80f464 Proper GUI feedback for leqno option
With these changes, equation numbers are shown properly on screen.
When setting is default, we guess the side using these two rules

* ams(art|book) and siamltex classes are leqno by default. This is
  signalled because the classes provide "leqno" (in amsdefs.inc). If
  there are other classes that do this in output, the relevant classes
  should be updated.

* the language arabic_arabi also sets leqno by default. This is
  currently hardcoded for lack of a better idea.

Besides, a few bugs are fixed:
* use mathrm instead of mathbf for numbers metrics
* set spacing between maths and labels in inches
2017-05-12 15:32:14 +02:00
Jean-Marc Lasgouttes
fa2dcd37a2 Show properly on screen "indented" maths.
This is done by two things:
1/ the equation returns LefAlign as display() value

2/ Inset::indent() return a value (in general 0) that should be added
   on the left (or right in rtl) of the inset when it is flushed.

The code that uses these values is in TextMetrics::computeRowMetrics.
2017-05-03 14:46:05 +02:00
Guillaume MM
4fc8c7fedd MathAtom: prefer composition over inheritance 2017-04-20 23:49:02 +02:00
Guillaume MM
b382b246b6 MathAtom is a unique_ptr
Fix coverity suggestion of defining a move constructor
2017-04-07 23:31:34 +02:00
Jean-Marc Lasgouttes
7b0e732eeb Check both lower and upper bound for tainted loop limit
In these cases, the lower bound is not that important, but coverity insists on it.
2017-04-05 11:36:40 +02:00
Enrico Forestieri
66aa52ff20 Fix bug #10581
Tell the math parser that we are parsing a macro definition, so that
it doesn't try to return a verbatim copy in case of failure.
2017-04-03 00:26:49 +02:00
Jean-Marc Lasgouttes
758de9577d Improve drawing of math roots (\sqrt and \root)
This is preliminary work to make roots look more like in TeX output:

* correct font size for root order

* set minimum size of the root from the max ascent descent of the
  font. This is what TeX does.

* fix drawing, and in particular horizontal size.

More needs to be done, in particular:

* handle zooming and dpi correctly by removing hardcoded pixel values.

* factor the code for the two types of roots in one.
2017-03-31 18:55:08 +02:00
Jean-Marc Lasgouttes
555338048d Add possibility for command inset to inherit enclosing font
The RenderButton object now has this property. It is set depending on
the value of inheritFont() method that is currently only set for
InsetRef, InsetBibtex and InsetCitation.

Fixes bug #10258
2017-03-28 13:57:34 +02:00
Jean-Marc Lasgouttes
31cd421bcd Limit multirow to 100 columns in mathed
Spotted by coverity, this avoids a blocking loop when parsing.
2017-03-28 11:43:12 +02:00
Jean-Marc Lasgouttes
bc7704a78e Limit the amount of derivatives in external CAS
The (arbitrary) limit is 1000.

Pointed out by coverity. A bad value could lock LyX.
2017-03-28 11:17:35 +02:00
Jean-Marc Lasgouttes
4ea0fd6af4 Two places where coverity urges us to limit string length
These two issues make sense, but there are probably others.
2017-03-24 15:27:22 +01:00
Jean-Marc Lasgouttes
f5fe3c17be Reduce horizontal spacing for simple inline equations 2017-03-24 10:22:32 +01:00
Jean-Marc Lasgouttes
a48581f48c Linearize macros in box edit mode too.
The special mode used by macros where the macro name is displayed as
grey text in a box is now one of the possible marker types for any
inset. The new code puts the macro name below the text, which means
that only the text below the current line will be moved. This makes
edition much more comfortable. The grey border around the contents has
been removed too.

The marker_type enum has been moved from Inset to InsetMath. A
markerMargin() function returns the horizontal margin required on each
side for the marker. Only the corner-type markers MARKER and MARKER2
need some.

A new BOX_MARKER enum value has been added and is taken care of in
afterMetricsMarkers (renamed from metricsMarkerVertical) and
drawMarkers.

The InsetMath::marker() macro now takes a BufferView pointer as
argument, so that the marker type can depend on editing state.

MathRow::metrics now makes changes to the MathRow object when needed.

The specific metrics/draw code in MathMacro has been removed and
replaced by assertions. Code in addToMathRow and marker is adapted to
reflect the cases where linearization is possible.
2017-03-23 10:17:07 +01:00
Jean-Marc Lasgouttes
b8c0891427 Remove optimization that avoids drawing some math inset cells.
It is not clear that the optimization is a gain, but it is clear that
it has a cost: some elements of formulas will not be present in the
position cache.

Fixes bug #10520.
2017-03-13 11:44:48 +01:00
Jean-Marc Lasgouttes
a69bae0c99 Make InsetMathNest::editXY more robust
If no reasonable cell has been found to put the cursor in (maybe
because the cell exist but is not in the cache), exit gracefully.

Fixes bug #10520
2017-03-13 11:44:22 +01:00
Jean-Marc Lasgouttes
9a013637bb Experiment: limit size of strings read from lib/symbols
Coverity complains that we might read strings that are arbitrary
large, and that this can be a security issue. This is a problem in
particular, when we feed these strings to from_utf8(), which coverity
flags as dangerous for some reason.

The best solution would be IMO to model from_utf8() properly, but I do
not know how to do that. Here I try a different solution, where I
cannot read a string larger than 64k from the file.

Let's see whether this removes part of coverity warnings.
2017-03-10 16:29:09 +01:00
Jean-Marc Lasgouttes
ce0c11ba4e Remove unreachable return statements
They were needed long ago to avoid gcc warnings, but now all they do
is create coverity warnings.
2017-03-09 15:05:33 +01:00
Jean-Marc Lasgouttes
000dcb8672 Make a false positive explicit
Pleases coverity
2017-03-08 16:50:03 +01:00
Jean-Marc Lasgouttes
25d64bf43a Fix test to make coverity happy
It is not obvious that cur is not null iff thisSlice is not -1, but
this is what happens in the caller.
2017-03-07 11:56:59 +01:00
Jean-Marc Lasgouttes
55957c4576 Fix test to make coverity happy
It is not obvious that cur is not null iff thisSlice is not -1, but
this is what happens in the caller.
2017-03-07 11:48:32 +01:00
Jean-Marc Lasgouttes
5ad8815a51 Please coverity properly 2017-03-02 14:47:31 +01:00
Jean-Marc Lasgouttes
9251a360a9 Initialize class member to please coverity 2017-03-01 16:31:00 +01:00
Jean-Marc Lasgouttes
d2ad9ae6e2 Rewrite selection code in mathed
Now the selection is not done by the inset, but by the MathData
itself. This allows for some code simplification and avoids an
extra redraw.

Additionally, this fixes the selection inside macros, which was broken
by the new MathRow code.
2017-02-22 11:00:30 +01:00
Jean-Marc Lasgouttes
1c1b3519f9 Use a plain font in macro edit box
Without this, the font would be mathcal in a mathcal environment.
Additionally, set the font size to tiny when computing metrics too.
2017-02-21 11:49:12 +01:00
Jean-Marc Lasgouttes
b9d45e5ef6 Set the cursor a bit on the left in empty cells 2017-02-21 09:53:52 +01:00
Jean-Marc Lasgouttes
fc02744119 Revert "Linearize macros in box edit mode too."
Guillaume tells me that there are problems. We'll return to it later.

This reverts commit 0140348118.
2017-02-21 05:43:38 +01:00
Guillaume Munch
7337c968b3 Fix InsetMathRef mouse behaviour (#10568)
Fix mouse-selection behaviour.

Don't open dialog when releasing if it was not a real click.
2017-02-18 23:03:54 +01:00
Guillaume Munch
63be456c8d When pressing math with the mouse, move to the closest edge (#9748)
Unless it has some dialog that we want to activate.
2017-02-18 23:03:54 +01:00
Guillaume Munch
faeb199793 When selecting math with the mouse, selection happens in the middle (#9748) 2017-02-18 23:03:54 +01:00
Guillaume Munch
86d9abeea7 Move cursor in front of InsetMathSpace before opening the dialog (#7749) 2017-02-18 23:03:53 +01:00
Guillaume Munch
71623b88b2 Generalise the deletion protection mechanism from math to text (#9540)
Now backspace and delete in text will select non-empty math and text insets
before deleting them. This is consistent with what happens in math already.

This is implemented for InsetText as well but can be disabled in case of
negative feedback.

This can be set for any sort of inset with the new virtual method
Inset::confirmDeletion.

New option "force" for the LFUN_*_DELETE_* commands, that bypasses the
confirmDeletion check.
2017-02-18 23:03:23 +01:00
Jean-Marc Lasgouttes
0140348118 Linearize macros in box edit mode too.
The special mode used by macros where the macro name is displayed as
grey text in a box is now one of the possible marker types for any
inset. The new code puts the macro name below the text, which means
that only the text below the current line will be moved. This makes
edition much more comfortable.

The marker_type enum has been moved from Inset to InsetMath.

A new BOX_MARKER enum value has been added and is taken care of in
afterMetricsMarkers (renamed from metricsMarkerVertical) and
drawMarkers.

The InsetMath::marker() macro now takes a BufferView pointer as
argument, so that the marker type can depend on editing state.

MathRow::metrics now makes changes to the MathRow object when needed.

The specific metrics/draw code in MathMacro has been removed and
replaced by assertions. Code in addToMathRow and marker is adapted to
reflect the cases where linearization is possible.
2017-02-14 01:02:00 +01:00
Guillaume Munch
527cc8ca9c Disable InsetMathKern with invalid lengths (#10539)
From now on \kern and \mkern remain as ERT as long as the length is invalid.

Fixes #10539 (regression at 10c8d51b).

The only way to produce an InsetMathKern now is via parsing (i.e. file opening
or copy-paste). This is because there has never been any sensible way to input a
valid InsetMathKern, but this is another issue.
2017-02-11 21:52:09 +01:00
Jean-Marc Lasgouttes
ace5dc157c Compilation fix: missing header for std::max 2017-02-07 11:43:06 +01:00
Jean-Marc Lasgouttes
6763301c05 Better fix for cursor in "blue box"
Since in InsetMathNest::cursorPos we do not know what is the value of
the row element before value of a given BOX, it does not make sense to
set the cursor at a given offset from the start of the MathData
object.

Therefore here we set the cursor in the middle of the MathData object,
which unfortunately may or may not be visually centered wrt the BOX.

The best solution would be to use the MathRow data here, but
unfortunately this is not completely trivial.

This patch replaces 7917ebcc4.
2017-02-06 17:23:00 +01:00
Jean-Marc Lasgouttes
e12b27e16b Some clean-up to markers handling code.
Horizontal space is now added for linearized macros too.

Vertical space handling is done in a separate method.

This is in preparation for handling of 'box' macro editing mode in
MathRow.
2017-02-06 17:17:56 +01:00
Jean-Marc Lasgouttes
7917ebcc40 Fix cursor positionning in empty math arrays (blue box) 2017-02-06 11:59:39 +01:00
Jean-Marc Lasgouttes
ad79ac406f Fixup 89662a68: remove markers that should not be there
InsetMathDelim does not need markers because the delimiters are
visually enough.

CommandInset (like InsetMathRef) does have cells, but they are hidden
(only for storage). Therefore the default InsetMath::markers() method
mistakenly added markers. In practice, the markers were never active
(since the cursor cannot go into the inset), but some space was
reserved for them.
2017-02-03 10:52:53 +01:00
Jean-Marc Lasgouttes
e0024231d3 Fix drawing of rectangle in old-style macro editing mode
The width was a bit to short.
2017-02-02 14:33:38 +01:00
Jean-Marc Lasgouttes
ec676a1dec Make MathRow tokens completely generic
The enum values BEG_MACRO/END_MACRO and BEG_AR/END_AR are replaced by a
single BEGIN/END pair.

The MathRow code now only knows about insets and math arrays.
2017-02-01 17:46:53 +01:00
Jean-Marc Lasgouttes
6c13af3f29 Introduce hooks to encapsulate macro code of MathRow
New hooks (before|after)(Metrics|Draw) are run by the MathRow code
as needed. They are actually also used internally by the MathMacro
code.

The gain is that most traces of explicit macro handling (and
the MathRow::Element::macro member) have been removed from MathRw.cpp.

The next step will be to extend the tokenizing process to allow for
linearizing insets other than macros.
2017-02-01 15:20:06 +01:00