Ignore:
Timestamp:
Feb 27, 2003, 3:22:45 PM (22 years ago)
Author:
sandervl
Message:

PF: Illegal PM sequence of maximizing from icon state corrected. Inter-thread controls change caused PM lockups. Rewrote PM window frame controls manipulation procedure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/oslibwin.cpp

    r9810 r9866  
    1 /* $Id: oslibwin.cpp,v 1.139 2003-02-16 15:31:10 sandervl Exp $ */
     1/* $Id: oslibwin.cpp,v 1.140 2003-02-27 14:22:42 sandervl Exp $ */
    22/*
    33 * Window API wrappers for OS/2
     
    567567  return WinWindowFromPoint((hwnd == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP : hwnd, (PPOINTL)ppoint, TRUE);
    568568}
     569
     570//******************************************************************************
     571//@PF This is exactly that weird message PM sends when we maximize window from
     572//icon - this coordinates NEVER surface later and this combination of SWP
     573//commands is useless, yet it starts the correct reaction of maximiztion from
     574//icon state
     575//******************************************************************************
     576BOOL OSLibWinRestoreWindow(HWND hwnd)
     577{
     578 BOOL rc = WinSetWindowPos(hwnd, 0, -32000, 32000, 32000, 32000 , SWP_MAXIMIZE | SWP_RESTORE | SWP_ACTIVATE);
     579 return (rc);
     580}
     581
    569582//******************************************************************************
    570583//******************************************************************************
     
    972985//******************************************************************************
    973986//******************************************************************************
     987//PF: PM Logic approved by numerous testcases shows this:
     988//There is no other way to tweak FID_MINMAX without deleting it
     989//Controls are created with size 0,0, invisible and should be immediately
     990//positioned. MINMAX control can't function properly without FID_SYSMENU
     991//control if it is present, so we need to recreate BOTH controls.
     992//Currently OSLibSetWindowStyle checks for changes and actually do the job
     993//only when it is needed so no additional messages are generated.
     994//TO-DO: There MAY BE some regressions here but I haven't seen them
     995//and yes this code is the only way to do WinCreateFrame controls,
     996//first delete old then create new - all other variants create new and
     997//leave old, WinCreateFrameControls can't tweak anything.
     998
    974999void OSLibSetWindowStyle(HWND hwndFrame, HWND hwndClient, ULONG dwStyle,
    975                          ULONG dwExStyle)
     1000                         ULONG dwExStyle, ULONG dwOldWindowsStyle)
    9761001{
    9771002    ULONG dwWinStyle;
    9781003    ULONG dwOldWinStyle;
    9791004
    980     //client window:
    981     dwWinStyle    = WinQueryWindowULong(hwndClient, QWL_STYLE);
    982     dwOldWinStyle = dwWinStyle;
    983 
    984     if(dwStyle & WS_CLIPCHILDREN_W) {
    985          dwWinStyle |= WS_CLIPCHILDREN;
    986     }
    987     else dwWinStyle &= ~WS_CLIPCHILDREN;
    988 
    989     if(dwWinStyle != dwOldWinStyle) {
    990          WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
     1005    int checksum, checksum2;
     1006    DWORD dest_tid, dest_pid;
     1007
     1008    static int minmaxwidth  = 0;
     1009    static int minmaxheight = 0;
     1010
     1011
     1012    //PF We can tweak OS/2 controls ONLY from thread that created them
     1013    //in other case heavy PM lockups will follow
     1014
     1015    dest_tid = GetWindowThreadProcessId(OS2ToWin32Handle(hwndClient) , &dest_pid );
     1016
     1017    if (dest_tid != GetCurrentThreadId())
     1018    {
     1019        dprintf(("OSLibSetWindowStyle: Redirecting Change Frame controls to another thread"));
     1020        WinSendMsg(hwndFrame, WIN32APP_CHNGEFRAMECTRLS, (MPARAM)dwStyle, (MPARAM)dwOldWindowsStyle);
     1021        return;
     1022    }
     1023    if(minmaxwidth == 0) {
     1024        minmaxwidth  = WinQuerySysValue(HWND_DESKTOP, SV_CXMINMAXBUTTON);
     1025        minmaxheight = WinQuerySysValue(HWND_DESKTOP, SV_CYMINMAXBUTTON);
     1026    }
     1027 
     1028    if (hwndClient)
     1029    {
     1030      //client window:
     1031      dwWinStyle    = WinQueryWindowULong(hwndClient, QWL_STYLE);
     1032      dwOldWinStyle = dwWinStyle;
     1033
     1034      if(dwStyle & WS_CLIPCHILDREN_W) {
     1035          dwWinStyle |= WS_CLIPCHILDREN;
     1036      }
     1037      else dwWinStyle &= ~WS_CLIPCHILDREN;
     1038
     1039      if(dwWinStyle != dwOldWinStyle) {
     1040           WinSetWindowULong(hwndClient, QWL_STYLE, dwWinStyle);
     1041      }
    9911042    }
    9921043
     
    9941045    dwWinStyle    = WinQueryWindowULong(hwndFrame, QWL_STYLE);
    9951046    dwOldWinStyle = dwWinStyle;
     1047
     1048    checksum =  (dwOldWindowsStyle & WS_MINIMIZEBOX_W) + (dwOldWindowsStyle & WS_MAXIMIZEBOX_W) + (dwOldWindowsStyle & WS_SYSMENU_W);
     1049    checksum2 =  (dwStyle & WS_MINIMIZEBOX_W) + (dwStyle & WS_MAXIMIZEBOX_W) + (dwStyle & WS_SYSMENU_W);
     1050
    9961051    if(dwStyle & WS_DISABLED_W) {
    9971052         dwWinStyle |= WS_DISABLED;
     
    10171072         dwWinStyle |= WS_MAXIMIZED;
    10181073    }
    1019     else dwWinStyle &= ~WS_MAXIMIZED;
    1020 
    1021     if(dwWinStyle != dwOldWinStyle) {
    1022          WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
    1023     }
     1074    else
     1075      dwWinStyle &= ~WS_MAXIMIZED;
     1076
    10241077    if(fOS2Look) {
    10251078        ULONG OSFrameStyle = 0;
     1079        SWP rc1,rc2,rc3;
     1080        int totalwidth = 0;
     1081
    10261082        if((dwStyle & WS_CAPTION_W) == WS_CAPTION_W)
    10271083        {
     
    10291085                OSFrameStyle = FCF_TITLEBAR;
    10301086            }
    1031            
     1087            else
     1088              WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR), &rc1);           
     1089
    10321090            if((dwStyle & WS_SYSMENU_W) && !(dwExStyle & WS_EX_TOOLWINDOW_W))
    10331091            {
    1034                 if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0) {
    1035                     OSFrameStyle |= FCF_SYSMENU;
    1036                 }
     1092              if(WinWindowFromID(hwndFrame, FID_SYSMENU) == 0)
     1093                OSFrameStyle |= FCF_SYSMENU;
    10371094            }
    1038 
    1039             if((dwStyle & WS_MINIMIZEBOX_W) || (dwStyle & WS_MAXIMIZEBOX_W))
     1095            WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU), &rc2);
     1096            WinQueryWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX), &rc3);
     1097
     1098            if (checksum != checksum2)
    10401099            {
    1041                 HWND hwndMinMax = WinWindowFromID(hwndFrame, FID_MINMAX);
    1042                 if(dwStyle & WS_MINIMIZEBOX_W) {
    1043                     if(hwndMinMax == 0) {
    1044                          OSFrameStyle |= FCF_MINBUTTON;
    1045                     }
    1046                     else {
    1047                         if(WinIsMenuItemValid(hwndMinMax, SC_MINIMIZE) == FALSE) {
    1048                             //recreate mimize button
    1049 //TODO: this method doesn't work (hang during destruction probably)
    1050 //                            OSFrameStyle |= FCF_MINBUTTON;
    1051                         }
    1052                     }
    1053                 }
    1054                 else
    1055                 if(hwndMinMax) {
    1056                     WinSendMsg(hwndMinMax, MM_REMOVEITEM, MPFROM2SHORT(SC_MINIMIZE, TRUE), NULL);
    1057                 }
    1058 
    1059                 if(dwStyle & WS_MAXIMIZEBOX_W) {
    1060                     if(hwndMinMax == 0) {
    1061                         OSFrameStyle |= FCF_MAXBUTTON;
    1062                     }
    1063                     else {
    1064                         if(WinIsMenuItemValid(hwndMinMax, SC_MAXIMIZE) == FALSE) {
    1065                             //recreate maximize button
    1066 //TODO: this method doesn't work (hang during destruction probably)
    1067 //                            OSFrameStyle |= FCF_MAXBUTTON;
    1068                         }
    1069                     }
    1070                 }
    1071                 else
    1072                 if(hwndMinMax) {
    1073                     WinSendMsg(hwndMinMax, MM_REMOVEITEM, MPFROM2SHORT(SC_MAXIMIZE, TRUE), NULL);
    1074                 }
    1075             }
    1076             else
    1077             if(dwStyle & WS_SYSMENU_W) {
    1078                 if(WinWindowFromID(hwndFrame, FID_MINMAX) == 0) {
    1079                     OSFrameStyle |= FCF_CLOSEBUTTON;
    1080                 }
     1100              dprintf(("OSLibSetWindowStyle: Min/Max/Close state changed. Creating:"));
     1101              if(dwStyle & WS_MINIMIZEBOX_W)
     1102              {
     1103                  OSFrameStyle |= FCF_MINBUTTON;
     1104                  totalwidth += minmaxwidth/2;
     1105                  dprintf(("min button"));
     1106              }
     1107
     1108              if(dwStyle & WS_MAXIMIZEBOX_W)
     1109              {
     1110                  OSFrameStyle |= FCF_MAXBUTTON;
     1111                  totalwidth += minmaxwidth/2;
     1112                  dprintf(("max button"));
     1113              }
     1114
     1115              if(dwStyle & WS_SYSMENU_W)
     1116              {
     1117                  OSFrameStyle |= FCF_CLOSEBUTTON;
     1118                  OSFrameStyle |= FCF_SYSMENU;                   
     1119                  totalwidth += minmaxwidth/2;
     1120                  dprintf(("close button"));
     1121              }
    10811122            }
    10821123       }
    1083        // no caption, delete all controls if they exist
    10841124       else
    10851125       {
    10861126          if (WinWindowFromID(hwndFrame, FID_TITLEBAR))
    10871127              WinDestroyWindow(WinWindowFromID(hwndFrame, FID_TITLEBAR));
    1088           if (WinWindowFromID(hwndFrame, FID_SYSMENU))
    1089               WinDestroyWindow(WinWindowFromID(hwndFrame, FID_SYSMENU));
    1090           if (WinWindowFromID(hwndFrame, FID_MINMAX))
    1091               WinDestroyWindow(WinWindowFromID(hwndFrame, FID_MINMAX));
    10921128       }
    1093        
     1129
     1130       if (checksum != checksum2)
     1131       {
     1132         if (WinWindowFromID(hwndFrame, FID_SYSMENU))
     1133             WinDestroyWindow(WinWindowFromID(hwndFrame, FID_SYSMENU));
     1134         if (WinWindowFromID(hwndFrame, FID_MINMAX))
     1135             WinDestroyWindow(WinWindowFromID(hwndFrame, FID_MINMAX));
     1136       }
     1137
    10941138       if(OSFrameStyle) {
    10951139            FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
    10961140            char buffer[255];
     1141            dprintf(("Controls will be created %x",OSFrameStyle));
    10971142            FCData.flCreateFlags = OSFrameStyle;
    10981143
    10991144            GetWindowTextA(OS2ToWin32Handle(hwndClient), buffer, sizeof(buffer));
    11001145            WinCreateFrameControls(hwndFrame, &FCData, buffer );
     1146 
     1147            if (totalwidth != rc3.cx)
     1148            {
     1149              rc3.cx =  totalwidth;
     1150              totalwidth = rc3.cx - totalwidth;
     1151              rc1.cx = rc1.cx + totalwidth;
     1152              rc3.x = rc3.x + totalwidth;
     1153            }
     1154             
     1155            WinSetWindowPos(WinWindowFromID(hwndFrame, FID_MINMAX),0,rc3.x,rc3.y,rc3.cx,rc3.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);     
     1156            WinSetWindowPos(WinWindowFromID(hwndFrame, FID_SYSMENU),0,rc2.x,rc2.y,rc2.cx,rc2.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);     
     1157            WinSetWindowPos(WinWindowFromID(hwndFrame, FID_TITLEBAR),0,rc1.x,rc1.y,rc1.cx,rc1.cy, SWP_MOVE | SWP_SIZE | SWP_SHOW);     
    11011158
    11021159            if (WinQueryActiveWindow(HWND_DESKTOP) == hwndFrame)
     
    11051162       }
    11061163   } // os2look
     1164
     1165   if(dwWinStyle != dwOldWinStyle) {
     1166          dprintf(("Setting new window U long"));
     1167          WinSetWindowULong(hwndFrame, QWL_STYLE, dwWinStyle);
     1168   }
     1169
    11071170}
    11081171//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.