comparison plugins/win32/transparency/win2ktrans.c @ 8961:92e061a1db10

[gaim-migrate @ 9735] (00:36:18) SimGuy: LSchiere: this is a patch to the wintrans plugin that does the following: (00:36:26) SimGuy: 1) Switches gaim_debug(FOO, ...) to gaim_debug_foo(...) (00:36:26) SimGuy: 2) Fixes a very old bug: (00:36:26) SimGuy: #781234 Transparency fails when dragging convo tab out of trans win (00:36:28) SimGuy: 3) Makes the preference changes take effect immediately, rather than only on new conversation windows, including enabling/disabling conversation window transparency and sliders. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 17 May 2004 04:39:14 +0000
parents 4b0b96196cfb
children 294ae6548d4e
comparison
equal deleted inserted replaced
8960:7c008d98ef33 8961:92e061a1db10
102 102
103 void set_wintrans_off(GtkWidget *window) { 103 void set_wintrans_off(GtkWidget *window) {
104 if(MySetLayeredWindowAttributes) { 104 if(MySetLayeredWindowAttributes) {
105 HWND hWnd = GDK_WINDOW_HWND(window->window); 105 HWND hWnd = GDK_WINDOW_HWND(window->window);
106 SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); 106 SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
107 107
108 /* Ask the window and its children to repaint */ 108 /* Ask the window and its children to repaint */
109 RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); 109 RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
110 } 110 }
111 } 111 }
112 112
163 } 163 }
164 164
165 gboolean win_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) { 165 gboolean win_destroy_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
166 slider_win *slidwin=NULL; 166 slider_win *slidwin=NULL;
167 /* Remove window from the window list */ 167 /* Remove window from the window list */
168 gaim_debug(GAIM_DEBUG_INFO, WINTRANS_PLUGIN_ID, "Conv window destoyed.. removing from list\n"); 168 gaim_debug_info(WINTRANS_PLUGIN_ID, "Conv window destoyed.. removing from list\n");
169 169
170 if((slidwin=find_slidwin(widget))) { 170 if((slidwin=find_slidwin(widget))) {
171 window_list = g_list_remove(window_list, (gpointer)slidwin); 171 window_list = g_list_remove(window_list, (gpointer)slidwin);
172 g_free(slidwin); 172 g_free(slidwin);
173 } 173 }
174 return FALSE; 174 return FALSE;
175 }
176
177 static void gaim_new_conversation(GaimConversation *c) {
178 GList *wl, *wl1;
179 GtkWidget *vbox=NULL;
180 GtkWidget *win=NULL;
181 GaimGtkConversation *gtkconv;
182 GaimGtkWindow *gtkwin;
183
184 gtkconv = GAIM_GTK_CONVERSATION(c);
185 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
186
187 win = gtkwin->window;
188
189 /* check prefs to see if we want trans */
190 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED) && gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) {
191 /* Look up this window to see if it already has a slider */
192 if(!find_slidwin(win)) {
193 GtkWidget *slider_box=NULL;
194 slider_win *slidwin=NULL;
195
196 /* Get top vbox */
197 for ( wl1 = wl = gtk_container_get_children(GTK_CONTAINER(win));
198 wl != NULL;
199 wl = wl->next ) {
200 if ( GTK_IS_VBOX(GTK_OBJECT(wl->data)) )
201 vbox = GTK_WIDGET(wl->data);
202 else {
203 gaim_debug(GAIM_DEBUG_ERROR, WINTRANS_PLUGIN_ID, "no vbox found\n");
204 return;
205 }
206 }
207 g_list_free(wl1);
208
209 slider_box = wintrans_slider(win);
210 gtk_box_pack_start(GTK_BOX(vbox),
211 slider_box,
212 FALSE, FALSE, 0);
213 /* Add window to list, to track that it has a slider */
214 slidwin = g_new0( slider_win, 1 );
215 slidwin->win = win;
216 slidwin->slider = slider_box;
217 window_list = g_list_append(window_list, (gpointer)slidwin);
218 /* Set callback to remove window from the list, if the window is destroyed */
219 g_signal_connect(GTK_OBJECT(win), "destroy_event", G_CALLBACK(win_destroy_cb), NULL);
220 }
221 else
222 return;
223 }
224
225 if(gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED) &&
226 !gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) {
227 set_wintrans(win, imalpha);
228 }
229 }
230
231 static void blist_created() {
232 if(blist) {
233 if(gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED))
234 set_wintrans(blist, blalpha);
235 else
236 set_wintrans_off(blist);
237 }
238 }
239
240 static void alpha_change(GtkWidget *w, gpointer data) {
241 int *alpha = (int*)data;
242 *alpha = gtk_range_get_value(GTK_RANGE(w));
243 }
244
245 static void alpha_pref_set_int(GtkWidget *w, GdkEventFocus *e, const char *pref) {
246 int alpha = 0;
247 if (pref == OPT_WINTRANS_IM_ALPHA)
248 alpha = imalpha;
249 else if (pref == OPT_WINTRANS_BL_ALPHA)
250 alpha = blalpha;
251
252 gaim_prefs_set_int(pref, alpha);
253 }
254
255 static void bl_alpha_change(GtkWidget *w, gpointer data) {
256 alpha_change(w, data);
257 if(blist)
258 change_alpha(w, blist);
259 } 175 }
260 176
261 static void set_trans_option(GtkWidget *w, const char *pref) { 177 static void set_trans_option(GtkWidget *w, const char *pref) {
262 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); 178 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));
263 if(pref == OPT_WINTRANS_BL_ENABLED) { 179 if(pref == OPT_WINTRANS_BL_ENABLED) {
268 set_wintrans_off(blist); 184 set_wintrans_off(blist);
269 } 185 }
270 } 186 }
271 } 187 }
272 188
189 static void add_slider(GtkWidget *win) {
190 GList *wl, *wl1;
191 GtkWidget *vbox=NULL;
192
193 /* Look up this window to see if it already has a slider */
194 if(!find_slidwin(win)) {
195 GtkWidget *slider_box=NULL;
196 slider_win *slidwin=NULL;
197
198 /* Get top vbox */
199 for ( wl1 = wl = gtk_container_get_children(GTK_CONTAINER(win));
200 wl != NULL;
201 wl = wl->next ) {
202 if ( GTK_IS_VBOX(GTK_OBJECT(wl->data)) )
203 vbox = GTK_WIDGET(wl->data);
204 else {
205 gaim_debug_error(WINTRANS_PLUGIN_ID, "no vbox found\n");
206 return;
207 }
208 }
209 g_list_free(wl1);
210
211 slider_box = wintrans_slider(win);
212 gtk_box_pack_start(GTK_BOX(vbox),
213 slider_box,
214 FALSE, FALSE, 0);
215 /* Add window to list, to track that it has a slider */
216 slidwin = g_new0( slider_win, 1 );
217 slidwin->win = win;
218 slidwin->slider = slider_box;
219 window_list = g_list_append(window_list, (gpointer)slidwin);
220 /* Set callback to remove window from the list, if the window is destroyed */
221 g_signal_connect(GTK_OBJECT(win), "destroy_event", G_CALLBACK(win_destroy_cb), NULL);
222 }
223 }
224
225 static void remove_sliders() {
226 if(window_list) {
227 GList *tmp=window_list;
228 while(tmp) {
229 slider_win *slidwin = (slider_win*)tmp->data;
230 gtk_widget_destroy(slidwin->slider);
231 g_free(slidwin);
232 tmp=tmp->next;
233 }
234 g_list_free(window_list);
235 window_list = NULL;
236 }
237 }
238
239 static void remove_convs_wintrans() {
240 GList *conv;
241
242 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next)
243 set_wintrans_off(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window);
244 }
245
246 static void update_convs_wintrans(GtkWidget *w, const char *pref) {
247 GList *conv;
248
249 if (w != NULL)
250 set_trans_option(w, pref);
251
252 if(gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) {
253 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next)
254 set_wintrans(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window, gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA));
255 }
256 else
257 remove_convs_wintrans();
258
259 if(gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)
260 && gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) {
261 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next)
262 add_slider(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window);
263 }
264 else
265 remove_sliders();
266 }
267
268 static void set_window_trans(GaimConvWindow *oldwin, GaimConvWindow *newwin) {
269 GtkWidget *win = GAIM_GTK_WINDOW(newwin)->window;
270
271 /* check prefs to see if we want trans */
272 if (gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED) && gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) {
273 add_slider(win);
274 }
275
276 if(gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED) &&
277 !gaim_prefs_get_bool(OPT_WINTRANS_IM_SLIDER)) {
278 set_wintrans(win, imalpha);
279 }
280 }
281
282 static void gaim_new_conversation(GaimConversation *c) {
283 GaimConvWindow *win = gaim_conversation_get_window(c);
284 set_window_trans(NULL, win);
285 }
286
287 static void blist_created() {
288 if(blist) {
289 if(gaim_prefs_get_bool(OPT_WINTRANS_BL_ENABLED))
290 set_wintrans(blist, blalpha);
291 else
292 set_wintrans_off(blist);
293 }
294 }
295
296 static void alpha_change(GtkWidget *w, gpointer data) {
297 int *alpha = (int*)data;
298 GList *conv;
299 *alpha = gtk_range_get_value(GTK_RANGE(w));
300
301 for(conv = gaim_get_conversations(); conv != NULL; conv = conv->next)
302 set_wintrans(GAIM_GTK_WINDOW(gaim_conversation_get_window(conv->data))->window, *alpha);
303 }
304
305 static void alpha_pref_set_int(GtkWidget *w, GdkEventFocus *e, const char *pref) {
306 int alpha = 0;
307 if (pref == OPT_WINTRANS_IM_ALPHA)
308 alpha = imalpha;
309 else if (pref == OPT_WINTRANS_BL_ALPHA)
310 alpha = blalpha;
311
312 gaim_prefs_set_int(pref, alpha);
313 }
314
315 static void bl_alpha_change(GtkWidget *w, gpointer data) {
316 alpha_change(w, data);
317 if(blist)
318 change_alpha(w, blist);
319 }
320
273 /* 321 /*
274 * EXPORTED FUNCTIONS 322 * EXPORTED FUNCTIONS
275 */ 323 */
276 G_MODULE_EXPORT gboolean plugin_load(GaimPlugin *plugin) { 324 G_MODULE_EXPORT gboolean plugin_load(GaimPlugin *plugin) {
277 imalpha = gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA); 325 imalpha = gaim_prefs_get_int(OPT_WINTRANS_IM_ALPHA);
283 GAIM_CALLBACK(gaim_new_conversation), 331 GAIM_CALLBACK(gaim_new_conversation),
284 NULL); 332 NULL);
285 gaim_signal_connect((void*)gaim_connections_get_handle(), "signed-on", plugin, GAIM_CALLBACK(blist_created), NULL); 333 gaim_signal_connect((void*)gaim_connections_get_handle(), "signed-on", plugin, GAIM_CALLBACK(blist_created), NULL);
286 MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" ); 334 MySetLayeredWindowAttributes = (void*)wgaim_find_and_loadproc("user32.dll", "SetLayeredWindowAttributes" );
287 335
336 gaim_signal_connect((void*)gaim_gtk_conversations_get_handle(), "conversation-drag-ended", plugin, GAIM_CALLBACK(set_window_trans), NULL);
337
338 update_convs_wintrans(NULL, NULL);
339
288 if(blist) { 340 if(blist) {
289 blist_created(); 341 blist_created();
290 } 342 }
291 343
292 return TRUE; 344 return TRUE;
293 } 345 }
294 346
295 G_MODULE_EXPORT gboolean plugin_unload(GaimPlugin *plugin) { 347 G_MODULE_EXPORT gboolean plugin_unload(GaimPlugin *plugin) {
296 gaim_debug(GAIM_DEBUG_INFO, WINTRANS_PLUGIN_ID, "Removing win2ktrans.dll plugin\n"); 348 gaim_debug_info(WINTRANS_PLUGIN_ID, "Removing win2ktrans.dll plugin\n");
297 349
298 /* Remove slider bars */ 350 remove_convs_wintrans();
299 if(window_list) { 351
300 GList *tmp=window_list;
301 while(tmp) {
302 slider_win *slidwin = (slider_win*)tmp->data;
303 gtk_widget_destroy(slidwin->slider);
304 set_wintrans_off(slidwin->win);
305 g_free(slidwin);
306 tmp=tmp->next;
307 }
308 g_list_free(window_list);
309 window_list = NULL;
310 }
311 if(blist) { 352 if(blist) {
312 set_wintrans_off(blist); 353 set_wintrans_off(blist);
313 } 354 }
314 return TRUE; 355 return TRUE;
315 } 356 }
326 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); 367 gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
327 368
328 /* IM Convo trans options */ 369 /* IM Convo trans options */
329 imtransbox = gaim_gtk_make_frame (ret, _("IM Conversation Windows")); 370 imtransbox = gaim_gtk_make_frame (ret, _("IM Conversation Windows"));
330 button = wgaim_button(_("_IM window transparency"), OPT_WINTRANS_IM_ENABLED, imtransbox); 371 button = wgaim_button(_("_IM window transparency"), OPT_WINTRANS_IM_ENABLED, imtransbox);
331 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (void *)OPT_WINTRANS_IM_ENABLED); 372 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(update_convs_wintrans), (void *)OPT_WINTRANS_IM_ENABLED);
332 373
333 trans_box = gtk_vbox_new(FALSE, 18); 374 trans_box = gtk_vbox_new(FALSE, 18);
334 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED)) 375 if (!gaim_prefs_get_bool(OPT_WINTRANS_IM_ENABLED))
335 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE); 376 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
336 gtk_widget_show(trans_box); 377 gtk_widget_show(trans_box);
337 378
338 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box); 379 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gaim_gtk_toggle_sensitive), trans_box);
339 380
340 button = wgaim_button(_("_Show slider bar in IM window"), OPT_WINTRANS_IM_SLIDER, trans_box); 381 button = wgaim_button(_("_Show slider bar in IM window"), OPT_WINTRANS_IM_SLIDER, trans_box);
341 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_trans_option), (void *)OPT_WINTRANS_IM_SLIDER); 382 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(update_convs_wintrans), (void *)OPT_WINTRANS_IM_SLIDER);
342 383
343 gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5); 384 gtk_box_pack_start(GTK_BOX(imtransbox), trans_box, FALSE, FALSE, 5);
344 385
345 /* IM transparency slider */ 386 /* IM transparency slider */
346 hbox = gtk_hbox_new(FALSE, 5); 387 hbox = gtk_hbox_new(FALSE, 5);
392 433
393 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5); 434 gtk_box_pack_start(GTK_BOX(trans_box), hbox, FALSE, FALSE, 5);
394 435
395 /* If this version of Windows dosn't support Transparency, grey out options */ 436 /* If this version of Windows dosn't support Transparency, grey out options */
396 if(!has_transparency()) { 437 if(!has_transparency()) {
397 gaim_debug(GAIM_DEBUG_WARNING, WINTRANS_PLUGIN_ID, "This version of windows dosn't support transparency\n"); 438 gaim_debug_warning(WINTRANS_PLUGIN_ID, "This version of windows dosn't support transparency\n");
398 gtk_widget_set_sensitive(GTK_WIDGET(imtransbox), FALSE); 439 gtk_widget_set_sensitive(GTK_WIDGET(imtransbox), FALSE);
399 gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE); 440 gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
400 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE); 441 gtk_widget_set_sensitive(GTK_WIDGET(trans_box), FALSE);
401 } 442 }
402 443