1 /********************************************************************************
2 *                                                                               *
3 *                     R e c e n t   F i l e s   L i s t                         *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1998,2005 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXRecentFiles.h,v 1.21 2005/01/16 16:06:06 fox Exp $                     *
23 ********************************************************************************/
24 #ifndef FXRECENTFILES_H
25 #define FXRECENTFILES_H
26 
27 #ifndef FXOBJECT_H
28 #include "FXObject.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /**
35 * The recent files object manages a most recently used (MRU) file list by
36 * means of the standard system registry.
37 * When connected to a widget, like a menu command, the recent files object
38 * updates the menu commands label to the associated recent file name; when
39 * the menu command is invoked, the recent file object sends its target a
40 * SEL_COMMAND message with the message data set to the associated file name,
41 * of the type const char*.
42 * When adding or removing file names, the recent files object automatically
43 * updates the system registry to record these changes.
44 */
45 class FXAPI FXRecentFiles : public FXObject {
46   FXDECLARE(FXRecentFiles)
47 protected:
48   FXString    group;          // MRU File group
49   FXObject   *target;         // Target object to send message
50   FXSelector  message;        // Message to send
51   FXint       maxfiles;       // Maximum number of files to track
52 private:
53   FXRecentFiles(const FXRecentFiles&);
54   FXRecentFiles &operator=(const FXRecentFiles&);
55 public:
56   long onCmdClear(FXObject*,FXSelector,void*);
57   long onCmdFile(FXObject*,FXSelector,void*);
58   long onUpdFile(FXObject*,FXSelector,void*);
59   long onUpdAnyFiles(FXObject*,FXSelector,void*);
60 public:
61   enum{
62     ID_CLEAR,
63     ID_ANYFILES,
64     ID_FILE_1,
65     ID_FILE_2,
66     ID_FILE_3,
67     ID_FILE_4,
68     ID_FILE_5,
69     ID_FILE_6,
70     ID_FILE_7,
71     ID_FILE_8,
72     ID_FILE_9,
73     ID_FILE_10
74     };
75 public:
76 
77   /// Make new Recent Files Group with default groupname
78   FXRecentFiles();
79 
80   /// Make new Recent Files Group with groupname gp
81   FXRecentFiles(const FXString& gp,FXObject *tgt=NULL,FXSelector sel=0);
82 
83   /// Change number of files we're tracking
setMaxFiles(FXint mx)84   void setMaxFiles(FXint mx){ maxfiles=mx; }
85 
86   /// Return the maximum number of files being tracked
getMaxFiles()87   FXint getMaxFiles() const { return maxfiles; }
88 
89   /// Set group name
setGroupName(const FXString & name)90   void setGroupName(const FXString& name){ group=name; }
91 
92   /// Return group name
getGroupName()93   FXString getGroupName() const { return group; }
94 
95   /// Change the target
setTarget(FXObject * t)96   void setTarget(FXObject *t){ target=t; }
97 
98   /// Get the target
getTarget()99   FXObject *getTarget() const { return target; }
100 
101   /// Change the message
setSelector(FXSelector sel)102   void setSelector(FXSelector sel){ message=sel; }
103 
104   /// Return the message id
getSelector()105   FXSelector getSelector() const { return message; }
106 
107   /// Obtain the filename at index
108   FXString getFile(FXint index) const;
109 
110   /// Change the filename at index
111   void setFile(FXint index,const FXString& filename);
112 
113   /// Append a file
114   void appendFile(const FXString& filename);
115 
116   /// Remove a file
117   void removeFile(const FXString& filename);
118 
119   /// Clear the list of files
120   void clear();
121 
122   /// Save to a stream
123   virtual void save(FXStream& store) const;
124 
125   /// Load from a stream
126   virtual void load(FXStream& store);
127 
128   /// Destructor
129   virtual ~FXRecentFiles();
130   };
131 
132 }
133 
134 #endif
135