aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlemort2008-01-21 09:50:11 +0000
committerlemort2008-01-21 09:50:11 +0000
commitcfcdf878e9b01161605f74f079119109dd07d4aa (patch)
treec2dab1ad8d25f4565c57478d288da3af196f9acf
parentf897309da7f5d145e504ccf427e8821cbda7c1e6 (diff)
downloadtkzinc-cfcdf878e9b01161605f74f079119109dd07d4aa.zip
tkzinc-cfcdf878e9b01161605f74f079119109dd07d4aa.tar.gz
tkzinc-cfcdf878e9b01161605f74f079119109dd07d4aa.tar.bz2
tkzinc-cfcdf878e9b01161605f74f079119109dd07d4aa.tar.xz
Ajout d'une pseudo-librairie de fonctions utiles au reparentage de fenetre. Le code a ete externalise pour ne pas polluer/allonger le code de Window.c
Cette pseudo librairie conteient des fonctions pour: - trouver une fenetre a partir de son nom - enlever/restaurer la decoration d'une fenetre - enlever une fenetre de la barre des taches
-rw-r--r--generic/WindowUtils.c269
-rw-r--r--generic/WindowUtils.h98
2 files changed, 367 insertions, 0 deletions
diff --git a/generic/WindowUtils.c b/generic/WindowUtils.c
new file mode 100644
index 0000000..37c2086
--- /dev/null
+++ b/generic/WindowUtils.c
@@ -0,0 +1,269 @@
+/*
+ * WindowUtils.c -- Implementation of routines to manipulate windows
+ *
+ * Authors : Christophe Berthuet, Alexandre Lemort
+ * Creation date : Fri oct 12 14:47:42 2007
+ *
+ */
+
+
+#include "WindowUtils.h"
+
+
+
+/*
+*************************************
+ *
+ * Platform specific functions
+ *
+ *************************************
+ */
+#ifdef _WIN32
+
+/*
+ *-----------------------------------
+ *
+ * Win32
+ *
+ *-----------------------------------
+ */
+
+/*
+ * Enumwindows callback struct
+ */
+typedef struct {
+ HWND window;
+ char *windowtitle;
+} EnumWindowsCallbackStruct;
+
+
+/*
+ * EnumWindows Callback
+ */
+BOOL CALLBACK SearchWindowCallback(HWND window, LPARAM userData)
+{
+ char windowTitle[1024];
+ EnumWindowsCallbackStruct *myStruct = (EnumWindowsCallbackStruct *)userData;
+
+ /* Get title of our window */
+ GetWindowText(window, (LPSTR)windowTitle, 1024);
+
+ /* Test if we have found our window */
+ if (Tcl_StringMatch((const char*)windowTitle, myStruct->windowtitle)) {
+ /* we have found our window */
+ myStruct->window = window;
+
+ /* Exit EnumWindows */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Retrieves the window handler of a window identified by its title
+ */
+HWND SearchWindowByTitle_simple(char *title, Display *display, HWND root, int depth)
+{
+ return FindWindow(NULL, (LPCTSTR)title);
+}
+
+HWND SearchWindowByTitle(char *title, Display *display, HWND root, int depth)
+{
+ EnumWindowsCallbackStruct myStruct;
+ myStruct.window = NULL;
+ myStruct.windowtitle = title;
+
+ /* Try to find our window */
+ EnumWindows(SearchWindowCallback, (LPARAM)&myStruct);
+
+ /* Return result */
+ return myStruct.window;
+}
+
+
+/*
+ * Remove window decoration
+ */
+LONG removeWindowDecoration(HWND window)
+{
+ /* Get style of our window */
+ LONG previousWindowStyle = GetWindowLong(window, GWL_STYLE);
+ LONG windowStyle = previousWindowStyle;
+
+ /* Change style */
+ windowStyle &= WS_DLGFRAME;
+ windowStyle &= WS_CAPTION;
+ windowStyle &= WS_POPUP;
+ windowStyle |= WS_CHILD;
+
+ SetWindowLong(window, GWL_STYLE, windowStyle);//windowStyle);
+
+ /* Apply change */
+ /* NB: SetWindowPos parameters (HWND_BOTTOM, 0, 0, 100, 100) will not be applied */
+ /* SWP_NOZORDER inhibits HWND_BOTTOM */
+ /* SWP_NOMOVE inhibits 0, 0 */
+ /* SWP_NOSIZE inhibits 100, 100 */
+ /* SWP_FRAMECHANGED applies our new style */
+ SetWindowPos(window, HWND_BOTTOM, 0, 0, 100, 100, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
+
+ /* return previous style */
+ return previousWindowStyle;
+}
+
+
+/*
+ * Restore window style
+ */
+void restoreWindowStyle(HWND window, LONG windowStyle)
+{
+ /* Restore style */
+ SetWindowLong(window, GWL_STYLE, windowStyle);
+
+ /* Apply change */
+ /* NB: SetWindowPos parameters (HWND_BOTTOM, 0, 0, 100, 100) will not be applied */
+ /* SWP_NOZORDER inhibits HWND_BOTTOM */
+ /* SWP_NOMOVE inhibits 0, 0 */
+ /* SWP_NOSIZE inhibits 100, 100 */
+ /* SWP_FRAMECHANGED applies our new style */
+ SetWindowPos(window, HWND_BOTTOM, 0, 0, 100, 100, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
+}
+
+
+
+
+#else
+
+
+/*
+ *-----------------------------------
+ *
+ * Linux
+ *
+ *-----------------------------------
+ */
+
+
+/*
+ * Retrieves the window handler of a window identified by its title
+ */
+Window SearchWindowByTitle(char* wndTitle, Display *dpy, Window wndRoot, int depth)
+{
+ Window wndFound = 0;
+
+ // Variables used in the search
+ Window root_return;
+ Window parent_return;
+ Window *children_return = 0 ;
+ unsigned int nchildren_return = 0;
+
+ char msg[255];
+ int j = 0;
+
+ if( XQueryTree( dpy, wndRoot, &root_return, &parent_return, &children_return, &nchildren_return) != 0 )
+ {
+ XTextProperty text_prop_return;
+ for( j = 0; j < nchildren_return; j++ )
+ {
+ if( XGetWMName(dpy, children_return[j], &text_prop_return) != 0 )
+ {
+ if (Tcl_StringMatch(((const char *)(text_prop_return.value)), wndTitle))
+ {
+ // Window found !!
+ wndFound = children_return[j];
+ break;
+ }
+ else
+ {
+ wndFound = SearchWindowByTitle(wndTitle, dpy, children_return[j], depth + 1 );
+ if( wndFound != 0)
+ {
+ break;
+ }
+ }
+ }
+ else
+ {
+ wndFound = SearchWindowByTitle(wndTitle, dpy, children_return[j], depth + 1);
+ if( wndFound != 0)
+ {
+ break;
+ }
+ }
+ }
+ XFree( children_return );
+ }
+
+ return wndFound;
+}
+
+
+/*
+ * Get WM_STATE value of a window
+ */
+static int
+getWM_STATE (Display *display, Window window)
+{
+ int status = 0;
+ long state = 0;
+ static Atom aWM_STATE = 0;
+ Atom actual_type = 0;
+ int actual_format = 0;
+ unsigned long num_ret = 0, num_left = 0;
+ unsigned char *data = NULL;
+
+ if (!aWM_STATE) {
+ aWM_STATE = XInternAtom(display, "WM_STATE", False);
+ }
+
+ status = XGetWindowProperty (display, window, aWM_STATE, 0L, sizeof (long), False, aWM_STATE, &actual_type, &actual_format, &num_ret, &num_left, &data);
+
+ /*I should point out that Success is defined as 0 in X11*/
+ if ((status == Success) && (NULL != data)) {
+ state = *(long *)data;
+ } else {
+ state = -1;
+ }
+
+ if (data) {
+ XFree (data);
+ }
+ return state;
+}
+
+
+/*
+ * Withdraw a window from desktop
+ */
+void withdrawWindowFromDesktop (Display *display, Window window, int screenNum) {
+ int wm_state;
+
+ /* Try to withdraw window */
+ XWithdrawWindow (display, window, screenNum);
+ XSync (display, 0);
+
+ /* Test if we succeed. Otherwise, try until it works */
+ while ((wm_state = getWM_STATE (display, window)) != 0 && wm_state != -1) {
+ XSync (display, 0);
+ XWithdrawWindow (display, window, screenNum);
+ }
+}
+
+
+
+
+#endif /* ifdef _WIN32 */
+
+
+
+
+/*
+ ************************************
+ *
+ * Common functions
+ *
+ ************************************
+ */
+
+
diff --git a/generic/WindowUtils.h b/generic/WindowUtils.h
new file mode 100644
index 0000000..e641580
--- /dev/null
+++ b/generic/WindowUtils.h
@@ -0,0 +1,98 @@
+/*
+ * WindowUtils.h -- routines to manipulate windows
+ *
+ * Authors : Christophe Berthuet, Alexandre Lemort
+ * Creation date : Fri oct 12 14:47:42 2007
+ *
+ */
+
+
+#include "tkZinc.h"
+
+
+#ifdef _WIN32
+/* Windows */
+#include <windows.h>
+
+#else
+/* Linux */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#endif /* ifdef _WIN32 */
+
+
+
+
+
+
+
+/*
+*************************************
+ *
+ * Platform specific functions
+ *
+ *************************************
+ */
+#ifdef _WIN32
+
+/*
+ *-----------------------------------
+ *
+ * Win32
+ *
+ *-----------------------------------
+ */
+
+/*
+ * Retrieves the window handler of a window identified by its title
+ */
+HWND SearchWindowByTitle(char *title, Display *display, HWND root, int depth);
+
+
+/*
+ * Add/remove window decoration
+ */
+void restoreWindowStyle(HWND window, LONG windowStyle);
+LONG removeWindowDecoration(HWND window);
+
+
+
+#else
+
+
+/*
+ *-----------------------------------
+ *
+ * Linux
+ *
+ *-----------------------------------
+ */
+
+
+/*
+ * Retrieves the window handler of a window identified by its title
+ */
+Window SearchWindowByTitle(char *title, Display *display, Window root, int depth);
+
+
+/*
+ * Withdraw a window from desktop
+ */
+void withdrawWindowFromDesktop (Display *display, Window window, int screenNum);
+
+
+#endif /* ifdef _WIN32 */
+
+
+
+
+/*
+ ************************************
+ *
+ * Common functions
+ *
+ ************************************
+ */
+
+