Changeset 1526 for trunk/src/user32/win32wbase.cpp
- Timestamp:
- Oct 31, 1999, 2:14:44 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/win32wbase.cpp
r1525 r1526 1 /* $Id: win32wbase.cpp,v 1. 69 1999-10-30 18:40:48 cbratschiExp $ */1 /* $Id: win32wbase.cpp,v 1.70 1999-10-31 01:14:42 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 16 16 */ 17 17 #include <os2win.h> 18 #include <windowsx.h>19 18 #include <win.h> 20 19 #include <stdlib.h> … … 191 190 192 191 ownDC = 0; 193 194 //set dialog base units195 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 205 192 } 206 193 //****************************************************************************** … … 1597 1584 case WM_SETTEXT: 1598 1585 { 1599 if(!fInternalMsg) 1586 if(!fInternalMsg) 1600 1587 { 1601 1588 LRESULT result; … … 2752 2739 // else return hwnd; //OS/2 window handle 2753 2740 } 2754 /***********************************************************************2755 * DIALOG_Init2756 *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_GetCharSizeFromDC2775 *2776 *2777 * Calculates the *true* average size of English characters in the2778 * 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 returned2805 * by tmAveCharWidth. This works better when dealing with2806 * proportional spaced fonts and (more important) that's2807 * how Microsoft's dialog creation code calculates the size2808 * of the font2809 */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 else2818 {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_GetCharSize2830 *2831 *2832 * Calculates the *true* average size of English characters in the2833 * 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 }2843 2741 //****************************************************************************** 2844 2742 // GetNextDlgTabItem32 (USER32.276) … … 2995 2893 return retvalue; 2996 2894 } 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;3012 2895 //****************************************************************************** 3013 2896 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.