/Users/airy/Sources/augui/AUGUIFramework/Controls/TViewNoCompositingCompatible.h

Go to the documentation of this file.
00001 /*
00002  *  TViewNoCompositingCompatible.h
00003  *  NeuSynth
00004  *
00005  *  Created by Airy André on Wed Nov 06 2002.
00006  *  Copyright (c) 2002 Airy André. All rights reserved.
00007  *
00008  */
00009 
00010 #ifndef TViewNoCompositingCompatible_H_
00011 #define TViewNoCompositingCompatible_H_
00012 
00013 #include "TView.h"
00014 #include "CACFDictionary.h"
00015 #include "AUProperty.h"
00016 
00017 // Using modifier keys with controls is supported by default.
00018 #if !defined(SUPPORT_CONTROL_MODIFIERS)
00019 #define SUPPORT_CONTROL_MODIFIERS 1
00020 #endif
00021 
00022 // Definitions of which actual modifiers to use.
00023 #if !defined(HIGH_PRECISION_MODIFIER)
00024 #define HIGH_PRECISION_MODIFIER optionKey
00025 #endif
00026 #if !defined(HIGHEST_PRECISION_MODIFIER)
00027 #define HIGHEST_PRECISION_MODIFIER controlKey
00028 #endif
00029 
00074 // All control class names should call this macro with some unique name
00075 #define AUGUIDefineControl(classname, parent, name) \
00076         friend class TViewNoCompositingCompatible; \
00077 protected: \
00078         static  const AUGUI::property_t mPropertiesList[];\
00079         static  const size_t mPropertiesListSize;\
00080 public: \
00081         static  CFStringRef GetControlName() { return CFSTR(name);}; \
00082         virtual CFStringRef GetType() { return GetControlName(); }; \
00083         virtual const AUGUI::property_t& GetPropertyDefinition(unsigned int i) const \
00084         { \
00085                 if (i < parent::GetPropertiesListSize())\
00086                         return parent::GetPropertyDefinition(i);\
00087                 else\
00088                         return mPropertiesList[i-parent::GetPropertiesListSize()]; \
00089         }\
00090         virtual size_t GetPropertiesListSize() const { return parent::GetPropertiesListSize() + mPropertiesListSize; }
00091 
00092 #define AUGUIProperties(CLASS) const AUGUI::property_t CLASS::mPropertiesList[]
00093 #define AUGUIInit(CLASS) const size_t CLASS::mPropertiesListSize = sizeof(mPropertiesList)/sizeof(AUGUI::property_t)-1
00094 
00095 class TViewNoCompositingCompatible
00096 : public TView
00097 {
00098 protected:
00099         static  const AUGUI::property_t mPropertiesList[];
00100         static  const size_t mPropertiesListSize;
00101 public:    
00102     typedef enum {
00103         kPropertyTypeInt = 0,
00104         kPropertyTypeDouble,
00105         kPropertyTypeString
00106     } tPropertyType;
00107     
00108         static const OSType theViewTag = 'TVew';
00109         
00110     static OSStatus                     RegisterSubclass(CFStringRef inID, ConstructProc inProc );
00111     static OSStatus                     UnRegisterSubclass( CFStringRef inID);
00112         
00113     TViewNoCompositingCompatible( HIViewRef inControl ); 
00114     virtual ~TViewNoCompositingCompatible();
00115         
00116         virtual CFStringRef GetType() = 0;
00117 
00118         void ForceRedraw();
00119         void ForceValueChange();
00120         
00121         static void SetClassBundle(CFBundleRef sBundle);
00122         
00123     virtual void                FlushStaticBackground();
00124         
00125         virtual OSStatus SetFocusPart(ControlPartCode inDesiredFocus, Boolean inFocusEverything, ControlPartCode* outActualFocus);
00126         virtual void            EraseBackground(CGContextRef inContext, bool inCompositing);
00127         virtual void            Draw(RgnHandle  inLimitRgn, CGContextRef inContext );
00128     virtual void                DrawStaticBackground(RgnHandle  inLimitRgn, CGContextRef inContext, bool  inCompositing ) {};
00129     virtual void                CompatibleDraw(RgnHandle inLimitRgn, CGContextRef inContext, bool  inCompositing ) = 0;
00130         
00138     virtual OSStatus            SetUpTracking(TCarbonEvent& inEvent);
00139         
00140     virtual OSStatus            StartTracking(TCarbonEvent&inEvent, HIPoint& from);
00141     virtual OSStatus            StillTracking(TCarbonEvent&inEvent, HIPoint& from);
00142     virtual OSStatus            StopTracking(TCarbonEvent&inEvent, HIPoint& from);
00143         
00147     virtual OSStatus            Track(TCarbonEvent& inEvent, ControlPartCode* outPartHit);
00148         
00149         virtual OSStatus GetData(OSType inTag, ControlPartCode inPart, Size inSize, Size* outSize, void* inPtr);
00150         virtual ControlPartCode HitTest(
00151                                                                         const HIPoint&          inWhere );
00152         virtual OSStatus                ControlHit(
00153                                                                            ControlPartCode              inPart,
00154                                                                            UInt32                               inModifiers );
00155         
00157         virtual UInt32 GetBehaviors() { return (TView::GetBehaviors() | kControlSupportsEmbedding); };
00158         
00161     virtual bool UseNonblockingTracking() { return false; }
00162         
00164         template <class V> static CFStringRef CopyClassIDForBundleID(CFStringRef bundleID);
00166         template <class V> static CFStringRef CopyCanonicalClassID();
00167     
00169     template <class V>  static void RegisterClassForBundleID(CFStringRef str);
00170         
00171     // The following is only needed if you need to unregister a single class
00172     // UnRegisterAllClasses is usually used.
00173     template <class V>  static void UnRegisterClassForBundleID(CFStringRef str);
00174         
00175         static OSStatus TViewNoCompositingCompatible::NewView(
00176                                                                                                                   HIViewRef*            outControl,
00177                                                                                                                   const HIRect*         inBounds,
00178                                                                                                                   HIViewRef                     inView,
00179                                                                                                                   CFStringRef   classID);
00180 
00181         static OSStatus TViewNoCompositingCompatible::NewViewForCurrentBundle(
00182                                                                                                                   HIViewRef*            outControl,
00183                                                                                                                   const HIRect*         inBounds,
00184                                                                                                                   HIViewRef                     inView,
00185                                                                                                                   CFStringRef   className);
00186         
00187     template <class V>  static OSStatus Construct(
00188                                                   HIObjectRef           inBaseObject,
00189                                                   TObject**                     outInstance );
00190         
00191     template <class V>  static OSStatus CreateInView(
00192                                                                                                          HIViewRef*                     outControl,
00193                                                                                                          const HIRect*          inBounds,
00194                                                                                                          HIViewRef                      inRoot,
00195                                                                                                          CFStringRef    classID);
00196         
00197     template <class V>  static OSStatus Create(
00198                                                                                            HIViewRef*                   outControl,
00199                                                                                            const HIRect*                inBounds,
00200                                                                                            WindowRef                    inWindow,
00201                                                                                            CFStringRef  classID);
00202         
00203     template <class V>  static TViewNoCompositingCompatible* CreateForCurrentBundle (
00204                                                                                            const HIRect*                inBounds,
00205                                                                                            HIViewRef                    inRoot);
00206         
00207     static void UnRegisterAllClasses();
00208         
00209     // Must be false while the window is building
00210     static void SetWindowReady(bool ready) { sWindowReady = ready; };
00211         
00212         virtual void DrawBackgroundImage(CGContextRef context);
00213         
00214         // utilities
00215         bool IsCompositing();
00216         void ConvertToGlobal(HIPoint& thePoint);
00217         void ConvertToLocal(HIPoint& thePoint);
00218         
00219         virtual void WriteToDictionary(CACFDictionary &dict);
00220         virtual void ReadFromDictionary(CACFDictionary &dict);
00221 
00222         // Control properties management
00223         virtual void SetProperty(OSType propID, double value);
00224         virtual void SetProperty(OSType propID, int32_t value);
00225         virtual void SetProperty(OSType propID, CFStringRef value);
00226         virtual void SetProperty(OSType propID, AUGUI::font_t &value);
00227         virtual void SetProperty(OSType propID, AUGUI::rect_t &value);
00228         virtual void SetProperty(OSType propID, AUGUI::color_t &value);
00229         virtual void SetProperty(OSType propID, AUGUI::point_t &value);
00230         virtual bool GetProperty(OSType propID, double &value);
00231         virtual bool GetProperty(OSType propID, int32_t &value);
00232         virtual bool GetProperty(OSType propID, CFStringRef &value);
00233         virtual bool GetProperty(OSType propID, AUGUI::font_t &value);
00234         virtual bool GetProperty(OSType propID, AUGUI::rect_t &value);
00235         virtual bool GetProperty(OSType propID, AUGUI::color_t &value);
00236         virtual bool GetProperty(OSType propID, AUGUI::point_t &value);
00237         
00238         virtual void PropertiesChanged() {};
00239 
00240         virtual const AUGUI::property_t& GetPropertyDefinition(unsigned int i) const { return mPropertiesList[i];}
00241         virtual size_t GetPropertiesListSize() const { return mSaveMinMaxVal?mPropertiesListSize:(mPropertiesListSize-3); }
00242 
00243         void SaveMinMaxVal(bool save) { mSaveMinMaxVal = save; }
00244         // We have to redefine Initialize and ObjectEventHandler because that are "private" in TView and we need them for
00245         // the unregistering stuff... Too bad
00246 protected:
00247         virtual bool Prerender() { return true; };
00248         bool IsWindowReady() const  { return sWindowReady; };
00249         virtual OSStatus                mouseDragged(TCarbonEvent&inEvent);
00250     virtual OSStatus            mouseUp(TCarbonEvent&inEvent);
00251         virtual void PrerenderStaticBackground();
00252         CFBundleRef mBundleRef;
00253         
00254         int mCurrentFocusPart;  
00255         CGImageRef mStaticBackground; // The composited background
00256 
00257 private:
00258         bool mRedrawn;
00259         HIPoint mFromPoint;
00260     EventHandlerRef      mMouseEventHandler;
00261         
00262         
00263         bool    mSaveMinMaxVal;
00264         
00265     static CFBundleRef      sStaticBundle;
00266     
00267     static bool sWindowReady; 
00268         
00269     static pascal OSStatus MouseEventHandler(
00270                                                                                          EventHandlerCallRef    inCallRef,
00271                                                                                          EventRef                       inEvent,
00272                                                                                          void*                          inUserData );
00273         
00274     static CFMutableDictionaryRef mRegisteryCache;
00275 };
00276 typedef TViewNoCompositingCompatible*                           TViewNoCompositingCompatiblePtr;
00277 
00278 template <class V>
00279 CFStringRef TViewNoCompositingCompatible::CopyCanonicalClassID()
00280 {
00281     return TViewNoCompositingCompatible::CopyClassIDForBundleID<V>(CFBundleGetIdentifier(V::sStaticBundle));
00282 }
00283 
00286 template <class V>
00287 CFStringRef TViewNoCompositingCompatible::CopyClassIDForBundleID(CFStringRef bundleID)
00288 {
00289     return CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@.%@"), bundleID, V::GetControlName());
00290 }
00291 
00292 template <class V>
00293 void TViewNoCompositingCompatible::RegisterClassForBundleID(CFStringRef str)
00294 {
00295     CFStringRef reg = CopyClassIDForBundleID<V>(str);
00296     RegisterSubclass( reg, (ConstructProc)Construct<V>);
00297     CFRelease(reg);
00298 }
00299 
00300 // The following is only needed if you need to unregister a single class
00301 // UnRegisterAllClasses is usually used.
00302 template <class V>
00303 void TViewNoCompositingCompatible::UnRegisterClassForBundleID(CFStringRef str)
00304 {
00305     CFStringRef reg = CopyClassIDForBundleID<V>(str);
00306     UnRegisterSubclass( reg);
00307     CFRelease(reg);
00308 }
00309 
00310 template <class V>
00311 OSStatus TViewNoCompositingCompatible::Construct(
00312                                                  HIObjectRef            inBaseObject,
00313                                                  TObject**                      outInstance )
00314 {
00315     *outInstance = new V( (HIViewRef)inBaseObject );
00316     return noErr;
00317 }
00318 
00319 
00320 template <class V>
00321 OSStatus TViewNoCompositingCompatible::CreateInView(
00322                                                                                           HIViewRef*            outControl,
00323                                                                                           const HIRect*         inBounds,
00324                                                                                           HIViewRef                     inView,
00325                                                                                           CFStringRef   classID)
00326 {
00327     RegisterSubclass(classID, TViewNoCompositingCompatible::Construct<V>);
00328     return NewView( outControl, inBounds, inView, classID );
00329 }
00330 
00331 template <class V>
00332 OSStatus TViewNoCompositingCompatible::Create(
00333                                                                                           HIViewRef*                    outControl,
00334                                                                                           const HIRect*         inBounds,
00335                                                                                           WindowRef                     inWindow,
00336                                                                                           CFStringRef   classID)
00337 {
00338         HIViewRef root = 0;
00339     if ( inWindow != NULL )
00340         GetRootControl( inWindow, &root );
00341         return CreateInView<V>(outControl, inBounds, root, classID);
00342 }
00343 
00344 template <class V> 
00345 TViewNoCompositingCompatible* TViewNoCompositingCompatible::CreateForCurrentBundle (
00346                                                                                                                 const HIRect*           inBounds,
00347                                                                                                                 HIViewRef                       root)
00348 {
00349         HIViewRef                       ctrl = 0;
00350         TViewNoCompositingCompatible *tview = 0;
00351     CFStringRef            classID = TViewNoCompositingCompatible::CopyCanonicalClassID<V>();
00352         TViewNoCompositingCompatible::CreateInView<V>(&ctrl, inBounds, root, classID);
00353         CFRelease(classID);
00354     if (ctrl)
00355                 GetControlData(ctrl, 0, TViewNoCompositingCompatible::theViewTag, sizeof(tview), &tview, 0);
00356         return tview;
00357 }
00358 
00359 namespace AUGUI {
00361 
00362 
00363 
00364 
00365         template <class V>  
00366         inline TViewNoCompositingCompatible* CreateForCurrentBundle (const HIRect* inBounds, HIViewRef root)
00367         {
00368                 return TViewNoCompositingCompatible::CreateForCurrentBundle<V>(inBounds, root);
00369         }
00370         
00371         
00374     template <class V>
00375     inline CFStringRef CopyCanonicalClassID()
00376     {
00377         return TViewNoCompositingCompatible::CopyCanonicalClassID<V>();
00378     }
00379     
00380     template <class V>
00381     inline CFStringRef CopyClassIDForBundleID(CFStringRef bundleID)
00382     {
00383         return TViewNoCompositingCompatible::CopyClassIDForBundleID<V>(bundleID);
00384     }
00386 
00387     template <class V>
00388     inline void AddPropertyInfo(uint32_t tag, std::string name, std::string label, property_type_t type)
00389     {
00390         V::mPropertiesList[tag] = property_t(tag, name, label, type);
00391     }
00392     
00393 } // end namespace
00394 
00395 
00396 #endif





Generated on Sat Jul 8 13:02:21 2006 for AUGUI Framework by doxygen1.4.6

hosted on SourceForge.net Logo