1 /* 2 * This file is a part of the Cairo-Dock project 3 * 4 * Copyright : (C) see the 'copyright' file. 5 * E-mail : see the 'copyright' file. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 3 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __CAIRO_DOCK_ICON_FACTORY__ 21 #define __CAIRO_DOCK_ICON_FACTORY__ 22 23 #include <glib.h> 24 25 #include "cairo-dock-struct.h" 26 #include "cairo-dock-image-buffer.h" 27 #include "cairo-dock-object.h" 28 29 G_BEGIN_DECLS 30 31 /** 32 *@file cairo-dock-icon-factory.h This class defines the items contained in containers : Icons. 33 * An icon can either be: 34 * - a launcher (it has a command, a class, and possible an X window ID) 35 * - an appli (it has a X window ID and a class, no command) 36 * - an applet (it has a module instance and no command, possibly a class) 37 * - a container (it has a sub-dock and no class nor command) 38 * - a class icon (it has a bsub-dock and a class, but no command nor X ID) 39 * - a separator (it has nothing) 40 * 41 * The class defines the methods used to create a generic Icon and to load its various buffers. 42 * Specialized Icons are created by the corresponding factory. 43 */ 44 45 /// Available groups of icons. 46 typedef enum { 47 CAIRO_DOCK_LAUNCHER = 0, // launchers and applets, and applis if mixed 48 CAIRO_DOCK_SEPARATOR12, 49 CAIRO_DOCK_APPLI, 50 CAIRO_DOCK_NB_GROUPS 51 } CairoDockIconGroup; 52 53 /// Animation state of an icon, sorted by priority. 54 typedef enum { 55 CAIRO_DOCK_STATE_REST = 0, 56 CAIRO_DOCK_STATE_MOUSE_HOVERED, 57 CAIRO_DOCK_STATE_CLICKED, 58 CAIRO_DOCK_STATE_AVOID_MOUSE, 59 CAIRO_DOCK_STATE_FOLLOW_MOUSE, 60 CAIRO_DOCK_STATE_REMOVE_INSERT, 61 CAIRO_DOCK_NB_STATES 62 } CairoDockAnimationState; 63 64 /// Icon's interface 65 struct _IconInterface { 66 /// function that loads the icon surface (and optionnally texture). 67 void (*load_image) (Icon *icon); 68 /// function called when the user drag something over the icon for more than 500ms. 69 void (*action_on_drag_hover) (Icon *icon); 70 }; 71 72 /// Definition of an Icon. 73 struct _Icon { 74 //\____________ Definition. 75 /// object 76 GldiObject object; 77 gpointer pDataSlot[CAIRO_DOCK_NB_DATA_SLOT]; 78 /// group of the icon. 79 CairoDockIconGroup iGroup; 80 /// interface 81 IconInterface iface; 82 GldiContainer *pContainer; // container where the icon is currently. 83 84 //\____________ properties. 85 // generic. 86 /// Name of the icon. 87 gchar *cName; 88 /// Short info displayed on the icon (few characters). 89 gchar *cQuickInfo; 90 /// name or path of an image displayed on the icon. 91 gchar *cFileName; 92 /// Class of application the icon will be bound to. 93 gchar *cClass; 94 /// name of the dock the icon belongs to (NULL means it's not currently inside a dock). 95 gchar *cParentDockName; 96 /// Sub-dock the icon is pointing to. 97 CairoDock *pSubDock; 98 /// Order of the icon amongst the other icons of its group. 99 gdouble fOrder; 100 101 gint iSpecificDesktop; 102 gint iSubdockViewType; 103 /// a hint to indicate the icon should be kept static (no animation like bouncing). 104 gboolean bStatic; 105 /// a flag that allows the icon to be always visible, even when the dock is hidden. 106 gboolean bAlwaysVisible; 107 gboolean bIsDemandingAttention; 108 gboolean bHasHiddenBg; 109 GldiColor *pHiddenBgColor; // NULL to use the default color 110 gboolean bIgnoreQuicklist; // TRUE to not display the Ubuntu's quicklist of the class 111 gboolean bHasIndicator; 112 113 // Launcher. 114 gchar *cDesktopFileName; // nom (et non pas chemin) du fichier .desktop 115 gchar *cCommand; 116 gchar *cWorkingDirectory; 117 gchar *cBaseURI; 118 gint iVolumeID; 119 gchar **pMimeTypes; 120 gchar *cWmClass; 121 gchar *cInitialName; 122 123 // Appli. 124 GldiWindowActor *pAppli; 125 126 // Applet. 127 GldiModuleInstance *pModuleInstance; 128 GldiModuleInstance *pAppletOwner; 129 130 //\____________ Buffers. 131 gdouble fWidth, fHeight; // size at rest in the container (including ratio and orientation). 132 gint iRequestedWidth, iRequestedHeight; // buffer image size that can be requested (surface/texture size) 133 gint iRequestedDisplayWidth, iRequestedDisplayHeight; // icon size that can be requested (as displayed in the dock) 134 gint iAllocatedWidth, iAllocatedHeight; // buffer image size actually allocated (surface/texture size) 135 CairoDockImageBuffer image; // the image of the icon 136 CairoDockImageBuffer label; // the label above the icon 137 GList *pOverlays; // a list of CairoOverlay 138 CairoDataRenderer *pDataRenderer; 139 CairoDockTransition *pTransition; 140 141 //\____________ Drawing parameters. 142 gdouble fXMin, fXMax; // Abscisse extremale gauche/droite que the icon atteindra (variable avec la vague). 143 gdouble fXAtRest; // Abscisse de the icon au repos. 144 gdouble fPhase; // Phase de the icon (entre -pi et piconi). 145 gdouble fX, fY; // Abscisse/Ordonnee temporaire du bord haut-gauche de l'image de the icon. 146 147 gdouble fScale; 148 gdouble fDrawX, fDrawY; 149 gdouble fWidthFactor, fHeightFactor; 150 gdouble fAlpha; 151 gdouble fDeltaYReflection; // Decalage en ordonnees du reflet (rebond). 152 gdouble fOrientation; // par rapport a la verticale Oz 153 gint iRotationX; // Rotation autour de l'axe Ox 154 gint iRotationY; // Rotation autour de l'axe Oy 155 gdouble fReflectShading; 156 157 gdouble fGlideOffset; // decalage pour le glissement des icons. 158 gint iGlideDirection; // direction dans laquelle glisse the icon. 159 gdouble fGlideScale; // echelle d'adaptation au glissement. 160 161 CairoDockAnimationState iAnimationState; 162 /// Whether the icon is currently pointed or not. 163 gboolean bPointed; 164 gdouble fInsertRemoveFactor; 165 gboolean bDamaged; // TRUE when the icon couldn't draw its surface, because the Gl context was not yet ready. 166 gboolean bNeedApplyBackground; 167 168 //\____________ Other dynamic parameters. 169 guint iSidRedrawSubdockContent; 170 guint iSidLoadImage; 171 guint iSidDoubleClickDelay; 172 gint iNbDoubleClickListeners; 173 gint iHideLabel; 174 gint iThumbnailX, iThumbnailY; // X icon geometry for apps 175 gint iThumbnailWidth, iThumbnailHeight; 176 177 gboolean bIsLaunching; // a mere recopy of gldi_class_is_starting() 178 gpointer reserved[4]; 179 }; 180 181 typedef void (*CairoIconContainerLoadFunc) (void); 182 typedef void (*CairoIconContainerUnloadFunc) (void); 183 typedef void (*CairoIconContainerRenderFunc) (Icon *pIcon, GldiContainer *pContainer, int w, int h, cairo_t *pCairoContext); 184 typedef void (*CairoIconContainerRenderOpenGLFunc) (Icon *pIcon, GldiContainer *pContainer, int w, int h); 185 186 /// Definition of an Icon container (= an icon holding a sub-dock) renderer. 187 struct _CairoIconContainerRenderer { 188 CairoIconContainerLoadFunc load; 189 CairoIconContainerUnloadFunc unload; 190 CairoIconContainerRenderFunc render; 191 CairoIconContainerRenderOpenGLFunc render_opengl; 192 }; 193 194 /** Say if an object is an Icon. 195 *@param obj the object. 196 *@return TRUE if the object is an icon. 197 */ 198 #define CAIRO_DOCK_IS_ICON(obj) gldi_object_is_manager_child (obj, &myIconObjectMgr) 199 200 #define CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER GLDI_OBJECT_IS_LAUNCHER_ICON 201 #define CAIRO_DOCK_ICON_TYPE_IS_CONTAINER GLDI_OBJECT_IS_STACK_ICON 202 #define CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR GLDI_OBJECT_IS_SEPARATOR_ICON 203 #define CAIRO_DOCK_ICON_TYPE_IS_CLASS_CONTAINER GLDI_OBJECT_IS_CLASS_ICON 204 #define CAIRO_DOCK_ICON_TYPE_IS_APPLI GLDI_OBJECT_IS_APPLI_ICON 205 #define CAIRO_DOCK_ICON_TYPE_IS_APPLET GLDI_OBJECT_IS_APPLET_ICON 206 207 /** TRUE if the icon holds a window. 208 *@param icon an icon. 209 */ 210 #define CAIRO_DOCK_IS_APPLI(icon) (icon != NULL && (icon)->pAppli != NULL) 211 212 /** TRUE if the icon holds an instance of a module. 213 *@param icon an icon. 214 */ 215 #define CAIRO_DOCK_IS_APPLET(icon) (icon != NULL && (icon)->pModuleInstance != NULL) 216 217 /** TRUE if the icon is an icon pointing on the sub-dock of a class. 218 *@param icon an icon. 219 */ 220 #define CAIRO_DOCK_IS_MULTI_APPLI(icon) (\ 221 ( CAIRO_DOCK_ICON_TYPE_IS_LAUNCHER (icon)\ 222 || CAIRO_DOCK_ICON_TYPE_IS_CLASS_CONTAINER (icon)\ 223 || (CAIRO_DOCK_ICON_TYPE_IS_APPLET (icon) && icon->cClass != NULL) )\ 224 && icon->pSubDock != NULL) 225 226 /** TRUE if the icon is an automatic separator. 227 *@param icon an icon. 228 */ 229 #define CAIRO_DOCK_IS_AUTOMATIC_SEPARATOR(icon) (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (icon) && (icon)->cDesktopFileName == NULL) 230 231 /** TRUE if the icon is a separator added by the user. 232 *@param icon an icon. 233 */ 234 #define CAIRO_DOCK_IS_USER_SEPARATOR(icon) (CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (icon) && (icon)->cDesktopFileName != NULL) 235 /** 236 *TRUE if the icon is an icon d'appli only. 237 *@param icon an icon. 238 */ 239 #define CAIRO_DOCK_IS_NORMAL_APPLI(icon) (CAIRO_DOCK_IS_APPLI (icon) && CAIRO_DOCK_ICON_TYPE_IS_APPLI (icon)) 240 /** 241 *TRUE if the icon is an icon d'applet detachable en desklet. 242 *@param icon an icon. 243 */ 244 #define CAIRO_DOCK_IS_DETACHABLE_APPLET(icon) (CAIRO_DOCK_IS_APPLET (icon) && ((icon)->pModuleInstance->pModule->pVisitCard->iContainerType & CAIRO_DOCK_MODULE_CAN_DESKLET)) 245 246 247 /** Create an empty icon. 248 *@return the newly allocated icon object. 249 */ 250 Icon *gldi_icon_new (void); 251 252 253 /** Create an Icon that will behave like a launcher. It's especially useful for applets that want to fill a sub-dock or a desklet (the icon is not loaded by the function). Be careful that the strings are not duplicated. Therefore, you must use g_strdup() if you want to set a constant string; and must not free the strings after calling this function. 254 * @param cName label of the icon 255 * @param cFileName name of an image 256 * @param cCommand a command, or NULL 257 * @param cQuickInfo a quick-info, or NULL 258 * @param fOrder order of the icon in its container. 259 * @return the newly created icon. 260 */ 261 Icon * cairo_dock_create_dummy_launcher (gchar *cName, gchar *cFileName, gchar *cCommand, gchar *cQuickInfo, double fOrder); 262 263 264 /* Cree la surface de reflection d'une icone (pour cairo). 265 *@param pIcon l'icone. 266 *@param pContainer le container de l'icone. 267 */ 268 void cairo_dock_add_reflection_to_icon (Icon *pIcon, GldiContainer *pContainer); 269 270 271 gboolean cairo_dock_apply_icon_background_opengl (Icon *icon); 272 273 /**Fill the image buffer (surface & texture) of a given icon, according to its type. Set its size if necessary, and fills the reflection buffer for cairo. 274 *@param icon the icon. 275 *@param pContainer its container. 276 */ 277 void cairo_dock_load_icon_image (Icon *icon, GldiContainer *pContainer); 278 #define cairo_dock_reload_icon_image cairo_dock_load_icon_image 279 280 /**Fill the label buffer (surface & texture) of a given icon, according to a text description. 281 *@param icon the icon. 282 */ 283 void cairo_dock_load_icon_text (Icon *icon); 284 285 /**Fill the quick-info buffer (surface & texture) of a given icon, according to a text description. 286 *@param icon the icon. 287 */ 288 void cairo_dock_load_icon_quickinfo (Icon *icon); 289 290 /** Fill all the buffers (surfaces & textures) of a given icon, according to its type. Set its size accordingly, and fills the reflection buffer for cairo. Label and quick-info are loaded with the current global text description. 291 *@param pIcon the icon. 292 *@param pContainer its container. 293 */ 294 void cairo_dock_load_icon_buffers (Icon *pIcon, GldiContainer *pContainer); 295 296 void cairo_dock_trigger_load_icon_buffers (Icon *pIcon); 297 298 299 void cairo_dock_draw_subdock_content_on_icon (Icon *pIcon, CairoDock *pDock); 300 301 #define cairo_dock_set_subdock_content_renderer(pIcon, view) (pIcon)->iSubdockViewType = view 302 303 304 void gldi_icon_detach (Icon *pIcon); 305 306 void gldi_icon_insert_in_container (Icon *pIcon, GldiContainer *pContainer, gboolean bAnimateIcon); 307 308 309 G_END_DECLS 310 #endif 311