QbWidget.h

00001 #ifndef QBWIDGET_H
00002 #define QBWIDGET_H
00003 
00004 #include "QbIncludes.h"
00005 #include "QbUtility.h"
00006 #include "QbWidgetController.h"
00007 #include "QbFieldSensorList.h"
00008 
00009 #include <cstdarg>
00010 
00011 class QbWidget;
00012 typedef void QbCallback(void * data, QbWidget * widget);
00013 
00014 class QbWidget : public SoSeparator {
00015   SO_NODE_ABSTRACT_HEADER(QbWidget);
00016   typedef SoSeparator inherited;
00017   friend class QbWidgetController; // for hover, focusing etc.
00018   friend class QbBox; // for setWidgetController
00019 public:
00020   static void initClass(void);
00021   QbWidget(void);
00022   ~QbWidget(void);
00023 
00024   /* properties and events are fields
00025     contain current / last value
00026     can be changed / triggered by user (if makes sense)
00027     can be connected to engines, sensors and auditors
00028   */
00029   SoSFVec3f position; // the upper left coordinate - does not affect size
00030   SoSFVec3f center; // only affects position
00031 
00032   SoSFVec2f size;
00033   SoSFFloat width;  // connected with size for convenience
00034   SoSFFloat height; // connected with size for convenience
00035 
00036   SoSFBool fixedSize; // if true, changing bounds do not affect size
00037 
00038   // changing bounds also affects size (if fixedSize == false), in contrast to changing the position
00039   SoSFVec3f topLeft; // the 4 corners
00040   SoSFVec3f topRight;
00041   SoSFVec3f bottomLeft;
00042   SoSFVec3f bottomRight;
00043   SoSFVec3f left; // center of the 4 sides
00044   SoSFVec3f right;
00045   SoSFVec3f top;
00046   SoSFVec3f bottom;
00047 
00048   SoSFBool captureEvents;
00049   SoSFTrigger click;
00050   SoSFUInt32 keyDown; // enum as int at now - switch to SoSFEnum later (see QbUtility.h or dynload-example for that)
00051   SoSFUInt32 keyUp;
00052   SoSFShort mouseDown;
00053   SoSFShort mouseUp;
00054   SoSFBool hover; // includes mouseEnter and -leave // TODO: consider using an EngineOutput for readOnly
00055   SoSFVec2s mouseMove;  // TODO: coin doc for SoEvent: find out which position to use
00056   SoSFBool focus;
00057 
00058   QbFieldSensorList sensors;
00059 
00060   /* returns the last QbWidget in the given path
00061      returns null if not found
00062   */
00063   static QbWidget * getLastWidgetInPath(SoPath *path);
00064 
00065   // IDEA: Ereignis-Methoden fuer Annaeherung und Sichtbarsein
00066 
00067   QbWidgetController * getWidgetController();
00068 
00069   virtual void notify(SoNotList * list);
00070 
00071 protected:
00072   // overwrite this to set children's controller too
00073   virtual void setWidgetController(QbWidgetController * controller);
00074   const SbViewportRegion getViewportRegion();
00075 
00076   /* virtual event methods
00077      allow the widget react to events and property changes
00078      values are stored in fields, these methods are called on field changes
00079      so don't change field values here to avoid stack overflow
00080      super should always be called when overwriting
00081   */
00082   virtual void doClick();
00083   virtual void doClickCancel(); // mouseDown here but up elsewhere
00084   virtual void doKeyDown(const SoKeyboardEvent::Key key);
00085   virtual void doKeyUp(const SoKeyboardEvent::Key key);
00086   virtual void doMouseDown(const SoMouseButtonEvent::Button button);
00087   virtual void doMouseUp(const SoMouseButtonEvent::Button button);
00088   virtual void doMouseEnter();
00089   virtual void doMouseExit();
00090   virtual void doMouseMove(SbVec2s position);
00091   virtual void doFocus();
00092   virtual void doUnFocus();
00093   virtual void doResize(const SbVec2f size);
00094   virtual void doPositionChange(const SbVec3f position); // position is topLeft
00095 
00096   SoTranslation * positionTranslation;
00097   SoSeparator * topSeparator; // all parts should be added here
00098 
00099 private:
00100   QbWidgetController * widgetController;
00101   SoInput input;
00102   SoNode * modelFocus;
00103 };
00104 
00105 
00106 inline QbWidgetController * QbWidget::getWidgetController () {
00107   return this->widgetController;
00108 }
00109 
00110 #define IS_QB_WIDGET(_node_) _node_->getTypeId().isDerivedFrom(QbWidget::getClassTypeId())
00111 #define QB_WIDGET(_node_) dynamic_cast<QbWidget*>(_node_)
00112 
00113 #endif

Generated on Thu Oct 28 10:59:16 2004 for gitk by doxygen 1.3.6