winemac.drv: Improve positioning of IME client window based on caret

Aric Stewart aric at codeweavers.com
Wed Feb 19 15:42:06 CST 2014



On 2014/02/20 0:32, Ken Thomases wrote:
> On Feb 19, 2014, at 3:08 AM, Aric Stewart wrote:
> 
>> diff --git a/dlls/winemac.drv/ime.c b/dlls/winemac.drv/ime.c
>> index 2c74f6e..066c77a 100644
>> --- a/dlls/winemac.drv/ime.c
>> +++ b/dlls/winemac.drv/ime.c
>> @@ -1585,14 +1585,20 @@ BOOL query_ime_char_rect(macdrv_query* query)
>>           if (focus && (focus == hwnd || IsChild(hwnd, focus)) &&
>>               GetClientRect(focus, &charpos.rcDocument))
>>           {
>> +            HDC hdc = GetDC(focus);
>> +            TEXTMETRICA tm;
>> +
>>               if (!GetCaretPos((POINT*)&charpos.rcDocument))
>>                   charpos.rcDocument.left = charpos.rcDocument.top = 0;
>>   
>> +            GetTextMetricsA(hdc, &tm);
>>               charpos.rcDocument.right = charpos.rcDocument.left + 1;
>> +            charpos.rcDocument.bottom = charpos.rcDocument.top + tm.tmHeight;
>>               MapWindowPoints(focus, 0, (POINT*)&charpos.rcDocument, 2);
>>   
>>               *rect = cgrect_from_rect(charpos.rcDocument);
>>               ret = TRUE;
>> +            ReleaseDC(focus, hdc);
>>           }
>>       }
> 
> I don't think this does what you want.  GetDC() typically returns a DC whose parameters were reset.  It doesn't know what font has previously been used in the window.  So, you're basically getting the metrics for the System font.  I suppose that may be better than nothing.

I never knew that about GetDC, I did not see anything about reset parameters in MSDN. It was working for me pretty accurately in my testing even with different fonts.  Is there a way to get the font metrics from a window handle? I am going to need that for when I am implementing the Candidate Window stuff also.

> 
> Also, you don't check if GetTextMetricsA() succeeded.
> 

True.

> 
> Perhaps using GetGUIThreadInfo() and the rcCaret field of the GUITHREADINFO structure would be better than using GetCaretPos().  In that case, you'd map the coordinates from hwndCaret (which may be different from "focus") to the screen.  Be sure to read the remarks in the MSDN docs for the GetGUIThreadInfo() function about how to use rcCaret, although it's not clear to me if Wine implements this faithfully.
> 

I will look into this, I have a number of programs where GetCaretPos is not returning correct information anyway so an alternative would be useful. 

-aric



More information about the wine-devel mailing list