Add:wince: Integrate ceglue aygshell and display power management
authorzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 23:42:27 +0000 (23:42 +0000)
committerzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 23:42:27 +0000 (23:42 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1602 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/win32/Makefile.am
navit/navit/gui/win32/ceglue.c [new file with mode: 0644]
navit/navit/gui/win32/ceglue.h [new file with mode: 0644]
navit/navit/gui/win32/gui_win32.c

index 2433df7..74bf724 100644 (file)
@@ -5,5 +5,5 @@ modulegui_LTLIBRARIES = libgui_win32.la
 else
 noinst_LTLIBRARIES = libgui_win32.la
 endif
-libgui_win32_la_SOURCES = gui_win32.c win32_gui_destination.c win32_gui_notify.c
+libgui_win32_la_SOURCES = gui_win32.c win32_gui_destination.c win32_gui_notify.c ceglue.h ceglue.c
 libgui_win32_la_LIBADD = 
diff --git a/navit/navit/gui/win32/ceglue.c b/navit/navit/gui/win32/ceglue.c
new file mode 100644 (file)
index 0000000..a0817f9
--- /dev/null
@@ -0,0 +1,77 @@
+#include <windows.h>\r
+#include "ceglue.h"\r
+\r
+BOOL FAR (*SHFullScreenPtr)(HWND hwnd, DWORD state) = NULL;\r
+\r
+void InitCeGlue (void)\r
+{\r
+  HINSTANCE ayg = LoadLibraryW (TEXT ("aygshell.dll"));\r
+  if (ayg != NULL) {\r
+    SHFullScreenPtr = (BOOL (*)(HWND, DWORD))\r
+      GetProcAddressW (ayg, TEXT ("SHFullScreen"));\r
+  }\r
+}\r
+\r
+// code to turn of screen adopted from\r
+// http://msdn.microsoft.com/en-us/library/ms838354.aspx\r
+\r
+// GDI Escapes for ExtEscape()\r
+#define QUERYESCSUPPORT    8\r
\r
+// The following are unique to CE\r
+#define GETVFRAMEPHYSICAL   6144\r
+#define GETVFRAMELEN    6145\r
+#define DBGDRIVERSTAT    6146\r
+#define SETPOWERMANAGEMENT   6147\r
+#define GETPOWERMANAGEMENT   6148\r
\r
\r
+typedef enum _VIDEO_POWER_STATE {\r
+    VideoPowerOn = 1,\r
+    VideoPowerStandBy,\r
+    VideoPowerSuspend,\r
+    VideoPowerOff\r
+} VIDEO_POWER_STATE, *PVIDEO_POWER_STATE;\r
\r
\r
+typedef struct _VIDEO_POWER_MANAGEMENT {\r
+    ULONG Length;\r
+    ULONG DPMSVersion;\r
+    ULONG PowerState;\r
+} VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;\r
+\r
+\r
+int CeEnableBacklight(int enable)\r
+{\r
+  HDC gdc;\r
+  int iESC=SETPOWERMANAGEMENT;\r
+\r
+  gdc = GetDC(NULL);\r
+  if (ExtEscape(gdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iESC, \r
+      0, NULL)==0)\r
+  {\r
+    MessageBox(NULL,\r
+                L"Sorry, your Pocket PC does not support DisplayOff",\r
+                L"Pocket PC Display Off Feature",\r
+              MB_OK);\r
+    ReleaseDC(NULL, gdc);\r
+    return FALSE;\r
+  }\r
+  else\r
+  {\r
+    VIDEO_POWER_MANAGEMENT vpm;\r
+    vpm.Length = sizeof(VIDEO_POWER_MANAGEMENT);\r
+    vpm.DPMSVersion = 0x0001;\r
+    if (enable) {\r
+      vpm.PowerState = VideoPowerOn;\r
+    } else {\r
+      vpm.PowerState = VideoPowerOff;\r
+    }\r
+    // Power off the display\r
+    ExtEscape(gdc, SETPOWERMANAGEMENT, vpm.Length, (LPCSTR) &vpm, \r
+              0, NULL);\r
+    ReleaseDC(NULL, gdc);\r
+    return TRUE;\r
+  }\r
+}\r
+\r
diff --git a/navit/navit/gui/win32/ceglue.h b/navit/navit/gui/win32/ceglue.h
new file mode 100644 (file)
index 0000000..b0dc79d
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef CEGLUE_H\r
+#define CEGLUE_H\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+extern BOOL (*SHFullScreenPtr)(HWND hwnd, DWORD state);\r
+void InitCeGlue (void);\r
+\r
+int CeEnableBacklight(int enable);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
index 4cab534..f8f7e20 100644 (file)
 #include "callback.h"
 #include <commctrl.h>
 #include "debug.h"
+#ifdef __CEGCC__
+#include <sipapi.h>
+#include <aygshell.h>
+#include "ceglue.h"
 
+static int ce_backlight = 1;
+static int ce_fullscreen;
+#endif
 
 #ifdef HAVE_GLIB
 //static GHashTable *popup_callback_hash = NULL;
@@ -189,6 +196,30 @@ static void window_layout( HWND hwnd )
        }
 #endif
 }
+#ifdef __CEGCC__
+static void toggle_fullscreen(HWND mWnd)
+{
+       if (SHFullScreenPtr) {
+               if (!ce_fullscreen) {
+                       (*SHFullScreenPtr)(mWnd, SHFS_HIDETASKBAR |
+                       SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);
+               } else {
+                       (*SHFullScreenPtr)(mWnd, SHFS_HIDESIPBUTTON);
+               }
+               ce_fullscreen = !ce_fullscreen;
+       }
+}
+
+static void toggle_backlight(void)
+{
+       if (ce_backlight)
+               if (CeEnableBacklight(FALSE))
+                       ce_backlight = 0;
+       else
+               if (CeEnableBacklight(TRUE))
+                       ce_backlight = 1;
+}
+#endif
 
 static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
 {
@@ -357,6 +388,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
                                navit_zoom_in(gui->nav, 2, NULL);
                        } else if (wParam == '3') {
                                navit_zoom_out(gui->nav, 2, NULL);
+                       } else if (wParam == '7') {
+                               toggle_backlight();
+                       } else if (wParam == '9') {
+                               toggle_fullscreen(hwnd);
                        }
                        }
                break;
@@ -584,6 +619,7 @@ static struct gui_priv *win32_gui_new( struct navit *nav, struct gui_methods *me
                InvalidateRect (prev, NULL, FALSE);
                exit(0);
        }
+       InitCeGlue();
 #endif
 
        *meth=win32_gui_methods;