Changeset 1525 for trunk/src/user32/win32wbase.cpp
- Timestamp:
- Oct 30, 1999, 8:40:49 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/win32wbase.cpp
r1513 r1525 1 /* $Id: win32wbase.cpp,v 1.6 8 1999-10-30 09:19:45 sandervlExp $ */1 /* $Id: win32wbase.cpp,v 1.69 1999-10-30 18:40:48 cbratschi Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 16 16 */ 17 17 #include <os2win.h> 18 #include <windowsx.h> 18 19 #include <win.h> 19 20 #include <stdlib.h> … … 190 191 191 192 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 192 205 } 193 206 //****************************************************************************** … … 1584 1597 case WM_SETTEXT: 1585 1598 { 1586 if(!fInternalMsg) 1599 if(!fInternalMsg) 1587 1600 { 1588 1601 LRESULT result; … … 2739 2752 // else return hwnd; //OS/2 window handle 2740 2753 } 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 } 2843 //****************************************************************************** 2844 // GetNextDlgTabItem32 (USER32.276) 2845 //****************************************************************************** 2846 HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious) 2847 { 2848 Win32BaseWindow *child, *nextchild, *lastchild; 2849 HWND retvalue; 2850 2851 if (hwndCtrl) 2852 { 2853 child = GetWindowFromHandle(hwndCtrl); 2854 if (!child) 2855 { 2856 retvalue = 0; 2857 goto END; 2858 } 2859 /* Make sure hwndCtrl is a top-level child */ 2860 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this)) 2861 { 2862 child = child->getParent(); 2863 if(child == NULL) break; 2864 } 2865 2866 if (!child || child->getParent() != this) 2867 { 2868 retvalue = 0; 2869 goto END; 2870 } 2871 } 2872 else 2873 { 2874 /* No ctrl specified -> start from the beginning */ 2875 child = (Win32BaseWindow *)getFirstChild(); 2876 if (!child) 2877 { 2878 retvalue = 0; 2879 goto END; 2880 } 2881 2882 if (!fPrevious) 2883 { 2884 while (child->getNextChild()) 2885 { 2886 child = (Win32BaseWindow *)child->getNextChild(); 2887 } 2888 } 2889 } 2890 2891 lastchild = child; 2892 nextchild = (Win32BaseWindow *)child->getNextChild(); 2893 while (TRUE) 2894 { 2895 if (!nextchild) nextchild = (Win32BaseWindow *)getFirstChild(); 2896 2897 if (child == nextchild) break; 2898 2899 if ((nextchild->getStyle() & WS_TABSTOP) && (nextchild->getStyle() & WS_VISIBLE) && 2900 !(nextchild->getStyle() & WS_DISABLED)) 2901 { 2902 lastchild = nextchild; 2903 if (!fPrevious) break; 2904 } 2905 nextchild = (Win32BaseWindow *)nextchild->getNextChild(); 2906 } 2907 retvalue = lastchild->getWindowHandle(); 2908 2909 END: 2910 return retvalue; 2911 } 2912 //****************************************************************************** 2913 //****************************************************************************** 2914 HWND Win32BaseWindow::getNextDlgGroupItem(HWND hwndCtrl, BOOL fPrevious) 2915 { 2916 Win32BaseWindow *child, *nextchild, *lastchild; 2917 HWND retvalue; 2918 2919 if (hwndCtrl) 2920 { 2921 child = GetWindowFromHandle(hwndCtrl); 2922 if (!child) 2923 { 2924 retvalue = 0; 2925 goto END; 2926 } 2927 /* Make sure hwndCtrl is a top-level child */ 2928 while ((child->getStyle() & WS_CHILD) && (child->getParent() != this)) 2929 { 2930 child = child->getParent(); 2931 if(child == NULL) break; 2932 } 2933 2934 if (!child || child->getParent() != this) 2935 { 2936 retvalue = 0; 2937 goto END; 2938 } 2939 } 2940 else 2941 { 2942 /* No ctrl specified -> start from the beginning */ 2943 child = (Win32BaseWindow *)getFirstChild(); 2944 if (!child) 2945 { 2946 retvalue = 0; 2947 goto END; 2948 } 2949 2950 if (fPrevious) 2951 { 2952 while (child->getNextChild()) 2953 { 2954 child = (Win32BaseWindow *)child->getNextChild(); 2955 } 2956 } 2957 } 2958 2959 lastchild = child; 2960 nextchild = (Win32BaseWindow *)child->getNextChild(); 2961 while (TRUE) 2962 { 2963 if (!nextchild || nextchild->getStyle() & WS_GROUP) 2964 { 2965 /* Wrap-around to the beginning of the group */ 2966 Win32BaseWindow *pWndTemp; 2967 2968 nextchild = (Win32BaseWindow *)getFirstChild(); 2969 2970 for(pWndTemp = nextchild;pWndTemp;pWndTemp = (Win32BaseWindow *)pWndTemp->getNextChild()) 2971 { 2972 if (pWndTemp->getStyle() & WS_GROUP) 2973 nextchild = pWndTemp; 2974 2975 if (pWndTemp == child) 2976 break; 2977 } 2978 2979 } 2980 if (nextchild == child) 2981 break; 2982 2983 if ((nextchild->getStyle() & WS_VISIBLE) && !(nextchild->getStyle() & WS_DISABLED)) 2984 { 2985 lastchild = nextchild; 2986 2987 if (!fPrevious) 2988 break; 2989 } 2990 2991 nextchild = (Win32BaseWindow *)nextchild->getNextChild(); 2992 } 2993 retvalue = lastchild->getWindowHandle(); 2994 END: 2995 return retvalue; 2996 } 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; 2741 3012 //****************************************************************************** 2742 3013 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.