michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkViewInflate_DEFINED michael@0: #define SkViewInflate_DEFINED michael@0: michael@0: #include "SkDOM.h" michael@0: #include "SkTDict.h" michael@0: #include "SkEvent.h" michael@0: michael@0: class SkView; michael@0: michael@0: class SkViewInflate { michael@0: public: michael@0: SkViewInflate(); michael@0: virtual ~SkViewInflate(); michael@0: michael@0: /** Return the tree of inflated views. If root is null, create the root element michael@0: as a view, otherwise assume root is that view, and just "inflate" it. michael@0: michael@0: Returns null if the tree cannot be built. michael@0: */ michael@0: SkView* inflate(const SkDOM& dom, const SkDOM::Node* node, SkView* root = NULL); michael@0: SkView* inflate(const char xml[], size_t len, SkView* root = NULL); michael@0: michael@0: /** Given an id attribute value, return the corresponding view, or null michael@0: if no match is found. michael@0: */ michael@0: SkView* findViewByID(const char id[]) const; michael@0: michael@0: SkDEBUGCODE(void dump() const;) michael@0: michael@0: protected: michael@0: /* Override this in your subclass to handle instantiating views michael@0: Call the inherited version for nodes you don't recognize. michael@0: michael@0: Do not call "inflate" on the view, just return it. This will michael@0: get called automatically after createView returns. michael@0: */ michael@0: virtual SkView* createView(const SkDOM& dom, const SkDOM::Node* node); michael@0: /** Base implementation calls view->inflate(dom, node). Subclasses may override this michael@0: to perform additional initializations to view, either before or after calling michael@0: the inherited version. michael@0: */ michael@0: virtual void inflateView(SkView* view, const SkDOM& dom, const SkDOM::Node* node); michael@0: michael@0: private: michael@0: enum { michael@0: kMinIDStrAlloc = 64 michael@0: }; michael@0: SkTDict fIDs; michael@0: michael@0: struct IDStr { michael@0: SkView* fView; michael@0: char* fStr; michael@0: }; michael@0: SkTDArray fListenTo, fBroadcastTo; michael@0: SkChunkAlloc fStrings; michael@0: michael@0: void addIDStr(SkTDArray* list, SkView*, const char* str); michael@0: michael@0: void rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent); michael@0: }; michael@0: michael@0: #endif