Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXHistoryItems.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  Generic history list traversal                               *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************/
00022 #ifndef FXHISTORYITEMS_H
00023 #define FXHISTORYITEMS_H
00024 
00025 #ifndef FXBASEOBJECT_H
00026 #include "FXBaseObject.h"
00027 #endif
00028 namespace FXEX {
00029 
00030 /**
00031  * Implements generic history list traversal
00032  */
00033 class FXAPI FXHistoryItems : public FXBaseObject {
00034   FXDECLARE(FXHistoryItems)
00035 
00036 protected:
00037   struct ItemDict{
00038     FXString  name;
00039     void*     data;
00040     FXint     key;
00041     ItemDict *previous;
00042     ItemDict *next;
00043     };
00044 
00045 protected:
00046   FXString    group;          // MRU Item group
00047   FXint       maxitems;       // Maximum number of items to track
00048   FXint       key;            // position of the most recently tracked item (ie *not* the most recent item)
00049   FXint       amount;         // The current amount of entries being tracked
00050   FXbool      destroySave;    // Indicates the save state on object destroy
00051   FXbool      stringData;     // Indicates that the 'data' is an FXString type
00052   ItemDict   *listStart;      // The first item in the list
00053   ItemDict   *currentItem;    // The current item in the list
00054 
00055 private:
00056   FXHistoryItems(const FXHistoryItems&);
00057   FXHistoryItems &operator=(const FXHistoryItems&);
00058 
00059 protected:
00060   /// serialisation
00061   FXHistoryItems(){};
00062 
00063   /// Reset the keys for each item
00064   void renumber();
00065 
00066   /// Remove any extra items
00067   void removeExtras();
00068 
00069 public:
00070   long onCmdClear(FXObject*,FXSelector,void*);
00071   long onCmdPrevious(FXObject*,FXSelector,void*);
00072   long onCmdNext(FXObject*,FXSelector,void*);
00073   long onUpdPrevious(FXObject*,FXSelector,void*);
00074   long onUpdNext(FXObject*,FXSelector,void*);
00075   long onCmdItem(FXObject*,FXSelector,void*);
00076   long onUpdItem(FXObject*,FXSelector,void*);
00077   long onUpdAnyItems(FXObject*,FXSelector,void*);
00078   long onUpdNextItems(FXObject*,FXSelector,void*);
00079   long onUpdPreviousItems(FXObject*,FXSelector,void*);
00080 
00081 public:
00082   // FIXME hmm...
00083   // since we are derived from FXBaseObject, this enum is kinda broken, but in this
00084   // case everything still happens to work...
00085   enum{
00086     ID_ITEM_NOT_FOUND=-1,
00087     ID_ITEM_0,
00088     ID_ITEM_1,
00089     ID_ITEM_2,
00090     ID_ITEM_3,
00091     ID_ITEM_4,
00092     ID_ITEM_5,
00093     ID_ITEM_6,
00094     ID_ITEM_7,
00095     ID_ITEM_8,
00096     ID_ITEM_9,
00097     ID_ITEM_10,
00098     ID_ITEM_NEXT,
00099     ID_ITEM_PREVIOUS,
00100     ID_CLEAR,
00101     ID_ANY_ITEMS,
00102     ID_NEXT_ITEMS,
00103     ID_PREVIOUS_ITEMS,
00104     ID_LAST
00105     };
00106 
00107 public:
00108   /**
00109    * Make new History Items Group with groupname gp,
00110    * capable of tracking an unlimited (-1) amount of items
00111    */
00112   FXHistoryItems(FXApp *a,const FXString& gp="History Items",FXObject* tgt=NULL,FXSelector sel=0,FXint size=-1);
00113 
00114   /// Change number of items we're tracking
00115   FXint size(const FXint mx);
00116 
00117   /// Return the maximum number of items capable being tracked
00118   FXint size() const { return maxitems; }
00119 
00120   /// Get the amount of entries in the list
00121   FXint no() { return amount; }
00122 
00123   /// Clear the list of items
00124   void clear();
00125 
00126   /// Get current index number
00127   FXint index() const { return key; }
00128 
00129   /// Set current index number - returns the current item pointed to
00130   FXint index(const FXint item);
00131 
00132   /// Get the previous/older item index, if it exists - stays on the same index
00133   FXint previous();
00134 
00135   /// Get the next/newer item index, if it exists - stays on the same index
00136   FXint next();
00137 
00138   /// Get the index of particular item name
00139   FXint find(const FXString& name);
00140 
00141   /// Get name of current item
00142   FXString name() { return currentItem->name; }
00143 
00144   /// get data of current item
00145   virtual void* data() { return currentItem->data; }
00146 
00147   /// Remove current item
00148   FXint remove();
00149 
00150   /// Remove an item by name
00151   FXint remove(const FXString& name);
00152 
00153   /// Remove an item by index
00154   FXint remove(const FXint item);
00155 
00156   /**
00157    * Add an item to the start of the list
00158    * --> made virtual so that decendants can change the 'add' behaviour
00159    */
00160   virtual FXint add(const FXString& name,void* data=NULL);
00161 
00162   /// Remove items newer than specified item - returns the current item pointed to
00163   FXint removeNewer(const FXint item);
00164 
00165   /// Remove items older than specified item - returns the current item pointed to
00166   FXint removeOlder(const FXint item);
00167 
00168   /**
00169    * Moves the 'named item' to the top of the list
00170    * Sets the current item reference to the top of the list
00171    */
00172   FXint moveFirst(const FXString& name);
00173 
00174   /**
00175    * Moves the 'item' to the top of the list
00176    * Sets the current item reference to the top of the list
00177    */
00178   FXint moveFirst(const FXint item);
00179 
00180   /// Saves the list to the registry on object destroy
00181   void saveOnDestroy(FXbool state);
00182 
00183   /// Saves the 'data' to the registry if it declared to an FXString type
00184   void dataIsString(FXbool state);
00185 
00186   /// Removes this list from the registry
00187   void clearReg();
00188 
00189   /// Save the current history to the registory - returns the current item
00190   FXint writeReg();
00191 
00192   /// Load the history from the registory - returns the most recent item
00193   FXint readReg();
00194 
00195   /// Save to a stream
00196   virtual void save(FXStream& store) const;
00197 
00198   /// Load from a stream
00199   virtual void load(FXStream& store);
00200 
00201   /// Destructor
00202   virtual ~FXHistoryItems();
00203   };
00204 
00205 } // namespace FXEX
00206 #endif // FXHISTORYITEMS_H