~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to switcher/src/applet-load-icons.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

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
/************************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Cchumi & Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
************************************************************************************/
 
28
#include <string.h>
 
29
 
 
30
#include "applet-struct.h"
 
31
#include "applet-desktops.h"
 
32
#include "applet-load-icons.h"
 
33
#include "applet-draw.h"
 
34
 
 
35
 
 
36
static GList * _load_icons (void)
 
37
{
 
38
        GList *pIconList = NULL;
 
39
        int iIndex = cd_switcher_compute_index (myData.switcher.iCurrentDesktop, myData.switcher.iCurrentViewportX, myData.switcher.iCurrentViewportY);
 
40
        Icon *pIcon;
 
41
        int i;
 
42
        for (i = 0; i < myData.switcher.iNbViewportTotal; i ++)
 
43
        {
 
44
                pIcon = g_new0 (Icon, 1);
 
45
                
 
46
                if (i == iIndex)
 
47
                {
 
48
                        pIcon->acName = g_strdup_printf ("%s (%d)", D_("Current"), i+1);
 
49
                        pIcon->bHasIndicator = TRUE;
 
50
                        pIcon->fAlpha = .7;
 
51
                }
 
52
                else
 
53
                {
 
54
                        pIcon->acName = g_strdup_printf ("%s %d", D_("Desktop"), i+1);
 
55
                        pIcon->bHasIndicator = FALSE;
 
56
                        pIcon->fAlpha = 1.;
 
57
                }
 
58
                pIcon->cQuickInfo = g_strdup_printf ("%d",i+1);
 
59
                pIcon->fOrder = i;
 
60
                pIcon->fWidthFactor = 1.;
 
61
                pIcon->fHeightFactor = 1.;
 
62
                pIcon->acCommand = g_strdup ("none");
 
63
                pIcon->cParentDockName = g_strdup (myIcon->acName);
 
64
                pIcon->acFileName = (myConfig.bMapWallpaper ? NULL : (myConfig.cDefaultIcon != NULL ? g_strdup (myConfig.cDefaultIcon) : g_strdup (MY_APPLET_SHARE_DATA_DIR"/default.svg")));
 
65
                
 
66
                pIconList = g_list_append (pIconList, pIcon);
 
67
        }
 
68
        
 
69
        return pIconList;
 
70
}
 
71
 
 
72
 
 
73
 
 
74
void cd_switcher_load_icons (void)
 
75
{
 
76
        if (myConfig.bCompactView)
 
77
        {
 
78
                CD_APPLET_DELETE_MY_ICONS_LIST;
 
79
                if (myIcon->pSubDock != NULL)  // si on est passe de expanded a compact, le sous-dock vide reste.
 
80
                {
 
81
                        CD_APPLET_DESTROY_MY_SUBDOCK;
 
82
                }
 
83
                if (myDesklet)
 
84
                {
 
85
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
86
                }
 
87
                cd_switcher_load_default_map_surface ();
 
88
                
 
89
                cd_message ("SWITCHER : chargement de l'icone Switcher sans sous-dock");
 
90
        }
 
91
        else
 
92
        {
 
93
                //\_______________________ On cree la liste des icones de prevision.
 
94
                GList *pIconList = _load_icons ();
 
95
                
 
96
                /*//\_______________________ On efface l'ancienne liste.
 
97
                if (myIcon->pSubDock != NULL)
 
98
                {
 
99
                        g_list_foreach (myIcon->pSubDock->icons, (GFunc) cairo_dock_free_icon, NULL);
 
100
                        g_list_free (myIcon->pSubDock->icons);
 
101
                        myIcon->pSubDock->icons = NULL;
 
102
                }
 
103
                */
 
104
                //\_______________________ On charge la nouvelle liste.
 
105
                gpointer pConfig[2] = {GINT_TO_POINTER (myConfig.bDesklet3D), GINT_TO_POINTER (FALSE)};
 
106
                CD_APPLET_LOAD_MY_ICONS_LIST (pIconList, myConfig.cRenderer, "Caroussel", pConfig);
 
107
                /*if (myDock)
 
108
                {
 
109
                        if (myIcon->pSubDock == NULL)
 
110
                        {
 
111
                                if (pIconList != NULL)
 
112
                                {
 
113
                                        CD_APPLET_CREATE_MY_SUBDOCK (pIconList, myConfig.cRenderer);
 
114
                                }
 
115
                        }
 
116
                        else  // on a deja notre sous-dock, on remplace juste ses icones.
 
117
                        {
 
118
                                if (pIconList == NULL)  // inutile de le garder.
 
119
                                {
 
120
                                        CD_APPLET_DESTROY_MY_SUBDOCK;
 
121
                                        return ;
 
122
                                }
 
123
                                else
 
124
                                {
 
125
                                        CD_APPLET_LOAD_ICONS_IN_MY_SUBDOCK (pIconList);
 
126
                                }
 
127
                        }
 
128
                }
 
129
                else
 
130
                {
 
131
                        if (myIcon->pSubDock != NULL)
 
132
                        {
 
133
                                CD_APPLET_DESTROY_MY_SUBDOCK;
 
134
                        }
 
135
                        if (myDesklet->icons != NULL)  // si on recharge la liste a cause d'un changement de configuration du bureau.
 
136
                        {
 
137
                                g_list_foreach (myDesklet->icons, (GFunc) cairo_dock_free_icon, NULL);
 
138
                                g_list_free (myDesklet->icons);
 
139
                        }
 
140
                        myDesklet->icons = pIconList;
 
141
                        
 
142
                        gpointer pConfig[2] = {GINT_TO_POINTER (myConfig.bDesklet3D), GINT_TO_POINTER (FALSE)};
 
143
                        CD_APPLET_SET_DESKLET_RENDERER_WITH_DATA ("Caroussel", pConfig);
 
144
                }*/
 
145
                
 
146
                //\_______________________ On peint les icones.
 
147
                cd_switcher_paint_icons ();
 
148
        }
 
149
}
 
150
 
 
151
void cd_switcher_paint_icons (void)
 
152
{
 
153
        //\_______________________ On applique la surface.
 
154
        CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
 
155
        GList *pIconList = CD_APPLET_MY_ICONS_LIST;
 
156
        if (pIconList == NULL)
 
157
                return ;
 
158
        
 
159
        cairo_surface_t *pSurface = NULL;
 
160
        double fZoomX, fZoomY;
 
161
        Icon *pFirstIcon = pIconList->data;
 
162
        
 
163
        int iWidth, iHeight;
 
164
        cairo_dock_get_icon_extent (pFirstIcon, pContainer, &iWidth, &iHeight);
 
165
        
 
166
        if (myConfig.bMapWallpaper)
 
167
        {
 
168
                cd_switcher_draw_main_icon();
 
169
                pSurface = cairo_dock_get_desktop_bg_surface ();
 
170
                double fMaxScale = cairo_dock_get_max_scale (pContainer);
 
171
                fZoomX = 1. * iWidth / g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
 
172
                fZoomY = 1. * iHeight / g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
 
173
 
 
174
        }
 
175
        if (pSurface == NULL)
 
176
        {
 
177
                int _iWidth, _iHeight;
 
178
                CD_APPLET_GET_MY_ICON_EXTENT (&_iWidth, &_iHeight);
 
179
                cd_switcher_load_default_map_surface ();
 
180
                pSurface = myData.pDefaultMapSurface;
 
181
                fZoomX = 1. * iWidth / _iWidth;
 
182
                fZoomY = 1. * iHeight / _iHeight;
 
183
        }
 
184
        
 
185
        cairo_t *pIconContext;
 
186
        GList* ic;
 
187
        Icon *icon;
 
188
        for (ic = pIconList; ic != NULL; ic = ic->next)
 
189
        {
 
190
                icon = ic->data;
 
191
                //g_print (" (%.2f; %.2f) %.2fx%.2f\n", icon->fDrawX, icon->fDrawY, icon->fWidth, icon->fHeight);
 
192
                pIconContext = cairo_create (icon->pIconBuffer);
 
193
                cairo_scale (pIconContext,
 
194
                        fZoomX,
 
195
                        fZoomY);
 
196
 
 
197
                cairo_dock_set_icon_surface_with_reflect (pIconContext, pSurface, icon, pContainer);
 
198
                cairo_destroy (pIconContext);
 
199
        }
 
200
}
 
201
 
 
202
 
 
203
void cd_switcher_load_default_map_surface (void)
 
204
{
 
205
        g_return_if_fail (myDrawContext != NULL);
 
206
        if (myData.pDefaultMapSurface != NULL)
 
207
                cairo_surface_destroy (myData.pDefaultMapSurface);
 
208
        cd_debug ("%s (%.2fx%.2f)", __func__, myIcon->fWidth, myIcon->fHeight);
 
209
        myData.pDefaultMapSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (myConfig.cDefaultIcon);
 
210
}