| 1 | /* $Id: text.cpp,v 1.1 2000-01-01 14:57:23 cbratschi Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Font and Text Functions | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Christoph Bratschi | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright 1997 Bertho A. Stultiens | 
|---|
| 9 | * Copyright 1993, 1994 Alexandre Julliard | 
|---|
| 10 | * | 
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #include "winuser.h" | 
|---|
| 15 | #include "user32.h" | 
|---|
| 16 |  | 
|---|
| 17 | //WINE parts: wine-991031 | 
|---|
| 18 |  | 
|---|
| 19 | static const WORD wPattern55AA[] = | 
|---|
| 20 | { | 
|---|
| 21 | 0x5555, 0xaaaa, 0x5555, 0xaaaa, | 
|---|
| 22 | 0x5555, 0xaaaa, 0x5555, 0xaaaa | 
|---|
| 23 | }; | 
|---|
| 24 |  | 
|---|
| 25 | static HBRUSH  hPattern55AABrush = 0; | 
|---|
| 26 | static HBITMAP hPattern55AABitmap = 0; | 
|---|
| 27 |  | 
|---|
| 28 | /********************************************************************* | 
|---|
| 29 | *      CACHE_GetPattern55AABitmap | 
|---|
| 30 | */ | 
|---|
| 31 | HBITMAP CACHE_GetPattern55AABitmap(void) | 
|---|
| 32 | { | 
|---|
| 33 | if (!hPattern55AABitmap) | 
|---|
| 34 | hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA ); | 
|---|
| 35 | return hPattern55AABitmap; | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | /********************************************************************* | 
|---|
| 39 | *      CACHE_GetPattern55AABrush | 
|---|
| 40 | */ | 
|---|
| 41 | HBRUSH CACHE_GetPattern55AABrush(void) | 
|---|
| 42 | { | 
|---|
| 43 | if (!hPattern55AABrush) | 
|---|
| 44 | hPattern55AABrush = CreatePatternBrush(CACHE_GetPattern55AABitmap()); | 
|---|
| 45 | return hPattern55AABrush; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | INT WIN32API DrawTextA(HDC hDC,LPCSTR lpString,INT nCount,PRECT lpRect,UINT nFormat) | 
|---|
| 49 | { | 
|---|
| 50 | dprintf(("USER32: DrawTextA %x",hDC)); | 
|---|
| 51 |  | 
|---|
| 52 | return InternalDrawTextExA(hDC,lpString,nCount,lpRect,nFormat,NULL,FALSE); | 
|---|
| 53 | } | 
|---|
| 54 | //****************************************************************************** | 
|---|
| 55 | //****************************************************************************** | 
|---|
| 56 | INT WIN32API DrawTextW(HDC hDC,LPCWSTR lpString,INT nCount,PRECT lpRect,UINT nFormat) | 
|---|
| 57 | { | 
|---|
| 58 | dprintf(("USER32: DrawTextW %x",hDC)); | 
|---|
| 59 |  | 
|---|
| 60 | return InternalDrawTextExW(hDC,lpString,nCount,lpRect,nFormat,NULL,FALSE); | 
|---|
| 61 | } | 
|---|
| 62 | //****************************************************************************** | 
|---|
| 63 | //****************************************************************************** | 
|---|
| 64 | INT WIN32API DrawTextExA(HDC hdc,LPCSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams) | 
|---|
| 65 | { | 
|---|
| 66 | dprintf(("USER32:DrawTextExA %x\n",hdc)); | 
|---|
| 67 |  | 
|---|
| 68 | return InternalDrawTextExA(hdc,lpchText,cchText,lprc,dwDTFormat,lpDTParams,TRUE); | 
|---|
| 69 | } | 
|---|
| 70 | //****************************************************************************** | 
|---|
| 71 | //****************************************************************************** | 
|---|
| 72 | int WIN32API DrawTextExW(HDC hdc,LPWSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams) | 
|---|
| 73 | { | 
|---|
| 74 | dprintf(("USER32: DrawTextExW %x",hdc)); | 
|---|
| 75 |  | 
|---|
| 76 | return InternalDrawTextExW(hdc,lpchText,cchText,lprc,dwDTFormat,lpDTParams,TRUE); | 
|---|
| 77 | } | 
|---|
| 78 | //****************************************************************************** | 
|---|
| 79 | //****************************************************************************** | 
|---|
| 80 | DWORD WIN32API GetTabbedTextExtentA( HDC hDC, LPCSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions) | 
|---|
| 81 | { | 
|---|
| 82 | dprintf(("USER32: GetTabbedTextExtentA %x",hDC)); | 
|---|
| 83 |  | 
|---|
| 84 | return InternalGetTabbedTextExtentA(hDC,lpString,nCount,nTabPositions,lpnTabStopPositions); | 
|---|
| 85 | } | 
|---|
| 86 | //****************************************************************************** | 
|---|
| 87 | //****************************************************************************** | 
|---|
| 88 | DWORD WIN32API GetTabbedTextExtentW(HDC hDC,LPCWSTR lpString,INT nCount,INT nTabPositions,LPINT lpnTabStopPositions) | 
|---|
| 89 | { | 
|---|
| 90 | dprintf(("USER32: GetTabbedTextExtentW %x",hDC)); | 
|---|
| 91 |  | 
|---|
| 92 | return InternalGetTabbedTextExtentW(hDC,lpString,nCount,nTabPositions,lpnTabStopPositions); | 
|---|
| 93 | } | 
|---|
| 94 | //****************************************************************************** | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | LONG WIN32API TabbedTextOutA(HDC hdc,INT x,INT y,LPCSTR lpString,INT nCount,INT nTabPositions, LPINT lpnTabStopPositions,INT nTabOrigin) | 
|---|
| 97 | { | 
|---|
| 98 | dprintf(("USER32: TabbedTextOutA %x",hdc)); | 
|---|
| 99 |  | 
|---|
| 100 | return InternalTabbedTextOutA(hdc,x,y,lpString,nCount,nTabPositions,lpnTabStopPositions,nTabOrigin); | 
|---|
| 101 | } | 
|---|
| 102 | //****************************************************************************** | 
|---|
| 103 | //****************************************************************************** | 
|---|
| 104 | LONG WIN32API TabbedTextOutW( HDC hdc, int x, int y, LPCWSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int  nTabOrigin) | 
|---|
| 105 | { | 
|---|
| 106 | dprintf(("USER32: TabbedTextOutW %x",hdc)); | 
|---|
| 107 |  | 
|---|
| 108 | return InternalTabbedTextOutW(hdc,x,y,lpString,nCount,nTabPositions,lpnTabStopPositions,nTabOrigin); | 
|---|
| 109 | } | 
|---|
| 110 | //****************************************************************************** | 
|---|
| 111 | // WINE/objects/text.c | 
|---|
| 112 | //****************************************************************************** | 
|---|
| 113 | static BOOL InternalGrayString(HDC hdc,HBRUSH hBrush,GRAYSTRINGPROC lpOutputFunc,LPARAM lpData,INT nCount,INT x,INT y,INT nWidth,INT nHeight,BOOL isUnicode) | 
|---|
| 114 | { | 
|---|
| 115 | HBITMAP hbm, hbmsave; | 
|---|
| 116 | HBRUSH hbsave; | 
|---|
| 117 | HFONT hfsave; | 
|---|
| 118 | HDC memdc = CreateCompatibleDC(hdc); | 
|---|
| 119 | BOOL retval = TRUE; | 
|---|
| 120 | RECT r; | 
|---|
| 121 | COLORREF fg, bg; | 
|---|
| 122 |  | 
|---|
| 123 | if (!hdc) return FALSE; | 
|---|
| 124 |  | 
|---|
| 125 | if (nCount == 0) | 
|---|
| 126 | nCount = isUnicode ? lstrlenW((LPCWSTR)lpData):lstrlenA((LPCSTR)lpData); | 
|---|
| 127 |  | 
|---|
| 128 | if((nWidth == 0 || nHeight == 0) && nCount != -1) | 
|---|
| 129 | { | 
|---|
| 130 | SIZE s; | 
|---|
| 131 |  | 
|---|
| 132 | if (isUnicode) | 
|---|
| 133 | GetTextExtentPoint32W(hdc,(LPCWSTR)lpData,nCount,&s); | 
|---|
| 134 | else | 
|---|
| 135 | GetTextExtentPoint32A(hdc,(LPCSTR)lpData,nCount,&s); | 
|---|
| 136 | if (nWidth == 0) nWidth = s.cx; | 
|---|
| 137 | if (nHeight == 0) nHeight = s.cy; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | r.left = r.top = 0; | 
|---|
| 141 | r.right = nWidth; | 
|---|
| 142 | r.bottom = nHeight; | 
|---|
| 143 |  | 
|---|
| 144 | hbm = CreateBitmap(nWidth,nHeight,1,1,NULL); | 
|---|
| 145 | hbmsave = (HBITMAP)SelectObject(memdc,hbm); | 
|---|
| 146 | FillRect(memdc,&r,(HBRUSH)GetStockObject(BLACK_BRUSH)); | 
|---|
| 147 | SetTextColor(memdc,RGB(255,255,255)); | 
|---|
| 148 | SetBkColor(memdc,RGB(0,0,0)); | 
|---|
| 149 | hfsave = (HFONT)SelectObject(memdc,GetCurrentObject(hdc,OBJ_FONT)); | 
|---|
| 150 |  | 
|---|
| 151 | if (lpOutputFunc) | 
|---|
| 152 | retval = lpOutputFunc(memdc,lpData,nCount); | 
|---|
| 153 | else | 
|---|
| 154 | if (isUnicode) | 
|---|
| 155 | TextOutW(memdc,0,0,(LPCWSTR)lpData,nCount); | 
|---|
| 156 | else | 
|---|
| 157 | TextOutA(memdc,0,0,(LPCSTR)lpData,nCount); | 
|---|
| 158 | SelectObject(memdc, hfsave); | 
|---|
| 159 |  | 
|---|
| 160 | /* | 
|---|
| 161 | * Windows doc says that the bitmap isn't grayed when len == -1 and | 
|---|
| 162 | * the callback function returns FALSE. However, testing this on | 
|---|
| 163 | * win95 showed otherwise... | 
|---|
| 164 | */ | 
|---|
| 165 | #ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR | 
|---|
| 166 | if(retval || nCount != -1) | 
|---|
| 167 | #endif | 
|---|
| 168 | { | 
|---|
| 169 | hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush()); | 
|---|
| 170 | PatBlt(memdc,0,0,nWidth,nHeight,0x000A0329); | 
|---|
| 171 | SelectObject(memdc, hbsave); | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | if (hBrush) hbsave = (HBRUSH)SelectObject(hdc,hBrush); | 
|---|
| 175 | fg = SetTextColor(hdc, RGB(0, 0, 0)); | 
|---|
| 176 | bg = SetBkColor(hdc, RGB(255, 255, 255)); | 
|---|
| 177 | BitBlt(hdc,x,y,nWidth,nHeight,memdc,0,0,0x00E20746); | 
|---|
| 178 | SetTextColor(hdc, fg); | 
|---|
| 179 | SetBkColor(hdc, bg); | 
|---|
| 180 | if (hBrush) SelectObject(hdc,hbsave); | 
|---|
| 181 |  | 
|---|
| 182 | SelectObject(memdc, hbmsave); | 
|---|
| 183 | DeleteObject(hbm); | 
|---|
| 184 | DeleteDC(memdc); | 
|---|
| 185 |  | 
|---|
| 186 | return retval; | 
|---|
| 187 | } | 
|---|
| 188 | //****************************************************************************** | 
|---|
| 189 | //****************************************************************************** | 
|---|
| 190 | BOOL WIN32API GrayStringA(HDC hdc,HBRUSH hBrush,GRAYSTRINGPROC lpOutputFunc,LPARAM lpData,int nCount,int X,int Y,int nWidth,int nHeight) | 
|---|
| 191 | { | 
|---|
| 192 | dprintf(("USER32: GrayStringA %x",hdc)); | 
|---|
| 193 |  | 
|---|
| 194 | return InternalGrayString(hdc,hBrush,lpOutputFunc,lpData,nCount,X,Y,nWidth,nHeight,FALSE); | 
|---|
| 195 | } | 
|---|
| 196 | //****************************************************************************** | 
|---|
| 197 | //****************************************************************************** | 
|---|
| 198 | BOOL WIN32API GrayStringW(HDC hdc,HBRUSH hBrush,GRAYSTRINGPROC lpOutputFunc,LPARAM lpData,int nCount,int X,int Y,int nWidth,int nHeight) | 
|---|
| 199 | { | 
|---|
| 200 | dprintf(("USER32: GrayStringW %x",hdc)); | 
|---|
| 201 |  | 
|---|
| 202 | return InternalGrayString(hdc,hBrush,lpOutputFunc,lpData,nCount,X,Y,nWidth,nHeight,TRUE); | 
|---|
| 203 | } | 
|---|
| 204 |  | 
|---|