1 /* GTK - The GIMP Toolkit
2 * gtkwin32embed.c: Utilities for Win32 embedding
3 * Copyright (C) 2005, Novell, Inc.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /* By Tor Lillqvist <tml@novell.com> 2005 */
20
21 #include "config.h"
22
23 #include "win32/gdkwin32.h"
24
25 #include "gtkwin32embed.h"
26
27
28 static guint message_type[GTK_WIN32_EMBED_LAST];
29
30 static GSList *current_messages;
31
32 guint
_gtk_win32_embed_message_type(GtkWin32EmbedMessageType type)33 _gtk_win32_embed_message_type (GtkWin32EmbedMessageType type)
34 {
35 if (type < 0 || type >= GTK_WIN32_EMBED_LAST)
36 return 0;
37
38 if (message_type[type] == 0)
39 {
40 char name[100];
41 sprintf (name, "gtk-win32-embed:%d", type);
42 message_type[type] = RegisterWindowMessage (name);
43 }
44
45 return message_type[type];
46 }
47
48 void
_gtk_win32_embed_push_message(MSG * msg)49 _gtk_win32_embed_push_message (MSG *msg)
50 {
51 MSG *message = g_new (MSG, 1);
52
53 *message = *msg;
54
55 current_messages = g_slist_prepend (current_messages, message);
56 }
57
58 void
_gtk_win32_embed_pop_message(void)59 _gtk_win32_embed_pop_message (void)
60 {
61 MSG *message = current_messages->data;
62
63 current_messages = g_slist_delete_link (current_messages, current_messages);
64
65 g_free (message);
66 }
67
68 void
_gtk_win32_embed_send(GdkWindow * recipient,GtkWin32EmbedMessageType message,WPARAM wparam,LPARAM lparam)69 _gtk_win32_embed_send (GdkWindow *recipient,
70 GtkWin32EmbedMessageType message,
71 WPARAM wparam,
72 LPARAM lparam)
73 {
74 PostMessage (GDK_WINDOW_HWND (recipient),
75 _gtk_win32_embed_message_type (message),
76 wparam, lparam);
77 }
78
79 void
_gtk_win32_embed_send_focus_message(GdkWindow * recipient,GtkWin32EmbedMessageType message,WPARAM wparam)80 _gtk_win32_embed_send_focus_message (GdkWindow *recipient,
81 GtkWin32EmbedMessageType message,
82 WPARAM wparam)
83 {
84 int lparam = 0;
85
86 if (!recipient)
87 return;
88
89 g_return_if_fail (GDK_IS_WINDOW (recipient));
90 g_return_if_fail (message == GTK_WIN32_EMBED_FOCUS_IN ||
91 message == GTK_WIN32_EMBED_FOCUS_NEXT ||
92 message == GTK_WIN32_EMBED_FOCUS_PREV);
93
94 if (current_messages)
95 {
96 MSG *msg = current_messages->data;
97 if (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_IN) ||
98 msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_NEXT) ||
99 msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_PREV))
100 lparam = (msg->lParam & GTK_WIN32_EMBED_FOCUS_WRAPAROUND);
101 }
102
103 _gtk_win32_embed_send (recipient, message, wparam, lparam);
104 }
105
106 void
_gtk_win32_embed_set_focus_wrapped(void)107 _gtk_win32_embed_set_focus_wrapped (void)
108 {
109 MSG *msg;
110
111 g_return_if_fail (current_messages != NULL);
112
113 msg = current_messages->data;
114
115 g_return_if_fail (msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_PREV) ||
116 msg->message == _gtk_win32_embed_message_type (GTK_WIN32_EMBED_FOCUS_NEXT));
117
118 msg->lParam |= GTK_WIN32_EMBED_FOCUS_WRAPAROUND;
119 }
120
121 gboolean
_gtk_win32_embed_get_focus_wrapped(void)122 _gtk_win32_embed_get_focus_wrapped (void)
123 {
124 MSG *msg;
125
126 g_return_val_if_fail (current_messages != NULL, FALSE);
127
128 msg = current_messages->data;
129
130 return (msg->lParam & GTK_WIN32_EMBED_FOCUS_WRAPAROUND) != 0;
131 }
132