00001 #ifndef KDE__WIDGET_H
00002 #define KDE__WIDGET_H
00003
00004 #include <faith/string.h>
00005 #include <faith/font.h>
00006 #include <faith/application.h>
00007 #include <faith/point.h>
00008 #include <faith/rect.h>
00009 #include <faith/color.h>
00010 #include <faith/painter.h>
00011 #include <faith/paintdevice.h>
00012 #include <faith/colorgroup.h>
00013 #include <faith/sizepolicy.h>
00014
00015 namespace Faith
00016 {
00017
00018 class Event;
00019 class MouseEvent;
00020 class PaintEvent;
00021 class Font;
00022 class Layout;
00023 class Style;
00024
00038 class FAITH_CORE_EXPORT Widget : public Object, public PaintDevice
00039 {
00040 K_OBJECT
00041
00042 friend class Faith::Layout;
00043 friend class Faith::Object;
00044
00045 Handle mDrawable;
00046 Widget *mParentWidget;
00047 Rect mGeometry;
00048 ColorGroup mColorGroup;
00049 int mFlags;
00050 SizePolicy mSizePolicy;
00051
00052 struct FaithWidgetPrivate;
00053 FaithWidgetPrivate *d;
00054
00055 public:
00064 enum Flags
00065 {
00066 DeleteOnClose = 1 << 0,
00067 TopLevel = 1 << 1,
00068 Popup = (1 << 2) | TopLevel,
00069
00070 AvoidInit = 1<<3,
00071
00072 RepaintNoErase = 1<<4
00073 };
00074
00081 Widget(Widget *parent, const char *name=0, int wflags=0);
00082
00087 virtual ~Widget();
00088
00092 void setFlags(int flags);
00093
00094 int flags() const { return mFlags; }
00095
00096 virtual Handle handle() { return mDrawable; }
00097
00098 Faith::String caption() const;
00099
00100 Faith::Layout *layout();
00101
00102 public slots:
00110 virtual void show();
00111
00120 virtual void hide();
00121
00126 void setCaption(const Faith::String &title);
00127
00128 public:
00129
00130 SizePolicy sizePolicy() const { return mSizePolicy; }
00131 void setSizePolicy(const SizePolicy &p) { mSizePolicy = p; }
00132 void setSizePolicy(SizePolicy::Policy h, SizePolicy::Policy v)
00133 { mSizePolicy = SizePolicy(SizePolicy(h, v)); }
00134
00135
00140 Faith::Rect rect() const;
00141
00151 Faith::Rect geometry() const;
00152
00153 int width() const { return rect().width(); }
00154 int height() const { return rect().height(); }
00166 Faith::Size minimumSize() const;
00167
00180 Faith::Size maximumSize() const;
00181
00189 void setMinimumSize(const Faith::Size &size);
00190
00198 void setMaximumSize(const Faith::Size &size);
00199
00200 Faith::Size size() const { return rect().size(); }
00201 Faith::Point topLeft() const { return geometry().topLeft(); }
00202
00203 void move(int x, int y);
00204 void resize(int w, int h);
00205 void setWidth(int w) { resize(w, height()); }
00206 void setHeight(int h) { resize(width(), h); }
00207 void move(const Faith::Point &pt) { move(pt.x(), pt.y()); }
00208 void resize(const Faith::Size &sz) { resize(sz.width(), sz.height()); }
00209 void setGeometry(int x, int y, int w, int h);
00210 void setGeometry(const Rect &r)
00211 {
00212 setGeometry(r.x(), r.y(), r.width(), r.height());
00213 }
00214
00220 Faith::Widget *parentWidget();
00221 const Faith::Widget *parentWidget() const { return const_cast<Widget*>(this)->parentWidget(); }
00222
00229 Faith::Point mapFromGlobal(const Faith::Point &pt) const;
00230
00237 Faith::Point mapToGlobal(const Faith::Point &pt) const;
00238
00245 Faith::Rect mapFromGlobal(const Faith::Rect &rect) const
00246 {
00247 Faith::Rect out = rect;
00248 out.setTopLeft(mapFromGlobal(out.topLeft()));
00249 return out;
00250 }
00251
00258 Faith::Rect mapToGlobal(const Faith::Rect &rect) const
00259 {
00260 Faith::Rect out = rect;
00261 out.setTopLeft(mapToGlobal(out.topLeft()));
00262 return out;
00263 }
00264
00265
00266 const Faith::Pixmap *erasePixmap() const { return 0; }
00267
00268 const ColorGroup &colorGroup() const { return mColorGroup; }
00269
00276 void setPaletteBackgroundColor(const Color &color);
00277
00284 Faith::Color paletteBackgroundColor() const;
00285
00295 void setMouseTracking(bool on);
00296
00304 void grabMouse();
00305
00312 void releaseMouse();
00313
00321 enum FocusMode
00322 {
00323 NoFocus,
00324 WeakFocus,
00325 ClickFocus
00326 };
00327
00328 void setFocusMode(FocusMode mode);
00329 FocusMode focusMode() const { return mFocusMode; }
00330
00334 bool hasFocus() const { return false; }
00335
00341 bool isVisible() const;
00342
00343 void setActiveWindow();
00344
00349 bool topLevel() const;
00350
00358 void repaint() { paintEvent(0); }
00359
00360 public slots:
00365 void update();
00366
00367 signals:
00371 void hidden();
00372
00376 void shown();
00377
00381 void closed();
00382
00383 public:
00384
00385 FontMetrics fontMetrics() const { return FontMetrics(faithapp->font()); }
00386
00393 virtual Size sizeHint() const;
00394
00395 Style *style();
00396 const Style *style() const { return const_cast<Widget*>(this)->style(); }
00397
00398 protected:
00405 virtual void polish(Style *) { }
00406
00407 #ifdef WITH_X11
00408
00411 void faith_init(void *visual, int depth);
00412 #endif
00413
00414 public:
00421 virtual bool event(Faith::Event *event);
00422
00427 virtual void mousePressEvent(Faith::MouseEvent *) { }
00428
00438 virtual void mouseReleaseEvent(Faith::MouseEvent *) { }
00439
00440 virtual void mouseMoveEvent(Faith::MouseEvent *) { }
00441
00442 virtual void keyPressEvent(Faith::KeyPressEvent *) { }
00443
00444 virtual void paintEvent(Faith::PaintEvent *e);
00445
00446 virtual void focusInEvent(Faith::FocusEvent *) { }
00447
00448 virtual void focusOutEvent(Faith::FocusEvent *) { }
00449
00450 virtual void enterEvent(Faith::Event *) { }
00451
00452 virtual void leaveEvent(Faith::Event *) { }
00453
00454 virtual void showEvent(Faith::Event *) { }
00455
00456 virtual void hideEvent(Faith::Event *) { }
00457
00463 virtual void closeEvent(Faith::CloseEvent *);
00464
00465 virtual void resizeEvent(Faith::ResizeEvent *) { }
00466
00467 virtual void moveEvent(Faith::MoveEvent *) { }
00468
00469 private:
00470 virtual Internal::Drawable *getDrawable();
00471
00472 void invalidateSize();
00473 void childAdded(Faith::Widget *w);
00474 void childRemoved(Faith::Widget *w);
00475 void setLayout(Faith::Layout *layout);
00476 void layoutDeleted(Faith::Layout *layout);
00477 void beginLayoutUse();
00478
00479 private:
00480 FocusMode mFocusMode;
00481 };
00482
00483 }
00484
00485 #endif