render_form.h 10.9 KB
Newer Older
kocienda's avatar
kocienda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * This file is part of the DOM implementation for KDE.
 *
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2000 Dirk Mueller (mueller@kde.org)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */
#ifndef RENDER_FORM_H
#define RENDER_FORM_H

27
28
29
30
#include "rendering/render_replaced.h"
#include "rendering/render_image.h"
#include "rendering/render_flow.h"
#include "html/html_formimpl.h"
kocienda's avatar
kocienda committed
31
32
33
34
35

class QWidget;
class QLineEdit;
class QListboxItem;

36
#include <qtextedit.h>
kocienda's avatar
kocienda committed
37
38
39
40
41
42
43
44
45
#include <klineedit.h>
#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qpushbutton.h>
#include <qhbox.h>
#include <klistbox.h>
#include <kcombobox.h>
#include "dom/dom_misc.h"

darin's avatar
darin committed
46
typedef class QTextEdit KTextEdit;
kocienda's avatar
kocienda committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class KHTMLPartBrowserExtension;

namespace DOM {
    class HTMLFormElementImpl;
    class HTMLInputElementImpl;
    class HTMLSelectElementImpl;
    class HTMLGenericFormElementImpl;
    class HTMLTextAreaElementImpl;
};

namespace khtml {

class DocLoader;

// -------------------------------------------------------------------------

class RenderFormElement : public khtml::RenderWidget
{
    Q_OBJECT
public:
67
    RenderFormElement(DOM::HTMLGenericFormElementImpl* node);
kocienda's avatar
kocienda committed
68
69
70
71
72
73
74
75
76
77
78
    virtual ~RenderFormElement();

    virtual const char *renderName() const { return "RenderForm"; }

    virtual bool isRendered() const  { return true; }
    virtual bool isFormElement() const { return true; }

    // IE does not scale according to intrinsicWidth/Height
    // aspect ratio :-(
    virtual short calcReplacedWidth(bool* ieHack=0) const;
    virtual int   calcReplacedHeight() const;
79
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
80
81
82
83

    virtual void layout();
    virtual short baselinePosition( bool ) const;

84
85
    DOM::HTMLGenericFormElementImpl *element() const
    { return static_cast<DOM::HTMLGenericFormElementImpl*>(RenderObject::element()); }
rjw's avatar
   
rjw committed
86

kocienda's avatar
kocienda committed
87
88
89
90
91
92
93
public slots:
    virtual void slotClicked();

protected:
    virtual bool isRenderButton() const { return false; }
    virtual bool isEditable() const { return false; }

94
    virtual void handleFocusOut() {};
kocienda's avatar
kocienda committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

    QPoint m_mousePos;
    int m_state;
    int m_button;
    int m_clickCount;
    bool m_isDoubleClick;
};

// -------------------------------------------------------------------------

// generic class for all buttons
class RenderButton : public RenderFormElement
{
    Q_OBJECT
public:
110
    RenderButton(DOM::HTMLGenericFormElementImpl* node);
kocienda's avatar
kocienda committed
111
112
113
114

    virtual const char *renderName() const { return "RenderButton"; }
    virtual short baselinePosition( bool ) const;

115
116
117
118
    // don't even think about making this method virtual!
    DOM::HTMLInputElementImpl* element() const
    { return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }

kocienda's avatar
kocienda committed
119
120
121
122
123
124
125
126
127
128
protected:
    virtual bool isRenderButton() const { return true; }
};

// -------------------------------------------------------------------------

class RenderCheckBox : public RenderButton
{
    Q_OBJECT
public:
129
    RenderCheckBox(DOM::HTMLInputElementImpl* node);
kocienda's avatar
kocienda committed
130
131

    virtual const char *renderName() const { return "RenderCheckBox"; }
132
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
133
    virtual void calcMinMaxWidth();
134
135
136

    QCheckBox *widget() const { return static_cast<QCheckBox*>(m_widget); }

kocienda's avatar
kocienda committed
137
138
139
140
141
142
143
144
145
146
public slots:
    virtual void slotStateChanged(int state);
};

// -------------------------------------------------------------------------

class RenderRadioButton : public RenderButton
{
    Q_OBJECT
public:
147
    RenderRadioButton(DOM::HTMLInputElementImpl* node);
kocienda's avatar
kocienda committed
148
149
150
151

    virtual const char *renderName() const { return "RenderRadioButton"; }

    virtual void calcMinMaxWidth();
152
153
154
    virtual void updateFromElement();

    QRadioButton *widget() const { return static_cast<QRadioButton*>(m_widget); }
kocienda's avatar
kocienda committed
155
156
157
158
159
160
161
162
163
164

public slots:
    void slotClicked();
};

// -------------------------------------------------------------------------

class RenderSubmitButton : public RenderButton
{
public:
165
    RenderSubmitButton(DOM::HTMLInputElementImpl *element);
kocienda's avatar
kocienda committed
166
167
168
169
170
171

    virtual const char *renderName() const { return "RenderSubmitButton"; }

    virtual QString defaultLabel();

    virtual void calcMinMaxWidth();
darin's avatar
darin committed
172
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
173
    virtual short baselinePosition( bool ) const;
darin's avatar
darin committed
174
175
private:
    QString rawText();
kocienda's avatar
kocienda committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
};

// -------------------------------------------------------------------------

class RenderImageButton : public RenderImage
{
public:
    RenderImageButton(DOM::HTMLInputElementImpl *element);

    virtual const char *renderName() const { return "RenderImageButton"; }
};


// -------------------------------------------------------------------------

class RenderResetButton : public RenderSubmitButton
{
public:
194
    RenderResetButton(DOM::HTMLInputElementImpl *element);
kocienda's avatar
kocienda committed
195
196
197
198
199
200
201
202
203
204
205

    virtual const char *renderName() const { return "RenderResetButton"; }

    virtual QString defaultLabel();
};

// -------------------------------------------------------------------------

class RenderPushButton : public RenderSubmitButton
{
public:
206
    RenderPushButton(DOM::HTMLInputElementImpl *element);
kocienda's avatar
kocienda committed
207
208
209
210
211
212
213
214
215
216

    virtual QString defaultLabel();
};

// -------------------------------------------------------------------------

class RenderLineEdit : public RenderFormElement
{
    Q_OBJECT
public:
217
    RenderLineEdit(DOM::HTMLInputElementImpl *element);
kocienda's avatar
kocienda committed
218
219
220
221

    virtual void calcMinMaxWidth();

    virtual const char *renderName() const { return "RenderLineEdit"; }
222
223
    virtual void updateFromElement();

kocienda's avatar
kocienda committed
224
    void select();
rjw's avatar
   
rjw committed
225

226
227
228
229
    KLineEdit *widget() const { return static_cast<KLineEdit*>(m_widget); }
    DOM::HTMLInputElementImpl* element() const
    { return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }

kocienda's avatar
kocienda committed
230
231
232
233
public slots:
    void slotReturnPressed();
    void slotTextChanged(const QString &string);

234
235
236
protected:
    virtual void handleFocusOut();

kocienda's avatar
kocienda committed
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
private:
    virtual bool isEditable() const { return true; }
};

// -------------------------------------------------------------------------

class LineEditWidget : public KLineEdit
{
public:
    LineEditWidget(QWidget *parent);

protected:
    virtual bool event( QEvent *e );
};

// -------------------------------------------------------------------------

class RenderFieldset : public RenderFormElement
{
public:
257
    RenderFieldset(DOM::HTMLGenericFormElementImpl *element);
kocienda's avatar
kocienda committed
258
259
260
261
262
263
264
265
266
267
268

    virtual const char *renderName() const { return "RenderFieldSet"; }
};


// -------------------------------------------------------------------------

class RenderFileButton : public RenderFormElement
{
    Q_OBJECT
public:
269
    RenderFileButton(DOM::HTMLInputElementImpl *element);
kocienda's avatar
kocienda committed
270
271
272

    virtual const char *renderName() const { return "RenderFileButton"; }
    virtual void calcMinMaxWidth();
273
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
274
275
    void select();

276
277
278
279
280
    DOM::HTMLInputElementImpl *element() const
    { return static_cast<DOM::HTMLInputElementImpl*>(RenderObject::element()); }

    KLineEdit* lineEdit() const { return m_edit; }

kocienda's avatar
kocienda committed
281
282
283
284
285
286
public slots:
    virtual void slotClicked();
    virtual void slotReturnPressed();
    virtual void slotTextChanged(const QString &string);

protected:
287
288
    virtual void handleFocusOut();

kocienda's avatar
kocienda committed
289
    virtual bool isEditable() const { return true; }
290

kocienda's avatar
kocienda committed
291
292
293
294
295
296
297
298
299
300
301
302
    bool m_clicked;
    bool m_haveFocus;
    KLineEdit   *m_edit;
    QPushButton *m_button;
};


// -------------------------------------------------------------------------

class RenderLabel : public RenderFormElement
{
public:
303
    RenderLabel(DOM::HTMLGenericFormElementImpl *element);
kocienda's avatar
kocienda committed
304
305
306
307
308
309
310
311
312
313

    virtual const char *renderName() const { return "RenderLabel"; }
};


// -------------------------------------------------------------------------

class RenderLegend : public RenderFormElement
{
public:
314
    RenderLegend(DOM::HTMLGenericFormElementImpl *element);
kocienda's avatar
kocienda committed
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

    virtual const char *renderName() const { return "RenderLegend"; }
};

// -------------------------------------------------------------------------

class ComboBoxWidget : public KComboBox
{
public:
    ComboBoxWidget(QWidget *parent);

protected:
    virtual bool event(QEvent *);
    virtual bool eventFilter(QObject *dest, QEvent *e);
};

// -------------------------------------------------------------------------

class RenderSelect : public RenderFormElement
{
    Q_OBJECT
public:
337
    RenderSelect(DOM::HTMLSelectElementImpl *element);
kocienda's avatar
kocienda committed
338
339
340

    virtual const char *renderName() const { return "RenderSelect"; }

341
#if APPLE_CHANGES
hyatt's avatar
hyatt committed
342
343
344
    short baselinePosition( bool f ) const;
#endif

kocienda's avatar
kocienda committed
345
346
347
348
349
350
351
    virtual void calcMinMaxWidth();
    virtual void layout();

    void setOptionsChanged(bool _optionsChanged);

    bool selectionChanged() { return m_selectionChanged; }
    void setSelectionChanged(bool _selectionChanged) { m_selectionChanged = _selectionChanged; }
352
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
353
354

    void updateSelection();
rjw's avatar
rjw committed
355

356
357
358
    DOM::HTMLSelectElementImpl *element() const
    { return static_cast<DOM::HTMLSelectElementImpl*>(RenderObject::element()); }

kocienda's avatar
kocienda committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
protected:
    KListBox *createListBox();
    ComboBoxWidget *createComboBox();

    unsigned  m_size;
    bool m_multiple;
    bool m_useListBox;
    bool m_selectionChanged;
    bool m_ignoreSelectEvents;
    bool m_optionsChanged;

protected slots:
    void slotSelected(int index);
    void slotSelectionChanged();
};

// -------------------------------------------------------------------------

darin's avatar
darin committed
377
class TextAreaWidget : public KTextEdit
kocienda's avatar
kocienda committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
{
public:
    TextAreaWidget(int wrap, QWidget* parent);

protected:
    virtual bool event (QEvent *e );
};


// -------------------------------------------------------------------------

class RenderTextArea : public RenderFormElement
{
    Q_OBJECT
public:
393
    RenderTextArea(DOM::HTMLTextAreaElementImpl *element);
kocienda's avatar
kocienda committed
394
395
396
397
398
    ~RenderTextArea();

    virtual const char *renderName() const { return "RenderTextArea"; }
    virtual void calcMinMaxWidth();
    virtual void close ( );
399
    virtual void updateFromElement();
kocienda's avatar
kocienda committed
400

401
402
    virtual bool isTextArea() const { return true; }
    
403
404
405
406
407
    // don't even think about making this method virtual!
    DOM::HTMLTextAreaElementImpl* element() const
    { return static_cast<DOM::HTMLTextAreaElementImpl*>(RenderObject::element()); }

    QString text();
kocienda's avatar
kocienda committed
408
409
410
411
412
413
414

    void select();

protected slots:
    void slotTextChanged();

protected:
415
416
    virtual void handleFocusOut();

kocienda's avatar
kocienda committed
417
418
419
420
421
422
423
424
    virtual bool isEditable() const { return true; }
};

// -------------------------------------------------------------------------

}; //namespace

#endif