~cairo-dock-team/ubuntu/oneiric/cairo-dock/2.3.0-3

« back to all changes in this revision

Viewing changes to src/cairo-dock-load.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20100809232612-pocdxliaxjdetm37
Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include <math.h>
21
 
#include <string.h>
22
 
#include <stdlib.h>
23
 
 
24
 
#include <gtk/gtk.h>
25
 
 
26
 
#ifdef HAVE_GLITZ
27
 
#include <gdk/gdkx.h>
28
 
#include <glitz-glx.h>
29
 
#include <cairo-glitz.h>
30
 
#endif
31
 
 
32
 
#include <gtk/gtkgl.h>
33
 
 
34
 
#include "cairo-dock-draw.h"
35
 
#include "cairo-dock-icons.h"
36
 
#include "cairo-dock-surface-factory.h"
37
 
#include "cairo-dock-launcher-factory.h"
38
 
#include "cairo-dock-application-factory.h"
39
 
#include "cairo-dock-separator-factory.h"
40
 
#include "cairo-dock-applet-factory.h"
41
 
#include "cairo-dock-dock-factory.h"
42
 
#include "cairo-dock-modules.h"
43
 
#include "cairo-dock-log.h"
44
 
#include "cairo-dock-dock-manager.h"
45
 
#include "cairo-dock-class-manager.h"
46
 
#include "cairo-dock-X-utilities.h"
47
 
#include "cairo-dock-draw-opengl.h"
48
 
#include "cairo-dock-internal-taskbar.h"
49
 
#include "cairo-dock-internal-indicators.h"
50
 
#include "cairo-dock-internal-labels.h"
51
 
#include "cairo-dock-internal-background.h"
52
 
#include "cairo-dock-internal-icons.h"
53
 
#include "cairo-dock-container.h"
54
 
#include "cairo-dock-desklet.h"
55
 
#include "cairo-dock-dialogs.h"
56
 
#include "cairo-dock-data-renderer.h"
57
 
#include "cairo-dock-flying-container.h"
58
 
#include "cairo-dock-emblem.h"
59
 
#include "cairo-dock-load.h"
60
 
 
61
 
extern CairoDock *g_pMainDock;
62
 
 
63
 
extern gint g_iXScreenWidth[2];  // change tous les g_iScreen par g_iXScreen le 28/07/2009
64
 
extern gint g_iXScreenHeight[2];
65
 
 
66
 
extern gchar *g_cCurrentThemePath;
67
 
 
68
 
extern CairoDockImageBuffer g_pDockBackgroundBuffer;
69
 
extern CairoDockImageBuffer g_pVisibleZoneBuffer;
70
 
extern CairoDockImageBuffer g_pIndicatorBuffer;
71
 
extern CairoDockImageBuffer g_pActiveIndicatorBuffer;
72
 
extern CairoDockImageBuffer g_pClassIndicatorBuffer;
73
 
extern CairoDockImageBuffer g_pIconBackgroundBuffer;
74
 
extern CairoDockImageBuffer g_pBoxAboveBuffer;
75
 
extern CairoDockImageBuffer g_pBoxBelowBuffer;
76
 
 
77
 
extern GLuint g_pGradationTexture[2];
78
 
 
79
 
extern gboolean g_bUseOpenGL;
80
 
 
81
 
static CairoDockDesktopBackground *s_pDesktopBg = NULL;
82
 
static cairo_t *s_pSourceContext = NULL;
83
 
 
84
 
void cairo_dock_free_label_description (CairoDockLabelDescription *pTextDescription)
85
 
{
86
 
        if (pTextDescription == NULL)
87
 
                return ;
88
 
        g_free (pTextDescription->cFont);
89
 
        g_free (pTextDescription);
90
 
}
91
 
 
92
 
void cairo_dock_copy_label_description (CairoDockLabelDescription *pDestTextDescription, CairoDockLabelDescription *pOrigTextDescription)
93
 
{
94
 
        g_return_if_fail (pOrigTextDescription != NULL && pDestTextDescription != NULL);
95
 
        memcpy (pDestTextDescription, pOrigTextDescription, sizeof (CairoDockLabelDescription));
96
 
        pDestTextDescription->cFont = g_strdup (pOrigTextDescription->cFont);
97
 
}
98
 
 
99
 
CairoDockLabelDescription *cairo_dock_duplicate_label_description (CairoDockLabelDescription *pOrigTextDescription)
100
 
{
101
 
        g_return_val_if_fail (pOrigTextDescription != NULL, NULL);
102
 
        CairoDockLabelDescription *pTextDescription = g_memdup (pOrigTextDescription, sizeof (CairoDockLabelDescription));
103
 
        pTextDescription->cFont = g_strdup (pOrigTextDescription->cFont);
104
 
        return pTextDescription;
105
 
}
106
 
 
107
 
gchar *cairo_dock_generate_file_path (const gchar *cImageFile)
108
 
{
109
 
        g_return_val_if_fail (cImageFile != NULL, NULL);
110
 
        gchar *cImagePath;
111
 
        if (*cImageFile == '~')
112
 
        {
113
 
                cImagePath = g_strdup_printf ("%s%s", getenv("HOME"), cImageFile + 1);
114
 
        }
115
 
        else if (*cImageFile == '/')
116
 
        {
117
 
                cImagePath = g_strdup (cImageFile);
118
 
        }
119
 
        else
120
 
        {
121
 
                cImagePath = g_strdup_printf ("%s/%s", g_cCurrentThemePath, cImageFile);
122
 
        }
123
 
        return cImagePath;
124
 
}
125
 
 
126
 
 
127
 
#define _get_source_context(...) \
128
 
        __extension__ ({\
129
 
        if (s_pSourceContext == NULL) {\
130
 
                if (g_pMainDock == NULL) return;\
131
 
                s_pSourceContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (g_pMainDock)); }\
132
 
        s_pSourceContext; })
133
 
#define _destroy_source_context(...) do {\
134
 
        if (s_pSourceContext != NULL) {\
135
 
                cairo_destroy (s_pSourceContext);\
136
 
                s_pSourceContext = NULL; } } while (0)
137
 
 
138
 
void cairo_dock_load_image_buffer_full (CairoDockImageBuffer *pImage, const gchar *cImageFile, int iWidth, int iHeight, CairoDockLoadImageModifier iLoadModifier, double fAlpha)
139
 
{
140
 
        if (cImageFile == NULL)
141
 
                return;
142
 
        cairo_t *pSourceContext = _get_source_context ();
143
 
        gchar *cImagePath = cairo_dock_generate_file_path (cImageFile);
144
 
        double w, h;
145
 
        pImage->pSurface = cairo_dock_create_surface_from_image (
146
 
                cImagePath,
147
 
                pSourceContext,
148
 
                1.,
149
 
                iWidth,
150
 
                iHeight,
151
 
                iLoadModifier,
152
 
                &w,
153
 
                &h,
154
 
                NULL, NULL);
155
 
        pImage->iWidth = w;
156
 
        pImage->iHeight = h;
157
 
        
158
 
        if (fAlpha < 1)
159
 
        {
160
 
                cairo_surface_t *pNewSurfaceAlpha = _cairo_dock_create_blank_surface (pSourceContext,
161
 
                        w,
162
 
                        h);
163
 
                cairo_t *pCairoContext = cairo_create (pNewSurfaceAlpha);
164
 
 
165
 
                cairo_set_source_surface (pCairoContext, pImage->pSurface, 0, 0);
166
 
                cairo_paint_with_alpha (pCairoContext, fAlpha);
167
 
                cairo_destroy (pCairoContext);
168
 
 
169
 
                cairo_surface_destroy (pImage->pSurface);
170
 
                pImage->pSurface = pNewSurfaceAlpha;
171
 
        }
172
 
        
173
 
        if (g_bUseOpenGL)
174
 
                pImage->iTexture = cairo_dock_create_texture_from_surface (pImage->pSurface);
175
 
        
176
 
        g_free (cImagePath);
177
 
}
178
 
 
179
 
void cairo_dock_load_image_buffer_from_surface (CairoDockImageBuffer *pImage, cairo_surface_t *pSurface, int iWidth, int iHeight)
180
 
{
181
 
        pImage->pSurface = pSurface;
182
 
        pImage->iWidth = iWidth;
183
 
        pImage->iHeight = iHeight;
184
 
        if (g_bUseOpenGL)
185
 
                pImage->iTexture = cairo_dock_create_texture_from_surface (pImage->pSurface);
186
 
}
187
 
 
188
 
CairoDockImageBuffer *cairo_dock_create_image_buffer (const gchar *cImageFile, int iWidth, int iHeight, CairoDockLoadImageModifier iLoadModifier)
189
 
{
190
 
        CairoDockImageBuffer *pImage = g_new0 (CairoDockImageBuffer, 1);
191
 
        
192
 
        cairo_dock_load_image_buffer (pImage, cImageFile, iWidth, iHeight, iLoadModifier);
193
 
        
194
 
        return pImage;
195
 
}
196
 
 
197
 
void cairo_dock_unload_image_buffer (CairoDockImageBuffer *pImage)
198
 
{
199
 
        if (pImage->pSurface != NULL)
200
 
        {
201
 
                cairo_surface_destroy (pImage->pSurface);
202
 
        }
203
 
        if (pImage->iTexture != 0)
204
 
        {
205
 
                _cairo_dock_delete_texture (pImage->iTexture);
206
 
        }
207
 
        memset (pImage, 0, sizeof (CairoDockImageBuffer));
208
 
}
209
 
 
210
 
void cairo_dock_free_image_buffer (CairoDockImageBuffer *pImage)
211
 
{
212
 
        if (pImage == NULL)
213
 
                return;
214
 
        cairo_dock_unload_image_buffer (pImage);
215
 
        g_free (pImage);
216
 
}
217
 
 
218
 
 
219
 
 
220
 
  //////////////////
221
 
 /// ICON LOADER ///
222
 
//////////////////
223
 
 
224
 
void cairo_dock_add_reflection_to_icon (cairo_t *pSourceContext, Icon *pIcon, CairoContainer *pContainer)
225
 
{
226
 
        if (g_bUseOpenGL)
227
 
                return ;
228
 
        g_return_if_fail (pIcon != NULL && pContainer!= NULL);
229
 
        if (pIcon->pReflectionBuffer != NULL)
230
 
                cairo_surface_destroy (pIcon->pReflectionBuffer);
231
 
        
232
 
        int iWidth, iHeight;
233
 
        cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
234
 
        pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
235
 
                pSourceContext,
236
 
                iWidth,
237
 
                iHeight,
238
 
                myIcons.fReflectSize * cairo_dock_get_max_scale (pContainer),
239
 
                myIcons.fAlbedo,
240
 
                pContainer->bIsHorizontal,
241
 
                pContainer->bDirectionUp);
242
 
}
243
 
 
244
 
 
245
 
void cairo_dock_fill_one_icon_buffer (Icon *icon, cairo_t* pSourceContext, gdouble fMaxScale, gboolean bIsHorizontal, gboolean bDirectionUp)
246
 
{
247
 
        //g_print ("%s (%d, %.2f, %s)\n", __func__, icon->iType, fMaxScale, icon->cFileName);
248
 
        if (cairo_dock_icon_is_being_removed (icon))  // si la fenetre est en train de se faire degager du dock, pas la peine de mettre a jour son icone. /// A voir pour les icones d'appli ...
249
 
        {
250
 
                cd_debug ("skip icon reload for %s", icon->cName);
251
 
                return;
252
 
        }
253
 
        // on garde la surface/texture actuelle pour les emblemes.
254
 
        cairo_surface_t *pPrevSurface = icon->pIconBuffer;
255
 
        icon->pIconBuffer = NULL;
256
 
        GLuint iPrevTexture = icon->iIconTexture;
257
 
        icon->iIconTexture = 0;
258
 
        
259
 
        if (icon->pReflectionBuffer != NULL)
260
 
        {
261
 
                cairo_surface_destroy (icon->pReflectionBuffer);
262
 
                icon->pReflectionBuffer = NULL;
263
 
        }
264
 
        
265
 
        if (icon->fWidth < 0 || icon->fHeight < 0)  // on ne veut pas de surface.
266
 
        {
267
 
                if (iPrevTexture != 0)
268
 
                        _cairo_dock_delete_texture (iPrevTexture);
269
 
                if (pPrevSurface != NULL)
270
 
                        cairo_surface_destroy (pPrevSurface);
271
 
                return;
272
 
        }
273
 
        
274
 
        if (CAIRO_DOCK_IS_LAUNCHER (icon)/** || (CAIRO_DOCK_IS_USER_SEPARATOR (icon) && icon->cFileName != NULL)*/)  // si c'est un lanceur /*ou un separateur avec une icone.*/
275
 
        {
276
 
                /// A FAIRE : verifier qu'on peut enlever le test sur fMaxScale ...
277
 
                if (icon->fWidth == 0 || fMaxScale != 1.)
278
 
                        icon->fWidth = myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER];
279
 
                if (icon->fHeight == 0 || fMaxScale != 1.)
280
 
                        icon->fHeight = myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER];
281
 
                gchar *cIconPath = cairo_dock_search_icon_s_path (icon->cFileName);
282
 
                
283
 
                if (icon->pSubDock != NULL && icon->iSubdockViewType != 0)  // icone de sous-dock, on le redessinera lorsque les icones du sous-dock auront ete chargees.
284
 
                {
285
 
                        icon->pIconBuffer = _cairo_dock_create_blank_surface (pSourceContext, icon->fWidth * fMaxScale, icon->fHeight * fMaxScale);
286
 
                }
287
 
                else if (cIconPath != NULL && *cIconPath != '\0')  // c'est un lanceur classique.
288
 
                {
289
 
                        icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
290
 
                                pSourceContext,
291
 
                                fMaxScale,
292
 
                                icon->fWidth/*myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER]*/,
293
 
                                icon->fHeight/*myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER]*/,
294
 
                                CAIRO_DOCK_FILL_SPACE,
295
 
                                (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
296
 
                                (bIsHorizontal ? &icon->fHeight : &icon->fWidth),
297
 
                                NULL, NULL);
298
 
                }
299
 
                else if (icon->pSubDock != NULL && icon->cClass != NULL)  // c'est un epouvantail
300
 
                {
301
 
                        //g_print ("c'est un epouvantail\n");
302
 
                        icon->pIconBuffer = cairo_dock_create_surface_from_class (icon->cClass,
303
 
                                pSourceContext,
304
 
                                fMaxScale,
305
 
                                (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
306
 
                                (bIsHorizontal ? &icon->fHeight : &icon->fWidth));
307
 
                        if (icon->pIconBuffer == NULL)  // aucun inhibiteur ou aucune image correspondant a cette classe, on cherche a copier une des icones d'appli de cette classe.
308
 
                        {
309
 
                                const GList *pApplis = cairo_dock_list_existing_appli_with_class (icon->cClass);
310
 
                                if (pApplis != NULL)
311
 
                                {
312
 
                                        Icon *pOneIcon = (Icon *) (g_list_last ((GList*)pApplis)->data);  // on prend le dernier car les applis sont inserees a l'envers, et on veut avoir celle qui etait deja present dans le dock (pour 2 raison : continuite, et la nouvelle (en 1ere position) n'est pas forcement deja dans un dock, ce qui fausse le ratio).
313
 
                                        icon->pIconBuffer = cairo_dock_duplicate_inhibator_surface_for_appli (pSourceContext,
314
 
                                                pOneIcon,
315
 
                                                fMaxScale,
316
 
                                                (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
317
 
                                                (bIsHorizontal ? &icon->fHeight : &icon->fWidth));
318
 
                                }
319
 
                        }
320
 
                }
321
 
                g_free (cIconPath);
322
 
        }
323
 
        else if (CAIRO_DOCK_IS_APPLET (icon))  // c'est l'icone d'une applet.
324
 
        {
325
 
                //g_print ("  icon->cFileName : %s\n", icon->cFileName);
326
 
                icon->pIconBuffer = cairo_dock_create_applet_surface (icon->cFileName,
327
 
                        pSourceContext,
328
 
                        fMaxScale,
329
 
                        (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
330
 
                        (bIsHorizontal ? &icon->fHeight : &icon->fWidth));
331
 
        }
332
 
        else if (CAIRO_DOCK_IS_APPLI (icon))  // c'est l'icone d'une appli valide. Dans cet ordre on n'a pas besoin de verifier que c'est NORMAL_APPLI.
333
 
        {
334
 
                icon->fWidth = myIcons.tIconAuthorizedWidth[CAIRO_DOCK_APPLI];
335
 
                icon->fHeight = myIcons.tIconAuthorizedHeight[CAIRO_DOCK_APPLI];
336
 
                if (myTaskBar.iMinimizedWindowRenderType == 1 && icon->bIsHidden && icon->iBackingPixmap != 0)
337
 
                {
338
 
                        // on cree la miniature.
339
 
                        if (g_bUseOpenGL)
340
 
                        {
341
 
                                icon->iIconTexture = cairo_dock_texture_from_pixmap (icon->Xid, icon->iBackingPixmap);
342
 
                                //g_print ("opengl thumbnail : %d\n", icon->iIconTexture);
343
 
                        }
344
 
                        if (icon->iIconTexture == 0)
345
 
                        {
346
 
                                icon->pIconBuffer = cairo_dock_create_surface_from_xpixmap (icon->iBackingPixmap, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
347
 
                                if (g_bUseOpenGL)
348
 
                                        icon->iIconTexture = cairo_dock_create_texture_from_surface (icon->pIconBuffer);
349
 
                        }
350
 
                        // on affiche l'image precedente en embleme.
351
 
                        if (icon->iIconTexture != 0 && iPrevTexture != 0)
352
 
                        {
353
 
                                CairoDock *pParentDock = NULL;  // cairo_dock_search_dock_from_name (icon->cParentDockName);
354
 
                                CairoEmblem *e = cairo_dock_make_emblem_from_texture (iPrevTexture,icon, CAIRO_CONTAINER (pParentDock));
355
 
                                cairo_dock_set_emblem_position (e, CAIRO_DOCK_EMBLEM_LOWER_LEFT);
356
 
                                cairo_dock_draw_emblem_on_icon (e, icon, CAIRO_CONTAINER (pParentDock));
357
 
                                g_free (e);  // on n'utilise pas cairo_dock_free_emblem pour ne pas detruire la texture avec.
358
 
                        }
359
 
                        else if (icon->pIconBuffer != NULL && pPrevSurface != NULL)
360
 
                        {
361
 
                                CairoDock *pParentDock = NULL;  // cairo_dock_search_dock_from_name (icon->cParentDockName);
362
 
                                CairoEmblem *e = cairo_dock_make_emblem_from_surface (pPrevSurface, 0, 0, icon, CAIRO_CONTAINER (pParentDock));
363
 
                                cairo_dock_set_emblem_position (e, CAIRO_DOCK_EMBLEM_LOWER_LEFT);
364
 
                                cairo_dock_draw_emblem_on_icon (e, icon, CAIRO_CONTAINER (pParentDock));
365
 
                                g_free (e);  // meme remarque.
366
 
                        }
367
 
                }
368
 
                if (icon->pIconBuffer == NULL && myTaskBar.bOverWriteXIcons && ! cairo_dock_class_is_using_xicon (icon->cClass))
369
 
                        icon->pIconBuffer = cairo_dock_create_surface_from_class (icon->cClass, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
370
 
                if (icon->pIconBuffer == NULL)
371
 
                        icon->pIconBuffer = cairo_dock_create_surface_from_xwindow (icon->Xid, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
372
 
                if (icon->pIconBuffer == NULL)  // certaines applis comme xterm ne definissent pas d'icone, on en met une par defaut.
373
 
                {
374
 
                        g_print ("%s (%ld) doesn't define any icon, we set the default one.\n", icon->cName, icon->Xid);
375
 
                        gchar *cIconPath = cairo_dock_generate_file_path (CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME);
376
 
                        if (cIconPath == NULL || ! g_file_test (cIconPath, G_FILE_TEST_EXISTS))
377
 
                        {
378
 
                                g_free (cIconPath);
379
 
                                cIconPath = g_strdup (CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_DEFAULT_APPLI_ICON_NAME);
380
 
                        }
381
 
                        icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
382
 
                                pSourceContext,
383
 
                                fMaxScale,
384
 
                                myIcons.tIconAuthorizedWidth[CAIRO_DOCK_APPLI],
385
 
                                myIcons.tIconAuthorizedHeight[CAIRO_DOCK_APPLI],
386
 
                                CAIRO_DOCK_FILL_SPACE,
387
 
                                (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
388
 
                                (bIsHorizontal ? &icon->fHeight : &icon->fWidth),
389
 
                                NULL, NULL);
390
 
                        g_free (cIconPath);
391
 
                }
392
 
        }
393
 
        else  // c'est une icone de separation.
394
 
        {
395
 
                if (CAIRO_DOCK_IS_USER_SEPARATOR (icon) && icon->cFileName != NULL)
396
 
                {
397
 
                        /// A FAIRE : verifier qu'on peut enlever le test sur fMaxScale ...
398
 
                        if (icon->fWidth == 0 || fMaxScale != 1.)
399
 
                                icon->fWidth = myIcons.tIconAuthorizedWidth[CAIRO_DOCK_SEPARATOR12];
400
 
                        if (icon->fHeight == 0 || fMaxScale != 1.)
401
 
                                icon->fHeight = myIcons.tIconAuthorizedHeight[CAIRO_DOCK_SEPARATOR12];
402
 
                        gchar *cIconPath = cairo_dock_search_icon_s_path (icon->cFileName);
403
 
                        
404
 
                        if (cIconPath != NULL && *cIconPath != '\0')
405
 
                        {
406
 
                                icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
407
 
                                        pSourceContext,
408
 
                                        fMaxScale,
409
 
                                        icon->fWidth,
410
 
                                        icon->fHeight,
411
 
                                        CAIRO_DOCK_FILL_SPACE,
412
 
                                        (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
413
 
                                        (bIsHorizontal ? &icon->fHeight : &icon->fWidth),
414
 
                                        NULL, NULL);
415
 
                        }
416
 
                        g_free (cIconPath);
417
 
                }
418
 
                else
419
 
                {
420
 
                        icon->pIconBuffer = cairo_dock_create_separator_surface (pSourceContext, fMaxScale, bIsHorizontal, bDirectionUp, &icon->fWidth, &icon->fHeight);
421
 
                }
422
 
        }
423
 
 
424
 
        if (icon->pIconBuffer == NULL)
425
 
        {
426
 
                gchar *cIconPath = cairo_dock_generate_file_path (CAIRO_DOCK_DEFAULT_ICON_NAME);
427
 
                if (cIconPath == NULL || ! g_file_test (cIconPath, G_FILE_TEST_EXISTS))
428
 
                {
429
 
                        g_free (cIconPath);
430
 
                        cIconPath = g_strdup (CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_DEFAULT_ICON_NAME);
431
 
                }
432
 
                CairoDockIconType iType = cairo_dock_get_icon_type  (icon);
433
 
                /// A FAIRE : verifier qu'on peut enlever le test sur fMaxScale ...
434
 
                if (icon->fWidth == 0 || fMaxScale != 1.)
435
 
                        icon->fWidth = myIcons.tIconAuthorizedWidth[iType];
436
 
                if (icon->fHeight == 0 || fMaxScale != 1.)
437
 
                        icon->fHeight = myIcons.tIconAuthorizedHeight[iType];
438
 
                icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
439
 
                        pSourceContext,
440
 
                        fMaxScale,
441
 
                        icon->fWidth,
442
 
                        icon->fHeight,
443
 
                        CAIRO_DOCK_FILL_SPACE,
444
 
                        (bIsHorizontal ? &icon->fWidth : &icon->fHeight),
445
 
                        (bIsHorizontal ? &icon->fHeight : &icon->fWidth),
446
 
                        NULL, NULL);
447
 
                g_free (cIconPath);
448
 
        }
449
 
        cd_debug ("%s (%s) -> %.2fx%.2f", __func__, icon->cName, icon->fWidth, icon->fHeight);
450
 
        
451
 
        //\_____________ On met le background de l'icone si necessaire
452
 
        if (icon->pIconBuffer != NULL &&
453
 
                g_pIconBackgroundBuffer.pSurface != NULL &&
454
 
                (! CAIRO_DOCK_IS_SEPARATOR (icon)/* && (myIcons.bBgForApplets || ! CAIRO_DOCK_IS_APPLET(pIcon))*/))
455
 
        {
456
 
                cairo_t *pCairoIconBGContext = cairo_create (icon->pIconBuffer);
457
 
                cairo_scale(pCairoIconBGContext,
458
 
                        icon->fWidth / (g_pIconBackgroundBuffer.iWidth / fMaxScale),
459
 
                        icon->fHeight / (g_pIconBackgroundBuffer.iHeight / fMaxScale));
460
 
                cairo_set_source_surface (pCairoIconBGContext,
461
 
                        g_pIconBackgroundBuffer.pSurface,
462
 
                        0.,
463
 
                        0.);
464
 
                cairo_set_operator (pCairoIconBGContext, CAIRO_OPERATOR_DEST_OVER);
465
 
                cairo_paint (pCairoIconBGContext);
466
 
                cairo_destroy (pCairoIconBGContext);
467
 
        }
468
 
 
469
 
        if (! g_bUseOpenGL && myIcons.fAlbedo > 0 && icon->pIconBuffer != NULL && ! (CAIRO_DOCK_IS_APPLET (icon) && icon->cFileName == NULL))
470
 
        {
471
 
                icon->pReflectionBuffer = cairo_dock_create_reflection_surface (icon->pIconBuffer,
472
 
                        pSourceContext,
473
 
                        (bIsHorizontal ? icon->fWidth : icon->fHeight) * fMaxScale,
474
 
                        (bIsHorizontal ? icon->fHeight : icon->fWidth) * fMaxScale,
475
 
                        myIcons.fReflectSize * fMaxScale,
476
 
                        myIcons.fAlbedo,
477
 
                        bIsHorizontal,
478
 
                        bDirectionUp);
479
 
        }
480
 
        
481
 
        if (g_bUseOpenGL && icon->pIconBuffer != NULL && icon->iIconTexture == 0)
482
 
        {
483
 
                icon->iIconTexture = cairo_dock_create_texture_from_surface (icon->pIconBuffer);
484
 
        }
485
 
        if (iPrevTexture != 0)
486
 
                _cairo_dock_delete_texture (iPrevTexture);
487
 
        if (pPrevSurface != NULL)
488
 
                cairo_surface_destroy (pPrevSurface);
489
 
}
490
 
 
491
 
 
492
 
gchar *cairo_dock_cut_string (const gchar *cString, int iNbCaracters)  // gere l'UTF-8
493
 
{
494
 
        g_return_val_if_fail (cString != NULL, NULL);
495
 
        gchar *cTruncatedName = NULL;
496
 
        gsize bytes_read, bytes_written;
497
 
        GError *erreur = NULL;
498
 
        gchar *cUtf8Name = g_locale_to_utf8 (cString,
499
 
                -1,
500
 
                &bytes_read,
501
 
                &bytes_written,
502
 
                &erreur);  // inutile sur Ubuntu, qui est nativement UTF8, mais sur les autres on ne sait pas.
503
 
        if (erreur != NULL)
504
 
        {
505
 
                cd_warning (erreur->message);
506
 
                g_error_free (erreur);
507
 
                erreur = NULL;
508
 
        }
509
 
        if (cUtf8Name == NULL)  // une erreur s'est produite, on tente avec la chaine brute.
510
 
                cUtf8Name = g_strdup (cString);
511
 
        
512
 
        const gchar *cEndValidChain = NULL;
513
 
        int iStringLength;
514
 
        if (g_utf8_validate (cUtf8Name, -1, &cEndValidChain))
515
 
        {
516
 
                iStringLength = g_utf8_strlen (cUtf8Name, -1);
517
 
                int iNbChars = -1;
518
 
                if (iNbCaracters < 0)
519
 
                {
520
 
                        iNbChars = MAX (0, iStringLength + iNbCaracters);
521
 
                }
522
 
                else if (iStringLength > iNbCaracters)
523
 
                {
524
 
                        iNbChars = iNbCaracters;
525
 
                }
526
 
                
527
 
                if (iNbChars != -1)
528
 
                {
529
 
                        cTruncatedName = g_new0 (gchar, 8 * (iNbChars + 4));  // 8 octets par caractere.
530
 
                        if (iNbChars != 0)
531
 
                                g_utf8_strncpy (cTruncatedName, cUtf8Name, iNbChars);
532
 
                        
533
 
                        gchar *cTruncature = g_utf8_offset_to_pointer (cTruncatedName, iNbChars);
534
 
                        *cTruncature = '.';
535
 
                        *(cTruncature+1) = '.';
536
 
                        *(cTruncature+2) = '.';
537
 
                }
538
 
        }
539
 
        else
540
 
        {
541
 
                iStringLength = strlen (cString);
542
 
                int iNbChars = -1;
543
 
                if (iNbCaracters < 0)
544
 
                {
545
 
                        iNbChars = MAX (0, iStringLength + iNbCaracters);
546
 
                }
547
 
                else if (iStringLength > iNbCaracters)
548
 
                {
549
 
                        iNbChars = iNbCaracters;
550
 
                }
551
 
                
552
 
                if (iNbChars != -1)
553
 
                {
554
 
                        cTruncatedName = g_new0 (gchar, iNbCaracters + 4);
555
 
                        if (iNbChars != 0)
556
 
                                strncpy (cTruncatedName, cString, iNbChars);
557
 
                        
558
 
                        cTruncatedName[iNbChars] = '.';
559
 
                        cTruncatedName[iNbChars+1] = '.';
560
 
                        cTruncatedName[iNbChars+2] = '.';
561
 
                }
562
 
        }
563
 
        if (cTruncatedName == NULL)
564
 
                cTruncatedName = cUtf8Name;
565
 
        else
566
 
                g_free (cUtf8Name);
567
 
        //g_print (" -> etiquette : %s\n", cTruncatedName);
568
 
        return cTruncatedName;
569
 
}
570
 
 
571
 
void cairo_dock_fill_one_text_buffer (Icon *icon, cairo_t* pSourceContext, CairoDockLabelDescription *pTextDescription)
572
 
{
573
 
        //g_print ("%s (%s, %d)\n", __func__, cLabelPolice, iLabelSize);
574
 
        cairo_surface_destroy (icon->pTextBuffer);
575
 
        icon->pTextBuffer = NULL;
576
 
        if (icon->iLabelTexture != 0)
577
 
        {
578
 
                _cairo_dock_delete_texture (icon->iLabelTexture);
579
 
                icon->iLabelTexture = 0;
580
 
        }
581
 
        if (icon->cName == NULL || (pTextDescription->iSize == 0))
582
 
                return ;
583
 
 
584
 
        gchar *cTruncatedName = NULL;
585
 
        if (CAIRO_DOCK_IS_APPLI (icon) && myTaskBar.iAppliMaxNameLength > 0)
586
 
        {
587
 
                cTruncatedName = cairo_dock_cut_string (icon->cName, myTaskBar.iAppliMaxNameLength);
588
 
        }
589
 
        
590
 
        double fTextXOffset, fTextYOffset;
591
 
        cairo_surface_t* pNewSurface = cairo_dock_create_surface_from_text ((cTruncatedName != NULL ? cTruncatedName : icon->cName),
592
 
                pSourceContext,
593
 
                pTextDescription,
594
 
                &icon->iTextWidth, &icon->iTextHeight);
595
 
        g_free (cTruncatedName);
596
 
        //g_print (" -> %s : (%.2f;%.2f) %dx%d\n", icon->cName, icon->fTextXOffset, icon->fTextYOffset, icon->iTextWidth, icon->iTextHeight);
597
 
 
598
 
        icon->pTextBuffer = pNewSurface;
599
 
        
600
 
        if (g_bUseOpenGL && icon->pTextBuffer != NULL)
601
 
        {
602
 
                icon->iLabelTexture = cairo_dock_create_texture_from_surface (icon->pTextBuffer);
603
 
        }
604
 
}
605
 
 
606
 
void cairo_dock_fill_one_quick_info_buffer (Icon *icon, cairo_t* pSourceContext, CairoDockLabelDescription *pTextDescription, double fMaxScale)
607
 
{
608
 
        cairo_surface_destroy (icon->pQuickInfoBuffer);
609
 
        icon->pQuickInfoBuffer = NULL;
610
 
        if (icon->iQuickInfoTexture != 0)
611
 
        {
612
 
                _cairo_dock_delete_texture (icon->iQuickInfoTexture);
613
 
                icon->iQuickInfoTexture = 0;
614
 
        }
615
 
        if (icon->cQuickInfo == NULL)
616
 
                return ;
617
 
 
618
 
        double fQuickInfoXOffset, fQuickInfoYOffset;
619
 
        icon->pQuickInfoBuffer = cairo_dock_create_surface_from_text_full (icon->cQuickInfo,
620
 
                pSourceContext,
621
 
                pTextDescription,
622
 
                fMaxScale,
623
 
                icon->fWidth * fMaxScale,
624
 
                &icon->iQuickInfoWidth, &icon->iQuickInfoHeight, NULL, NULL);
625
 
        
626
 
        if (g_bUseOpenGL && icon->pQuickInfoBuffer != NULL)
627
 
        {
628
 
                icon->iQuickInfoTexture = cairo_dock_create_texture_from_surface (icon->pQuickInfoBuffer);
629
 
        }
630
 
}
631
 
 
632
 
 
633
 
 
634
 
void cairo_dock_fill_icon_buffers (Icon *icon, cairo_t *pSourceContext, double fMaxScale, gboolean bIsHorizontal, gboolean bDirectionUp)
635
 
{
636
 
        cairo_dock_fill_one_icon_buffer (icon, pSourceContext, fMaxScale, bIsHorizontal, bDirectionUp);
637
 
 
638
 
        cairo_dock_fill_one_text_buffer (icon, pSourceContext, &myLabels.iconTextDescription);
639
 
 
640
 
        cairo_dock_fill_one_quick_info_buffer (icon, pSourceContext, &myLabels.quickInfoTextDescription, fMaxScale);
641
 
}
642
 
 
643
 
void cairo_dock_load_one_icon_from_scratch (Icon *pIcon, CairoContainer *pContainer)
644
 
{
645
 
        g_return_if_fail (pIcon != NULL);
646
 
        cairo_t *pCairoContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (pContainer));
647
 
        if (CAIRO_DOCK_IS_DOCK (pContainer))
648
 
        {
649
 
                CairoDock *pDock = CAIRO_DOCK (pContainer);
650
 
                cairo_dock_fill_icon_buffers_for_dock (pIcon, pCairoContext, pDock);
651
 
        }
652
 
        else
653
 
        {
654
 
                cairo_dock_fill_icon_buffers_for_desklet (pIcon, pCairoContext);
655
 
        }
656
 
        cairo_destroy (pCairoContext);
657
 
}
658
 
 
659
 
void cairo_dock_reload_buffers_in_dock (gchar *cDockName, CairoDock *pDock, gpointer data)
660
 
{
661
 
        gboolean bReloadAppletsToo = GPOINTER_TO_INT (data);
662
 
        cd_message ("%s (%s, %d)", __func__, cDockName, bReloadAppletsToo);
663
 
 
664
 
        double fFlatDockWidth = - myIcons.iIconGap;
665
 
        pDock->iMaxIconHeight = 0;
666
 
 
667
 
        cairo_t *pCairoContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (pDock));
668
 
 
669
 
        Icon* icon;
670
 
        GList* ic;
671
 
        for (ic = pDock->icons; ic != NULL; ic = ic->next)
672
 
        {
673
 
                icon = ic->data;
674
 
                
675
 
                if (CAIRO_DOCK_IS_APPLET (icon))
676
 
                {
677
 
                        if (bReloadAppletsToo)  /// modif du 23/05/2009 : utiliser la taille avec ratio ici. les applets doivent faire attention a utiliser la fonction get_icon_extent().
678
 
                                cairo_dock_reload_module_instance (icon->pModuleInstance, FALSE);
679
 
                }
680
 
                else
681
 
                {
682
 
                        icon->fWidth /= pDock->container.fRatio;
683
 
                        icon->fHeight /= pDock->container.fRatio;
684
 
                        cairo_dock_fill_icon_buffers_for_dock (icon, pCairoContext, pDock);
685
 
                        icon->fWidth *= pDock->container.fRatio;
686
 
                        icon->fHeight *= pDock->container.fRatio;
687
 
                }
688
 
                
689
 
                //g_print (" =size <- %.2fx%.2f\n", icon->fWidth, icon->fHeight);
690
 
                fFlatDockWidth += myIcons.iIconGap + icon->fWidth;
691
 
                pDock->iMaxIconHeight = MAX (pDock->iMaxIconHeight, icon->fHeight);
692
 
        }
693
 
        pDock->fFlatDockWidth = (int) fFlatDockWidth;  /// (int) n'est plus tellement necessaire ...
694
 
        cairo_destroy (pCairoContext);
695
 
}
696
 
 
697
 
void cairo_dock_reload_one_icon_buffer_in_dock (Icon *icon, CairoDock *pDock)
698
 
{
699
 
        cairo_t *pCairoContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (pDock));
700
 
        cairo_dock_reload_one_icon_buffer_in_dock_full (icon, pDock, pCairoContext);
701
 
        cairo_destroy (pCairoContext);
702
 
}
703
 
 
704
 
 
705
 
  ///////////////////////
706
 
 /// DOCK BACKGROUND ///
707
 
///////////////////////
708
 
 
709
 
void cairo_dock_load_visible_zone (CairoDock *pDock, gchar *cVisibleZoneImageFile, int iVisibleZoneWidth, int iVisibleZoneHeight, double fVisibleZoneAlpha)
710
 
{
711
 
        cairo_dock_unload_image_buffer (&g_pVisibleZoneBuffer);
712
 
        
713
 
        cairo_dock_load_image_buffer (&g_pVisibleZoneBuffer,
714
 
                cVisibleZoneImageFile,
715
 
                iVisibleZoneWidth,
716
 
                iVisibleZoneHeight,
717
 
                CAIRO_DOCK_FILL_SPACE);
718
 
}
719
 
 
720
 
 
721
 
static cairo_surface_t *_cairo_dock_make_stripes_background (cairo_t* pSourceContext, int iStripesWidth, int iStripesHeight)
722
 
{
723
 
        g_return_val_if_fail (cairo_status (pSourceContext) == CAIRO_STATUS_SUCCESS, NULL);
724
 
        cairo_pattern_t *pStripesPattern;
725
 
        double fWidth = (myBackground.iNbStripes > 0 ? 200. : iStripesWidth);
726
 
        if (fabs (myBackground.fStripesAngle) != 90)
727
 
                pStripesPattern = cairo_pattern_create_linear (0.0f,
728
 
                        0.0f,
729
 
                        fWidth,
730
 
                        fWidth * tan (myBackground.fStripesAngle * G_PI/180.));
731
 
        else
732
 
                pStripesPattern = cairo_pattern_create_linear (0.0f,
733
 
                        0.0f,
734
 
                        0.,
735
 
                        (myBackground.fStripesAngle == 90) ? iStripesHeight : - iStripesHeight);
736
 
        g_return_val_if_fail (cairo_pattern_status (pStripesPattern) == CAIRO_STATUS_SUCCESS, NULL);
737
 
 
738
 
        cairo_pattern_set_extend (pStripesPattern, CAIRO_EXTEND_REPEAT);
739
 
 
740
 
        if (myBackground.iNbStripes > 0)
741
 
        {
742
 
                gdouble fStep;
743
 
                double fStripesGap = 1. / (myBackground.iNbStripes);  // ecart entre 2 rayures foncees.
744
 
                for (fStep = 0.0f; fStep < 1.0f; fStep += fStripesGap)
745
 
                {
746
 
                        cairo_pattern_add_color_stop_rgba (pStripesPattern,
747
 
                                fStep - myBackground.fStripesWidth / 2,
748
 
                                myBackground.fStripesColorBright[0],
749
 
                                myBackground.fStripesColorBright[1],
750
 
                                myBackground.fStripesColorBright[2],
751
 
                                myBackground.fStripesColorBright[3]);
752
 
                        cairo_pattern_add_color_stop_rgba (pStripesPattern,
753
 
                                fStep,
754
 
                                myBackground.fStripesColorDark[0],
755
 
                                myBackground.fStripesColorDark[1],
756
 
                                myBackground.fStripesColorDark[2],
757
 
                                myBackground.fStripesColorDark[3]);
758
 
                        cairo_pattern_add_color_stop_rgba (pStripesPattern,
759
 
                                fStep + myBackground.fStripesWidth / 2,
760
 
                                myBackground.fStripesColorBright[0],
761
 
                                myBackground.fStripesColorBright[1],
762
 
                                myBackground.fStripesColorBright[2],
763
 
                                myBackground.fStripesColorBright[3]);
764
 
                }
765
 
        }
766
 
        else
767
 
        {
768
 
                cairo_pattern_add_color_stop_rgba (pStripesPattern,
769
 
                        0.,
770
 
                        myBackground.fStripesColorDark[0],
771
 
                        myBackground.fStripesColorDark[1],
772
 
                        myBackground.fStripesColorDark[2],
773
 
                        myBackground.fStripesColorDark[3]);
774
 
                cairo_pattern_add_color_stop_rgba (pStripesPattern,
775
 
                        1.,
776
 
                        myBackground.fStripesColorBright[0],
777
 
                        myBackground.fStripesColorBright[1],
778
 
                        myBackground.fStripesColorBright[2],
779
 
                        myBackground.fStripesColorBright[3]);
780
 
        }
781
 
 
782
 
        cairo_surface_t *pNewSurface = _cairo_dock_create_blank_surface (pSourceContext,
783
 
                iStripesWidth,
784
 
                iStripesHeight);
785
 
        cairo_t *pImageContext = cairo_create (pNewSurface);
786
 
        cairo_set_source (pImageContext, pStripesPattern);
787
 
        cairo_paint (pImageContext);
788
 
 
789
 
        cairo_pattern_destroy (pStripesPattern);
790
 
        cairo_destroy (pImageContext);
791
 
        
792
 
        return pNewSurface;
793
 
}
794
 
void cairo_dock_update_background_decorations_if_necessary (CairoDock *pDock, int iNewDecorationsWidth, int iNewDecorationsHeight)
795
 
{
796
 
        //g_print ("%s (%dx%d) [%.2fx%.2f]\n", __func__, iNewDecorationsWidth, iNewDecorationsHeight, g_fBackgroundImageWidth, g_fBackgroundImageHeight);
797
 
        int k = (myBackground.fDecorationSpeed || myBackground.bDecorationsFollowMouse ? 2 : 1);
798
 
        if (k * iNewDecorationsWidth > g_pDockBackgroundBuffer.iWidth || iNewDecorationsHeight > g_pDockBackgroundBuffer.iHeight)
799
 
        {
800
 
                cairo_dock_unload_image_buffer (&g_pDockBackgroundBuffer);
801
 
                cairo_t *pCairoContext = _get_source_context ();
802
 
                int iWidth, iHeight;
803
 
                if (myBackground.cBackgroundImageFile != NULL)
804
 
                {
805
 
                        if (myBackground.bBackgroundImageRepeat)
806
 
                        {
807
 
                                iWidth = MAX (g_pDockBackgroundBuffer.iWidth, k * iNewDecorationsWidth);
808
 
                                iHeight = MAX (g_pDockBackgroundBuffer.iHeight, iNewDecorationsHeight);
809
 
                                cairo_surface_t *pBgSurface = cairo_dock_create_surface_from_pattern (myBackground.cBackgroundImageFile,
810
 
                                        pCairoContext,
811
 
                                        iWidth,
812
 
                                        iHeight,
813
 
                                        myBackground.fBackgroundImageAlpha);
814
 
                                cairo_dock_load_image_buffer_from_surface (&g_pDockBackgroundBuffer,
815
 
                                        pBgSurface,
816
 
                                        iWidth,
817
 
                                        iHeight);
818
 
                        }
819
 
                        else
820
 
                        {
821
 
                                iWidth = MAX (g_pDockBackgroundBuffer.iWidth, iNewDecorationsWidth);
822
 
                                iHeight = MAX (g_pDockBackgroundBuffer.iHeight, iNewDecorationsHeight);
823
 
                                cairo_dock_load_image_buffer_full (&g_pDockBackgroundBuffer,
824
 
                                        myBackground.cBackgroundImageFile,
825
 
                                        iWidth,
826
 
                                        iHeight,
827
 
                                        CAIRO_DOCK_FILL_SPACE,
828
 
                                        myBackground.fBackgroundImageAlpha);
829
 
                        }
830
 
                }
831
 
                else
832
 
                {
833
 
                        iWidth = MAX (g_pDockBackgroundBuffer.iWidth, k * iNewDecorationsWidth);
834
 
                        iHeight = MAX (g_pDockBackgroundBuffer.iHeight, iNewDecorationsHeight);
835
 
                        cairo_surface_t *pBgSurface = _cairo_dock_make_stripes_background (pCairoContext,
836
 
                                iWidth,
837
 
                                iHeight);
838
 
                        cairo_dock_load_image_buffer_from_surface (&g_pDockBackgroundBuffer,
839
 
                                pBgSurface,
840
 
                                iWidth,
841
 
                                iHeight);
842
 
                }
843
 
                //cd_debug ("  MaJ des decorations du fond -> %dx%d", iWidth, iHeight);
844
 
        }
845
 
}
846
 
 
847
 
void cairo_dock_load_background_decorations (CairoDock *pDock)
848
 
{
849
 
        int iWidth, iHeight;
850
 
        cairo_dock_search_max_decorations_size (&iWidth, &iHeight);
851
 
        
852
 
        g_pDockBackgroundBuffer.iWidth = 0;
853
 
        g_pDockBackgroundBuffer.iHeight = 0;
854
 
        cairo_dock_update_background_decorations_if_necessary (pDock, iWidth, iHeight);
855
 
}
856
 
 
857
 
 
858
 
void cairo_dock_load_icons_background_surface (const gchar *cImagePath, double fMaxScale)
859
 
{
860
 
        cairo_dock_unload_image_buffer (&g_pIconBackgroundBuffer);
861
 
        
862
 
        int iSize = MAX (myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER], myIcons.tIconAuthorizedWidth[CAIRO_DOCK_APPLI]);
863
 
        if (iSize == 0)
864
 
                iSize = 48;
865
 
        iSize *= fMaxScale;
866
 
        cairo_dock_load_image_buffer (&g_pIconBackgroundBuffer,
867
 
                cImagePath,
868
 
                iSize,
869
 
                iSize,
870
 
                CAIRO_DOCK_FILL_SPACE);
871
 
}
872
 
 
873
 
 
874
 
void cairo_dock_load_box_surface (double fMaxScale)
875
 
{
876
 
        /*cairo_dock_unload_image_buffer (&g_pBoxAboveBuffer);
877
 
        cairo_dock_unload_image_buffer (&g_pBoxBelowBuffer);
878
 
        
879
 
        int iSize = myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER];
880
 
        if (iSize == 0)
881
 
                iSize = 48;
882
 
        iSize *= fMaxScale;
883
 
        cairo_dock_load_image_buffer (&g_pBoxAboveBuffer,
884
 
                CAIRO_DOCK_SHARE_DATA_DIR"/box-front.png",
885
 
                iSize,
886
 
                iSize,
887
 
                CAIRO_DOCK_FILL_SPACE);
888
 
        cairo_dock_load_image_buffer (&g_pBoxBelowBuffer,
889
 
                CAIRO_DOCK_SHARE_DATA_DIR"/box-back.png",
890
 
                iSize,
891
 
                iSize,
892
 
                CAIRO_DOCK_FILL_SPACE);*/  // 2.1.4
893
 
}
894
 
 
895
 
 
896
 
 
897
 
  //////////////////
898
 
 /// DESKTOP BG ///
899
 
//////////////////
900
 
 
901
 
static cairo_surface_t *_cairo_dock_create_surface_from_desktop_bg (void)  // attention : fonction lourde.
902
 
{
903
 
        cd_debug ("%s ()", __func__);
904
 
        Pixmap iRootPixmapID = cairo_dock_get_window_background_pixmap (cairo_dock_get_root_id ());
905
 
        g_return_val_if_fail (iRootPixmapID != 0, NULL);
906
 
        
907
 
        cairo_surface_t *pDesktopBgSurface = NULL;
908
 
        GdkPixbuf *pBgPixbuf = cairo_dock_get_pixbuf_from_pixmap (iRootPixmapID, FALSE);  // FALSE <=> on n'y ajoute pas de transparence.
909
 
        if (pBgPixbuf != NULL)
910
 
        {
911
 
                cairo_t *pSourceContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (g_pMainDock));
912
 
                
913
 
                if (gdk_pixbuf_get_height (pBgPixbuf) == 1 && gdk_pixbuf_get_width (pBgPixbuf) == 1)  // couleur unie.
914
 
                {
915
 
                        guchar *pixels = gdk_pixbuf_get_pixels (pBgPixbuf);
916
 
                        cd_debug ("c'est une couleur unie (%.2f, %.2f, %.2f)", (double) pixels[0] / 255, (double) pixels[1] / 255, (double) pixels[2] / 255);
917
 
                        
918
 
                        pDesktopBgSurface = _cairo_dock_create_blank_surface (pSourceContext,
919
 
                                g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL],
920
 
                                g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
921
 
                        
922
 
                        cairo_t *pCairoContext = cairo_create (pDesktopBgSurface);
923
 
                        cairo_set_source_rgb (pCairoContext,
924
 
                                (double) pixels[0] / 255,
925
 
                                (double) pixels[1] / 255,
926
 
                                (double) pixels[2] / 255);
927
 
                        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
928
 
                        cairo_paint (pCairoContext);
929
 
                        cairo_destroy (pCairoContext);
930
 
                }
931
 
                else
932
 
                {
933
 
                        cairo_t *pSourceContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (g_pMainDock));
934
 
                        double fWidth, fHeight;
935
 
                        cairo_surface_t *pBgSurface = cairo_dock_create_surface_from_pixbuf (pBgPixbuf,
936
 
                                pSourceContext,
937
 
                                1,
938
 
                                0,
939
 
                                0,
940
 
                                FALSE,
941
 
                                &fWidth,
942
 
                                &fHeight,
943
 
                                NULL, NULL);
944
 
                        
945
 
                        if (fWidth < g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] || fHeight < g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL])
946
 
                        {
947
 
                                cd_debug ("c'est un degrade ou un motif (%dx%d)", (int) fWidth, (int) fHeight);
948
 
                                pDesktopBgSurface = _cairo_dock_create_blank_surface (pSourceContext,
949
 
                                        g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL],
950
 
                                        g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
951
 
                                cairo_t *pCairoContext = cairo_create (pDesktopBgSurface);
952
 
                                
953
 
                                cairo_pattern_t *pPattern = cairo_pattern_create_for_surface (pBgSurface);
954
 
                                g_return_val_if_fail (cairo_pattern_status (pPattern) == CAIRO_STATUS_SUCCESS, NULL);
955
 
                                cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_REPEAT);
956
 
                                
957
 
                                cairo_set_source (pCairoContext, pPattern);
958
 
                                cairo_paint (pCairoContext);
959
 
                                
960
 
                                cairo_destroy (pCairoContext);
961
 
                                cairo_pattern_destroy (pPattern);
962
 
                                cairo_surface_destroy (pBgSurface);
963
 
                        }
964
 
                        else
965
 
                        {
966
 
                                cd_debug ("c'est un fond d'ecran de taille %dx%d", (int) fWidth, (int) fHeight);
967
 
                                pDesktopBgSurface = pBgSurface;
968
 
                        }
969
 
                }
970
 
                
971
 
                g_object_unref (pBgPixbuf);
972
 
                cairo_destroy (pSourceContext);
973
 
        }
974
 
        return pDesktopBgSurface;
975
 
}
976
 
 
977
 
CairoDockDesktopBackground *cairo_dock_get_desktop_background (gboolean bWithTextureToo)
978
 
{
979
 
        cd_message ("%s (%d, %d)", __func__, bWithTextureToo, s_pDesktopBg?s_pDesktopBg->iRefCount:-1);
980
 
        if (s_pDesktopBg == NULL)
981
 
        {
982
 
                s_pDesktopBg = g_new0 (CairoDockDesktopBackground, 1);
983
 
        }
984
 
        if (s_pDesktopBg->iRefCount == 0)
985
 
        {
986
 
                s_pDesktopBg->pSurface = _cairo_dock_create_surface_from_desktop_bg ();
987
 
        }
988
 
        if (s_pDesktopBg->iTexture == 0 && bWithTextureToo)
989
 
        {
990
 
                s_pDesktopBg->iTexture = cairo_dock_create_texture_from_surface (s_pDesktopBg->pSurface);
991
 
        }
992
 
        
993
 
        s_pDesktopBg->iRefCount ++;
994
 
        if (s_pDesktopBg->iSidDestroyBg != 0)
995
 
        {
996
 
                g_source_remove (s_pDesktopBg->iSidDestroyBg);
997
 
                s_pDesktopBg->iSidDestroyBg = 0;
998
 
        }
999
 
        return s_pDesktopBg;
1000
 
}
1001
 
 
1002
 
static gboolean _destroy_bg (CairoDockDesktopBackground *pDesktopBg)
1003
 
{
1004
 
        cd_message ("%s ()", __func__);
1005
 
        g_return_val_if_fail (pDesktopBg != NULL, 0);
1006
 
        if (pDesktopBg->pSurface != NULL)
1007
 
        {
1008
 
                cairo_surface_destroy (pDesktopBg->pSurface);
1009
 
                pDesktopBg->pSurface = NULL;
1010
 
        }
1011
 
        if (pDesktopBg->iTexture != 0)
1012
 
        {
1013
 
                _cairo_dock_delete_texture (pDesktopBg->iTexture);
1014
 
                pDesktopBg->iTexture = 0;
1015
 
        }
1016
 
        pDesktopBg->iSidDestroyBg = 0;
1017
 
        return FALSE;
1018
 
}
1019
 
void cairo_dock_destroy_desktop_background (CairoDockDesktopBackground *pDesktopBg)
1020
 
{
1021
 
        g_return_if_fail (pDesktopBg != NULL);
1022
 
        pDesktopBg->iRefCount --;
1023
 
        if (pDesktopBg->iRefCount == 0 && pDesktopBg->iSidDestroyBg == 0)
1024
 
        {
1025
 
                pDesktopBg->iSidDestroyBg = g_timeout_add_seconds (3, (GSourceFunc)_destroy_bg, pDesktopBg);
1026
 
        }
1027
 
}
1028
 
 
1029
 
cairo_surface_t *cairo_dock_get_desktop_bg_surface (CairoDockDesktopBackground *pDesktopBg)
1030
 
{
1031
 
        g_return_val_if_fail (pDesktopBg != NULL, NULL);
1032
 
        return pDesktopBg->pSurface;
1033
 
}
1034
 
 
1035
 
GLuint cairo_dock_get_desktop_bg_texture (CairoDockDesktopBackground *pDesktopBg)
1036
 
{
1037
 
        g_return_val_if_fail (pDesktopBg != NULL, 0);
1038
 
        return pDesktopBg->iTexture;
1039
 
}
1040
 
 
1041
 
void cairo_dock_reload_desktop_background (void)
1042
 
{
1043
 
        cd_message ("%s ()", __func__);
1044
 
        if (s_pDesktopBg == NULL)  // rien a recharger.
1045
 
                return ;
1046
 
        if (s_pDesktopBg->pSurface == NULL && s_pDesktopBg->iTexture == 0)  // rien a recharger.
1047
 
                return ;
1048
 
        
1049
 
        if (s_pDesktopBg->pSurface != NULL)
1050
 
                cairo_surface_destroy (s_pDesktopBg->pSurface);
1051
 
        s_pDesktopBg->pSurface = _cairo_dock_create_surface_from_desktop_bg ();
1052
 
        
1053
 
        if (s_pDesktopBg->iTexture != 0)
1054
 
        {
1055
 
                _cairo_dock_delete_texture (s_pDesktopBg->iTexture);
1056
 
                s_pDesktopBg->iTexture = cairo_dock_create_texture_from_surface (s_pDesktopBg->pSurface);
1057
 
        }
1058
 
}
1059
 
 
1060
 
 
1061
 
  //////////////////
1062
 
 /// INDICATORS ///
1063
 
//////////////////
1064
 
 
1065
 
void cairo_dock_load_task_indicator (const gchar *cIndicatorImagePath, double fMaxScale, double fIndicatorRatio)
1066
 
{
1067
 
        cairo_dock_unload_image_buffer (&g_pIndicatorBuffer);
1068
 
        
1069
 
        double fLauncherWidth = (myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] != 0 ? myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] : 48);
1070
 
        double fLauncherHeight = (myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] != 0 ? myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] : 48);
1071
 
        double fScale = (myIndicators.bLinkIndicatorWithIcon ? fMaxScale : 1.) * fIndicatorRatio;
1072
 
        
1073
 
        cairo_dock_load_image_buffer (&g_pIndicatorBuffer,
1074
 
                cIndicatorImagePath,
1075
 
                fLauncherWidth * fScale,
1076
 
                fLauncherHeight * fScale,
1077
 
                CAIRO_DOCK_KEEP_RATIO);
1078
 
}
1079
 
 
1080
 
void cairo_dock_load_active_window_indicator (const gchar *cImagePath, double fMaxScale, double fCornerRadius, double fLineWidth, double *fActiveColor)
1081
 
{
1082
 
        cairo_dock_unload_image_buffer (&g_pActiveIndicatorBuffer);
1083
 
        
1084
 
        int iWidth = MAX (myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER], myIcons.tIconAuthorizedWidth[CAIRO_DOCK_APPLI]);
1085
 
        int iHeight = MAX (myIcons.tIconAuthorizedHeight[CAIRO_DOCK_APPLI], myIcons.tIconAuthorizedHeight[CAIRO_DOCK_APPLI]);
1086
 
        if (iWidth == 0)
1087
 
                iWidth = 48;
1088
 
        if (iHeight == 0)
1089
 
                iHeight = 48;
1090
 
        iWidth *= fMaxScale;
1091
 
        iHeight *= fMaxScale;
1092
 
        
1093
 
        if (cImagePath != NULL)
1094
 
        {
1095
 
                cairo_dock_load_image_buffer (&g_pActiveIndicatorBuffer,
1096
 
                        cImagePath,
1097
 
                        iWidth,
1098
 
                        iHeight,
1099
 
                        CAIRO_DOCK_FILL_SPACE);
1100
 
        }
1101
 
        else if (fActiveColor[3] > 0)
1102
 
        {
1103
 
                cairo_t *pSourceContext = _get_source_context ();
1104
 
                cairo_surface_t *pSurface = _cairo_dock_create_blank_surface (pSourceContext,
1105
 
                        iWidth,
1106
 
                        iHeight);
1107
 
                cairo_t *pCairoContext = cairo_create (pSurface);
1108
 
                
1109
 
                fCornerRadius = MIN (fCornerRadius, (iWidth - fLineWidth) / 2);
1110
 
                double fFrameWidth = iWidth - (2 * fCornerRadius + fLineWidth);
1111
 
                double fFrameHeight = iHeight - 2 * fLineWidth;
1112
 
                double fDockOffsetX = fCornerRadius + fLineWidth/2;
1113
 
                double fDockOffsetY = fLineWidth/2;
1114
 
                cairo_dock_draw_frame (pCairoContext, fCornerRadius, fLineWidth, fFrameWidth, fFrameHeight, fDockOffsetX, fDockOffsetY, 1, 0., CAIRO_DOCK_HORIZONTAL);
1115
 
                
1116
 
                cairo_set_source_rgba (pCairoContext, fActiveColor[0], fActiveColor[1], fActiveColor[2], fActiveColor[3]);
1117
 
                if (fLineWidth > 0)
1118
 
                {
1119
 
                        cairo_set_line_width (pCairoContext, fLineWidth);
1120
 
                        cairo_stroke (pCairoContext);
1121
 
                }
1122
 
                else
1123
 
                {
1124
 
                        cairo_fill (pCairoContext);
1125
 
                }
1126
 
                cairo_destroy (pCairoContext);
1127
 
                
1128
 
                cairo_dock_load_image_buffer_from_surface (&g_pActiveIndicatorBuffer,
1129
 
                        pSurface,
1130
 
                        iWidth,
1131
 
                        iHeight);
1132
 
        }
1133
 
}
1134
 
 
1135
 
void cairo_dock_load_class_indicator (const gchar *cIndicatorImagePath, double fMaxScale)
1136
 
{
1137
 
        cairo_dock_unload_image_buffer (&g_pClassIndicatorBuffer);
1138
 
        
1139
 
        double fLauncherWidth = (myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] != 0 ? myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] : 48);
1140
 
        double fLauncherHeight = (myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] != 0 ? myIcons.tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] : 48);
1141
 
        
1142
 
        cairo_dock_load_image_buffer (&g_pClassIndicatorBuffer,
1143
 
                cIndicatorImagePath,
1144
 
                fLauncherWidth/3,
1145
 
                fLauncherHeight/3,
1146
 
                CAIRO_DOCK_KEEP_RATIO);
1147
 
}
1148
 
 
1149
 
 
1150
 
void cairo_dock_unload_additionnal_textures (void)
1151
 
{
1152
 
        cd_debug ("");
1153
 
        cairo_dock_unload_image_buffer (&g_pDockBackgroundBuffer);
1154
 
        cairo_dock_unload_image_buffer (&g_pVisibleZoneBuffer);
1155
 
        cairo_dock_unload_image_buffer (&g_pIconBackgroundBuffer);
1156
 
        cairo_dock_unload_image_buffer (&g_pIndicatorBuffer);
1157
 
        cairo_dock_unload_image_buffer (&g_pActiveIndicatorBuffer);
1158
 
        cairo_dock_unload_image_buffer (&g_pClassIndicatorBuffer);
1159
 
        /*cairo_dock_unload_image_buffer (&g_pBoxAboveBuffer);
1160
 
        cairo_dock_unload_image_buffer (&g_pBoxBelowBuffer);*/  // 2.1.4
1161
 
        cairo_dock_unload_desklet_buttons ();
1162
 
        cairo_dock_unload_dialog_buttons ();
1163
 
        if (g_pGradationTexture[0] != 0)
1164
 
        {
1165
 
                _cairo_dock_delete_texture (g_pGradationTexture[0]);
1166
 
                g_pGradationTexture[0] = 0;
1167
 
        }
1168
 
        if (g_pGradationTexture[1] != 0)
1169
 
        {
1170
 
                _cairo_dock_delete_texture (g_pGradationTexture[1]);
1171
 
                g_pGradationTexture[1] = 0;
1172
 
        }
1173
 
        if (s_pDesktopBg != NULL && s_pDesktopBg->iTexture != 0)
1174
 
        {
1175
 
                _cairo_dock_delete_texture (s_pDesktopBg->iTexture);
1176
 
                s_pDesktopBg->iTexture = 0;
1177
 
        }
1178
 
        cairo_dock_destroy_icon_pbuffer ();
1179
 
        cairo_dock_unload_default_data_renderer_font ();
1180
 
        cairo_dock_unload_flying_container_textures ();
1181
 
        _destroy_source_context ();
1182
 
}