Ignore:
Timestamp:
Jul 14, 1999, 10:35:38 AM (26 years ago)
Author:
sandervl
Message:

Very preliminary code for Open32 replacement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/pmwindow.cpp

    r4 r300  
    1 /* $Id: pmwindow.cpp,v 1.1 1999-05-24 20:20:04 ktk Exp $ */
    2 
     1/* $Id: pmwindow.cpp,v 1.2 1999-07-14 08:35:35 sandervl Exp $ */
    32/*
    43 * Win32 Window Managment Code for OS/2
    54 *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
     6 *
     7 *
     8 * Project Odin Software License can be found in LICENSE.TXT
    79 *
    810 */
     
    1113
    1214#include <os2.h>                        /* PM header file               */
    13 #include "misc.h"
    14 #include "win32wnd.h"
    15 #include "win32dlg.h"
     15#include <os2wrap.h>
     16#include "win32type.h"
     17#include <wprocess.h>
     18#include <misc.h>
     19#include <win32wnd.h>
     20#include <win32dlg.h>
     21#include "pmwindow.h"
     22#include "oslibwin.h"
    1623
    1724HMQ  hmq = 0;                             /* Message queue handle         */
     
    1926
    2027MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
    21 MRESULT EXPENTRY Win32DialogProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2);
    22 
    23 //******************************************************************************
    24 //Initialize PM; create hab, message queue and register special Win32 window class
     28
     29//******************************************************************************
     30//Initialize PM; create hab, message queue and register special Win32 window classes
    2531//******************************************************************************
    2632BOOL InitPM()
     
    3642  if(!WinRegisterClass(                 /* Register window class        */
    3743     hab,                               /* Anchor block handle          */
    38      (PSZ)"Win32Window",                /* Window class name            */
     44     (PSZ)WIN32_STDCLASS,               /* Window class name            */
    3945     (PFNWP)Win32WindowProc,            /* Address of window procedure  */
    4046     CS_SIZEREDRAW,                     /* Class style                  */
    41      4)) {
     47     8)) {
    4248        dprintf(("WinRegisterClass Win32Window failed"));
    4349        return(FALSE);
    4450   }
    4551
    46   if(!WinRegisterClass(                 /* Register window class        */
    47      hab,                               /* Anchor block handle          */
    48      (PSZ)"Win32Dialog",                /* Window class name            */
    49      (PFNWP)Win32DialogProc,            /* Address of window procedure  */
    50      CS_SIZEREDRAW,                     /* Class style                  */
    51      4)) {
    52         dprintf(("WinRegisterClass Win32Dialog failed"));
    53         return(FALSE);
    54    }
    55 
    5652   return(TRUE);
    5753} /* End of main */
     
    6157MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    6258{
    63  Win32Window *win32wnd = (Win32Window *)WinQueryWindowULong(hwnd, 0);
    64  MRESULT      rc;
    65 
     59 Win32Window  *win32wnd;
     60 ULONG         magic;
     61 APIRET        rc;
     62
     63  //Restore our FS selector
     64  SetWin32TIB();
     65
     66  win32wnd = (Win32Window *)WinQueryWindowULong(hwnd, OFFSET_WIN32WNDPTR);
     67  magic    = WinQueryWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
     68
     69  if(msg != WM_CREATE && win32wnd == NULL && magic != WIN32PM_MAGIC) {
     70        dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
     71        goto RunDefWndProc;
     72  }
    6673  switch( msg )
    67   {
     74  {     
    6875    case WM_CREATE:
    69         win32wnd = new Win32Window(hwnd, msg, mp1, mp2);
    70         if(win32wnd == NULL) {
    71                 dprintf(("new win32wnd failed!"));
    72         }
    73         if(WinSetWindowULong(hwnd, 0, (ULONG)win32wnd) == FALSE) {
    74                 dprintf(("WinSetWindowULong %X failed!!", hwnd));
    75         }
     76        //Processing is done in after WinCreateWindow returns
    7677        break;
    77 
     78       
     79    case WM_QUIT:
     80        if(win32wnd->MsgQuit()) {
     81                goto RunDefWndProc;
     82        }
     83        break;
     84       
     85    case WM_CLOSE:
     86        if(win32wnd->MsgClose()) {
     87                goto RunDefWndProc;
     88        }
     89        break;
     90
     91    case WM_DESTROY:
     92        if(win32wnd->MsgDestroy()) {
     93                goto RunDefWndProc;
     94        }
     95        break;
     96
     97    case WM_ENABLE:
     98        if(win32wnd->MsgEnable((ULONG)mp1)) {
     99                goto RunDefWndProc;
     100        }
     101        break;
     102
     103    case WM_SHOW:
     104        if(win32wnd->MsgShow((ULONG)mp1)) {
     105                goto RunDefWndProc;
     106        }
     107        break;
     108
     109    case WM_MOVE:
     110    {
     111     RECTL  rectl, rectl2;
     112     POINTL point;
     113     HWND   hwndParent;
     114     ULONG  xScreen, yScreen, yParent, xParent;
     115
     116        rc = WinQueryWindowRect(hwnd, &rectl);
     117        if(rc == TRUE) {
     118                point.x = rectl.xLeft;
     119                point.y = rectl.yBottom;
     120
     121                //If the window has a parent, calculate position relative to that window
     122                if((hwndParent = WinQueryWindow(hwnd, QW_PARENT)) != WinQueryDesktopWindow(hab, NULLHANDLE)) {
     123                        rc = WinMapWindowPoints(hwnd, hwndParent, &point, 1);
     124                        if(rc == FALSE) {
     125                                dprintf(("WM_MOVE: WinMapWindowPoints (parent) failed!"));
     126                                break;
     127                        }
     128                        rc = WinQueryWindowRect(hwndParent, &rectl2);
     129                        if(rc == FALSE) {
     130                                dprintf(("WM_MOVE: WinQueryWindowRect(HWND_DESKTOP, &rectl) failed!"));
     131                                break;
     132                        }
     133                        yParent = point.x;
     134                        yParent = OS2TOWIN32POINT(rectl2.yTop - rectl2.yBottom, point.y);
     135                }
     136                else    xParent = yParent = -1;
     137
     138                point.x = rectl.xLeft;
     139                point.y = rectl.yBottom;
     140
     141                rc = WinMapWindowPoints(hwnd, HWND_DESKTOP, &point, 1);
     142                if(rc == FALSE) {
     143                        dprintf(("WM_MOVE: WinMapWindowPoints (desktop) failed!"));
     144                        break;
     145                }
     146                rc = WinQueryWindowRect(HWND_DESKTOP, &rectl);
     147                if(rc == FALSE) {
     148                        dprintf(("WM_MOVE: WinQueryWindowRect(HWND_DESKTOP, &rectl) failed!"));
     149                        break;
     150                }
     151                xScreen = point.x;
     152                yScreen = OS2TOWIN32POINT(rectl.yTop - rectl.yBottom, point.y);
     153
     154                if(win32wnd->MsgMove(xScreen, yScreen, xParent, yParent)) {
     155                        goto RunDefWndProc;
     156                }
     157        }
     158        else {
     159                dprintf(("WM_MOVE: WinQueryWindowRect failed!"));
     160        }
     161        break;
     162    }
     163
     164    case WM_WINDOWPOSCHANGED:
     165    {
     166        break;
     167    }
     168
     169    case WM_ADJUSTWINDOWPOS:
     170    {
     171//      if(win32wnd->MsgWindowPosChanging(0, 0)) {
     172        break;
     173    }
     174
     175    case WM_ERASEBACKGROUND:
     176    {
     177     HPS hps;
     178
     179        hps = WinGetPS(hwnd);
     180        if(win32wnd->MsgEraseBackGround((ULONG)hps))
     181        {
     182                /*
     183                 * Return TRUE to request PM to paint the window background
     184                 * in SYSCLR_WINDOW.
     185                 */
     186                WinReleasePS(hps);
     187                return (MRESULT)( TRUE );
     188        }
     189        WinReleasePS(hps);
     190        return (MRESULT) FALSE;
     191    }
     192    case WM_SIZE:
     193    {
     194     SWP swp;
     195
     196        rc = WinQueryWindowPos(hwnd, &swp);
     197        if(rc == FALSE) {
     198                dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
     199                break;
     200        }
     201        if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
     202                                (swp.fl & SWP_MINIMIZE) != 0,
     203                                (swp.fl & SWP_MAXIMIZE) != 0))
     204        {
     205                goto RunDefWndProc;
     206        }
     207
     208        break;
     209    }
     210
     211    case WM_ACTIVATE:
     212    {
     213      HWND hwndActivate = (HWND)mp1;
     214
     215        if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
     216                //another (non-win32) application's window
     217                //set to NULL (allowed according to win32 SDK) to avoid problems
     218                hwndActivate = NULL;
     219        }
     220        if(win32wnd->MsgActivate(1, hwndActivate)) {
     221                goto RunDefWndProc;
     222        }
     223        break;
     224    }
     225    case WM_FOCUSCHANGE:
     226        break;
     227
     228    case WM_SETFOCUS:
     229    {
     230      HWND hwndFocus = (HWND)mp1;
     231
     232        if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
     233                //another (non-win32) application's window
     234                //set to NULL (allowed according to win32 SDK) to avoid problems
     235                hwndFocus = NULL;
     236        }
     237        if((ULONG)mp2 == TRUE) {
     238                rc = win32wnd->MsgSetFocus(hwndFocus);
     239        }
     240        else    rc = win32wnd->MsgKillFocus(hwndFocus);
     241        if(rc) {
     242                goto RunDefWndProc;
     243        }
     244        break;
     245    }
     246    //**************************************************************************
     247    //Mouse messages
     248    //**************************************************************************
     249    case WM_BUTTON1DOWN:
     250        if(win32wnd->MsgButton(BUTTON_LEFTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     251                goto RunDefWndProc;
     252        }
     253        break;
     254    case WM_BUTTON1UP:
     255        if(win32wnd->MsgButton(BUTTON_LEFTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     256                goto RunDefWndProc;
     257        }
     258        break;
     259    case WM_BUTTON1DBLCLK:
     260        if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     261                goto RunDefWndProc;
     262        }
     263        break;
     264    case WM_BUTTON2DOWN:
     265        if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     266                goto RunDefWndProc;
     267        }
     268        break;
     269    case WM_BUTTON2UP:
     270        if(win32wnd->MsgButton(BUTTON_RIGHTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     271                goto RunDefWndProc;
     272        }
     273        break;
     274    case WM_BUTTON2DBLCLK:
     275        if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
     276                goto RunDefWndProc;
     277        }
     278        break;
     279    case WM_BUTTON2MOTIONSTART:
     280    case WM_BUTTON2MOTIONEND:
     281    case WM_BUTTON2CLICK:
     282    case WM_BUTTON1MOTIONSTART:
     283    case WM_BUTTON1MOTIONEND:
     284    case WM_BUTTON1CLICK:
     285    case WM_BUTTON3DOWN:
     286    case WM_BUTTON3UP:
     287    case WM_BUTTON3DBLCLK:
     288    case WM_BUTTON3MOTIONSTART:
     289    case WM_BUTTON3MOTIONEND:
     290    case WM_BUTTON3CLICK:
     291        break;
     292
     293    case WM_MOUSEMOVE:
     294        break;
     295
     296    //**************************************************************************
     297    //Slider messages
     298    //**************************************************************************
     299    case WM_VSCROLL:
     300        break;
     301    case WM_HSCROLL:
     302        break;
     303
     304    case WM_CONTROL:
     305        break;
     306
     307    case WM_COMMAND:
     308    case WM_SYSCOMMAND:
     309        break;
     310
     311    case WM_CHAR:
     312        break;
     313
     314    case WM_INITMENU:
     315    case WM_MENUSELECT:
     316    case WM_MENUEND:
     317    case WM_NEXTMENU:
     318        break;
     319
     320    case WM_TIMER:
     321        break;
     322
     323    case WM_PAINT:
     324        if(win32wnd->MsgPaint(0, 0)) {
     325                goto RunDefWndProc;
     326        }
     327        break;
     328
     329    case WM_SYSCOLORCHANGE:
     330    case WM_SYSVALUECHANGED:
     331        break;
     332
     333    case WM_CALCVALIDRECTS:
     334    case WM_SETWINDOWPARAMS:
     335    case WM_QUERYWINDOWPARAMS:
     336    case WM_HITTEST:
     337    case WM_SETSELECTION:
     338    case WM_PPAINT:
     339    case WM_PSETFOCUS:
     340    case WM_PSYSCOLORCHANGE:
     341    case WM_PSIZE:
     342    case WM_PACTIVATE:
     343    case WM_PCONTROL:
     344    case WM_HELP:
     345    case WM_APPTERMINATENOTIFY:
     346    case WM_PRESPARAMCHANGED:
     347    case WM_DRAWITEM:
     348    case WM_MEASUREITEM:
     349    case WM_CONTROLPOINTER:
     350    case WM_QUERYDLGCODE:
     351    case WM_SUBSTITUTESTRING:
     352    case WM_MATCHMNEMONIC:
     353    case WM_SAVEAPPLICATION:
     354    case WM_SEMANTICEVENT:
     355        break;
    78356    default:
    79       /*
    80        * Everything else comes here.  This call MUST exist
    81        * in your window procedure.
    82        */
    83         if(win32wnd == NULL) {
    84                 dprintf(("Win32WindowProc: win32wnd NULL!"));
    85                 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
    86         }
    87 
    88         if(win32wnd->ProcessMessage(hwnd, msg, mp1, mp2, &rc) == TRUE) {
    89                 return(rc);
    90         }
    91         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
     357        RestoreOS2TIB();       
     358        return WinDefWindowProc( hwnd, msg, mp1, mp2 );
    92359  }
     360  RestoreOS2TIB();     
    93361  return (MRESULT)FALSE;
     362
     363RunDefWndProc:
     364  RestoreOS2TIB();     
     365  return WinDefWindowProc( hwnd, msg, mp1, mp2 );
    94366} /* End of Win32WindowProc */
    95367//******************************************************************************
    96 //Win32 dialog message handler
    97 //******************************************************************************
    98 MRESULT EXPENTRY Win32DialogProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
    99 {
    100  Win32Dialog *win32dlg = (Win32Dialog *)WinQueryWindowULong(hwndDlg, 0);
    101  MRESULT      rc;
    102 
    103   switch(msg)
    104   {
    105     case WM_INITDLG:
    106         win32dlg = new Win32Dialog(hwndDlg, msg, mp1, mp2);
    107         if(win32dlg == NULL) {
    108                 dprintf(("new win32dlg failed!"));
    109         }
    110         if(WinSetWindowULong(hwndDlg, 0, (ULONG)win32dlg) == FALSE) {
    111                 dprintf(("WinSetWindowULong %X failed!!", hwndDlg));
    112         }
    113         break;
    114 
    115     default:
    116       /*
    117        * Any event messages that the dialog procedure has not processed
    118        * come here and are processed by WinDefDlgProc.
    119        * This call MUST exist in your dialog procedure.
    120        */
    121         if(win32dlg == NULL) {
    122                 dprintf(("Win32DialogProc: win32dlg NULL!"));
    123                 return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
    124         }
    125         if(win32dlg->ProcessDlgMessage(hwndDlg, msg, mp1, mp2, &rc) == TRUE) {
    126                 return(rc);
    127         }
    128         return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
    129   }
    130   return (MRESULT) FALSE;
    131 }
    132 //******************************************************************************
    133 //******************************************************************************
     368//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.