Win GUI fix: Blender won't hide behind the taskbar anymore on startup (in non maximiz...
authorDaniel Genrich <daniel.genrich@gmx.net>
Sun, 7 Jun 2009 23:36:34 +0000 (23:36 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sun, 7 Jun 2009 23:36:34 +0000 (23:36 +0000)
- Windows devs (elubie, jesterKing): please check this fix.

intern/ghost/intern/GHOST_WindowWin32.cpp

index ce1a42176bdeed4a4a0f80c306c0577960258ef5..3ba2cedcf82418f2a4aad4380539a2d1271c77c4 100644 (file)
@@ -117,16 +117,18 @@ GHOST_WindowWin32::GHOST_WindowWin32(
        m_maxPressure(0)
 {
        if (state != GHOST_kWindowStateFullScreen) {
-                       /* Convert client size into window size */
-               width += GetSystemMetrics(SM_CXSIZEFRAME)*2;
-               height += GetSystemMetrics(SM_CYSIZEFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
+               // take taskbar into account
+               RECT rect;
+               SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
+               height = rect.bottom - rect.top;
+               width = rect.right - rect.left;
 
                m_hWnd = ::CreateWindow(
                        s_windowClassName,                      // pointer to registered class name
                        title,                                          // pointer to window name
                        WS_OVERLAPPEDWINDOW,            // window style
-                       left,                                           // horizontal position of window
-                       top,                                            // vertical position of window
+                       rect.left,                                              // horizontal position of window
+                       rect.top,                                               // vertical position of window
                        width,                                          // window width
                        height,                                         // window height
                        0,                                                      // handle to parent or owner window
@@ -239,7 +241,7 @@ GHOST_WindowWin32::~GHOST_WindowWin32()
        if (m_wintab) {
                GHOST_WIN32_WTClose fpWTClose = ( GHOST_WIN32_WTClose ) ::GetProcAddress( m_wintab, "WTClose" );
                if (fpWTClose) {
-                       if (m_tablet) 
+                       if (m_tablet)
                                fpWTClose(m_tablet);
                        if (m_tabletData)
                                delete m_tabletData;
@@ -297,15 +299,17 @@ void GHOST_WindowWin32::getWindowBounds(GHOST_Rect& bounds) const
 void GHOST_WindowWin32::getClientBounds(GHOST_Rect& bounds) const
 {
        RECT rect;
-       ::GetWindowRect(m_hWnd, &rect);
 
        LONG_PTR result = ::GetWindowLongPtr(m_hWnd, GWL_STYLE);
        if((result & (WS_POPUP | WS_MAXIMIZE)) != (WS_POPUP | WS_MAXIMIZE)) {
+               SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
+
                bounds.m_b = rect.bottom-GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYSIZEFRAME)*2;
                bounds.m_l = rect.left;
                bounds.m_r = rect.right-GetSystemMetrics(SM_CYSIZEFRAME)*2;
                bounds.m_t = rect.top;
        } else {
+               ::GetWindowRect(m_hWnd, &rect);
                bounds.m_b = rect.bottom;
                bounds.m_l = rect.left;
                bounds.m_r = rect.right;
@@ -415,12 +419,12 @@ GHOST_TSuccess GHOST_WindowWin32::setState(GHOST_TWindowState state)
        wp.length = sizeof(WINDOWPLACEMENT);
        ::GetWindowPlacement(m_hWnd, &wp);
        switch (state) {
-       case GHOST_kWindowStateMinimized: 
-               wp.showCmd = SW_SHOWMINIMIZED; 
+       case GHOST_kWindowStateMinimized:
+               wp.showCmd = SW_SHOWMINIMIZED;
                break;
-       case GHOST_kWindowStateMaximized: 
+       case GHOST_kWindowStateMaximized:
                ShowWindow(m_hWnd, SW_HIDE);
-               wp.showCmd = SW_SHOWMAXIMIZED; 
+               wp.showCmd = SW_SHOWMAXIMIZED;
                SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
                break;
        case GHOST_kWindowStateFullScreen:
@@ -429,10 +433,10 @@ GHOST_TSuccess GHOST_WindowWin32::setState(GHOST_TWindowState state)
                wp.ptMaxPosition.y = 0;
                SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_POPUP | WS_MAXIMIZE);
                break;
-       case GHOST_kWindowStateNormal: 
-       default: 
+       case GHOST_kWindowStateNormal:
+       default:
                ShowWindow(m_hWnd, SW_HIDE);
-               wp.showCmd = SW_SHOWNORMAL; 
+               wp.showCmd = SW_SHOWNORMAL;
                SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
                break;
        }
@@ -490,7 +494,7 @@ GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextTyp
        switch (type) {
        case GHOST_kDrawingContextTypeOpenGL:
                {
-               if(m_stereoVisual) 
+               if(m_stereoVisual)
                        sPreferredFormat.dwFlags |= PFD_STEREO;
 
                // Attempt to match device context pixel format to the preferred format
@@ -627,7 +631,7 @@ void GHOST_WindowWin32::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
                        default:
                        success = false;
                }
-               
+
                if (success) {
                        ::SetCursor(::LoadCursor(0, id));
                }
@@ -660,7 +664,7 @@ void GHOST_WindowWin32::processWin32TabletInitEvent()
 {
        if (m_wintab) {
                GHOST_WIN32_WTInfo fpWTInfo = ( GHOST_WIN32_WTInfo ) ::GetProcAddress( m_wintab, "WTInfoA" );
-               
+
                // let's see if we can initialize tablet here
                /* check if WinTab available. */
                if (fpWTInfo) {
@@ -671,7 +675,7 @@ void GHOST_WindowWin32::processWin32TabletInitEvent()
                                m_maxPressure = Pressure.axMax;
                        else
                                m_maxPressure = 0;
-                       
+
                        BOOL tiltSupport = fpWTInfo (WTI_DEVICES, DVC_ORIENTATION, &Orientation);
                        if (tiltSupport) {
                                /* does the tablet support azimuth ([0]) and altitude ([1]) */
@@ -737,7 +741,7 @@ void GHOST_WindowWin32::processWin32TabletEvent(WPARAM wParam, LPARAM lParam)
                                                WACOM uses negative altitude values to show that the pen is inverted;
                                                therefore we cast .orAltitude as an (int) and then use the absolute value.
                                                */
-                                               
+
                                                /* convert raw fixed point data to radians */
                                                altRad = (float)((fabs((float)ort.orAltitude)/(float)m_maxAltitude) * M_PI/2.0);
                                                azmRad = (float)(((float)ort.orAzimuth/(float)m_maxAzimuth) * M_PI*2.0);
@@ -777,25 +781,25 @@ static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)
        shrt= ((shrt>>8)&0x00FF) | ((shrt<<8)&0xFF00);
        return shrt;
 }
-GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], 
+GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
                                        GHOST_TUns8 mask[16][2], int hotX, int hotY)
 {
-       return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*)mask, 
+       return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*)mask,
                                                                        16, 16, hotX, hotY, 0, 1);
 }
 
-GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, 
-                                       GHOST_TUns8 *mask, int sizeX, int sizeY, int hotX, int hotY, 
+GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(GHOST_TUns8 *bitmap,
+                                       GHOST_TUns8 *mask, int sizeX, int sizeY, int hotX, int hotY,
                                        int fg_color, int bg_color)
 {
        GHOST_TUns32 andData[32];
        GHOST_TUns32 xorData[32];
        GHOST_TUns32 fullBitRow, fullMaskRow;
        int x, y, cols;
-       
+
        cols=sizeX/8; /* Num of whole bytes per row (width of bm/mask) */
        if (sizeX%8) cols++;
-       
+
        if (m_customCursor) {
                DestroyCursor(m_customCursor);
                m_customCursor = NULL;
@@ -835,9 +839,9 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(GHOST_TUns8 *bitmap
 
 static int WeightPixelFormat(PIXELFORMATDESCRIPTOR& pfd) {
        int weight = 0;
-       
+
        /* assume desktop color depth is 32 bits per pixel */
-       
+
        /* cull unusable pixel formats */
        /* if no formats can be found, can we determine why it was rejected? */
        if( !(pfd.dwFlags & PFD_SUPPORT_OPENGL) ||
@@ -846,45 +850,45 @@ static int WeightPixelFormat(PIXELFORMATDESCRIPTOR& pfd) {
                ( pfd.cDepthBits <= 8 ) ||
                !(pfd.iPixelType == PFD_TYPE_RGBA) )
                return 0;
-       
+
        weight = 1;  /* it's usable */
-       
+
        /* the bigger the depth buffer the better */
        /* give no weight to a 16-bit depth buffer, because those are crap */
        weight += pfd.cDepthBits - 16;
-       
+
        weight += pfd.cColorBits - 8;
-       
+
        /* want swap copy capability -- it matters a lot */
        if(pfd.dwFlags & PFD_SWAP_COPY) weight += 16;
-       
+
        /* but if it's a generic (not accelerated) view, it's really bad */
        if(pfd.dwFlags & PFD_GENERIC_FORMAT) weight /= 10;
-       
+
        return weight;
 }
 
-/* A modification of Ron Fosner's replacement for ChoosePixelFormat */ 
+/* A modification of Ron Fosner's replacement for ChoosePixelFormat */
 /* returns 0 on error, else returns the pixel format number to be used */
 static int EnumPixelFormats(HDC hdc) {
        int iPixelFormat;
        int i, n, w, weight = 0;
        PIXELFORMATDESCRIPTOR pfd;
-       
+
        /* we need a device context to do anything */
        if(!hdc) return 0;
 
        iPixelFormat = 1; /* careful! PFD numbers are 1 based, not zero based */
-       
-       /* obtain detailed information about 
+
+       /* obtain detailed information about
        the device context's first pixel format */
-       n = 1+::DescribePixelFormat(hdc, iPixelFormat, 
+       n = 1+::DescribePixelFormat(hdc, iPixelFormat,
                sizeof(PIXELFORMATDESCRIPTOR), &pfd);
-       
+
        /* choose a pixel format using the useless Windows function in case
                we come up empty handed */
        iPixelFormat = ::ChoosePixelFormat( hdc, &sPreferredFormat );
-       
+
        if(!iPixelFormat) return 0; /* couldn't find one to use */
 
        for(i=1; i<=n; i++) { /* not the idiom, but it's right */
@@ -899,7 +903,7 @@ static int EnumPixelFormats(HDC hdc) {
                }
        }
        if (weight == 0) {
-               // we could find the correct stereo setting, just find any suitable format 
+               // we could find the correct stereo setting, just find any suitable format
                for(i=1; i<=n; i++) { /* not the idiom, but it's right */
                        ::DescribePixelFormat( hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd );
                        w = WeightPixelFormat(pfd);