21#include "kspread_editors.h"
22#include "kspread_canvas.h"
23#include "kspread_cell.h"
24#include "kspread_doc.h"
26#include "kspread_sheet.h"
27#include "kspread_view.h"
28#include "kspread_util.h"
32#include <tdelistbox.h>
34#include <tqapplication.h>
39#include <tqvaluelist.h>
40#include <tqrichtext_p.h>
44#include <tqapplication.h>
47#include <tqfontmetrics.h>
64class FormulaEditorHighlighter::Private
84 : TQSyntaxHighlighter(textEdit)
90FormulaEditorHighlighter::~FormulaEditorHighlighter()
95const Tokens& FormulaEditorHighlighter::formulaTokens()
const
103 setFormat(0, text.length(), TQt::black);
106 Tokens oldTokens = d->tokens;
113 TQFont editorFont = textEdit()->currentFont();
116 uint oldRangeCount = d->rangeCount;
119 TQValueList<TQColor> colors = d->canvas->choice()->colors();
120 TQValueList<Range> alreadyFoundRanges;
122 for (uint i = 0; i < d->tokens.count(); ++i)
124 Token token = d->tokens[i];
133 if (!d->rangeChanged && i < oldTokens.count() && token.
text() != oldTokens[i].text())
135 d->rangeChanged =
true;
140 if (!alreadyFoundRanges.contains(newRange))
142 alreadyFoundRanges.append(newRange);
145 setFormat(token.pos() + 1, token.
text().length(), colors[ alreadyFoundRanges.findIndex(newRange) % colors.size()] );
180 if (oldRangeCount != d->rangeCount)
181 d->rangeChanged =
true;
190 const Token& token = d->tokens.at( index );
192 textEdit()->getCursorPosition( &cursorParagraph , &cursorPos );
194 int distance = cursorPos-token.pos();
196 bool highlightBrace=
false;
212 if ( (index == d->tokens.count()-1) || ( d->tokens.at(index+1).asOperator() !=
Token::LeftPar) )
226 if ( (index == 0) || (d->tokens.at(index-1).asOperator() !=
Token::RightPar) )
232 TQFont font = TQFont( textEdit()->currentFont() );
234 setFormat(token.pos() + 1, token.
text().length(), font);
240 Token matchingBrace = d->tokens.at(matching);
241 setFormat( matchingBrace.pos() + 1 , matchingBrace.
text().length() , font);
251 Tokens tokens = d->tokens;
261 for (
int index=pos ; (index >= 0) && (index < (int) tokens.count() ) ; index += step )
277uint FormulaEditorHighlighter::rangeCount()
const
279 return d->rangeCount;
284 return d->rangeChanged;
289 d->rangeChanged=
false;
302class FunctionCompletion::Private
306 TQVBox *completionPopup;
307 TDEListBox *completionListBox;
311FunctionCompletion::FunctionCompletion(
CellEditor* editor ):
318 d->completionPopup =
new TQVBox( editor->topLevelWidget(), 0, WType_Popup );
319 d->completionPopup->setFrameStyle( TQFrame::Box | TQFrame::Plain );
320 d->completionPopup->setLineWidth( 1 );
321 d->completionPopup->installEventFilter(
this );
322 d->completionPopup->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum);
324 d->completionListBox =
new TDEListBox( d->completionPopup );
325 d->completionPopup->setFocusProxy( d->completionListBox );
326 d->completionListBox->setFrameStyle( TQFrame::NoFrame );
327 d->completionListBox->setVariableWidth(
true );
328 d->completionListBox->installEventFilter(
this );
329 connect( d->completionListBox, TQ_SIGNAL(selected(
const TQString&)),
this,
330 TQ_SLOT(itemSelected(
const TQString&)) );
331 connect( d->completionListBox, TQ_SIGNAL(highlighted(
const TQString&)),
this,
332 TQ_SLOT(itemSelected(
const TQString&)) );
334 d->hintLabel =
new TQLabel( 0,
"autocalc", TQt::WStyle_StaysOnTop |
335 TQt::WStyle_Customize | TQt::WStyle_NoBorder | TQt::WStyle_Tool | TQt::WX11BypassWM );
336 d->hintLabel->setFrameStyle( TQFrame::Plain | TQFrame::Box );
337 d->hintLabel->setPalette( TQToolTip::palette() );
338 d->hintLabel->hide();
341FunctionCompletion::~FunctionCompletion()
347void FunctionCompletion::itemSelected(
const TQString& item )
349 KSpread::FunctionDescription* desc;
350 desc = KSpread::FunctionRepository::self()->functionInfo(item);
353 d->hintLabel->hide();
357 TQString helpText = desc->helpText()[0];
358 if( helpText.isEmpty() )
360 d->hintLabel->hide();
364 helpText.append(
"</qt>").prepend(
"<qt>");
365 d->hintLabel->setText( helpText );
366 d->hintLabel->adjustSize();
369 TQPoint pos = d->editor->mapToGlobal( TQPoint( d->editor->width(), 0 ) );
370 pos.setY( pos.y() - d->hintLabel->height() - 1 );
371 d->hintLabel->move( pos );
372 d->hintLabel->show();
373 d->hintLabel->raise();
381 if ( obj == d->completionPopup || obj == d->completionListBox )
383 if ( ev->type() == TQEvent::KeyPress )
385 TQKeyEvent *ke = (TQKeyEvent*)ev;
386 if ( ke->key() == Key_Enter || ke->key() == Key_Return )
391 else if ( ke->key() == Key_Left || ke->key() == Key_Right ||
392 ke->key() == Key_Up || ke->key() == Key_Down ||
393 ke->key() == Key_Home || ke->key() == Key_End ||
394 ke->key() == Key_Prior || ke->key() == Key_Next )
397 d->hintLabel->hide();
398 d->completionPopup->close();
399 d->editor->setFocus();
400 TQApplication::sendEvent( d->editor, ev );
404 if ( ev->type() == TQEvent::MouseButtonDblClick )
416 d->hintLabel->hide();
417 d->completionPopup->close();
418 d->editor->setFocus();
424 if( !choices.count() )
return;
426 d->completionListBox->clear();
427 for(
unsigned i = 0; i < choices.count(); i++ )
428 new TQListBoxText( (TQListBox*)d->completionListBox, choices[i] );
429 d->completionListBox->setCurrentItem( 0 );
432 d->completionPopup->setMaximumHeight( 100 );
433 d->completionPopup->resize( d->completionListBox->sizeHint() +
434 TQSize( d->completionListBox->verticalScrollBar()->width() + 4,
435 d->completionListBox->horizontalScrollBar()->height() + 4 ) );
436 int h = d->completionListBox->height();
437 int w = d->completionListBox->width();
439 TQPoint pos = d->editor->globalCursorPosition();
443 int screen_num = TQApplication::desktop()->screenNumber( d->completionPopup );
444 TQRect screen = TQApplication::desktop()->screenGeometry( screen_num );
445 if( pos.y() + h > screen.y()+screen.height() )
446 pos.setY( pos.y() - h - d->editor->height() );
447 if( pos.x() + w > screen.x()+screen.width() )
448 pos.setX( screen.x()+screen.width() - w );
450 d->completionPopup->move( pos );
451 d->completionListBox->setFocus();
452 d->completionPopup->show();
463class CellEditor::Private
471 TQTimer* functionCompletionTimer;
473 TQPoint globalCursorPos;
475 bool captureAllKeyEvents : 1;
476 bool checkChoice : 1;
477 bool updateChoice : 1;
478 bool updatingChoice : 1;
482 uint length_namecell;
490 : TQWidget( _parent, _name )
495 d->textEdit =
new KTextEdit(
this);
496 d->globalCursorPos = TQPoint();
497 d->captureAllKeyEvents = captureAllKeyEvents;
498 d->checkChoice =
true;
499 d->updateChoice =
true;
500 d->updatingChoice =
false;
503 d->length_namecell = 0;
510 d->textEdit->setHScrollBarMode(TQScrollView::AlwaysOff);
511 d->textEdit->setVScrollBarMode(TQScrollView::AlwaysOff);
512 d->textEdit->setFrameStyle(TQFrame::NoFrame);
513 d->textEdit->setLineWidth(0);
514 d->textEdit->installEventFilter(
this );
519 d->functionCompletionTimer =
new TQTimer(
this );
520 connect( d->functionCompletion, TQ_SIGNAL( selectedCompletion(
const TQString& ) ),
521 TQ_SLOT( functionAutoComplete(
const TQString& ) ) );
522 connect( d->textEdit, TQ_SIGNAL( textChanged() ), TQ_SLOT( checkFunctionAutoComplete() ) );
523 connect( d->functionCompletionTimer, TQ_SIGNAL( timeout() ),
524 TQ_SLOT( triggerFunctionAutoComplete() ) );
526 if (!cell()->format()->multiRow(cell()->column(),cell()->row()))
527 d->textEdit->setWordWrap(TQTextEdit::NoWrap);
529 d->textEdit->setWrapPolicy(TQTextEdit::AtWordOrDocumentBoundary);
537 setFocusProxy( d->textEdit );
539 connect( d->textEdit, TQ_SIGNAL( cursorPositionChanged(
int,
int) ),
this, TQ_SLOT (slotCursorPositionChanged(
int,
int)));
540 connect( d->textEdit, TQ_SIGNAL( cursorPositionChanged(TQTextCursor*) ),
this, TQ_SLOT (slotTextCursorChanged(TQTextCursor*)));
541 connect( d->textEdit, TQ_SIGNAL( textChanged() ),
this, TQ_SLOT( slotTextChanged() ) );
550 TQFont font( _cell->
format()->font() );
551 font.setPointSizeFloat( 0.01 * _parent->doc()->zoom() * font.pointSizeFloat() );
552 d->textEdit->setFont( font );
554 if (d->fontLength == 0)
556 TQFontMetrics fm( d->textEdit->font() );
557 d->fontLength = fm.width(
'x');
561CellEditor::~CellEditor()
565 delete d->highlighter;
566 delete d->functionCompletion;
567 delete d->functionCompletionTimer;
571Cell* CellEditor::cell()
const
576Canvas* CellEditor::canvas()
const
581TQPoint CellEditor::globalCursorPosition()
const
583 return d->globalCursorPos;
586void CellEditor::checkFunctionAutoComplete()
588 d->functionCompletionTimer->stop();
589 d->functionCompletionTimer->start( 2000,
true );
592void CellEditor::triggerFunctionAutoComplete()
595 int para = 0, curPos = 0;
596 d->textEdit->getCursorPosition( ¶, &curPos );
597 TQString subtext = d->textEdit->text().left( curPos );
600 KSpread::Tokens tokens = f.
scan( subtext );
601 if( !tokens.valid() )
return;
602 if( tokens.count()<1 )
return;
604 KSpread::Token lastToken = tokens[ tokens.count()-1 ];
608 TQString
id = lastToken.
text();
609 if(
id.length() < 1 )
return;
612 TQStringList fnames = KSpread::FunctionRepository::self()->functionNames();
613 TQStringList choices;
614 for(
unsigned i=0; i<fnames.count(); i++ )
615 if( fnames[i].startsWith(
id,
false ) )
616 choices.append( fnames[i] );
620 if( !choices.count() )
return;
623 if( choices.count()==1 )
624 if( choices[0].lower() ==
id.lower() )
628 d->functionCompletion->showCompletion( choices );
631void CellEditor::functionAutoComplete(
const TQString& item )
633 if( item.isEmpty() )
return;
635 int para = 0, curPos = 0;
636 d->textEdit->getCursorPosition( ¶, &curPos );
637 TQString subtext =
text().left( curPos );
640 KSpread::Tokens tokens = f.
scan( subtext );
641 if( !tokens.valid() )
return;
642 if( tokens.count()<1 )
return;
644 KSpread::Token lastToken = tokens[ tokens.count()-1 ];
647 d->textEdit->blockSignals(
true );
648 d->textEdit->setSelection( 0, lastToken.pos()+1, 0, lastToken.pos()+lastToken.
text().length()+1 );
649 d->textEdit->insert( item );
650 d->textEdit->blockSignals(
false );
653void CellEditor::slotCursorPositionChanged(
int ,
int pos)
663 d->highlighter->rehighlight();
665 Tokens tokens = d->highlighter->formulaTokens();
666 uint rangeCounter = 0;
667 uint currentRange = 0;
668 uint regionStart = 0;
670 bool lastWasASemicolon =
false;
672 uint rangeCount = d->highlighter->rangeCount();
673 d->rangeCount = rangeCount;
679 for (uint i = 0; i < tokens.count(); ++i)
681 if (tokens[i].pos() >= pos - 1)
684 type = tokens[i].type();
687 if (lastWasASemicolon)
689 regionEnd = rangeCounter++;
690 lastWasASemicolon =
false;
696 lastWasASemicolon =
true;
699 lastWasASemicolon =
false;
708 if (!lastWasASemicolon)
710 regionStart = rangeCounter;
712 regionEnd = rangeCounter;
713 currentRange = rangeCounter++;
720 lastWasASemicolon =
true;
724 lastWasASemicolon =
false;
726 regionStart = currentRange + 1;
727 regionEnd = regionStart - 1;
736 d->canvas->choice()->setActiveElement(currentRange);
737 d->canvas->choice()->setActiveSubRegion(regionStart, regionEnd-regionStart+1);
740 if (!d->updatingChoice)
742 if (d->highlighter->rangeChanged())
744 d->highlighter->resetRangeChanged();
746 disconnect( d->canvas->choice(), TQ_SIGNAL(changed(
const Region&)),
747 d->canvas->view(), TQ_SLOT(slotScrollChoice(
const Region&)) );
748 d->canvas->doc()->emitBeginOperation();
749 setUpdateChoice(
false);
751 Tokens tokens = d->highlighter->formulaTokens();
752 d->canvas->choice()->update();
753 d->canvas->choice()->clear();
755 Region::ConstIterator it;
760 TQValueList<Region> alreadyUsedRegions;
762 for (uint i = 0; i < tokens.count(); ++i)
764 Token token = tokens[i];
768 Region region(d->canvas->view(), token.
text());
769 it = region.constBegin();
771 if (!alreadyUsedRegions.contains(region))
773 TQRect r=(*it)->rect();
775 if (d->canvas->choice()->isEmpty())
776 d->canvas->choice()->initialize((*it)->rect(), (*it)->sheet());
778 d->canvas->choice()->extend((*it)->rect(), (*it)->sheet());
780 alreadyUsedRegions.append(region);
784 setUpdateChoice(
true);
785 d->canvas->doc()->emitEndOperation(*d->canvas->choice());
786 connect( d->canvas->choice(), TQ_SIGNAL(changed(
const Region&)),
787 d->canvas->view(), TQ_SLOT(slotScrollChoice(
const Region&)) );
792void CellEditor::slotTextCursorChanged(TQTextCursor* cursor)
794 TQTextStringChar *chr = cursor->paragraph()->at( cursor->index() );
795 int h = cursor->paragraph()->lineHeightOfChar( cursor->index() );
796 int x = cursor->paragraph()->rect().x() + chr->x;
798 cursor->paragraph()->lineHeightOfChar( cursor->index(), &dummy, &y );
799 y += cursor->paragraph()->rect().y();
801 d->globalCursorPos = d->textEdit->mapToGlobal( d->textEdit-> contentsToViewport( TQPoint( x, y + h ) ) );
811 d->textEdit->paste();
819void CellEditor::setEditorFont(TQFont
const & font,
bool updateSize)
821 TQFont tmpFont( font );
822 tmpFont.setPointSizeFloat( 0.01 * canvas()->doc()->zoom() * tmpFont.pointSizeFloat() );
823 d->textEdit->setFont( tmpFont );
827 TQFontMetrics fm( d->textEdit->font() );
828 d->fontLength = fm.width(
'x');
830 int mw = fm.width( d->textEdit->text() ) + d->fontLength;
835 int mh = fm.height();
839 setGeometry(x(), y(), mw, mh);
843void CellEditor::slotCompletionModeChanged(TDEGlobalSettings::Completion _completion)
845 canvas()->view()->doc()->setCompletionMode( _completion );
848void CellEditor::slotTextChanged()
855 if (t.length() > d->length)
857 d->length = t.length();
859 TQFontMetrics fm(d->textEdit->font());
861 int requiredWidth = fm.width(t) + (2*fm.width(
'x'));
867 if (d->textEdit->wordWrap() == TQTextEdit::NoWrap)
869 if (requiredWidth > width())
871 if (t.isRightToLeft())
873 setGeometry(x() - requiredWidth + width(), y(), requiredWidth,height());
877 setGeometry(x(), y(), requiredWidth,height());
883 int requiredHeight = d->textEdit->heightForWidth(width());
885 if (requiredHeight > height())
887 setGeometry(x(), y(), width(), requiredHeight);
910 if ( (cell()->formatType()) == Percentage_format )
912 if ( (t.length() == 1) && t[0].isDigit() )
914 TQString tmp = t +
" %";
915 d->textEdit->setText(tmp);
916 d->textEdit->setCursorPosition(0,1);
921 canvas()->view()->editWidget()->setText( t );
925void CellEditor::setCheckChoice(
bool state)
927 d->checkChoice = state;
930bool CellEditor::checkChoice()
938 d->length_namecell = 0;
941 TQString
text = d->textEdit->text();
942 if (
text[0] !=
'=' )
944 canvas()->setChooseMode(
false);
949 d->textEdit->getCursorPosition(¶, &cur);
951 Tokens tokens = d->highlighter->formulaTokens();
954 if (tokens.count() < 1)
956 canvas()->startChoose();
961 for (uint i = 0; i < tokens.count(); ++i)
963 if (tokens[i].pos() >= cur - 1)
974 canvas()->setChooseMode(
true);
978 d->length_namecell = token.
text().length();
979 canvas()->setChooseMode(
true);
983 canvas()->setChooseMode(
false);
993void CellEditor::setUpdateChoice(
bool state)
995 d->updateChoice = state;
998void CellEditor::updateChoice()
1002 if (!d->updateChoice)
1007 d->updatingChoice =
true;
1009 Selection* choice = d->canvas->choice();
1014 if (!choice->activeElement())
1018 if (++choice->constBegin() == choice->constEnd())
1022 TQString name_cell = choice->activeSubRegionName();
1024 Tokens tokens = d->highlighter->formulaTokens();
1027 if (!tokens.empty())
1029 Token token = tokens[d->currentToken];
1033 start = token.pos() + 1;
1034 length = token.
text().length();
1038 start = token.pos() + token.
text().length() + 1;
1042 d->length_namecell = name_cell.length();
1043 d->length_text =
text().length();
1046 TQString oldText =
text();
1047 TQString newText = oldText.left(start) + name_cell + oldText.right(d->length_text - start - length);
1049 setCheckChoice(
false );
1051 setCheckChoice(
true );
1052 setCursorPosition( start + d->length_namecell );
1054 d->canvas->view()->editWidget()->setText( newText );
1058 d->updatingChoice =
false;
1061void CellEditor::resizeEvent( TQResizeEvent* )
1063 d->textEdit->setGeometry( 0, 0, width(), height() );
1066void CellEditor::handleKeyPressEvent( TQKeyEvent * _ev )
1068 if (_ev->key() == TQt::Key_F4)
1070 if (d->textEdit == 0)
1072 TQApplication::sendEvent( d->textEdit, _ev );
1076 TQRegExp exp(
"(\\$?)([a-zA-Z]+)(\\$?)([0-9]+)$");
1079 d->textEdit->getCursorPosition(¶,&cur);
1087 for( i = 0; i < 10; i++ )
1089 tmp = d->textEdit->text().left( cur+i );
1090 tmp2 = d->textEdit->text().right( d->textEdit->text().length() - cur - i );
1092 n = exp.search(tmp);
1096 if (n == -1)
return;
1099 if ((exp.cap(1) ==
"$") && (exp.cap(3) ==
"$"))
1100 newPart =
"$" + exp.cap(2) + exp.cap(4);
1101 else if ((exp.cap(1) !=
"$") && (exp.cap(3) !=
"$"))
1102 newPart =
"$" + exp.cap(2) +
"$" + exp.cap(4);
1103 else if ((exp.cap(1) ==
"$") && (exp.cap(3) !=
"$"))
1104 newPart = exp.cap(2) +
"$" + exp.cap(4);
1105 else if ((exp.cap(1) !=
"$") && (exp.cap(3) ==
"$"))
1106 newPart = exp.cap(2) + exp.cap(4);
1108 TQString newString = tmp.left(n);
1109 newString += newPart;
1110 cur = newString.length() - i;
1113 d->textEdit->setText(newString);
1114 d->textEdit->setCursorPosition( 0, cur );
1122 TQApplication::sendEvent( d->textEdit, _ev );
1125void CellEditor::handleIMEvent( TQIMEvent * _ev )
1128 TQApplication::sendEvent( d->textEdit, _ev );
1133 return d->textEdit->text();
1136void CellEditor::setText(TQString text)
1138 d->textEdit->setText(
text);
1143 d->textEdit->setCursorPosition(0,
text.length());
1145 if (d->fontLength == 0)
1147 TQFontMetrics fm( d->textEdit->font() );
1148 d->fontLength = fm.width(
'x');
1152int CellEditor::cursorPosition()
const
1155 d->textEdit->getCursorPosition(¶,&cur);
1160void CellEditor::setCursorPosition(
int pos )
1162 d->textEdit->setCursorPosition(0,pos);
1163 canvas()->view()->editWidget()->setCursorPosition( pos );
1169 if ( o != d->textEdit )
1171 if ( e->type() == TQEvent::FocusOut )
1173 canvas()->setLastEditorWithFocus( Canvas::CellEditor );
1177 if ( e->type() == TQEvent::KeyPress || e->type() == TQEvent::KeyRelease )
1179 TQKeyEvent* k = (TQKeyEvent*)e;
1180 if (!(k->state() & TQt::ShiftButton) || canvas()->chooseMode())
1184 if (k->key() == Key_Return || k->key() == Key_Enter)
1186 kdDebug() <<
"CellEditor::eventFilter: canvas()->endChoose();" << endl;
1187 canvas()->endChoose();
1192 if ( k->key() == Key_Up || k->key() == Key_Down ||
1193 k->key() == Key_Next || k->key() == Key_Prior ||
1194 k->key() == Key_Escape || k->key() == Key_Tab ||
1195 k->key() == Key_Return || k->key() == Key_Enter)
1198 TQApplication::sendEvent( parent(), e );
1202 else if ( k->state() & TQt::ShiftButton && ( k->key() == Key_Return || k->key() == Key_Enter ) )
1205 d->cell->format()->setMultiRow(
true );
1208 if ( e->type() == TQEvent::KeyPress && !k->text().isEmpty() )
1210 canvas()->setChooseMode(
false);
1218 if ( ((k->key() == TQt::Key_Left) || (k->key() == TQt::Key_Right)) && (!d->captureAllKeyEvents)) {
1219 TQApplication::sendEvent (parent(), e);
1227void CellEditor::setCursorToRange(uint pos)
1231 d->updatingChoice =
true;
1233 Tokens tokens = d->highlighter->formulaTokens();
1234 for (uint i = 0; i < tokens.count(); ++i)
1236 Token token = tokens[i];
1242 setCursorPosition(token.pos() + token.
text().length() + 1);
1247 d->updatingChoice =
false;
1258ComboboxLocationEditWidget::ComboboxLocationEditWidget( TQWidget * _parent,
1260 : KComboBox( _parent,
"ComboboxLocationEditWidget" )
1262 m_locationWidget =
new LocationEditWidget( _parent, _view );
1263 setLineEdit( m_locationWidget );
1266 TQValueList<Reference>::Iterator it;
1267 TQValueList<Reference> area = _view->doc()->listArea();
1268 for ( it = area.begin(); it != area.end(); ++it )
1269 slotAddAreaName( (*it).ref_name);
1270 connect(
this, TQ_SIGNAL( activated (
const TQString & ) ), m_locationWidget, TQ_SLOT( slotActivateItem() ) );
1274void ComboboxLocationEditWidget::slotAddAreaName(
const TQString &_name)
1276 insertItem( _name );
1277 m_locationWidget->addCompletionItem( _name );
1280void ComboboxLocationEditWidget::slotRemoveAreaName(
const TQString &_name )
1282 for (
int i = 0; i<count(); i++ )
1284 if ( text(i)==_name )
1290 m_locationWidget->removeCompletionItem( _name );
1301LocationEditWidget::LocationEditWidget( TQWidget * _parent,
1303 : KLineEdit( _parent,
"LocationEditWidget" ),
1306 setCompletionObject( &completionList,
true );
1307 setCompletionMode(TDEGlobalSettings::CompletionAuto );
1310void LocationEditWidget::addCompletionItem(
const TQString &_item )
1312 kdDebug()<<
" LocationEditWidget::addCompletionItem add :"<<_item<<endl;
1313 if ( completionList.items().contains( _item) == 0 )
1315 completionList.addItem( _item );
1316 kdDebug()<<
" _utem :"<<_item<<endl;
1317 kdDebug()<<
" completionList.items().count()"<<completionList.items().count()<<endl;
1321void LocationEditWidget::removeCompletionItem(
const TQString &_item )
1323 completionList.removeItem( _item );
1326void LocationEditWidget::slotActivateItem()
1331bool LocationEditWidget::activateItem()
1333 TQString ltext = text();
1334 TQString tmp = ltext.lower();
1335 TQValueList<Reference>::Iterator it;
1336 TQValueList<Reference> area = m_pView->doc()->listArea();
1337 for ( it = area.begin(); it != area.end(); ++it )
1339 if ((*it).ref_name == tmp)
1341 TQString tmp = (*it).sheet_name;
1343 tmp += util_rangeName((*it).rect);
1344 m_pView->selectionInfo()->initialize( Region(m_pView,tmp) );
1351 int pos = ltext.find(
'!');
1353 tmp = ltext.left(pos)+ltext.mid(pos).upper();
1355 tmp = ltext.upper();
1358 if ( ltext.contains(
':' ) )
1359 m_pView->selectionInfo()->initialize( Region(m_pView,tmp) );
1363 Region region(m_pView,tmp);
1364 bool validName =
true;
1365 for (
unsigned int i = 0; i < ltext.length(); ++i)
1367 if (!ltext[i].isLetter())
1373 if ( !region.isValid() && validName)
1375 TQRect rect( m_pView->selectionInfo()->selection() );
1376 Sheet * t = m_pView->activeSheet();
1379 m_pView->doc()->addAreaName(rect, ltext.lower(), t->sheetName());
1384 m_pView->selectionInfo()->initialize(region);
1389 m_pView->canvasWidget()->setFocus();
1394void LocationEditWidget::keyPressEvent( TQKeyEvent * _ev )
1398 if ( _ev->state() & ( TQt::AltButton | TQt::ControlButton ) )
1400 TQLineEdit::keyPressEvent( _ev );
1408 switch( _ev->key() )
1413 if ( activateItem() )
1421 if ( m_pView->selectionInfo()->isSingular() ) {
1423 + TQString::number( m_pView->canvasWidget()->markerRow() ) );
1426 + TQString::number( m_pView->selectionInfo()->lastRange().top() )
1429 + TQString::number( m_pView->selectionInfo()->lastRange().bottom() ) );
1431 m_pView->canvasWidget()->setFocus();
1435 TQLineEdit::keyPressEvent( _ev );
1451EditWidget::EditWidget( TQWidget *_parent,
Canvas *_canvas,
1452 TQButton *cancelButton, TQButton *okButton )
1453 : TQLineEdit( _parent,
"EditWidget" )
1455 m_pCanvas = _canvas;
1456 Q_ASSERT(m_pCanvas != NULL);
1459 m_pCancelButton = cancelButton;
1460 m_pOkButton = okButton;
1463 installEventFilter(m_pCanvas);
1465 if ( !m_pCanvas->doc()->isReadWrite() || !m_pCanvas->activeSheet() )
1466 setEnabled(
false );
1468 TQObject::connect( m_pCancelButton, TQ_SIGNAL( clicked() ),
1469 this, TQ_SLOT( slotAbortEdit() ) );
1470 TQObject::connect( m_pOkButton, TQ_SIGNAL( clicked() ),
1471 this, TQ_SLOT( slotDoneEdit() ) );
1473 setEditMode(
false );
1476void EditWidget::showEditWidget(
bool _show)
1480 m_pCancelButton->show();
1481 m_pOkButton->show();
1486 m_pCancelButton->hide();
1487 m_pOkButton->hide();
1492void EditWidget::slotAbortEdit()
1494 m_pCanvas->deleteEditor(
false );
1498void EditWidget::slotDoneEdit()
1500 m_pCanvas->deleteEditor(
true , isArray);
1505void EditWidget::keyPressEvent ( TQKeyEvent* _ev )
1508 if (( ( _ev->state() & ( TQt::AltButton | TQt::ControlButton ) )
1509 || ( _ev->state() & TQt::ShiftButton )
1510 || ( _ev->key() == Key_Shift )
1511 || ( _ev->key() == Key_Control ) )
1512 && (_ev->key() != Key_Return) && (_ev->key() != Key_Enter))
1514 TQLineEdit::keyPressEvent( _ev );
1519 if ( !m_pCanvas->doc()->isReadWrite() )
1522 if ( !m_pCanvas->editor() )
1525 m_pCanvas->createEditor( Canvas::CellEditor,
false );
1527 CellEditor * cellEditor = (CellEditor*) m_pCanvas->editor();
1529 switch ( _ev->key() )
1535 cellEditor->setText( text());
1541 isArray = (_ev->state() & TQt::AltButton) &&
1542 (_ev->state() & TQt::ControlButton);
1544 m_pCanvas->view()->updateEditWidget();
1548 cellEditor->setFocus();
1549 cellEditor->setText( text());
1550 cellEditor->setCursorPosition(cursorPosition());
1554 TQLineEdit::keyPressEvent( _ev );
1557 cellEditor->setCheckChoice(
false );
1558 cellEditor->setText( text() );
1559 cellEditor->setCheckChoice(
true );
1560 cellEditor->setCursorPosition( cursorPosition() );
1564void EditWidget::setEditMode(
bool mode )
1566 m_pCancelButton->setEnabled(mode);
1567 m_pOkButton->setEnabled(mode);
1570void EditWidget::focusOutEvent( TQFocusEvent* ev )
1574 m_pCanvas->setLastEditorWithFocus( Canvas::EditWidget );
1576 TQLineEdit::focusOutEvent( ev );
1579void EditWidget::setText(
const TQString& t )
1584 TQLineEdit::setText( t );
1589#include "kspread_editors.moc"
The canvas builds a part of the GUI of KSpread.
void endChoose()
Switches to selection mode.
void copy()
wrapper to KTextEdit::copy()
bool eventFilter(TQObject *o, TQEvent *e)
Steals some key events from the TQLineEdit and sends it to the Canvas ( its parent ) instead.
void paste()
wrapper to KTextEdit::paste()
TQString text() const
wrapper to KTextEdit::text()
CellEditor(Cell *cell, Canvas *_parent=0, bool captureAllKeyEvents=false, const char *_name=0)
Creates a new CellEditor.
void cut()
wrapper to KTextEdit::cut()
For every cell in the spread sheet there is a Cell object.
Format * format() const
Returns the format object of this cell.
TQString columnName() const
Returns the column name of the cell.
Provides autocompletition facilities in formula editors.
void doneCompletion()
Hides the autocompletion list box if it is visible and emits the selectedCompletion signal.
bool eventFilter(TQObject *o, TQEvent *e)
Handles various keyboard and mouse actions which may occur on the autocompletion popup list.
void selectedCompletion(const TQString &item)
Emitted, if the user selects a function name from the list.
void showCompletion(const TQStringList &choices)
Populates the autocompletion list box with the specified choices and shows it so that the user can vi...
Represents a region within a workbook.
@ Semicolon
; (argument separator)
TQString text() const
Returns text associated with the token.
Type type() const
Returns type of the token.
bool isIdentifier() const
Returns true if token is an identifier.
@ Identifier
function name or named area
@ Cell
$A$1, F4, Sheet2!B5, 'Sales Forecast'!Sum
@ Boolean
True, False (also i18n-ized).
@ Float
3.141592, 1e10, 5.9e-7
@ String
"KOffice", "The quick brown fox..."
Op asOperator() const
Returns operator value for an operator token.
Class Tokens represents array of tokens.
The View class displays a KSpread document.