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

« back to all changes in this revision

Viewing changes to src/gldit/cairo-dock-icon-loader.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 "../config.h"
 
35
#include "cairo-dock-draw.h"
 
36
#include "cairo-dock-icons.h"
 
37
#include "cairo-dock-surface-factory.h"
 
38
#include "cairo-dock-launcher-manager.h"
 
39
#include "cairo-dock-separator-manager.h"
 
40
#include "cairo-dock-applet-manager.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-icons.h"
 
52
#include "cairo-dock-container.h"
 
53
#include "cairo-dock-desklet-factory.h"
 
54
#include "cairo-dock-dialog-manager.h"
 
55
#include "cairo-dock-data-renderer.h"
 
56
#include "cairo-dock-flying-container.h"
 
57
#include "cairo-dock-emblem.h"
 
58
#include "cairo-dock-X-manager.h"
 
59
#include "cairo-dock-applications-manager.h"
 
60
#include "cairo-dock-load.h"
 
61
#include "cairo-dock-backends-manager.h"
 
62
#include "cairo-dock-icon-loader.h"
 
63
 
 
64
CairoDockImageBuffer g_pIconBackgroundBuffer;
 
65
 
 
66
extern CairoDock *g_pMainDock;
 
67
extern gchar *g_cCurrentThemePath;
 
68
extern gboolean g_bUseOpenGL;
 
69
 
 
70
const gchar *s_cRendererNames[4] = {NULL, "Emblem", "Stack", "Box"};  // c'est juste pour realiser la transition entre le chiffre en conf, et un nom (limitation du panneau de conf). On garde le numero pour savoir rapidement sur laquelle on set.
 
71
 
 
72
  //////////////
 
73
 /// LOADER ///
 
74
//////////////
 
75
 
 
76
gchar *cairo_dock_search_icon_s_path (const gchar *cFileName)
 
77
{
 
78
        g_return_val_if_fail (cFileName != NULL, NULL);
 
79
        
 
80
        //\_______________________ cas faciles : l'entree est deja un chemin.
 
81
        if (*cFileName == '~')
 
82
        {
 
83
                return g_strdup_printf ("%s%s", g_getenv ("HOME"), cFileName+1);
 
84
        }
 
85
        
 
86
        if (*cFileName == '/')
 
87
        {
 
88
                return g_strdup (cFileName);
 
89
        }
 
90
        
 
91
        //\_______________________ On determine si le suffixe et une version sont presents ou non.
 
92
        g_return_val_if_fail (myIcons.pDefaultIconDirectory != NULL, NULL);
 
93
        
 
94
        GString *sIconPath = g_string_new ("");
 
95
        const gchar *cSuffixTab[4] = {".svg", ".png", ".xpm", NULL};
 
96
        gboolean bAddSuffix=FALSE, bFileFound=FALSE, bHasVersion=FALSE;
 
97
        GtkIconInfo* pIconInfo = NULL;
 
98
        int i, j;
 
99
        gchar *str = strrchr (cFileName, '.');
 
100
        bAddSuffix = (str == NULL || ! g_ascii_isalpha (*(str+1)));  // exemple : firefox-3.0
 
101
        bHasVersion = (str != NULL && g_ascii_isdigit (*(str+1)) && g_ascii_isdigit (*(str-1)) && str-1 != cFileName);  // doit finir par x.y, x et y ayant autant de chiffres que l'on veut.
 
102
        
 
103
        //\_______________________ On parcourt les themes disponibles, en testant tous les suffixes connus.
 
104
        for (i = 0; i < myIcons.iNbIconPlaces && ! bFileFound; i ++)
 
105
        {
 
106
                if (myIcons.pDefaultIconDirectory[2*i] != NULL)  // repertoire.
 
107
                {
 
108
                        //g_print ("on recherche %s dans le repertoire %s\n", sIconPath->str, myIcons.pDefaultIconDirectory[2*i]);
 
109
                        j = 0;
 
110
                        while (! bFileFound && (cSuffixTab[j] != NULL || ! bAddSuffix))
 
111
                        {
 
112
                                g_string_printf (sIconPath, "%s/%s", (gchar *)myIcons.pDefaultIconDirectory[2*i], cFileName);
 
113
                                if (bAddSuffix)
 
114
                                        g_string_append_printf (sIconPath, "%s", cSuffixTab[j]);
 
115
                                //g_print ("  -> %s\n", sIconPath->str);
 
116
                                if ( g_file_test (sIconPath->str, G_FILE_TEST_EXISTS) )
 
117
                                        bFileFound = TRUE;
 
118
                                j ++;
 
119
                                if (! bAddSuffix)
 
120
                                        break;
 
121
                        }
 
122
                }
 
123
                else  // theme d'icones.
 
124
                {
 
125
                        g_string_assign (sIconPath, cFileName);
 
126
                        if (! bAddSuffix)  // on vire le suffixe pour chercher tous les formats dans le theme d'icones.
 
127
                        {
 
128
                                gchar *str = strrchr (sIconPath->str, '.');
 
129
                                if (str != NULL)
 
130
                                        *str = '\0';
 
131
                        }
 
132
                        //g_print ("on recherche %s dans le theme d'icones\n", sIconPath->str);
 
133
                        GtkIconTheme *pIconTheme;
 
134
                        if (myIcons.pDefaultIconDirectory[2*i+1] != NULL)
 
135
                                pIconTheme = myIcons.pDefaultIconDirectory[2*i+1];
 
136
                        else
 
137
                                pIconTheme = gtk_icon_theme_get_default ();
 
138
                        pIconInfo = gtk_icon_theme_lookup_icon  (GTK_ICON_THEME (pIconTheme),
 
139
                                sIconPath->str,
 
140
                                128,
 
141
                                GTK_ICON_LOOKUP_FORCE_SVG);
 
142
                        if (pIconInfo != NULL)
 
143
                        {
 
144
                                g_string_assign (sIconPath, gtk_icon_info_get_filename (pIconInfo));
 
145
                                bFileFound = TRUE;
 
146
                                gtk_icon_info_free (pIconInfo);
 
147
                        }
 
148
                }
 
149
        }
 
150
        
 
151
        //\_______________________ si rien trouve, on cherche sans le numero de version.
 
152
        if (! bFileFound && bHasVersion)
 
153
        {
 
154
                cd_debug ("on cherche sans le numero de version...");
 
155
                g_string_assign (sIconPath, cFileName);
 
156
                gchar *str = strrchr (sIconPath->str, '.');
 
157
                str --;  // on sait que c'est un digit.
 
158
                str --;
 
159
                while ((g_ascii_isdigit (*str) || *str == '.' || *str == '-') && (str != sIconPath->str))
 
160
                        str --;
 
161
                if (str != sIconPath->str)
 
162
                {
 
163
                        *(str+1) = '\0';
 
164
                        cd_debug (" on cherche '%s'...\n", sIconPath->str);
 
165
                        gchar *cPath = cairo_dock_search_icon_s_path (sIconPath->str);
 
166
                        if (cPath != NULL)
 
167
                        {
 
168
                                bFileFound = TRUE;
 
169
                                g_string_assign (sIconPath, cPath);
 
170
                                g_free (cPath);
 
171
                        }
 
172
                }
 
173
        }
 
174
        
 
175
        if (! bFileFound)
 
176
        {
 
177
                g_string_free (sIconPath, TRUE);
 
178
                return NULL;
 
179
        }
 
180
        
 
181
        gchar *cIconPath = sIconPath->str;
 
182
        g_string_free (sIconPath, FALSE);
 
183
        return cIconPath;
 
184
}
 
185
 
 
186
static void _set_icon_size_generic (CairoContainer *pContainer, Icon *icon)
 
187
{
 
188
        if (icon->fWidth == 0)
 
189
                icon->fWidth = 48;
 
190
        if (icon->fHeight == 0)
 
191
                icon->fHeight = 48;
 
192
}
 
193
void cairo_dock_set_icon_size (CairoContainer *pContainer, Icon *icon)
 
194
{
 
195
        if (! pContainer)
 
196
        {
 
197
                ///pContainer = CAIRO_CONTAINER (g_pMainDock);
 
198
                g_print ("icone dans aucun container => pas chargee\n");
 
199
                return;
 
200
        }
 
201
        // taille de l'icone dans le container (hors ratio).
 
202
        if (pContainer->iface.set_icon_size)
 
203
                pContainer->iface.set_icon_size (pContainer, icon);
 
204
        else
 
205
                _set_icon_size_generic (pContainer, icon);
 
206
        // la taille que devra avoir la texture s'en deduit.
 
207
        double fMaxScale = cairo_dock_get_max_scale (pContainer);
 
208
        icon->iImageWidth = (pContainer->bIsHorizontal ? icon->fWidth : icon->fHeight) * fMaxScale;
 
209
        icon->iImageHeight = (pContainer->bIsHorizontal ? icon->fHeight : icon->fWidth) * fMaxScale;
 
210
}
 
211
 
 
212
void cairo_dock_load_icon_image (Icon *icon, CairoContainer *pContainer)
 
213
{
 
214
        if (icon->fWidth < 0 || icon->fHeight < 0)  // on ne veut pas de surface.
 
215
        {
 
216
                if (icon->pIconBuffer != NULL)
 
217
                        cairo_surface_destroy (icon->pIconBuffer);
 
218
                icon->pIconBuffer = NULL;
 
219
                if (icon->iIconTexture != 0)
 
220
                        _cairo_dock_delete_texture (icon->iIconTexture);
 
221
                icon->iIconTexture = 0;
 
222
                if (icon->pReflectionBuffer != NULL)
 
223
                        cairo_surface_destroy (icon->pReflectionBuffer);
 
224
                icon->pReflectionBuffer = NULL;
 
225
                return;
 
226
        }
 
227
        
 
228
        if (icon->fWidth == 0 || icon->iImageWidth <= 0)
 
229
        {
 
230
                cairo_dock_set_icon_size (pContainer, icon);
 
231
        }
 
232
        //g_print ("%s (%.2fx%.2f ; %dx%d)\n", __func__, icon->fWidth, icon->fHeight, icon->iImageWidth, icon->iImageHeight);
 
233
        
 
234
        //\______________ on reset les buffers (on garde la surface/texture actuelle pour les emblemes).
 
235
        cairo_surface_t *pPrevSurface = icon->pIconBuffer;
 
236
        GLuint iPrevTexture = icon->iIconTexture;
 
237
        
 
238
        if (icon->pReflectionBuffer != NULL)
 
239
        {
 
240
                cairo_surface_destroy (icon->pReflectionBuffer);
 
241
                icon->pReflectionBuffer = NULL;
 
242
        }
 
243
        
 
244
        //\______________ on charge la surface/texture.
 
245
        if (icon->iface.load_image)
 
246
                icon->iface.load_image (icon);
 
247
        
 
248
        //\______________ Si rien charge, on met une image par defaut.
 
249
        if ((icon->pIconBuffer == pPrevSurface || icon->pIconBuffer == NULL) &&
 
250
                (icon->iIconTexture == iPrevTexture || icon->iIconTexture == 0))
 
251
        {
 
252
                gchar *cIconPath = cairo_dock_generate_file_path (CAIRO_DOCK_DEFAULT_ICON_NAME);
 
253
                if (cIconPath == NULL || ! g_file_test (cIconPath, G_FILE_TEST_EXISTS))
 
254
                {
 
255
                        g_free (cIconPath);
 
256
                        cIconPath = g_strdup (CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_DEFAULT_ICON_NAME);
 
257
                }
 
258
                icon->pIconBuffer = cairo_dock_create_surface_from_image_simple (cIconPath,
 
259
                        icon->iImageWidth,
 
260
                        icon->iImageHeight);
 
261
                g_free (cIconPath);
 
262
        }
 
263
        cd_debug ("%s (%s) -> %.2fx%.2f", __func__, icon->cName, icon->fWidth, icon->fHeight);
 
264
        
 
265
        //\_____________ On met le background de l'icone si necessaire
 
266
        if (icon->pIconBuffer != NULL && g_pIconBackgroundBuffer.pSurface != NULL && ! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (icon))
 
267
        {
 
268
                cairo_t *pCairoIconBGContext = cairo_create (icon->pIconBuffer);
 
269
                cairo_scale(pCairoIconBGContext,
 
270
                        icon->iImageWidth / g_pIconBackgroundBuffer.iWidth,
 
271
                        icon->iImageHeight / g_pIconBackgroundBuffer.iHeight);
 
272
                cairo_set_source_surface (pCairoIconBGContext,
 
273
                        g_pIconBackgroundBuffer.pSurface,
 
274
                        0.,
 
275
                        0.);
 
276
                cairo_set_operator (pCairoIconBGContext, CAIRO_OPERATOR_DEST_OVER);
 
277
                cairo_paint (pCairoIconBGContext);
 
278
                cairo_destroy (pCairoIconBGContext);
 
279
        }
 
280
        
 
281
        //\______________ le reflet en mode cairo.
 
282
        if (! g_bUseOpenGL && myIcons.fAlbedo > 0 && icon->pIconBuffer != NULL && ! (CAIRO_DOCK_ICON_TYPE_IS_APPLET (icon) && icon->cFileName == NULL))
 
283
        {
 
284
                icon->pReflectionBuffer = cairo_dock_create_reflection_surface (icon->pIconBuffer,
 
285
                        icon->iImageWidth,
 
286
                        icon->iImageHeight,
 
287
                        myIcons.fReflectSize * cairo_dock_get_max_scale (pContainer),
 
288
                        myIcons.fAlbedo,
 
289
                        pContainer ? pContainer->bIsHorizontal : TRUE,
 
290
                        pContainer ? pContainer->bDirectionUp : TRUE);
 
291
        }
 
292
        
 
293
        //\______________ on charge la texture si elle ne l'a pas ete.
 
294
        if (g_bUseOpenGL && (icon->iIconTexture == iPrevTexture || icon->iIconTexture == 0))
 
295
        {
 
296
                icon->iIconTexture = cairo_dock_create_texture_from_surface (icon->pIconBuffer);
 
297
        }
 
298
        
 
299
        //\______________ on libere maintenant les anciennes ressources.
 
300
        if (pPrevSurface != NULL)
 
301
                cairo_surface_destroy (pPrevSurface);
 
302
        if (iPrevTexture != 0)
 
303
                _cairo_dock_delete_texture (iPrevTexture);
 
304
        
 
305
}
 
306
 
 
307
 
 
308
gchar *cairo_dock_cut_string (const gchar *cString, int iNbCaracters)  // gere l'UTF-8
 
309
{
 
310
        g_return_val_if_fail (cString != NULL, NULL);
 
311
        gchar *cTruncatedName = NULL;
 
312
        gsize bytes_read, bytes_written;
 
313
        GError *erreur = NULL;
 
314
        gchar *cUtf8Name = g_locale_to_utf8 (cString,
 
315
                -1,
 
316
                &bytes_read,
 
317
                &bytes_written,
 
318
                &erreur);  // inutile sur Ubuntu, qui est nativement UTF8, mais sur les autres on ne sait pas.
 
319
        if (erreur != NULL)
 
320
        {
 
321
                cd_warning (erreur->message);
 
322
                g_error_free (erreur);
 
323
                erreur = NULL;
 
324
        }
 
325
        if (cUtf8Name == NULL)  // une erreur s'est produite, on tente avec la chaine brute.
 
326
                cUtf8Name = g_strdup (cString);
 
327
        
 
328
        const gchar *cEndValidChain = NULL;
 
329
        int iStringLength;
 
330
        if (g_utf8_validate (cUtf8Name, -1, &cEndValidChain))
 
331
        {
 
332
                iStringLength = g_utf8_strlen (cUtf8Name, -1);
 
333
                int iNbChars = -1;
 
334
                if (iNbCaracters < 0)
 
335
                {
 
336
                        iNbChars = MAX (0, iStringLength + iNbCaracters);
 
337
                }
 
338
                else if (iStringLength > iNbCaracters)
 
339
                {
 
340
                        iNbChars = iNbCaracters;
 
341
                }
 
342
                
 
343
                if (iNbChars != -1)
 
344
                {
 
345
                        cTruncatedName = g_new0 (gchar, 8 * (iNbChars + 4));  // 8 octets par caractere.
 
346
                        if (iNbChars != 0)
 
347
                                g_utf8_strncpy (cTruncatedName, cUtf8Name, iNbChars);
 
348
                        
 
349
                        gchar *cTruncature = g_utf8_offset_to_pointer (cTruncatedName, iNbChars);
 
350
                        *cTruncature = '.';
 
351
                        *(cTruncature+1) = '.';
 
352
                        *(cTruncature+2) = '.';
 
353
                }
 
354
        }
 
355
        else
 
356
        {
 
357
                iStringLength = strlen (cString);
 
358
                int iNbChars = -1;
 
359
                if (iNbCaracters < 0)
 
360
                {
 
361
                        iNbChars = MAX (0, iStringLength + iNbCaracters);
 
362
                }
 
363
                else if (iStringLength > iNbCaracters)
 
364
                {
 
365
                        iNbChars = iNbCaracters;
 
366
                }
 
367
                
 
368
                if (iNbChars != -1)
 
369
                {
 
370
                        cTruncatedName = g_new0 (gchar, iNbCaracters + 4);
 
371
                        if (iNbChars != 0)
 
372
                                strncpy (cTruncatedName, cString, iNbChars);
 
373
                        
 
374
                        cTruncatedName[iNbChars] = '.';
 
375
                        cTruncatedName[iNbChars+1] = '.';
 
376
                        cTruncatedName[iNbChars+2] = '.';
 
377
                }
 
378
        }
 
379
        if (cTruncatedName == NULL)
 
380
                cTruncatedName = cUtf8Name;
 
381
        else
 
382
                g_free (cUtf8Name);
 
383
        //g_print (" -> etiquette : %s\n", cTruncatedName);
 
384
        return cTruncatedName;
 
385
}
 
386
 
 
387
void cairo_dock_load_icon_text (Icon *icon, CairoDockLabelDescription *pTextDescription)
 
388
{
 
389
        cairo_surface_destroy (icon->pTextBuffer);
 
390
        icon->pTextBuffer = NULL;
 
391
        if (icon->iLabelTexture != 0)
 
392
        {
 
393
                _cairo_dock_delete_texture (icon->iLabelTexture);
 
394
                icon->iLabelTexture = 0;
 
395
        }
 
396
        if (icon->cName == NULL || (pTextDescription->iSize == 0))
 
397
                return ;
 
398
 
 
399
        gchar *cTruncatedName = NULL;
 
400
        if (CAIRO_DOCK_IS_APPLI (icon) && myTaskBar.iAppliMaxNameLength > 0)
 
401
        {
 
402
                cTruncatedName = cairo_dock_cut_string (icon->cName, myTaskBar.iAppliMaxNameLength);
 
403
        }
 
404
        
 
405
        double fTextXOffset, fTextYOffset;
 
406
        cairo_surface_t* pNewSurface = cairo_dock_create_surface_from_text ((cTruncatedName != NULL ? cTruncatedName : icon->cName),
 
407
                pTextDescription,
 
408
                &icon->iTextWidth, &icon->iTextHeight);
 
409
        g_free (cTruncatedName);
 
410
        //g_print (" -> %s : (%.2f;%.2f) %dx%d\n", icon->cName, icon->fTextXOffset, icon->fTextYOffset, icon->iTextWidth, icon->iTextHeight);
 
411
 
 
412
        icon->pTextBuffer = pNewSurface;
 
413
        
 
414
        if (g_bUseOpenGL && icon->pTextBuffer != NULL)
 
415
        {
 
416
                icon->iLabelTexture = cairo_dock_create_texture_from_surface (icon->pTextBuffer);
 
417
        }
 
418
}
 
419
 
 
420
void cairo_dock_load_icon_quickinfo (Icon *icon, CairoDockLabelDescription *pTextDescription, double fMaxScale)
 
421
{
 
422
        cairo_surface_destroy (icon->pQuickInfoBuffer);
 
423
        icon->pQuickInfoBuffer = NULL;
 
424
        if (icon->iQuickInfoTexture != 0)
 
425
        {
 
426
                _cairo_dock_delete_texture (icon->iQuickInfoTexture);
 
427
                icon->iQuickInfoTexture = 0;
 
428
        }
 
429
        if (icon->cQuickInfo == NULL)
 
430
                return ;
 
431
 
 
432
        double fQuickInfoXOffset, fQuickInfoYOffset;
 
433
        icon->pQuickInfoBuffer = cairo_dock_create_surface_from_text_full (icon->cQuickInfo,
 
434
                pTextDescription,
 
435
                fMaxScale,
 
436
                icon->fWidth * fMaxScale,
 
437
                &icon->iQuickInfoWidth, &icon->iQuickInfoHeight, NULL, NULL);
 
438
        
 
439
        if (g_bUseOpenGL && icon->pQuickInfoBuffer != NULL)
 
440
        {
 
441
                icon->iQuickInfoTexture = cairo_dock_create_texture_from_surface (icon->pQuickInfoBuffer);
 
442
        }
 
443
}
 
444
 
 
445
 
 
446
void cairo_dock_load_icon_buffers (Icon *pIcon, CairoContainer *pContainer)
 
447
{
 
448
        if (pIcon->iSidLoadImage != 0)
 
449
        {
 
450
                g_source_remove (pIcon->iSidLoadImage);
 
451
                pIcon->iSidLoadImage = 0;
 
452
        }
 
453
        
 
454
        cairo_dock_load_icon_image (pIcon, pContainer);
 
455
 
 
456
        cairo_dock_load_icon_text (pIcon, &myLabels.iconTextDescription);
 
457
 
 
458
        double fMaxScale = cairo_dock_get_max_scale (pContainer);
 
459
        cairo_dock_load_icon_quickinfo (pIcon, &myLabels.quickInfoTextDescription, fMaxScale);
 
460
}
 
461
 
 
462
static gboolean _load_icon_buffer_idle (Icon *pIcon)
 
463
{
 
464
        //g_print ("%s (%s; %dx%d; %.2fx%.2f; %x)\n", __func__, pIcon->cName, pIcon->iImageWidth, pIcon->iImageHeight, pIcon->fWidth, pIcon->fHeight, pIcon->pContainerForLoad);
 
465
        pIcon->iSidLoadImage = 0;
 
466
        
 
467
        CairoContainer *pContainer = pIcon->pContainerForLoad;
 
468
        if (pContainer)
 
469
        {
 
470
                cairo_dock_load_icon_image (pIcon, pContainer);
 
471
 
 
472
                double fMaxScale = cairo_dock_get_max_scale (pContainer);
 
473
                cairo_dock_load_icon_quickinfo (pIcon, &myLabels.quickInfoTextDescription, fMaxScale);
 
474
                
 
475
                cairo_dock_redraw_icon (pIcon, pContainer);
 
476
        }
 
477
        return FALSE;
 
478
}
 
479
void cairo_dock_trigger_load_icon_buffers (Icon *pIcon, CairoContainer *pContainer)
 
480
{
 
481
        cairo_dock_set_icon_size (pContainer, pIcon);
 
482
        pIcon->pContainerForLoad = pContainer;
 
483
        if (pIcon->iSidLoadImage == 0)
 
484
        {
 
485
                //g_print ("trigger load for %s (%x)\n", pIcon->cName, pContainer);
 
486
                //cairo_dock_load_icon_buffers (pIcon, pContainer);
 
487
                cairo_dock_load_icon_text (pIcon, &myLabels.iconTextDescription);  // la vue peut avoir besoin de connaitre la taille du texte.
 
488
                pIcon->iSidLoadImage = g_idle_add ((GSourceFunc)_load_icon_buffer_idle, pIcon);
 
489
        }
 
490
}
 
491
 
 
492
 
 
493
void cairo_dock_reload_buffers_in_dock (gchar *cDockName, CairoDock *pDock, gpointer data)
 
494
{
 
495
        gboolean bReloadAppletsToo = GPOINTER_TO_INT (data);
 
496
        cd_message ("%s (%s, %d)", __func__, cDockName, bReloadAppletsToo);
 
497
 
 
498
        double fFlatDockWidth = - myIcons.iIconGap;
 
499
        pDock->iMaxIconHeight = 0;
 
500
        Icon* icon;
 
501
        GList* ic;
 
502
        for (ic = pDock->icons; ic != NULL; ic = ic->next)
 
503
        {
 
504
                icon = ic->data;
 
505
                
 
506
                if (CAIRO_DOCK_IS_APPLET (icon))
 
507
                {
 
508
                        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().
 
509
                                cairo_dock_reload_module_instance (icon->pModuleInstance, FALSE);
 
510
                }
 
511
                else
 
512
                {
 
513
                        ///cairo_dock_set_icon_size (CAIRO_CONTAINER (pDock), icon);
 
514
                        cairo_dock_trigger_load_icon_buffers (icon, CAIRO_CONTAINER (pDock));  // fait un set_icon_size
 
515
                        icon->fWidth *= pDock->container.fRatio;
 
516
                        icon->fHeight *= pDock->container.fRatio;
 
517
                }
 
518
                
 
519
                //g_print (" =size <- %.2fx%.2f\n", icon->fWidth, icon->fHeight);
 
520
                fFlatDockWidth += myIcons.iIconGap + icon->fWidth;
 
521
                if (! CAIRO_DOCK_ICON_TYPE_IS_SEPARATOR (icon))
 
522
                        pDock->iMaxIconHeight = MAX (pDock->iMaxIconHeight, icon->fHeight);
 
523
        }
 
524
        pDock->fFlatDockWidth = (int) fFlatDockWidth;  /// (int) n'est plus tellement necessaire ...
 
525
}
 
526
 
 
527
void cairo_dock_reload_icon_image (Icon *icon, CairoContainer *pContainer)
 
528
{
 
529
        if (pContainer)
 
530
        {
 
531
                icon->fWidth /= pContainer->fRatio;
 
532
                icon->fHeight /= pContainer->fRatio;
 
533
        }
 
534
        cairo_dock_load_icon_image (icon, pContainer);
 
535
        if (pContainer)
 
536
        {
 
537
                icon->fWidth *= pContainer->fRatio;
 
538
                icon->fHeight *= pContainer->fRatio;
 
539
        }
 
540
}
 
541
 
 
542
void cairo_dock_add_reflection_to_icon (Icon *pIcon, CairoContainer *pContainer)
 
543
{
 
544
        if (g_bUseOpenGL)
 
545
                return ;
 
546
        g_return_if_fail (pIcon != NULL && pContainer!= NULL);
 
547
        
 
548
        if (pIcon->pReflectionBuffer != NULL)
 
549
        {
 
550
                cairo_surface_destroy (pIcon->pReflectionBuffer);
 
551
                pIcon->pReflectionBuffer = NULL;
 
552
        }
 
553
        if (! pContainer->bUseReflect)
 
554
                return;
 
555
        
 
556
        int iWidth, iHeight;
 
557
        cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
 
558
        pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
 
559
                iWidth,
 
560
                iHeight,
 
561
                myIcons.fReflectSize * cairo_dock_get_max_scale (pContainer),
 
562
                myIcons.fAlbedo,
 
563
                pContainer->bIsHorizontal,
 
564
                pContainer->bDirectionUp);
 
565
}
 
566
 
 
567
 
 
568
  ///////////////
 
569
 /// MANAGER ///
 
570
///////////////
 
571
 
 
572
void cairo_dock_load_icons_background_surface (const gchar *cImagePath, double fMaxScale)
 
573
{
 
574
        cairo_dock_unload_image_buffer (&g_pIconBackgroundBuffer);
 
575
        
 
576
        int iSize = MAX (myIcons.tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER], myIcons.tIconAuthorizedWidth[CAIRO_DOCK_APPLI]);
 
577
        if (iSize == 0)
 
578
                iSize = 48;
 
579
        iSize *= fMaxScale;
 
580
        cairo_dock_load_image_buffer (&g_pIconBackgroundBuffer,
 
581
                cImagePath,
 
582
                iSize,
 
583
                iSize,
 
584
                CAIRO_DOCK_FILL_SPACE);
 
585
}
 
586
 
 
587
void cairo_dock_init_icon_manager (void)
 
588
{
 
589
        memset (&g_pIconBackgroundBuffer, 0, sizeof (CairoDockImageBuffer));
 
590
}
 
591
 
 
592
static void _load_renderer (const gchar *cRenderername, CairoIconContainerRenderer *pRenderer, gpointer data)
 
593
{
 
594
        if (pRenderer && pRenderer->load)
 
595
                pRenderer->load ();
 
596
}
 
597
void cairo_dock_load_icon_textures (void)
 
598
{
 
599
        double fMaxScale = cairo_dock_get_max_scale (g_pMainDock);
 
600
        
 
601
        cairo_dock_load_icons_background_surface (myIcons.cBackgroundImagePath, fMaxScale);
 
602
        
 
603
        cairo_dock_foreach_icon_container_renderer ((GHFunc)_load_renderer, NULL);
 
604
}
 
605
 
 
606
static void _unload_renderer (const gchar *cRenderername, CairoIconContainerRenderer *pRenderer, gpointer data)
 
607
{
 
608
        if (pRenderer && pRenderer->unload)
 
609
                pRenderer->unload ();
 
610
}
 
611
void cairo_dock_unload_icon_textures (void)
 
612
{
 
613
        cairo_dock_unload_image_buffer (&g_pIconBackgroundBuffer);
 
614
        
 
615
        cairo_dock_foreach_icon_container_renderer ((GHFunc)_unload_renderer, NULL);
 
616
}
 
617
 
 
618
 
 
619
  ///////////////////////
 
620
 /// CONTAINER ICONS ///
 
621
///////////////////////
 
622
 
 
623
void cairo_dock_draw_subdock_content_on_icon (Icon *pIcon, CairoDock *pDock)
 
624
{
 
625
        g_return_if_fail (pIcon != NULL && pIcon->pSubDock != NULL && (pIcon->pIconBuffer != NULL || pIcon->iIconTexture != 0));
 
626
        
 
627
        CairoIconContainerRenderer *pRenderer = cairo_dock_get_icon_container_renderer (pIcon->cClass != NULL ? "Stack" : s_cRendererNames[pIcon->iSubdockViewType]);
 
628
        if (pRenderer == NULL)
 
629
                return;
 
630
        cd_debug ("%s (%s)", __func__, pIcon->cName);
 
631
        
 
632
        int w, h;
 
633
        cairo_dock_get_icon_extent (pIcon, CAIRO_CONTAINER (pDock), &w, &h);
 
634
        
 
635
        cairo_t *pCairoContext = NULL;
 
636
        if (pIcon->iIconTexture != 0 && pRenderer->render_opengl)  // dessin opengl
 
637
        {
 
638
                //\______________ On efface le dessin existant.
 
639
                if (! cairo_dock_begin_draw_icon (pIcon, CAIRO_CONTAINER (pDock), 0))
 
640
                        return ;
 
641
                
 
642
                _cairo_dock_set_blend_source ();
 
643
                if (g_pIconBackgroundBuffer.iTexture != 0)  // on ecrase le dessin existant avec l'image de fond des icones.
 
644
                {
 
645
                        _cairo_dock_enable_texture ();
 
646
                        _cairo_dock_set_alpha (1.);
 
647
                        _cairo_dock_apply_texture_at_size (g_pIconBackgroundBuffer.iTexture, w, h);
 
648
                }
 
649
                else  // sinon on efface juste ce qu'il y'avait.
 
650
                {
 
651
                        glPolygonMode (GL_FRONT, GL_FILL);
 
652
                        _cairo_dock_set_alpha (0.);
 
653
                        glBegin(GL_QUADS);
 
654
                        glVertex3f(-.5*w,  .5*h, 0.);
 
655
                        glVertex3f( .5*w,  .5*h, 0.);
 
656
                        glVertex3f( .5*w, -.5*h, 0.);
 
657
                        glVertex3f(-.5*w, -.5*h, 0.);
 
658
                        glEnd();
 
659
                        _cairo_dock_enable_texture ();
 
660
                        _cairo_dock_set_alpha (1.);
 
661
                }
 
662
                _cairo_dock_set_blend_alpha ();
 
663
                
 
664
                //\______________ On dessine les 3 ou 4 premieres icones du sous-dock.
 
665
                pRenderer->render_opengl (pIcon, CAIRO_CONTAINER (pDock), w, h);
 
666
                
 
667
                //\______________ On finit le dessin.
 
668
                _cairo_dock_disable_texture ();
 
669
                cairo_dock_end_draw_icon (pIcon, CAIRO_CONTAINER (pDock));
 
670
        }
 
671
        else if (pIcon->pIconBuffer != NULL && pRenderer->render != NULL)  // dessin cairo
 
672
        {
 
673
                //\______________ On efface le dessin existant.
 
674
                pCairoContext = cairo_create (pIcon->pIconBuffer);
 
675
                g_return_if_fail (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS);
 
676
                
 
677
                if (g_pIconBackgroundBuffer.pSurface != NULL)  // on ecrase le dessin existant avec l'image de fond des icones.
 
678
                {
 
679
                        cairo_save (pCairoContext);
 
680
                        cairo_scale(pCairoContext,
 
681
                                (double) w / g_pIconBackgroundBuffer.iWidth,
 
682
                                (double) h / g_pIconBackgroundBuffer.iHeight);
 
683
                        cairo_set_source_surface (pCairoContext,
 
684
                                g_pIconBackgroundBuffer.pSurface,
 
685
                                0.,
 
686
                                0.);
 
687
                        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
 
688
                        cairo_paint (pCairoContext);
 
689
                        cairo_restore (pCairoContext);
 
690
                }
 
691
                else  // sinon on efface juste ce qu'il y'avait.
 
692
                {
 
693
                        cairo_dock_erase_cairo_context (pCairoContext);
 
694
                }
 
695
                cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
 
696
                
 
697
                //\______________ On dessine les 3 ou 4 premieres icones du sous-dock.
 
698
                pRenderer->render (pIcon, CAIRO_CONTAINER (pDock), w, h, pCairoContext);
 
699
                
 
700
                //\______________ On finit le dessin.
 
701
                if (g_bUseOpenGL)
 
702
                        cairo_dock_update_icon_texture (pIcon);
 
703
                else
 
704
                        cairo_dock_add_reflection_to_icon (pIcon, CAIRO_CONTAINER (pDock));
 
705
                cairo_destroy (pCairoContext);
 
706
        }
 
707
}