2004/01/18 01:27:16
[org.ibex.core.git] / src / org / xwt / plat / Win32.cc
index 95fe5f7..c278998 100644 (file)
@@ -180,22 +180,31 @@ void org::xwt::plat::Win32::natInit() {
             sprintf(buf, "XWT_WINDOW_CLASS_%i", window_class_counter++);
 
             WNDCLASSEX wc;
-            wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
+            wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
             wc.lpfnWndProc = WndProc;
             wc.cbClsExtra = 0;
             wc.cbSize = sizeof(WNDCLASSEX);
             wc.cbWndExtra = 0;
             wc.hInstance = GetModuleHandle(NULL);
-            wc.hIcon = NULL;
-            wc.hIconSm = NULL;
-            wc.hCursor = NULL;
-            wc.hbrBackground = (HBRUSH)(COLOR_SCROLLBAR + 1);
-            wc.lpszMenuName = NULL;
+            wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+            wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
+                                          MAKEINTRESOURCE(5),
+                                          IMAGE_ICON,
+                                          GetSystemMetrics(SM_CXSMICON),
+                                          GetSystemMetrics(SM_CYSMICON),
+                                          LR_DEFAULTCOLOR);
+            wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+            wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+            wc.lpszMenuName = "menu";
             wc.lpszClassName = buf;
             RegisterClassEx(&wc);
+
+            surface->hwnd = (jint)CreateWindow(wc.lpszClassName, TEXT(""),
+                                               msg.wParam ? WS_NORMAL : WS_POPUP,
+                                               200, 200, 100, 100,
+                                               (HWND__*)NULL, (HMENU__*)NULL,
+                                               GetModuleHandle(NULL), (LPVOID)NULL);
             
-            surface->hwnd = (jint)CreateWindow(wc.lpszClassName, TEXT(""), msg.wParam ? WS_NORMAL : WS_POPUP, 200, 200, 100, 100,
-                                               (HWND__*)NULL, (HMENU__*)NULL, GetModuleHandle(NULL), (LPVOID)NULL);
             SetFocus((HWND)surface->hwnd);
             surface->hwndCreated->release();
             
@@ -354,12 +363,21 @@ static jint* scratch_bits = NULL;
 static jint scratch_w = 0;
 static jint scratch_h = 0;
 
+#define max(a,b) ((a)>(b)?(a):(b))
+#define min(a,b) ((a)<(b)?(a):(b))
+
 void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* source0,
                                                          jint dx, jint dy,
                                                          jint cx1, jint cy1, jint cx2, jint cy2,
                                                          jint rgb, jboolean alphaOnly) {
     org::xwt::plat::Win32$Win32Picture* source = (org::xwt::plat::Win32$Win32Picture*)source0;
 
+    cx1 = max(dx, cx1);
+    cy1 = max(dy, cy1);
+    cx2 = min(dx + source->getWidth(), cx2);
+    cy2 = min(dy + source->getHeight(), cy2);
+    if (cx1 >= cx2 || cy1 >= cy2) return; 
+
     if (source->hasalpha) {
 
         if (scratch == NULL || scratch_w < cx2 - cx1 || scratch_h < cy2 - cy1) {
@@ -403,16 +421,16 @@ void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* sour
             }
 
         // copy back from scratch to screen
-        BitBlt((HDC)hdc, cx1, cy1, cx2, cy2, (HDC)scratch_dc, 0, 0, SRCCOPY);
+        BitBlt((HDC)hdc, cx1, cy1, cx2 - cx1, cy2 - cy1, (HDC)scratch_dc, 0, 0, SRCCOPY);
 
     } else {
 
         // FIXME: support alphaOnly case here
         if (source->hasmask) {
-            BitBlt((HDC)hdc, cx1, cy1, cx2, cy2, (HDC)source->maskdc, cx1 - dx, cy1 - dy, SRCAND);
-            BitBlt((HDC)hdc, cx1, cy1, cx2, cy2, (HDC)source->hdc, cx1 - dx, cy1 - dy, SRCPAINT);
+            BitBlt((HDC)hdc, cx1, cy1, cx2 - cx1, cy2 - cy1, (HDC)source->maskdc, cx1 - dx, cy1 - dy, SRCAND);
+            BitBlt((HDC)hdc, cx1, cy1, cx2 - cx1, cy2 - cy1, (HDC)source->hdc, cx1 - dx, cy1 - dy, SRCPAINT);
         } else {
-            BitBlt((HDC)hdc, cx1, cy1, cx2, cy2, (HDC)source->hdc, cx1 - dx, cy1 - dy, SRCCOPY);
+            BitBlt((HDC)hdc, cx1, cy1, cx2 - cx1, cy2 - cy1, (HDC)source->hdc, cx1 - dx, cy1 - dy, SRCCOPY);
         }
 
     }
@@ -458,18 +476,18 @@ void org::xwt::plat::Win32$Win32Picture::natInit() {
     BITMAPINFO bitmapinfo;
     memset(&bitmapinfo, 0, sizeof(BITMAPINFO));
     bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
-    bitmapinfo.bmiHeader.biWidth = w;
-    bitmapinfo.bmiHeader.biHeight = -1 * h;
+    bitmapinfo.bmiHeader.biWidth = width;
+    bitmapinfo.bmiHeader.biHeight = -1 * height;
     bitmapinfo.bmiHeader.biPlanes = 1;
     bitmapinfo.bmiHeader.biBitCount = 32;
     bitmapinfo.bmiHeader.biCompression = BI_RGB;
 
-    hbitmap = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, w, h);
+    hbitmap = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, width, height);
     hdc = (jint)CreateCompatibleDC((HDC)org::xwt::plat::Win32::desktop_dc);
     SelectObject((HDC)hdc, (HBITMAP)hbitmap);
     uint32_t* dat = (uint32_t*)elements(data);
     for(int i=0; i<data->length; i++) if ((dat[i] & 0xFF000000) == 0x00000000) dat[i] = 0x00000000;
-    StretchDIBits((HDC)hdc, 0, 0, w, h, 0, 0, w, h, elements(data), &bitmapinfo, DIB_RGB_COLORS, SRCCOPY);
+    StretchDIBits((HDC)hdc, 0, 0, width, height, 0, 0, width, height, elements(data), &bitmapinfo, DIB_RGB_COLORS, SRCCOPY);
 
     jint _copy[min(1024, data->length)];
     jint* copy = data->length > 1024 ? (jint*)malloc(data->length * 4) : _copy;
@@ -494,10 +512,10 @@ void org::xwt::plat::Win32$Win32Picture::natInit() {
     }
 
     //    hmask = (jint)CreateBitmap(w, h, 1, 1, NULL);
-    hmask = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, w, h);
+    hmask = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, width, height);
     maskdc = (jint)CreateCompatibleDC(NULL);
     SelectObject((HDC)maskdc, (HBITMAP)hmask);
-    StretchDIBits((HDC)maskdc, 0, 0, w, h, 0, 0, w, h, copy, &bitmapinfo, DIB_RGB_COLORS, SRCCOPY);
+    StretchDIBits((HDC)maskdc, 0, 0, width, height, 0, 0, width, height, copy, &bitmapinfo, DIB_RGB_COLORS, SRCCOPY);
     if (data->length > 1024) free(copy);
 }
 
@@ -600,6 +618,7 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w
 
     int oldmousex, oldmousey;
     MINMAXINFO* mmi;
+    int resizable;
     POINT point;
     HWND hwnd2;
     RECT rect, rect2;
@@ -720,8 +739,9 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w
         mmi = (MINMAXINFO*)lParam;
         mmi->ptMinTrackSize.x = ((uint32_t)root->minwidth) + addwidth;
         mmi->ptMinTrackSize.y = ((uint32_t)root->minheight) + addheight;
-        mmi->ptMaxTrackSize.x = min(org::xwt::plat::Win32::getScreenWidth(), ((uint32_t)root->maxwidth) + addwidth);
-        mmi->ptMaxTrackSize.y = min(org::xwt::plat::Win32::getScreenHeight(), ((uint32_t)root->maxheight) + addheight);
+        resizable = !((root->minwidth == root->maxwidth) && (root->minheight == root->maxheight));
+        mmi->ptMaxTrackSize.x = resizable ? org::xwt::plat::Win32::getScreenWidth() : mmi->ptMinTrackSize.x;
+        mmi->ptMaxTrackSize.y = resizable ? org::xwt::plat::Win32::getScreenHeight() : mmi->ptMinTrackSize.y;
         return 0;
         
     case WM_PAINT: