element.h

Go to the documentation of this file.
00001 /*
00002  * element.h
00003  *
00004  * Copyright (C) 2008,2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Basic dialog element.  This is *very* basic, capturing the base class of
00032  * elements in the dialog hierarchy.
00033  */
00034 
00035 #ifndef WAVEPACKET_DIALOG_ELEMENT_H__
00036 #define WAVEPACKET_DIALOG_ELEMENT_H__
00037 
00038 // includes --------------------------------------------------------------------
00039 #include "drawer.h"
00040 #include "crypto/crypto.h"
00041 
00042 
00043 // forward declaration
00044 class Datahash;
00045 
00046 
00047 namespace dialog {
00048 
00049 // forward declaration
00050 class Manager;
00051 
00052 
00053 /// \ingroup dialog
00054 /*@{*/
00055 
00056 
00057 ////////////////////////////////////////////////////////////////////////////////
00058 //
00059 //      Element base class
00060 //
00061 ////////////////////////////////////////////////////////////////////////////////
00062 
00063 class Element {
00064 public:
00065         // virtual destructor --------------------------------------------------
00066         virtual ~Element(void) throw();
00067 
00068         // dialog::Element class interface methods ------------------------------
00069         virtual int getWidth(void) = 0;
00070         virtual int getHeight(void) = 0;
00071         virtual void draw(IN const point_t& offset) = 0;
00072         virtual void cursor(IN const point_t& pos) = 0;
00073         virtual const char * keyboard(IN int key, IN int mods);
00074         virtual Element * getFocus(IN const point_t& pos);
00075         virtual void notifyFocus(IN bool haveFocus);
00076         virtual const char * button(IN int button, IN int state,
00077                                 IN const point_t& pos) = 0;
00078         virtual void addData(IN crypto::DESKey * key,
00079                                 IO Datahash * data);
00080 };
00081 
00082 
00083 
00084 smart_ptr<Element> constructElementTree(IN Manager * mgr,
00085                                 IN const Datahash * hash);
00086 
00087 
00088 
00089 ///     Clients will need to provide an object that implements this interface if
00090 ///     they want to provide their own custom-defined dialog::Element objects.
00091 class Factory {
00092 public:
00093         // virtual destructor --------------------------------------------------
00094         virtual ~Factory(void) throw();
00095 
00096         // dialog::Factory class interface methods -----------------------------
00097         virtual smart_ptr<Element> createElement(IN const char * type,
00098                                         IN Manager * mgr,
00099                                         IN const Datahash * data) = 0;
00100 };
00101 
00102 
00103 
00104 /// factory for built-in types
00105 smart_ptr<Factory> getDefaultFactory(void);
00106 
00107 
00108 /// helper method to register default types with a manager
00109 void registerDefaultFactories(IN Manager * mgr);
00110 
00111 
00112 
00113 };      // dialog namespace
00114 
00115 #endif  // WAVEPACKET_DIALOG_ELEMENT_H__
00116