Ejemplo n.º 1
0
void CEditWnd::InsertText(LPCSTR text, int action)
{
	m_pTextBuffer->BeginUndoGroup();
    
	CPoint ptCursorPos;
  if (IsSelection ())
  {
		CPoint ptSelStart, ptSelEnd;
    GetSelection (ptSelStart, ptSelEnd);
    
    ptCursorPos = ptSelStart;
    
		m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_PASTE);
	}
  else ptCursorPos = GetCursorPos ();
	ASSERT_VALIDTEXTPOS (ptCursorPos);
      
  int x, y;
  m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, text, y, x, action);

  ptCursorPos.x = x;
  ptCursorPos.y = y;
  ASSERT_VALIDTEXTPOS (ptCursorPos);
  SetAnchor (ptCursorPos);
  SetSelection (ptCursorPos, ptCursorPos);
  SetCursorPos (ptCursorPos);
  EnsureVisible (ptCursorPos);
  m_pTextBuffer->FlushUndoGroup (this);
}
Ejemplo n.º 2
0
BOOL CEditWnd::ReplaceSelection (LPCTSTR pszNewText)
{
  if (!pszNewText)
    pszNewText = _T ("");

  CPoint ptCursorPos;
  if (IsSelection ())
	{
		CPoint ptSelStart, ptSelEnd;
		GetSelection (ptSelStart, ptSelEnd);
		ptCursorPos = ptSelStart;
		m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_REPLACE);
	}
  else ptCursorPos = GetCursorPos ();
  ASSERT_VALIDTEXTPOS (ptCursorPos);

  int x, y;
  m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, pszNewText, y, x, CE_ACTION_REPLACE);
  m_nLastReplaceLen = (int)_tcslen (pszNewText);
  CPoint ptEndOfBlock = CPoint (x, y);
  ASSERT_VALIDTEXTPOS (ptCursorPos);
  ASSERT_VALIDTEXTPOS (ptEndOfBlock);
  SetAnchor (ptEndOfBlock);
  SetSelection (ptCursorPos, ptEndOfBlock);
  SetCursorPos (ptEndOfBlock);
  EnsureVisible (ptEndOfBlock);
  return TRUE;
}
Ejemplo n.º 3
0
void CEditWnd::Cut()
{
  if (!QueryEditable ())
    return;
  if (m_pTextBuffer == NULL)
    return;
  if (!IsSelection ())
    return;

  CPoint ptSelStart, ptSelEnd;
  GetSelection (ptSelStart, ptSelEnd);
  string text;
  GetText (ptSelStart, ptSelEnd, text);
  PutToClipboard (text.c_str());

  CPoint ptCursorPos = ptSelStart;
  ASSERT_VALIDTEXTPOS (ptCursorPos);
  SetAnchor (ptCursorPos);
  SetSelection (ptCursorPos, ptCursorPos);
  SetCursorPos (ptCursorPos);
  EnsureVisible (ptCursorPos);

  m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_CUT);

}
Ejemplo n.º 4
0
const std::string wex::grid::get_find_string() const
{
  if (IsSelection())
  {
    // This does not work (if single cell selected, array count is 0!
    // const wxGridCellCoordsArray cells(GetSelectedCells());
    tokenizer tkz(get_selected_cells_value(), "\n");

    // Only if we have one cell, so one EOL.
    if (tkz.count_tokens() == 1)
    {
      find_replace_data::get()->set_find_string(tkz.get_next_token());
    }
  }
  else
  {
    // Just take current cell value, if not empty.
    const auto row = GetGridCursorRow();
    const auto col = GetGridCursorCol();
    const std::string val = GetCellValue(row, col);

    if (!val.empty())
    {
      find_replace_data::get()->set_find_string(val);
    }
  }
    
  return find_replace_data::get()->get_find_string();
}
Ejemplo n.º 5
0
void RichEdit::SetStyle()
{
	if(!IsSelection()) {
		NextUndo();
		WithSetStyleLayout<TopWindow> d;
		CtrlLayoutOKCancel(d, t_("Set style"));
		d.newstyle <<= d.Breaker(IDYES);
		d.style.AddKey();
		d.style.AddColumn();
		d.style.NoHeader().NoGrid();
		for(int i = 0; i < text.GetStyleCount(); i++)
			d.style.Add(text.GetStyleId(i), text.GetStyle(i).name);
		d.style.Sort(1, CompareStyle);
		int q = d.style.Find(RichStyle::GetDefaultId());
		if(q >= 0)
			d.style.SetDisplay(q, 0, Single<DisplayDefault>());
		d.style.FindSetCursor(formatinfo.styleid);
		RichStyle cs;
		cs.format = formatinfo;
		cs.format.sscript = 0;
		cs.format.link.Clear();
		cs.format.indexentry.Clear();
		cs.format.language = LNG_ENGLISH;
		cs.format.label.Clear();

		Uuid id;
		switch(d.Run()) {
		case IDCANCEL:
			return;
		case IDOK:
			if(d.style.IsCursor()) {
				id = d.style.GetKey();
				const RichStyle& st = text.GetStyle(id);
				cs.name = st.name;
				cs.next = st.next;
				SaveStyleUndo(id);
				break;
			}
			return;
		case IDYES:
			String newname;
			if(EditText(newname, Format(t_("New style no. %d"), text.GetStyleCount()),
			            "Name", CharFilterAscii128)) {
				cs.name = newname;
				id = Uuid::Create();
				cs.next = id;
				SaveStylesUndo();
				break;
			}
			return;
		}
		text.SetStyle(id, cs);
		ReadStyles();
		formatinfo.styleid = id;
		SaveFormat(GetCursor(), 0);
		text.ReStyle(GetCursor(), id);
		Finish();
	}
}
Ejemplo n.º 6
0
void RichEdit::ParaFormat()
{
	ParaFormatDlg d;
	d.para.Set(unit, formatinfo, !IsSelection() && cursorp.level == 0);
	if(d.Execute() != IDOK || !d.para.IsChanged())
		return;
	dword v = d.para.Get(formatinfo);
	if(v) ApplyFormat(0, v);
}
Ejemplo n.º 7
0
//
//	[JRT]: Added Support For "Disable Backspace At Start Of Line"
//
void CCrystalEditView::OnEditDeleteBack() 
{
	if (IsSelection())
	{
		OnEditDelete();
		return;
	}

	if (! QueryEditable() || m_pTextBuffer == NULL)
		return;

	CPoint ptCursorPos = GetCursorPos();
	CPoint ptCurrentCursorPos = ptCursorPos;
	bool	bDeleted = false;

	if( !( ptCursorPos.x ) )							// If At Start Of Line
	{
		if( !m_bDisableBSAtSOL )						// If DBSASOL Is Disabled
		{
			if( ptCursorPos.y > 0 )						// If Previous Lines Available
			{
				ptCursorPos.y--;						// Decrement To Previous Line
				ptCursorPos.x = GetLineLength(
						ptCursorPos.y );				// Set Cursor To End Of Previous Line
				bDeleted = true;						// Set Deleted Flag
			}
		}
	}
	else												// If Caret Not At SOL
	{
		ptCursorPos.x--;								// Decrement Position
		bDeleted = true;								// Set Deleted Flag
	}
/*
	if (ptCursorPos.x == 0)
	{
		if (ptCursorPos.y == 0)
			return;
		ptCursorPos.y --;
		ptCursorPos.x = GetLineLength(ptCursorPos.y);
	}
	else
		ptCursorPos.x --;
*/
	ASSERT_VALIDTEXTPOS(ptCursorPos);
	SetAnchor(ptCursorPos);
	SetSelection(ptCursorPos, ptCursorPos);
	SetCursorPos(ptCursorPos);
	EnsureVisible(ptCursorPos);

	if (bDeleted)
	{
		m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCurrentCursorPos.y, ptCurrentCursorPos.x, CE_ACTION_BACKSPACE); // [JRT]
	}
	return;
}
Ejemplo n.º 8
0
void RichEdit::TableInsertColumn()
{
	if(IsSelection() || !cursorp.table)
		return;
	NextUndo();
	SaveTable(cursorp.table);
	Point p = cursorp.cell;
	if(cursorp.cell.x == cursorp.tabsize.cx - 1 && cursorp.posincell == cursorp.celllen)
		p.x++;
	text.InsertTableColumn(cursorp.table, p.x);
	Move(text.GetCellPos(cursorp.table, text.GetMasterCell(cursorp.table, p)).pos);
}
Ejemplo n.º 9
0
void RichEdit::CellProperties()
{
	if(!(tablesel || cursorp.table && !IsSelection()))
		return;
	WithCellPropertiesLayout<TopWindow> dlg;
	CtrlLayoutOKCancel(dlg, t_("Cell properties"));
	int  tab;
	Rect a;
	if(tablesel) {
		tab = tablesel;
		a = cells;
	}
	else {
		tab = cursorp.table;
		a = Rect(cursorp.cell, Size(0, 0));
	}
	RichCell::Format fmt = text.GetCellFormat(tab, a);
	CtrlRetriever r;
	r
		(dlg.leftb.SetUnit(unit), fmt.border.left)
		(dlg.rightb.SetUnit(unit), fmt.border.right)
		(dlg.topb.SetUnit(unit), fmt.border.top)
		(dlg.bottomb.SetUnit(unit), fmt.border.bottom)
		(dlg.leftm.SetUnit(unit), fmt.margin.left)
		(dlg.rightm.SetUnit(unit), fmt.margin.right)
		(dlg.topm.SetUnit(unit), fmt.margin.top)
		(dlg.bottomm.SetUnit(unit), fmt.margin.bottom)
		(dlg.align, fmt.align)
		(dlg.minheight.SetUnit(unit), fmt.minheight)
		(dlg.color, fmt.color)
		(dlg.border, fmt.bordercolor)
		(dlg.keep, fmt.keep)
		(dlg.round, fmt.round)
	;
	dlg.align.Set(0, ALIGN_TOP);
	dlg.align.Set(1, ALIGN_CENTER);
	dlg.align.Set(2, ALIGN_BOTTOM);
	dlg.color.WithVoid().VoidText(t_("(no change)"));
	dlg.border.WithVoid().VoidText(t_("(no change)"));
	if(tablesel) {
		dlg.keep.ThreeState();
		dlg.keep <<= Null;
		dlg.round.ThreeState();
		dlg.round <<= Null;
	}
	if(dlg.Run() != IDOK)
		return;
	r.Retrieve();
	NextUndo();
	SaveTable(tab);
	text.SetCellFormat(tab, a, fmt, !tablesel || !IsNull(dlg.keep), !tablesel || !IsNull(dlg.round));
	Finish();
}
Ejemplo n.º 10
0
void RichEdit::TableInsertRow()
{
	if(IsSelection() || !cursorp.table)
		return;
	NextUndo();
	SaveTable(cursorp.table);
	Point p = cursorp.cell;
	if(cursorp.posintab == cursorp.tablen) {
		p.y++;
		p.x = 0;
	}
	text.InsertTableRow(cursorp.table, p.y);
	Move(text.GetCellPos(cursorp.table, text.GetMasterCell(cursorp.table, p)).pos);
}
Ejemplo n.º 11
0
void RichEdit::TableRemoveColumn()
{

	if(IsSelection() || !cursorp.table)
		return;
	NextUndo();
	if(cursorp.tabsize.cx <= 1)
		DestroyTable();
	else {
		SaveTable(cursorp.table);
		text.RemoveTableColumn(cursorp.table, cursorp.cell.x);
		Move(text.GetCellPos(cursorp.table, text.GetMasterCell(cursorp.table, cursorp.cell)).pos);
	}
}
Ejemplo n.º 12
0
void DataGrid::onKeyDown(wxKeyEvent &event)
{
	bool modified = false;
	if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) {
		if (event.ControlDown()) {
			if (!IsCellEditControlEnabled()) {
				insertRowToDataUp(GetGridCursorRow());
				modified = true;
			}
		} else {
			insertRowToData(GetGridCursorRow());
			modified = true;
		}
	} else if (event.GetKeyCode() == WXK_DELETE) {
		if (IsSelection()) {
			wxArrayInt rows = GetSelectedRows();
			if (rows.Count() > 0) {
				modified = deleteRowsFromData(rows);
			} else {
				unsigned int i;
				int row, col;
				wxGridCellCoordsArray cells = GetSelectedCells();
				for (i = 0; i < cells.Count(); i++) {
					clearCellData(cells[i].GetRow(), cells[i].GetCol());
				}
				wxGridCellCoordsArray topLeft = GetSelectionBlockTopLeft();
				wxGridCellCoordsArray bottomRight = GetSelectionBlockBottomRight();
				for (i = 0; i < topLeft.Count(); i++) {
					for (row = topLeft[i].GetRow(); row <= bottomRight[i].GetRow(); row++) {
						for (col = topLeft[i].GetCol(); col <= bottomRight[i].GetCol(); col++) {
							clearCellData(row, col);
						}
					}
				}
				wxArrayInt cols = GetSelectedCols();
				for (i = 0; i < cols.Count(); i++) {
					for (row = 1; row < GetNumberRows(); row++) {
						clearCellData(row, cols[i]);
					}
				}
			}
			ClearSelection();
		} else {
			clearCellData(GetGridCursorRow(), GetGridCursorCol());
		}
	}
	wxGrid::OnKeyDown(event);
	if (modified) updateData(true);
}
Ejemplo n.º 13
0
void RichEdit::Replace()
{
	NextUndo();
	if(IsSelection() && found) {
		FindReplaceAddHistory();
		int c = min(cursor, anchor);
		Remove(c, abs(cursor - anchor));
		anchor = cursor = c;
		Insert(cursor, ReplaceText(), false);
		cursor += findreplace.replace.GetText().GetLength();
		anchor = cursor;
		Finish();
		Find();
	}
}
Ejemplo n.º 14
0
void RichEdit::SplitCell()
{
	if(IsSelection() || !cursorp.table)
		return;
	WithSplitCellLayout<TopWindow> dlg;
	CtrlLayoutOKCancel(dlg, t_("Split cell"));
	dlg.cx.MinMax(1, 20).NotNull();
	dlg.cx <<= 1;
	dlg.cy.MinMax(1, 20).NotNull();
	dlg.cy <<= 1;
	if(dlg.Execute() != IDOK)
		return;
	NextUndo();
	SaveTable(cursorp.table);
	text.SplitCell(cursorp.table, cursorp.cell, Size(~dlg.cx, ~dlg.cy));
	Finish();
}
Ejemplo n.º 15
0
BOOL CEditWnd::DeleteCurrentSelection ()
{
  if (IsSelection ())
	{
		CPoint ptSelStart, ptSelEnd;
    GetSelection (ptSelStart, ptSelEnd);

    CPoint ptCursorPos = ptSelStart;
    ASSERT_VALIDTEXTPOS (ptCursorPos);
    SetAnchor (ptCursorPos);
    SetSelection (ptCursorPos, ptCursorPos);
    SetCursorPos (ptCursorPos);
    EnsureVisible (ptCursorPos);

    m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_DELSEL);
    return TRUE;
	}
  return FALSE;
}
Ejemplo n.º 16
0
BOOL CCrystalEditView::ReplaceSelection(LPCTSTR pszNewText)
{
	ASSERT(pszNewText != NULL);
	if (IsSelection())
		DeleteCurrentSelection();

	CPoint ptCursorPos = GetCursorPos();
	ASSERT_VALIDTEXTPOS(ptCursorPos);
	int x, y;
	m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszNewText, y, x, CE_ACTION_REPLACE); //	[JRT]
	CPoint ptEndOfBlock = CPoint(x, y);
	ASSERT_VALIDTEXTPOS(ptCursorPos);
	ASSERT_VALIDTEXTPOS(ptEndOfBlock);
	SetAnchor(ptEndOfBlock);
	SetSelection(ptCursorPos, ptEndOfBlock);
	SetCursorPos(ptEndOfBlock);
	EnsureVisible(ptEndOfBlock);
	return TRUE;
}
Ejemplo n.º 17
0
void RichEdit::InsertTable()
{
	if(IsSelection())
		return;
	WithCreateTableLayout<TopWindow> dlg;
	CtrlLayoutOKCancel(dlg, t_("Insert table"));
	dlg.header = false;
	dlg.columns <<= 2;
	dlg.columns.MinMax(1, 20);
	dlg.ActiveFocus(dlg.columns);
	if(dlg.Run() != IDOK)
		return;
	RichTable::Format fmt;
	int nx = minmax((int)~dlg.columns, 1, 20);
	for(int q = nx; q--;)
		fmt.column.Add(1);
	if(dlg.header)
		fmt.header = 1;
	RichTable table;
	table.SetFormat(fmt);
	for(int i = 0; i < (dlg.header ? 2 : 1); i++)
		for(int j = 0; j < nx; j++) {
			RichText h;
			h.SetStyles(text.GetStyles());
			RichPara p;
			p.format = formatinfo;
			p.format.newpage = false;
			p.format.label.Clear();
			h.Cat(p);
			table.SetPick(i, j, pick(h));
		}
	NextUndo();
	if(cursorp.posinpara)
		InsertLine();
	if(text.GetRichPos(cursor).paralen) {
		InsertLine();
		cursor = anchor = cursor - 1;
		begtabsel = false;
	}
	SaveFormat(cursor, 0);
	AddUndo(new UndoCreateTable(text.SetTable(cursor, table)));
	Finish();
}
Ejemplo n.º 18
0
void DocEdit::PlaceCaret(int newpos, bool select) {
	if(newpos > GetLength())
		newpos = GetLength();
	int z = GetLine(newpos);
	if(select) {
		if(anchor < 0) {
			anchor = cursor;
		}
		RefreshLines(z, GetLine(cursor));
	}
	else
		if(anchor >= 0) {
			RefreshLines(GetLine(cursor), GetLine(anchor));
			anchor = -1;
		}
	cursor = newpos;
	PlaceCaret(true);
	SelectionChanged();
	if(IsSelection())
		SetSelectionSource(ClipFmtsText());
}
Ejemplo n.º 19
0
void wxStfGrid::Copy(wxCommandEvent& WXUNUSED(event)) {
    if (!IsSelection()) {
        wxGetApp().ErrorMsg( wxT("Select cells first") );
        return;
    }
    // Write some text to the clipboard
    // These data objects are held by the clipboard, 
    // so do not delete them in the app.
    selection.Clear();
    bool newline=true;
    for (int nRow=0;nRow<GetNumberRows();++nRow) {
        /* bool selected=false;*/
        newline=true;
        for (int nCol=0;nCol<GetNumberCols();++nCol) {
            if (IsInSelection(nRow,nCol)) {
                // Add a line break if this is not the first line:
                if (newline && selection != wxT("") ) {
                    selection << wxT("\n");
                }
                if (!newline) {
                    selection << wxT("\t");
                }
                newline=false;
                try {
                    selection << GetCellValue(nRow,nCol);
                    /* selected=true;*/
                }
                catch (const std::out_of_range& e) {
                    throw e;
                }
            }
        }
    }
    if (wxTheClipboard->Open()) {
        wxTheClipboard->SetData(
                                new wxTextDataObject(selection)
                                );
        wxTheClipboard->Close();
    }
}
Ejemplo n.º 20
0
int LineEdit::PlaceCaretNoG(int newcursor, bool sel) {
	if(newcursor > total) newcursor = total;
	Point p = GetColumnLine(newcursor);
	if(sel) {
		if(anchor < 0) {
			anchor = cursor;
		}
		RefreshLines(p.y, GetLine(cursor));
	}
	else
		if(anchor >= 0) {
			RefreshLines(GetLine(cursor), GetLine(anchor));
			anchor = -1;
		}
	cursor = newcursor;
	ScrollIntoCursor();
	PlaceCaret0(p);
	SelectionChanged();
	WhenSel();
	if(IsSelection())
		SetSelectionSource(ClipFmtsText());
	return p.x;
}
Ejemplo n.º 21
0
void CCrystalEditView::OnEditReplace() 
{
	if (! QueryEditable())
		return;

	CWinApp *pApp = AfxGetApp();
	ASSERT(pApp != NULL);

	CEditReplaceDlg dlg(this);

	//	Take search parameters from registry
	dlg.m_bMatchCase = pApp->GetProfileInt(REG_REPLACE_SUBKEY, REG_MATCH_CASE, FALSE);
	dlg.m_bWholeWord = pApp->GetProfileInt(REG_REPLACE_SUBKEY, REG_WHOLE_WORD, FALSE);
	dlg.m_sText = pApp->GetProfileString(REG_REPLACE_SUBKEY, REG_FIND_WHAT, _T(""));
	dlg.m_sNewText = pApp->GetProfileString(REG_REPLACE_SUBKEY, REG_REPLACE_WITH, _T(""));

	/*
	if (IsSelection())
	{
		GetSelection(m_ptSavedSelStart, m_ptSavedSelEnd);
		m_bSelectionPushed = TRUE;

		dlg.m_nScope = 0;	//	Replace in current selection
		dlg.m_ptCurrentPos = m_ptSavedSelStart;
		dlg.m_bEnableScopeSelection = TRUE;
		dlg.m_ptBlockBegin = m_ptSavedSelStart;
		dlg.m_ptBlockEnd = m_ptSavedSelEnd;
	}
	else
	{
		dlg.m_nScope = 1;	//	Replace in whole text
		dlg.m_ptCurrentPos = GetCursorPos();
		dlg.m_bEnableScopeSelection = FALSE;
	}*/
	//	Take the current selection, if any
	if (IsSelection())
	{
		CPoint ptSelStart, ptSelEnd;
		GetSelection(ptSelStart, ptSelEnd);		if (ptSelStart.y == ptSelEnd.y)
		{
			LPCTSTR pszChars = GetLineChars(ptSelStart.y);
			int nChars = ptSelEnd.x - ptSelStart.x;
			lstrcpyn(dlg.m_sText.GetBuffer(nChars + 1), pszChars + ptSelStart.x, nChars + 1);
			dlg.m_sText.ReleaseBuffer();
		}
		dlg.m_nScope = 1;	//	Replace in whole text
		dlg.m_ptCurrentPos = ptSelStart;
		dlg.m_bEnableScopeSelection = FALSE;
	}


	//	Execute Replace dialog
	m_bShowInactiveSelection = TRUE;
	dlg.DoModal();
	m_bShowInactiveSelection = FALSE;

	//	Restore selection
	if (m_bSelectionPushed)
	{
		SetSelection(m_ptSavedSelStart, m_ptSavedSelEnd);
		m_bSelectionPushed = FALSE;
	}

	//	Save search parameters to registry
	pApp->WriteProfileInt(REG_REPLACE_SUBKEY, REG_MATCH_CASE, dlg.m_bMatchCase);
	pApp->WriteProfileInt(REG_REPLACE_SUBKEY, REG_WHOLE_WORD, dlg.m_bWholeWord);
	pApp->WriteProfileString(REG_REPLACE_SUBKEY, REG_FIND_WHAT, dlg.m_sText);
	pApp->WriteProfileString(REG_REPLACE_SUBKEY, REG_REPLACE_WITH, dlg.m_sNewText);
}
Ejemplo n.º 22
0
void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	CTextWnd::OnKeyDown(nChar, nRepCnt, nFlags);
	if (!QueryEditable() || m_pTextBuffer == NULL)
		return;

	bool isShift = (GetKeyState(VK_SHIFT) & 0xF0) != 0;
	bool isCtrl = (GetKeyState(VK_CONTROL) & 0xF0) != 0;

	if (nChar == VK_TAB)
	{
		BOOL bTabify = FALSE;
		CPoint ptSelStart, ptSelEnd;
		if (IsSelection())
		{	
			GetSelection(ptSelStart, ptSelEnd);
			bTabify = ptSelStart.y != ptSelEnd.y;
		}

		if (bTabify)
		{
			m_pTextBuffer->BeginUndoGroup();
	
			int nStartLine = ptSelStart.y;
			int nEndLine = ptSelEnd.y;
			ptSelStart.x = 0;
			if (ptSelEnd.x > 0)
			{
				if (ptSelEnd.y == GetLineCount() - 1)
				{
					ptSelEnd.x = GetLineLength(ptSelEnd.y);
				}
				else
				{
					ptSelEnd.x = 0;
					ptSelEnd.y ++;
				}
			}
			else
				nEndLine --;
			SetSelection(ptSelStart, ptSelEnd);
			SetCursorPos(ptSelEnd);
			EnsureVisible(ptSelEnd);

			//	Shift selection to right
			m_bHorzScrollBarLocked = TRUE;
			//static const TCHAR pszText[] = _T("\t");
			CString pszText;
			if (!m_bReplaceTabs) pszText = "\t";
			else 
			{
				CString tmp(' ', GetTabSize());
				pszText = tmp;
			}

			for (int L = nStartLine; L <= nEndLine; L ++)
			{
				int x, y;
				m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT);
			}
			m_bHorzScrollBarLocked = FALSE;
			RecalcHorzScrollBar();

			m_pTextBuffer->FlushUndoGroup(this);
		}
		else
		{
			m_pTextBuffer->BeginUndoGroup();

			DeleteCurrentSelection();

			CPoint ptCursorPos = GetCursorPos();
			ASSERT_VALIDTEXTPOS(ptCursorPos);

			CString pszText;
			if (!m_bReplaceTabs) pszText = "\t";
			else 
			{
				CString tmp(' ', GetTabSize());
				pszText = tmp;
			}

			int x, y;
			m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING);
			ptCursorPos.x = x;
			ptCursorPos.y = y;
			ASSERT_VALIDTEXTPOS(ptCursorPos);
			SetSelection(ptCursorPos, ptCursorPos);
			SetAnchor(ptCursorPos);
			SetCursorPos(ptCursorPos);
			EnsureVisible(ptCursorPos);

			m_pTextBuffer->FlushUndoGroup(this);
		}
	}

	if (nChar == VK_BACK && !IsSelection())
	{
		CPoint ptCursorPos = GetCursorPos();

		if (ptCursorPos.y > 0 || (ptCursorPos.x > 0 && ptCursorPos.y == 0))
		{
			CPoint ptCurrentCursorPos = ptCursorPos;
			bool	bDeleted = false;
			if(ptCursorPos.x == 0)					
			{
				ptCursorPos.y--;						
				ptCursorPos.x = GetLineLength(ptCursorPos.y);	
				bDeleted = true;	
			}
			else								
			{
				ptCursorPos.x--;	
				bDeleted = true;	
			}
			ASSERT_VALIDTEXTPOS(ptCursorPos);
			SetAnchor(ptCursorPos);
			SetSelection(ptCursorPos, ptCursorPos);
			SetCursorPos(ptCursorPos); 
			EnsureVisible(ptCursorPos);

			if (bDeleted)
				m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, 
					ptCurrentCursorPos.y, ptCurrentCursorPos.x, CE_ACTION_BACKSPACE); 
		}
	}

	if (nChar == VK_DELETE && !isShift) 
	{
		CPoint ptSelStart, ptSelEnd;
		GetSelection(ptSelStart, ptSelEnd);
		if (ptSelStart == ptSelEnd)
		{	
			if (ptSelEnd.x == GetLineLength(ptSelEnd.y))
			{
				if (ptSelEnd.y == GetLineCount() - 1)
					return;
				ptSelEnd.y++;
				ptSelEnd.x = 0;

				if (GetLineLength(ptSelStart.y) != 0)
				{
					LPCSTR chars = GetLineChars(ptSelEnd.y);
					for (int j = 0; j < QUOTE_LENGTH && j < GetLineLength(ptSelEnd.y); j++)
						if (chars[j] == '>') ptSelEnd.x = j + 1;
				
					while (ptSelEnd.x < GetLineLength(ptSelEnd.y) && 
						(chars[ptSelEnd.x] == ' ' || chars[ptSelEnd.x] == '\t'))
						ptSelEnd.x++;
				}
			}
			else ptSelEnd.x++;
		}

		CPoint ptCursorPos = ptSelStart;
		ASSERT_VALIDTEXTPOS(ptCursorPos);
		SetAnchor(ptCursorPos);
		SetSelection(ptCursorPos, ptCursorPos);
		SetCursorPos(ptCursorPos);
		EnsureVisible(ptCursorPos);

		m_pTextBuffer->DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_DELETE); 
	}

	if ((nChar == 'X' && isCtrl) || (nChar == VK_DELETE && isShift)) 
		Cut();

	if ((nChar == 'V' && isCtrl) || (nChar == VK_INSERT && isShift)) 
		Paste();
		
	if (nChar == 'Z' && isCtrl && isShift)
		Redo();
		
	if (nChar == 'Z' && isCtrl && !isShift)
		Undo();
}
Ejemplo n.º 23
0
void CCrystalEditView::OnUpdateEditCut(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(IsSelection());
}
Ejemplo n.º 24
0
void CCrystalEditView::OnEditTab() 
{
	if (! QueryEditable() || m_pTextBuffer == NULL)
		return;

	BOOL bTabify = FALSE;
	CPoint ptSelStart, ptSelEnd;
	if (IsSelection())
	{
		GetSelection(ptSelStart, ptSelEnd);
		bTabify = ptSelStart.y != ptSelEnd.y;
	}

	if (bTabify)
	{
		m_pTextBuffer->BeginUndoGroup();

		int nStartLine = ptSelStart.y;
		int nEndLine = ptSelEnd.y;
		ptSelStart.x = 0;
		if (ptSelEnd.x > 0)
		{
			if (ptSelEnd.y == GetLineCount() - 1)
			{
				ptSelEnd.x = GetLineLength(ptSelEnd.y);
			}
			else
			{
				ptSelEnd.x = 0;
				ptSelEnd.y ++;
			}
		}
		else
			nEndLine --;
		SetSelection(ptSelStart, ptSelEnd);
		SetCursorPos(ptSelEnd);
		EnsureVisible(ptSelEnd);

		//	Shift selection to right
		m_bHorzScrollBarLocked = TRUE;
		static const TCHAR pszText[] = _T("\t");
		for (int L = nStartLine; L <= nEndLine; L ++)
		{
			int x, y;
			m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); //	[JRT]
		}
		m_bHorzScrollBarLocked = FALSE;
		RecalcHorzScrollBar();

		m_pTextBuffer->FlushUndoGroup(this);
		return;
	}

	if (m_bOvrMode)
	{
		CPoint ptCursorPos = GetCursorPos();
		ASSERT_VALIDTEXTPOS(ptCursorPos);

		int nLineLength = GetLineLength(ptCursorPos.y);
		LPCTSTR pszLineChars = GetLineChars(ptCursorPos.y);
		if (ptCursorPos.x < nLineLength)
		{
			int nTabSize = GetTabSize();
			int nChars = nTabSize - CalculateActualOffset(ptCursorPos.y, ptCursorPos.x) % nTabSize;
			ASSERT(nChars > 0 && nChars <= nTabSize);

			while (nChars > 0)
			{
				if (ptCursorPos.x == nLineLength)
					break;
				if (pszLineChars[ptCursorPos.x] == _T('\t'))
				{
					ptCursorPos.x ++;
					break;
				}
				ptCursorPos.x ++;
				nChars --;
			}
			ASSERT(ptCursorPos.x <= nLineLength);
			ASSERT_VALIDTEXTPOS(ptCursorPos);

			SetSelection(ptCursorPos, ptCursorPos);
			SetAnchor(ptCursorPos);
			SetCursorPos(ptCursorPos);
			EnsureVisible(ptCursorPos);
			return;
		}
	}

	m_pTextBuffer->BeginUndoGroup();

	DeleteCurrentSelection();

	CPoint ptCursorPos = GetCursorPos();
	ASSERT_VALIDTEXTPOS(ptCursorPos);

	static const TCHAR pszText[] = _T("\t");
	int x, y;
	m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); //	[JRT]
	ptCursorPos.x = x;
	ptCursorPos.y = y;
	ASSERT_VALIDTEXTPOS(ptCursorPos);
	SetSelection(ptCursorPos, ptCursorPos);
	SetAnchor(ptCursorPos);
	SetCursorPos(ptCursorPos);
	EnsureVisible(ptCursorPos);

	m_pTextBuffer->FlushUndoGroup(this);
}
Ejemplo n.º 25
0
void   LineEdit::Paint0(Draw& w) {
	LTIMING("LineEdit::Paint0");
	int sell, selh;
	GetSelection(sell, selh);
	if(!IsEnabled())
		sell = selh = 0;
	Rect rect;
	bool rectsel = IsRectSelection();
	if(IsRectSelection())
		rect = GetRectSelection();
	Size sz = GetSize();
	Size fsz = GetFontSize();
	Point sc = sb;
	int ll = min(line.GetCount(), sz.cy / fsz.cy + sc.y + 1);
	int  y = 0;
	sc.y = minmax(sc.y, 0, line.GetCount() - 1);
	cpos = GetPos(sc.y);
	cline = sc.y;
	sell -= cpos;
	selh -= cpos;
	int pos = cpos;
	int fascent = font.Info().GetAscent();
	int cursorline = GetLine(cursor);
	Highlight ih;
	ih.ink = color[IsShowEnabled() ? INK_NORMAL : INK_DISABLED];
	ih.paper = color[IsReadOnly() && showreadonly || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL];
	if(nobg)
		ih.paper = Null;
	ih.font = font;
	ih.chr = 0;
	for(int i = sc.y; i < ll; i++) {
		Color showcolor = color[WHITESPACE];
		WString tx = line[i];
		bool warn_whitespace = false;
		if(warnwhitespace && !IsSelection()) {
			int pos = GetCursor();
			int linei = GetLinePos(pos);
			if(linei != i || pos < tx.GetCount()) {
				int wkind = 0;
				bool empty = true;
				for(const wchar *s = tx; *s; s++) {
					if(*s == '\t') {
						if(wkind == ' ') {
							warn_whitespace = true;
							break;
						}
						wkind = '\t';
					}
					else
					if(*s == ' ')
						wkind = ' ';
					else
					if(*s > ' ') {
						empty = false;
						wkind = 0;
					}
				}
				if(wkind && !empty)
					warn_whitespace = true;
				if(warn_whitespace)
					showcolor = color[WARN_WHITESPACE];
			}
		}
		bool do_highlight = tx.GetCount() < 100000;
		int len = tx.GetLength();
		if(w.IsPainting(0, y, sz.cx, fsz.cy)) {
			LTIMING("PaintLine");
			Vector<Highlight> hl;
			int ln;
			if(do_highlight) {
				hl.SetCount(len + 1, ih);
				for(int q = 0; q < tx.GetCount(); q++)
					hl[q].chr = tx[q];
				LTIMING("HighlightLine");
				HighlightLine(i, hl, pos);
				ln = hl.GetCount() - 1;
			}
			else
				ln = tx.GetCount();
			int lgp = -1;
			for(int pass = 0; pass < 2; pass++) {
				int gp = 0;
				int scx = fsz.cx * sc.x;
				sOptimizedRectRenderer rw(w);
				if(ln >= 0) {
					int q = 0;
					int x = 0;
					int scx2 = scx - max(2, tabsize) * fsz.cx;
					while(q < ln && x < scx2) { // Skip part before left border
						wchar chr = do_highlight ? hl[q++].chr : tx[q++];
						if(chr == '\t') {
							gp = (gp + tabsize) / tabsize * tabsize;
							x = fsz.cx * gp;
						}
						else
						if(IsCJKIdeograph(chr)) {
							x += 2 * fsz.cx;
							gp += 2;
						}
						else {
							x += fsz.cx;
							gp++;
						}
					}
					sOptimizedTextRenderer tw(w);
					while(q < ln) {
						if(q == tx.GetCount())
							lgp = gp;
						Highlight h;
						if(do_highlight)
							h = hl[q];
						else {
							h = ih;
							h.chr = tx[q];
						}
						int pos = min(q, len); // Highligting can add chars at the end of line
						if(rectsel ? i >= rect.top && i <= rect.bottom && gp >= rect.left && gp < rect.right
						           : pos >= sell && pos < selh) {
							h.paper = color[PAPER_SELECTED];
							h.ink = color[INK_SELECTED];
						}
						int x = gp * fsz.cx - scx;
						if(h.chr == '\t') {
							int ngp = (gp + tabsize) / tabsize * tabsize;
							int l = ngp - gp;
							LLOG("Highlight -> tab[" << q << "] paper = " << h.paper);
							if(pass == 0 && x >= -fsz.cy * tabsize) {
								rw.DrawRect(x, y, fsz.cx * l, fsz.cy, h.paper);
								if((showtabs || warn_whitespace) &&
								   h.paper != SColorHighlight && q < tx.GetLength()) {
									rw.DrawRect(x + 2, y + fsz.cy / 2, l * fsz.cx - 4, 1, showcolor);
									rw.DrawRect(ngp * fsz.cx - scx - 3, y + 3, 1, fsz.cy - 6, showcolor);
								}
								if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + l)
									rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
							}
							q++;
							gp = ngp;
						}
						else
						if(h.chr == ' ') {
							LLOG("Highlight -> space[" << q << "] paper = " << h.paper);
							if(pass == 0 && x >= -fsz.cy) {
								rw.DrawRect(x, y, fsz.cx, fsz.cy, h.paper);
								if((showspaces || warn_whitespace)
								   && h.paper != SColorHighlight && q < tx.GetLength()) {
									int n = fsz.cy / 10 + 1;
									rw.DrawRect(x + fsz.cx / 2, y + fsz.cy / 2, n, n, showcolor);
								}
								if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + 1)
									rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
							}
							q++;
							gp++;
						}
						else {
							bool cjk = IsCJKIdeograph(h.chr);
							LLOG("Highlight -> paper[" << q << "] = " << h.paper);
							int xx = x + (gp + 1 + cjk) * fsz.cx;
							if(max(x, 0) < min(xx, sz.cx) && fsz.cx >= -fsz.cy) {
								if(pass == 0) {
									rw.DrawRect(x, y, (cjk + 1) * fsz.cx, fsz.cy, h.paper);
									if(bordercolumn > 0 && bordercolumn >= gp && bordercolumn < gp + 1 + cjk)
										rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
								}
								else
									tw.DrawChar(x + (h.flags & SHIFT_L ? -fsz.cx / 6 : h.flags & SHIFT_R ? fsz.cx / 6 : 0),
									            y + fascent - h.font.GetAscent(),
									            h.chr, (cjk + 1) * fsz.cx, h.font, h.ink);
							}
							q++;
							gp += 1 + cjk;
							if(x > sz.cx)
								break;
						}
					}
				}
				if(pass == 0) {
					int gpx = gp * fsz.cx - scx;
					rw.DrawRect(gpx, y, sz.cx - gpx, fsz.cy,
					            !rectsel && sell <= len && len < selh ? color[PAPER_SELECTED]
					            : (do_highlight ? hl.Top() : ih).paper);
					if(bordercolumn > 0 && bordercolumn >= gp)
						rw.DrawRect((bordercolumn - sc.x) * fsz.cx, y, 1, fsz.cy, bordercolor);
				}
				if(pass == 0 && (showlines || warn_whitespace)) {
					int yy = 2 * fsz.cy / 3;
					int x = (lgp >= 0 ? lgp : gp) * fsz.cx - scx;
					rw.DrawRect(x, y + yy, fsz.cx / 2, 1, showcolor);
					if(fsz.cx > 2)
						rw.DrawRect(x + 1, y + yy - 1, 1, 3, showcolor);
					if(fsz.cx > 5)
						rw.DrawRect(x + 2, y + yy - 2, 1, 5, showcolor);
					rw.DrawRect(x + fsz.cx / 2, y + yy / 2, 1, yy - yy / 2, showcolor);
				}
				if(pass == 0 && !IsNull(hline) && sell == selh && i == cursorline) {
					rw.DrawRect(0, y, sz.cx, 1, hline);
					rw.DrawRect(0, y + fsz.cy - 1, sz.cx, 1, hline);
				}
				if(pass == 0 && rectsel && rect.left == rect.right && i >= rect.top && i <= rect.bottom)
					rw.DrawRect(rect.left * fsz.cx - scx, y, 2, fsz.cy, Blend(color[PAPER_SELECTED], color[PAPER_NORMAL]));
			}
		}
		y += fsz.cy;
		sell -= len + 1;
		selh -= len + 1;
		pos += len + 1;
	}
	
	w.DrawRect(0, y, sz.cx, sz.cy - y, color[IsReadOnly() && showreadonly || !IsShowEnabled() ? PAPER_READONLY : PAPER_NORMAL]);
	DrawTiles(w, DropCaret(), CtrlImg::checkers());
}
Ejemplo n.º 26
0
void CCrystalEditView::OnEditUntab() 
{
	if (! QueryEditable() || m_pTextBuffer == NULL)
		return;

	BOOL bTabify = FALSE;
	CPoint ptSelStart, ptSelEnd;
	if (IsSelection())
	{
		GetSelection(ptSelStart, ptSelEnd);
		bTabify = ptSelStart.y != ptSelEnd.y;
	}

	if (bTabify)
	{
		m_pTextBuffer->BeginUndoGroup();

		CPoint ptSelStart, ptSelEnd;
		GetSelection(ptSelStart, ptSelEnd);
		int nStartLine = ptSelStart.y;
		int nEndLine = ptSelEnd.y;
		ptSelStart.x = 0;
		if (ptSelEnd.x > 0)
		{
			if (ptSelEnd.y == GetLineCount() - 1)
			{
				ptSelEnd.x = GetLineLength(ptSelEnd.y);
			}
			else
			{
				ptSelEnd.x = 0;
				ptSelEnd.y ++;
			}
		}
		else
			nEndLine --;
		SetSelection(ptSelStart, ptSelEnd);
		SetCursorPos(ptSelEnd);
		EnsureVisible(ptSelEnd);

		//	Shift selection to left
		m_bHorzScrollBarLocked = TRUE;
		for (int L = nStartLine; L <= nEndLine; L ++)
		{
			int nLength = GetLineLength(L);
			if (nLength > 0)
			{
				LPCTSTR pszChars = GetLineChars(L);
				int nPos = 0, nOffset = 0;
				while (nPos < nLength)
				{
					if (pszChars[nPos] == _T(' '))
					{
						nPos ++;
						if (++ nOffset >= GetTabSize())
							break;
					}
					else
					{
						if (pszChars[nPos] == _T('\t'))
							nPos ++;
						break;
					}
				}

				if (nPos > 0)
					m_pTextBuffer->DeleteText(this, L, 0, L, nPos, CE_ACTION_INDENT); // [JRT]
			}
		}
		m_bHorzScrollBarLocked = FALSE;
		RecalcHorzScrollBar();

		m_pTextBuffer->FlushUndoGroup(this);
	}
	else
	{
		CPoint ptCursorPos = GetCursorPos();
		ASSERT_VALIDTEXTPOS(ptCursorPos);
		if (ptCursorPos.x > 0)
		{
			int nTabSize = GetTabSize();
			int nOffset = CalculateActualOffset(ptCursorPos.y, ptCursorPos.x);
			int nNewOffset = nOffset / nTabSize * nTabSize;
			if (nOffset == nNewOffset && nNewOffset > 0)
				nNewOffset -= nTabSize;
			ASSERT(nNewOffset >= 0);

			LPCTSTR pszChars = GetLineChars(ptCursorPos.y);
			int nCurrentOffset = 0;
			int I = 0;
			while (nCurrentOffset < nNewOffset)
			{
				if (pszChars[I] == _T('\t'))
					nCurrentOffset = nCurrentOffset / nTabSize * nTabSize + nTabSize;
				else
					nCurrentOffset ++;
				I ++;
			}

			ASSERT(nCurrentOffset == nNewOffset);

			ptCursorPos.x = I;
			ASSERT_VALIDTEXTPOS(ptCursorPos);
			SetSelection(ptCursorPos, ptCursorPos);
			SetAnchor(ptCursorPos);
			SetCursorPos(ptCursorPos);
			EnsureVisible(ptCursorPos);
		}
	}
}
Ejemplo n.º 27
0
void AssistEditor::SyncParamInfo()
{
	String qtf;
	Ctrl *p = GetTopCtrl();
	int mpar = INT_MAX;
	int pos = 0;
	if(p && p->HasFocusDeep()) {
		for(int q = 0; q < PARAMN; q++) {
			ParamInfo& m = param[q];
			int i = GetCursorLine();
			if(m.line >= 0 && m.line < GetLineCount() && i >= m.line && i < m.line + 10
			   && m.editfile == theide->editfile && GetWLine(m.line).StartsWith(m.test)) {
				int c = GetCursor();
				i = GetPos(m.line) + m.test.GetCount();
				if(c >= i) {
					int par = 0;
					int pari = 0;
					for(;;) {
						int ch = Ch(i++);
						if(i > c) {
							if(par < mpar) {
								qtf = "[A1  " + DecoratedItem(m.item.name, m.item, m.item.natural, pari);
								mpar = par;
								pos = m.pos;
							}
							break;
						}
						if(ch == ')') {
							if(par <= 0)
								break;
							par--;
						}
						if(ch == '(')
							par++;
						if(ch == ',' && par == 0)
							pari++;
					}
				}
			}
		}
	}
	if(param_qtf != qtf)
		param_info.SetQTF(qtf);
	Rect r = GetLineScreenRect(GetCursorLine());
	int cx = max(GetSize().cx - 30, 300);
	int h = param_info.GetHeight(cx);
	h = min(h, 550);
	int y = r.top - h - 6;
	if(y < GetWorkArea().top)
		y = r.bottom;
	r = RectC(r.left, y, min(param_info.GetWidth(), cx) + 8, h + 6);
	r.OffsetHorz(GetColumnLine(pos).x * GetFontSize().cx);
	r.OffsetHorz(min(GetWorkArea().right - r.right, 0));
	if(param_qtf != qtf || r != param_info.GetRect()) {
		param_qtf = qtf;
		if(IsNull(qtf)) {
			if(param_info.IsOpen())
				param_info.Close();
		}
		else {
			param_info.SetRect(r);
			if(!param_info.IsOpen() && !IsSelection())
				param_info.Ctrl::PopUp(this, false, false, false);
		}
	}
}
Ejemplo n.º 28
0
/** GetSelectedRow
  *
  * Gets the first selected row
  */
int MemoryGrid::GetSelectedRow() const
{
    if (!IsSelection()) return -1;

    return GetSelectedRows()[0];
}
Ejemplo n.º 29
0
wex::grid::grid(const window_data& data)
  : wxGrid(
    data.parent(), 
    data.id(), 
    data.pos(), 
    data.size(), 
    data.style(), 
    data.name())
{
  SetDropTarget(new text_droptarget(this));
  m_use_drag_and_drop = true;

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    empty_selection();}, wxID_DELETE);
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    SelectAll();}, wxID_SELECTALL);
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    ClearSelection();}, ID_EDIT_SELECT_NONE);
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    copy_selected_cells_to_clipboard();}, wxID_COPY);
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    copy_selected_cells_to_clipboard();
    empty_selection();}, wxID_CUT);
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    paste_cells_from_clipboard();}, wxID_PASTE);

  Bind(wxEVT_FIND, [=](wxFindDialogEvent& event) {
    find_next(
      find_replace_data::get()->get_find_string(), 
      find_replace_data::get()->search_down());});
      
  Bind(wxEVT_FIND_NEXT, [=](wxFindDialogEvent& event) {
    find_next(
      find_replace_data::get()->get_find_string(), 
      find_replace_data::get()->search_down());});

  Bind(wxEVT_GRID_CELL_LEFT_CLICK, [=](wxGridEvent& event) {
    // Removed extra check for !IsEditable(),
    // drag/drop is different from editing, so allow that.
    if (!IsSelection())
    {
      event.Skip();
      return;
    }

    if (m_use_drag_and_drop)
    {
      // This is because drag/drop is not really supported by the wxGrid.
      // Even the wxEVT_GRID_CELL_BEGIN_DRAG does not seem to come in.
      // Therefore, we are really dragging if you click again in
      // your selection and move mouse and drop elsewhere.
      // So, if not clicked in the selection, do nothing, this was no drag.
      if (!IsInSelection(event.GetRow(), event.GetCol()))
      {
        event.Skip();
        return;
      }

      // Is it allowed to drag current selection??
      if (!is_allowed_drag_selection())
      {
        event.Skip();
        return;
      }

      // Start drag operation.
      wxTextDataObject textData(get_selected_cells_value());
      wxDropSource source(textData, this);
      wxDragResult result = source.DoDragDrop(wxDrag_DefaultMove);

      if (result != wxDragError &&
          result != wxDragNone &&
          result != wxDragCancel)
      {
        // The old contents is not deleted, as should be by moving.
        // To fix this, do not call Skip so selection remains active,
        // and call empty_selection.
        //  event.Skip();
        empty_selection();
        ClearSelection();
      }
      else
      {
        // Do not call Skip so selection remains active.
        // event.Skip();
      }
    }
    else
    {
      event.Skip();
    }
    });
  
  Bind(wxEVT_GRID_CELL_RIGHT_CLICK, [=](wxGridEvent& event) {
    int style = (IsEditable() ? wex::menu::DEFAULT: wex::menu::IS_READ_ONLY);
    if (IsSelection()) style |= wex::menu::IS_SELECTED;

    wex::menu menu(style);
    build_popup_menu(menu);
    PopupMenu(&menu);
    });
    
  Bind(wxEVT_GRID_SELECT_CELL, [=](wxGridEvent& event) {
    frame::statustext(
      std::to_string(1 + event.GetCol()) + "," + std::to_string(1 + event.GetRow()),
      "PaneInfo");
    event.Skip();});

  Bind(wxEVT_GRID_RANGE_SELECT, [=](wxGridRangeSelectEvent& event) {
    event.Skip();
    frame::statustext(std::to_string(GetSelectedCells().GetCount()),
      "PaneInfo");
    });
  
  Bind(wxEVT_SET_FOCUS, [=](wxFocusEvent& event) {
    wex::frame* frame = dynamic_cast<wex::frame*>(wxTheApp->GetTopWindow());
    if (frame != nullptr)
    {
      frame->set_find_focus(this);
    }
    event.Skip();});
}
Ejemplo n.º 30
0
void RichEdit::TableProps()
{
	if(IsSelection() || cursorp.table == 0)
		return;
	RichEditTableProperties dlg;
	dlg.Breaker(dlg.destroy, IDNO);
	RichTable::Format fmt = text.GetTableFormat(cursorp.table);
	String ratios;
	for(int i = 0; i < fmt.column.GetCount(); i++) {
		if(i)
			ratios << ':';
		ratios << "1";
	}
	dlg.ratios.SetFilter(CharFilterEqualize);
	dlg.ratios <<= ratios;
	CtrlRetriever r;
	Advn(r, dlg.before.SetUnit(unit), fmt.before);
	Advn(r, dlg.after.SetUnit(unit), fmt.after);
	Advn(r, dlg.lm.SetUnit(unit), fmt.lm);
	Advn(r, dlg.rm.SetUnit(unit), fmt.rm);
	Advn(r, dlg.frame.SetUnit(unit), fmt.frame);
	r(dlg.framecolor, fmt.framecolor);
	Advn(r, dlg.grid.SetUnit(unit), fmt.grid);
	Advn(r, dlg.header, fmt.header);
	Advn(r, dlg.keep, fmt.keep);
	Advn(r, dlg.newpage, fmt.newpage);
	Advn(r, dlg.newhdrftr, fmt.newhdrftr);
	dlg.header_qtf = fmt.header_qtf;
	dlg.footer_qtf = fmt.footer_qtf;
	r(dlg.gridcolor, fmt.gridcolor);
	dlg.SyncHdrFtr();
	dlg.newhdrftr.Enable(cursorp.level == 1);
	dlg.hdrftr.Enable(cursorp.level == 1);
	for(;;) {
		switch(dlg.Run()) {
		case IDCANCEL:
			return;
		case IDNO:
			NextUndo();
			DestroyTable();
			return;
		default:
			r.Retrieve();
			if(dlg.newhdrftr) {
				fmt.header_qtf = dlg.header_qtf;
				fmt.footer_qtf = dlg.footer_qtf;
			}
			else
				fmt.header_qtf = fmt.footer_qtf = Null;
			const RichTable& tbl = text.GetConstTable(cursorp.table);
			bool valid = true;
			Point violator(0, 0);
			int vspan = 0;
			for(int rw = 0; valid && rw < fmt.header && rw < tbl.GetRows(); rw++)
				for(int co = 0; valid && co < tbl.GetColumns(); co++)
					if(tbl(rw, co) && (vspan = tbl[rw][co].vspan) + rw > fmt.header) {
						valid = false;
						violator.x = co;
						violator.y = rw;
						break;
					}
			if(!valid) {
				Exclamation(NFormat(t_("Invalid header row count %d, cell at rw %d, co %d has vspan = %d."),
					fmt.header, violator.y + 1, violator.x + 1, vspan));
				continue;
			}
			NextUndo();
			SaveTableFormat(cursorp.table);
			if(dlg.equalize) {
				Vector<String> r = Split((String)~dlg.ratios, ':');
				for(int i = 0; i < fmt.column.GetCount(); i++)
					fmt.column[i] = i < r.GetCount() ? max(atoi(r[i]), 1) : 1;
			}
			text.SetTableFormat(cursorp.table, fmt);
			Finish();
			return;
		}
	}
}