Changeset 1526


Ignore:
Timestamp:
Oct 31, 1999, 2:14:44 AM (25 years ago)
Author:
sandervl
Message:

Window size + paint fix + dialog fixes

Location:
trunk/src/user32
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/user32/win32dlg.cpp

    r1525 r1526  
    1 /* $Id: win32dlg.cpp,v 1.25 1999-10-30 18:40:47 cbratschi Exp $ */
     1/* $Id: win32dlg.cpp,v 1.26 1999-10-31 01:14:42 sandervl Exp $ */
    22/*
    33 * Win32 Dialog Code for OS/2
     
    4646
    4747    dprintf(("********* CREATE DIALOG ************"));
    48     xUnit = getXBaseUnit();
    49     yUnit = getYBaseUnit();
     48    if(fInitialized == FALSE) {
     49        if(DIALOG_Init() == FALSE) {
     50            dprintf(("DIALOG_Init FAILED!"));
     51            DebugInt3();
     52            SetLastError(ERROR_GEN_FAILURE);
     53            return;
     54        }
     55        fInitialized = TRUE;
     56    }
     57    xUnit = xBaseUnit;
     58    yUnit = yBaseUnit;
    5059
    5160    /* Parse dialog template */
     
    227236    dprintf(("********* DIALOG CREATION FAILED! ************"));
    228237    return FALSE;
     238}
     239//******************************************************************************
     240//******************************************************************************
     241BOOL Win32Dialog::MapDialogRect(LPRECT rect)
     242{
     243    rect->left   = (rect->left * xUnit) / 4;
     244    rect->right  = (rect->right * xUnit) / 4;
     245    rect->top    = (rect->top * yUnit) / 8;
     246    rect->bottom = (rect->bottom * yUnit) / 8;
     247    return TRUE;
    229248}
    230249/***********************************************************************
     
    312331}
    313332/***********************************************************************
     333 *           DIALOG_Init
     334 *
     335 * Initialisation of the dialog manager.
     336 */
     337BOOL Win32Dialog::DIALOG_Init(void)
     338{
     339    HDC hdc;
     340    SIZE size;
     341
     342    /* Calculate the dialog base units */
     343    if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
     344    if (!getCharSizeFromDC( hdc, 0, &size )) return FALSE;
     345    DeleteDC( hdc );
     346    xBaseUnit = size.cx;
     347    yBaseUnit = size.cy;
     348
     349    return TRUE;
     350}
     351/***********************************************************************
     352 *           DIALOG_GetCharSizeFromDC
     353 *
     354 *
     355 *  Calculates the *true* average size of English characters in the
     356 *  specified font as oppposed to the one returned by GetTextMetrics.
     357 */
     358BOOL Win32Dialog::getCharSizeFromDC( HDC hDC, HFONT hUserFont, SIZE * pSize )
     359{
     360    BOOL Success = FALSE;
     361    HFONT hUserFontPrev = 0;
     362    pSize->cx = xBaseUnit;
     363    pSize->cy = yBaseUnit;
     364
     365    if ( hDC )
     366    {
     367        /* select the font */
     368        TEXTMETRICA tm;
     369        memset(&tm,0,sizeof(tm));
     370        if (hUserFont) hUserFontPrev = SelectFont(hDC,hUserFont);
     371        if (GetTextMetricsA(hDC,&tm))
     372        {
     373            pSize->cx = tm.tmAveCharWidth;
     374            pSize->cy = tm.tmHeight;
     375
     376            /* if variable width font */
     377            if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
     378            {
     379                SIZE total;
     380                static const char szAvgChars[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     381
     382                /* Calculate a true average as opposed to the one returned
     383                 * by tmAveCharWidth. This works better when dealing with
     384                 * proportional spaced fonts and (more important) that's
     385                 * how Microsoft's dialog creation code calculates the size
     386                 * of the font
     387                 */
     388                if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
     389                {
     390                   /* round up */
     391                    pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
     392                    Success = TRUE;
     393                }
     394            }
     395            else
     396            {
     397                Success = TRUE;
     398            }
     399        }
     400
     401        /* select the original font */
     402        if (hUserFontPrev) SelectFont(hDC,hUserFontPrev);
     403    }
     404    return (Success);
     405}
     406/***********************************************************************
     407 *           DIALOG_GetCharSize
     408 *
     409 *
     410 *  Calculates the *true* average size of English characters in the
     411 *  specified font as oppposed to the one returned by GetTextMetrics.
     412 *  A convenient variant of DIALOG_GetCharSizeFromDC.
     413 */
     414BOOL Win32Dialog::getCharSize( HFONT hUserFont, SIZE * pSize )
     415{
     416    HDC  hDC = GetDC(0);
     417    BOOL Success = getCharSizeFromDC( hDC, hUserFont, pSize );
     418    ReleaseDC(0, hDC);
     419    return Success;
     420}
     421/***********************************************************************
    314422 *           DIALOG_ParseTemplate32
    315423 *
     
    513621                                        (LPCWSTR)info.className,
    514622                                        (LPCWSTR)info.windowName,
    515                                         info.style | WS_CHILD | WS_CLIPSIBLINGS,
     623                                        info.style | WS_CHILD,
    516624                                        info.x * xUnit / 4,
    517625                                        info.y * yUnit / 8,
     
    537645                                        classNameA,
    538646                                        windowNameA,
    539                                         info.style | WS_CHILD | WS_CLIPSIBLINGS,
     647                                        info.style | WS_CHILD,
    540648                                        info.x * xUnit / 4,
    541649                                        info.y * yUnit / 8,
     
    9781086//******************************************************************************
    9791087//******************************************************************************
    980 
     1088BOOL Win32Dialog::fInitialized = FALSE;
     1089int  Win32Dialog::xBaseUnit    = 10;
     1090int  Win32Dialog::yBaseUnit    = 20;
  • TabularUnified trunk/src/user32/win32dlg.h

    r1525 r1526  
    1 /* $Id: win32dlg.h,v 1.6 1999-10-30 18:40:47 cbratschi Exp $ */
     1/* $Id: win32dlg.h,v 1.7 1999-10-31 01:14:42 sandervl Exp $ */
    22/*
    33 * Win32 Dialog Code for OS/2
     
    7171         BOOL   endDialog(int retval);
    7272
     73         BOOL   MapDialogRect(LPRECT rect);
     74
    7375virtual  ULONG  MsgCreate(HWND hwndFrame, HWND hwndClient);
    7476
    75 virtual  LONG   SetWindowLongA(int index, ULONG value);
    76 virtual  ULONG  GetWindowLongA(int index);
     77virtual  LONG   SetWindowLongA(int index, ULONG value);
     78virtual  ULONG  GetWindowLongA(int index);
    7779
    78            INT  doDialogBox();
     80static   ULONG  GetDialogBaseUnits()  { return MAKELONG(xBaseUnit, yBaseUnit); };
     81
     82           INT  doDialogBox();
    7983
    8084protected:
    81         LPCSTR  parseTemplate( LPCSTR dlgtemplate, DLG_TEMPLATE *result);
     85        BOOL    DIALOG_Init(void);
     86        BOOL    getCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize );
     87        BOOL    getCharSize( HFONT hFont, SIZE * pSize);
     88        LPCSTR  parseTemplate( LPCSTR dlgtemplate, DLG_TEMPLATE *result);
    8289        WORD   *getControl(const WORD *p, DLG_CONTROL_INFO *info, BOOL dialogEx);
    83         BOOL    createControls(LPCSTR dlgtemplate, HINSTANCE hInst);
    84 
    85         LRESULT DefDlg_Proc(UINT msg, WPARAM wParam, LPARAM lParam);
     90        BOOL    createControls(LPCSTR dlgtemplate, HINSTANCE hInst);
     91       
     92        LRESULT DefDlg_Proc(UINT msg, WPARAM wParam, LPARAM lParam);
    8693        LRESULT DefDlg_Epilog(UINT msg, BOOL fResult);
    8794
    88         BOOL    setDefButton(HWND hwndNew );
    89         HWND    findDefButton();
    90         BOOL    saveFocus();
    91         BOOL    restoreFocus();
    92         void    setFocus(HWND hwndCtrl );
     95        BOOL    setDefButton(HWND hwndNew );
     96        HWND    findDefButton();
     97        BOOL    saveFocus();
     98        BOOL    restoreFocus();
     99        void    setFocus(HWND hwndCtrl );
    93100
    94         // values normally contained in the standard dialog words
    95       DLGPROC   Win32DlgProc;   //DWL_WNDPROC
    96         ULONG   msgResult;      //DWL_MSGRESULT
    97         ULONG   userDlgData;    //DWL_USER
     101        // values normally contained in the standard dialog words
     102      DLGPROC   Win32DlgProc;   //DWL_WNDPROC
     103        ULONG   msgResult;      //DWL_MSGRESULT
     104        ULONG   userDlgData;    //DWL_USER
    98105
    99106   DLG_TEMPLATE dlgInfo;
    100         WORD    xUnit;
    101         WORD    yUnit;
    102         HWND    hwndFocus;
    103         HFONT   hUserFont;
    104         HMENU   hMenu;
    105         DWORD   idResult;
    106         DWORD   dialogFlags;
     107        WORD    xUnit;
     108        WORD    yUnit;
     109        HWND    hwndFocus;
     110        HFONT   hUserFont;
     111        HMENU   hMenu;
     112        DWORD   idResult;
     113        DWORD   dialogFlags;
    107114
    108         DWORD   tmpParam;       //set in ctor, used in MsgCreate method
    109         LPSTR   tmpDlgTemplate; //set in ctor, used in MsgCreate method
     115        DWORD   tmpParam;       //set in ctor, used in MsgCreate method
     116        LPSTR   tmpDlgTemplate; //set in ctor, used in MsgCreate method
     117private:
     118 static BOOL    fInitialized;
     119 static int     xBaseUnit;
     120 static int     yBaseUnit;
    110121};
    111122
  • TabularUnified trunk/src/user32/win32wbase.cpp

    r1525 r1526  
    1 /* $Id: win32wbase.cpp,v 1.69 1999-10-30 18:40:48 cbratschi Exp $ */
     1/* $Id: win32wbase.cpp,v 1.70 1999-10-31 01:14:42 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    1616 */
    1717#include <os2win.h>
    18 #include <windowsx.h>
    1918#include <win.h>
    2019#include <stdlib.h>
     
    191190
    192191  ownDC              = 0;
    193 
    194   //set dialog base units
    195   if(fInitialized == FALSE) {
    196     if(DIALOG_Init() == FALSE) {
    197       dprintf(("DIALOG_Init FAILED!"));
    198       DebugInt3();
    199       SetLastError(ERROR_GEN_FAILURE);
    200       return;
    201     }
    202     fInitialized = TRUE;
    203   }
    204 
    205192}
    206193//******************************************************************************
     
    15971584    case WM_SETTEXT:
    15981585    {
    1599         if(!fInternalMsg)
     1586        if(!fInternalMsg) 
    16001587        {
    16011588           LRESULT result;
     
    27522739//    else    return hwnd;    //OS/2 window handle
    27532740}
    2754 /***********************************************************************
    2755  *           DIALOG_Init
    2756  *
    2757  * Initialisation of the dialog manager.
    2758  */
    2759 BOOL Win32BaseWindow::DIALOG_Init(void)
    2760 {
    2761     HDC hdc;
    2762     SIZE size;
    2763 
    2764     /* Calculate the dialog base units */
    2765     if (!(hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
    2766     if (!getCharSizeFromDC( hdc, 0, &size )) return FALSE;
    2767     DeleteDC( hdc );
    2768     xBaseUnit = size.cx;
    2769     yBaseUnit = size.cy;
    2770 
    2771     return TRUE;
    2772 }
    2773 /***********************************************************************
    2774  *           DIALOG_GetCharSizeFromDC
    2775  *
    2776  *
    2777  *  Calculates the *true* average size of English characters in the
    2778  *  specified font as oppposed to the one returned by GetTextMetrics.
    2779  */
    2780 BOOL Win32BaseWindow::getCharSizeFromDC( HDC hDC, HFONT hUserFont, SIZE * pSize )
    2781 {
    2782     BOOL Success = FALSE;
    2783     HFONT hUserFontPrev = 0;
    2784     pSize->cx = xBaseUnit;
    2785     pSize->cy = yBaseUnit;
    2786 
    2787     if ( hDC )
    2788     {
    2789         /* select the font */
    2790         TEXTMETRICA tm;
    2791         memset(&tm,0,sizeof(tm));
    2792         if (hUserFont) hUserFontPrev = SelectFont(hDC,hUserFont);
    2793         if (GetTextMetricsA(hDC,&tm))
    2794         {
    2795             pSize->cx = tm.tmAveCharWidth;
    2796             pSize->cy = tm.tmHeight;
    2797 
    2798             /* if variable width font */
    2799             if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
    2800             {
    2801                 SIZE total;
    2802                 static const char szAvgChars[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    2803 
    2804                 /* Calculate a true average as opposed to the one returned
    2805                  * by tmAveCharWidth. This works better when dealing with
    2806                  * proportional spaced fonts and (more important) that's
    2807                  * how Microsoft's dialog creation code calculates the size
    2808                  * of the font
    2809                  */
    2810                 if (GetTextExtentPointA(hDC,szAvgChars,sizeof(szAvgChars),&total))
    2811                 {
    2812                    /* round up */
    2813                     pSize->cx = ((2*total.cx/sizeof(szAvgChars)) + 1)/2;
    2814                     Success = TRUE;
    2815                 }
    2816             }
    2817             else
    2818             {
    2819                 Success = TRUE;
    2820             }
    2821         }
    2822 
    2823         /* select the original font */
    2824         if (hUserFontPrev) SelectFont(hDC,hUserFontPrev);
    2825     }
    2826     return (Success);
    2827 }
    2828 /***********************************************************************
    2829  *           DIALOG_GetCharSize
    2830  *
    2831  *
    2832  *  Calculates the *true* average size of English characters in the
    2833  *  specified font as oppposed to the one returned by GetTextMetrics.
    2834  *  A convenient variant of DIALOG_GetCharSizeFromDC.
    2835  */
    2836 BOOL Win32BaseWindow::getCharSize( HFONT hUserFont, SIZE * pSize )
    2837 {
    2838     HDC  hDC = GetDC(0);
    2839     BOOL Success = getCharSizeFromDC( hDC, hUserFont, pSize );
    2840     ReleaseDC(0, hDC);
    2841     return Success;
    2842 }
    28432741//******************************************************************************
    28442742// GetNextDlgTabItem32   (USER32.276)
     
    29952893    return retvalue;
    29962894}
    2997 //******************************************************************************
    2998 //******************************************************************************
    2999 BOOL Win32BaseWindow::MapDialogRect(LPRECT rect)
    3000 {
    3001     rect->left   = (rect->left * xBaseUnit) / 4;
    3002     rect->right  = (rect->right * xBaseUnit) / 4;
    3003     rect->top    = (rect->top * yBaseUnit) / 8;
    3004     rect->bottom = (rect->bottom * yBaseUnit) / 8;
    3005     return TRUE;
    3006 }
    3007 //******************************************************************************
    3008 //******************************************************************************
    3009 BOOL Win32BaseWindow::fInitialized = FALSE;
    3010 int  Win32BaseWindow::xBaseUnit    = 10;
    3011 int  Win32BaseWindow::yBaseUnit    = 20;
    30122895//******************************************************************************
    30132896//******************************************************************************
  • TabularUnified trunk/src/user32/win32wbase.h

    r1525 r1526  
    1 /* $Id: win32wbase.h,v 1.36 1999-10-30 18:40:48 cbratschi Exp $ */
     1/* $Id: win32wbase.h,v 1.37 1999-10-31 01:14:43 sandervl Exp $ */
    22/*
    33 * Win32 Window Base Class for OS/2
     
    148148         BOOL   ShowWindow(ULONG nCmdShow);
    149149         BOOL   SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
    150         BOOL   SetWindowPlacement(WINDOWPLACEMENT *winpos);
     150        BOOL   SetWindowPlacement(WINDOWPLACEMENT *winpos);
    151151         BOOL   DestroyWindow();
    152152         HWND   SetActiveWindow();
     
    205205           BOOL EnumChildWindows(WNDENUMPROC lpfn, LPARAM lParam);
    206206
     207         HWND   getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious);
     208         HWND   getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
     209
    207210    static HWND Win32ToOS2Handle(HWND hwnd);
    208211    static HWND Win32ToOS2FrameHandle(HWND hwnd);
     
    218221       ULONG getBorderHeight() { return borderHeight; };
    219222
    220 static  void  NC_AdjustRectInner(LPRECT rect, DWORD style, DWORD exStyle);
    221 static  void  NC_AdjustRectOuter(LPRECT rect, DWORD style, BOOL menu, DWORD exStyle);
    222 static  BOOL  WindowNeedsWMBorder( DWORD style, DWORD exStyle );
     223static  void  NC_AdjustRectInner(LPRECT rect, DWORD style, DWORD exStyle);
     224static  void  NC_AdjustRectOuter(LPRECT rect, DWORD style, BOOL menu, DWORD exStyle);
     225static  BOOL  WindowNeedsWMBorder( DWORD style, DWORD exStyle );
    223226
    224227       PVOID getOldWndProc() { return pOldWndProc; }
     
    303306#ifndef OS2_INCLUDED
    304307        void  GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
    305         LONG  HandleWindowPosChanging(WINDOWPOS *winpos);
     308        LONG  HandleWindowPosChanging(WINDOWPOS *winpos);
    306309        LONG  HandleSysCommand(WPARAM wParam, POINT *pt32);
    307310
     
    345348         BOOL   isPSErase()      { return EraseBkgndFlag | PSEraseFlag; }
    346349         BOOL   isSupressErase() { return SupressEraseFlag; }
    347 
    348 protected:
    349         BOOL    DIALOG_Init(void);
    350         BOOL    getCharSizeFromDC( HDC hDC, HFONT hFont, SIZE * pSize );
    351         BOOL    getCharSize( HFONT hFont, SIZE * pSize);
    352 
    353 public:
    354          HWND   getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious);
    355          HWND   getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious);
    356 
    357          BOOL   MapDialogRect(LPRECT rect);
    358 
    359 static   ULONG  GetDialogBaseUnits()  { return MAKELONG(xBaseUnit, yBaseUnit); };
    360 static   int    getXBaseUnit() { return xBaseUnit; }
    361 static   int    getYBaseUnit() { return yBaseUnit; }
    362 
    363 private:
    364  static BOOL    fInitialized;
    365  static int     xBaseUnit;
    366  static int     yBaseUnit;
    367350};
    368351
  • TabularUnified trunk/src/user32/windlg.cpp

    r1525 r1526  
    1 /* $Id: windlg.cpp,v 1.9 1999-10-30 18:40:49 cbratschi Exp $ */
     1/* $Id: windlg.cpp,v 1.10 1999-10-31 01:14:44 sandervl Exp $ */
    22/*
    33 * Win32 dialog apis for OS/2
     
    202202BOOL WIN32API MapDialogRect(HWND hwndDlg, LPRECT rect)
    203203{
    204   Win32BaseWindow *window;
    205 
    206     window = Win32BaseWindow::GetWindowFromHandle(hwndDlg);
    207     if(!window) {
     204  Win32Dialog *dialog;
     205
     206    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwndDlg);
     207    if(!dialog || !dialog->IsDialog()) {
    208208        dprintf(("MapDialogRect, window %x not found", hwndDlg));
    209209        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
     
    211211    }
    212212    dprintf(("USER32: MapDialogRect\n"));
    213     return window->MapDialogRect(rect);
     213    return dialog->MapDialogRect(rect);
    214214}
    215215//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.