2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2000-2003 Dirk Mueller (mueller@kde.org)
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
27 #include "rendering/render_replaced.h"
28 #include "rendering/render_image.h"
29 #include "rendering/render_flow.h"
30 #include "rendering/render_style.h"
31 #include "khtmlview.h"
32 #include "html/html_formimpl.h"
36 #include <ktextedit.h>
37 #include <kurlrequester.h>
38 #include <klineedit.h>
39 #include <QtGui/QCheckBox>
40 #include <QtGui/QRadioButton>
41 #include <QtGui/QPushButton>
42 #include <klistwidget.h>
43 #include <kcombobox.h>
44 #include "dom/dom_misc.h"
54 class HTMLInputElementImpl
;
55 class HTMLSelectElementImpl
;
56 class HTMLGenericFormElementImpl
;
57 class HTMLTextAreaElementImpl
;
63 // -------------------------------------------------------------------------
65 class RenderFormElement
: public khtml::RenderWidget
68 RenderFormElement(DOM::HTMLGenericFormElementImpl
* node
);
69 virtual ~RenderFormElement();
71 virtual const char *renderName() const { return "RenderForm"; }
73 virtual bool isFormElement() const { return true; }
75 // form elements never have padding
76 virtual int paddingTop() const { return 0; }
77 virtual int paddingBottom() const { return 0; }
78 virtual int paddingLeft() const { return 0; }
79 virtual int paddingRight() const { return 0; }
81 virtual void updateFromElement();
83 virtual void layout();
84 virtual short baselinePosition( bool ) const;
86 DOM::HTMLGenericFormElementImpl
*element() const
87 { return static_cast<DOM::HTMLGenericFormElementImpl
*>(RenderObject::element()); }
90 virtual bool isRenderButton() const { return false; }
91 virtual bool isEditable() const { return false; }
92 Qt::AlignmentFlag
textAlignment() const;
98 // -------------------------------------------------------------------------
100 // generic class for all buttons
101 class RenderButton
: public RenderFormElement
105 RenderButton(DOM::HTMLGenericFormElementImpl
* node
);
107 virtual const char *renderName() const { return "RenderButton"; }
109 virtual short baselinePosition( bool ) const;
111 // don't even think about making this method virtual!
112 DOM::HTMLInputElementImpl
* element() const
113 { return static_cast<DOM::HTMLInputElementImpl
*>(RenderObject::element()); }
116 virtual bool isRenderButton() const { return true; }
119 // -------------------------------------------------------------------------
121 class CheckBoxWidget
: public QCheckBox
, public KHTMLWidget
124 CheckBoxWidget(QWidget
*p
): QCheckBox(p
) { m_kwp
->setIsRedirected(true); }
127 class RenderCheckBox
: public RenderButton
131 RenderCheckBox(DOM::HTMLInputElementImpl
* node
);
133 virtual const char *renderName() const { return "RenderCheckBox"; }
134 virtual void updateFromElement();
135 virtual void calcMinMaxWidth();
137 virtual bool handleEvent(const DOM::EventImpl
&);
139 QCheckBox
*widget() const { return static_cast<QCheckBox
*>(m_widget
); }
142 virtual void slotStateChanged(int state
);
145 // -------------------------------------------------------------------------
147 class RadioButtonWidget
: public QRadioButton
, public KHTMLWidget
150 RadioButtonWidget(QWidget
* p
): QRadioButton(p
) { m_kwp
->setIsRedirected(true); }
153 class RenderRadioButton
: public RenderButton
157 RenderRadioButton(DOM::HTMLInputElementImpl
* node
);
159 virtual const char *renderName() const { return "RenderRadioButton"; }
161 virtual void calcMinMaxWidth();
162 virtual void updateFromElement();
164 virtual bool handleEvent(const DOM::EventImpl
&);
166 QRadioButton
*widget() const { return static_cast<QRadioButton
*>(m_widget
); }
169 virtual void slotToggled(bool);
173 // -------------------------------------------------------------------------
175 class PushButtonWidget
: public QPushButton
, public KHTMLWidget
178 PushButtonWidget(QWidget
* p
): QPushButton(p
) { m_kwp
->setIsRedirected(true); }
181 class RenderSubmitButton
: public RenderButton
184 RenderSubmitButton(DOM::HTMLInputElementImpl
*element
);
186 virtual const char *renderName() const { return "RenderSubmitButton"; }
188 virtual void calcMinMaxWidth();
189 virtual void updateFromElement();
190 virtual short baselinePosition( bool ) const;
195 // -------------------------------------------------------------------------
197 class RenderImageButton
: public RenderImage
200 RenderImageButton(DOM::HTMLInputElementImpl
*element
)
201 : RenderImage(element
) {}
203 virtual const char *renderName() const { return "RenderImageButton"; }
207 // -------------------------------------------------------------------------
209 class RenderResetButton
: public RenderSubmitButton
212 RenderResetButton(DOM::HTMLInputElementImpl
*element
);
214 virtual const char *renderName() const { return "RenderResetButton"; }
218 // -------------------------------------------------------------------------
220 class RenderPushButton
: public RenderSubmitButton
223 RenderPushButton(DOM::HTMLInputElementImpl
*element
)
224 : RenderSubmitButton(element
) {}
228 // -------------------------------------------------------------------------
230 class RenderLineEdit
: public RenderFormElement
234 RenderLineEdit(DOM::HTMLInputElementImpl
*element
);
236 virtual void calcMinMaxWidth();
238 virtual const char *renderName() const { return "RenderLineEdit"; }
239 virtual void updateFromElement();
240 virtual void setStyle(RenderStyle
*style
);
244 KLineEdit
*widget() const { return static_cast<KLineEdit
*>(m_widget
); }
245 DOM::HTMLInputElementImpl
* element() const
246 { return static_cast<DOM::HTMLInputElementImpl
*>(RenderObject::element()); }
247 void highLightWord( unsigned int length
, unsigned int pos
);
249 long selectionStart();
251 void setSelectionStart(long pos
);
252 void setSelectionEnd(long pos
);
253 void setSelectionRange(long start
, long end
);
255 void slotReturnPressed();
256 void slotTextChanged(const QString
&string
);
258 virtual void handleFocusOut();
261 virtual bool isEditable() const { return true; }
262 virtual bool canHaveBorder() const { return true; }
265 // -------------------------------------------------------------------------
267 class LineEditWidget
: public KLineEdit
, public KHTMLWidget
271 LineEditWidget(DOM::HTMLInputElementImpl
* input
,
272 KHTMLView
* view
, QWidget
* parent
);
275 void highLightWord( unsigned int length
, unsigned int pos
);
278 virtual bool event( QEvent
*e
);
279 virtual void paintEvent( QPaintEvent
*pe
);
280 virtual void mouseMoveEvent(QMouseEvent
*e
);
281 virtual void contextMenuEvent(QContextMenuEvent
*e
);
283 void clearHistoryActivated();
284 void slotCheckSpelling();
285 void slotSpellCheckDone( const QString
&s
);
286 void spellCheckerMisspelling( const QString
&text
, int pos
);
287 void spellCheckerCorrected( const QString
&, int, const QString
&);
288 void spellCheckerFinished();
291 enum LineEditMenuID
{
294 DOM::HTMLInputElementImpl
* m_input
;
296 KAction
*m_spellAction
;
299 // -------------------------------------------------------------------------
301 class RenderFieldset
: public RenderBlock
304 RenderFieldset(DOM::HTMLGenericFormElementImpl
*element
);
306 virtual void calcMinMaxWidth();
307 virtual const char *renderName() const { return "RenderFieldSet"; }
308 virtual RenderObject
* layoutLegend(bool relayoutChildren
);
309 virtual void setStyle(RenderStyle
* _style
);
312 virtual void paintBoxDecorations(PaintInfo
& pI
, int _tx
, int _ty
);
313 void paintBorderMinusLegend(QPainter
*p
, int _tx
, int _ty
, int w
,
314 int h
, const RenderStyle
*style
, int lx
, int lw
, int lb
);
315 RenderObject
* findLegend() const;
316 virtual short intrinsicWidth() const { return m_intrinsicWidth
; }
317 int m_intrinsicWidth
;
320 // -------------------------------------------------------------------------
322 class FileButtonWidget
: public KUrlRequester
, public KHTMLWidget
325 FileButtonWidget(QWidget
* p
): KUrlRequester(p
) { m_kwp
->setIsRedirected(true); }
328 class RenderFileButton
: public RenderFormElement
332 RenderFileButton(DOM::HTMLInputElementImpl
*element
);
334 virtual const char *renderName() const { return "RenderFileButton"; }
335 virtual void calcMinMaxWidth();
336 virtual void updateFromElement();
339 KUrlRequester
*widget() const { return static_cast<KUrlRequester
*>(m_widget
); }
341 DOM::HTMLInputElementImpl
*element() const
342 { return static_cast<DOM::HTMLInputElementImpl
*>(RenderObject::element()); }
345 void slotReturnPressed();
346 void slotTextChanged(const QString
&string
);
347 void slotUrlSelected(const KUrl
&url
);
350 virtual void handleFocusOut();
352 virtual bool isEditable() const { return true; }
353 virtual bool canHaveBorder() const { return true; }
354 virtual bool acceptsSyntheticEvents() const { return false; }
361 // -------------------------------------------------------------------------
363 class RenderLabel
: public RenderFormElement
366 RenderLabel(DOM::HTMLGenericFormElementImpl
*element
);
368 virtual const char *renderName() const { return "RenderLabel"; }
371 virtual bool canHaveBorder() const { return true; }
375 // -------------------------------------------------------------------------
377 class RenderLegend
: public RenderBlock
380 RenderLegend(DOM::HTMLGenericFormElementImpl
*element
);
382 virtual const char *renderName() const { return "RenderLegend"; }
385 // -------------------------------------------------------------------------
387 class ComboBoxWidget
: public KComboBox
, public KHTMLWidget
390 ComboBoxWidget(QWidget
*parent
);
393 virtual bool event(QEvent
*);
394 virtual bool eventFilter(QObject
*dest
, QEvent
*e
);
395 virtual void showPopup();
396 virtual void hidePopup();
399 // -------------------------------------------------------------------------
401 class ListBoxWidget
: public KListWidget
, public KHTMLWidget
404 ListBoxWidget(QWidget
* p
): KListWidget(p
) { m_kwp
->setIsRedirected(true); }
406 void scrollContentsBy(int, int)
408 viewport()->update();
410 virtual bool event( QEvent
* event
);
413 class RenderSelect
: public RenderFormElement
417 RenderSelect(DOM::HTMLSelectElementImpl
*element
);
419 virtual const char *renderName() const { return "RenderSelect"; }
421 virtual void calcMinMaxWidth();
422 virtual void layout();
424 void setOptionsChanged(bool _optionsChanged
);
426 bool selectionChanged() { return m_selectionChanged
; }
427 void setSelectionChanged(bool _selectionChanged
) { m_selectionChanged
= _selectionChanged
; }
428 virtual void updateFromElement();
430 void updateSelection();
432 DOM::HTMLSelectElementImpl
*element() const
433 { return static_cast<DOM::HTMLSelectElementImpl
*>(RenderObject::element()); }
436 ListBoxWidget
*createListBox();
437 ComboBoxWidget
*createComboBox();
442 bool m_selectionChanged
;
443 bool m_ignoreSelectEvents
;
444 bool m_optionsChanged
;
447 void slotSelected(int index
);
448 void slotSelectionChanged();
451 // -------------------------------------------------------------------------
452 class TextAreaWidget
: public KTextEdit
, public KHTMLWidget
456 TextAreaWidget(int wrap
, QWidget
* parent
);
457 virtual ~TextAreaWidget();
460 virtual bool event (QEvent
*e
);
461 virtual void contextMenuEvent(QContextMenuEvent
* e
);
462 virtual void scrollContentsBy(int dx
, int dy
);
469 void slotDoReplace();
470 void slotReplaceNext();
471 void slotReplaceText(const QString
&, int, int, int);
472 void slotFindHighlight(const QString
&, int, int);
474 KFindDialog
*m_findDlg
;
476 KReplaceDialog
*m_repDlg
;
478 KAction
*m_findAction
;
479 KAction
*m_findNextAction
;
480 KAction
*m_replaceAction
;
481 int m_findIndex
, m_findPara
;
482 int m_repIndex
, m_repPara
;
486 // -------------------------------------------------------------------------
488 class RenderTextArea
: public RenderFormElement
492 RenderTextArea(DOM::HTMLTextAreaElementImpl
*element
);
495 virtual const char *renderName() const { return "RenderTextArea"; }
496 virtual void calcMinMaxWidth();
497 virtual void layout();
498 virtual void setStyle(RenderStyle
*style
);
500 virtual void updateFromElement();
502 // don't even think about making this method virtual!
503 TextAreaWidget
*widget() const { return static_cast<TextAreaWidget
*>(m_widget
); }
504 DOM::HTMLTextAreaElementImpl
* element() const
505 { return static_cast<DOM::HTMLTextAreaElementImpl
*>(RenderObject::element()); }
508 void setText(const QString
& text
);
510 void highLightWord( unsigned int length
, unsigned int pos
);
514 long selectionStart();
516 void setSelectionStart(long pos
);
517 void setSelectionEnd(long pos
);
518 void setSelectionRange(long start
, long end
);
520 void slotTextChanged();
523 virtual void handleFocusOut();
525 virtual bool isEditable() const { return true; }
526 virtual bool canHaveBorder() const { return true; }
528 bool scrollbarsStyled
;
531 // -------------------------------------------------------------------------
533 class ScrollBarWidget
: public QScrollBar
, public KHTMLWidget
536 ScrollBarWidget( QWidget
* parent
= 0 ): QScrollBar(parent
) { m_kwp
->setIsRedirected( true ); }
537 ScrollBarWidget( Qt::Orientation orientation
, QWidget
* parent
= 0 ): QScrollBar(orientation
, parent
) { m_kwp
->setIsRedirected( true ); }