~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_userInterfaces/ADM_GTK/ADM_toolkit_gtk/eggtray_win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Borrowed from mldonkey
 
3
*/
 
4
/* Copyright 2004 b8_bavard, INRIA */
 
5
/*
 
6
    This file is part of mldonkey.
 
7
 
 
8
    mldonkey is free software; you can redistribute it and/or modify
 
9
    it under the terms of the GNU General Public License as published by
 
10
    the Free Software Foundation; either version 2 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    mldonkey is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU General Public License
 
19
    along with mldonkey; if not, write to the Free Software
 
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
*/
 
22
 
 
23
/* Stub code to interface with Shell_NotifyIcon */
 
24
#include <config.h>
 
25
#ifdef ADM_WIN32
 
26
#include <windows.h>
 
27
#include <wingdi.h>
 
28
 
 
29
#include <gdk/gdk.h> 
 
30
#include <gdk/gdkwin32.h>
 
31
#include <gdk-pixbuf/gdk-pixbuf.h>
 
32
 
 
33
#include <stdio.h>
 
34
#include <systray.h>
 
35
#define WM_TRAYMESSAGE           WM_USER /* User defined WM Message */
 
36
#define SYSTRAY_LBUTTONDBLCLK    0
 
37
#define SYSTRAY_LBUTTONCLK       1
 
38
#define SYSTRAY_RBUTTONCLK       2
 
39
 
 
40
static UINT timerID = 3;
 
41
static NOTIFYICONDATA nid;
 
42
static HWND systray_hwnd=0;
 
43
static HICON systray_hicon=0;
 
44
static int  win32egg_nb=0;
 
45
static GdkPixbuf **win32egg_pixbuf;
 
46
static int flipflop=0;
 
47
LRESULT msg_handler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
48
{
 
49
  static UINT taskbarRestartMsg; /* static here means value is kept across multiple calls to this func */
 
50
 
 
51
  switch(msg) {
 
52
    case WM_CREATE:
 
53
      taskbarRestartMsg = RegisterWindowMessage("TaskbarCreated");
 
54
      break;
 
55
 
 
56
    case WM_TIMER:
 
57
        #if 0
 
58
      KillTimer(hWnd, timerID);
 
59
      call_caml_systray_clicked(SYSTRAY_LBUTTONCLK);
 
60
      #endif
 
61
      break;
 
62
 
 
63
    case WM_DESTROY:
 
64
      break;
 
65
 
 
66
    case WM_TRAYMESSAGE:
 
67
#if 0
 
68
      switch (lParam) {
 
69
        case WM_RBUTTONUP:
 
70
          call_caml_systray_clicked(SYSTRAY_RBUTTONCLK);
 
71
          break;
 
72
 
 
73
        case WM_LBUTTONDBLCLK:
 
74
          KillTimer(hWnd, timerID);
 
75
          call_caml_systray_clicked(SYSTRAY_LBUTTONDBLCLK);
 
76
          break;
 
77
 
 
78
        case WM_LBUTTONDOWN:
 
79
          SetTimer(hWnd, timerID, GetDoubleClickTime(), NULL);
 
80
          break;
 
81
 
 
82
      }
 
83
#endif
 
84
    default: 
 
85
      if (msg == taskbarRestartMsg) {
 
86
        /* explorer crashed and left us hanging... 
 
87
           This will put the systray icon back in it's place, when it restarts */
 
88
        Shell_NotifyIcon(NIM_ADD,&nid);
 
89
      }
 
90
      break;
 
91
 
 
92
  }/* end switch */
 
93
 
 
94
  return DefWindowProc(hWnd, msg, wParam, lParam);
 
95
 
 
96
 
97
/* Create hidden window to process systray messages */
 
98
 
 
99
static HWND systray_create_hiddenwin(void)
 
100
{
 
101
 
 
102
  WNDCLASSEX wcex;
 
103
  TCHAR wname[32];
 
104
 
 
105
  strcpy(wname, "Win");
 
106
 
 
107
  wcex.cbSize = sizeof(WNDCLASSEX);
 
108
 
 
109
  wcex.style = 0;
 
110
  wcex.lpfnWndProc = (WNDPROC)msg_handler;
 
111
  wcex.cbClsExtra = 0;
 
112
  wcex.cbWndExtra = 0;
 
113
  wcex.hInstance = GetModuleHandle(NULL);
 
114
  wcex.hIcon = NULL;
 
115
  wcex.hCursor = NULL,
 
116
  wcex.hbrBackground = NULL;
 
117
  wcex.lpszMenuName = NULL;
 
118
  wcex.lpszClassName = wname;
 
119
  wcex.hIconSm = NULL;
 
120
 
 
121
  RegisterClassEx(&wcex);
 
122
 
 
123
  /* Create the window */
 
124
  return (CreateWindow(wname, "", 0, 0, 0, 0, 0, GetDesktopWindow(), NULL, GetModuleHandle(NULL), 0));
 
125
}
 
126
 
 
127
/* taken and modified from gdk/win32/gdkwindow-win32.c */
 
128
 
 
129
HICON pixmap_to_hicon (GdkPixmap *pixmap, GdkBitmap *mask)
 
130
{
 
131
  ICONINFO ii;
 
132
  HICON hIcon;
 
133
  gint w = 0, h = 0;
 
134
  HANDLE hpixmap = NULL;
 
135
  HBITMAP hbitmap = NULL;
 
136
 
 
137
  /* Create Drawing Context */
 
138
  HDC hdc1 = NULL;
 
139
  HBITMAP hbitmaptmp1 = NULL;
 
140
 
 
141
    if (!pixmap) {
 
142
      return NULL;
 
143
    }
 
144
 
 
145
    gdk_drawable_get_size (GDK_DRAWABLE (pixmap), &w, &h);
 
146
 
 
147
    hpixmap = gdk_win32_drawable_get_handle (pixmap); 
 
148
 
 
149
    /* we need the inverted mask for the XOR op */
 
150
    hdc1 = CreateCompatibleDC (NULL);
 
151
    hbitmap = CreateCompatibleBitmap (hdc1, w, h);
 
152
    hbitmaptmp1 = SelectObject (hdc1, hbitmap);
 
153
 
 
154
    if (mask) {
 
155
      HANDLE hmask = NULL;
 
156
      HDC hdc2 = NULL;
 
157
      HBITMAP hbitmaptmp2 = NULL;
 
158
 
 
159
      hmask = gdk_win32_drawable_get_handle (mask); 
 
160
 
 
161
      hdc2 = CreateCompatibleDC (NULL);
 
162
      hbitmaptmp2 = SelectObject (hdc2, hmask);
 
163
 
 
164
      BitBlt (hdc1, 0,0,w,h, hdc2, 0,0, NOTSRCCOPY);    
 
165
 
 
166
      SelectObject (hdc2, hbitmaptmp2);
 
167
      DeleteDC (hdc2);
 
168
    } else {
 
169
      RECT rect;
 
170
      GetClipBox (hdc1, &rect);
 
171
      FillRect (hdc1, &rect, GetStockObject (WHITE_BRUSH));
 
172
    }
 
173
 
 
174
    SelectObject (hdc1, hbitmaptmp1); 
 
175
    DeleteDC (hdc1); 
 
176
 
 
177
    ii.fIcon = TRUE;
 
178
    ii.xHotspot = ii.yHotspot = 0; /* ignored for icons */
 
179
    ii.hbmMask = hbitmap;
 
180
    ii.hbmColor = hpixmap; 
 
181
 
 
182
    hIcon = CreateIconIndirect (&ii);
 
183
    if (!hIcon) {
 
184
      return NULL;
 
185
    }
 
186
 
 
187
    DeleteObject (hbitmap);
 
188
 
 
189
    return hIcon;
 
190
}
 
191
 
 
192
NOTIFYICONDATA systray_init(GdkPixbuf *pixbuf,  char* text) 
 
193
{
 
194
  GdkPixmap *pm;
 
195
  GdkBitmap *mask;
 
196
 
 
197
  gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pm, &mask, 128);
 
198
 
 
199
  char* locenc=NULL;
 
200
 
 
201
  ZeroMemory(&nid,sizeof(nid));
 
202
  systray_hicon = pixmap_to_hicon (pm, mask);
 
203
  systray_hwnd = systray_create_hiddenwin();
 
204
 
 
205
  nid.cbSize=sizeof(NOTIFYICONDATA);
 
206
  nid.hWnd=systray_hwnd;
 
207
  nid.uID=0;
 
208
  nid.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP ;
 
209
  nid.uCallbackMessage=WM_TRAYMESSAGE;
 
210
  nid.hIcon=systray_hicon;
 
211
 
 
212
  if(text) {
 
213
    locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL);
 
214
    lstrcpy(nid.szTip, locenc);
 
215
    g_free(locenc);
 
216
  }
 
217
 
 
218
  Shell_NotifyIcon(NIM_ADD,&nid);
 
219
  return nid;
 
220
}
 
221
 
 
222
void systray_modify_icon (GdkPixmap *pm, GdkBitmap *mask) 
 
223
{
 
224
 
 
225
  systray_hicon = pixmap_to_hicon (pm, mask);
 
226
  nid.hIcon = systray_hicon;
 
227
  Shell_NotifyIcon(NIM_MODIFY,&nid);
 
228
}
 
229
 
 
230
void systray_modify_tooltip (const char* text) 
 
231
{
 
232
  char *locenc=NULL;
 
233
 
 
234
  if(text) {
 
235
    locenc = g_locale_from_utf8(text, -1, NULL, NULL, NULL);
 
236
    lstrcpy(nid.szTip, locenc);
 
237
    g_free(locenc);
 
238
  }
 
239
  Shell_NotifyIcon(NIM_MODIFY,&nid);
 
240
}
 
241
 
 
242
void systray_remove_nid(void) 
 
243
{
 
244
  DestroyWindow(nid.hWnd);
 
245
  Shell_NotifyIcon(NIM_DELETE,&nid);
 
246
}
 
247
//*********************************************************
 
248
//*********************************************************
 
249
//*********************************************************
 
250
void *adm_new_systray(GdkPixbuf *zpixbuf[],int nb, char *name)
 
251
{
 
252
void *r;
 
253
        flipflop=0;
 
254
        win32egg_pixbuf=zpixbuf;
 
255
        win32egg_nb=nb;
 
256
  systray_init(win32egg_pixbuf[0],  name);
 
257
  r=(void *)0xdead;
 
258
  return r;
 
259
 
 
260
}
 
261
void adm_delete_systray(void *systray)
 
262
{
 
263
 systray_remove_nid() ;
 
264
}
 
265
void adm_change_tooltip(void *systray, const char *tips)
 
266
{
 
267
    systray_modify_tooltip (tips ) ;
 
268
}
 
269
void adm_changeIcon_systray(void)
 
270
{
 
271
  GdkPixmap *pm;
 
272
  GdkBitmap *mask;
 
273
  GdkPixbuf *icon;
 
274
        flipflop=flipflop%win32egg_nb;
 
275
        icon=win32egg_pixbuf[flipflop];
 
276
        //ADM_assert(icon);
 
277
 
 
278
        gdk_pixbuf_render_pixmap_and_mask(icon, &pm, &mask, 128);
 
279
 
 
280
 
 
281
        systray_modify_icon (pm, mask) ;
 
282
 
 
283
                
 
284
        flipflop++;
 
285
        flipflop=flipflop%win32egg_nb;
 
286
}
 
287
#endif