winehq.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
January
2003
December
November
October
September
August
July
June
May
April
March
February
January
2002
December
November
October
September
August
July
June
May
April
March
February
January
2001
December
November
October
September
August
July
June
May
April
March
February
List overview
wine-commits
July 2009
----- 2025 -----
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
----- 2003 -----
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
----- 2002 -----
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
April 2002
March 2002
February 2002
January 2002
----- 2001 -----
December 2001
November 2001
October 2001
September 2001
August 2001
July 2001
June 2001
May 2001
April 2001
March 2001
February 2001
wine-commits@winehq.org
4 participants
1067 discussions
Start a n
N
ew thread
Huw Davies : gdi32: Write the map mode and window size records after the mfcomment.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 8edbd0639ed9c6586b10e2d7600ae3db4570080a URL:
http://source.winehq.org/git/wine.git/?a=commit;h=8edbd0639ed9c6586b10e2d76…
Author: Huw Davies <huw(a)codeweavers.com> Date: Thu Jul 2 11:37:29 2009 +0100 gdi32: Write the map mode and window size records after the mfcomment. --- dlls/gdi32/metafile.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 69 insertions(+), 2 deletions(-) diff --git a/dlls/gdi32/metafile.c b/dlls/gdi32/metafile.c index d0c55ce..2e34f37 100644 --- a/dlls/gdi32/metafile.c +++ b/dlls/gdi32/metafile.c @@ -1223,11 +1223,71 @@ end: } /****************************************************************** + * set_window + * + * Helper for GetWinMetaFileBits + * + * Add the SetWindowOrg and SetWindowExt records + */ +static BOOL set_window(HDC hdc, HENHMETAFILE emf, HDC ref_dc, INT map_mode) +{ + ENHMETAHEADER header; + INT horz_res, vert_res, horz_size, vert_size; + POINT pt; + + if(!GetEnhMetaFileHeader(emf, sizeof(header), &header)) return FALSE; + + horz_res = GetDeviceCaps(ref_dc, HORZRES); + vert_res = GetDeviceCaps(ref_dc, VERTRES); + horz_size = GetDeviceCaps(ref_dc, HORZSIZE); + vert_size = GetDeviceCaps(ref_dc, VERTSIZE); + + switch(map_mode) + { + case MM_TEXT: + case MM_ISOTROPIC: + case MM_ANISOTROPIC: + pt.y = MulDiv(header.rclFrame.top, vert_res, vert_size * 100); + pt.x = MulDiv(header.rclFrame.left, horz_res, horz_size * 100); + break; + case MM_LOMETRIC: + pt.y = MulDiv(-header.rclFrame.top, 1, 10) + 1; + pt.x = MulDiv( header.rclFrame.left, 1, 10); + break; + case MM_HIMETRIC: + pt.y = -header.rclFrame.top + 1; + pt.x = header.rclFrame.left; + break; + case MM_LOENGLISH: + pt.y = MulDiv(-header.rclFrame.top, 10, 254) + 1; + pt.x = MulDiv( header.rclFrame.left, 10, 254); + break; + case MM_HIENGLISH: + pt.y = MulDiv(-header.rclFrame.top, 100, 254) + 1; + pt.x = MulDiv( header.rclFrame.left, 100, 254); + break; + case MM_TWIPS: + pt.y = MulDiv(-header.rclFrame.top, 72 * 20, 2540) + 1; + pt.x = MulDiv( header.rclFrame.left, 72 * 20, 2540); + break; + default: + WARN("Unknown map mode %d\n", map_mode); + return FALSE; + } + SetWindowOrgEx(hdc, pt.x, pt.y, NULL); + + pt.x = MulDiv(header.rclFrame.right - header.rclFrame.left, horz_res, horz_size * 100); + pt.y = MulDiv(header.rclFrame.bottom - header.rclFrame.top, vert_res, vert_size * 100); + SetWindowExtEx(hdc, pt.x, pt.y, NULL); + return TRUE; +} + +/****************************************************************** * GetWinMetaFileBits [GDI32.@] */ UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf, UINT cbBuffer, LPBYTE lpbBuffer, - INT fnMapMode, HDC hdcRef) + INT map_mode, HDC hdcRef) { HDC hdcmf; HMETAFILE hmf; @@ -1237,11 +1297,14 @@ UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf, GetClipBox(hdcRef, &rc); TRACE("(%p,%d,%p,%d,%p) rc=%s\n", hemf, cbBuffer, lpbBuffer, - fnMapMode, hdcRef, wine_dbgstr_rect(&rc)); + map_mode, hdcRef, wine_dbgstr_rect(&rc)); hdcmf = CreateMetaFileW(NULL); add_mf_comment(hdcmf, hemf); + SetMapMode(hdcmf, map_mode); + if(!set_window(hdcmf, hemf, hdcRef, map_mode)) + goto error; PlayEnhMetaFile(hdcmf, hemf, &rc); hmf = CloseMetaFile(hdcmf); @@ -1260,6 +1323,10 @@ UINT WINAPI GetWinMetaFileBits(HENHMETAFILE hemf, comment_rec->rdParm[8] = ~checksum + 1; } return ret; + +error: + DeleteMetaFile(CloseMetaFile(hdcmf)); + return 0; } /******************************************************************
1
0
0
0
Dmitry Timoshkov : user32: Add a test for BM_SETSTYLE, make it pass under Wine.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 87418f0aaac3a16f8c715923f044fe153d6c4da5 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=87418f0aaac3a16f8c715923f…
Author: Dmitry Timoshkov <dmitry(a)codeweavers.com> Date: Thu Jul 2 19:27:18 2009 +0900 user32: Add a test for BM_SETSTYLE, make it pass under Wine. --- dlls/user32/button.c | 14 ++++++- dlls/user32/tests/msg.c | 86 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/dlls/user32/button.c b/dlls/user32/button.c index 926563c..a61a4e7 100644 --- a/dlls/user32/button.c +++ b/dlls/user32/button.c @@ -75,6 +75,7 @@ #include "wingdi.h" #include "wine/winuser16.h" #include "controls.h" +#include "win.h" #include "user_private.h" #include "wine/debug.h" @@ -271,6 +272,13 @@ static LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, } if (btn_type >= MAX_BTN_TYPE) return -1; /* abort */ + + /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ + if (btn_type == BS_USERBUTTON ) + { + style = (style & ~0x0f) | BS_PUSHBUTTON; + WIN_SetStyle( hWnd, style, 0x0f & ~style ); + } set_button_state( hWnd, BUTTON_UNCHECKED ); return 0; @@ -458,11 +466,11 @@ static LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, if ((wParam & 0x0f) >= MAX_BTN_TYPE) break; btn_type = wParam & 0x0f; style = (style & ~0x0f) | btn_type; - SetWindowLongW( hWnd, GWL_STYLE, style ); + WIN_SetStyle( hWnd, style, 0x0f & ~style ); /* Only redraw if lParam flag is set.*/ if (lParam) - paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); + InvalidateRect( hWnd, NULL, TRUE ); break; @@ -1105,6 +1113,8 @@ static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) if ((action == ODA_FOCUS) || ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) DrawFocusRect( hDC, &rc ); + + BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); } diff --git a/dlls/user32/tests/msg.c b/dlls/user32/tests/msg.c index 580582f..0e6ed29 100644 --- a/dlls/user32/tests/msg.c +++ b/dlls/user32/tests/msg.c @@ -5209,6 +5209,49 @@ static const struct message WmSetFontButtonSeq[] = { WM_CTLCOLORBTN, sent|defwinproc }, { 0 } }; +static const struct message WmSetStyleButtonSeq[] = +{ + { BM_SETSTYLE, sent }, + { WM_APP, sent|wparam|lparam, 0, 0 }, + { WM_PAINT, sent }, + { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */ + { WM_ERASEBKGND, sent|defwinproc }, + { WM_CTLCOLORBTN, sent|parent }, + { 0 } +}; +static const struct message WmSetStyleStaticSeq[] = +{ + { BM_SETSTYLE, sent }, + { WM_APP, sent|wparam|lparam, 0, 0 }, + { WM_PAINT, sent }, + { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */ + { WM_ERASEBKGND, sent|defwinproc }, + { WM_CTLCOLORSTATIC, sent|parent }, + { 0 } +}; +static const struct message WmSetStyleUserSeq[] = +{ + { BM_SETSTYLE, sent }, + { WM_APP, sent|wparam|lparam, 0, 0 }, + { WM_PAINT, sent }, + { WM_NCPAINT, sent|defwinproc|optional }, /* FIXME: Wine sends it */ + { WM_ERASEBKGND, sent|defwinproc }, + { WM_CTLCOLORBTN, sent|parent }, + { WM_COMMAND, sent|wparam|parent, MAKEWPARAM(ID_BUTTON, BN_PAINT) }, + { 0 } +}; +static const struct message WmSetStyleOwnerdrawSeq[] = +{ + { BM_SETSTYLE, sent }, + { WM_APP, sent|wparam|lparam, 0, 0 }, + { WM_PAINT, sent }, + { WM_NCPAINT, sent|optional }, /* FIXME: Wine sends it */ + { WM_ERASEBKGND, sent|defwinproc }, + { WM_CTLCOLORBTN, sent|parent }, + { WM_CTLCOLORBTN, sent|parent }, + { WM_DRAWITEM, sent|wparam|lparam|parent, ID_BUTTON, 0x000010e4 }, + { 0 } +}; static WNDPROC old_button_proc; @@ -5268,29 +5311,30 @@ static void test_button_messages(void) DWORD dlg_code; const struct message *setfocus; const struct message *killfocus; + const struct message *setstyle; } button[] = { { BS_PUSHBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON, - WmSetFocusButtonSeq, WmKillFocusButtonSeq }, + WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq }, { BS_DEFPUSHBUTTON, DLGC_BUTTON | DLGC_DEFPUSHBUTTON, - WmSetFocusButtonSeq, WmKillFocusButtonSeq }, + WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleButtonSeq }, { BS_CHECKBOX, DLGC_BUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_AUTOCHECKBOX, DLGC_BUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_RADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_3STATE, DLGC_BUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_AUTO3STATE, DLGC_BUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_GROUPBOX, DLGC_STATIC, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_USERBUTTON, DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON, - WmSetFocusButtonSeq, WmKillFocusButtonSeq }, + WmSetFocusButtonSeq, WmKillFocusButtonSeq, WmSetStyleUserSeq }, { BS_AUTORADIOBUTTON, DLGC_BUTTON | DLGC_RADIOBUTTON, - WmSetFocusStaticSeq, WmKillFocusStaticSeq }, + WmSetFocusStaticSeq, WmKillFocusStaticSeq, WmSetStyleStaticSeq }, { BS_OWNERDRAW, DLGC_BUTTON, - WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq } + WmSetFocusOwnerdrawSeq, WmKillFocusOwnerdrawSeq, WmSetStyleOwnerdrawSeq } }; unsigned int i; HWND hwnd, parent; @@ -5319,6 +5363,8 @@ static void test_button_messages(void) MSG msg; DWORD style; + trace("button style %08x\n", button[i].style); + hwnd = CreateWindowExA(0, "my_button_class", "test", button[i].style | WS_CHILD | BS_NOTIFY, 0, 0, 50, 14, parent, (HMENU)ID_BUTTON, 0, NULL); ok(hwnd != 0, "Failed to create button window\n"); @@ -5327,9 +5373,9 @@ static void test_button_messages(void) style &= ~(WS_CHILD | BS_NOTIFY); /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ if (button[i].style == BS_USERBUTTON) - todo_wine ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style); + ok(style == BS_PUSHBUTTON, "expected style BS_PUSHBUTTON got %x\n", style); else - ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style); + ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style); dlg_code = SendMessageA(hwnd, WM_GETDLGCODE, 0, 0); ok(dlg_code == button[i].dlg_code, "%u: wrong dlg_code %08x\n", i, dlg_code); @@ -5342,7 +5388,6 @@ static void test_button_messages(void) log_all_parent_messages++; - trace("button style %08x\n", button[i].style); ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus()); SetFocus(hwnd); SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */ @@ -5354,9 +5399,20 @@ static void test_button_messages(void) while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg); ok_sequence(button[i].killfocus, "SetFocus(0) on a button", FALSE); + ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus()); + + SendMessage(hwnd, BM_SETSTYLE, button[i].style | BS_BOTTOM, TRUE); + SendMessage(hwnd, WM_APP, 0, 0); /* place a separator mark here */ + while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg); + ok_sequence(button[i].setstyle, "BM_SETSTYLE on a button", FALSE); + + style = GetWindowLongA(hwnd, GWL_STYLE); + style &= ~(WS_VISIBLE | WS_CHILD | BS_NOTIFY); + /* XP doesn't turn a BS_USERBUTTON into BS_PUSHBUTTON here! */ + ok(style == button[i].style, "expected style %x got %x\n", button[i].style, style); + log_all_parent_messages--; - ok(GetFocus() == 0, "expected focus 0, got %p\n", GetFocus()); DestroyWindow(hwnd); }
1
0
0
0
Alexander Scott-Johns : notepad: Detect if saving will lose information.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 84fd1c84f8f2393290438f452adaeb24ff9fba92 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=84fd1c84f8f2393290438f452…
Author: Alexander Scott-Johns <alexander.scott.johns(a)googlemail.com> Date: Tue Jun 30 00:24:18 2009 +0100 notepad: Detect if saving will lose information. --- programs/notepad/En.rc | 7 +++ programs/notepad/dialog.c | 97 +++++++++++++++++++++++++++++++++------- programs/notepad/notepad_res.h | 2 + 3 files changed, 89 insertions(+), 17 deletions(-) diff --git a/programs/notepad/En.rc b/programs/notepad/En.rc index dea29c2..3c4d052 100644 --- a/programs/notepad/En.rc +++ b/programs/notepad/En.rc @@ -131,4 +131,11 @@ memory." STRING_UNICODE_LE, "Unicode (UTF-16)" STRING_UNICODE_BE, "Unicode (UTF-16 big-endian)" + +STRING_LOSS_OF_UNICODE_CHARACTERS, "%s\n\ +This file contains Unicode characters which will be lost if \n\ +you save this file in the %s encoding. \n\ +To keep these characters, click Cancel, and then select \n\ +one of the Unicode options in the Encoding drop down list. \n\ +Continue?" } diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index cef0dce..c1dbb6d 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -142,6 +142,23 @@ static int AlertFileNotSaved(LPCWSTR szFileName) MB_ICONQUESTION|MB_YESNOCANCEL); } +static int AlertUnicodeCharactersLost(LPCWSTR szFileName) +{ + WCHAR szMsgFormat[MAX_STRING_LEN]; + WCHAR szEnc[MAX_STRING_LEN]; + WCHAR szMsg[ARRAY_SIZE(szMsgFormat) + MAX_PATH + ARRAY_SIZE(szEnc)]; + WCHAR szCaption[MAX_STRING_LEN]; + + LoadStringW(Globals.hInstance, STRING_LOSS_OF_UNICODE_CHARACTERS, + szMsgFormat, ARRAY_SIZE(szMsgFormat)); + load_encoding_name(ENCODING_ANSI, szEnc, ARRAY_SIZE(szEnc)); + wnsprintfW(szMsg, ARRAY_SIZE(szMsg), szMsgFormat, szFileName, szEnc); + LoadStringW(Globals.hInstance, STRING_NOTEPAD, szCaption, + ARRAY_SIZE(szCaption)); + return MessageBoxW(Globals.hMainWnd, szMsg, szCaption, + MB_OKCANCEL|MB_ICONEXCLAMATION); +} + /** * Returns: * TRUE - if file exists @@ -158,8 +175,30 @@ BOOL FileExists(LPCWSTR szFilename) return (hFile != INVALID_HANDLE_VALUE); } +static inline BOOL is_conversion_to_ansi_lossy(LPCWSTR textW, int lenW) +{ + BOOL ret = FALSE; + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, textW, lenW, NULL, 0, + NULL, &ret); + return ret; +} -static VOID DoSaveFile(VOID) +typedef enum +{ + SAVED_OK, + SAVE_FAILED, + SHOW_SAVEAS_DIALOG +} SAVE_STATUS; + +/* szFileName is the filename to save under; enc is the encoding to use. + * + * If the function succeeds, it returns SAVED_OK. + * If the function fails, it returns SAVE_FAILED. + * If Unicode data could be lost due to conversion to a non-Unicode character + * set, a warning is displayed. The user can continue (and the function carries + * on), or cancel (and the function returns SHOW_SAVEAS_DIALOG). + */ +static SAVE_STATUS DoSaveFile(LPCWSTR szFileName, ENCODING enc) { int lenW; WCHAR* textW; @@ -174,12 +213,12 @@ static VOID DoSaveFile(VOID) if (!textW) { ShowLastError(); - return; + return SAVE_FAILED; } textW[0] = (WCHAR) 0xfeff; lenW = GetWindowTextW(Globals.hEdit, textW+1, lenW) + 1; - switch (Globals.encFile) + switch (enc) { case ENCODING_UTF16BE: byteswap_wide_string(textW, lenW); @@ -197,46 +236,54 @@ static VOID DoSaveFile(VOID) { ShowLastError(); HeapFree(GetProcessHeap(), 0, textW); - return; + return SAVE_FAILED; } WideCharToMultiByte(CP_UTF8, 0, textW, lenW, pBytes, size, NULL, NULL); HeapFree(GetProcessHeap(), 0, textW); break; default: + if (is_conversion_to_ansi_lossy(textW+1, lenW-1) + && AlertUnicodeCharactersLost(szFileName) == IDCANCEL) + { + HeapFree(GetProcessHeap(), 0, textW); + return SHOW_SAVEAS_DIALOG; + } + size = WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, NULL, 0, NULL, NULL); pBytes = HeapAlloc(GetProcessHeap(), 0, size); if (!pBytes) { ShowLastError(); HeapFree(GetProcessHeap(), 0, textW); - return; + return SAVE_FAILED; } WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, pBytes, size, NULL, NULL); HeapFree(GetProcessHeap(), 0, textW); break; } - hFile = CreateFileW(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, + hFile = CreateFileW(szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { ShowLastError(); HeapFree(GetProcessHeap(), 0, pBytes); - return; + return SAVE_FAILED; } if (!WriteFile(hFile, pBytes, size, &dwNumWrite, NULL)) { ShowLastError(); CloseHandle(hFile); HeapFree(GetProcessHeap(), 0, pBytes); - return; + return SAVE_FAILED; } SetEndOfFile(hFile); CloseHandle(hFile); HeapFree(GetProcessHeap(), 0, pBytes); SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0); + return SAVED_OK; } /** @@ -570,14 +617,20 @@ VOID DIALOG_FileOpen(VOID) DoOpenFile(openfilename.lpstrFile, Globals.encOfnCombo); } - +/* Return FALSE to cancel close */ BOOL DIALOG_FileSave(VOID) { if (Globals.szFileName[0] == '\0') return DIALOG_FileSaveAs(); else - DoSaveFile(); - return TRUE; + { + switch (DoSaveFile(Globals.szFileName, Globals.encFile)) + { + case SAVED_OK: return TRUE; + case SHOW_SAVEAS_DIALOG: return DIALOG_FileSaveAs(); + default: return FALSE; + } + } } BOOL DIALOG_FileSaveAs(VOID) @@ -611,13 +664,23 @@ BOOL DIALOG_FileSaveAs(VOID) Globals.encOfnCombo = Globals.encFile; Globals.bOfnIsOpenDialog = FALSE; - if (GetSaveFileNameW(&saveas)) { - SetFileNameAndEncoding(szPath, Globals.encOfnCombo); - UpdateWindowCaption(); - DoSaveFile(); - return TRUE; +retry: + if (!GetSaveFileNameW(&saveas)) + return FALSE; + + switch (DoSaveFile(szPath, Globals.encOfnCombo)) + { + case SAVED_OK: + SetFileNameAndEncoding(szPath, Globals.encOfnCombo); + UpdateWindowCaption(); + return TRUE; + + case SHOW_SAVEAS_DIALOG: + goto retry; + + default: + return FALSE; } - return FALSE; } typedef struct { diff --git a/programs/notepad/notepad_res.h b/programs/notepad/notepad_res.h index 7ea7f00..5428c0d 100644 --- a/programs/notepad/notepad_res.h +++ b/programs/notepad/notepad_res.h @@ -88,6 +88,8 @@ #define STRING_UNICODE_LE 0x180 #define STRING_UNICODE_BE 0x181 +#define STRING_LOSS_OF_UNICODE_CHARACTERS 0x182 + /* Open/Save As dialog template */ #define IDD_OFN_TEMPLATE 0x190 #define IDC_OFN_ENCCOMBO 0x191
1
0
0
0
Alexander Scott-Johns : notepad: Allow user to choose which encoding to open and save files in.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 67766392bf735c6c9007213bd14b64bdeeee389a URL:
http://source.winehq.org/git/wine.git/?a=commit;h=67766392bf735c6c9007213bd…
Author: Alexander Scott-Johns <alexander.scott.johns(a)googlemail.com> Date: Mon Jun 29 23:50:39 2009 +0100 notepad: Allow user to choose which encoding to open and save files in. --- programs/notepad/En.rc | 10 +++ programs/notepad/dialog.c | 153 +++++++++++++++++++++++++++++++++++++--- programs/notepad/dialog.h | 2 +- programs/notepad/main.c | 4 +- programs/notepad/main.h | 15 +++- programs/notepad/notepad_res.h | 7 ++ 6 files changed, 175 insertions(+), 16 deletions(-) Diff:
http://source.winehq.org/git/wine.git/?a=commitdiff;h=67766392bf735c6c90072…
1
0
0
0
Alexander Scott-Johns : notepad: Remember the encoding of files when they are opened, and use the same encoding when saving.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 080cc909929dc4eb64711120b6544d5f42634ebf URL:
http://source.winehq.org/git/wine.git/?a=commit;h=080cc909929dc4eb64711120b…
Author: Alexander Scott-Johns <alexander.scott.johns(a)googlemail.com> Date: Mon Jun 29 23:03:53 2009 +0100 notepad: Remember the encoding of files when they are opened, and use the same encoding when saving. --- programs/notepad/dialog.c | 82 +++++++++++++++++++++++++++++++++++--------- programs/notepad/main.c | 11 ++++-- programs/notepad/main.h | 3 +- 3 files changed, 74 insertions(+), 22 deletions(-) diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index 7f2fade..67a21a7 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -139,37 +139,82 @@ BOOL FileExists(LPCWSTR szFilename) static VOID DoSaveFile(VOID) { + int lenW; + WCHAR* textW; HANDLE hFile; DWORD dwNumWrite; - LPSTR pTemp; + PVOID pBytes; DWORD size; + /* lenW includes the byte-order mark, but not the \0. */ + lenW = GetWindowTextLengthW(Globals.hEdit) + 1; + textW = HeapAlloc(GetProcessHeap(), 0, (lenW+1) * sizeof(WCHAR)); + if (!textW) + { + ShowLastError(); + return; + } + textW[0] = (WCHAR) 0xfeff; + lenW = GetWindowTextW(Globals.hEdit, textW+1, lenW) + 1; + + switch (Globals.encFile) + { + case ENCODING_UTF16BE: + byteswap_wide_string(textW, lenW); + /* fall through */ + + case ENCODING_UTF16LE: + size = lenW * sizeof(WCHAR); + pBytes = textW; + break; + + case ENCODING_UTF8: + size = WideCharToMultiByte(CP_UTF8, 0, textW, lenW, NULL, 0, NULL, NULL); + pBytes = HeapAlloc(GetProcessHeap(), 0, size); + if (!pBytes) + { + ShowLastError(); + HeapFree(GetProcessHeap(), 0, textW); + return; + } + WideCharToMultiByte(CP_UTF8, 0, textW, lenW, pBytes, size, NULL, NULL); + HeapFree(GetProcessHeap(), 0, textW); + break; + + default: + size = WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, NULL, 0, NULL, NULL); + pBytes = HeapAlloc(GetProcessHeap(), 0, size); + if (!pBytes) + { + ShowLastError(); + HeapFree(GetProcessHeap(), 0, textW); + return; + } + WideCharToMultiByte(CP_ACP, 0, textW+1, lenW-1, pBytes, size, NULL, NULL); + HeapFree(GetProcessHeap(), 0, textW); + break; + } + hFile = CreateFileW(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { ShowLastError(); + HeapFree(GetProcessHeap(), 0, pBytes); return; } - - size = GetWindowTextLengthA(Globals.hEdit) + 1; - pTemp = HeapAlloc(GetProcessHeap(), 0, size); - if (!pTemp) + if (!WriteFile(hFile, pBytes, size, &dwNumWrite, NULL)) { - CloseHandle(hFile); ShowLastError(); + CloseHandle(hFile); + HeapFree(GetProcessHeap(), 0, pBytes); return; } - size = GetWindowTextA(Globals.hEdit, pTemp, size); - - if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL)) - ShowLastError(); - else - SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0); - SetEndOfFile(hFile); CloseHandle(hFile); - HeapFree(GetProcessHeap(), 0, pTemp); + HeapFree(GetProcessHeap(), 0, pBytes); + + SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0); } /** @@ -197,7 +242,7 @@ BOOL DoCloseFile(void) } /* switch */ } /* if */ - SetFileName(empty_strW); + SetFileNameAndEncoding(empty_strW, ENCODING_ANSI); UpdateWindowCaption(); return(TRUE); @@ -304,6 +349,9 @@ void DoOpenFile(LPCWSTR szFileName) { case ENCODING_UTF16BE: byteswap_wide_string((WCHAR*) pTemp, size/sizeof(WCHAR)); + /* Forget whether the file is BE or LE, like native Notepad. */ + enc = ENCODING_UTF16LE; + /* fall through */ case ENCODING_UTF16LE: @@ -349,7 +397,7 @@ void DoOpenFile(LPCWSTR szFileName) SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW); } - SetFileName(szFileName); + SetFileNameAndEncoding(szFileName, enc); UpdateWindowCaption(); } @@ -429,7 +477,7 @@ BOOL DIALOG_FileSaveAs(VOID) saveas.lpstrDefExt = szDefaultExt; if (GetSaveFileNameW(&saveas)) { - SetFileName(szPath); + SetFileNameAndEncoding(szPath, Globals.encFile); UpdateWindowCaption(); DoSaveFile(); return TRUE; diff --git a/programs/notepad/main.c b/programs/notepad/main.c index 7e33372..98eec96 100644 --- a/programs/notepad/main.c +++ b/programs/notepad/main.c @@ -64,15 +64,18 @@ static const WCHAR value_szFooter[] = {'s','z','T','r','a','i','l','e',' /*********************************************************************** * - * SetFileName + * SetFileNameAndEncoding * - * Sets Global File Name. + * Sets global file name and encoding (which is used to preselect original + * encoding in Save As dialog, and when saving without using the Save As + * dialog). */ -VOID SetFileName(LPCWSTR szFileName) +VOID SetFileNameAndEncoding(LPCWSTR szFileName, ENCODING enc) { lstrcpyW(Globals.szFileName, szFileName); Globals.szFileTitle[0] = 0; GetFileTitleW(szFileName, Globals.szFileTitle, sizeof(Globals.szFileTitle)); + Globals.encFile = enc; } /****************************************************************************** @@ -698,7 +701,7 @@ static void HandleCommandLine(LPWSTR cmdline) { switch (AlertFileDoesNotExist(file_name)) { case IDYES: - SetFileName(file_name); + SetFileNameAndEncoding(file_name, ENCODING_ANSI); UpdateWindowCaption(); break; diff --git a/programs/notepad/main.h b/programs/notepad/main.h index bb9b7cc..ac8b6ca 100644 --- a/programs/notepad/main.h +++ b/programs/notepad/main.h @@ -46,6 +46,7 @@ typedef struct WCHAR szReplaceText[MAX_PATH]; WCHAR szFileName[MAX_PATH]; WCHAR szFileTitle[MAX_PATH]; + ENCODING encFile; WCHAR szFilter[2 * MAX_STRING_LEN + 100]; INT iMarginTop; INT iMarginBottom; @@ -62,6 +63,6 @@ typedef struct extern NOTEPAD_GLOBALS Globals; -VOID SetFileName(LPCWSTR szFileName); +VOID SetFileNameAndEncoding(LPCWSTR szFileName, ENCODING enc); void NOTEPAD_DoFind(FINDREPLACEW *fr); DWORD get_dpi(void);
1
0
0
0
Alexander Scott-Johns : notepad: Improve encoding detection when opening files.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 8b6b7b2c39d77f7cd29657ecc3956955e5aa75c2 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=8b6b7b2c39d77f7cd29657ecc…
Author: Alexander Scott-Johns <alexander.scott.johns(a)googlemail.com> Date: Mon Jun 29 22:24:59 2009 +0100 notepad: Improve encoding detection when opening files. --- programs/notepad/dialog.c | 97 +++++++++++++++++++++++++++++++++++++++++--- programs/notepad/main.h | 8 ++++ 2 files changed, 98 insertions(+), 7 deletions(-) diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index 026fe25..7f2fade 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -26,6 +26,7 @@ #include <windows.h> #include <commdlg.h> #include <shlwapi.h> +#include <winternl.h> #include "main.h" #include "dialog.h" @@ -37,6 +38,13 @@ static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); +/* Swap bytes of WCHAR buffer (big-endian <-> little-endian). */ +static inline void byteswap_wide_string(LPWSTR str, UINT num) +{ + UINT i; + for (i = 0; i < num; i++) str[i] = RtlUshortByteSwap(str[i]); +} + VOID ShowLastError(void) { DWORD error = GetLastError(); @@ -195,6 +203,43 @@ BOOL DoCloseFile(void) return(TRUE); } +static inline ENCODING detect_encoding_of_buffer(const void* buffer, int size) +{ + static const char bom_utf8[] = { 0xef, 0xbb, 0xbf }; + if (size >= sizeof(bom_utf8) && !memcmp(buffer, bom_utf8, sizeof(bom_utf8))) + return ENCODING_UTF8; + else + { + int flags = IS_TEXT_UNICODE_SIGNATURE | + IS_TEXT_UNICODE_REVERSE_SIGNATURE | + IS_TEXT_UNICODE_ODD_LENGTH; + IsTextUnicode(buffer, size, &flags); + if (flags & IS_TEXT_UNICODE_SIGNATURE) + return ENCODING_UTF16LE; + else if (flags & IS_TEXT_UNICODE_REVERSE_SIGNATURE) + return ENCODING_UTF16BE; + else + return ENCODING_ANSI; + } +} + +/* Similar to SetWindowTextA, but uses a CP_UTF8 encoded input, not CP_ACP. + * lpTextInUtf8 should be NUL-terminated and not include the BOM. + * + * Returns FALSE on failure, TRUE on success, like SetWindowTextA/W. + */ +static BOOL SetWindowTextUtf8(HWND hwnd, LPCSTR lpTextInUtf8) +{ + BOOL ret; + int lenW = MultiByteToWideChar(CP_UTF8, 0, lpTextInUtf8, -1, NULL, 0); + LPWSTR textW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR)); + if (!textW) + return FALSE; + MultiByteToWideChar(CP_UTF8, 0, lpTextInUtf8, -1, textW, lenW); + ret = SetWindowTextW(hwnd, textW); + HeapFree(GetProcessHeap(), 0, textW); + return ret; +} void DoOpenFile(LPCWSTR szFileName) { @@ -203,6 +248,8 @@ void DoOpenFile(LPCWSTR szFileName) LPSTR pTemp; DWORD size; DWORD dwNumRead; + ENCODING enc; + BOOL succeeded; WCHAR log[5]; /* Close any files and prompt to save changes */ @@ -224,9 +271,9 @@ void DoOpenFile(LPCWSTR szFileName) ShowLastError(); return; } - size++; - pTemp = HeapAlloc(GetProcessHeap(), 0, size); + /* Extra memory for (WCHAR)'\0'-termination. */ + pTemp = HeapAlloc(GetProcessHeap(), 0, size+2); if (!pTemp) { CloseHandle(hFile); @@ -243,12 +290,48 @@ void DoOpenFile(LPCWSTR szFileName) } CloseHandle(hFile); - pTemp[dwNumRead] = 0; - if((size -1) >= 2 && (BYTE)pTemp[0] == 0xff && (BYTE)pTemp[1] == 0xfe) - SetWindowTextW(Globals.hEdit, (LPWSTR)pTemp + 1); - else - SetWindowTextA(Globals.hEdit, pTemp); + size = dwNumRead; + pTemp[size] = 0; /* make sure it's (char)'\0'-terminated */ + pTemp[size+1] = 0; /* make sure it's (WCHAR)'\0'-terminated */ + + enc = detect_encoding_of_buffer(pTemp, size); + + /* SetWindowTextUtf8 and SetWindowTextA try to allocate memory, so we + * check if they succeed. + */ + switch (enc) + { + case ENCODING_UTF16BE: + byteswap_wide_string((WCHAR*) pTemp, size/sizeof(WCHAR)); + /* fall through */ + + case ENCODING_UTF16LE: + if (size >= 2 && (BYTE)pTemp[0] == 0xff && (BYTE)pTemp[1] == 0xfe) + succeeded = SetWindowTextW(Globals.hEdit, (LPWSTR)pTemp + 1); + else + succeeded = SetWindowTextW(Globals.hEdit, (LPWSTR)pTemp); + break; + + case ENCODING_UTF8: + if (size >= 3 && (BYTE)pTemp[0] == 0xef && (BYTE)pTemp[1] == 0xbb && + (BYTE)pTemp[2] == 0xbf) + succeeded = SetWindowTextUtf8(Globals.hEdit, pTemp+3); + else + succeeded = SetWindowTextUtf8(Globals.hEdit, pTemp); + break; + + default: + succeeded = SetWindowTextA(Globals.hEdit, pTemp); + break; + } + + if (!succeeded) + { + ShowLastError(); + HeapFree(GetProcessHeap(), 0, pTemp); + return; + } HeapFree(GetProcessHeap(), 0, pTemp); diff --git a/programs/notepad/main.h b/programs/notepad/main.h index f81c437..bb9b7cc 100644 --- a/programs/notepad/main.h +++ b/programs/notepad/main.h @@ -25,6 +25,14 @@ #define MAX_STRING_LEN 255 +typedef enum +{ + ENCODING_ANSI, + ENCODING_UTF16LE, + ENCODING_UTF16BE, + ENCODING_UTF8 +} ENCODING; + typedef struct { HANDLE hInstance;
1
0
0
0
Alexander Scott-Johns : notepad: Fix trying to open non-existent files with the command line.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: 42729bc1c1cc513a82cae4f793dccce52da71ddb URL:
http://source.winehq.org/git/wine.git/?a=commit;h=42729bc1c1cc513a82cae4f79…
Author: Alexander Scott-Johns <alexander.scott.johns(a)googlemail.com> Date: Tue Jun 30 21:25:02 2009 +0100 notepad: Fix trying to open non-existent files with the command line. --- programs/notepad/dialog.c | 2 +- programs/notepad/dialog.h | 1 + programs/notepad/main.c | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index d7354e7..026fe25 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -59,7 +59,7 @@ VOID ShowLastError(void) * Untitled - Notepad if no file is open * filename - Notepad if a file is given */ -static void UpdateWindowCaption(void) +void UpdateWindowCaption(void) { WCHAR szCaption[MAX_STRING_LEN]; WCHAR szNotepad[MAX_STRING_LEN]; diff --git a/programs/notepad/dialog.h b/programs/notepad/dialog.h index d927143..38c20e4 100644 --- a/programs/notepad/dialog.h +++ b/programs/notepad/dialog.h @@ -52,6 +52,7 @@ int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFl /* utility functions */ VOID ShowLastError(void); +void UpdateWindowCaption(void); BOOL FileExists(LPCWSTR szFilename); BOOL DoCloseFile(void); void DoOpenFile(LPCWSTR szFileName); diff --git a/programs/notepad/main.c b/programs/notepad/main.c index c195668..7e33372 100644 --- a/programs/notepad/main.c +++ b/programs/notepad/main.c @@ -698,7 +698,8 @@ static void HandleCommandLine(LPWSTR cmdline) { switch (AlertFileDoesNotExist(file_name)) { case IDYES: - DoOpenFile(file_name); + SetFileName(file_name); + UpdateWindowCaption(); break; case IDNO:
1
0
0
0
Paul Vriens : oleaut32/tests: Fix test failures and crash on Win9x/WinME.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: f57c603798b238df4c236c7f698f4113271aa033 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=f57c603798b238df4c236c7f6…
Author: Paul Vriens <Paul.Vriens.Wine(a)gmail.com> Date: Thu Jul 2 08:52:25 2009 +0200 oleaut32/tests: Fix test failures and crash on Win9x/WinME. --- dlls/oleaut32/tests/usrmarshal.c | 96 ++++++++++++++++++++----------------- 1 files changed, 52 insertions(+), 44 deletions(-) Diff:
http://source.winehq.org/git/wine.git/?a=commitdiff;h=f57c603798b238df4c236…
1
0
0
0
Henri Verbeet : wined3d: Get rid of the silly refcount for the "fake" GL context.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: db6ea72201bed5f51ede902e08e37fdc3742ab22 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=db6ea72201bed5f51ede902e0…
Author: Henri Verbeet <hverbeet(a)codeweavers.com> Date: Thu Jul 2 10:01:38 2009 +0200 wined3d: Get rid of the silly refcount for the "fake" GL context. --- dlls/wined3d/directx.c | 35 +++++++++++++---------------------- 1 files changed, 13 insertions(+), 22 deletions(-) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 13651e6..87f6e89 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -197,7 +197,6 @@ glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT]; * function query some info from GL. */ -static int wined3d_fake_gl_context_ref = 0; static BOOL wined3d_fake_gl_context_available = FALSE; static HDC wined3d_fake_gl_context_hdc = NULL; static HWND wined3d_fake_gl_context_hwnd = NULL; @@ -224,26 +223,22 @@ static void WineD3D_ReleaseFakeGLContext(void) { } glCtx = pwglGetCurrentContext(); - - TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref); - if (0 == (--wined3d_fake_gl_context_ref) ) { - if (glCtx) + if (glCtx) + { + TRACE_(d3d_caps)("destroying fake GL context\n"); + if (!pwglMakeCurrent(NULL, NULL)) { - TRACE_(d3d_caps)("destroying fake GL context\n"); - if (!pwglMakeCurrent(NULL, NULL)) - { - ERR("Failed to disable fake GL context.\n"); - } - pwglDeleteContext(glCtx); + ERR("Failed to disable fake GL context.\n"); } - if(wined3d_fake_gl_context_hdc) - ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc); - wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */ - if(wined3d_fake_gl_context_hwnd) - DestroyWindow(wined3d_fake_gl_context_hwnd); - wined3d_fake_gl_context_hwnd = NULL; - wined3d_fake_gl_context_available = FALSE; + pwglDeleteContext(glCtx); } + if (wined3d_fake_gl_context_hdc) + ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc); + wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */ + if (wined3d_fake_gl_context_hwnd) + DestroyWindow(wined3d_fake_gl_context_hwnd); + wined3d_fake_gl_context_hwnd = NULL; + wined3d_fake_gl_context_available = FALSE; LeaveCriticalSection(&wined3d_fake_gl_context_cs); } @@ -256,7 +251,6 @@ static BOOL WineD3D_CreateFakeGLContext(void) { EnterCriticalSection(&wined3d_fake_gl_context_cs); TRACE("getting context...\n"); - if(wined3d_fake_gl_context_ref > 0) goto ret; /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */ wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", @@ -309,9 +303,6 @@ static BOOL WineD3D_CreateFakeGLContext(void) { } context_set_last_device(NULL); - ret: - TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref); - wined3d_fake_gl_context_ref++; wined3d_fake_gl_context_available = TRUE; LeaveCriticalSection(&wined3d_fake_gl_context_cs); return TRUE;
1
0
0
0
Henri Verbeet : wined3d: Don' t reuse random GL contexts during initialization.
by Alexandre Julliard
02 Jul '09
02 Jul '09
Module: wine Branch: master Commit: b5da7f49d332ed5d64be1256e14035af74a7efa2 URL:
http://source.winehq.org/git/wine.git/?a=commit;h=b5da7f49d332ed5d64be1256e…
Author: Henri Verbeet <hverbeet(a)codeweavers.com> Date: Thu Jul 2 10:01:37 2009 +0200 wined3d: Don't reuse random GL contexts during initialization. Obviously there's no guarantee about the state of such a context. The specific problem is that it might have GL_UNPACK_CLIENT_STORAGE_APPLE enabled, causing some glTexImage2D() calls to fail, but it's a bad idea in general. --- dlls/wined3d/directx.c | 99 ++++++++++++++++++++++++------------------------ 1 files changed, 49 insertions(+), 50 deletions(-) diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 9e50b0d..13651e6 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -198,7 +198,6 @@ glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT]; */ static int wined3d_fake_gl_context_ref = 0; -static BOOL wined3d_fake_gl_context_foreign; static BOOL wined3d_fake_gl_context_available = FALSE; static HDC wined3d_fake_gl_context_hdc = NULL; static HWND wined3d_fake_gl_context_hwnd = NULL; @@ -228,7 +227,8 @@ static void WineD3D_ReleaseFakeGLContext(void) { TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref); if (0 == (--wined3d_fake_gl_context_ref) ) { - if(!wined3d_fake_gl_context_foreign && glCtx) { + if (glCtx) + { TRACE_(d3d_caps)("destroying fake GL context\n"); if (!pwglMakeCurrent(NULL, NULL)) { @@ -249,64 +249,63 @@ static void WineD3D_ReleaseFakeGLContext(void) { } static BOOL WineD3D_CreateFakeGLContext(void) { + PIXELFORMATDESCRIPTOR pfd; HGLRC glCtx = NULL; + int iPixelFormat; EnterCriticalSection(&wined3d_fake_gl_context_cs); TRACE("getting context...\n"); if(wined3d_fake_gl_context_ref > 0) goto ret; - wined3d_fake_gl_context_foreign = TRUE; - - glCtx = pwglGetCurrentContext(); - if (!glCtx) { - PIXELFORMATDESCRIPTOR pfd; - int iPixelFormat; + /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */ + wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", + WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL); + if (!wined3d_fake_gl_context_hwnd) + { + ERR("HWND creation failed!\n"); + goto fail; + } - wined3d_fake_gl_context_foreign = FALSE; + wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd); + if (!wined3d_fake_gl_context_hdc) + { + ERR("GetDC failed!\n"); + goto fail; + } - /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */ - wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL); - if(!wined3d_fake_gl_context_hwnd) { - ERR("HWND creation failed!\n"); - goto fail; - } - wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd); - if(!wined3d_fake_gl_context_hdc) { - ERR("GetDC failed!\n"); - goto fail; - } + /* PixelFormat selection */ + ZeroMemory(&pfd, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */ + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 32; + pfd.iLayerType = PFD_MAIN_PLANE; + + iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd); + if (!iPixelFormat) + { + /* If this happens something is very wrong as ChoosePixelFormat barely fails. */ + ERR("Can't find a suitable iPixelFormat.\n"); + goto fail; + } + DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd); + SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd); - /* PixelFormat selection */ - ZeroMemory(&pfd, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/ - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 32; - pfd.iLayerType = PFD_MAIN_PLANE; - - iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd); - if(!iPixelFormat) { - /* If this happens something is very wrong as ChoosePixelFormat barely fails */ - ERR("Can't find a suitable iPixelFormat\n"); - goto fail; - } - DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd); - SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd); - - /* Create a GL context */ - glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc); - if (!glCtx) { - WARN_(d3d_caps)("Error creating default context for capabilities initialization\n"); - goto fail; - } + /* Create a GL context. */ + glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc); + if (!glCtx) + { + WARN_(d3d_caps)("Error creating default context for capabilities initialization.\n"); + goto fail; + } - /* Make it the current GL context */ - if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) { - ERR_(d3d_caps)("Failed to make fake GL context current.\n"); - goto fail; - } + /* Make it the current GL context. */ + if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) + { + ERR_(d3d_caps)("Failed to make fake GL context current.\n"); + goto fail; } context_set_last_device(NULL);
1
0
0
0
← Newer
1
...
94
95
96
97
98
99
100
...
107
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Results per page:
10
25
50
100
200