1 /* vim:tabstop=4:expandtab:shiftwidth=4 2 * 3 * Idesk -- AbstractClasses.h 4 * 5 * Copyright (c) 2002, Chris (nikon) (nikon@sc.rr.com) 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name of the <ORGANIZATION> nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * (See the included file COPYING / BSD ) 23 */ 24 25 #ifndef ABSTRACT_IDESK_CLASSES 26 #define ABSTRACT_IDESK_CLASSES 27 28 #include <string> 29 #include <vector> 30 #include <iostream> 31 #include "Misc.h" 32 #include "Action.h" 33 #include <stdlib.h> 34 35 //class Application; //circular include 36 37 using namespace std; 38 39 /* The classed defined below are all abstract, so they can never be 40 * instantized. They represent the core functionality of idesk, and 41 * should not include any extraneous data which is specific to a certain 42 * idesk configuration or usage (more on that in AbstractContainer). 43 */ 44 class AbtractApp; 45 class AbstractContainer; 46 class AbstractIcon; 47 class AbstractImage; 48 class AbstractCaption; 49 class AbstractConfig; 50 class AbstractIconConfig; 51 class AbstractActionConfig; 52 53 // TODO description 54 class AbstractApp 55 { 56 protected: 57 char ** argv; 58 int argc; 59 60 AbstractContainer * container; 61 62 virtual bool processArguments() = 0; 63 public: AbstractApp(int arg,char ** args)64 AbstractApp(int arg, char ** args) : argc(arg), argv(args) {} ~AbstractApp()65 virtual ~AbstractApp() {} 66 67 virtual void startIdesk() = 0; 68 virtual void restartIdesk() = 0; 69 }; 70 71 /* AbstractContainer 72 * This class represents the holding container for the icons. It contains 73 * a list of all the icons and a few methods that act on the program as a 74 * whole. Subclass this is create different icon containers. Possibilities 75 * for containers are a desktop container (already implemented), a widget 76 * container (gtk, qt, or other), or a taskbar container. 77 */ 78 class AbstractContainer 79 { 80 protected: 81 vector<AbstractIcon *> iconList; 82 AbstractConfig * config; 83 AbstractActionConfig * actionConfig; 84 85 AbstractApp * app; 86 Action currentAction; 87 88 public: AbstractContainer(AbstractApp * a)89 AbstractContainer(AbstractApp * a) : app(a) {} ~AbstractContainer()90 virtual ~AbstractContainer() {} 91 92 virtual void run() = 0; 93 virtual void destroy() = 0; 94 virtual void create() = 0; 95 virtual void addIcon(AbstractIcon *) = 0 ; 96 virtual void eventLoop() = 0 ; 97 98 virtual void configure() = 0; 99 100 virtual void saveState() = 0 ; 101 virtual void saveIcon(AbstractIcon *) = 0 ; 102 virtual void reloadState() = 0 ; 103 104 virtual void loadIcons() = 0 ; 105 virtual void arrangeIcons() = 0 ; 106 107 virtual void runCommand(const string & command) = 0 ; 108 }; 109 110 /* 111 * AbstractIcon 112 * This class represents all the functionality of an icon. It includes an 113 * image and a caption, which are the two defining characteristics of an 114 * idesk icon. Methods include functions that getcommon data used in both 115 * the image and caption and methods that utilize the entire icon object 116 * such as saving. Included are pointers to the parent container, the general 117 * configuration class, and the configuration class specific to the icon. 118 * Subclass this to create different types of icons. Possibilities include 119 * icons that utilize different different drawing toolkits (Xlib, Gdk, Qt) and 120 * icons that have special and/or different effects. 121 */ 122 class AbstractIcon 123 { 124 protected: 125 AbstractContainer * container; 126 127 AbstractImage * image; 128 AbstractCaption * caption; 129 130 AbstractConfig * config; 131 AbstractIconConfig * iconConfig; 132 133 vector<string> commandArray; 134 string iconFilename; 135 136 bool dragging, dragged; 137 bool captionOn; 138 bool valid; 139 140 int x, y; 141 142 public: AbstractIcon(AbstractContainer * c,AbstractConfig * con,AbstractIconConfig * iConfig)143 AbstractIcon(AbstractContainer * c, AbstractConfig * con, 144 AbstractIconConfig * iConfig) 145 : container(c), config(con), iconConfig(iConfig) {} ~AbstractIcon()146 virtual ~AbstractIcon() {} ; 147 148 virtual bool setImage(AbstractImage *) = 0 ; 149 virtual bool setCaption(AbstractCaption *) = 0 ; 150 151 virtual void mouseOverEffect() = 0 ; 152 virtual void mouseOffEffect() = 0 ; 153 154 virtual int getX() = 0; 155 virtual int getY() = 0; 156 virtual int getHeight() = 0; 157 virtual int getWidth() = 0; 158 159 virtual bool createIcon() = 0; isValid()160 virtual bool isValid(){ return valid; } getCursorOver()161 virtual void getCursorOver(){} getCursorOut()162 virtual void getCursorOut(){} event_enter_notify()163 virtual void event_enter_notify (){} event_leave_notify()164 virtual void event_leave_notify (){} 165 getCommandArray()166 virtual vector<string> getCommandArray() { return commandArray; } getCommand(int i)167 virtual string getCommand(int i) { return commandArray[i]; } 168 169 virtual void save() = 0; 170 }; 171 172 /* AbstractImage 173 * This class represents the image functionality of an image that represents 174 * the icon. Methods included perform basic image functions, such as drawing 175 * loading picture data, and image state changes. Pointers are included that 176 * point to the parent container, parent icon, general configuration, and 177 * icon specific configuration. Subclass this class to create different kinds 178 * of images. Possibilities include different image types (raster vs vector) 179 * and special effect images such as a shadow or a glow. 180 */ 181 class AbstractImage 182 { 183 protected: 184 AbstractContainer * container; 185 AbstractIcon * iconParent; 186 187 AbstractConfig * config; 188 AbstractIconConfig * iconConfig; 189 int width, height; 190 191 bool valid; 192 193 public: AbstractImage(AbstractContainer * c,AbstractIcon * iParent,AbstractConfig * con,AbstractIconConfig * iConfig)194 AbstractImage(AbstractContainer * c, AbstractIcon * iParent, 195 AbstractConfig * con, AbstractIconConfig * iConfig) 196 : container(c), iconParent(iParent), config(con), 197 iconConfig(iConfig) {} ~AbstractImage()198 virtual ~AbstractImage() {} ; 199 200 virtual void draw() = 0; redraw()201 virtual void redraw() {}; 202 mouseOverEffect()203 virtual void mouseOverEffect() {} mouseOffEffect()204 virtual void mouseOffEffect() {} 205 getWidth()206 int getWidth() { return width; } getHeight()207 int getHeight() { return height; } event_enter_notify()208 virtual void event_enter_notify (){} event_leave_notify()209 virtual void event_leave_notify (){} 210 configure()211 virtual void configure() {} ; 212 virtual void createPicture() = 0; 213 }; 214 215 /* 216 * AbstractCaption 217 * This class represents the text functionality of an icon. The caption for 218 * an icon is only optional. Methods included perform basic manipulation of 219 * the caption window, such as drawing, loading/creating font, and changing 220 * state. Pointers are included that point to the parent container, parent 221 * icon, general configuration, and icon specific configuration. Subclass 222 * this to create different caption types. Possibilities include captions 223 * that render using different font libraries (pango, Xft, Xlib). 224 */ 225 class AbstractCaption 226 { 227 protected: 228 AbstractContainer * container; 229 AbstractIcon * iconParent; 230 231 AbstractConfig * config; 232 AbstractIconConfig * iconConfig; 233 234 string text; 235 236 public: AbstractCaption(AbstractContainer * c,AbstractIcon * iParent,AbstractConfig * con,AbstractIconConfig * iConfig)237 AbstractCaption(AbstractContainer * c, AbstractIcon * iParent, 238 AbstractConfig * con, AbstractIconConfig * iConfig) 239 : container(c), iconParent(iParent), config(con), 240 iconConfig(iConfig) {} ~AbstractCaption()241 virtual ~AbstractCaption() {} ; 242 setText(const string & str)243 virtual void setText(const string & str) { text = str; } getText()244 virtual string getText() { return text; } 245 246 virtual int getFontWidth() = 0 ; 247 virtual int getFontHeight() = 0 ; 248 249 virtual void draw() = 0; 250 //virtual void updateText() = 0; mouseOverEffect()251 virtual void mouseOverEffect() {} mouseOffEffect()252 virtual void mouseOffEffect() {} 253 254 virtual void configure() = 0; 255 virtual void createFont() = 0; 256 }; 257 258 /* AbstractConfig 259 * This class represents the main configuration for idesk. This class is 260 * created once by the container upon initialization. This should parse 261 * any configuration files and set default values. Contained is a list of 262 * configurations for each individual icon. Methods in the class allow for 263 * iterator style access to the list of icon configurations and general 264 * program configuration. Subclass this to create different ways to configure 265 * idesk, basically for different configuration syntaxes. 266 */ 267 class AbstractConfig 268 { 269 protected: 270 vector<AbstractIconConfig *> iconConfigList; 271 272 string ideskrcFile; 273 274 unsigned int iterCtr; 275 276 int clickDelay; 277 278 public: AbstractConfig(string str)279 AbstractConfig(string str) : ideskrcFile(str), iterCtr(0), 280 clickDelay(300) {} ~AbstractConfig()281 virtual ~AbstractConfig() {} 282 getNumIcons()283 virtual int getNumIcons() { return iconConfigList.size(); } nextIcon()284 virtual AbstractIconConfig * nextIcon() 285 { 286 // TODO - use try and catch here to grab out-of-bounds errors 287 return iconConfigList[++iterCtr]; 288 } notFinished()289 virtual bool notFinished() { return iterCtr < iconConfigList.size(); } 290 start()291 virtual AbstractIconConfig * start() 292 { 293 iterCtr = 0; 294 return iconConfigList.front(); 295 } end()296 virtual AbstractIconConfig * end() 297 { 298 iterCtr = iconConfigList.size(); 299 return iconConfigList.back(); 300 } numIcons()301 virtual unsigned int numIcons() { return iconConfigList.size(); } getClickSpeed()302 virtual unsigned int getClickSpeed() { return clickDelay; } 303 }; 304 305 /* AbstractIconConfig 306 * This class is the configuration for a specific icon. This class should only 307 * be created and accessed through a class that extends AbstractConfig. 308 * This class pasrses data for a specific icon, whatever format that may be. 309 * Members include all the options and data for an icon such as the caption 310 * and command text, picture and icon filename. It is assumed that each 311 * icon has a seperate configuration file. Subclass this to create different 312 * ways to configure an icon, basically for different configuration syntaxes. 313 */ 314 class AbstractIconConfig 315 { 316 protected: 317 string iconFilename; 318 string pictureFilename; 319 string picExtension; 320 string caption; 321 string captionTip; 322 vector<string> commandArray; 323 324 int width, height; 325 326 public: ~AbstractIconConfig()327 virtual ~AbstractIconConfig() {} 328 getWidth()329 virtual int getWidth() { return width; } getHeight()330 virtual int getHeight() { return height; } 331 getIconFilename()332 virtual string getIconFilename() { return iconFilename; } getPictureFilename()333 virtual string getPictureFilename() { return pictureFilename; } getCaption()334 virtual string getCaption() { return caption; } getCaptionTip()335 virtual string getCaptionTip() { return captionTip; } getCommand(int i)336 virtual string getCommand(int i) { return commandArray[i]; } getCommandArray()337 virtual vector<string> getCommandArray() { return commandArray; } 338 }; 339 340 /* AbstractActionConfig 341 * Desc: TODO 342 * 343 */ 344 class AbstractActionConfig 345 { 346 protected: 347 vector<Action *> executeActions; 348 Action * lock; 349 Action * reload; 350 Action * drag; 351 Action * endDrag; 352 353 string ideskrcFile; 354 355 public: AbstractActionConfig(string str)356 AbstractActionConfig(string str) : ideskrcFile(str) {} ~AbstractActionConfig()357 virtual ~AbstractActionConfig() {} 358 359 // returning an dynamically allocated pointer, so some other class must 360 // do unallocation getLock()361 virtual Action * getLock() { return lock; } getReload()362 virtual Action * getReload() { return reload; } getDrag()363 virtual Action * getDrag() { return drag; } getEndDrag()364 virtual Action * getEndDrag() { return endDrag; } 365 getExecuteActions()366 virtual vector<Action *> getExecuteActions() { return executeActions; } getExecuteAction(int i)367 virtual Action * getExecuteAction(int i) { return executeActions[i]; } 368 }; 369 370 371 #endif 372