*
* Copyright 2000 The LyX Team.
*
- *======================================================
+ * ======================================================
*/
#include <config.h>
#include "LyXView.h"
#include "lyxfunc.h"
#include "insets/insettext.h"
-
-extern void MenuLayoutTabular(bool, InsetTabular *);
-extern bool UpdateLayoutTabular(bool, InsetTabular *);
-extern void TabularOptClose();
+#include "frontends/Dialogs.h"
const int ADD_TO_HEIGHT = 2;
const int ADD_TO_TABULAR_WIDTH = 2;
using std::ifstream;
using std::max;
using std::endl;
+using std::swap;
#define cellstart(p) ((p % 2) == 0)
actcell = 0;
cursor.pos(0);
sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
+ dialogs_ = 0;
need_update = INIT;
}
actcell = 0;
cursor.pos(0);
sel_pos_start = sel_pos_end = sel_cell_start = sel_cell_end = 0;
+ dialogs_ = 0;
need_update = INIT;
}
InsetTabular::~InsetTabular()
{
delete tabular;
+ if (dialogs_)
+ dialogs_->hideTabular(this);
}
int InsetTabular::descent(BufferView *, LyXFont const &) const
{
- return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0);
+ return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1;
}
float & x, bool cleared) const
{
Painter & pain = bv->painter();
- int i, j, cell=0;
+ int i, j, cell = 0;
int nx;
float cx;
UpdatableInset::draw(bv,font,baseline,x,cleared);
if (!cleared && ((need_update == INIT) || (need_update == FULL) ||
(top_x != int(x)) || (top_baseline != baseline))) {
-#if 1
int h = ascent(bv, font) + descent(bv, font);
- int tx = display()? 0:top_x;
+ int tx = display()||!owner()? 0:top_x;
int w = tx? width(bv, font):pain.paperWidth();
int ty = baseline - ascent(bv, font);
pain.fillRectangle(tx, ty, w, h);
need_update = FULL;
cleared = true;
-#else
- need_update = FULL;
- resetPos(pain);
- if (locked) { // repaint this way as the background was not cleared
- if (the_locking_inset)
- the_locking_inset->update(bv, font, true);
- locked = false;
- bv->updateInset(const_cast<InsetTabular*>(this), false);
- locked = true;
- return;
- }
-#endif
}
top_x = int(x);
top_baseline = baseline;
void InsetTabular::DrawCellSelection(Painter & pain, int x, int baseline,
int row, int column, int cell) const
{
- int tmp;
-
int cs = tabular->column_of_cell(sel_cell_start);
int ce = tabular->column_of_cell(sel_cell_end);
if (cs > ce) {
int rs = tabular->row_of_cell(sel_cell_start);
int re = tabular->row_of_cell(sel_cell_end);
- if (rs > re) {
- tmp = rs;
- rs = re;
- re = tmp;
- }
+ if (rs > re) swap(rs, re);
if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) {
int w = tabular->GetWidthOfColumn(cell);
}
-void InsetTabular::update(BufferView * bv, LyXFont const & font, bool dodraw)
+void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit)
{
+ if (reinit) {
+ need_update = INIT;
+ calculate_dimensions_of_cells(bv, font, true);
+ if (owner())
+ owner()->update(bv, font, true);
+ return;
+ }
if (the_locking_inset)
- the_locking_inset->update(bv, font, dodraw);
+ the_locking_inset->update(bv, font, reinit);
switch(need_update) {
case INIT:
case FULL:
case CELL:
- if (calculate_dimensions_of_cells(bv, font, dodraw))
+ if (calculate_dimensions_of_cells(bv, font, false))
need_update = INIT;
break;
case SELECTION:
void InsetTabular::InsetUnlock(BufferView * bv)
{
- TabularOptClose();
if (the_locking_inset) {
the_locking_inset->InsetUnlock(bv);
the_locking_inset = 0;
locked = false;
}
+
void InsetTabular::UpdateLocal(BufferView * bv, UpdateCodes what,
bool mark_dirty)
{
resetPos(bv);
}
+
bool InsetTabular::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
{
lyxerr[Debug::INSETS] << "InsetTabular::LockInsetInInset(" <<inset<< "): ";
return false;
}
+
bool InsetTabular::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
bool lr)
{
if ((inset->LyxCode() == TABULAR_CODE) &&
!the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))
{
- UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
+ dialogs_ = bv->owner()->getDialogs();
+ dialogs_->updateTabular(const_cast<InsetTabular *>(this));
oldcell = actcell;
}
return true;
return false;
}
+
bool InsetTabular::UpdateInsetInInset(BufferView * bv, Inset * inset)
{
if (!the_locking_inset)
}
-void InsetTabular::InsetButtonRelease(BufferView * bv,
- int x, int y, int button)
-{
- if (button == 3) {
- if (the_locking_inset) {
- UpdatableInset * i;
- if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
- i->InsetButtonRelease(bv, x, y, button);
- return;
- }
- }
- MenuLayoutTabular(true, this);
- return;
- }
- if (the_locking_inset) {
- the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
- return;
- }
- no_selection = false;
-}
-
-
void InsetTabular::InsetButtonPress(BufferView * bv, int x, int y, int button)
{
if (hasSelection()) {
ActivateCellInset(bv, x, y, button);
the_locking_inset->InsetButtonPress(bv, x-inset_x, y-inset_y, button);
}
-
+}
+
+
+void InsetTabular::InsetButtonRelease(BufferView * bv,
+ int x, int y, int button)
+{
+ if (button == 3) {
+ if (the_locking_inset) {
+ UpdatableInset * i;
+ if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
+ i->InsetButtonRelease(bv, x, y, button);
+ return;
+ }
+ }
+ dialogs_ = bv->owner()->getDialogs();
+ dialogs_->showTabular(this);
#if 0
- if (button == 3)
- bview->getOwner()->getPopups().showFormTabular();
- else if (ocell != actcell)
- bview->getOwner()->getPopups().updateFormTabular();
+ else if (ocell != actcell)
+ bview->getOwner()->getPopups().updateTabular();
#endif
+ return;
+ }
+ if (the_locking_inset) {
+ the_locking_inset->InsetButtonRelease(bv, x-inset_x, y-inset_y,button);
+ return;
+ }
+ no_selection = false;
}
resetPos(bv);
return result;
}
- result=DISPATCHED;
if ((action < 0) && arg.empty())
return FINISHED;
bool hs = hasSelection();
HideInsetCursor(bv);
+ result=DISPATCHED;
switch (action) {
// Normal chars not handled here
case -1:
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
- UpdateLocal(bv, CURSOR, false);
+ UpdateLocal(bv, SELECTION, false);
break;
case LFUN_LEFTSEL:
if (tabular->IsFirstCellInRow(actcell) && cellstart(cursor.pos()))
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
- UpdateLocal(bv, CURSOR, false);
+ UpdateLocal(bv, SELECTION, false);
break;
case LFUN_DOWNSEL:
{
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
- UpdateLocal(bv, CURSOR, false);
+ UpdateLocal(bv, SELECTION, false);
break;
case LFUN_UPSEL:
{
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
- UpdateLocal(bv, CURSOR, false);
+ UpdateLocal(bv, SELECTION, false);
break;
case LFUN_BACKSPACE:
break;
case LFUN_SHIFT_TAB:
case LFUN_TAB:
if (the_locking_inset) {
- the_locking_inset->InsetUnlock(bv);
+ UnlockInsetInInset(bv, the_locking_inset);
+ the_locking_inset = 0;
}
- the_locking_inset = 0;
if (action == LFUN_TAB)
moveNextCell(bv);
else
sel_pos_start = sel_pos_end = cursor.pos();
sel_cell_start = sel_cell_end = actcell;
if (hs)
- UpdateLocal(bv, CURSOR, false);
+ UpdateLocal(bv, SELECTION, false);
break;
case LFUN_LAYOUT_TABLE:
{
- int flag = (arg == "true");
- MenuLayoutTabular(flag, this);
+ dialogs_ = bv->owner()->getDialogs();
+ dialogs_->showTabular(this);
}
break;
default:
}
-int InsetTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
+int InsetTabular::Latex(Buffer const * buf, ostream & os,
+ bool fragile, bool fp) const
{
return tabular->Latex(buf, os, fragile, fp);
}
return 0;
}
+
int InsetTabular::Linuxdoc(Buffer const *, ostream &) const
{
return 0;
bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
LyXFont const & font,
- bool dodraw) const
+ bool reinit) const
{
int cell = -1;
int maxAsc, maxDesc;
continue;
++cell;
inset = tabular->GetCellInset(cell);
- inset->update(bv, font, dodraw);
+ if (!reinit)
+ inset->update(bv, font, false);
maxAsc = max(maxAsc, inset->ascent(bv, font));
maxDesc = max(maxDesc, inset->descent(bv, font));
changed = tabular->SetWidthOfCell(cell, inset->width(bv, font)) || changed;
resetPos(bv);
}
+
int InsetTabular::getCellXPos(int cell) const
{
int c;
ADD_TO_TABULAR_WIDTH);
}
+
void InsetTabular::resetPos(BufferView * bv) const
{
if (!locked)
if ((!the_locking_inset ||
!the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE)) &&
(actcell != oldcell)) {
- UpdateLayoutTabular(true, const_cast<InsetTabular *>(this));
+ dialogs_ = bv->owner()->getDialogs();
+ dialogs_->updateTabular(const_cast<InsetTabular *>(this));
oldcell = actcell;
}
}
}
}
+
bool InsetTabular::ActivateCellInset(BufferView * bv, int x, int y, int button,
bool behind)
{
return true;
}
+
bool InsetTabular::InsetHit(BufferView * bv, int x, int ) const
{
InsetText * inset = tabular->GetCellInset(actcell);
}
}
+
// This returns paperWidth() if the cell-width is unlimited or the width
// in pixels if we have a pwidth for this cell.
int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const
return VSpace(s).inPixels( 0, 0);
}
+
int InsetTabular::getMaxWidth(Painter & pain,
UpdatableInset const * inset) const
{
return w;
}
-void InsetTabular::recomputeTextInsets(BufferView * bv, const LyXFont & font) const
+
+void InsetTabular::recomputeTextInsets(BufferView * bv,
+ LyXFont const & font) const
{
InsetText * inset;
int cell;
// cx += tabular->GetWidthOfColumn(cell);
}
}
+
+
+void InsetTabular::resizeLyXText(BufferView *) const
+{
+ need_update = FULL;
+}