commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r825029 - in /commons/sandbox/runtime/trunk/src/main/native/os/win32: gui.c main.rc
Date Wed, 14 Oct 2009 06:43:55 GMT
Author: mturk
Date: Wed Oct 14 06:43:54 2009
New Revision: 825029

URL: http://svn.apache.org/viewvc?rev=825029&view=rev
Log:
Add few Windows GUI methods

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/gui.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/gui.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/gui.c?rev=825029&r1=825028&r2=825029&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/gui.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/gui.c Wed Oct 14 06:43:54 2009
@@ -25,5 +25,171 @@
 #include "acr_tlsd.h"
 #include "acr_vm.h"
 
+#include <commdlg.h>
+#include <commctrl.h>
+#include <objbase.h>
+#include <shlobj.h>
+#include <shlwapi.h>
+#include <shellapi.h>
+#include <zmouse.h>
+#include <richedit.h>
+
+#pragma comment(lib, "comctl32.lib")
+
 /* GUI Windows functions
  */
+#define IDI_MAINICON 101
+#define MGUI_WINDOWS 32
+
+HICON            gui_h16Icon    = NULL;
+HICON            gui_h32Icon    = NULL;
+HICON            gui_h48Icon    = NULL;
+HMODULE          gui_hMSHTML    = NULL;
+HWND             gui_DialogWnd  = NULL;
+static HINSTANCE gui_hInstance  = NULL;
+static HWND      gui_hMainWnd   = NULL;
+static HMODULE   gui_hRichedit  = NULL;
+
+static UINT      gui_ucNumLines = 3;
+static CHAR      gui_szWndClass[MAX_PATH];
+
+
+static HWND     gui_Windows[MGUI_WINDOWS];
+
+int GuiRegisterWindow(HWND hWnd)
+{
+    int i;
+    for (i = 0; i < MGUI_WINDOWS; i++) {
+        if (!gui_Windows[i]) {
+            gui_Windows[i] = hWnd;
+            return i;
+        }
+    }
+    return -1;
+}
+
+void GuiUnregisterWindow(int nIndex)
+{
+    if (nIndex >= 0 && nIndex < MGUI_WINDOWS)
+        gui_Windows[nIndex] = NULL;
+}
+
+BOOL GuiInitialize()
+{
+    int i;
+    INITCOMMONCONTROLSEX stCmn;
+
+    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+    gui_hInstance = GetModuleHandle(NULL);
+    stCmn.dwSize  = sizeof(INITCOMMONCONTROLSEX);
+    stCmn.dwICC   = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES |
+                    ICC_COOL_CLASSES | ICC_NATIVEFNTCTL_CLASS |
+                    ICC_INTERNET_CLASSES | ICC_PAGESCROLLER_CLASS |
+                    ICC_BAR_CLASSES;
+
+    InitCommonControlsEx(&stCmn);
+    gui_hRichedit   = LoadLibraryA("RICHED32.DLL");
+    gui_hMSHTML     = LoadLibraryA("MSHTML.DLL");
+
+    gui_h16Icon     = LoadImage(gui_hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+                                IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
+    gui_h32Icon     = LoadImage(gui_hInstance, MAKEINTRESOURCE(IDI_MAINICON),
+                                IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
+
+    SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
+                         &gui_ucNumLines, 0);
+    for (i = 0; i < MGUI_WINDOWS; i++)
+        gui_Windows[i] = NULL;
+    return TRUE;
+}
+
+BOOL GuiTerminate()
+{
+    int i;
+    for (i = 0; i < MGUI_WINDOWS; i++) {
+        if (gui_Windows[i]) {
+            SendMessage(gui_Windows[i], WM_CLOSE, 0, 0);
+            gui_Windows[i] = NULL;
+        }
+    }
+    FreeLibrary(gui_hRichedit);
+    FreeLibrary(gui_hMSHTML);
+
+    return TRUE;
+}
+
+/**
+ * Load the resource string with the ID given, and return a
+ * pointer to it.  Notice that the buffer is common memory so
+ * the string must be used before this call is made a second time.
+ */
+LPSTR GuiLoadResource(
+    UINT wID,
+    UINT nBuf)
+{
+    static CHAR szBuf[4][ACR_MBUFF_SIZ];
+    if (nBuf > 3)
+        return "";
+    if (LoadStringA(gui_hInstance, wID, szBuf[nBuf], ACR_MBUFF_LEN) > 0)
+        return szBuf[nBuf];
+    else
+        return "";
+}
+
+void GuiCenterWindow(HWND hWnd)
+{
+   RECT    rc, rw;
+   int     cw, ch;
+   int     px, py;
+
+   /* Get the Height and Width of the child window */
+   GetWindowRect(hWnd, &rc);
+   cw = rc.right  - rc.left;
+   ch = rc.bottom - rc.top;
+
+   /* Get the limits of the 'workarea' */
+   if (!SystemParametersInfo(SPI_GETWORKAREA,
+                             sizeof(RECT),
+                             &rw,
+                             0)) {
+      rw.left   = rw.top = 0;
+      rw.right  = GetSystemMetrics(SM_CXSCREEN);
+      rw.bottom = GetSystemMetrics(SM_CYSCREEN);
+   }
+
+   /* Calculate new X and Y position*/
+   px = (rw.right  - cw) / 2;
+   py = (rw.bottom - ch) / 2;
+   SetWindowPos(hWnd, HWND_TOP, px, py, 0, 0,
+                SWP_NOSIZE | SWP_SHOWWINDOW);
+}
+
+BOOL GuiBrowseForFolderW(HWND hWnd, LPCWSTR szTitle,
+                         LPWSTR szPath, int iFlags)
+{
+    BOOL rv = FALSE;
+
+    BROWSEINFOW bi;
+    ITEMIDLIST *il , *ir;
+    LPMALLOC    pMalloc;
+
+    memset(&bi, 0, sizeof(BROWSEINFOW));
+    SHGetSpecialFolderLocation(hWnd, CSIDL_DRIVES, &il);
+
+    bi.lpszTitle      = szTitle;
+    bi.pszDisplayName = szPath;
+    bi.hwndOwner      = hWnd;
+    bi.ulFlags        = iFlags;
+    bi.pidlRoot       = il;
+    if ((ir = SHBrowseForFolderW(&bi)) != NULL) {
+        SHGetPathFromIDListW(ir, szPath);
+        rv = TRUE;
+    }
+
+    if (SHGetMalloc(&pMalloc)) {
+        pMalloc->lpVtbl->Free(pMalloc, il);
+        pMalloc->lpVtbl->Release(pMalloc);
+    }
+    return rv;
+}
+

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc?rev=825029&r1=825028&r2=825029&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.rc Wed Oct 14 06:43:54 2009
@@ -74,6 +74,7 @@
 #define APP_FILEFLAGS STD_FILEFLAGS
 #endif
 
+#define IDI_MAINICON 101
 
 IDI_MAINICON         ICON                       "apache.ico"
 CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST  "commonc.manifest"



Mime
View raw message