wc/r18788/#8438/ by mitz@webkit.org
[kdelibs.git] / khtml / rendering / render_form.h
blob1e517b6ab1457b638024b661752b496bcd18df39
1 /*
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.
24 #ifndef RENDER_FORM_H
25 #define RENDER_FORM_H
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"
34 class QWidget;
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"
46 class KFindDialog;
47 class KReplaceDialog;
48 class KFind;
49 class KReplace;
50 class KAction;
51 class KUrlRequester;
53 namespace DOM {
54 class HTMLInputElementImpl;
55 class HTMLSelectElementImpl;
56 class HTMLGenericFormElementImpl;
57 class HTMLTextAreaElementImpl;
60 namespace khtml {
63 // -------------------------------------------------------------------------
65 class RenderFormElement : public khtml::RenderWidget
67 public:
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()); }
89 protected:
90 virtual bool isRenderButton() const { return false; }
91 virtual bool isEditable() const { return false; }
92 Qt::AlignmentFlag textAlignment() const;
94 // QPoint m_mousePos;
95 // int m_state;
98 // -------------------------------------------------------------------------
100 // generic class for all buttons
101 class RenderButton : public RenderFormElement
103 Q_OBJECT
104 public:
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()); }
115 protected:
116 virtual bool isRenderButton() const { return true; }
119 // -------------------------------------------------------------------------
121 class CheckBoxWidget: public QCheckBox, public KHTMLWidget
123 public:
124 CheckBoxWidget(QWidget *p): QCheckBox(p) { m_kwp->setIsRedirected(true); }
127 class RenderCheckBox : public RenderButton
129 Q_OBJECT
130 public:
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); }
141 public Q_SLOTS:
142 virtual void slotStateChanged(int state);
145 // -------------------------------------------------------------------------
147 class RadioButtonWidget: public QRadioButton, public KHTMLWidget
149 public:
150 RadioButtonWidget(QWidget* p): QRadioButton(p) { m_kwp->setIsRedirected(true); }
153 class RenderRadioButton : public RenderButton
155 Q_OBJECT
156 public:
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); }
168 public Q_SLOTS:
169 virtual void slotToggled(bool);
173 // -------------------------------------------------------------------------
175 class PushButtonWidget: public QPushButton, public KHTMLWidget
177 public:
178 PushButtonWidget(QWidget* p): QPushButton(p) { m_kwp->setIsRedirected(true); }
181 class RenderSubmitButton : public RenderButton
183 public:
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;
191 private:
192 QString rawText();
195 // -------------------------------------------------------------------------
197 class RenderImageButton : public RenderImage
199 public:
200 RenderImageButton(DOM::HTMLInputElementImpl *element)
201 : RenderImage(element) {}
203 virtual const char *renderName() const { return "RenderImageButton"; }
207 // -------------------------------------------------------------------------
209 class RenderResetButton : public RenderSubmitButton
211 public:
212 RenderResetButton(DOM::HTMLInputElementImpl *element);
214 virtual const char *renderName() const { return "RenderResetButton"; }
218 // -------------------------------------------------------------------------
220 class RenderPushButton : public RenderSubmitButton
222 public:
223 RenderPushButton(DOM::HTMLInputElementImpl *element)
224 : RenderSubmitButton(element) {}
228 // -------------------------------------------------------------------------
230 class RenderLineEdit : public RenderFormElement
232 Q_OBJECT
233 public:
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);
242 void select();
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();
250 long selectionEnd();
251 void setSelectionStart(long pos);
252 void setSelectionEnd(long pos);
253 void setSelectionRange(long start, long end);
254 public Q_SLOTS:
255 void slotReturnPressed();
256 void slotTextChanged(const QString &string);
257 protected:
258 virtual void handleFocusOut();
260 private:
261 virtual bool isEditable() const { return true; }
262 virtual bool canHaveBorder() const { return true; }
265 // -------------------------------------------------------------------------
267 class LineEditWidget : public KLineEdit, public KHTMLWidget
269 Q_OBJECT
270 public:
271 LineEditWidget(DOM::HTMLInputElementImpl* input,
272 KHTMLView* view, QWidget* parent);
273 ~LineEditWidget();
274 void setFocus();
275 void highLightWord( unsigned int length, unsigned int pos );
277 protected:
278 virtual bool event( QEvent *e );
279 virtual void paintEvent( QPaintEvent *pe );
280 virtual void mouseMoveEvent(QMouseEvent *e);
281 virtual void contextMenuEvent(QContextMenuEvent *e);
282 private Q_SLOTS:
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();
290 private:
291 enum LineEditMenuID {
292 ClearHistory
294 DOM::HTMLInputElementImpl* m_input;
295 KHTMLView* m_view;
296 KAction *m_spellAction;
299 // -------------------------------------------------------------------------
301 class RenderFieldset : public RenderBlock
303 public:
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);
311 protected:
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
324 public:
325 FileButtonWidget(QWidget* p): KUrlRequester(p) { m_kwp->setIsRedirected(true); }
328 class RenderFileButton : public RenderFormElement
330 Q_OBJECT
331 public:
332 RenderFileButton(DOM::HTMLInputElementImpl *element);
334 virtual const char *renderName() const { return "RenderFileButton"; }
335 virtual void calcMinMaxWidth();
336 virtual void updateFromElement();
337 void select();
339 KUrlRequester *widget() const { return static_cast<KUrlRequester*>(m_widget); }
341 DOM::HTMLInputElementImpl *element() const
342 { return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }
344 public Q_SLOTS:
345 void slotReturnPressed();
346 void slotTextChanged(const QString &string);
347 void slotUrlSelected(const KUrl &url);
349 protected:
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; }
356 bool m_clicked;
357 bool m_haveFocus;
361 // -------------------------------------------------------------------------
363 class RenderLabel : public RenderFormElement
365 public:
366 RenderLabel(DOM::HTMLGenericFormElementImpl *element);
368 virtual const char *renderName() const { return "RenderLabel"; }
370 protected:
371 virtual bool canHaveBorder() const { return true; }
375 // -------------------------------------------------------------------------
377 class RenderLegend : public RenderBlock
379 public:
380 RenderLegend(DOM::HTMLGenericFormElementImpl *element);
382 virtual const char *renderName() const { return "RenderLegend"; }
385 // -------------------------------------------------------------------------
387 class ComboBoxWidget : public KComboBox, public KHTMLWidget
389 public:
390 ComboBoxWidget(QWidget *parent);
392 protected:
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
403 public:
404 ListBoxWidget(QWidget* p): KListWidget(p) { m_kwp->setIsRedirected(true); }
405 protected:
406 void scrollContentsBy(int, int)
408 viewport()->update();
410 virtual bool event( QEvent * event );
413 class RenderSelect : public RenderFormElement
415 Q_OBJECT
416 public:
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()); }
435 protected:
436 ListBoxWidget *createListBox();
437 ComboBoxWidget *createComboBox();
439 unsigned m_size;
440 bool m_multiple;
441 bool m_useListBox;
442 bool m_selectionChanged;
443 bool m_ignoreSelectEvents;
444 bool m_optionsChanged;
446 protected Q_SLOTS:
447 void slotSelected(int index);
448 void slotSelectionChanged();
451 // -------------------------------------------------------------------------
452 class TextAreaWidget : public KTextEdit, public KHTMLWidget
454 Q_OBJECT
455 public:
456 TextAreaWidget(int wrap, QWidget* parent);
457 virtual ~TextAreaWidget();
459 protected:
460 virtual bool event (QEvent *e );
461 virtual void contextMenuEvent(QContextMenuEvent * e);
462 virtual void scrollContentsBy(int dx, int dy);
464 private Q_SLOTS:
465 void slotFind();
466 void slotDoFind();
467 void slotFindNext();
468 void slotReplace();
469 void slotDoReplace();
470 void slotReplaceNext();
471 void slotReplaceText(const QString&, int, int, int);
472 void slotFindHighlight(const QString&, int, int);
473 private:
474 KFindDialog *m_findDlg;
475 KFind *m_find;
476 KReplaceDialog *m_repDlg;
477 KReplace *m_replace;
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
490 Q_OBJECT
491 public:
492 RenderTextArea(DOM::HTMLTextAreaElementImpl *element);
493 ~RenderTextArea();
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()); }
507 QString text();
508 void setText(const QString& text);
510 void highLightWord( unsigned int length, unsigned int pos );
512 void select();
514 long selectionStart();
515 long selectionEnd();
516 void setSelectionStart(long pos);
517 void setSelectionEnd(long pos);
518 void setSelectionRange(long start, long end);
519 protected Q_SLOTS:
520 void slotTextChanged();
522 protected:
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
535 public:
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 ); }
540 } //namespace
542 #endif