Index: khtml/Makefile.am =================================================================== RCS file: /home/kde/kdelibs/khtml/Makefile.am,v retrieving revision 1.166 diff -u -2 -r1.166 Makefile.am --- khtml/Makefile.am 11 Mar 2005 19:30:00 -0000 1.166 +++ khtml/Makefile.am 28 Mar 2005 17:18:10 -0000 @@ -56,4 +56,5 @@ $(LIB_KPARTS) \ $(LIBTHAI) \ + $(top_builddir)/interfaces/ktexteditor/libktexteditor.la \ $(top_builddir)/kdeprint/libkdeprint.la \ $(top_builddir)/kutils/libkutils.la \ Index: khtml/rendering/render_form.cpp =================================================================== RCS file: /home/kde/kdelibs/khtml/rendering/render_form.cpp,v retrieving revision 1.285 diff -u -2 -r1.285 render_form.cpp --- khtml/rendering/render_form.cpp 15 Mar 2005 18:05:17 -0000 1.285 +++ khtml/rendering/render_form.cpp 28 Mar 2005 17:18:13 -0000 @@ -55,4 +55,7 @@ #include +#include +#include + using namespace khtml; @@ -86,4 +89,5 @@ KHTMLAssert( minMaxKnown() ); + // minimum height m_height = 0; @@ -96,4 +100,5 @@ m_height-borderTop()-borderBottom()-paddingTop()-paddingBottom()); + if ( !style()->width().isPercent() ) setNeedsLayout(false); @@ -1239,4 +1244,5 @@ m_findNextAction = KStdAction::findNext( this, SLOT( slotFindNext() ), ac ); m_replaceAction = KStdAction::replace( this, SLOT( slotReplace() ), ac ); + m_switchEditor = new KAction( i18n("Edit with ktexteditor"), 0, this, SLOT( slotSwitchEditor() ), ac ); } @@ -1274,4 +1280,6 @@ m_replaceAction->plug(popup); m_replaceAction->setEnabled( !text().isEmpty() ); + + m_switchEditor->plug(popup); } @@ -1279,4 +1287,8 @@ } +void TextAreaWidget::slotSwitchEditor() +{ + emit switchEditor(); +} void TextAreaWidget::slotFindHighlight(const QString& text, int matchingIndex, int matchingLength) @@ -1548,8 +1560,43 @@ // ------------------------------------------------------------------------- +TextAreaPart::TextAreaPart(int , QWidget* parent) + : QHBox(parent) +{ + editor = KTextEditor::EditorChooser::createDocument( this ); + editorView = editor->createView( this ); + connect(editor,SIGNAL(textChanged()),this,SLOT(slotTextChanged())); +} +TextAreaPart::~TextAreaPart() { +} +void TextAreaPart::slotTextChanged() { + emit textChanged(); +} +void TextAreaPart::selectAll() { + KTextEditor::SelectionInterface* seliface = dynamic_cast(editor); + if ( seliface ) + seliface->selectAll(); +} + +QString TextAreaPart::text() const { + KTextEditor::EditInterface* ediface = dynamic_cast(editor); + if ( ediface ) + return ediface->text(); + return QString::null; +} +void TextAreaPart::setText( const QString& text ) { + KTextEditor::EditInterface* ediface = dynamic_cast(editor); + if ( ediface ) + ediface->setText( text ); +} + + + +// ------------------------------------------------------------------------- + RenderTextArea::RenderTextArea(HTMLTextAreaElementImpl *element) : RenderFormElement(element) { scrollbarsStyled = false; + mEditorPart = NULL; TextAreaWidget *edit = new TextAreaWidget(element->wrap(), view()); @@ -1559,4 +1606,5 @@ edit->setTabChangesFocus( ! settings->allowTabulation() ); + connect(edit,SIGNAL(switchEditor()),this,SLOT(slotSwitchEditor())); connect(edit,SIGNAL(textChanged()),this,SLOT(slotTextChanged())); } @@ -1572,6 +1620,5 @@ void RenderTextArea::handleFocusOut() { - TextAreaWidget* w = static_cast(m_widget); - if ( w && element()->m_dirtyvalue ) { + if ( m_widget && element()->m_dirtyvalue ) { element()->m_value = text(); element()->m_dirtyvalue = false; @@ -1584,13 +1631,19 @@ KHTMLAssert( !minMaxKnown() ); - TextAreaWidget* w = static_cast(m_widget); const QFontMetrics &m = style()->fontMetrics(); - w->setTabStopWidth(8 * m.width(" ")); - QSize size( kMax(element()->cols(), 1L)*m.width('x') + w->frameWidth() + - w->verticalScrollBar()->sizeHint().width(), - kMax(element()->rows(), 1L)*m.lineSpacing() + w->frameWidth()*4 + - (w->wordWrap() == QTextEdit::NoWrap ? - w->horizontalScrollBar()->sizeHint().height() : 0) - ); + + QSize size; + if ( mEditorPart ) { + size.setWidth( kMax( element()->cols(), 1L)*m.width('x') + mEditorPart->width() ); + size.setHeight( kMax( element()->rows(), 3L)*m.lineSpacing() + mEditorPart->width()*4 ); + } else { + TextAreaWidget* w = static_cast(m_widget); + w->setTabStopWidth(8 * m.width(" ")); + size.setWidth( kMax(element()->cols(), 1L)*m.width('x') + w->frameWidth() + + w->verticalScrollBar()->sizeHint().width() ); + size.setHeight( kMax(element()->rows(), 1L)*m.lineSpacing() + w->frameWidth()*4 + + (w->wordWrap() == QTextEdit::NoWrap ? + w->horizontalScrollBar()->sizeHint().height() : 0) ); + } setIntrinsicWidth( size.width() ); @@ -1606,4 +1659,5 @@ RenderFormElement::setStyle(_style); + if ( mEditorPart ) return; widget()->blockSignals(true); widget()->setAlignment( _style->direction() == RTL ? @@ -1620,5 +1674,7 @@ KHTMLAssert( needsLayout() ); + RenderFormElement::layout(); + if ( mEditorPart ) return; TextAreaWidget* w = static_cast(m_widget); @@ -1633,18 +1689,28 @@ void RenderTextArea::updateFromElement() { - TextAreaWidget* w = static_cast(m_widget); - w->setReadOnly(element()->readOnly()); QString elementText = element()->value().string(); - if ( elementText != w->text() ) - { - w->blockSignals(true); - int line, col; - w->getCursorPosition( &line, &col ); - int cx = w->contentsX(); - int cy = w->contentsY(); - w->setText( elementText ); - w->setCursorPosition( line, col ); - w->scrollBy( cx, cy ); - w->blockSignals(false); + if ( mEditorPart ) { + TextAreaPart* w = static_cast(m_widget); + if ( elementText != w->text() ) + { + w->blockSignals(true); + w->setText( elementText ); + w->blockSignals(false); + } + } else { + TextAreaWidget* w = static_cast(m_widget); + w->setReadOnly(element()->readOnly()); + if ( elementText != w->text() ) + { + w->blockSignals(true); + int line, col; + w->getCursorPosition( &line, &col ); + int cx = w->contentsX(); + int cy = w->contentsY(); + w->setText( elementText ); + w->setCursorPosition( line, col ); + w->scrollBy( cx, cy ); + w->blockSignals(false); + } } element()->m_dirtyvalue = false; @@ -1696,4 +1762,9 @@ { QString txt; + if ( mEditorPart ) { + TextAreaPart* w = static_cast(m_widget); + txt = w->text(); + } else { + TextAreaWidget* w = static_cast(m_widget); @@ -1718,4 +1789,5 @@ else txt = w->text(); + } return expandLF(txt); @@ -1725,4 +1797,5 @@ void RenderTextArea::highLightWord( unsigned int length, unsigned int pos ) { + if ( mEditorPart ) return; TextAreaWidget* w = static_cast(m_widget); if ( w ) @@ -1734,5 +1807,5 @@ { element()->m_dirtyvalue = true; - if (element()->m_value != text()) + if (mEditorPart || element()->m_value != text()) element()->m_unsubmittedFormChange = true; } @@ -1740,5 +1813,20 @@ void RenderTextArea::select() { - static_cast(m_widget)->selectAll(); + if ( mEditorPart ) + static_cast(m_widget)->selectAll(); + else + static_cast(m_widget)->selectAll(); +} + +void RenderTextArea::slotSwitchEditor() +{ + mEditorPart = new TextAreaPart( element()->wrap(), view() ); + bool k_needsLayout = needsLayout(); + setNeedsLayout( false ); + setQWidget( mEditorPart ); + connect(mEditorPart,SIGNAL(textChanged()),this,SLOT(slotTextChanged())); + repaint(); + updateFromElement(); + setNeedsLayout( k_needsLayout ); } Index: khtml/rendering/render_form.h =================================================================== RCS file: /home/kde/kdelibs/khtml/rendering/render_form.h,v retrieving revision 1.117 diff -u -2 -r1.117 render_form.h --- khtml/rendering/render_form.h 22 Nov 2004 00:16:08 -0000 1.117 +++ khtml/rendering/render_form.h 28 Mar 2005 17:18:13 -0000 @@ -36,4 +36,7 @@ #include +#include +#include +#include #include #include @@ -421,5 +424,7 @@ TextAreaWidget(int wrap, QWidget* parent); virtual ~TextAreaWidget(); - +signals: + void switchEditor(); + protected: virtual bool event (QEvent *e ); @@ -427,4 +432,5 @@ virtual QPopupMenu* createPopupMenu() { return KTextEdit::createPopupMenu(); } private slots: + void slotSwitchEditor(); void slotFind(); void slotDoFind(); @@ -443,8 +449,27 @@ KAction *m_findNextAction; KAction *m_replaceAction; + KAction *m_switchEditor; int m_findIndex, m_findPara; int m_repIndex, m_repPara; }; +// ------------------------------------------------------------------------- +class TextAreaPart : public QHBox +{ + Q_OBJECT +public: + TextAreaPart(int wrap, QWidget* parent); + virtual ~TextAreaPart(); + QString text() const; + void setText( const QString& text ); + void selectAll(); +signals: + void textChanged(); +private slots : + void slotTextChanged(); +private : + KTextEditor::Document* editor; + KTextEditor::View* editorView; +}; // ------------------------------------------------------------------------- @@ -477,4 +502,5 @@ protected slots: void slotTextChanged(); + void slotSwitchEditor(); protected: @@ -485,4 +511,5 @@ bool scrollbarsStyled; + TextAreaPart* mEditorPart; };