~cairo-dock-team/ubuntu/precise/cairo-dock/3.0.0.0beta1

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2008-09-14 16:26:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080914162612-t6aa8pr2o0qry48o
Tags: 1.6.2.3-0ubuntu1
* New upstream release.
* debian/control
 - Update to 3.8.0 (no change needed).
 - Add libxtst-dev as Build-Depends.
* debian/cairo-dock-data.install
 - Add usr/share/cairo-dock/emblems directory.
* debian/watch
 - Update location.
* debian/rules
 - Add a get-orig-source rule.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "cairo-dock-log.h"
31
31
#include "cairo-dock-dock-manager.h"
32
32
#include "cairo-dock-class-manager.h"
 
33
#include "cairo-dock-X-utilities.h"
33
34
#include "cairo-dock-load.h"
34
35
 
35
36
extern CairoDock *g_pMainDock;
36
37
extern double g_fSubDockSizeRatio;
37
38
extern gboolean g_bSameHorizontality;
38
39
 
 
40
extern gint g_iScreenWidth[2];
 
41
extern gint g_iScreenHeight[2];
 
42
 
39
43
extern int g_iSinusoidWidth;
40
44
extern gint g_iDockLineWidth;
41
45
extern gint g_iDockRadius;
47
51
extern cairo_surface_t *g_pVisibleZoneSurface;
48
52
extern gboolean g_bReverseVisibleImage;
49
53
 
50
 
extern int g_iLabelWeight;
51
 
extern int g_iLabelStyle;
52
 
extern int g_iLabelSize;
53
 
extern gchar *g_cLabelPolice;
 
54
extern CairoDockLabelDescription g_iconTextDescription;
 
55
extern CairoDockLabelDescription g_quickInfoTextDescription;
54
56
extern gboolean g_bTextAlwaysHorizontal;
55
 
extern double g_fLabelBackgroundColor[4];
56
 
extern gboolean g_bUseBackgroundForLabel;
57
57
 
58
58
extern gchar *g_cCurrentThemePath;
59
59
 
77
77
extern int g_tIconAuthorizedWidth[CAIRO_DOCK_NB_TYPES];
78
78
extern int g_tIconAuthorizedHeight[CAIRO_DOCK_NB_TYPES];
79
79
extern gboolean g_bOverWriteXIcons;
80
 
 
81
 
extern gboolean g_bUseGlitz;
82
 
 
83
 
 
84
 
gchar *cairo_dock_generate_file_path (gchar *cImageFile)
 
80
extern gboolean g_bShowThumbnail;
 
81
 
 
82
extern cairo_surface_t *g_pDropIndicatorSurface;
 
83
extern double g_fDropIndicatorWidth, g_fDropIndicatorHeight;
 
84
extern cairo_surface_t *g_pIndicatorSurface[2];
 
85
extern gboolean g_bLinkIndicatorWithIcon;
 
86
extern double g_fIndicatorWidth, g_fIndicatorHeight;
 
87
 
 
88
extern cairo_surface_t *g_pActiveIndicatorSurface;
 
89
extern double g_fActiveIndicatorWidth, g_fActiveIndicatorHeight;
 
90
 
 
91
extern cairo_surface_t *g_pDesktopBgSurface;
 
92
 
 
93
void cairo_dock_free_label_description (CairoDockLabelDescription *pTextDescription)
 
94
{
 
95
        if (pTextDescription == NULL)
 
96
                return ;
 
97
        g_free (pTextDescription->cFont);
 
98
        g_free (pTextDescription);
 
99
}
 
100
 
 
101
void cairo_dock_copy_label_description (CairoDockLabelDescription *pDestTextDescription, CairoDockLabelDescription *pOrigTextDescription)
 
102
{
 
103
        g_return_if_fail (pOrigTextDescription != NULL && pDestTextDescription != NULL);
 
104
        memcpy (pDestTextDescription, pOrigTextDescription, sizeof (CairoDockLabelDescription));
 
105
        pDestTextDescription->cFont = g_strdup (pOrigTextDescription->cFont);
 
106
}
 
107
 
 
108
CairoDockLabelDescription *cairo_dock_duplicate_label_description (CairoDockLabelDescription *pOrigTextDescription)
 
109
{
 
110
        g_return_val_if_fail (pOrigTextDescription != NULL, NULL);
 
111
        CairoDockLabelDescription *pTextDescription = g_memdup (pOrigTextDescription, sizeof (CairoDockLabelDescription));
 
112
        pTextDescription->cFont = g_strdup (pOrigTextDescription->cFont);
 
113
        return pTextDescription;
 
114
}
 
115
 
 
116
gchar *cairo_dock_generate_file_path (const gchar *cImageFile)
85
117
{
86
118
        g_return_val_if_fail (cImageFile != NULL, NULL);
87
119
        gchar *cImagePath;
100
132
        return cImagePath;
101
133
}
102
134
 
103
 
cairo_surface_t *cairo_dock_load_image (cairo_t *pSourceContext, gchar *cImageFile, double *fImageWidth, double *fImageHeight, double fRotationAngle, double fAlpha, gboolean bReapeatAsPattern)
 
135
cairo_surface_t *cairo_dock_load_image (cairo_t *pSourceContext, const gchar *cImageFile, double *fImageWidth, double *fImageHeight, double fRotationAngle, double fAlpha, gboolean bReapeatAsPattern)
104
136
{
105
137
        g_return_val_if_fail (cairo_status (pSourceContext) == CAIRO_STATUS_SUCCESS, NULL);
106
138
        cairo_surface_t *pNewSurface = NULL;
115
147
                        1.,
116
148
                        bReapeatAsPattern ? 0 : iDesiredWidth,  // pas de contrainte sur
117
149
                        bReapeatAsPattern ? 0 : iDesiredHeight,  // la taille du motif initialement.
 
150
                        CAIRO_DOCK_FILL_SPACE,
118
151
                        fImageWidth,
119
152
                        fImageHeight,
120
 
                        FALSE);
 
153
                        NULL, NULL);
121
154
                
122
155
                if (bReapeatAsPattern)
123
156
                {
173
206
        return pNewSurface;
174
207
}
175
208
 
176
 
cairo_surface_t *cairo_dock_load_image_for_icon (cairo_t *pSourceContext, gchar *cImageFile, double fImageWidth, double fImageHeight)
 
209
cairo_surface_t *cairo_dock_load_image_for_icon (cairo_t *pSourceContext, const gchar *cImageFile, double fImageWidth, double fImageHeight)
177
210
{
178
211
        double fImageWidth_ = fImageWidth, fImageHeight_ = fImageHeight;
179
212
        return cairo_dock_load_image (pSourceContext, cImageFile, &fImageWidth_, &fImageHeight_, 0., 1., FALSE);
180
213
}
181
214
 
182
215
 
 
216
void cairo_dock_load_reflect_on_icon (Icon *icon, cairo_t *pSourceContext, gdouble fMaxScale, gboolean bHorizontalDock, gboolean bDirectionUp)
 
217
{
 
218
        if (g_fAlbedo > 0 && icon->pIconBuffer != NULL && ! (CAIRO_DOCK_IS_APPLET (icon) && icon->acFileName == NULL))
 
219
        {
 
220
                icon->pReflectionBuffer = cairo_dock_create_reflection_surface (icon->pIconBuffer,
 
221
                        pSourceContext,
 
222
                        (bHorizontalDock ? icon->fWidth : icon->fHeight) * fMaxScale,
 
223
                        (bHorizontalDock ? icon->fHeight : icon->fWidth) * fMaxScale,
 
224
                        bHorizontalDock,
 
225
                        fMaxScale,
 
226
                        bDirectionUp);
 
227
 
 
228
                icon->pFullIconBuffer = cairo_dock_create_icon_surface_with_reflection (icon->pIconBuffer,
 
229
                        icon->pReflectionBuffer,
 
230
                        pSourceContext,
 
231
                        (bHorizontalDock ? icon->fWidth : icon->fHeight) * fMaxScale,
 
232
                        (bHorizontalDock ? icon->fHeight : icon->fWidth) * fMaxScale,
 
233
                        bHorizontalDock,
 
234
                        fMaxScale,
 
235
                        bDirectionUp);
 
236
        }
 
237
}
 
238
 
183
239
void cairo_dock_fill_one_icon_buffer (Icon *icon, cairo_t* pSourceContext, gdouble fMaxScale, gboolean bHorizontalDock, gboolean bApplySizeRestriction, gboolean bDirectionUp)
184
240
{
185
241
        //g_print ("%s (%d, %.2f, %s)\n", __func__, icon->iType, fMaxScale, icon->acFileName);
202
258
                //\_______________________ On cree la surface cairo a afficher.
203
259
                if (cIconPath != NULL && *cIconPath != '\0')
204
260
                {
205
 
                        //cairo_surface_t *pSurface =cairo_dock_create_surface_from_image (cIconPath,
206
261
                        icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
207
262
                                pSourceContext,
208
263
                                fMaxScale,
209
264
                                (bApplySizeRestriction ? g_tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] : icon->fWidth),
210
265
                                (bApplySizeRestriction ? g_tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] : icon->fHeight),
 
266
                                CAIRO_DOCK_FILL_SPACE,
211
267
                                (bHorizontalDock ? &icon->fWidth : &icon->fHeight),
212
268
                                (bHorizontalDock ? &icon->fHeight : &icon->fWidth),
213
 
                                FALSE);
214
 
                        //g_print (" => %.2fx%.2f\n", icon->fWidth, icon->fHeight);
215
 
                        /*int w = (int) icon->fWidth * (1 + g_fAmplitude), h = (int) icon->fHeight * (1 + g_fAmplitude);
216
 
                        guchar *pSurfaceData = g_new0 (guchar, w * h * 4);
217
 
                        icon->pIconBuffer = cairo_image_surface_create_for_data (pSurfaceData,
218
 
                                CAIRO_FORMAT_ARGB32,
219
 
                                w,
220
 
                                h,
221
 
                                w * 4);
222
 
                        cd_message (" + (%dx%d)\n", w, h);
223
 
                        
224
 
                        cairo_t* pCairoContext = cairo_create (icon->pIconBuffer);
225
 
                        cairo_set_source_surface (pCairoContext, pSurface, 0.0, 0.0);
226
 
                        cairo_paint (pCairoContext);
227
 
                        cairo_destroy (pCairoContext);
228
 
                        cairo_surface_destroy (pSurface);*/
 
269
                                NULL, NULL);
229
270
                }
230
271
                
231
272
                g_free (cIconPath);
237
278
        }
238
279
        else if (CAIRO_DOCK_IS_APPLI (icon))  // c'est l'icône d'une appli valide. Dans cet ordre on n'a pas besoin de verifier que c'est NORMAL_APPLI.
239
280
        {
240
 
                if (g_bOverWriteXIcons && ! cairo_dock_class_is_using_xicon (icon->cClass))
 
281
                if (g_bOverWriteXIcons && ! cairo_dock_class_is_using_xicon (icon->cClass) && ! (g_bShowThumbnail && icon->bIsHidden))
241
282
                        icon->pIconBuffer = cairo_dock_create_surface_from_class (icon->cClass, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
 
283
                if (icon->pIconBuffer == NULL && g_bShowThumbnail && icon->bIsHidden && icon->iBackingPixmap != 0)
 
284
                        icon->pIconBuffer = cairo_dock_create_surface_from_xpixmap (icon->iBackingPixmap, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
242
285
                if (icon->pIconBuffer == NULL)
243
286
                        icon->pIconBuffer = cairo_dock_create_surface_from_xwindow (icon->Xid, pSourceContext, fMaxScale, &icon->fWidth, &icon->fHeight);
244
287
        }
250
293
        if (icon->pIconBuffer == NULL)
251
294
        {
252
295
                gchar *cIconPath = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, CAIRO_DOCK_DEFAULT_ICON_NAME);
 
296
                CairoDockIconType iType = cairo_dock_get_icon_type  (icon);
253
297
                icon->pIconBuffer = cairo_dock_create_surface_from_image (cIconPath,
254
298
                        pSourceContext,
255
299
                        fMaxScale,
256
 
                        (bApplySizeRestriction ? g_tIconAuthorizedWidth[icon->iType] : icon->fWidth),
257
 
                        (bApplySizeRestriction ? g_tIconAuthorizedHeight[icon->iType] : icon->fHeight),
 
300
                        (bApplySizeRestriction ? g_tIconAuthorizedWidth[iType] : icon->fWidth),
 
301
                        (bApplySizeRestriction ? g_tIconAuthorizedHeight[iType] : icon->fHeight),
 
302
                        CAIRO_DOCK_FILL_SPACE,
258
303
                        (bHorizontalDock ? &icon->fWidth : &icon->fHeight),
259
304
                        (bHorizontalDock ? &icon->fHeight : &icon->fWidth),
260
 
                        FALSE);
 
305
                        NULL, NULL);
261
306
                g_free (cIconPath);
262
307
        }
263
308
        cd_debug ("%s () -> %.2fx%.2f", __func__, icon->fWidth, icon->fHeight);
283
328
        }
284
329
}
285
330
 
286
 
void cairo_dock_fill_one_text_buffer (Icon *icon, cairo_t* pSourceContext, int iLabelSize, gchar *cLabelPolice, gboolean bHorizontalDock, gboolean bDirectionUp)
 
331
gchar *cairo_dock_cut_string (gchar *cString, int iNbCaracters)  // gere l'UTF-8
 
332
{
 
333
        gchar *cTruncatedName = NULL;
 
334
        gsize bytes_read, bytes_written;
 
335
        GError *erreur = NULL;
 
336
        gchar *cUtf8Name = g_locale_to_utf8 (cString,
 
337
                -1,
 
338
                &bytes_read,
 
339
                &bytes_written,
 
340
                &erreur);  // inutile sur Ubuntu, qui est nativement UTF8, mais sur les autres on ne sait pas.
 
341
        if (erreur != NULL)
 
342
        {
 
343
                cd_warning (erreur->message);
 
344
                g_error_free (erreur);
 
345
                erreur = NULL;
 
346
        }
 
347
        if (cUtf8Name == NULL)  // une erreur s'est produite, on tente avec la chaine brute.
 
348
                cUtf8Name = g_strdup (cString);
 
349
        
 
350
        const gchar *cEndValidChain = NULL;
 
351
        if (g_utf8_validate (cUtf8Name, -1, &cEndValidChain))
 
352
        {
 
353
                if (g_utf8_strlen (cUtf8Name, -1) > iNbCaracters)
 
354
                {
 
355
                        cTruncatedName = g_new0 (gchar, 8 * (iNbCaracters + 4));  // 8 octets par caractere.
 
356
                        g_utf8_strncpy (cTruncatedName, cUtf8Name, iNbCaracters);
 
357
 
 
358
                        gchar *cTruncature = g_utf8_offset_to_pointer (cTruncatedName, iNbCaracters);
 
359
                        *cTruncature = '.';
 
360
                        *(cTruncature+1) = '.';
 
361
                        *(cTruncature+2) = '.';
 
362
                }
 
363
        }
 
364
        else
 
365
        {
 
366
                if (strlen (cString) > iNbCaracters)
 
367
                {
 
368
                        cTruncatedName = g_new0 (gchar, iNbCaracters + 4);
 
369
                        strncpy (cTruncatedName, cString, iNbCaracters);
 
370
 
 
371
                        cTruncatedName[iNbCaracters] = '.';
 
372
                        cTruncatedName[iNbCaracters+1] = '.';
 
373
                        cTruncatedName[iNbCaracters+2] = '.';
 
374
                }
 
375
        }
 
376
        if (cTruncatedName == NULL)
 
377
                cTruncatedName = cUtf8Name;
 
378
        else
 
379
                g_free (cUtf8Name);
 
380
        //g_print (" -> etiquette : %s\n", cTruncatedName);
 
381
        return cTruncatedName;
 
382
}
 
383
 
 
384
void cairo_dock_fill_one_text_buffer (Icon *icon, cairo_t* pSourceContext, CairoDockLabelDescription *pTextDescription, gboolean bHorizontalDock, gboolean bDirectionUp)
287
385
{
288
386
        //g_print ("%s (%s, %d)\n", __func__, cLabelPolice, iLabelSize);
289
387
        cairo_surface_destroy (icon->pTextBuffer);
290
388
        icon->pTextBuffer = NULL;
291
 
        if (icon->acName == NULL || (iLabelSize == 0))
 
389
        if (icon->acName == NULL || (pTextDescription->iSize == 0))
292
390
                return ;
293
391
 
294
392
        gchar *cTruncatedName = NULL;
295
393
        if (CAIRO_DOCK_IS_APPLI (icon) && g_iAppliMaxNameLength > 0)
296
394
        {
297
 
                //g_print ("troncature de %s\n", icon->acName);
298
 
                gsize bytes_read, bytes_written;
 
395
                cTruncatedName = cairo_dock_cut_string (icon->acName, g_iAppliMaxNameLength);
 
396
                /**gsize bytes_read, bytes_written;
299
397
                GError *erreur = NULL;
300
398
                gchar *cUtf8Name = g_locale_to_utf8 (icon->acName,
301
399
                        -1,
304
402
                        &erreur);  // inutile sur Ubuntu, qui est nativement UTF8, mais sur les autres on ne sait pas.
305
403
                if (erreur != NULL)
306
404
                {
307
 
                        cd_warning ("Attention : %s", erreur->message);
 
405
                        cd_warning ("%s", erreur->message);
308
406
                        g_error_free (erreur);
309
407
                        erreur = NULL;
310
408
                }
338
436
                        }
339
437
                }
340
438
                g_free (cUtf8Name);
341
 
                //g_print (" -> etiquette : %s\n", cTruncatedName);
 
439
                //g_print (" -> etiquette : %s\n", cTruncatedName);*/
342
440
        }
343
441
 
344
 
        cairo_surface_t* pNewSurface = cairo_dock_create_surface_from_text ((cTruncatedName != NULL ? cTruncatedName : icon->acName), pSourceContext, iLabelSize, cLabelPolice, g_iLabelWeight, (g_bUseBackgroundForLabel ? g_fLabelBackgroundColor : NULL), 1., &icon->iTextWidth, &icon->iTextHeight, &icon->fTextXOffset, &icon->fTextYOffset);
 
442
        cairo_surface_t* pNewSurface = cairo_dock_create_surface_from_text ((cTruncatedName != NULL ? cTruncatedName : icon->acName),
 
443
                pSourceContext,
 
444
                pTextDescription,
 
445
                1.,
 
446
                &icon->iTextWidth, &icon->iTextHeight, &icon->fTextXOffset, &icon->fTextYOffset);
345
447
        g_free (cTruncatedName);
346
448
        //g_print (" -> %s : (%.2f;%.2f) %dx%d\n", icon->acName, icon->fTextXOffset, icon->fTextYOffset, icon->iTextWidth, icon->iTextHeight);
347
449
 
356
458
        icon->pTextBuffer = pNewSurface;
357
459
}
358
460
 
359
 
void cairo_dock_fill_one_quick_info_buffer (Icon *icon, cairo_t* pSourceContext, int iLabelSize, gchar *cLabelPolice, int iLabelWeight, double fMaxScale)
 
461
void cairo_dock_fill_one_quick_info_buffer (Icon *icon, cairo_t* pSourceContext, CairoDockLabelDescription *pTextDescription, double fMaxScale)
360
462
{
361
463
        cairo_surface_destroy (icon->pQuickInfoBuffer);
362
464
        icon->pQuickInfoBuffer = NULL;
363
465
        if (icon->cQuickInfo == NULL)
364
466
                return ;
365
467
 
366
 
        icon->pQuickInfoBuffer = cairo_dock_create_surface_from_text (icon->cQuickInfo, pSourceContext, iLabelSize, cLabelPolice, iLabelWeight, g_fLabelBackgroundColor, fMaxScale, &icon->iQuickInfoWidth, &icon->iQuickInfoHeight, &icon->fQuickInfoXOffset, &icon->fQuickInfoYOffset);
 
468
        icon->pQuickInfoBuffer = cairo_dock_create_surface_from_text_full (icon->cQuickInfo,
 
469
                pSourceContext,
 
470
                pTextDescription,
 
471
                fMaxScale,
 
472
                icon->fWidth * fMaxScale,
 
473
                &icon->iQuickInfoWidth, &icon->iQuickInfoHeight, &icon->fQuickInfoXOffset, &icon->fQuickInfoYOffset);
367
474
}
368
475
 
369
476
 
372
479
{
373
480
        cairo_dock_fill_one_icon_buffer (icon, pSourceContext, fMaxScale, bHorizontalDock, bApplySizeRestriction, bDirectionUp);
374
481
 
375
 
        cairo_dock_fill_one_text_buffer (icon, pSourceContext, g_iLabelSize, g_cLabelPolice, (g_bTextAlwaysHorizontal ? CAIRO_DOCK_HORIZONTAL : bHorizontalDock), bDirectionUp);
 
482
        cairo_dock_fill_one_text_buffer (icon, pSourceContext, &g_iconTextDescription, (g_bTextAlwaysHorizontal ? CAIRO_DOCK_HORIZONTAL : bHorizontalDock), bDirectionUp);
376
483
 
377
 
        cairo_dock_fill_one_quick_info_buffer (icon, pSourceContext, 12, g_cLabelPolice, PANGO_WEIGHT_HEAVY, fMaxScale);
 
484
        cairo_dock_fill_one_quick_info_buffer (icon, pSourceContext, &g_quickInfoTextDescription, fMaxScale);
378
485
}
379
486
 
380
487
void cairo_dock_load_one_icon_from_scratch (Icon *pIcon, CairoContainer *pContainer)
395
502
 
396
503
void cairo_dock_reload_buffers_in_dock (gchar *cDockName, CairoDock *pDock, gpointer data)
397
504
{
398
 
        cd_message ("%s (%s)", __func__, cDockName);
399
 
        if (pDock->iRefCount > 0)
400
 
                pDock->bHorizontalDock = (g_bSameHorizontality ? g_pMainDock->bHorizontalDock : ! g_pMainDock->bHorizontalDock);
401
 
        else
402
 
                pDock->bHorizontalDock = g_pMainDock->bHorizontalDock;
 
505
        gboolean bReloadAppletsToo = GPOINTER_TO_INT (data);
 
506
        cd_message ("%s (%s, %d)", __func__, cDockName, bReloadAppletsToo);
 
507
        ///if (pDock->iRefCount > 0)
 
508
        ///     pDock->bHorizontalDock = (g_bSameHorizontality ? g_pMainDock->bHorizontalDock : ! g_pMainDock->bHorizontalDock);
 
509
        //else
 
510
        //      pDock->bHorizontalDock = g_pMainDock->bHorizontalDock;
403
511
 
404
512
        double fFlatDockWidth = - g_iIconGap;
405
513
        pDock->iMaxIconHeight = 0;
413
521
        for (ic = pDock->icons; ic != NULL; ic = ic->next)
414
522
        {
415
523
                icon = ic->data;
416
 
                icon->fWidth /= pDock->fRatio;
417
 
                icon->fHeight /= pDock->fRatio;
418
524
                
419
 
                /*if (CAIRO_DOCK_IS_APPLET (icon))
420
 
                        cairo_dock_reload_module (icon->pModule, FALSE);
421
 
                else*/
422
 
                if (! CAIRO_DOCK_IS_APPLET (icon))
 
525
                if (CAIRO_DOCK_IS_APPLET (icon))
 
526
                {
 
527
                        if (bReloadAppletsToo)
 
528
                                cairo_dock_reload_module_instance (icon->pModuleInstance, FALSE);
 
529
                }
 
530
                else
 
531
                {
 
532
                        icon->fWidth /= pDock->fRatio;
 
533
                        icon->fHeight /= pDock->fRatio;
423
534
                        cairo_dock_fill_icon_buffers_for_dock (icon, pCairoContext, pDock);
424
 
                        ///cairo_dock_fill_icon_buffers (icon, pCairoContext, fMaxScale, pDock->bHorizontalDock, TRUE, pDock->bDirectionUp);
425
 
 
426
 
                icon->fWidth *= pDock->fRatio;
427
 
                icon->fHeight *= pDock->fRatio;
 
535
                        icon->fWidth *= pDock->fRatio;
 
536
                        icon->fHeight *= pDock->fRatio;
 
537
                }
 
538
                
428
539
                //g_print (" =size <- %.2fx%.2f\n", icon->fWidth, icon->fHeight);
429
540
                fFlatDockWidth += g_iIconGap + icon->fWidth;
430
541
                pDock->iMaxIconHeight = MAX (pDock->iMaxIconHeight, icon->fHeight);
585
696
                                        
586
697
                                g_pBackgroundSurfaceFull[CAIRO_DOCK_VERTICAL] = cairo_dock_rotate_surface (g_pBackgroundSurfaceFull[CAIRO_DOCK_HORIZONTAL], pCairoContext, g_fBackgroundImageWidth, g_fBackgroundImageHeight, (pDock->bDirectionUp ? -G_PI/2 : G_PI/2));
587
698
                        }
588
 
                        else if (g_fBackgroundImageWidth == 0 || g_fBackgroundImageHeight == 0)
 
699
                        else/** if (g_fBackgroundImageWidth == 0 || g_fBackgroundImageHeight == 0)*/
589
700
                        {
590
 
                                g_fBackgroundImageWidth = 0;
 
701
                                g_fBackgroundImageWidth = MAX (g_fBackgroundImageWidth, iNewDecorationsWidth);  /// 0
591
702
                                g_fBackgroundImageHeight = MAX (g_fBackgroundImageHeight, iNewDecorationsHeight);
592
703
                                g_pBackgroundSurface[CAIRO_DOCK_HORIZONTAL] = cairo_dock_load_image (pCairoContext,
593
704
                                        g_cBackgroundImageFile,
624
735
        g_fBackgroundImageHeight = 0;
625
736
        cairo_dock_update_background_decorations_if_necessary (pDock, iWidth, iHeight);
626
737
}
 
738
 
 
739
 
 
740
void cairo_dock_load_drop_indicator (gchar *cImagePath, cairo_t* pSourceContext, double fMaxScale)
 
741
{
 
742
        if (g_pDropIndicatorSurface != NULL)
 
743
                cairo_surface_destroy (g_pDropIndicatorSurface);
 
744
        g_pDropIndicatorSurface = cairo_dock_create_surface_from_image (cImagePath,
 
745
                pSourceContext,
 
746
                1.,
 
747
                g_tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] * fMaxScale,
 
748
                g_tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] * fMaxScale / 2,
 
749
                CAIRO_DOCK_KEEP_RATIO,
 
750
                &g_fDropIndicatorWidth, &g_fDropIndicatorHeight,
 
751
                NULL, NULL);
 
752
}
 
753
 
 
754
 
 
755
void cairo_dock_load_task_indicator (const gchar *cIndicatorImagePath, cairo_t* pSourceContext, double fMaxScale, double fIndicatorRatio)
 
756
{
 
757
        cairo_surface_destroy (g_pIndicatorSurface[0]);
 
758
        cairo_surface_destroy (g_pIndicatorSurface[1]);
 
759
        g_pIndicatorSurface[0] = NULL;
 
760
        g_pIndicatorSurface[1] = NULL;
 
761
        if (cIndicatorImagePath != NULL)
 
762
        {
 
763
                double fLauncherWidth = (g_tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] != 0 ? g_tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER] : 48);
 
764
                double fLauncherHeight = (g_tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] != 0 ? g_tIconAuthorizedHeight[CAIRO_DOCK_LAUNCHER] : 48);
 
765
                
 
766
                double fScale = (g_bLinkIndicatorWithIcon ? 1 + g_fAmplitude : 1);
 
767
                g_pIndicatorSurface[CAIRO_DOCK_HORIZONTAL] = cairo_dock_create_surface_from_image (
 
768
                        cIndicatorImagePath,
 
769
                        pSourceContext,
 
770
                        fScale,
 
771
                        fLauncherWidth * fIndicatorRatio,
 
772
                        fLauncherHeight * fIndicatorRatio,
 
773
                        CAIRO_DOCK_KEEP_RATIO,
 
774
                        &g_fIndicatorWidth,
 
775
                        &g_fIndicatorHeight,
 
776
                        NULL, NULL);
 
777
                //g_print ("g_pIndicatorSurface : %.2fx%.2f\n", g_fIndicatorWidth, g_fIndicatorHeight);
 
778
                if (g_pIndicatorSurface[CAIRO_DOCK_HORIZONTAL] != NULL)
 
779
                        g_pIndicatorSurface[CAIRO_DOCK_VERTICAL] = cairo_dock_rotate_surface (
 
780
                                g_pIndicatorSurface[CAIRO_DOCK_HORIZONTAL],
 
781
                                pSourceContext,
 
782
                                g_fIndicatorWidth * fScale,
 
783
                                g_fIndicatorHeight * fScale,
 
784
                                - G_PI / 2);
 
785
                else
 
786
                        cd_warning ("couldn't load image '%s' for indicators", cIndicatorImagePath);
 
787
        }
 
788
}
 
789
 
 
790
 
 
791
void cairo_dock_load_desktop_background_surface (void)  // attention : fonction lourde.
 
792
{
 
793
        cairo_surface_destroy (g_pDesktopBgSurface);
 
794
        g_pDesktopBgSurface = NULL;
 
795
        
 
796
        Pixmap iRootPixmapID = cairo_dock_get_window_background_pixmap (cairo_dock_get_root_id ());
 
797
        g_return_if_fail (iRootPixmapID != 0);
 
798
        
 
799
        GdkPixbuf *pBgPixbuf = cairo_dock_get_pixbuf_from_pixmap (iRootPixmapID, FALSE);  // on n'y ajoute pas de transparence.
 
800
        if (pBgPixbuf != NULL)
 
801
        {
 
802
                cairo_t *pSourceContext = cairo_dock_create_context_from_window (CAIRO_CONTAINER (g_pMainDock));
 
803
                
 
804
                if (gdk_pixbuf_get_height (pBgPixbuf) == 1 && gdk_pixbuf_get_width(pBgPixbuf) == 1)  // couleur unie.
 
805
                {
 
806
                        guchar *pixels = gdk_pixbuf_get_pixels (pBgPixbuf);
 
807
                        cd_message ("c'est une couleur unie (%.2f, %.2f, %.2f)", (double) pixels[0] / 255, (double) pixels[1] / 255, (double) pixels[2] / 255);
 
808
                        
 
809
                        g_pDesktopBgSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
 
810
                                CAIRO_CONTENT_COLOR_ALPHA,
 
811
                                g_iScreenWidth[CAIRO_DOCK_HORIZONTAL],
 
812
                                g_iScreenHeight[CAIRO_DOCK_HORIZONTAL]);
 
813
                        
 
814
                        cairo_t *pCairoContext = cairo_create (g_pDesktopBgSurface);
 
815
                        cairo_set_source_rgb (pCairoContext,
 
816
                                (double) pixels[0] / 255,
 
817
                                (double) pixels[1] / 255,
 
818
                                (double) pixels[2] / 255);
 
819
                        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
 
820
                        cairo_paint (pCairoContext);
 
821
                        cairo_destroy (pCairoContext);
 
822
                }
 
823
                else
 
824
                {
 
825
                        cairo_t *pSourceContext = cairo_dock_create_context_from_window (CAIRO_CONTAINER (g_pMainDock));
 
826
                        double fWidth, fHeight;
 
827
                        cairo_surface_t *pBgSurface = cairo_dock_create_surface_from_pixbuf (pBgPixbuf,
 
828
                                pSourceContext,
 
829
                                1,
 
830
                                0,
 
831
                                0,
 
832
                                FALSE,
 
833
                                &fWidth,
 
834
                                &fHeight,
 
835
                                NULL, NULL);
 
836
                        
 
837
                        if (fWidth < g_iScreenWidth[CAIRO_DOCK_HORIZONTAL] || fHeight < g_iScreenHeight[CAIRO_DOCK_HORIZONTAL])
 
838
                        {
 
839
                                cd_message ("c'est un degrade ou un motif (%dx%d)", (int) fWidth, (int) fHeight);
 
840
                                g_pDesktopBgSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
 
841
                                        CAIRO_CONTENT_COLOR_ALPHA,
 
842
                                        g_iScreenWidth[CAIRO_DOCK_HORIZONTAL],
 
843
                                        g_iScreenHeight[CAIRO_DOCK_HORIZONTAL]);
 
844
                                
 
845
                                cairo_t *pCairoContext = cairo_create (g_pDesktopBgSurface);
 
846
                                
 
847
                                cairo_pattern_t *pPattern = cairo_pattern_create_for_surface (pBgSurface);
 
848
                                g_return_if_fail (cairo_pattern_status (pPattern) == CAIRO_STATUS_SUCCESS);
 
849
                                cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_REPEAT);
 
850
                                
 
851
                                cairo_set_source (pCairoContext, pPattern);
 
852
                                cairo_paint (pCairoContext);
 
853
                                
 
854
                                cairo_destroy (pCairoContext);
 
855
                                cairo_pattern_destroy (pPattern);
 
856
                                cairo_surface_destroy (pBgSurface);
 
857
                        }
 
858
                        else
 
859
                        {
 
860
                                cd_message ("c'est un fond d'ecran de taille %dx%d", (int) fWidth, (int) fHeight);
 
861
                                g_pDesktopBgSurface = pBgSurface;
 
862
                        }
 
863
                        
 
864
                        g_object_unref (pBgPixbuf);
 
865
                }
 
866
                
 
867
                cairo_destroy (pSourceContext);
 
868
        }
 
869
}
 
870
 
 
871
void cairo_dock_invalidate_desktop_bg_surface (void)
 
872
{
 
873
        if (g_pDesktopBgSurface != NULL)
 
874
        {
 
875
                cairo_surface_destroy (g_pDesktopBgSurface);
 
876
                g_pDesktopBgSurface = NULL;
 
877
        }
 
878
}
 
879
 
 
880
cairo_surface_t *cairo_dock_get_desktop_bg_surface (void)
 
881
{
 
882
        if (g_pDesktopBgSurface == NULL)
 
883
                cairo_dock_load_desktop_background_surface ();
 
884
        return g_pDesktopBgSurface;
 
885
}
 
886
 
 
887
 
 
888
void cairo_dock_load_active_window_indicator (cairo_t* pSourceContext, const gchar *cImagePath, double fMaxScale, double fCornerRadius, double fLineWidth, double *fActiveColor)
 
889
{
 
890
        if (g_pActiveIndicatorSurface != NULL)
 
891
                cairo_surface_destroy (g_pActiveIndicatorSurface);
 
892
        g_fActiveIndicatorWidth = MAX (g_tIconAuthorizedWidth[CAIRO_DOCK_LAUNCHER], g_tIconAuthorizedWidth[CAIRO_DOCK_APPLI]);
 
893
        g_fActiveIndicatorHeight = MAX (g_tIconAuthorizedHeight[CAIRO_DOCK_APPLI], g_tIconAuthorizedHeight[CAIRO_DOCK_APPLI]);
 
894
        if (g_fActiveIndicatorWidth == 0)
 
895
                g_fActiveIndicatorWidth = 48;
 
896
        if (g_fActiveIndicatorHeight == 0)
 
897
                g_fActiveIndicatorHeight = 48;
 
898
        
 
899
        if (cImagePath != NULL)
 
900
        {
 
901
                g_pActiveIndicatorSurface = cairo_dock_create_surface_for_icon (cImagePath,
 
902
                        pSourceContext,
 
903
                        g_fActiveIndicatorWidth * fMaxScale,
 
904
                        g_fActiveIndicatorHeight * fMaxScale);
 
905
        }
 
906
        else if (fActiveColor[3] > 0)
 
907
        {
 
908
                g_pActiveIndicatorSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
 
909
                        CAIRO_CONTENT_COLOR_ALPHA,
 
910
                        g_fActiveIndicatorWidth * fMaxScale,
 
911
                        g_fActiveIndicatorHeight * fMaxScale);
 
912
                cairo_t *pCairoContext = cairo_create (g_pActiveIndicatorSurface);
 
913
                
 
914
                fCornerRadius = MIN (fCornerRadius, (g_fActiveIndicatorWidth * fMaxScale - fLineWidth) / 2);
 
915
                double fFrameWidth = g_fActiveIndicatorWidth * fMaxScale - (2 * fCornerRadius + fLineWidth);
 
916
                double fFrameHeight = g_fActiveIndicatorHeight * fMaxScale - 2 * fLineWidth;
 
917
                double fDockOffsetX = fCornerRadius + fLineWidth/2;
 
918
                double fDockOffsetY = fLineWidth/2;
 
919
                cairo_dock_draw_frame (pCairoContext, fCornerRadius, fLineWidth, fFrameWidth, fFrameHeight, fDockOffsetX, fDockOffsetY, 1, 0., CAIRO_DOCK_HORIZONTAL);
 
920
                
 
921
                cairo_set_source_rgba (pCairoContext, fActiveColor[0], fActiveColor[1], fActiveColor[2], fActiveColor[3]);
 
922
                if (fLineWidth > 0)
 
923
                {
 
924
                        cairo_set_line_width (pCairoContext, fLineWidth);
 
925
                        cairo_stroke (pCairoContext);
 
926
                }
 
927
                else
 
928
                {
 
929
                        cairo_fill (pCairoContext);
 
930
                }
 
931
                cairo_destroy (pCairoContext);
 
932
        }
 
933
        else  // invisible.
 
934
        {
 
935
                g_pActiveIndicatorSurface = NULL;
 
936
                return ;
 
937
        }
 
938
}