-void BufferView::workAreaButtonRelease(int x, int y, unsigned int button)
-{
- if (buffer_ == 0 || screen == 0) return;
-
- // If we hit an inset, we have the inset coordinates in these
- // and inset_hit points to the inset. If we do not hit an
- // inset, inset_hit is 0, and inset_x == x, inset_y == y.
- Inset * inset_hit = checkInsetHit(x, y, button);
-
- if (the_locking_inset) {
- // We are in inset locking mode.
-
- /* LyX does a kind of work-area grabbing for insets.
- Only a ButtonPress Event outside the inset will
- force a InsetUnlock. */
- the_locking_inset->
- InsetButtonRelease(this, x, y, button);
- return;
- }
-
- selection_possible = false;
- if (text->cursor.par->table) {
- int cell = text->
- NumberOfCell(text->cursor.par,
- text->cursor.pos);
- if (text->cursor.par->table->IsContRow(cell) &&
- text->cursor.par->table->
- CellHasContRow(text->cursor.par->table->
- GetCellAbove(cell))<0) {
- text->CursorUp();
- }
- }
-
- if (button >= 2) return;
-
- setState();
- owner_->getMiniBuffer()->Set(CurrentState());
-
- // Did we hit an editable inset?
- if (inset_hit != 0) {
- // Inset like error, notes and figures
- selection_possible = false;
-#ifdef WITH_WARNINGS
-#warning fix this proper in 0.13
-#endif
- // Following a ref shouldn't issue
- // a push on the undo-stack
- // anylonger, now that we have
- // keybindings for following
- // references and returning from
- // references. IMHO though, it
- // should be the inset's own business
- // to push or not push on the undo
- // stack. They don't *have* to
- // alter the document...
- // (Joacim)
- // ...or maybe the SetCursorParUndo()
- // below isn't necessary at all anylonger?
- if (inset_hit->LyxCode() == Inset::REF_CODE) {
- text->SetCursorParUndo();
- }
-
- owner_->getMiniBuffer()->Set(inset_hit->EditMessage());
- if (inset_hit->Editable()==Inset::HIGHLY_EDITABLE) {
- // Highly editable inset, like math
- UpdatableInset *inset = (UpdatableInset *)inset_hit;
- inset->InsetButtonRelease(this, x, y, button);
- } else {
- inset_hit->Edit(this, x, y, button);
- }
- return;
- }
-
- // check whether we want to open a float
- if (text) {
- bool hit = false;
- char c = ' ';
- if (text->cursor.pos <
- text->cursor.par->Last()) {
- c = text->cursor.par->
- GetChar(text->cursor.pos);
- }
- if (c == LyXParagraph::META_FOOTNOTE
- || c == LyXParagraph::META_MARGIN
- || c == LyXParagraph::META_FIG
- || c == LyXParagraph::META_TAB
- || c == LyXParagraph::META_WIDE_FIG
- || c == LyXParagraph::META_WIDE_TAB
- || c == LyXParagraph::META_ALGORITHM){
- hit = true;
- } else if (text->cursor.pos - 1 >= 0) {
- c = text->cursor.par->
- GetChar(text->cursor.pos - 1);
- if (c == LyXParagraph::META_FOOTNOTE
- || c == LyXParagraph::META_MARGIN
- || c == LyXParagraph::META_FIG
- || c == LyXParagraph::META_TAB
- || c == LyXParagraph::META_WIDE_FIG
- || c == LyXParagraph::META_WIDE_TAB
- || c == LyXParagraph::META_ALGORITHM){
- // We are one step too far to the right
- text->CursorLeft();
- hit = true;
- }
- }
- if (hit == true) {
- toggleFloat();
- selection_possible = false;
- return;
- }
- }
-
- // Do we want to close a float? (click on the float-label)
- if (text->cursor.row->par->footnoteflag ==
- LyXParagraph::OPEN_FOOTNOTE
- //&& text->cursor.pos == 0
- && text->cursor.row->previous &&
- text->cursor.row->previous->par->
- footnoteflag != LyXParagraph::OPEN_FOOTNOTE){
- LyXFont font(LyXFont::ALL_SANE);
- font.setSize(LyXFont::SIZE_FOOTNOTE);
-
- int box_x = 20; // LYX_PAPER_MARGIN;
- box_x += font.textWidth(" wide-tab ", 10);
-
- int screen_first = screen->first;
-
- if (x < box_x
- && y + screen_first > text->cursor.y -
- text->cursor.row->baseline
- && y + screen_first < text->cursor.y -
- text->cursor.row->baseline
- + font.maxAscent() * 1.2 + font.maxDescent() * 1.2) {
- toggleFloat();
- selection_possible = false;
- return;
- }
- }
-
- // Maybe we want to edit a bibitem ale970302
- if (text->cursor.par->bibkey && x < 20 +
- bibitemMaxWidth(painter(),
- textclasslist
- .TextClass(buffer_->
- params.textclass).defaultfont())) {
- text->cursor.par->bibkey->Edit(this, 0, 0, 0);
- }
-
- return;
-}
-
-
-/*
- * Returns an inset if inset was hit. 0 otherwise.
- * If hit, the coordinates are changed relative to the inset.
- * Otherwise coordinates are not changed, and false is returned.
- */
-Inset * BufferView::checkInsetHit(int & x, int & y, unsigned int button)
-{
- if (!screen)
- return 0;
-
- int y_tmp = y + screen->first;
-
- LyXCursor cursor;
- text->SetCursorFromCoordinates(cursor, x, y_tmp);
-#if 1
- bool move_cursor = true;
-#else
- bool move_cursor = ((cursor.par != text->cursor.par) ||
- (cursor.pos != text->cursor.pos)) && (button < 2);
-#endif
-
- if (cursor.pos < cursor.par->Last()
- && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET
- && cursor.par->GetInset(cursor.pos)
- && cursor.par->GetInset(cursor.pos)->Editable()) {
-
- // Check whether the inset really was hit
- Inset * tmpinset = cursor.par->GetInset(cursor.pos);
- LyXFont font = text->GetFont(cursor.par, cursor.pos);
- bool is_rtl = font.isVisibleRightToLeft();
- int start_x, end_x;
-
- if (is_rtl) {
- start_x = cursor.x - tmpinset->width(painter(), font);
- end_x = cursor.x;
- } else {
- start_x = cursor.x;
- end_x = cursor.x + tmpinset->width(painter(), font);
- }
-
- if (x > start_x && x < end_x
- && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
- && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
- if (move_cursor)
- text->SetCursorFromCoordinates(x, y_tmp);
- x = x - start_x;
- // The origin of an inset is on the baseline
- y = y_tmp - (text->cursor.y);
- return tmpinset;
- }
- }
-
- if ((cursor.pos - 1 >= 0) &&
- (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
- (cursor.par->GetInset(cursor.pos - 1)) &&
- (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
- Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
- LyXFont font = text->GetFont(cursor.par, cursor.pos-1);
- bool is_rtl = font.isVisibleRightToLeft();
- int start_x, end_x;
-
- if (!is_rtl) {
- start_x = cursor.x - tmpinset->width(painter(), font);
- end_x = cursor.x;
- } else {
- start_x = cursor.x;
- end_x = cursor.x + tmpinset->width(painter(), font);
- }
- if (x > start_x && x < end_x
- && y_tmp > cursor.y - tmpinset->ascent(painter(), font)
- && y_tmp < cursor.y + tmpinset->descent(painter(), font)) {
- if (move_cursor)
- text->SetCursorFromCoordinates(x, y_tmp);
- x = x - start_x;
- // The origin of an inset is on the baseline
- y = y_tmp - (text->cursor.y);
- return tmpinset;
- }
- }
- return 0;
-}
-
-void BufferView::workAreaExpose()