ReactOS.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
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
List overview
Download
Ros-diffs
July 2015
----- 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
ros-diffs@reactos.org
13 participants
257 discussions
Start a n
N
ew thread
[hbelusca] 68384: [KERNEL32] Since CsrClientCallServer returns the value of ApiMessage.Status, then just use ApiMessage.Status instead of declaring another Status variable for querying the return v...
by hbelusca@svn.reactos.org
Author: hbelusca Date: Fri Jul 10 23:57:26 2015 New Revision: 68384 URL:
http://svn.reactos.org/svn/reactos?rev=68384&view=rev
Log: [KERNEL32] Since CsrClientCallServer returns the value of ApiMessage.Status, then just use ApiMessage.Status instead of declaring another Status variable for querying the return value of CsrClientCallServer (continuation of r62460). Modified: trunk/reactos/dll/win32/kernel32/client/console/vista.c trunk/reactos/dll/win32/kernel32/client/dosdev.c trunk/reactos/dll/win32/kernel32/client/file/deviceio.c trunk/reactos/dll/win32/kernel32/client/file/filename.c trunk/reactos/dll/win32/kernel32/client/proc.c Modified: trunk/reactos/dll/win32/kernel32/client/console/vista.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/console/vista.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/console/vista.c [iso-8859-1] Fri Jul 10 23:57:26 2015 @@ -26,7 +26,6 @@ DECLSPEC_HOTPATCH GetConsoleHistoryInfo(PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo) { - NTSTATUS Status; CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &ApiMessage.Data.HistoryInfoRequest; @@ -36,13 +35,13 @@ return FALSE; } - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHistory), - sizeof(CONSOLE_GETSETHISTORYINFO)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepGetHistory), + sizeof(*HistoryInfoRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { - BaseSetLastNTError(Status); + BaseSetLastNTError(ApiMessage.Status); return FALSE; } @@ -62,7 +61,6 @@ DECLSPEC_HOTPATCH SetConsoleHistoryInfo(IN PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo) { - NTSTATUS Status; CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_GETSETHISTORYINFO HistoryInfoRequest = &ApiMessage.Data.HistoryInfoRequest; @@ -76,13 +74,13 @@ HistoryInfoRequest->NumberOfHistoryBuffers = lpConsoleHistoryInfo->NumberOfHistoryBuffers; HistoryInfoRequest->dwFlags = lpConsoleHistoryInfo->dwFlags; - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHistory), - sizeof(CONSOLE_GETSETHISTORYINFO)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetHistory), + sizeof(*HistoryInfoRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { - BaseSetLastNTError(Status); + BaseSetLastNTError(ApiMessage.Status); return FALSE; } Modified: trunk/reactos/dll/win32/kernel32/client/dosdev.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/dosdev.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/dosdev.c [iso-8859-1] Fri Jul 10 23:57:26 2015 @@ -85,7 +85,6 @@ BASE_API_MESSAGE ApiMessage; PBASE_DEFINE_DOS_DEVICE DefineDosDeviceRequest = &ApiMessage.Data.DefineDosDeviceRequest; PCSR_CAPTURE_BUFFER CaptureBuffer; - NTSTATUS Status; UNICODE_STRING NtTargetPathU; UNICODE_STRING DeviceNameU; UNICODE_STRING DeviceUpcaseNameU; @@ -174,16 +173,16 @@ DefineDosDeviceRequest->TargetPath.MaximumLength = NtTargetPathU.Length; - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - CaptureBuffer, - CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepDefineDosDevice), - sizeof(BASE_DEFINE_DOS_DEVICE)); + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepDefineDosDevice), + sizeof(*DefineDosDeviceRequest)); CsrFreeCaptureBuffer(CaptureBuffer); - if (!NT_SUCCESS(Status)) - { - WARN("CsrClientCallServer() failed (Status %lx)\n", Status); - BaseSetLastNTError(Status); + if (!NT_SUCCESS(ApiMessage.Status)) + { + WARN("CsrClientCallServer() failed (Status %lx)\n", ApiMessage.Status); + BaseSetLastNTError(ApiMessage.Status); Result = FALSE; } else Modified: trunk/reactos/dll/win32/kernel32/client/file/deviceio.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/deviceio.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/deviceio.c [iso-8859-1] Fri Jul 10 23:57:26 2015 @@ -36,7 +36,7 @@ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, NULL, CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSoundSentryNotification), - sizeof(BASE_SOUND_SENTRY)); + sizeof(*SoundSentryRequest)); } } Modified: trunk/reactos/dll/win32/kernel32/client/file/filename.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/file/filename.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/file/filename.c [iso-8859-1] Fri Jul 10 23:57:26 2015 @@ -161,7 +161,7 @@ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, NULL, CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetTempFile), - sizeof(BASE_GET_TEMP_FILE)); + sizeof(*GetTempFile)); if (GetTempFile->UniqueID == 0) { Num++; Modified: trunk/reactos/dll/win32/kernel32/client/proc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
============================================================================== --- trunk/reactos/dll/win32/kernel32/client/proc.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/kernel32/client/proc.c [iso-8859-1] Fri Jul 10 23:57:26 2015 @@ -499,7 +499,6 @@ BasepNotifyCsrOfThread(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId) { - NTSTATUS Status; BASE_API_MESSAGE ApiMessage; PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest; @@ -511,14 +510,14 @@ CreateThreadRequest->ThreadHandle = ThreadHandle; /* Call CSR */ - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread), - sizeof(BASE_CREATE_THREAD)); - if (!NT_SUCCESS(Status)) - { - DPRINT1("Failed to tell CSRSS about new thread: %lx\n", Status); - return Status; + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread), + sizeof(*CreateThreadRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) + { + DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status); + return ApiMessage.Status; } /* Return Success */ @@ -966,19 +965,18 @@ GetProcessShutdownParameters(OUT LPDWORD lpdwLevel, OUT LPDWORD lpdwFlags) { - NTSTATUS Status; BASE_API_MESSAGE ApiMessage; PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest; /* Ask CSRSS for shutdown information */ - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetProcessShutdownParam), - sizeof(BASE_GETSET_PROCESS_SHUTDOWN_PARAMS)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepGetProcessShutdownParam), + sizeof(*ShutdownParametersRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { /* Return the failure from CSRSS */ - BaseSetLastNTError(Status); + BaseSetLastNTError(ApiMessage.Status); return FALSE; } @@ -996,21 +994,20 @@ SetProcessShutdownParameters(IN DWORD dwLevel, IN DWORD dwFlags) { - NTSTATUS Status; BASE_API_MESSAGE ApiMessage; PBASE_GETSET_PROCESS_SHUTDOWN_PARAMS ShutdownParametersRequest = &ApiMessage.Data.ShutdownParametersRequest; /* Write the data into the CSRSS request and send it */ ShutdownParametersRequest->ShutdownLevel = dwLevel; ShutdownParametersRequest->ShutdownFlags = dwFlags; - Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, - NULL, - CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetProcessShutdownParam), - sizeof(BASE_GETSET_PROCESS_SHUTDOWN_PARAMS)); - if (!NT_SUCCESS(Status)) + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepSetProcessShutdownParam), + sizeof(*ShutdownParametersRequest)); + if (!NT_SUCCESS(ApiMessage.Status)) { /* Return the failure from CSRSS */ - BaseSetLastNTError(Status); + BaseSetLastNTError(ApiMessage.Status); return FALSE; } @@ -1555,7 +1552,7 @@ CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, NULL, CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepExitProcess), - sizeof(BASE_EXIT_PROCESS)); + sizeof(*ExitProcessRequest)); /* Now do it again */ NtTerminateProcess(NtCurrentProcess(), uExitCode);
9 years, 5 months
1
0
0
0
[bfreisen] 68383: [MSPAINT_NEW] use the same hard-coded observer pattern for the SelectionModel (WIP)
by bfreisen@svn.reactos.org
Author: bfreisen Date: Thu Jul 9 18:48:42 2015 New Revision: 68383 URL:
http://svn.reactos.org/svn/reactos?rev=68383&view=rev
Log: [MSPAINT_NEW] use the same hard-coded observer pattern for the SelectionModel (WIP) Modified: trunk/reactos/base/applications/mspaint_new/definitions.h trunk/reactos/base/applications/mspaint_new/palette.cpp trunk/reactos/base/applications/mspaint_new/palettemodel.cpp trunk/reactos/base/applications/mspaint_new/selection.cpp trunk/reactos/base/applications/mspaint_new/selection.h trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp trunk/reactos/base/applications/mspaint_new/selectionmodel.h trunk/reactos/base/applications/mspaint_new/toolsettings.cpp trunk/reactos/base/applications/mspaint_new/toolsmodel.cpp trunk/reactos/base/applications/mspaint_new/winproc.cpp Modified: trunk/reactos/base/applications/mspaint_new/definitions.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/definitions.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/definitions.h [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -228,3 +228,4 @@ #define WM_PALETTEMODELPALETTECHANGED (WM_APP + 4) #define WM_IMAGEMODELDIMENSIONSCHANGED (WM_APP + 5) #define WM_IMAGEMODELIMAGECHANGED (WM_APP + 6) +#define WM_SELECTIONMODELREFRESHNEEDED (WM_APP + 7) Modified: trunk/reactos/base/applications/mspaint_new/palette.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/palette.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/palette.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -61,22 +61,14 @@ LRESULT CPaletteWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (GET_X_LPARAM(lParam) >= 31) - { paletteModel.SetFgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14)); - if (toolsModel.GetActiveTool() == 10) - ForceRefreshSelectionContents(); - } return 0; } LRESULT CPaletteWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (GET_X_LPARAM(lParam) >= 31) - { paletteModel.SetBgColor(paletteModel.GetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14)); - if (toolsModel.GetActiveTool() == 10) - ForceRefreshSelectionContents(); - } return 0; } @@ -88,8 +80,6 @@ paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14, choosecolor.rgbResult); paletteModel.SetFgColor(choosecolor.rgbResult); - if (toolsModel.GetActiveTool() == 10) - ForceRefreshSelectionContents(); } return 0; } @@ -102,8 +92,6 @@ paletteModel.SetColor((GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14, choosecolor.rgbResult); paletteModel.SetBgColor(choosecolor.rgbResult); - if (toolsModel.GetActiveTool() == 10) - ForceRefreshSelectionContents(); } return 0; } Modified: trunk/reactos/base/applications/mspaint_new/palettemodel.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/palettemodel.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/palettemodel.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -90,6 +90,7 @@ void PaletteModel::NotifyColorChanged() { paletteWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED); + selectionWindow.SendMessage(WM_PALETTEMODELCOLORCHANGED); } void PaletteModel::NotifyPaletteChanged() Modified: trunk/reactos/base/applications/mspaint_new/selection.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selection.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selection.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -229,3 +229,25 @@ } return 0; } + +LRESULT CSelectionWindow::OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (toolsModel.GetActiveTool() == TOOL_TEXT) + ForceRefreshSelectionContents(); + return 0; +} + +LRESULT CSelectionWindow::OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if (toolsModel.GetActiveTool() == TOOL_FREESEL || + toolsModel.GetActiveTool() == TOOL_RECTSEL || + toolsModel.GetActiveTool() == TOOL_TEXT) + ForceRefreshSelectionContents(); + return 0; +} + +LRESULT CSelectionWindow::OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + ForceRefreshSelectionContents(); + return 0; +} Modified: trunk/reactos/base/applications/mspaint_new/selection.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selection.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selection.h [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -20,6 +20,9 @@ MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown) MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove) MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp) + MESSAGE_HANDLER(WM_PALETTEMODELCOLORCHANGED, OnPaletteModelColorChanged) + MESSAGE_HANDLER(WM_TOOLSMODELSETTINGSCHANGED, OnToolsModelSettingsChanged) + MESSAGE_HANDLER(WM_SELECTIONMODELREFRESHNEEDED, OnSelectionModelRefreshNeeded) END_MSG_MAP() LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); @@ -30,6 +33,9 @@ LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSelectionModelRefreshNeeded(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); private: static const LPCTSTR m_lpszCursorLUT[9]; Modified: trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -183,6 +183,7 @@ SelectObject(m_hDC, m_hBm); StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, 0, -RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + NotifyRefreshNeeded(); } void SelectionModel::FlipVertically() @@ -193,6 +194,7 @@ SelectObject(m_hDC, m_hBm); StretchBlt(m_hDC, 0, RECT_HEIGHT(m_rcDest) - 1, RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + NotifyRefreshNeeded(); } void SelectionModel::RotateNTimes90Degrees(int iN) @@ -206,6 +208,7 @@ StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, RECT_HEIGHT(m_rcDest) - 1, -RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); } + NotifyRefreshNeeded(); } HBITMAP SelectionModel::GetBitmap() @@ -326,3 +329,8 @@ { Text(hDCImage, m_rcDest.left, m_rcDest.top, m_rcDest.right, m_rcDest.bottom, crFg, crBg, textToolText, hfontTextFont, bBgTransparent); } + +void SelectionModel::NotifyRefreshNeeded() +{ + selectionWindow.SendMessage(WM_SELECTIONMODELREFRESHNEEDED); +} Modified: trunk/reactos/base/applications/mspaint_new/selectionmodel.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selectionmodel.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selectionmodel.h [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -33,6 +33,7 @@ // void NotifySelectionChanging(); // void NotifySelectionChanged(); + void NotifyRefreshNeeded(); public: SelectionModel(); Modified: trunk/reactos/base/applications/mspaint_new/toolsettings.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/toolsettings.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/toolsettings.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -188,11 +188,7 @@ case TOOL_RECTSEL: case TOOL_TEXT: if ((y > 1) && (y < 64)) - { toolsModel.SetBackgroundTransparent((y - 2) / 31); - - ForceRefreshSelectionContents(); - } break; case TOOL_RUBBER: if ((y > 1) && (y < 62)) Modified: trunk/reactos/base/applications/mspaint_new/toolsmodel.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/toolsmodel.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/toolsmodel.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -122,6 +122,7 @@ void ToolsModel::NotifyToolSettingsChanged() { toolSettingsWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED); + selectionWindow.SendMessage(WM_TOOLSMODELSETTINGSCHANGED); } void ToolsModel::NotifyZoomChanged() Modified: trunk/reactos/base/applications/mspaint_new/winproc.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/winproc.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/winproc.cpp [iso-8859-1] Thu Jul 9 18:48:42 2015 @@ -448,10 +448,7 @@ { case 1: /* flip horizontally */ if (selectionWindow.IsWindowVisible()) - { selectionModel.FlipHorizontally(); - ForceRefreshSelectionContents(); - } else { imageModel.CopyPrevious(); @@ -462,10 +459,7 @@ break; case 2: /* flip vertically */ if (selectionWindow.IsWindowVisible()) - { selectionModel.FlipVertically(); - ForceRefreshSelectionContents(); - } else { imageModel.CopyPrevious(); @@ -478,10 +472,7 @@ break; case 4: /* rotate 180 degrees */ if (selectionWindow.IsWindowVisible()) - { selectionModel.RotateNTimes90Degrees(2); - ForceRefreshSelectionContents(); - } else { imageModel.CopyPrevious();
9 years, 5 months
1
0
0
0
[bfreisen] 68382: [MSPAINT_NEW] refactoring: move selection management to a dedicated SelectionModel (WIP)
by bfreisen@svn.reactos.org
Author: bfreisen Date: Thu Jul 9 09:48:01 2015 New Revision: 68382 URL:
http://svn.reactos.org/svn/reactos?rev=68382&view=rev
Log: [MSPAINT_NEW] refactoring: move selection management to a dedicated SelectionModel (WIP) Added: trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp (with props) trunk/reactos/base/applications/mspaint_new/selectionmodel.h (with props) Modified: trunk/reactos/base/applications/mspaint_new/CMakeLists.txt trunk/reactos/base/applications/mspaint_new/globalvar.h trunk/reactos/base/applications/mspaint_new/main.cpp trunk/reactos/base/applications/mspaint_new/mouse.cpp trunk/reactos/base/applications/mspaint_new/precomp.h trunk/reactos/base/applications/mspaint_new/selection.cpp trunk/reactos/base/applications/mspaint_new/selection.h trunk/reactos/base/applications/mspaint_new/winproc.cpp Modified: trunk/reactos/base/applications/mspaint_new/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/CMakeLists.txt [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/CMakeLists.txt [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -18,6 +18,7 @@ registry.cpp scrollbox.cpp selection.cpp + selectionmodel.cpp sizebox.cpp textedit.cpp toolbox.cpp Modified: trunk/reactos/base/applications/mspaint_new/globalvar.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/globalvar.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/globalvar.h [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -21,7 +21,6 @@ /* VARIABLES declared in main.c *************************************/ extern HDC hDrawingDC; -extern HDC hSelDC; extern int *bmAddress; extern BITMAPINFO bitmapinfo; @@ -39,10 +38,9 @@ class ToolsModel; extern ToolsModel toolsModel; -extern RECT rectSel_src; -extern RECT rectSel_dest; -extern HBITMAP hSelBm; -extern HBITMAP hSelMask; +class SelectionModel; +extern SelectionModel selectionModel; + extern HWND hwndEditCtl; extern LOGFONT lfTextFont; extern HFONT hfontTextFont; @@ -114,5 +112,3 @@ extern POINT pointStack[256]; extern short pointSP; -extern POINT *ptStack; -extern int ptSP; Modified: trunk/reactos/base/applications/mspaint_new/main.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/main.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/main.cpp [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -13,7 +13,6 @@ /* FUNCTIONS ********************************************************/ HDC hDrawingDC; -HDC hSelDC; int *bmAddress; BITMAPINFO bitmapinfo; int imgXRes = 400; @@ -31,10 +30,8 @@ ToolsModel toolsModel; -RECT rectSel_src; -RECT rectSel_dest; -HBITMAP hSelBm; -HBITMAP hSelMask; +SelectionModel selectionModel; + LOGFONT lfTextFont; HFONT hfontTextFont; HWND hwndEditCtl; @@ -205,7 +202,7 @@ hDC = imageArea.GetDC(); hDrawingDC = CreateCompatibleDC(hDC); - hSelDC = CreateCompatibleDC(hDC); + selectionModel.SetDC(CreateCompatibleDC(hDC)); imageArea.ReleaseDC(hDC); SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, paletteModel.GetFgColor())); SelectObject(hDrawingDC, CreateSolidBrush(paletteModel.GetBgColor())); Modified: trunk/reactos/base/applications/mspaint_new/mouse.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/mouse.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/mouse.cpp [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -15,44 +15,42 @@ void placeSelWin() { - selectionWindow.MoveWindow(rectSel_dest.left * toolsModel.GetZoom() / 1000, rectSel_dest.top * toolsModel.GetZoom() / 1000, - RECT_WIDTH(rectSel_dest) * toolsModel.GetZoom() / 1000 + 6, RECT_HEIGHT(rectSel_dest) * toolsModel.GetZoom() / 1000 + 6, TRUE); + selectionWindow.MoveWindow(selectionModel.GetDestRectLeft() * toolsModel.GetZoom() / 1000, selectionModel.GetDestRectTop() * toolsModel.GetZoom() / 1000, + selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6, selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6, TRUE); selectionWindow.BringWindowToTop(); imageArea.InvalidateRect(NULL, FALSE); } void -regularize(LONG x0, LONG y0, LONG *x1, LONG *y1) -{ - if (abs(*x1 - x0) >= abs(*y1 - y0)) - *y1 = y0 + (*y1 > y0 ? abs(*x1 - x0) : -abs(*x1 - x0)); +regularize(LONG x0, LONG y0, LONG& x1, LONG& y1) +{ + if (abs(x1 - x0) >= abs(y1 - y0)) + y1 = y0 + (y1 > y0 ? abs(x1 - x0) : -abs(x1 - x0)); else - *x1 = x0 + (*x1 > x0 ? abs(*y1 - y0) : -abs(*y1 - y0)); -} - -void -roundTo8Directions(LONG x0, LONG y0, LONG *x1, LONG *y1) -{ - if (abs(*x1 - x0) >= abs(*y1 - y0)) - { - if (abs(*y1 - y0) * 5 < abs(*x1 - x0) * 2) - *y1 = y0; + x1 = x0 + (x1 > x0 ? abs(y1 - y0) : -abs(y1 - y0)); +} + +void +roundTo8Directions(LONG x0, LONG y0, LONG& x1, LONG& y1) +{ + if (abs(x1 - x0) >= abs(y1 - y0)) + { + if (abs(y1 - y0) * 5 < abs(x1 - x0) * 2) + y1 = y0; else - *y1 = y0 + (*y1 > y0 ? abs(*x1 - x0) : -abs(*x1 - x0)); + y1 = y0 + (y1 > y0 ? abs(x1 - x0) : -abs(x1 - x0)); } else { - if (abs(*x1 - x0) * 5 < abs(*y1 - y0) * 2) - *x1 = x0; + if (abs(x1 - x0) * 5 < abs(y1 - y0) * 2) + x1 = x0; else - *x1 = x0 + (*x1 > x0 ? abs(*y1 - y0) : -abs(*y1 - y0)); + x1 = x0 + (x1 > x0 ? abs(y1 - y0) : -abs(y1 - y0)); } } POINT pointStack[256]; short pointSP; -POINT *ptStack = NULL; -int ptSP = 0; void startPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg) @@ -65,12 +63,8 @@ { case TOOL_FREESEL: selectionWindow.ShowWindow(SW_HIDE); - if (ptStack != NULL) - HeapFree(GetProcessHeap(), 0, ptStack); - ptStack = (POINT*) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * 1024); - ptSP = 0; - ptStack[0].x = x; - ptStack[0].y = y; + selectionModel.ResetPtStack(); + selectionModel.PushToPtStack(x, y); break; case TOOL_LINE: case TOOL_RECT: @@ -82,8 +76,7 @@ case TOOL_TEXT: imageModel.CopyPrevious(); selectionWindow.ShowWindow(SW_HIDE); - rectSel_src.right = rectSel_src.left; - rectSel_src.bottom = rectSel_src.top; + selectionModel.SetSrcRectSizeToZero(); break; case TOOL_RUBBER: imageModel.CopyPrevious(); @@ -134,15 +127,11 @@ switch (toolsModel.GetActiveTool()) { case TOOL_FREESEL: - if (ptSP == 0) - imageModel.CopyPrevious(); - ptSP++; - if (ptSP % 1024 == 0) - ptStack = (POINT*) HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, ptStack, sizeof(POINT) * (ptSP + 1024)); - ptStack[ptSP].x = max(0, min(x, imageModel.GetWidth())); - ptStack[ptSP].y = max(0, min(y, imageModel.GetHeight())); - imageModel.ResetToPrevious(); - Poly(hdc, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE, TRUE); /* draw the freehand selection inverted/xored */ + if (selectionModel.PtStackSize() == 1) + imageModel.CopyPrevious(); + selectionModel.PushToPtStack(max(0, min(x, imageModel.GetWidth())), max(0, min(y, imageModel.GetHeight()))); + imageModel.ResetToPrevious(); + selectionModel.DrawFramePoly(hdc); break; case TOOL_RECTSEL: case TOOL_TEXT: @@ -151,10 +140,7 @@ imageModel.ResetToPrevious(); temp.x = max(0, min(x, imageModel.GetWidth())); temp.y = max(0, min(y, imageModel.GetHeight())); - rectSel_dest.left = rectSel_src.left = min(start.x, temp.x); - rectSel_dest.top = rectSel_src.top = min(start.y, temp.y); - rectSel_dest.right = rectSel_src.right = max(start.x, temp.x); - rectSel_dest.bottom = rectSel_src.bottom = max(start.y, temp.y); + selectionModel.SetSrcAndDestRectFromPoints(start, temp); RectSel(hdc, start.x, start.y, temp.x, temp.y); break; } @@ -173,7 +159,7 @@ case TOOL_LINE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - roundTo8Directions(start.x, start.y, &x, &y); + roundTo8Directions(start.x, start.y, x, y); Line(hdc, start.x, start.y, x, y, fg, toolsModel.GetLineWidth()); break; case TOOL_BEZIER: @@ -197,7 +183,7 @@ case TOOL_RECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Rect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_SHAPE: @@ -206,20 +192,20 @@ pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, - &pointStack[pointSP].x, &pointStack[pointSP].y); + pointStack[pointSP].x, pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), FALSE, FALSE); break; case TOOL_ELLIPSE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Ellp(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_RRECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; } @@ -235,96 +221,47 @@ { case TOOL_FREESEL: { - POINT *ptStackCopy; - int i; - rectSel_src.left = rectSel_src.top = MAXLONG; - rectSel_src.right = rectSel_src.bottom = 0; - for (i = 0; i <= ptSP; i++) - { - if (ptStack[i].x < rectSel_src.left) - rectSel_src.left = ptStack[i].x; - if (ptStack[i].y < rectSel_src.top) - rectSel_src.top = ptStack[i].y; - if (ptStack[i].x > rectSel_src.right) - rectSel_src.right = ptStack[i].x; - if (ptStack[i].y > rectSel_src.bottom) - rectSel_src.bottom = ptStack[i].y; - } - rectSel_src.right += 1; - rectSel_src.bottom += 1; - rectSel_dest.left = rectSel_src.left; - rectSel_dest.top = rectSel_src.top; - rectSel_dest.right = rectSel_src.right; - rectSel_dest.bottom = rectSel_src.bottom; - if (ptSP != 0) - { - DeleteObject(hSelMask); - hSelMask = CreateBitmap(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 1, 1, NULL); - DeleteObject(SelectObject(hSelDC, hSelMask)); - ptStackCopy = (POINT*) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * (ptSP + 1)); - for (i = 0; i <= ptSP; i++) - { - ptStackCopy[i].x = ptStack[i].x - rectSel_src.left; - ptStackCopy[i].y = ptStack[i].y - rectSel_src.top; - } - Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE, FALSE); - HeapFree(GetProcessHeap(), 0, ptStackCopy); - SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src))); - imageModel.ResetToPrevious(); - MaskBlt(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hDrawingDC, rectSel_src.left, - rectSel_src.top, hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS)); - Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE, FALSE); - imageModel.CopyPrevious(); - - MaskBlt(hDrawingDC, rectSel_src.left, rectSel_src.top, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hSelDC, 0, - 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); - - placeSelWin(); - selectionWindow.ShowWindow(SW_SHOW); - /* force refresh of selection contents */ - selectionWindow.SendMessage(WM_LBUTTONDOWN, 0, 0); - selectionWindow.SendMessage(WM_MOUSEMOVE, 0, 0); - selectionWindow.SendMessage(WM_LBUTTONUP, 0, 0); - } - HeapFree(GetProcessHeap(), 0, ptStack); - ptStack = NULL; - break; - } - case TOOL_RECTSEL: - imageModel.ResetToPrevious(); - if ((RECT_WIDTH(rectSel_src) != 0) && (RECT_HEIGHT(rectSel_src) != 0)) - { - DeleteObject(hSelMask); - hSelMask = CreateBitmap(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 1, 1, NULL); - DeleteObject(SelectObject(hSelDC, hSelMask)); - Rect(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), 0x00ffffff, 0x00ffffff, 1, 2); - SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src))); - imageModel.ResetToPrevious(); - BitBlt(hSelDC, 0, 0, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hDrawingDC, rectSel_src.left, - rectSel_src.top, SRCCOPY); - Rect(hdc, rectSel_src.left, rectSel_src.top, rectSel_src.right, - rectSel_src.bottom, bg, bg, 0, TRUE); - imageModel.CopyPrevious(); - - BitBlt(hDrawingDC, rectSel_src.left, rectSel_src.top, RECT_WIDTH(rectSel_src), RECT_HEIGHT(rectSel_src), hSelDC, 0, - 0, SRCCOPY); + selectionModel.CalculateBoundingBoxAndContents(hdc); + if (selectionModel.PtStackSize() > 1) + { + selectionModel.DrawBackgroundPoly(hdc, bg); + imageModel.CopyPrevious(); + + selectionModel.DrawSelection(hdc); placeSelWin(); selectionWindow.ShowWindow(SW_SHOW); ForceRefreshSelectionContents(); } - break; - case TOOL_TEXT: - imageModel.ResetToPrevious(); - if ((RECT_WIDTH(rectSel_src) != 0) && (RECT_HEIGHT(rectSel_src) != 0)) - { - imageModel.CopyPrevious(); + selectionModel.ResetPtStack(); + break; + } + case TOOL_RECTSEL: + imageModel.ResetToPrevious(); + if (selectionModel.IsSrcRectSizeNonzero()) + { + selectionModel.CalculateContents(hdc); + selectionModel.DrawBackgroundRect(hdc, bg); + imageModel.CopyPrevious(); + + selectionModel.DrawSelection(hdc); placeSelWin(); selectionWindow.ShowWindow(SW_SHOW); ForceRefreshSelectionContents(); } break; + case TOOL_TEXT: + imageModel.ResetToPrevious(); + if (selectionModel.IsSrcRectSizeNonzero()) + { + imageModel.CopyPrevious(); + + placeSelWin(); + selectionWindow.ShowWindow(SW_SHOW); + ForceRefreshSelectionContents(); + } + break; case TOOL_RUBBER: Erase(hdc, last.x, last.y, x, y, bg, toolsModel.GetRubberRadius()); break; @@ -335,7 +272,7 @@ case TOOL_LINE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - roundTo8Directions(start.x, start.y, &x, &y); + roundTo8Directions(start.x, start.y, x, y); Line(hdc, start.x, start.y, x, y, fg, toolsModel.GetLineWidth()); break; case TOOL_BEZIER: @@ -346,7 +283,7 @@ case TOOL_RECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Rect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_SHAPE: @@ -355,7 +292,7 @@ pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, - &pointStack[pointSP].x, &pointStack[pointSP].y); + pointStack[pointSP].x, pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { @@ -376,13 +313,13 @@ case TOOL_ELLIPSE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Ellp(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_RRECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); RRect(hdc, start.x, start.y, x, y, fg, bg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; } @@ -468,7 +405,7 @@ case TOOL_LINE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - roundTo8Directions(start.x, start.y, &x, &y); + roundTo8Directions(start.x, start.y, x, y); Line(hdc, start.x, start.y, x, y, bg, toolsModel.GetLineWidth()); break; case TOOL_BEZIER: @@ -492,7 +429,7 @@ case TOOL_RECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Rect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_SHAPE: @@ -501,20 +438,20 @@ pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, - &pointStack[pointSP].x, &pointStack[pointSP].y); + pointStack[pointSP].x, pointStack[pointSP].y); if (pointSP + 1 >= 2) Poly(hdc, pointStack, pointSP + 1, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle(), FALSE, FALSE); break; case TOOL_ELLIPSE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Ellp(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_RRECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; } @@ -538,7 +475,7 @@ case TOOL_LINE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - roundTo8Directions(start.x, start.y, &x, &y); + roundTo8Directions(start.x, start.y, x, y); Line(hdc, start.x, start.y, x, y, bg, toolsModel.GetLineWidth()); break; case TOOL_BEZIER: @@ -549,7 +486,7 @@ case TOOL_RECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Rect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_SHAPE: @@ -558,7 +495,7 @@ pointStack[pointSP].y = y; if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0)) roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y, - &pointStack[pointSP].x, &pointStack[pointSP].y); + pointStack[pointSP].x, pointStack[pointSP].y); pointSP++; if (pointSP >= 2) { @@ -579,13 +516,13 @@ case TOOL_ELLIPSE: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); Ellp(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; case TOOL_RRECT: imageModel.ResetToPrevious(); if (GetAsyncKeyState(VK_SHIFT) < 0) - regularize(start.x, start.y, &x, &y); + regularize(start.x, start.y, x, y); RRect(hdc, start.x, start.y, x, y, bg, fg, toolsModel.GetLineWidth(), toolsModel.GetShapeStyle()); break; } Modified: trunk/reactos/base/applications/mspaint_new/precomp.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/precomp.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/precomp.h [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -30,6 +30,7 @@ #include "palettemodel.h" #include "scrollbox.h" #include "selection.h" +#include "selectionmodel.h" #include "sizebox.h" #include "textedit.h" #include "toolbox.h" Modified: trunk/reactos/base/applications/mspaint_new/selection.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selection.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selection.cpp [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -10,34 +10,15 @@ #include "precomp.h" -/* DEFINES **********************************************************/ - -#define ACTION_MOVE 0 -#define ACTION_RESIZE_TOP_LEFT 1 -#define ACTION_RESIZE_TOP 2 -#define ACTION_RESIZE_TOP_RIGHT 3 -#define ACTION_RESIZE_LEFT 4 -#define ACTION_RESIZE_RIGHT 5 -#define ACTION_RESIZE_BOTTOM_LEFT 6 -#define ACTION_RESIZE_BOTTOM 7 -#define ACTION_RESIZE_BOTTOM_RIGHT 8 - /* FUNCTIONS ********************************************************/ -LPCTSTR cursors[9] = { /* action to mouse cursor lookup table */ +const LPCTSTR CSelectionWindow::m_lpszCursorLUT[9] = { /* action to mouse cursor lookup table */ IDC_SIZEALL, IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW, IDC_SIZEWE, IDC_SIZEWE, IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE }; - -BOOL moving = FALSE; -int action = ACTION_MOVE; -POINTS pos; -POINTS frac; -POINT delta; -DWORD system_selection_color; BOOL ColorKeyedMaskBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, HBITMAP hbmMask, int xMask, int yMask, DWORD dwRop, COLORREF keyColor) @@ -81,32 +62,31 @@ } } -int -identifyCorner(short x, short y, short w, short h) -{ - if (y < 3) - { - if (x < 3) +int CSelectionWindow::IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight) +{ + if (iYPos < 3) + { + if (iXPos < 3) return ACTION_RESIZE_TOP_LEFT; - if ((x < w / 2 + 2) && (x >= w / 2 - 1)) + if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1)) return ACTION_RESIZE_TOP; - if (x >= w - 3) + if (iXPos >= iWidth - 3) return ACTION_RESIZE_TOP_RIGHT; } - if ((y < h / 2 + 2) && (y >= h / 2 - 1)) - { - if (x < 3) + if ((iYPos < iHeight / 2 + 2) && (iYPos >= iHeight / 2 - 1)) + { + if (iXPos < 3) return ACTION_RESIZE_LEFT; - if (x >= w - 3) + if (iXPos >= iWidth - 3) return ACTION_RESIZE_RIGHT; } - if (y >= h - 3) - { - if (x < 3) + if (iYPos >= iHeight - 3) + { + if (iXPos < 3) return ACTION_RESIZE_BOTTOM_LEFT; - if ((x < w / 2 + 2) && (x >= w / 2 - 1)) + if ((iXPos < iWidth / 2 + 2) && (iXPos >= iWidth / 2 - 1)) return ACTION_RESIZE_BOTTOM; - if (x >= w - 3) + if (iXPos >= iWidth - 3) return ACTION_RESIZE_BOTTOM_RIGHT; } return 0; @@ -114,13 +94,13 @@ LRESULT CSelectionWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (!moving) + if (!m_bMoving) { HDC hDC = GetDC(); DefWindowProc(WM_PAINT, wParam, lParam); - SelectionFrame(hDC, 1, 1, RECT_WIDTH(rectSel_dest) * toolsModel.GetZoom() / 1000 + 5, - RECT_HEIGHT(rectSel_dest) * toolsModel.GetZoom() / 1000 + 5, - system_selection_color); + SelectionFrame(hDC, 1, 1, selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 5, + selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 5, + m_dwSystemSelectionColor); ReleaseDC(hDC); } return 0; @@ -134,8 +114,10 @@ LRESULT CSelectionWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + m_bMoving = FALSE; + m_iAction = ACTION_MOVE; /* update the system selection color */ - system_selection_color = GetSysColor(COLOR_HIGHLIGHT); + m_dwSystemSelectionColor = GetSysColor(COLOR_HIGHLIGHT); SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0)); return 0; } @@ -143,7 +125,7 @@ LRESULT CSelectionWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { /* update the system selection color */ - system_selection_color = GetSysColor(COLOR_HIGHLIGHT); + m_dwSystemSelectionColor = GetSysColor(COLOR_HIGHLIGHT); SendMessage(WM_PAINT, 0, MAKELPARAM(0, 0)); return 0; } @@ -156,14 +138,14 @@ LRESULT CSelectionWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - pos.x = GET_X_LPARAM(lParam); - pos.y = GET_Y_LPARAM(lParam); - delta.x = 0; - delta.y = 0; + m_ptPos.x = GET_X_LPARAM(lParam); + m_ptPos.y = GET_Y_LPARAM(lParam); + m_ptDelta.x = 0; + m_ptDelta.y = 0; SetCapture(); - if (action != ACTION_MOVE) - SetCursor(LoadCursor(NULL, cursors[action])); - moving = TRUE; + if (m_iAction != ACTION_MOVE) + SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction])); + m_bMoving = TRUE; scrlClientWindow.InvalidateRect(NULL, TRUE); imageArea.SendMessage(WM_PAINT, 0, 0); return 0; @@ -171,127 +153,66 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (moving) + if (m_bMoving) { TCHAR sizeStr[100]; - POINT deltaUsed; imageModel.ResetToPrevious(); - frac.x += GET_X_LPARAM(lParam) - pos.x; - frac.y += GET_Y_LPARAM(lParam) - pos.y; - delta.x += frac.x * 1000 / toolsModel.GetZoom(); - delta.y += frac.y * 1000 / toolsModel.GetZoom(); + m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x; + m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y; + m_ptDelta.x += m_ptFrac.x * 1000 / toolsModel.GetZoom(); + m_ptDelta.y += m_ptFrac.y * 1000 / toolsModel.GetZoom(); if (toolsModel.GetZoom() < 1000) { - frac.x = 0; - frac.y = 0; + m_ptFrac.x = 0; + m_ptFrac.y = 0; } else { - frac.x -= (frac.x * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000; - frac.y -= (frac.y * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000; - } - switch (action) - { - case ACTION_MOVE: /* move selection */ - deltaUsed.x = delta.x; - deltaUsed.y = delta.y; - OffsetRect(&rectSel_dest, deltaUsed.x, deltaUsed.y); - break; - case ACTION_RESIZE_TOP_LEFT: /* resize at upper left corner */ - deltaUsed.x = min(delta.x, RECT_WIDTH(rectSel_dest) - 1); - deltaUsed.y = min(delta.y, RECT_HEIGHT(rectSel_dest) - 1); - rectSel_dest.left += deltaUsed.x; - rectSel_dest.top += deltaUsed.y; - break; - case ACTION_RESIZE_TOP: /* resize at top edge */ - deltaUsed.x = delta.x; - deltaUsed.y = min(delta.y, RECT_HEIGHT(rectSel_dest) - 1); - rectSel_dest.top += deltaUsed.y; - break; - case ACTION_RESIZE_TOP_RIGHT: /* resize at upper right corner */ - deltaUsed.x = max(delta.x, -(RECT_WIDTH(rectSel_dest) - 1)); - deltaUsed.y = min(delta.y, RECT_HEIGHT(rectSel_dest) - 1); - rectSel_dest.top += deltaUsed.y; - rectSel_dest.right += deltaUsed.x; - break; - case ACTION_RESIZE_LEFT: /* resize at left edge */ - deltaUsed.x = min(delta.x, RECT_WIDTH(rectSel_dest) - 1); - deltaUsed.y = delta.y; - rectSel_dest.left += deltaUsed.x; - break; - case ACTION_RESIZE_RIGHT: /* resize at right edge */ - deltaUsed.x = max(delta.x, -(RECT_WIDTH(rectSel_dest) - 1)); - deltaUsed.y = delta.y; - rectSel_dest.right += deltaUsed.x; - break; - case ACTION_RESIZE_BOTTOM_LEFT: /* resize at lower left corner */ - deltaUsed.x = min(delta.x, RECT_WIDTH(rectSel_dest) - 1); - deltaUsed.y = max(delta.y, -(RECT_HEIGHT(rectSel_dest) - 1)); - rectSel_dest.left += deltaUsed.x; - rectSel_dest.bottom += deltaUsed.y; - break; - case ACTION_RESIZE_BOTTOM: /* resize at bottom edge */ - deltaUsed.x = delta.x; - deltaUsed.y = max(delta.y, -(RECT_HEIGHT(rectSel_dest) - 1)); - rectSel_dest.bottom += deltaUsed.y; - break; - case ACTION_RESIZE_BOTTOM_RIGHT: /* resize at lower right corner */ - deltaUsed.x = max(delta.x, -(RECT_WIDTH(rectSel_dest) - 1)); - deltaUsed.y = max(delta.y, -(RECT_HEIGHT(rectSel_dest) - 1)); - rectSel_dest.right += deltaUsed.x; - rectSel_dest.bottom += deltaUsed.y; - break; - } - delta.x -= deltaUsed.x; - delta.y -= deltaUsed.y; - - _stprintf(sizeStr, _T("%d x %d"), RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest)); + m_ptFrac.x -= (m_ptFrac.x * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000; + m_ptFrac.y -= (m_ptFrac.y * 1000 / toolsModel.GetZoom()) * toolsModel.GetZoom() / 1000; + } + selectionModel.ModifyDestRect(m_ptDelta, m_iAction); + + _stprintf(sizeStr, _T("%d x %d"), selectionModel.GetDestRectWidth(), selectionModel.GetDestRectHeight()); SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr); if (toolsModel.GetActiveTool() == TOOL_TEXT) { - Text(hDrawingDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, rectSel_dest.bottom, paletteModel.GetFgColor(), paletteModel.GetBgColor(), textToolText, hfontTextFont, toolsModel.IsBackgroundTransparent()); + selectionModel.DrawTextToolText(hDrawingDC, paletteModel.GetFgColor(), paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); } else { - if (action != ACTION_MOVE) - StretchBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); + if (m_iAction != ACTION_MOVE) + selectionModel.DrawSelectionStretched(hDrawingDC); else - if (toolsModel.IsBackgroundTransparent() == 0) - MaskBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), - hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); - else - { - ColorKeyedMaskBlt(hDrawingDC, rectSel_dest.left, rectSel_dest.top, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), - hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND), paletteModel.GetBgColor()); - } + selectionModel.DrawSelection(hDrawingDC, paletteModel.GetBgColor(), toolsModel.IsBackgroundTransparent()); } imageArea.InvalidateRect(NULL, FALSE); imageArea.SendMessage(WM_PAINT, 0, 0); - pos.x = GET_X_LPARAM(lParam); - pos.y = GET_Y_LPARAM(lParam); + m_ptPos.x = GET_X_LPARAM(lParam); + m_ptPos.y = GET_Y_LPARAM(lParam); } else { - int w = RECT_WIDTH(rectSel_dest) * toolsModel.GetZoom() / 1000 + 6; - int h = RECT_HEIGHT(rectSel_dest) * toolsModel.GetZoom() / 1000 + 6; - pos.x = GET_X_LPARAM(lParam); - pos.y = GET_Y_LPARAM(lParam); + int w = selectionModel.GetDestRectWidth() * toolsModel.GetZoom() / 1000 + 6; + int h = selectionModel.GetDestRectHeight() * toolsModel.GetZoom() / 1000 + 6; + m_ptPos.x = GET_X_LPARAM(lParam); + m_ptPos.y = GET_Y_LPARAM(lParam); SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL); - action = identifyCorner(pos.x, pos.y, w, h); - if (action != ACTION_MOVE) - SetCursor(LoadCursor(NULL, cursors[action])); + m_iAction = IdentifyCorner(m_ptPos.x, m_ptPos.y, w, h); + if (m_iAction != ACTION_MOVE) + SetCursor(LoadCursor(NULL, m_lpszCursorLUT[m_iAction])); } return 0; } LRESULT CSelectionWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (moving) - { - moving = FALSE; + if (m_bMoving) + { + m_bMoving = FALSE; ReleaseCapture(); - if (action != ACTION_MOVE) + if (m_iAction != ACTION_MOVE) { if (toolsModel.GetActiveTool() == TOOL_TEXT) { @@ -299,25 +220,7 @@ } else { - HDC hTempDC; - HBITMAP hTempBm; - hTempDC = CreateCompatibleDC(hSelDC); - hTempBm = CreateDIBWithProperties(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest)); - SelectObject(hTempDC, hTempBm); - SelectObject(hSelDC, hSelBm); - StretchBlt(hTempDC, 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, - GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY); - DeleteObject(hSelBm); - hSelBm = hTempBm; - hTempBm = CreateBitmap(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), 1, 1, NULL); - SelectObject(hTempDC, hTempBm); - SelectObject(hSelDC, hSelMask); - StretchBlt(hTempDC, 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, 0, 0, - GetDIBWidth(hSelMask), GetDIBHeight(hSelMask), SRCCOPY); - DeleteObject(hSelMask); - hSelMask = hTempBm; - SelectObject(hSelDC, hSelBm); - DeleteDC(hTempDC); + selectionModel.ScaleContentsToFit(); } } placeSelWin(); Modified: trunk/reactos/base/applications/mspaint_new/selection.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selection.h [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/selection.h [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -30,6 +30,17 @@ LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + +private: + static const LPCTSTR m_lpszCursorLUT[9]; + BOOL m_bMoving; + int m_iAction; + POINT m_ptPos; + POINT m_ptFrac; + POINT m_ptDelta; + DWORD m_dwSystemSelectionColor; + + int IdentifyCorner(int iXPos, int iYPos, int iWidth, int iHeight); }; void ForceRefreshSelectionContents(); Added: trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp (added) +++ trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -0,0 +1,328 @@ +/* + * PROJECT: PAINT for ReactOS + * LICENSE: LGPL + * FILE: base/applications/mspaint_new/selectionmodel.cpp + * PURPOSE: Keep track of selection parameters, notify listeners + * PROGRAMMERS: Benedikt Freisen + */ + +/* INCLUDES *********************************************************/ + +#include "precomp.h" + +/* FUNCTIONS ********************************************************/ + +SelectionModel::SelectionModel() +{ + m_ptStack = NULL; + m_iPtSP = 0; +} + +void SelectionModel::SetDC(HDC hDC) +{ + m_hDC = hDC; +} + +void SelectionModel::ResetPtStack() +{ + if (m_ptStack != NULL) + HeapFree(GetProcessHeap(), 0, m_ptStack); + m_ptStack = NULL; + m_iPtSP = 0; +} + +void SelectionModel::PushToPtStack(LONG x, LONG y) +{ + if (m_iPtSP % 1024 == 0) + { + if (m_ptStack) + m_ptStack = (POINT*) HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, m_ptStack, sizeof(POINT) * (m_iPtSP + 1024)); + else + m_ptStack = (POINT*) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * 1024); + } + m_ptStack[m_iPtSP].x = x; + m_ptStack[m_iPtSP].y = y; + m_iPtSP++; +} + +void SelectionModel::CalculateBoundingBoxAndContents(HDC hDCImage) +{ + int i; + m_rcSrc.left = m_rcSrc.top = MAXLONG; + m_rcSrc.right = m_rcSrc.bottom = 0; + for (i = 0; i < m_iPtSP; i++) + { + if (m_ptStack[i].x < m_rcSrc.left) + m_rcSrc.left = m_ptStack[i].x; + if (m_ptStack[i].y < m_rcSrc.top) + m_rcSrc.top = m_ptStack[i].y; + if (m_ptStack[i].x > m_rcSrc.right) + m_rcSrc.right = m_ptStack[i].x; + if (m_ptStack[i].y > m_rcSrc.bottom) + m_rcSrc.bottom = m_ptStack[i].y; + } + m_rcSrc.right += 1; + m_rcSrc.bottom += 1; + m_rcDest.left = m_rcSrc.left; + m_rcDest.top = m_rcSrc.top; + m_rcDest.right = m_rcSrc.right; + m_rcDest.bottom = m_rcSrc.bottom; + + if (m_iPtSP > 1) + { + DeleteObject(m_hMask); + m_hMask = CreateBitmap(RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), 1, 1, NULL); + DeleteObject(SelectObject(m_hDC, m_hMask)); + POINT *m_ptStackCopy = (POINT*) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * m_iPtSP); + for (i = 0; i < m_iPtSP; i++) + { + m_ptStackCopy[i].x = m_ptStack[i].x - m_rcSrc.left; + m_ptStackCopy[i].y = m_ptStack[i].y - m_rcSrc.top; + } + Poly(m_hDC, m_ptStackCopy, m_iPtSP, 0x00ffffff, 0x00ffffff, 1, 2, TRUE, FALSE); + HeapFree(GetProcessHeap(), 0, m_ptStackCopy); + SelectObject(m_hDC, m_hBm = CreateDIBWithProperties(RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc))); + imageModel.ResetToPrevious(); + MaskBlt(m_hDC, 0, 0, RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), hDCImage, m_rcSrc.left, + m_rcSrc.top, m_hMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS)); + } +} + +void SelectionModel::CalculateContents(HDC hDCImage) +{ + DeleteObject(m_hMask); + m_hMask = CreateBitmap(RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), 1, 1, NULL); + DeleteObject(SelectObject(m_hDC, m_hMask)); + Rect(m_hDC, 0, 0, RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), 0x00ffffff, 0x00ffffff, 1, 2); + SelectObject(m_hDC, m_hBm = CreateDIBWithProperties(RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc))); + BitBlt(m_hDC, 0, 0, RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), hDCImage, m_rcSrc.left, + m_rcSrc.top, SRCCOPY); +} + +void SelectionModel::DrawBackgroundPoly(HDC hDCImage, COLORREF crBg) +{ + Poly(hDCImage, m_ptStack, m_iPtSP, crBg, crBg, 1, 2, TRUE, FALSE); +} + +void SelectionModel::DrawBackgroundRect(HDC hDCImage, COLORREF crBg) +{ + Rect(hDCImage, m_rcSrc.left, m_rcSrc.top, m_rcSrc.right, m_rcSrc.bottom, crBg, crBg, 0, TRUE); +} + +extern BOOL +ColorKeyedMaskBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HDC hdcSrc, int nXSrc, int nYSrc, HBITMAP hbmMask, int xMask, int yMask, DWORD dwRop, COLORREF keyColor); + +void SelectionModel::DrawSelection(HDC hDCImage, COLORREF crBg, BOOL bBgTransparent) +{ + MaskBlt(hDCImage, m_rcSrc.left, m_rcSrc.top, RECT_WIDTH(m_rcSrc), RECT_HEIGHT(m_rcSrc), m_hDC, 0, + 0, m_hMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); + if (!bBgTransparent) + MaskBlt(hDCImage, m_rcDest.left, m_rcDest.top, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), + m_hDC, 0, 0, m_hMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND)); + else + ColorKeyedMaskBlt(hDCImage, m_rcDest.left, m_rcDest.top, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), + m_hDC, 0, 0, m_hMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND), crBg); +} + +void SelectionModel::DrawSelectionStretched(HDC hDCImage) +{ + StretchBlt(hDCImage, m_rcDest.left, m_rcDest.top, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, GetDIBWidth(m_hBm), GetDIBHeight(m_hBm), SRCCOPY); +} + +void SelectionModel::ScaleContentsToFit() +{ + HDC hTempDC; + HBITMAP hTempBm; + hTempDC = CreateCompatibleDC(m_hDC); + hTempBm = CreateDIBWithProperties(RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest)); + SelectObject(hTempDC, hTempBm); + SelectObject(m_hDC, m_hBm); + StretchBlt(hTempDC, 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, + GetDIBWidth(m_hBm), GetDIBHeight(m_hBm), SRCCOPY); + DeleteObject(m_hBm); + m_hBm = hTempBm; + hTempBm = CreateBitmap(RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), 1, 1, NULL); + SelectObject(hTempDC, hTempBm); + SelectObject(m_hDC, m_hMask); + StretchBlt(hTempDC, 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, 0, 0, + GetDIBWidth(m_hMask), GetDIBHeight(m_hMask), SRCCOPY); + DeleteObject(m_hMask); + m_hMask = hTempBm; + SelectObject(m_hDC, m_hBm); + DeleteDC(hTempDC); +} + +void SelectionModel::InsertFromHBITMAP(HBITMAP hBm) +{ + HDC hTempDC; + HBITMAP hTempMask; + + DeleteObject(SelectObject(m_hDC, m_hBm = (HBITMAP) CopyImage(hBm, + IMAGE_BITMAP, 0, 0, + LR_COPYRETURNORG))); + + SetRectEmpty(&m_rcSrc); + m_rcDest.left = m_rcDest.top = 0; + m_rcDest.right = m_rcDest.left + GetDIBWidth(m_hBm); + m_rcDest.bottom = m_rcDest.top + GetDIBHeight(m_hBm); + + hTempDC = CreateCompatibleDC(m_hDC); + hTempMask = CreateBitmap(RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), 1, 1, NULL); + SelectObject(hTempDC, hTempMask); + Rect(hTempDC, m_rcDest.left, m_rcDest.top, m_rcDest.right, m_rcDest.bottom, 0x00ffffff, 0x00ffffff, 1, 1); + DeleteObject(m_hMask); + m_hMask = hTempMask; + DeleteDC(hTempDC); +} + +void SelectionModel::FlipHorizontally() +{ + SelectObject(m_hDC, m_hMask); + StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, 0, -RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + SelectObject(m_hDC, m_hBm); + StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, 0, -RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); +} + +void SelectionModel::FlipVertically() +{ + SelectObject(m_hDC, m_hMask); + StretchBlt(m_hDC, 0, RECT_HEIGHT(m_rcDest) - 1, RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + SelectObject(m_hDC, m_hBm); + StretchBlt(m_hDC, 0, RECT_HEIGHT(m_rcDest) - 1, RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); +} + +void SelectionModel::RotateNTimes90Degrees(int iN) +{ + if (iN == 2) + { + SelectObject(m_hDC, m_hMask); + StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, RECT_HEIGHT(m_rcDest) - 1, -RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + SelectObject(m_hDC, m_hBm); + StretchBlt(m_hDC, RECT_WIDTH(m_rcDest) - 1, RECT_HEIGHT(m_rcDest) - 1, -RECT_WIDTH(m_rcDest), -RECT_HEIGHT(m_rcDest), m_hDC, + 0, 0, RECT_WIDTH(m_rcDest), RECT_HEIGHT(m_rcDest), SRCCOPY); + } +} + +HBITMAP SelectionModel::GetBitmap() +{ + return m_hBm; +} + +int SelectionModel::PtStackSize() +{ + return m_iPtSP; +} + +void SelectionModel::DrawFramePoly(HDC hDCImage) +{ + Poly(hDCImage, m_ptStack, m_iPtSP, 0, 0, 2, 0, FALSE, TRUE); /* draw the freehand selection inverted/xored */ +} + +void SelectionModel::SetSrcAndDestRectFromPoints(POINT& ptFrom, POINT& ptTo) +{ + m_rcDest.left = m_rcSrc.left = min(ptFrom.x, ptTo.x); + m_rcDest.top = m_rcSrc.top = min(ptFrom.y, ptTo.y); + m_rcDest.right = m_rcSrc.right = max(ptFrom.x, ptTo.x); + m_rcDest.bottom = m_rcSrc.bottom = max(ptFrom.y, ptTo.y); +} + +void SelectionModel::SetSrcRectSizeToZero() +{ + m_rcSrc.right = m_rcSrc.left; + m_rcSrc.bottom = m_rcSrc.top; +} + +BOOL SelectionModel::IsSrcRectSizeNonzero() +{ + return (RECT_WIDTH(m_rcSrc) != 0) && (RECT_HEIGHT(m_rcSrc) != 0); +} + +void SelectionModel::ModifyDestRect(POINT& ptDelta, int iAction) +{ + POINT ptDeltaUsed; + + switch (iAction) + { + case ACTION_MOVE: /* move selection */ + ptDeltaUsed.x = ptDelta.x; + ptDeltaUsed.y = ptDelta.y; + OffsetRect(&m_rcDest, ptDeltaUsed.x, ptDeltaUsed.y); + break; + case ACTION_RESIZE_TOP_LEFT: /* resize at upper left corner */ + ptDeltaUsed.x = min(ptDelta.x, RECT_WIDTH(m_rcDest) - 1); + ptDeltaUsed.y = min(ptDelta.y, RECT_HEIGHT(m_rcDest) - 1); + m_rcDest.left += ptDeltaUsed.x; + m_rcDest.top += ptDeltaUsed.y; + break; + case ACTION_RESIZE_TOP: /* resize at top edge */ + ptDeltaUsed.x = ptDelta.x; + ptDeltaUsed.y = min(ptDelta.y, RECT_HEIGHT(m_rcDest) - 1); + m_rcDest.top += ptDeltaUsed.y; + break; + case ACTION_RESIZE_TOP_RIGHT: /* resize at upper right corner */ + ptDeltaUsed.x = max(ptDelta.x, -(RECT_WIDTH(m_rcDest) - 1)); + ptDeltaUsed.y = min(ptDelta.y, RECT_HEIGHT(m_rcDest) - 1); + m_rcDest.top += ptDeltaUsed.y; + m_rcDest.right += ptDeltaUsed.x; + break; + case ACTION_RESIZE_LEFT: /* resize at left edge */ + ptDeltaUsed.x = min(ptDelta.x, RECT_WIDTH(m_rcDest) - 1); + ptDeltaUsed.y = ptDelta.y; + m_rcDest.left += ptDeltaUsed.x; + break; + case ACTION_RESIZE_RIGHT: /* resize at right edge */ + ptDeltaUsed.x = max(ptDelta.x, -(RECT_WIDTH(m_rcDest) - 1)); + ptDeltaUsed.y = ptDelta.y; + m_rcDest.right += ptDeltaUsed.x; + break; + case ACTION_RESIZE_BOTTOM_LEFT: /* resize at lower left corner */ + ptDeltaUsed.x = min(ptDelta.x, RECT_WIDTH(m_rcDest) - 1); + ptDeltaUsed.y = max(ptDelta.y, -(RECT_HEIGHT(m_rcDest) - 1)); + m_rcDest.left += ptDeltaUsed.x; + m_rcDest.bottom += ptDeltaUsed.y; + break; + case ACTION_RESIZE_BOTTOM: /* resize at bottom edge */ + ptDeltaUsed.x = ptDelta.x; + ptDeltaUsed.y = max(ptDelta.y, -(RECT_HEIGHT(m_rcDest) - 1)); + m_rcDest.bottom += ptDeltaUsed.y; + break; + case ACTION_RESIZE_BOTTOM_RIGHT: /* resize at lower right corner */ + ptDeltaUsed.x = max(ptDelta.x, -(RECT_WIDTH(m_rcDest) - 1)); + ptDeltaUsed.y = max(ptDelta.y, -(RECT_HEIGHT(m_rcDest) - 1)); + m_rcDest.right += ptDeltaUsed.x; + m_rcDest.bottom += ptDeltaUsed.y; + break; + } + ptDelta.x -= ptDeltaUsed.x; + ptDelta.y -= ptDeltaUsed.y; +} + +LONG SelectionModel::GetDestRectWidth() +{ + return m_rcDest.right - m_rcDest.left; +} + +LONG SelectionModel::GetDestRectHeight() +{ + return m_rcDest.bottom - m_rcDest.top; +} + +LONG SelectionModel::GetDestRectLeft() +{ + return m_rcDest.left; +} + +LONG SelectionModel::GetDestRectTop() +{ + return m_rcDest.top; +} + +void SelectionModel::DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent) +{ + Text(hDCImage, m_rcDest.left, m_rcDest.top, m_rcDest.right, m_rcDest.bottom, crFg, crBg, textToolText, hfontTextFont, bBgTransparent); +} Propchange: trunk/reactos/base/applications/mspaint_new/selectionmodel.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: trunk/reactos/base/applications/mspaint_new/selectionmodel.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/selectionmodel.h (added) +++ trunk/reactos/base/applications/mspaint_new/selectionmodel.h [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -0,0 +1,65 @@ +/* + * PROJECT: PAINT for ReactOS + * LICENSE: LGPL + * FILE: base/applications/mspaint_new/selectionmodel.h + * PURPOSE: Keep track of selection parameters, notify listeners + * PROGRAMMERS: Benedikt Freisen + */ + +/* DEFINES **********************************************************/ + +#define ACTION_MOVE 0 +#define ACTION_RESIZE_TOP_LEFT 1 +#define ACTION_RESIZE_TOP 2 +#define ACTION_RESIZE_TOP_RIGHT 3 +#define ACTION_RESIZE_LEFT 4 +#define ACTION_RESIZE_RIGHT 5 +#define ACTION_RESIZE_BOTTOM_LEFT 6 +#define ACTION_RESIZE_BOTTOM 7 +#define ACTION_RESIZE_BOTTOM_RIGHT 8 + +/* CLASSES **********************************************************/ + +class SelectionModel +{ +private: + HDC m_hDC; + RECT m_rcSrc; + RECT m_rcDest; + HBITMAP m_hBm; + HBITMAP m_hMask; + POINT *m_ptStack; + int m_iPtSP; + +// void NotifySelectionChanging(); +// void NotifySelectionChanged(); + +public: + SelectionModel(); + void SetDC(HDC hDC); + void ResetPtStack(); + void PushToPtStack(LONG x, LONG y); + void CalculateBoundingBoxAndContents(HDC hDCImage); + void CalculateContents(HDC hDCImage); + void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg); + void DrawBackgroundRect(HDC hDCImage, COLORREF crBg); + void DrawSelection(HDC hDCImage, COLORREF crBg = 0, BOOL bBgTransparent = FALSE); + void DrawSelectionStretched(HDC hDCImage); + void ScaleContentsToFit(); + void InsertFromHBITMAP(HBITMAP hBm); + void FlipHorizontally(); + void FlipVertically(); + void RotateNTimes90Degrees(int iN); + HBITMAP GetBitmap(); + int PtStackSize(); + void DrawFramePoly(HDC hDCImage); + void SetSrcAndDestRectFromPoints(POINT& ptFrom, POINT& ptTo); + void SetSrcRectSizeToZero(); + BOOL IsSrcRectSizeNonzero(); + void ModifyDestRect(POINT& ptDelta, int iAction); + LONG GetDestRectWidth(); + LONG GetDestRectHeight(); + LONG GetDestRectLeft(); + LONG GetDestRectTop(); + void DrawTextToolText(HDC hDCImage, COLORREF crFg, COLORREF crBg, BOOL bBgTransparent = FALSE); +}; Propchange: trunk/reactos/base/applications/mspaint_new/selectionmodel.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: trunk/reactos/base/applications/mspaint_new/winproc.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mspaint_…
============================================================================== --- trunk/reactos/base/applications/mspaint_new/winproc.cpp [iso-8859-1] (original) +++ trunk/reactos/base/applications/mspaint_new/winproc.cpp [iso-8859-1] Thu Jul 9 09:48:01 2015 @@ -107,29 +107,12 @@ void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window) { - HDC hTempDC; - HBITMAP hTempMask; - HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL); SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0)); toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL); - DeleteObject(SelectObject(hSelDC, hSelBm = (HBITMAP) CopyImage(bitmap, - IMAGE_BITMAP, 0, 0, - LR_COPYRETURNORG))); imageModel.CopyPrevious(); - SetRectEmpty(&rectSel_src); - rectSel_dest.left = rectSel_dest.top = 0; - rectSel_dest.right = rectSel_dest.left + GetDIBWidth(hSelBm); - rectSel_dest.bottom = rectSel_dest.top + GetDIBHeight(hSelBm); - - hTempDC = CreateCompatibleDC(hSelDC); - hTempMask = CreateBitmap(RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), 1, 1, NULL); - SelectObject(hTempDC, hTempMask); - Rect(hTempDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, rectSel_dest.bottom, 0x00ffffff, 0x00ffffff, 1, 1); - DeleteObject(hSelMask); - hSelMask = hTempMask; - DeleteDC(hTempDC); + selectionModel.InsertFromHBITMAP(bitmap); placeSelWin(); selectionWindow.ShowWindow(SW_SHOW); @@ -159,8 +142,6 @@ { SendMessage(WM_SETICON, ICON_BIG, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON))); SendMessage(WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON))); - ptStack = NULL; - ptSP = 0; return 0; } @@ -392,7 +373,7 @@ case IDM_EDITCOPY: OpenClipboard(); EmptyClipboard(); - SetClipboardData(CF_BITMAP, CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)); + SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)); CloseClipboard(); break; case IDM_EDITCUT: @@ -411,20 +392,8 @@ break; case IDM_EDITDELETESELECTION: { - /* remove selection window and already painted content using undo(), - paint Rect for rectangular selections and Poly for freeform selections */ + /* remove selection window and already painted content using undo */ imageModel.Undo(); - if (toolsModel.GetActiveTool() == TOOL_RECTSEL) - { - imageModel.CopyPrevious(); - Rect(hDrawingDC, rectSel_dest.left, rectSel_dest.top, rectSel_dest.right, - rectSel_dest.bottom, paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE); - } - if (toolsModel.GetActiveTool() == TOOL_FREESEL) - { - imageModel.CopyPrevious(); - Poly(hDrawingDC, ptStack, ptSP + 1, 0, 0, 2, 0, FALSE, TRUE); - } break; } case IDM_EDITSELECTALL: @@ -440,7 +409,7 @@ } case IDM_EDITCOPYTO: if (GetSaveFileName(&ofn) != 0) - SaveDIBToFile(hSelBm, ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM); + SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, hDrawingDC, NULL, NULL, fileHPPM, fileVPPM); break; case IDM_EDITPASTEFROM: if (GetOpenFileName(&ofn) != 0) @@ -480,12 +449,7 @@ case 1: /* flip horizontally */ if (selectionWindow.IsWindowVisible()) { - SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); - SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, 0, -RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + selectionModel.FlipHorizontally(); ForceRefreshSelectionContents(); } else @@ -499,12 +463,7 @@ case 2: /* flip vertically */ if (selectionWindow.IsWindowVisible()) { - SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); - SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, 0, RECT_HEIGHT(rectSel_dest) - 1, RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + selectionModel.FlipVertically(); ForceRefreshSelectionContents(); } else @@ -520,12 +479,7 @@ case 4: /* rotate 180 degrees */ if (selectionWindow.IsWindowVisible()) { - SelectObject(hSelDC, hSelMask); - StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); - SelectObject(hSelDC, hSelBm); - StretchBlt(hSelDC, RECT_WIDTH(rectSel_dest) - 1, RECT_HEIGHT(rectSel_dest) - 1, -RECT_WIDTH(rectSel_dest), -RECT_HEIGHT(rectSel_dest), hSelDC, - 0, 0, RECT_WIDTH(rectSel_dest), RECT_HEIGHT(rectSel_dest), SRCCOPY); + selectionModel.RotateNTimes90Degrees(2); ForceRefreshSelectionContents(); } else @@ -561,7 +515,7 @@ toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent()); break; case IDM_IMAGECROP: - imageModel.Insert((HBITMAP) CopyImage(hSelBm, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)); + imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)); break; case IDM_VIEWTOOLBOX:
9 years, 5 months
1
0
0
0
[gedmurphy] 68381: [ATL] - Add the IAtlMemMgr interface - Add a basic implementation of CWin32Heap which just implements the base IAtlMemMgr - Required for CAtlString / CAtlStringMgr (coming later)
by gedmurphy@svn.reactos.org
Author: gedmurphy Date: Thu Jul 9 08:18:24 2015 New Revision: 68381 URL:
http://svn.reactos.org/svn/reactos?rev=68381&view=rev
Log: [ATL] - Add the IAtlMemMgr interface - Add a basic implementation of CWin32Heap which just implements the base IAtlMemMgr - Required for CAtlString / CAtlStringMgr (coming later) Added: trunk/reactos/lib/atl/atlmem.h (with props) Added: trunk/reactos/lib/atl/atlmem.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/atl/atlmem.h?rev=68381
============================================================================== --- trunk/reactos/lib/atl/atlmem.h (added) +++ trunk/reactos/lib/atl/atlmem.h [iso-8859-1] Thu Jul 9 08:18:24 2015 @@ -0,0 +1,102 @@ +#ifndef __ATLMEM_H__ +#define __ATLMEM_H__ + +#pragma once +#include <atlcore.h> + +namespace ATL +{ + +__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr +{ +public: + _Ret_maybenull_ _Post_writable_byte_size_(SizeBytes) void* Allocate( + _In_ size_t SizeBytes + ); + + void Free( + _Inout_opt_ void* Buffer + ); + + _Ret_maybenull_ _Post_writable_byte_size_(SizeBytes) void* Reallocate( + _Inout_updates_bytes_opt_(SizeBytes) void* Buffer, + _In_ size_t SizeBytes + ); + + size_t GetSize( + _In_ void* Buffer + ); +}; + +class CWin32Heap : public IAtlMemMgr +{ +public: + HANDLE m_hHeap; + +public: + CWin32Heap() : + m_hHeap(NULL) + { + } + + CWin32Heap(_In_ HANDLE hHeap) : + m_hHeap(hHeap) + { + ATLASSERT(hHeap != NULL); + } + + virtual ~CWin32Heap() + { + } + + + // IAtlMemMgr + _Ret_maybenull_ _Post_writable_byte_size_(SizeBytes) virtual void* Allocate( + _In_ size_t SizeBytes + ) + { + return ::HeapAlloc(m_hHeap, 0, SizeBytes); + } + + virtual void Free( + _In_opt_ void* Buffer + ) + { + if (Buffer) + { + BOOL FreeOk; + FreeOk = ::HeapFree(m_hHeap, 0, Buffer); + ATLASSERT(FreeOk == TRUE); + } + } + + _Ret_maybenull_ _Post_writable_byte_size_(SizeBytes) virtual void* Reallocate( + _In_opt_ void* Buffer, + _In_ size_t SizeBytes + ) + { + if (SizeBytes == 0) + { + Free(Buffer); + return NULL; + } + + if (Buffer == NULL) + { + return Allocate(SizeBytes); + } + + return ::HeapReAlloc(m_hHeap, 0, Buffer, SizeBytes); + } + + virtual size_t GetSize( + _Inout_ void* Buffer + ) + { + return ::HeapSize(m_hHeap, 0, Buffer); + } +}; + +} + +#endif Propchange: trunk/reactos/lib/atl/atlmem.h ------------------------------------------------------------------------------ svn:eol-style = native
9 years, 5 months
1
0
0
0
[gedmurphy] 68380: [ATL] - Add basic support for CAtlList, CAtlPlex, CElementTraitsBase, CDefaultCompareTraits. - Implements CAtlList::IsEmpty, ::GetHeadPosition, ::GetNext, ::AddTail, ::RemoveTail...
by gedmurphy@svn.reactos.org
Author: gedmurphy Date: Thu Jul 9 07:51:43 2015 New Revision: 68380 URL:
http://svn.reactos.org/svn/reactos?rev=68380&view=rev
Log: [ATL] - Add basic support for CAtlList, CAtlPlex, CElementTraitsBase, CDefaultCompareTraits. - Implements CAtlList::IsEmpty, ::GetHeadPosition, ::GetNext, ::AddTail, ::RemoveTail, ::RemoveAll - Required in the new devmgr code. Added: trunk/reactos/lib/atl/atlcoll.h (with props) Added: trunk/reactos/lib/atl/atlcoll.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/atl/atlcoll.h?rev=68380
============================================================================== --- trunk/reactos/lib/atl/atlcoll.h (added) +++ trunk/reactos/lib/atl/atlcoll.h [iso-8859-1] Thu Jul 9 07:51:43 2015 @@ -0,0 +1,383 @@ +#ifndef __ATLCOLL_H__ +#define __ATLCOLL_H__ + +#pragma once +#include <atlbase.h> + + +struct __POSITION +{ +}; +typedef __POSITION* POSITION; + + +namespace ATL +{ + +class CAtlPlex +{ +public: + CAtlPlex* m_Next; + +#if (_AFX_PACKING >= 8) + DWORD dwReserved[1]; +#endif + + static inline CAtlPlex* Create( + _Inout_ CAtlPlex*& Entry, + _In_ size_t MaxElements, + _In_ size_t ElementSize + ) + { + CAtlPlex* Block; + + ATLASSERT(MaxElements > 0); + ATLASSERT(ElementSize > 0); + + size_t BufferSize = sizeof(CAtlPlex) + (MaxElements * ElementSize); + + void *Buffer = HeapAlloc(GetProcessHeap(), 0, BufferSize); + if (Buffer == NULL) return NULL; + + Block = static_cast< CAtlPlex* >(Buffer); + Block->m_Next = Entry; + Entry = Block; + + return Block; + } + + void* GetData() + { + return (this + 1); + } + + inline void Destroy() + { + CAtlPlex* Block; + + Block = this; + while (Block != NULL) + { + CAtlPlex* Next; + + Next = Block->m_Next; + HeapFree(GetProcessHeap(), 0, Block); + Block = Next; + } + } +}; + + +template<typename T> +class CElementTraitsBase +{ +public: + typedef const T& INARGTYPE; + typedef T& OUTARGTYPE; + + static void CopyElements( + _Out_writes_all_(NumElements) T* Dest, + _In_reads_(NumElements) const T* Source, + _In_ size_t NumElements) + { + for (size_t i = 0; i < NumElements; i++) + { + Dest[i] = Source[i]; + } + } + + static void RelocateElements( + _Out_writes_all_(NumElements) T* Dest, + _In_reads_(NumElements) T* Source, + _In_ size_t NumElements) + { + memmove_s(Dest, NumElements * sizeof(T), Source, NumElements * sizeof(T)); + } +}; + +template<typename T> +class CDefaultCompareTraits +{ +public: + static bool CompareElements( + _In_ const T& Val1, + _In_ const T& Val2) + { + return (Val1 == Val2); + } + + static int CompareElementsOrdered( + _In_ const T& Val1, + _In_ const T& Val2) + { + if (Val1 < Val2) + { + return -1; + } + else if (Val1 > Val2) + { + return 1; + } + + return 0; // equal + } +}; + +template<typename T> +class CDefaultElementTraits : + public CElementTraitsBase<T>, + public CDefaultCompareTraits<T> +{ +}; + + +template<typename T> +class CElementTraits : + public CDefaultElementTraits<T> +{ +}; + + +template<typename E, class ETraits = CElementTraits<E>> +class CAtlList +{ +private: + typedef typename ETraits::INARGTYPE INARGTYPE; + +private: + class CNode : public __POSITION + { + public: + CNode* m_Next; + CNode* m_Prev; + E m_Element; + + public: + CNode(INARGTYPE Element) : + m_Element(Element) + { + } + }; + +private: + CAtlPlex* m_Blocks; + UINT m_BlockSize; + CNode* m_HeadNode; + CNode* m_TailNode; + CNode* m_FreeNode; + size_t m_NumElements; + +public: + CAtlList(_In_ UINT nBlockSize = 10); + ~CAtlList(); + + bool IsEmpty() const; + + POSITION GetHeadPosition() const; + + E& GetNext( + _Inout_ POSITION &Position + ); + + POSITION AddTail( + INARGTYPE element + ); + + E RemoveTail(); + void RemoveAll(); + +private: + CNode* CreateNode( + INARGTYPE element, + _In_opt_ CNode* pPrev, + _In_opt_ CNode* pNext + ); + + void FreeNode( + _Inout_ CNode* pNode + ); + + CNode* GetFreeNode( + ); + +}; + + +// +// CAtlist public methods +// + +template<typename E, class ETraits> +CAtlList< E, ETraits >::CAtlList(_In_ UINT nBlockSize) : + m_NumElements(0), + m_HeadNode(NULL), + m_TailNode(NULL), + m_FreeNode(NULL), + m_Blocks(NULL), + + m_BlockSize(nBlockSize) +{ + ATLASSERT(nBlockSize > 0); +} + +template<typename E, class ETraits> +CAtlList<E, ETraits >::~CAtlList(void) +{ + RemoveAll(); +} + +template<typename E, class ETraits> +inline bool CAtlList< E, ETraits >::IsEmpty(void) const +{ + return (m_NumElements == 0); +} + +template<typename E, class ETraits> +inline POSITION CAtlList<E, ETraits>::GetHeadPosition(void) const +{ + return (POSITION)m_HeadNode; +} + +template<typename E, class ETraits> +inline E& CAtlList< E, ETraits >::GetNext( + _Inout_ POSITION& Position + ) +{ + CNode* Node = (CNode*)Position; + Position = (POSITION)Node->m_Next; + return Node->m_Element; +} + +template<typename E, class ETraits> +POSITION CAtlList<E, ETraits>::AddTail( + INARGTYPE element + ) +{ + CNode* Node = CreateNode(element, m_TailNode, NULL); + if (m_TailNode) + { + m_TailNode->m_Next = Node; + } + else + { + m_HeadNode = Node; + } + m_TailNode = Node; + + return (POSITION)Node; +} + +template<typename E, class ETraits> +E CAtlList<E, ETraits>::RemoveTail(void) +{ + CNode* Node = m_TailNode; + + E Element(Node->m_Element); + + m_TailNode = Node->m_Prev; + if (m_TailNode) + { + m_TailNode->m_Next = NULL; + } + else + { + m_HeadNode = NULL; + } + FreeNode(Node); + + return Element; +} + +template<typename E, class ETraits> +void CAtlList<E, ETraits >::RemoveAll(void) +{ + while (m_NumElements > 0) + { + CNode* Node = m_HeadNode; + m_HeadNode = m_HeadNode->m_Next; + FreeNode(Node); + } + + m_HeadNode = NULL; + m_TailNode = NULL; + m_FreeNode = NULL; + + if (m_Blocks) + { + m_Blocks->Destroy(); + m_Blocks = NULL; + } +} + + +// +// CAtlist private methods +// + +template<typename E, class ETraits> +typename CAtlList<E, ETraits>::CNode* CAtlList<E, ETraits>::CreateNode( + INARGTYPE element, + _In_opt_ CNode* Prev, + _In_opt_ CNode* Next + ) +{ + GetFreeNode(); + + CNode* NewNode = GetFreeNode(); + CNode* NextFree = m_FreeNode->m_Next; + + NewNode = new CNode(element); + + m_FreeNode = NextFree; + NewNode->m_Prev = Prev; + NewNode->m_Next = Next; + m_NumElements++; + + return NewNode; +} + +template<typename E, class ETraits> +void CAtlList<E, ETraits>::FreeNode( + _Inout_ CNode* pNode + ) +{ + pNode->~CNode(); + pNode->m_Next = m_FreeNode; + m_FreeNode = pNode; + + m_NumElements--; + if (m_NumElements == 0) + { + RemoveAll(); + } +} + +template<typename E, class ETraits> +typename CAtlList<E, ETraits>::CNode* CAtlList< E, ETraits>::GetFreeNode(void) +{ + if (m_FreeNode) + { + return m_FreeNode; + } + + CAtlPlex* Block = CAtlPlex::Create(m_Blocks, m_BlockSize, sizeof(CNode)); + if (Block == NULL) + { + throw(E_OUTOFMEMORY); + } + + CNode* Node = (CNode*)Block->GetData(); + Node += (m_BlockSize - 1); + for (int i = m_BlockSize - 1; i >= 0; i--) + { + Node->m_Next = m_FreeNode; + m_FreeNode = Node; + Node--; + } + + return m_FreeNode; +} + +} + +#endif Propchange: trunk/reactos/lib/atl/atlcoll.h ------------------------------------------------------------------------------ svn:eol-style = native
9 years, 5 months
1
0
0
0
[cfinck] 68379: [LOCALSPL] Bugfix: Copy the full DevMode including the extra data by the driver.
by cfinck@svn.reactos.org
Author: cfinck Date: Wed Jul 8 12:35:35 2015 New Revision: 68379 URL:
http://svn.reactos.org/svn/reactos?rev=68379&view=rev
Log: [LOCALSPL] Bugfix: Copy the full DevMode including the extra data by the driver. Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/tools.c Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] Wed Jul 8 12:35:35 2015 @@ -279,7 +279,7 @@ pJob->dwStatus = JOB_STATUS_SPOOLING; pJob->pwszDatatype = AllocSplStr(pPrinterHandle->pwszDatatype); pJob->pwszDocumentName = AllocSplStr(wszDefaultDocumentName); - CopyMemory(&pJob->DevMode, &pPrinterHandle->DevMode, sizeof(DEVMODEW)); + pJob->pDevMode = DuplicateDevMode(pPrinterHandle->pDevMode); GetSystemTime(&pJob->stSubmitted); // Get the user name for the Job. @@ -440,6 +440,7 @@ _LocalGetJobLevel2(PLOCAL_PRINTER_HANDLE pPrinterHandle, PLOCAL_JOB pJob, PBYTE* ppStart, PBYTE* ppEnd, DWORD cbBuf, PDWORD pcbNeeded) { DWORD cbDatatype = (wcslen(pJob->pwszDatatype) + 1) * sizeof(WCHAR); + DWORD cbDevMode = pJob->pDevMode->dmSize + pJob->pDevMode->dmDriverExtra; DWORD cbDocumentName = (wcslen(pJob->pwszDocumentName) + 1) * sizeof(WCHAR); DWORD cbDriverName = (wcslen(pJob->pPrinter->pwszPrinterDriver) + 1) * sizeof(WCHAR); DWORD cbMachineName = (wcslen(pJob->pwszMachineName) + 1) * sizeof(WCHAR); @@ -464,7 +465,7 @@ cbStatus = (wcslen(pJob->pwszStatus) + 1) * sizeof(WCHAR); // Check if the supplied buffer is large enough. - *pcbNeeded += sizeof(JOB_INFO_2W) + cbDatatype + sizeof(DEVMODEW) + cbDocumentName + cbDriverName + cbMachineName + cbNotifyName + cbPrinterName + cbPrintProcessor + cbPrintProcessorParameters + cbStatus + cbUserName; + *pcbNeeded += sizeof(JOB_INFO_2W) + cbDatatype + cbDevMode + cbDocumentName + cbDriverName + cbMachineName + cbNotifyName + cbPrinterName + cbPrintProcessor + cbPrintProcessorParameters + cbStatus + cbUserName; if (cbBuf < *pcbNeeded) { dwErrorCode = ERROR_INSUFFICIENT_BUFFER; @@ -476,9 +477,9 @@ JobInfo2.pDatatype = (PWSTR)*ppEnd; CopyMemory(*ppEnd, pJob->pwszDatatype, cbDatatype); - *ppEnd -= sizeof(DEVMODEW); + *ppEnd -= cbDevMode; JobInfo2.pDevMode = (PDEVMODEW)*ppEnd; - CopyMemory(*ppEnd, &pJob->DevMode, sizeof(DEVMODEW)); + CopyMemory(*ppEnd, pJob->pDevMode, cbDevMode); *ppEnd -= cbDocumentName; JobInfo2.pDocument = (PWSTR)*ppEnd; @@ -1136,6 +1137,7 @@ pJob->dwUntilTime = pShadowFile->dwUntilTime; pJob->pPrinter = pPrinter; pJob->pPrintProcessor = pPrintProcessor; + pJob->pDevMode = DuplicateDevMode((PDEVMODEW)((ULONG_PTR)pShadowFile + pShadowFile->offDevMode)); pJob->pwszDatatype = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offDatatype)); pJob->pwszDocumentName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offDocumentName)); pJob->pwszMachineName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offMachineName)); @@ -1145,9 +1147,7 @@ pJob->pwszPrintProcessorParameters = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offPrintProcessorParameters)); pJob->pwszUserName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offUserName)); - CopyMemory(&pJob->stSubmitted, &pShadowFile->stSubmitted, sizeof(SYSTEMTIME)); - CopyMemory(&pJob->DevMode, (PDEVMODEW)((ULONG_PTR)pShadowFile + pShadowFile->offDevMode), sizeof(DEVMODEW)); pReturnValue = pJob; @@ -1166,6 +1166,7 @@ { BOOL bReturnValue = FALSE; DWORD cbDatatype; + DWORD cbDevMode; DWORD cbDocumentName; DWORD cbFileSize; DWORD cbMachineName; @@ -1191,6 +1192,7 @@ // Compute the total size of the shadow file. cbDatatype = (wcslen(pJob->pwszDatatype) + 1) * sizeof(WCHAR); + cbDevMode = pJob->pDevMode->dmSize + pJob->pDevMode->dmDriverExtra; cbDocumentName = (wcslen(pJob->pwszDocumentName) + 1) * sizeof(WCHAR); cbMachineName = (wcslen(pJob->pwszMachineName) + 1) * sizeof(WCHAR); cbNotifyName = (wcslen(pJob->pwszNotifyName) + 1) * sizeof(WCHAR); @@ -1203,7 +1205,7 @@ if (pJob->pwszPrintProcessorParameters) cbPrintProcessorParameters = (wcslen(pJob->pwszPrintProcessorParameters) + 1) * sizeof(WCHAR); - cbFileSize = sizeof(SHD_HEADER) + cbDatatype + cbDocumentName + sizeof(DEVMODEW) + cbMachineName + cbNotifyName + cbPrinterDriver + cbPrinterName + cbPrintProcessor + cbPrintProcessorParameters + cbUserName; + cbFileSize = sizeof(SHD_HEADER) + cbDatatype + cbDocumentName + cbDevMode + cbMachineName + cbNotifyName + cbPrinterDriver + cbPrinterName + cbPrintProcessor + cbPrintProcessorParameters + cbUserName; // Allocate memory for it. pShadowFile = DllAllocSplMem(cbFileSize); @@ -1243,9 +1245,9 @@ pShadowFile->offDocumentName = dwCurrentOffset; dwCurrentOffset += cbDocumentName; - CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, &pJob->DevMode, sizeof(DEVMODEW)); + CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pDevMode, cbDevMode); pShadowFile->offDevMode = dwCurrentOffset; - dwCurrentOffset += sizeof(DEVMODEW); + dwCurrentOffset += cbDevMode; // offDriverName is only written, but automatically determined through offPrinterName when reading. CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pPrinter->pwszPrinterDriver, cbPrinterDriver); Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h [iso-8859-1] Wed Jul 8 12:35:35 2015 @@ -81,7 +81,7 @@ PWSTR pwszPrinterDriver; PWSTR pwszDescription; PWSTR pwszDefaultDatatype; - DEVMODEW DefaultDevMode; + PDEVMODEW pDefaultDevMode; PLOCAL_PRINT_PROCESSOR pPrintProcessor; SKIPLIST JobList; } @@ -113,7 +113,7 @@ DWORD dwUntilTime; // Latest time in minutes since 12:00 AM UTC when this document can be printed DWORD dwStatus; // JOB_STATUS_* flags of the Job PWSTR pwszMachineName; // Name of the machine that submitted the Job (prepended with two backslashes) - DEVMODEW DevMode; // Associated Device Mode to this Job + PDEVMODEW pDevMode; // Associated Device Mode to this Job } LOCAL_JOB, *PLOCAL_JOB; @@ -129,7 +129,7 @@ PLOCAL_PRINTER pPrinter; PLOCAL_JOB pStartedJob; PWSTR pwszDatatype; - DEVMODEW DevMode; + PDEVMODEW pDevMode; } LOCAL_PRINTER_HANDLE, *PLOCAL_PRINTER_HANDLE; @@ -249,5 +249,6 @@ // tools.c PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName); +PDEVMODEW DuplicateDevMode(PDEVMODEW pInput); #endif Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] Wed Jul 8 12:35:35 2015 @@ -81,6 +81,9 @@ if (pPrinter) { + if (pPrinter->pDefaultDevMode) + DllFreeSplMem(pPrinter->pDefaultDevMode); + if (pPrinter->pwszDefaultDatatype) DllFreeSplStr(pPrinter->pwszDefaultDatatype); @@ -173,12 +176,28 @@ continue; } + // Determine the size of the DevMode. + dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Default DevMode", NULL, NULL, NULL, &cbData); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("Couldn't query the size of the DevMode for Printer \"%S\", status is %lu, cbData is %lu!\n", wszPrinterName, dwErrorCode, cbData); + continue; + } + + // Allocate enough memory for the DevMode. + pPrinter->pDefaultDevMode = DllAllocSplMem(cbData); + if (!pPrinter->pDefaultDevMode) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + // Get the default DevMode. - cbData = sizeof(DEVMODEW); - dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Default DevMode", NULL, NULL, (PBYTE)&pPrinter->DefaultDevMode, &cbData); - if (dwErrorCode != ERROR_SUCCESS || cbData != sizeof(DEVMODEW)) - { - ERR("Couldn't query a valid DevMode for Printer \"%S\", status is %lu, cbData is %lu!\n", wszPrinterName, dwErrorCode, cbData); + dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Default DevMode", NULL, NULL, (PBYTE)pPrinter->pDefaultDevMode, &cbData); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("Couldn't query a DevMode for Printer \"%S\", status is %lu, cbData is %lu!\n", wszPrinterName, dwErrorCode, cbData); continue; } @@ -220,6 +239,9 @@ if (pPrinter) { + if (pPrinter->pDefaultDevMode) + DllFreeSplMem(pPrinter->pDefaultDevMode); + if (pPrinter->pwszDefaultDatatype) DllFreeSplStr(pPrinter->pwszDefaultDatatype); @@ -567,9 +589,9 @@ // Check if a DevMode was given, otherwise use the default. if (pDefault && pDefault->pDevMode) - CopyMemory(&pPrinterHandle->DevMode, pDefault->pDevMode, sizeof(DEVMODEW)); + pPrinterHandle->pDevMode = DuplicateDevMode(pDefault->pDevMode); else - CopyMemory(&pPrinterHandle->DevMode, &pPrinter->DefaultDevMode, sizeof(DEVMODEW)); + pPrinterHandle->pDevMode = DuplicateDevMode(pPrinter->pDefaultDevMode); // Did we have a comma? Then the user may want a handle to an existing job instead of creating a new job. if (p) @@ -753,7 +775,7 @@ } // Copy over printer defaults. - CopyMemory(&pJob->DevMode, &pPrinterHandle->DevMode, sizeof(DEVMODEW)); + pJob->pDevMode = DuplicateDevMode(pPrinterHandle->pDevMode); // Copy over supplied information. if (pDocumentInfo1->pDocName) Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/tools.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/tools.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/tools.c [iso-8859-1] Wed Jul 8 12:35:35 2015 @@ -56,3 +56,22 @@ return pwszValue; } + +PDEVMODEW +DuplicateDevMode(PDEVMODEW pInput) +{ + PDEVMODEW pOutput; + + // Allocate a buffer for this DevMode. + pOutput = DllAllocSplMem(pInput->dmSize + pInput->dmDriverExtra); + if (!pOutput) + { + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + return NULL; + } + + // Copy it. + CopyMemory(pOutput, pInput, pInput->dmSize + pInput->dmDriverExtra); + + return pOutput; +}
9 years, 5 months
1
0
0
0
[gedmurphy] 68378: [DEV[DEVMGR] - Use the correct HINSTANCE in the dll. Fixes loading strings for tooltips, etc. - Rename CMainWindow to CDeviceManager - Fixup the decelerations and add missing SAL...
by gedmurphy@svn.reactos.org
Author: gedmurphy Date: Wed Jul 8 06:43:16 2015 New Revision: 68378 URL:
http://svn.reactos.org/svn/reactos?rev=68378&view=rev
Log: [DEV[DEVMGR] - Use the correct HINSTANCE in the dll. Fixes loading strings for tooltips, etc. - Rename CMainWindow to CDeviceManager - Fixup the decelerations and add missing SAL decoration Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.h trunk/reactos/dll/win32/devmgr_new/devmgmt/RootNode.cpp trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp [iso-8859-1] Wed Jul 8 06:43:16 2015 @@ -78,7 +78,7 @@ 0, 0, 0, 0, m_hMainWnd, (HMENU)IDC_TREEVIEW, - g_hInstance, + g_hThisInstance, NULL); if (m_hTreeView) { @@ -719,7 +719,7 @@ if (Enable == false) { CAtlStringW str; - if (str.LoadStringW(g_hInstance, IDS_CONFIRM_DISABLE)) + if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE)) { if (MessageBoxW(m_hMainWnd, str, @@ -840,7 +840,7 @@ if (DeviceNode->CanUpdate()) { - String.LoadStringW(g_hInstance, IDS_MENU_UPDATE); + String.LoadStringW(g_hThisInstance, IDS_MENU_UPDATE); MenuItemInfo.wID = IDC_UPDATE_DRV; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -849,7 +849,7 @@ if (DeviceNode->IsDisabled()) { - String.LoadStringW(g_hInstance, IDS_MENU_ENABLE); + String.LoadStringW(g_hThisInstance, IDS_MENU_ENABLE); MenuItemInfo.wID = IDC_ENABLE_DRV; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -858,7 +858,7 @@ if (DeviceNode->CanDisable() && !DeviceNode->IsDisabled()) { - String.LoadStringW(g_hInstance, IDS_MENU_DISABLE); + String.LoadStringW(g_hThisInstance, IDS_MENU_DISABLE); MenuItemInfo.wID = IDC_DISABLE_DRV; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -867,7 +867,7 @@ if (DeviceNode->CanUninstall()) { - String.LoadStringW(g_hInstance, IDS_MENU_UNINSTALL); + String.LoadStringW(g_hThisInstance, IDS_MENU_UNINSTALL); MenuItemInfo.wID = IDC_UNINSTALL_DRV; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -879,7 +879,7 @@ } // All nodes have the scan option - String.LoadStringW(g_hInstance, IDS_MENU_SCAN); + String.LoadStringW(g_hThisInstance, IDS_MENU_SCAN); MenuItemInfo.wID = IDC_SCAN_HARDWARE; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -887,7 +887,7 @@ if ((Node->GetNodeType() == RootNode) || (MainMenu == true)) { - String.LoadStringW(g_hInstance, IDS_MENU_ADD); + String.LoadStringW(g_hThisInstance, IDS_MENU_ADD); MenuItemInfo.wID = IDC_ADD_HARDWARE; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); @@ -899,7 +899,7 @@ InsertMenuItemW(OwnerMenu, i, TRUE, &MenuSeperator); i++; - String.LoadStringW(g_hInstance, IDS_MENU_PROPERTIES); + String.LoadStringW(g_hThisInstance, IDS_MENU_PROPERTIES); MenuItemInfo.wID = IDC_PROPERTIES; MenuItemInfo.dwTypeData = String.GetBuffer(); InsertMenuItemW(OwnerMenu, i, TRUE, &MenuItemInfo); Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp [iso-8859-1] Wed Jul 8 06:43:16 2015 @@ -21,6 +21,8 @@ #define BTN_UPDATE_DRV 4 #define BTN_UNINSTALL_DRV 5 +HINSTANCE g_hThisInstance = NULL; +HINSTANCE g_hParentInstance = NULL; // menu hints static const MENU_HINT MainMenuHintTable[] = @@ -75,8 +77,7 @@ /* PUBLIC METHODS **********************************************/ -CMainWindow::CMainWindow(void) : - m_ToolbarhImageList(NULL), +CDeviceManager::CDeviceManager(void) : m_hMainWnd(NULL), m_hStatusBar(NULL), m_hToolBar(NULL), @@ -85,15 +86,55 @@ m_szMainWndClass = L"DevMgmtWndClass"; } -CMainWindow::~CMainWindow(void) -{ - // Destroy any previous list - if (m_ToolbarhImageList) ImageList_Destroy(m_ToolbarhImageList); -} +CDeviceManager::~CDeviceManager(void) +{ +} + bool -CMainWindow::Initialize(LPCTSTR lpCaption, - int nCmdShow) +CDeviceManager::Create(_In_ HWND /*hWndParent*/, + _In_ HINSTANCE hInst, + _In_opt_z_ LPCWSTR /*lpMachineName*/, + _In_ int nCmdShow) +{ + CDeviceManager MainWindow; + INITCOMMONCONTROLSEX icex; + CAtlStringW szAppName; + int Ret = 1; + + // Store the instances + g_hParentInstance = hInst; + g_hThisInstance = GetModuleHandleW(L"devmgr.dll"); + + // Initialize common controls + icex.dwSize = sizeof(INITCOMMONCONTROLSEX); + icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; + InitCommonControlsEx(&icex); + + // Load the application name + if (szAppName.LoadStringW(g_hThisInstance, IDS_APPNAME)) + { + // Initialize the main window + if (MainWindow.Initialize(szAppName, nCmdShow)) + { + // Run the application + Ret = MainWindow.Run(); + + // Uninitialize the main window + MainWindow.Uninitialize(); + } + } + + return (Ret == 0); +} + + + +/* PRIVATE METHODS **********************************************/ + +bool +CDeviceManager::Initialize(_In_z_ LPCTSTR lpCaption, + _In_ int nCmdShow) { CAtlStringW szCaption; WNDCLASSEXW wc = {0}; @@ -104,13 +145,13 @@ // Setup the window class struct wc.cbSize = sizeof(WNDCLASSEXW); wc.lpfnWndProc = MainWndProc; - wc.hInstance = g_hInstance; - wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCEW(IDI_MAIN_ICON)); + wc.hInstance = g_hThisInstance; + wc.hIcon = LoadIcon(g_hThisInstance, MAKEINTRESOURCEW(IDI_MAIN_ICON)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wc.lpszMenuName = MAKEINTRESOURCEW(IDR_MAINMENU); wc.lpszClassName = m_szMainWndClass; - wc.hIconSm = (HICON)LoadImage(g_hInstance, + wc.hIconSm = (HICON)LoadImage(g_hThisInstance, MAKEINTRESOURCE(IDI_MAIN_ICON), IMAGE_ICON, 16, @@ -131,7 +172,7 @@ 500, NULL, NULL, - g_hInstance, + g_hThisInstance, this); } @@ -140,14 +181,14 @@ } void -CMainWindow::Uninitialize() +CDeviceManager::Uninitialize(void) { // Unregister the window class - UnregisterClassW(m_szMainWndClass, g_hInstance); + UnregisterClassW(m_szMainWndClass, g_hThisInstance); } int -CMainWindow::Run() +CDeviceManager::Run(void) { MSG Msg; @@ -161,14 +202,11 @@ return 0; } - -/* PRIVATE METHODS **********************************************/ - bool -CMainWindow::MainWndMenuHint(WORD CmdId, - const MENU_HINT *HintArray, - DWORD HintsCount, - UINT DefHintId) +CDeviceManager::MainWndMenuHint(_In_ WORD CmdId, + _In_ const MENU_HINT *HintArray, + _In_ DWORD HintsCount, + _In_ UINT DefHintId) { bool Found = false; const MENU_HINT *LastHint; @@ -188,16 +226,14 @@ StatusBarLoadString(m_hStatusBar, SB_SIMPLEID, - g_hInstance, + g_hThisInstance, HintId); return Found; } void -CMainWindow::UpdateStatusBar( - _In_ bool InMenuLoop - ) +CDeviceManager::UpdateStatusBar(_In_ bool InMenuLoop) { SendMessageW(m_hStatusBar, SB_SIMPLE, @@ -206,7 +242,7 @@ } bool -CMainWindow::RefreshView(ViewType Type) +CDeviceManager::RefreshView(_In_ ViewType Type) { UINT CheckId = 0; BOOL bSuccess; @@ -235,7 +271,7 @@ } bool -CMainWindow::CreateToolBar() +CDeviceManager::CreateToolBar(void) { TBADDBITMAP TbAddBitmap; INT Index; @@ -251,7 +287,7 @@ 0, 0, 0, 0, m_hMainWnd, (HMENU)IDC_TOOLBAR, - g_hInstance, + g_hThisInstance, NULL); if (m_hToolBar == NULL) return FALSE; @@ -269,7 +305,7 @@ sizeof(TBBUTTON), 0); - TbAddBitmap.hInst = g_hInstance; + TbAddBitmap.hInst = g_hThisInstance; TbAddBitmap.nID = IDB_TOOLBAR; Index = SendMessageW(m_hToolBar, TB_ADDBITMAP, _countof(TbButtons), (LPARAM)&TbAddBitmap); @@ -285,7 +321,7 @@ } bool -CMainWindow::CreateStatusBar() +CDeviceManager::CreateStatusBar(void) { int StatWidths[] = {110, -1}; // widths of status bar bool bRet = FALSE; @@ -298,7 +334,7 @@ 0, 0, 0, 0, m_hMainWnd, (HMENU)IDC_STATUSBAR, - g_hInstance, + g_hThisInstance, NULL); if (m_hStatusBar) { @@ -312,7 +348,7 @@ return bRet; } -void CMainWindow::UpdateToolbar() +void CDeviceManager::UpdateToolbar() { WORD State; @@ -367,10 +403,10 @@ bool -CMainWindow::StatusBarLoadString(IN HWND hStatusBar, - IN INT PartId, - IN HINSTANCE hInstance, - IN UINT uID) +CDeviceManager::StatusBarLoadString(_In_ HWND hStatusBar, + _In_ INT PartId, + _In_ HINSTANCE hInstance, + _In_ UINT uID) { CAtlStringW szMessage; bool bRet = false; @@ -389,7 +425,7 @@ } LRESULT -CMainWindow::OnCreate(HWND hwnd) +CDeviceManager::OnCreate(_In_ HWND hwnd) { LRESULT RetCode; @@ -422,7 +458,7 @@ } LRESULT -CMainWindow::OnSize() +CDeviceManager::OnSize(void) { RECT rcClient, rcTool, rcStatus; INT lvHeight, iToolHeight, iStatusHeight; @@ -457,7 +493,7 @@ } LRESULT -CMainWindow::OnNotify(LPARAM lParam) +CDeviceManager::OnNotify(_In_ LPARAM lParam) { LPNMHDR NmHdr = (LPNMHDR)lParam; LRESULT Ret; @@ -491,6 +527,7 @@ case TTN_GETDISPINFO: { LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)lParam; + lpttt->hinst = g_hThisInstance; UINT_PTR idButton = lpttt->hdr.idFrom; switch (idButton) @@ -502,18 +539,19 @@ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_SCAN); break; case IDC_ENABLE_DRV: - lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_ENABLE); + lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_ENABLE); break; case IDC_DISABLE_DRV: - lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_DISABLE); + lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_DISABLE); break; case IDC_UPDATE_DRV: - lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UPDATE); + lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UPDATE); break; case IDC_UNINSTALL_DRV: - lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_UNINSTALL); + lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UNINSTALL); break; } + idButton = idButton; break; } } @@ -522,14 +560,14 @@ } LRESULT -CMainWindow::OnContext(LPARAM lParam) +CDeviceManager::OnContext(_In_ LPARAM lParam) { return m_DeviceView->OnContextMenu(lParam); } LRESULT -CMainWindow::OnCommand(WPARAM wParam, - LPARAM /*lParam*/) +CDeviceManager::OnCommand(_In_ WPARAM wParam, + _In_ LPARAM /*lParam*/) { LRESULT RetCode = 0; WORD Msg; @@ -641,7 +679,7 @@ } LRESULT -CMainWindow::OnDestroy() +CDeviceManager::OnDestroy(void) { // Uninitialize the device view m_DeviceView->Uninitialize(); @@ -660,16 +698,16 @@ } LRESULT CALLBACK -CMainWindow::MainWndProc(HWND hwnd, - UINT msg, - WPARAM wParam, - LPARAM lParam) -{ - CMainWindow *This; +CDeviceManager::MainWndProc(_In_ HWND hwnd, + _In_ UINT msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam) +{ + CDeviceManager *This; LRESULT RetCode = 0; // Get the object pointer from window context - This = (CMainWindow *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + This = (CDeviceManager *)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (This == NULL) { // Check that this isn't a create message @@ -685,7 +723,7 @@ case WM_CREATE: { // Get the object pointer from the create param - This = (CMainWindow *)((LPCREATESTRUCT)lParam)->lpCreateParams; + This = (CDeviceManager *)((LPCREATESTRUCT)lParam)->lpCreateParams; // Store the pointer in the window's global user data SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)This); @@ -783,49 +821,15 @@ } -//////// MOVE ME //////////////// - -HINSTANCE g_hInstance = NULL; -HANDLE ProcessHeap = NULL; - - +#if 1 // test BOOL WINAPI -DeviceManager_ExecuteW(HWND /*hWndParent*/, +DeviceManager_ExecuteW(HWND hWndParent, HINSTANCE hInst, - LPCWSTR /*lpMachineName*/, + LPCWSTR lpMachineName, int nCmdShow) { - CMainWindow MainWindow; - INITCOMMONCONTROLSEX icex; - CAtlStringW szAppName; - int Ret = 1; - - // Store the global values - g_hInstance = hInst; - ProcessHeap = GetProcessHeap(); - - // Initialize common controls - icex.dwSize = sizeof(INITCOMMONCONTROLSEX); - icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; - InitCommonControlsEx(&icex); - - //__debugbreak(); - g_hInstance = GetModuleHandle(L"devmgr.dll"); - - // Load the application name - if (szAppName.LoadStringW(g_hInstance, IDS_APPNAME)) - { - // Initialize the main window - if (MainWindow.Initialize(szAppName, nCmdShow)) - { - // Run the application - Ret = MainWindow.Run(); - - // Uninitialize the main window - MainWindow.Uninitialize(); - } - } - - return Ret; -} + CDeviceManager DevMgr; + return DevMgr.Create(hWndParent, hInst, lpMachineName, nCmdShow); +} +#endif Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.h [iso-8859-1] Wed Jul 8 06:43:16 2015 @@ -7,25 +7,27 @@ UINT HintId; } MENU_HINT, *PMENU_HINT; -class CMainWindow +class CDeviceManager { CAtlStringW m_szMainWndClass; CDeviceView *m_DeviceView; HWND m_hMainWnd; HWND m_hStatusBar; HWND m_hToolBar; - HIMAGELIST m_ToolbarhImageList; HMENU m_hMenu; HMENU m_hActionMenu; int m_CmdShow; public: - CMainWindow(void); - ~CMainWindow(void); + CDeviceManager(void); + ~CDeviceManager(void); - bool Initialize(LPCTSTR lpCaption, int nCmdShow); - int Run(); - void Uninitialize(); + bool Create( + _In_ HWND hWndParent, + _In_ HINSTANCE hInst, + _In_opt_z_ LPCWSTR lpMachineName, + _In_ int nCmdShow + ); private: static LRESULT CALLBACK MainWndProc( @@ -35,24 +37,44 @@ LPARAM lParam ); - LRESULT OnCreate(HWND hwnd); - LRESULT OnDestroy(); - LRESULT OnSize(); - LRESULT OnNotify(LPARAM lParam); - LRESULT OnContext(LPARAM lParam); - LRESULT OnCommand(WPARAM wParam, LPARAM lParam); - - bool CreateToolBar(); - bool CreateStatusBar(); - - void UpdateToolbar( + bool Initialize( + _In_z_ LPCTSTR lpCaption, + _In_ int nCmdShow ); + int Run(); + void Uninitialize(void); + + LRESULT OnCreate( + _In_ HWND hwnd + ); + + LRESULT OnDestroy(void); + LRESULT OnSize(void); + + LRESULT OnNotify( + _In_ LPARAM lParam + ); + + LRESULT OnContext( + _In_ LPARAM lParam + ); + + LRESULT OnCommand( + _In_ WPARAM wParam, + LPARAM lParam + ); + + bool CreateToolBar(void); + bool CreateStatusBar(void); + + void UpdateToolbar(void); + bool StatusBarLoadString( - HWND hStatusBar, - INT PartId, - HINSTANCE hInstance, - UINT uID + _In_ HWND hStatusBar, + _In_ INT PartId, + _In_ HINSTANCE hInstance, + _In_ UINT uID ); void UpdateStatusBar( @@ -60,14 +82,14 @@ ); bool MainWndMenuHint( - WORD CmdId, - const MENU_HINT *HintArray, - DWORD HintsCount, - UINT DefHintId + _In_ WORD CmdId, + _In_ const MENU_HINT *HintArray, + _In_ DWORD HintsCount, + _In_ UINT DefHintId ); bool RefreshView( - ViewType Type + _In_ ViewType Type ); }; Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/RootNode.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/RootNode.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/RootNode.cpp [iso-8859-1] Wed Jul 8 06:43:16 2015 @@ -29,8 +29,8 @@ // Load the bitmap we'll be using as the root image HBITMAP hRootImage; - hRootImage = LoadBitmapW(g_hInstance, - MAKEINTRESOURCEW(IDB_ROOT_IMAGE)); + hRootImage = LoadBitmapW(g_hThisInstance, + MAKEINTRESOURCEW(IDB_ROOT_IMAGE)); if (hRootImage == NULL) return FALSE; // Add this bitmap to the device image list. This is a bit hacky, but it's safe Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h [iso-8859-1] Wed Jul 8 06:43:16 2015 @@ -4,6 +4,6 @@ #pragma once #include "..\resource.h" -extern HINSTANCE g_hInstance; -extern HANDLE ProcessHeap; +extern HINSTANCE g_hThisInstance; +extern HINSTANCE g_hParentInstance;
9 years, 5 months
1
0
0
0
[hbelusca] 68377: [NTVDM] - Add few remaining members to the SYSVARS list. - Implement retrieving the (DOS) boot drive (by using the host boot drive letter from %SYSTEMDRIVE%). Should fix Win3.11 a...
by hbelusca@svn.reactos.org
Author: hbelusca Date: Tue Jul 7 23:51:57 2015 New Revision: 68377 URL:
http://svn.reactos.org/svn/reactos?rev=68377&view=rev
Log: [NTVDM] - Add few remaining members to the SYSVARS list. - Implement retrieving the (DOS) boot drive (by using the host boot drive letter from %SYSTEMDRIVE%). Should fix Win3.11 and MSD 2.0+ boot drive retrieval. Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
============================================================================== --- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] (original) +++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.c [iso-8859-1] Tue Jul 7 23:51:57 2015 @@ -333,7 +333,7 @@ break; } - /* Write string to STDOUT */ + /* Write String to STDOUT */ case 0x09: { String = (PCHAR)SEG_OFF_TO_PTR(getDS(), getDX()); @@ -756,8 +756,17 @@ /* Extended functionalities */ case 0x33: { - if (getAL() == 0x06) - { + switch (getAL()) + { + /* + * DOS 4+ - GET BOOT DRIVE + */ + case 0x05: + { + setDL(SysVars->BootDrive); + break; + } + /* * DOS 5+ - GET TRUE VERSION NUMBER * This function always returns the true version number, unlike @@ -765,24 +774,29 @@ * See Ralf Brown:
http://www.ctyme.com/intr/rb-2730.htm
* for more information. */ - - /* - * Return the true DOS version: Minor:Major in BH:BL - * The Windows NT DOS box returns BX=3205h (version 5.50). - */ - setBX(NTDOS_VERSION); - - /* DOS revision 0 */ - setDL(0x00); - - /* Unpatched DOS */ - setDH(0x00); - } - // else - // { - // /* Invalid subfunction */ - // setAL(0xFF); - // } + case 0x06: + { + /* + * Return the true DOS version: Minor:Major in BH:BL + * The Windows NT DOS box returns BX=3205h (version 5.50). + */ + setBX(NTDOS_VERSION); + + /* DOS revision 0 */ + setDL(0x00); + + /* Unpatched DOS */ + setDH(0x00); + + break; + } + + default: + { + DPRINT1("INT 21h, AH = 33h, subfunction AL = %Xh NOT IMPLEMENTED\n", + getAL()); + } + } break; } @@ -841,7 +855,7 @@ /* SWITCH character - AVAILDEV */ case 0x37: { - if (getAL() == 0x00) + switch (getAL()) { /* * DOS 2+ - "SWITCHAR" - GET SWITCH CHARACTER @@ -850,44 +864,46 @@ * See Ralf Brown:
http://www.ctyme.com/intr/rb-2752.htm
* for more information. */ - setDL('/'); - setAL(0x00); - } - else if (getAL() == 0x01) - { + case 0x00: + setDL('/'); + setAL(0x00); + break; + /* * DOS 2+ - "SWITCHAR" - SET SWITCH CHARACTER * This setting is ignored by MS-DOS 5+. * See Ralf Brown:
http://www.ctyme.com/intr/rb-2753.htm
* for more information. */ - // getDL(); - setAL(0xFF); - } - else if (getAL() == 0x02) - { + case 0x01: + // getDL(); + setAL(0xFF); + break; + /* * DOS 2.x and 3.3+ only - "AVAILDEV" - SPECIFY \DEV\ PREFIX USE * See Ralf Brown:
http://www.ctyme.com/intr/rb-2754.htm
* for more information. */ - // setDL(); - setAL(0xFF); - } - else if (getAL() == 0x03) - { + case 0x02: + // setDL(); + setAL(0xFF); + break; + /* * DOS 2.x and 3.3+ only - "AVAILDEV" - SPECIFY \DEV\ PREFIX USE * See Ralf Brown:
http://www.ctyme.com/intr/rb-2754.htm
* for more information. */ - // getDL(); - setAL(0xFF); - } - else - { + case 0x03: + // getDL(); + setAL(0xFF); + break; + /* Invalid subfunction */ - setAL(0xFF); + default: + setAL(0xFF); + break; } break; @@ -1379,7 +1395,7 @@ break; } - /* Terminate With Return Code */ + /* Terminate with Return Code */ case 0x4C: { DosTerminateProcess(Sda->CurrentPsp, getAL(), 0); @@ -2090,6 +2106,10 @@ /* The last drive can be redefined with the LASTDRIVE command. At the moment, set the real maximum possible, 'Z'. */ SysVars->NumLocalDrives = 'Z' - 'A' + 1; + /* The boot drive is initialized to the %SYSTEMDRIVE% value */ + // NOTE: Using the NtSystemRoot system variable might be OS-specific... + SysVars->BootDrive = SharedUserData->NtSystemRoot[0] - 'A' + 1; + /* Initialize the NUL device driver */ SysVars->NullDevice.Link = 0xFFFFFFFF; SysVars->NullDevice.DeviceAttributes = DOS_DEVATTR_NUL | DOS_DEVATTR_CHARACTER; Modified: trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/dos/…
============================================================================== --- trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] (original) +++ trunk/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dos.h [iso-8859-1] Tue Jul 7 23:51:57 2015 @@ -91,6 +91,10 @@ BYTE NumLocalDrives; // Set by LASTDRIVE DOS_DRIVER NullDevice; BYTE NullDriverRoutine[7]; + BYTE Reserved2[8]; + BYTE BootDrive; + BYTE UseDwordMoves; + WORD ExtMemSize; } DOS_SYSVARS, *PDOS_SYSVARS; typedef struct _DOS_CLOCK_TRANSFER_RECORD
9 years, 5 months
1
0
0
0
[gedmurphy] 68376: Minor code cleanup
by gedmurphy@svn.reactos.org
Author: gedmurphy Date: Tue Jul 7 20:33:54 2015 New Revision: 68376 URL:
http://svn.reactos.org/svn/reactos?rev=68376&view=rev
Log: Minor code cleanup Removed: trunk/reactos/dll/win32/devmgr_new/devmgmt/Resource.h trunk/reactos/dll/win32/devmgr_new/devmgmt/lang/ trunk/reactos/dll/win32/devmgr_new/devmgmt/res/ trunk/reactos/dll/win32/devmgr_new/devmgmt/rsrc.rc Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h trunk/reactos/dll/win32/devmgr_new/devmgr.rc trunk/reactos/dll/win32/devmgr_new/lang/en-US.rc Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/DeviceView.cpp [iso-8859-1] Tue Jul 7 20:33:54 2015 @@ -204,7 +204,7 @@ m_ViewType = Type; RefreshThreadData *ThreadData; - ThreadData = new RefreshThreadData(); + ThreadData = new RefreshThreadData; ThreadData->This = this; ThreadData->ScanForChanges = ScanForChanges; ThreadData->UpdateView = UpdateView; @@ -222,11 +222,10 @@ HANDLE hThread; hThread = (HANDLE)_beginthreadex(NULL, 0, - &RefreshThread, + RefreshThread, ThreadData, 0, NULL); - if (hThread) CloseHandle(hThread); } @@ -479,7 +478,7 @@ // Get the cached class node ClassNode = GetClassNode(&ClassGuid); - if (ClassNode == NULL) + if (ClassNode == nullptr) { ATLASSERT(FALSE); ClassIndex++; @@ -520,7 +519,7 @@ // Get the cached device node DeviceNode = GetDeviceNode(DeviceInfoData.DevInst); - if (DeviceNode == NULL) + if (DeviceNode == nullptr) { ATLASSERT(bClassUnknown == true); DeviceIndex++; @@ -1021,13 +1020,14 @@ CClassNode *Node; Pos = m_ClassNodeList.GetHeadPosition(); + if (Pos == NULL) return nullptr; do { Node = m_ClassNodeList.GetNext(Pos); if (IsEqualGUID(*Node->GetClassGuid(), *ClassGuid)) { - //ATLASSERT(Node->GetType() == NodeClass); + ATLASSERT(Node->GetNodeType() == ClassNode); break; } @@ -1047,13 +1047,14 @@ CDeviceNode *Node; Pos = m_DeviceNodeList.GetHeadPosition(); + if (Pos == NULL) return nullptr; do { Node = m_DeviceNodeList.GetNext(Pos); if (Node->GetDeviceInst() == Device) { - //ATLASSERT(Node->GetType() == NodeDevice); + ATLASSERT(Node->GetNodeType() == DeviceNode); break; } @@ -1112,6 +1113,7 @@ if (m_RootNode) delete m_RootNode; m_RootNode = new CRootNode(&m_ImageListData); m_RootNode->SetupNode(); + // Loop through all the classes do { @@ -1155,6 +1157,11 @@ { m_DeviceNodeList.AddTail(DeviceNode); } + else + { + ATLASSERT(FALSE); + } + } SetupDiDestroyDeviceInfoList(hDevInfo); Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/MainWindow.cpp [iso-8859-1] Tue Jul 7 20:33:54 2015 @@ -788,6 +788,7 @@ HINSTANCE g_hInstance = NULL; HANDLE ProcessHeap = NULL; + BOOL WINAPI DeviceManager_ExecuteW(HWND /*hWndParent*/, @@ -809,6 +810,9 @@ icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES; InitCommonControlsEx(&icex); + //__debugbreak(); + g_hInstance = GetModuleHandle(L"devmgr.dll"); + // Load the application name if (szAppName.LoadStringW(g_hInstance, IDS_APPNAME)) { Removed: trunk/reactos/dll/win32/devmgr_new/devmgmt/Resource.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/Resource.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/Resource.h (removed) @@ -1,84 +0,0 @@ -#define IDC_STATIC -1 - -#define IDS_APPNAME 10 - -#define IDI_MAIN_ICON 20 -#define IDB_ROOT_IMAGE 21 -#define IDB_TOOLBAR 22 - -/* windows */ -#define IDC_TREEVIEW 50 -#define IDC_TOOLBAR 51 -#define IDC_STATUSBAR 52 -#define IDR_MAINMENU 53 -#define IDR_POPUP 54 - -/* Actions */ -#define IDC_PROPERTIES 100 -#define IDC_SCAN_HARDWARE 101 -#define IDC_ENABLE_DRV 102 -#define IDC_DISABLE_DRV 103 -#define IDC_UPDATE_DRV 104 -#define IDC_UNINSTALL_DRV 105 -#define IDC_ADD_HARDWARE 106 - -/* Menu items */ -#define IDC_ACTIONMENU 150 -#define IDC_ABOUT 151 -#define IDC_EXIT 152 - - -/* view menu */ -#define IDC_DEVBYTYPE 200 -#define IDC_DEVBYCONN 201 -#define IDC_RESBYTYPE 202 -#define IDC_RESBYCONN 203 -#define IDC_SHOWHIDDEN 204 - - -/* tooltips */ -#define IDS_TOOLTIP_PROPERTIES 300 -#define IDS_TOOLTIP_SCAN 301 -#define IDS_TOOLTIP_ENABLE 302 -#define IDS_TOOLTIP_DISABLE 303 -#define IDS_TOOLTIP_UPDATE 304 -#define IDS_TOOLTIP_UNINSTALL 305 - -/* General strings */ -#define IDS_CONFIRM_DISABLE 400 - -/* Menu strings */ -#define IDS_MENU_UPDATE 500 -#define IDS_MENU_ENABLE 501 -#define IDS_MENU_DISABLE 502 -#define IDS_MENU_UNINSTALL 503 -#define IDS_MENU_SCAN 504 -#define IDS_MENU_ADD 505 -#define IDS_MENU_PROPERTIES 506 - - -/* menu hints */ -#define IDS_HINT_BLANK 1000 -#define IDS_HINT_PROPERTIES 1001 -#define IDS_HINT_SCAN 1002 -#define IDS_HINT_ENABLE 1003 -#define IDS_HINT_DISABLE 1004 -#define IDS_HINT_UPDATE 1005 -#define IDS_HINT_UNINSTALL 1006 -#define IDS_HINT_ADD 1007 -#define IDS_HINT_ABOUT 20008 -#define IDS_HINT_EXIT 20009 - -#define IDS_HINT_DEV_BY_TYPE 20020 -#define IDS_HINT_DEV_BY_CONN 20021 -#define IDS_HINT_RES_BY_TYPE 20022 -#define IDS_HINT_RES_BY_CONN 20023 -#define IDS_HINT_SHOW_HIDDEN 20024 - -/* system menu hints */ -#define IDS_HINT_SYS_RESTORE 21001 -#define IDS_HINT_SYS_MOVE 21002 -#define IDS_HINT_SYS_SIZE 21003 -#define IDS_HINT_SYS_MINIMIZE 21004 -#define IDS_HINT_SYS_MAXIMIZE 21005 -#define IDS_HINT_SYS_CLOSE 21006 Modified: trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/devmgmt.h [iso-8859-1] Tue Jul 7 20:33:54 2015 @@ -2,7 +2,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #pragma once -#include "resource.h" +#include "..\resource.h" extern HINSTANCE g_hInstance; extern HANDLE ProcessHeap; Removed: trunk/reactos/dll/win32/devmgr_new/devmgmt/rsrc.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgmt/rsrc.rc [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgmt/rsrc.rc (removed) @@ -1,80 +0,0 @@ -#include <windows.h> -#include "resource.h" - -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL - -IDI_MAIN_ICON ICON "res/computer.ico" -IDB_ROOT_IMAGE BITMAP "res/root.bmp" - -/* main toolbar icons */ -IDB_TOOLBAR BITMAP DISCARDABLE "res/toolbar.bmp" - -// UTF-8 -#pragma code_page(65001) - -#ifdef LANGUAGE_BG_BG - #include "lang/bg-BG.rc" -#endif -#ifdef LANGUAGE_DE_DE - #include "lang/de-DE.rc" -#endif -#ifdef LANGUAGE_EL_GR - #include "lang/el-GR.rc" -#endif -#ifdef LANGUAGE_EN_US - #include "lang/en-US.rc" -#endif -#ifdef LANGUAGE_ES_ES - #include "lang/es-ES.rc" -#endif -#ifdef LANGUAGE_FR_FR - #include "lang/fr-FR.rc" -#endif -#ifdef LANGUAGE_HE_IL - #include "lang/he-IL.rc" -#endif -#ifdef LANGUAGE_ID_ID - #include "lang/id-ID.rc" -#endif -#ifdef LANGUAGE_IT_IT - #include "lang/it-IT.rc" -#endif -#ifdef LANGUAGE_JA_JP - #include "lang/ja-JP.rc" -#endif -#ifdef LANGUAGE_KO_KR - #include "lang/ko-KR.rc" -#endif -#ifdef LANGUAGE_NB_NO - #include "lang/no-NO.rc" -#endif -#ifdef LANGUAGE_PL_PL - #include "lang/pl-PL.rc" -#endif -#ifdef LANGUAGE_PT_BR - #include "lang/pt-BR.rc" -#endif -#ifdef LANGUAGE_RO_RO - #include "lang/ro-RO.rc" -#endif -#ifdef LANGUAGE_RU_RU - #include "lang/ru-RU.rc" -#endif -#ifdef LANGUAGE_SK_SK - #include "lang/sk-SK.rc" -#endif -#ifdef LANGUAGE_SV_SE - #include "lang/sv-SE.rc" -#endif -#ifdef LANGUAGE_TH_TH - #include "lang/th-TH.rc" -#endif -#ifdef LANGUAGE_TR_TR - #include "lang/tr-TR.rc" -#endif -#ifdef LANGUAGE_UK_UA - #include "lang/uk-UA.rc" -#endif -#ifdef LANGUAGE_ZH_CN - #include "lang/zh-CN.rc" -#endif Modified: trunk/reactos/dll/win32/devmgr_new/devmgr.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/devmg…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/devmgr.rc [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/devmgr.rc [iso-8859-1] Tue Jul 7 20:33:54 2015 @@ -4,13 +4,15 @@ #include "resource.h" -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL - #define REACTOS_VERSION_DLL #define REACTOS_STR_FILE_DESCRIPTION "ReactOS Device Manager" #define REACTOS_STR_INTERNAL_NAME "devmgr" #define REACTOS_STR_ORIGINAL_FILENAME "devmgr.dll" + #include <reactos/version.rc> +#include <reactos/manifest_dll.rc> + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDI_MAIN_ICON ICON "resources/computer.ico" IDB_ROOT_IMAGE BITMAP "resources/root.bmp" @@ -18,70 +20,7 @@ /* main toolbar icons */ IDB_TOOLBAR BITMAP DISCARDABLE "resources/toolbar.bmp" -#include <reactos/manifest_dll.rc> - -#define LANGUAGE_EN_US - /* UTF-8 */ #pragma code_page(65001) -#ifdef LANGUAGE_BG_BG - #include "lang/bg-BG.rc" -#endif -#ifdef LANGUAGE_CS_CZ - #include "lang/cs-CZ.rc" -#endif -#ifdef LANGUAGE_DE_DE - #include "lang/de-DE.rc" -#endif -#ifdef LANGUAGE_EL_GR - #include "lang/el-GR.rc" -#endif -#ifdef LANGUAGE_EN_US - #include "lang/en-US.rc" -#endif -#ifdef LANGUAGE_ES_ES - #include "lang/es-ES.rc" -#endif -#ifdef LANGUAGE_HE_IL - #include "lang/he-IL.rc" -#endif -#ifdef LANGUAGE_FR_FR - #include "lang/fr-FR.rc" -#endif -#ifdef LANGUAGE_HU_HU - #include "lang/hu-HU.rc" -#endif -#ifdef LANGUAGE_ID_ID - #include "lang/id-ID.rc" -#endif -#ifdef LANGUAGE_IT_IT - #include "lang/it-IT.rc" -#endif -#ifdef LANGUAGE_NB_NO - #include "lang/no-NO.rc" -#endif -#ifdef LANGUAGE_PL_PL - #include "lang/pl-PL.rc" -#endif -#ifdef LANGUAGE_PT_BR - #include "lang/pt-BR.rc" -#endif -#ifdef LANGUAGE_RO_RO - #include "lang/ro-RO.rc" -#endif -#ifdef LANGUAGE_RU_RU - #include "lang/ru-RU.rc" -#endif -#ifdef LANGUAGE_SK_SK - #include "lang/sk-SK.rc" -#endif -#ifdef LANGUAGE_SQ_AL - #include "lang/sq-AL.rc" -#endif -#ifdef LANGUAGE_TR_TR - #include "lang/tr-TR.rc" -#endif -#ifdef LANGUAGE_UK_UA - #include "lang/uk-UA.rc" -#endif +#include "lang/en-US.rc" Modified: trunk/reactos/dll/win32/devmgr_new/lang/en-US.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/devmgr_new/lang/…
============================================================================== --- trunk/reactos/dll/win32/devmgr_new/lang/en-US.rc [iso-8859-1] (original) +++ trunk/reactos/dll/win32/devmgr_new/lang/en-US.rc [iso-8859-1] Tue Jul 7 20:33:54 2015 @@ -266,6 +266,7 @@ STRINGTABLE DISCARDABLE BEGIN + IDS_APPNAME "ReactOS Device Manager" IDS_CONFIRM_DISABLE "Disabling this device will cause it to stop functioning.\r\nDo you really want to disable it?" END STRINGTABLE DISCARDABLE @@ -292,7 +293,6 @@ /* Hints */ STRINGTABLE DISCARDABLE BEGIN - IDS_APPNAME "ReactOS Device Manager" IDS_HINT_BLANK " " IDS_HINT_PROPERTIES " Open property dialog for the current selection." IDS_HINT_SCAN " Scan for changed or new plug and play devices."
9 years, 5 months
1
0
0
0
[cfinck] 68375: [LOCALSPL] - Initialize all Print Monitors on startup and keep a list of them. - Implement LocalEnumMonitors and LocalEnumPorts. - Check the result of the initialization functions. ...
by cfinck@svn.reactos.org
Author: cfinck Date: Tue Jul 7 17:06:48 2015 New Revision: 68375 URL:
http://svn.reactos.org/svn/reactos?rev=68375&view=rev
Log: [LOCALSPL] - Initialize all Print Monitors on startup and keep a list of them. - Implement LocalEnumMonitors and LocalEnumPorts. - Check the result of the initialization functions. [SPOOLSS] - Implement support for multiple Print Providers. Initialize them on startup and keep a list here as well. - Implement all functions that had simple stubs in the C code. This still needs to be done for the remaining functions stubbed in the .spec file. But generally spoken, this always boils down to 3 cases: * Forward the call to the Local Spooler (for general functions like GetPrintProcessorDirectory). * Forward the call to the Print Provider we used for OpenPrinter (for functions like SetJob). * Forward the call to all Print Providers and collect the results (for functions like EnumPrinters). Added: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/monitors.c (with props) branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/monitors.c (with props) branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/ports.c (with props) Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/CMakeLists.txt branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/jobs.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/main.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/memory.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/ports.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/precomp.h branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printers.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printprocessors.c branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/spoolss.spec branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/CMakeLists.txt branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/main.c branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/CMakeLists.txt [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/CMakeLists.txt [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -6,6 +6,7 @@ jobs.c main.c memory.c + monitors.c ports.c precomp.h printers.c Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/jobs.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/jobs.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/jobs.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -8,31 +8,76 @@ #include "precomp.h" BOOL WINAPI -AddJobW(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded) +AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded) { - return LocalSplFuncs.fpAddJob(hPrinter, Level, pData, cbBuf, pcbNeeded); + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpAddJob(pHandle->hPrinter, Level, pData, cbBuf, pcbNeeded); } BOOL WINAPI EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { - return LocalSplFuncs.fpEnumJobs(hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned); + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpEnumJobs(pHandle->hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned); } BOOL WINAPI -GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded) +GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded) { - return LocalSplFuncs.fpGetJob(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded); + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpGetJob(pHandle->hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded); } BOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD dwJobID) { - return LocalSplFuncs.fpScheduleJob(hPrinter, dwJobID); + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpScheduleJob(pHandle->hPrinter, dwJobID); } BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command) { - return LocalSplFuncs.fpSetJob(hPrinter, JobId, Level, pJobInfo, Command); + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpSetJob(pHandle->hPrinter, JobId, Level, pJobInfo, Command); } Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/main.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/main.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/main.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -7,9 +7,179 @@ #include "precomp.h" +// Global Variables HANDLE hProcessHeap; -PRINTPROVIDOR LocalSplFuncs; - +LIST_ENTRY PrintProviderList; + + +static DWORD +_AddPrintProviderToList(PCWSTR pwszFileName) +{ + DWORD dwErrorCode; + HINSTANCE hinstPrintProvider; + PInitializePrintProvidor pfnInitializePrintProvidor; + PSPOOLSS_PRINT_PROVIDER pPrintProvider = NULL; + + // Try to load it. + hinstPrintProvider = LoadLibraryW(pwszFileName); + if (!hinstPrintProvider) + { + dwErrorCode = GetLastError(); + ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", pwszFileName, dwErrorCode); + goto Cleanup; + } + + // Get the initialization routine. + pfnInitializePrintProvidor = (PInitializePrintProvidor)GetProcAddress(hinstPrintProvider, "InitializePrintProvidor"); + if (!pfnInitializePrintProvidor) + { + dwErrorCode = GetLastError(); + ERR("GetProcAddress failed for \"%S\" with error %lu!\n", pwszFileName, dwErrorCode); + goto Cleanup; + } + + // Create a new SPOOLSS_PRINT_PROVIDER structure for it. + pPrintProvider = DllAllocSplMem(sizeof(SPOOLSS_PRINT_PROVIDER)); + if (!pPrintProvider) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + // Call the Print Provider initialization function. + if (!pfnInitializePrintProvidor(&pPrintProvider->PrintProvider, sizeof(PRINTPROVIDOR), NULL)) + { + dwErrorCode = GetLastError(); + ERR("InitializePrintProvidor failed for \"%S\" with error %lu!\n", pwszFileName, dwErrorCode); + goto Cleanup; + } + + // Add this Print Provider to the list. + InsertTailList(&PrintProviderList, &pPrintProvider->Entry); + + // Don't let the cleanup routine free this. + pPrintProvider = NULL; + dwErrorCode = ERROR_SUCCESS; + +Cleanup: + if (pPrintProvider) + DllFreeSplMem(pPrintProvider); + + return dwErrorCode; +} + +static BOOL +_InitializePrintProviderList() +{ + DWORD cbFileName; + DWORD cchMaxSubKey; + DWORD cchPrintProviderName; + DWORD dwErrorCode; + DWORD dwSubKeys; + DWORD i; + HKEY hKey = NULL; + HKEY hSubKey = NULL; + PWSTR pwszPrintProviderName = NULL; + WCHAR wszFileName[MAX_PATH]; + + // Initialize an empty list for our Print Providers. + InitializeListHead(&PrintProviderList); + + // First add the Local Spooler. + // This one must exist and must be the first one in the list. + dwErrorCode = _AddPrintProviderToList(L"localspl"); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("The Local Spooler could not be loaded!\n"); + goto Cleanup; + } + + // Now add additional Print Providers from the registry. + // First of all, open the key containing print providers. + dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Print\\Providers", 0, KEY_READ, &hKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode); + goto Cleanup; + } + + // Get the number of Print Providers and maximum sub key length. + dwErrorCode = (DWORD)RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwSubKeys, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode); + goto Cleanup; + } + + // Allocate a temporary buffer for the Print Provider names. + pwszPrintProviderName = DllAllocSplMem((cchMaxSubKey + 1) * sizeof(WCHAR)); + if (!pwszPrintProviderName) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + // Loop through all available Print Providers. + for (i = 0; i < dwSubKeys; i++) + { + // Cleanup tasks from the previous run + if (hSubKey) + { + RegCloseKey(hSubKey); + hSubKey = NULL; + } + + // Get the name of this Print Provider. + cchPrintProviderName = cchMaxSubKey + 1; + dwErrorCode = (DWORD)RegEnumKeyExW(hKey, i, pwszPrintProviderName, &cchPrintProviderName, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegEnumKeyExW failed for iteration %lu with status %lu!\n", i, dwErrorCode); + continue; + } + + // Open this Print Provider's registry key. + dwErrorCode = (DWORD)RegOpenKeyExW(hKey, pwszPrintProviderName, 0, KEY_READ, &hSubKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed for Print Provider \"%S\" with status %lu!\n", pwszPrintProviderName, dwErrorCode); + continue; + } + + // Get the file name of the Print Provider. + cbFileName = MAX_PATH * sizeof(WCHAR); + dwErrorCode = (DWORD)RegQueryValueExW(hKey, L"Driver", NULL, NULL, (PBYTE)wszFileName, &cbFileName); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryValueExW failed with status %lu!\n", dwErrorCode); + continue; + } + + // Load and add it to the list. + dwErrorCode = _AddPrintProviderToList(wszFileName); + if (dwErrorCode != ERROR_SUCCESS) + continue; + } + + dwErrorCode = ERROR_SUCCESS; + +Cleanup: + // Inside the loop + if (hSubKey) + RegCloseKey(hSubKey); + + // Outside the loop + if (pwszPrintProviderName) + DllFreeSplMem(pwszPrintProviderName); + + if (hKey) + RegCloseKey(hKey); + + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); +} BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -18,7 +188,7 @@ { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); - hProcessHeap = GetProcessHeap(); + hProcessHeap = GetProcessHeap(); break; } @@ -28,32 +198,7 @@ BOOL WINAPI InitializeRouter(HANDLE SpoolerStatusHandle) { - HINSTANCE hinstLocalSpl; - PInitializePrintProvidor pfnInitializePrintProvidor; - - // Only initialize localspl.dll for now. - // This function should later look for all available print providers in the registry and initialize all of them. - hinstLocalSpl = LoadLibraryW(L"localspl"); - if (!hinstLocalSpl) - { - ERR("LoadLibraryW for localspl failed with error %lu!\n", GetLastError()); - return FALSE; - } - - pfnInitializePrintProvidor = (PInitializePrintProvidor)GetProcAddress(hinstLocalSpl, "InitializePrintProvidor"); - if (!pfnInitializePrintProvidor) - { - ERR("GetProcAddress failed with error %lu!\n", GetLastError()); - return FALSE; - } - - if (!pfnInitializePrintProvidor(&LocalSplFuncs, sizeof(PRINTPROVIDOR), NULL)) - { - ERR("InitializePrintProvidor failed for localspl with error %lu!\n", GetLastError()); - return FALSE; - } - - return TRUE; + return _InitializePrintProviderList(); } BOOL WINAPI Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/memory.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/memory.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/memory.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -9,17 +9,17 @@ /** -* @name AllocSplStr -* -* Allocates memory for a Unicode string and copies the input string into it. -* Equivalent of wcsdup, but the returned buffer is allocated from the spooler heap and must be freed with DllFreeSplStr. -* -* @param pwszInput -* The input string to copy -* -* @return -* Pointer to the copied string or NULL if no memory could be allocated. -*/ + * @name AllocSplStr + * + * Allocates memory for a Unicode string and copies the input string into it. + * Equivalent of wcsdup, but the returned buffer is allocated from the spooler heap and must be freed with DllFreeSplStr. + * + * @param pwszInput + * The input string to copy + * + * @return + * Pointer to the copied string or NULL if no memory could be allocated. + */ PWSTR WINAPI AllocSplStr(PCWSTR pwszInput) { Added: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/monitors.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/monitors.c (added) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/monitors.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -0,0 +1,68 @@ +/* + * PROJECT: ReactOS Spooler Router + * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation + * PURPOSE: Functions related to Print Monitors + * COPYRIGHT: Copyright 2015 Colin Finck <colin(a)reactos.org> + */ + +#include "precomp.h" + +BOOL WINAPI +EnumMonitorsW(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) +{ + BOOL bReturnValue; + DWORD cbCallBuffer; + DWORD cbNeeded; + DWORD dwReturned; + PBYTE pCallBuffer; + PSPOOLSS_PRINT_PROVIDER pPrintProvider; + PLIST_ENTRY pEntry; + + // Sanity checks. + if ((cbBuf && !pMonitors) || !pcbNeeded || !pcReturned) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // Begin counting. + *pcbNeeded = 0; + *pcReturned = 0; + + // At the beginning, we have the full buffer available. + cbCallBuffer = cbBuf; + pCallBuffer = pMonitors; + + // Loop through all Print Provider. + for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink) + { + pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry); + + // Check if this Print Provider provides an EnumMonitors function. + if (!pPrintProvider->PrintProvider.fpEnumMonitors) + continue; + + // Call the EnumMonitors function of this Print Provider. + bReturnValue = pPrintProvider->PrintProvider.fpEnumMonitors(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned); + + // Add the returned counts to the total values. + *pcbNeeded += cbNeeded; + *pcReturned += dwReturned; + + // Reduce the available buffer size for the next call without risking an underflow. + if (cbNeeded < cbCallBuffer) + cbCallBuffer -= cbNeeded; + else + cbCallBuffer = 0; + + // Advance the buffer if the caller provided it. + if (pCallBuffer) + pCallBuffer += cbNeeded; + + // Check if we shall not ask other Print Providers. + if (bReturnValue == ROUTER_STOP_ROUTING) + break; + } + + return bReturnValue; +} Propchange: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/monitors.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/ports.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/ports.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/ports.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -1,7 +1,7 @@ /* * PROJECT: ReactOS Spooler Router * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation - * PURPOSE: Functions related to ports + * PURPOSE: Functions related to Ports of the Print Monitors * COPYRIGHT: Copyright 2015 Colin Finck <colin(a)reactos.org> */ @@ -10,5 +10,55 @@ BOOL WINAPI EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { - return FALSE; + BOOL bReturnValue; + DWORD cbCallBuffer; + DWORD cbNeeded; + DWORD dwReturned; + PBYTE pCallBuffer; + PSPOOLSS_PRINT_PROVIDER pPrintProvider; + PLIST_ENTRY pEntry; + + // Sanity checks. + if ((cbBuf && !pPorts) || !pcbNeeded || !pcReturned) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // Begin counting. + *pcbNeeded = 0; + *pcReturned = 0; + + // At the beginning, we have the full buffer available. + cbCallBuffer = cbBuf; + pCallBuffer = pPorts; + + // Loop through all Print Provider. + for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink) + { + pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry); + + // Call the EnumPorts function of this Print Provider. + bReturnValue = pPrintProvider->PrintProvider.fpEnumPorts(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned); + + // Add the returned counts to the total values. + *pcbNeeded += cbNeeded; + *pcReturned += dwReturned; + + // Reduce the available buffer size for the next call without risking an underflow. + if (cbNeeded < cbCallBuffer) + cbCallBuffer -= cbNeeded; + else + cbCallBuffer = 0; + + // Advance the buffer if the caller provided it. + if (pCallBuffer) + pCallBuffer += cbNeeded; + + // Check if we shall not ask other Print Providers. + if (bReturnValue == ROUTER_STOP_ROUTING) + break; + } + + return bReturnValue; } Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/precomp.h URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/precomp.h [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/precomp.h [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -15,17 +15,40 @@ #include <winreg.h> #include <winspool.h> #include <winsplp.h> +#include <ndk/rtlfuncs.h> #include <spoolss.h> #include <wine/debug.h> WINE_DEFAULT_DEBUG_CHANNEL(spoolss); -// Function pointer to InitializePrintProvidor of a provider DLL +// Function pointers typedef BOOL (WINAPI *PInitializePrintProvidor)(LPPRINTPROVIDOR, DWORD, LPWSTR); + +// Structures +/** + * Describes a Print Provider. + */ +typedef struct _SPOOLSS_PRINT_PROVIDER +{ + LIST_ENTRY Entry; + PRINTPROVIDOR PrintProvider; +} +SPOOLSS_PRINT_PROVIDER, *PSPOOLSS_PRINT_PROVIDER; + +/* + * Describes a handle returned by OpenPrinterW. + * We can't just pass the handle returned by the Print Provider, because spoolss has to remember which Print Provider opened this handle. + */ +typedef struct _SPOOLSS_PRINTER_HANDLE +{ + PSPOOLSS_PRINT_PROVIDER pPrintProvider; /** Pointer to the Print Provider that opened this printer. */ + HANDLE hPrinter; /** The handle returned by fpOpenPrinter of the Print Provider and passed to subsequent Print Provider functions. */ +} +SPOOLSS_PRINTER_HANDLE, *PSPOOLSS_PRINTER_HANDLE; // main.c extern HANDLE hProcessHeap; -extern PRINTPROVIDOR LocalSplFuncs; +extern LIST_ENTRY PrintProviderList; #endif Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printers.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printers.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printers.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -11,71 +11,262 @@ BOOL WINAPI ClosePrinter(HANDLE hPrinter) { + BOOL bReturnValue; + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // FIXME: Call FindClosePrinterChangeNotification for all created change notifications (according to MSDN). + + // Call CloseHandle of the Print Provider. + bReturnValue = pHandle->pPrintProvider->PrintProvider.fpClosePrinter(pHandle->hPrinter); + + // Free our handle information. + DllFreeSplMem(pHandle); + + return bReturnValue; +} + +BOOL WINAPI +EndDocPrinter(HANDLE hPrinter) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpEndDocPrinter(pHandle->hPrinter); +} + +BOOL WINAPI +EndPagePrinter(HANDLE hPrinter) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpEndPagePrinter(pHandle->hPrinter); +} + +BOOL WINAPI +EnumPrintersW(DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) +{ + BOOL bReturnValue; + DWORD cbCallBuffer; + DWORD cbNeeded; + DWORD dwReturned; + PBYTE pCallBuffer; + PSPOOLSS_PRINT_PROVIDER pPrintProvider; + PLIST_ENTRY pEntry; + + // Sanity checks. + if ((cbBuf && !pPrinterEnum) || !pcbNeeded || !pcReturned) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // Begin counting. + *pcbNeeded = 0; + *pcReturned = 0; + + // At the beginning, we have the full buffer available. + cbCallBuffer = cbBuf; + pCallBuffer = pPrinterEnum; + + // Loop through all Print Provider. + for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink) + { + pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry); + + // Call the EnumPrinters function of this Print Provider. + bReturnValue = pPrintProvider->PrintProvider.fpEnumPrinters(Flags, Name, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned); + + // Add the returned counts to the total values. + *pcbNeeded += cbNeeded; + *pcReturned += dwReturned; + + // Reduce the available buffer size for the next call without risking an underflow. + if (cbNeeded < cbCallBuffer) + cbCallBuffer -= cbNeeded; + else + cbCallBuffer = 0; + + // Advance the buffer if the caller provided it. + if (pCallBuffer) + pCallBuffer += cbNeeded; + } + + return bReturnValue; +} + +BOOL WINAPI +GetPrinterDriverW(HANDLE hPrinter, PWSTR pEnvironment, DWORD Level, PBYTE pDriverInfo, DWORD cbBuf, PDWORD pcbNeeded) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpGetPrinterDriver(pHandle->hPrinter, pEnvironment, Level, pDriverInfo, cbBuf, pcbNeeded); +} + +BOOL WINAPI +GetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded); +} + +BOOL WINAPI +OpenPrinterW(PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault) +{ + BOOL bReturnValue; + HANDLE hPrinter; + PLIST_ENTRY pEntry; + PSPOOLSS_PRINTER_HANDLE pHandle; + PSPOOLSS_PRINT_PROVIDER pPrintProvider; + + // Sanity checks. + if (!pPrinterName || !phPrinter) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // Loop through all Print Providers to find one able to open this Printer. + for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink) + { + pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry); + + bReturnValue = pPrintProvider->PrintProvider.fpOpenPrinter(pPrinterName, &hPrinter, pDefault); + if (bReturnValue == ROUTER_SUCCESS) + { + // This Print Provider has opened this Printer. + // Store this information and return a handle. + pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE)); + if (!pHandle) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + return FALSE; + } + + pHandle->pPrintProvider = pPrintProvider; + pHandle->hPrinter = hPrinter; + *phPrinter = (HANDLE)pHandle; + + SetLastError(ERROR_SUCCESS); + return TRUE; + } + else if (bReturnValue == ROUTER_STOP_ROUTING) + { + ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName); + return FALSE; + } + } + + // We found no Print Provider able to open this Printer. return FALSE; } BOOL WINAPI -EndDocPrinter(HANDLE hPrinter) -{ - return FALSE; -} - -BOOL WINAPI -EndPagePrinter(HANDLE hPrinter) -{ - return FALSE; -} - -BOOL WINAPI -EnumPrintersW(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned) -{ - return LocalSplFuncs.fpEnumPrinters(Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned); -} - -BOOL WINAPI -GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment, DWORD Level, LPBYTE pDriverInfo, DWORD cbBuf, LPDWORD pcbNeeded) -{ - return FALSE; -} - -BOOL WINAPI -GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded) -{ - return FALSE; -} - -BOOL WINAPI -OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault) -{ - return LocalSplFuncs.fpOpenPrinter(pPrinterName, phPrinter, pDefault); -} - -BOOL WINAPI ReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead) { - return FALSE; + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpReadPrinter(pHandle->hPrinter, pBuf, cbBuf, pNoBytesRead); } DWORD WINAPI -StartDocPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo) -{ - return 0; +StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpStartDocPrinter(pHandle->hPrinter, Level, pDocInfo); } BOOL WINAPI StartPagePrinter(HANDLE hPrinter) { - return FALSE; -} - -BOOL WINAPI -WritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten) -{ - return FALSE; + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpStartPagePrinter(pHandle->hPrinter); +} + +BOOL WINAPI +WritePrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten) +{ + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpWritePrinter(pHandle->hPrinter, pBuf, cbBuf, pcWritten); } BOOL WINAPI XcvDataW(HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus) { - return FALSE; -} + PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hXcv; + + // Sanity checks. + if (!pHandle) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + return pHandle->pPrintProvider->PrintProvider.fpXcvData(pHandle->hPrinter, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded, pdwStatus); +} Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printprocessors.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printprocessors.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/printprocessors.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -8,19 +8,25 @@ #include "precomp.h" BOOL WINAPI -EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned) +EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { - return LocalSplFuncs.fpEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned); + // Always call this function on the Local Spooler. + PSPOOLSS_PRINT_PROVIDER pPrintProvider = CONTAINING_RECORD(&PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry); + return pPrintProvider->PrintProvider.fpEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned); } BOOL WINAPI -EnumPrintProcessorsW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned) +EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { - return LocalSplFuncs.fpEnumPrintProcessors(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned); + // Always call this function on the Local Spooler. + PSPOOLSS_PRINT_PROVIDER pPrintProvider = CONTAINING_RECORD(&PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry); + return pPrintProvider->PrintProvider.fpEnumPrintProcessors(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned); } BOOL WINAPI -GetPrintProcessorDirectoryW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded) +GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded) { - return LocalSplFuncs.fpGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded); + // Always call this function on the Local Spooler. + PSPOOLSS_PRINT_PROVIDER pPrintProvider = CONTAINING_RECORD(&PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry); + return pPrintProvider->PrintProvider.fpGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded); } Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/spoolss.spec URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/spoolss.spec [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/base/spoolss/spoolss.spec [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -60,16 +60,16 @@ @ stdcall EndPagePrinter(long) @ stub EnumFormsW @ stdcall EnumJobsW(long long long long ptr long ptr ptr) -@ stub EnumMonitorsW +@ stdcall EnumMonitorsW(wstr long ptr long ptr ptr) @ stub EnumPerMachineConnectionsW -@ stdcall EnumPortsW(ptr long ptr long ptr ptr) +@ stdcall EnumPortsW(wstr long ptr long ptr ptr) @ stub EnumPrinterDataExW @ stub EnumPrinterDataW @ stub EnumPrinterDriversW @ stub EnumPrinterKeyW -@ stdcall EnumPrintersW(long ptr long ptr long ptr ptr) -@ stdcall EnumPrintProcessorDatatypesW(ptr ptr long ptr long ptr ptr) -@ stdcall EnumPrintProcessorsW(ptr ptr long ptr long ptr ptr) +@ stdcall EnumPrintersW(long wstr long ptr long ptr ptr) +@ stdcall EnumPrintProcessorDatatypesW(wstr wstr long ptr long ptr ptr) +@ stdcall EnumPrintProcessorsW(wstr wstr long ptr long ptr ptr) @ stub FindClosePrinterChangeNotification @ stub FlushPrinter @ stub FormatPrinterForRegistryKey Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/CMakeLists.txt URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/CMakeLists.txt [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/CMakeLists.txt [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -6,6 +6,8 @@ list(APPEND SOURCE jobs.c main.c + monitors.c + ports.c precomp.h printers.c printprocessors.c Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -102,7 +102,7 @@ return TRUE; } -void +BOOL InitializeGlobalJobList() { const WCHAR wszPath[] = L"\\PRINTERS\\?????.SHD"; @@ -110,6 +110,7 @@ const DWORD cchFolders = sizeof("\\PRINTERS\\") - 1; const DWORD cchPattern = sizeof("?????") - 1; + DWORD dwErrorCode; DWORD dwJobID; HANDLE hFind; PLOCAL_JOB pJob = NULL; @@ -133,6 +134,7 @@ if (hFind == INVALID_HANDLE_VALUE) { // No unfinished jobs found. + dwErrorCode = ERROR_SUCCESS; goto Cleanup; } @@ -159,6 +161,7 @@ // Add it to the Global Job List. if (!InsertElementSkiplist(&GlobalJobList, pJob)) { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("InsertElementSkiplist failed for job %lu for the GlobalJobList!\n", pJob->dwJobID); goto Cleanup; } @@ -166,16 +169,22 @@ // Add it to the Printer's Job List. if (!InsertElementSkiplist(&pJob->pPrinter->JobList, pJob)) { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("InsertElementSkiplist failed for job %lu for the Printer's Job List!\n", pJob->dwJobID); goto Cleanup; } } while (FindNextFileW(hFind, &FindData)); + + dwErrorCode = ERROR_SUCCESS; Cleanup: // Outside the loop if (hFind) FindClose(hFind); + + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); } void Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/main.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/main.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/main.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -22,6 +22,8 @@ #else #error Unsupported architecture #endif + +const DWORD cbCurrentEnvironment = sizeof(wszCurrentEnvironment); const WCHAR wszDefaultDocumentName[] = L"Local Downlevel Document"; @@ -70,8 +72,8 @@ NULL, // fpGetForm NULL, // fpSetForm NULL, // fpEnumForms - NULL, // fpEnumMonitors - NULL, // fpEnumPorts + LocalEnumMonitors, // fpEnumMonitors + LocalEnumPorts, // fpEnumPorts NULL, // fpAddPort NULL, // fpConfigurePort NULL, // fpDeletePort @@ -142,13 +144,15 @@ case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); _GetSpoolDirectory(); - InitializePrintProcessorList(); - InitializePrinterList(); - InitializeGlobalJobList(); - break; + + return InitializePrintMonitorList() && + InitializePrintProcessorList() && + InitializePrinterList() && + InitializeGlobalJobList(); + + default: + return TRUE; } - - return TRUE; } BOOL WINAPI Added: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/monitors.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/monitors.c (added) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/monitors.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -0,0 +1,314 @@ +/* + * PROJECT: ReactOS Local Spooler + * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation + * PURPOSE: Functions related to Print Monitors + * COPYRIGHT: Copyright 2015 Colin Finck <colin(a)reactos.org> + */ + +#include "precomp.h" + +// Local Variables +LIST_ENTRY PrintMonitorList; + +BOOL +InitializePrintMonitorList() +{ + const WCHAR wszMonitorsPath[] = L"SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors"; + const DWORD cchMonitorsPath = _countof(wszMonitorsPath) - 1; + + DWORD cchMaxSubKey; + DWORD cchPrintMonitorName; + DWORD dwErrorCode; + DWORD dwSubKeys; + DWORD i; + HINSTANCE hinstPrintMonitor = NULL; + HKEY hKey = NULL; + HKEY hSubKey = NULL; + MONITORINIT MonitorInit; + PInitializePrintMonitor pfnInitializePrintMonitor; + PInitializePrintMonitor2 pfnInitializePrintMonitor2; + PLOCAL_PRINT_MONITOR pPrintMonitor = NULL; + PWSTR pwszRegistryPath = NULL; + + // Initialize an empty list for our Print Monitors. + InitializeListHead(&PrintMonitorList); + + // Open the key containing Print Monitors. + dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszMonitorsPath, 0, KEY_READ, &hKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode); + goto Cleanup; + } + + // Get the number of Print Providers and maximum sub key length. + dwErrorCode = (DWORD)RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwSubKeys, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode); + goto Cleanup; + } + + // Loop through all available Print Providers. + for (i = 0; i < dwSubKeys; i++) + { + // Cleanup tasks from the previous run + if (hSubKey) + { + RegCloseKey(hSubKey); + hSubKey = NULL; + } + + if (pwszRegistryPath) + { + DllFreeSplMem(pwszRegistryPath); + pwszRegistryPath = NULL; + } + + if (pPrintMonitor) + { + if (pPrintMonitor->pwszFileName) + DllFreeSplMem(pPrintMonitor->pwszFileName); + + if (pPrintMonitor->pwszName) + DllFreeSplMem(pPrintMonitor->pwszName); + + DllFreeSplMem(pPrintMonitor); + pPrintMonitor = NULL; + } + + // Create a new LOCAL_PRINT_MONITOR structure for it. + pPrintMonitor = DllAllocSplMem(sizeof(LOCAL_PRINT_MONITOR)); + if (!pPrintMonitor) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + // Allocate memory for the Print Monitor Name. + pPrintMonitor->pwszName = DllAllocSplMem((cchMaxSubKey + 1) * sizeof(WCHAR)); + if (!pPrintMonitor->pwszName) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + // Get the name of this Print Monitor. + cchPrintMonitorName = cchMaxSubKey + 1; + dwErrorCode = (DWORD)RegEnumKeyExW(hKey, i, pPrintMonitor->pwszName, &cchPrintMonitorName, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegEnumKeyExW failed for iteration %lu with status %lu!\n", i, dwErrorCode); + continue; + } + + // Open this Print Monitor's registry key. + dwErrorCode = (DWORD)RegOpenKeyExW(hKey, pPrintMonitor->pwszName, 0, KEY_READ, &hSubKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed for Print Provider \"%S\" with status %lu!\n", pPrintMonitor->pwszName, dwErrorCode); + continue; + } + + // Get the file name of the Print Monitor. + pPrintMonitor->pwszFileName = AllocAndRegQueryWSZ(hSubKey, L"Driver"); + if (!pPrintMonitor->pwszFileName) + continue; + + // Try to load it. + hinstPrintMonitor = LoadLibraryW(pPrintMonitor->pwszFileName); + if (!hinstPrintMonitor) + { + ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError()); + continue; + } + + // Try to find a Level 2 initialization routine first. + pfnInitializePrintMonitor2 = (PInitializePrintMonitor2)GetProcAddress(hinstPrintMonitor, "InitializePrintMonitor2"); + if (pfnInitializePrintMonitor2) + { + // Prepare a MONITORINIT structure. + MonitorInit.cbSize = sizeof(MONITORINIT); + MonitorInit.bLocal = TRUE; + + // TODO: Fill the other fields. + + // Call the Level 2 initialization routine. + pPrintMonitor->pMonitor = (PMONITOR2)pfnInitializePrintMonitor2(&MonitorInit, &pPrintMonitor->hMonitor); + if (!pPrintMonitor->pMonitor) + { + ERR("InitializePrintMonitor2 failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError()); + continue; + } + + pPrintMonitor->bIsLevel2 = TRUE; + } + else + { + // Try to find a Level 1 initialization routine then. + pfnInitializePrintMonitor = (PInitializePrintMonitor)GetProcAddress(hinstPrintMonitor, "InitializePrintMonitor"); + if (pfnInitializePrintMonitor) + { + // Construct the registry path. + pwszRegistryPath = DllAllocSplMem((cchMonitorsPath + 1 + cchPrintMonitorName + 1) * sizeof(WCHAR)); + if (!pwszRegistryPath) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + CopyMemory(pwszRegistryPath, wszMonitorsPath, cchMonitorsPath * sizeof(WCHAR)); + pwszRegistryPath[cchMonitorsPath] = L'\\'; + CopyMemory(&pwszRegistryPath[cchMonitorsPath + 1], pPrintMonitor->pwszName, (cchPrintMonitorName + 1) * sizeof(WCHAR)); + + // Call the Level 1 initialization routine. + pPrintMonitor->pMonitor = (LPMONITOREX)pfnInitializePrintMonitor(pwszRegistryPath); + if (!pPrintMonitor->pMonitor) + { + ERR("InitializePrintMonitor failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError()); + continue; + } + } + else + { + ERR("No initialization routine found for \"%S\"!\n", pPrintMonitor->pwszFileName); + continue; + } + } + + // Add this Print Monitor to the list. + InsertTailList(&PrintMonitorList, &pPrintMonitor->Entry); + + // Don't let the cleanup routine free this. + pPrintMonitor = NULL; + } + + dwErrorCode = ERROR_SUCCESS; + +Cleanup: + // Inside the loop + if (hSubKey) + RegCloseKey(hSubKey); + + if (pwszRegistryPath) + DllFreeSplMem(pwszRegistryPath); + + if (pPrintMonitor) + { + if (pPrintMonitor->pwszFileName) + DllFreeSplMem(pPrintMonitor->pwszFileName); + + if (pPrintMonitor->pwszName) + DllFreeSplMem(pPrintMonitor->pwszName); + + DllFreeSplMem(pPrintMonitor); + } + + // Outside the loop + if (hKey) + RegCloseKey(hKey); + + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); +} + +BOOL WINAPI +LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) +{ + DWORD cbFileName; + DWORD cbMonitorName; + DWORD dwErrorCode; + PBYTE pStart; + PBYTE pEnd; + PLIST_ENTRY pEntry; + PLOCAL_PRINT_MONITOR pPrintMonitor; + MONITOR_INFO_2W MonitorInfo2; // MONITOR_INFO_1W is a subset of MONITOR_INFO_2W, so we can handle both in one function here. + + // Sanity checks. + if (Level > 2) + { + dwErrorCode = ERROR_INVALID_LEVEL; + goto Cleanup; + } + + if ((cbBuf && !pMonitors) || !pcbNeeded || !pcReturned) + { + dwErrorCode = ERROR_INVALID_PARAMETER; + goto Cleanup; + } + + // Begin counting. + *pcbNeeded = 0; + *pcReturned = 0; + + // Count the required buffer size and the number of monitors. + for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink) + { + pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry); + + cbMonitorName = (wcslen(pPrintMonitor->pwszName) + 1) * sizeof(WCHAR); + cbFileName = (wcslen(pPrintMonitor->pwszFileName) + 1) * sizeof(WCHAR); + + if (Level == 1) + *pcbNeeded += sizeof(MONITOR_INFO_1W) + cbMonitorName; + else + *pcbNeeded += sizeof(MONITOR_INFO_2W) + cbMonitorName + cbCurrentEnvironment + cbFileName; + } + + // Check if the supplied buffer is large enough. + if (cbBuf < *pcbNeeded) + { + dwErrorCode = ERROR_INSUFFICIENT_BUFFER; + goto Cleanup; + } + + // Put the strings at the end of the buffer. + pStart = pMonitors; + pEnd = &pMonitors[cbBuf]; + + for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink) + { + pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry); + + // Copy the monitor name. + cbMonitorName = (wcslen(pPrintMonitor->pwszName) + 1) * sizeof(WCHAR); + pEnd -= cbMonitorName; + MonitorInfo2.pName = (PWSTR)pEnd; + CopyMemory(pEnd, pPrintMonitor->pwszName, cbMonitorName); + + if (Level == 1) + { + // Finally copy the structure. + CopyMemory(pStart, &MonitorInfo2, sizeof(MONITOR_INFO_1W)); + pStart += sizeof(MONITOR_INFO_1W); + } + else + { + // Copy the environment. + pEnd -= cbCurrentEnvironment; + MonitorInfo2.pEnvironment = (PWSTR)pEnd; + CopyMemory(pEnd, wszCurrentEnvironment, cbCurrentEnvironment); + + // Copy the file name. + cbFileName = (wcslen(pPrintMonitor->pwszFileName) + 1) * sizeof(WCHAR); + pEnd -= cbFileName; + MonitorInfo2.pDLLName = (PWSTR)pEnd; + CopyMemory(pEnd, pPrintMonitor->pwszFileName, cbFileName); + + // Finally copy the structure. + CopyMemory(pStart, &MonitorInfo2, sizeof(MONITOR_INFO_2W)); + pStart += sizeof(MONITOR_INFO_2W); + } + + (*pcReturned)++; + } + + dwErrorCode = ERROR_SUCCESS; + +Cleanup: + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); +} Propchange: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/monitors.c ------------------------------------------------------------------------------ svn:eol-style = native Added: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/ports.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/ports.c (added) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/ports.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -0,0 +1,64 @@ +/* + * PROJECT: ReactOS Local Spooler + * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation + * PURPOSE: Functions related to Ports of the Print Monitors + * COPYRIGHT: Copyright 2015 Colin Finck <colin(a)reactos.org> + */ + +#include "precomp.h" + + +BOOL WINAPI +LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) +{ + BOOL bReturnValue; + DWORD cbCallBuffer; + DWORD cbNeeded; + DWORD dwReturned; + PBYTE pCallBuffer; + PLOCAL_PRINT_MONITOR pPrintMonitor; + PLIST_ENTRY pEntry; + + // Sanity checks. + if ((cbBuf && !pPorts) || !pcbNeeded || !pcReturned) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + // Begin counting. + *pcbNeeded = 0; + *pcReturned = 0; + + // At the beginning, we have the full buffer available. + cbCallBuffer = cbBuf; + pCallBuffer = pPorts; + + // Loop through all Print Monitors. + for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink) + { + pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry); + + // Call the EnumPorts function of this Print Monitor. + if (pPrintMonitor->bIsLevel2) + bReturnValue = ((PMONITOR2)pPrintMonitor->pMonitor)->pfnEnumPorts(pPrintMonitor->hMonitor, pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned); + else + bReturnValue = ((LPMONITOREX)pPrintMonitor->pMonitor)->Monitor.pfnEnumPorts(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned); + + // Add the returned counts to the total values. + *pcbNeeded += cbNeeded; + *pcReturned += dwReturned; + + // Reduce the available buffer size for the next call without risking an underflow. + if (cbNeeded < cbCallBuffer) + cbCallBuffer -= cbNeeded; + else + cbCallBuffer = 0; + + // Advance the buffer if the caller provided it. + if (pCallBuffer) + pCallBuffer += cbNeeded; + } + + return bReturnValue; +} Propchange: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/ports.c ------------------------------------------------------------------------------ svn:eol-style = native Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/precomp.h [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -45,6 +45,8 @@ typedef DWORD (WINAPI *PGetPrintProcessorCapabilities)(LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD); typedef HANDLE (WINAPI *POpenPrintProcessor)(LPWSTR, PPRINTPROCESSOROPENDATA); typedef BOOL (WINAPI *PPrintDocumentOnPrintProcessor)(HANDLE, LPWSTR); +typedef LPMONITOREX(WINAPI *PInitializePrintMonitor)(PWSTR); +typedef LPMONITOR2(WINAPI *PInitializePrintMonitor2)(PMONITORINIT, PHANDLE); // Structures /** @@ -141,6 +143,21 @@ PVOID pSpecificHandle; } LOCAL_HANDLE, *PLOCAL_HANDLE; + +/** + * Describes a Print Monitor. + */ +typedef struct _LOCAL_PRINT_MONITOR +{ + LIST_ENTRY Entry; + PWSTR pwszName; /** Name of the Print Monitor as read from the registry. */ + PWSTR pwszFileName; /** DLL File Name of the Print Monitor. */ + BOOL bIsLevel2; /** Whether this Print Monitor supplies an InitializePrintMonitor2 API (preferred) instead of InitializePrintMonitor. */ + PVOID pMonitor; /** For bIsLevel2 == TRUE: LPMONITOR2 pointer returned by InitializePrintMonitor2. + For bIsLevel2 == FALSE: LPMONITOREX pointer returned by InitializePrintMonitor. */ + HANDLE hMonitor; /** Only used when bIsLevel2 == TRUE: Handle returned by InitializePrintMonitor2. */ +} +LOCAL_PRINT_MONITOR, *PLOCAL_PRINT_MONITOR; /** * Describes the header of a print job serialized into a shadow file (.SHD) @@ -184,7 +201,7 @@ // jobs.c extern SKIPLIST GlobalJobList; BOOL GetNextJobID(PDWORD dwJobID); -void InitializeGlobalJobList(); +BOOL InitializeGlobalJobList(); void InitializePrinterJobList(PLOCAL_PRINTER pPrinter); BOOL WINAPI LocalAddJob(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded); BOOL WINAPI LocalEnumJobs(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned); @@ -196,14 +213,23 @@ // main.c extern const WCHAR wszCurrentEnvironment[]; +extern const DWORD cbCurrentEnvironment; extern const WCHAR wszDefaultDocumentName[]; extern const WCHAR* wszPrintProviderInfo[3]; extern WCHAR wszSpoolDirectory[MAX_PATH]; extern DWORD cchSpoolDirectory; +// monitors.c +extern LIST_ENTRY PrintMonitorList; +BOOL InitializePrintMonitorList(); +BOOL WINAPI LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned); + +// ports.c +BOOL WINAPI LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned); + // printers.c extern SKIPLIST PrinterList; -void InitializePrinterList(); +BOOL InitializePrinterList(); BOOL WINAPI LocalEnumPrinters(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned); BOOL WINAPI LocalOpenPrinter(PWSTR lpPrinterName, HANDLE* phPrinter, PPRINTER_DEFAULTSW pDefault); DWORD WINAPI LocalStartDocPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo); @@ -216,7 +242,7 @@ // printprocessors.c BOOL FindDatatype(PLOCAL_PRINT_PROCESSOR pPrintProcessor, PWSTR pwszDatatype); PLOCAL_PRINT_PROCESSOR FindPrintProcessor(PWSTR pwszName); -void InitializePrintProcessorList(); +BOOL InitializePrintProcessorList(); BOOL WINAPI LocalEnumPrintProcessorDatatypes(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned); BOOL WINAPI LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned); BOOL WINAPI LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded); Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -33,18 +33,18 @@ * The list is searchable by name and returns information about the printers, including their job queues. * During this process, the job queues are also initialized. */ -void +BOOL InitializePrinterList() { const WCHAR wszPrintersKey[] = L"SYSTEM\\CurrentControlSet\\Control\\Print\\Printers"; DWORD cbData; DWORD cchPrinterName; + DWORD dwErrorCode; DWORD dwSubKeys; DWORD i; HKEY hKey = NULL; HKEY hSubKey = NULL; - LONG lStatus; PLOCAL_PRINTER pPrinter = NULL; PLOCAL_PRINT_PROCESSOR pPrintProcessor; PWSTR pwszPrintProcessor = NULL; @@ -54,18 +54,18 @@ InitializeSkiplist(&PrinterList, DllAllocSplMem, _PrinterListCompareRoutine, (PSKIPLIST_FREE_ROUTINE)DllFreeSplMem); // Open our printers registry key. Each subkey is a local printer there. - lStatus = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszPrintersKey, 0, KEY_READ, &hKey); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegOpenKeyExW failed with status %ld!\n", lStatus); + dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszPrintersKey, 0, KEY_READ, &hKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode); goto Cleanup; } // Get the number of subkeys. - lStatus = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegQueryInfoKeyW failed with status %ld!\n", lStatus); + dwErrorCode = (DWORD)RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode); goto Cleanup; } @@ -105,23 +105,23 @@ // Get the name of this printer. cchPrinterName = _countof(wszPrinterName); - lStatus = RegEnumKeyExW(hKey, i, wszPrinterName, &cchPrinterName, NULL, NULL, NULL, NULL); - if (lStatus == ERROR_MORE_DATA) + dwErrorCode = (DWORD)RegEnumKeyExW(hKey, i, wszPrinterName, &cchPrinterName, NULL, NULL, NULL, NULL); + if (dwErrorCode == ERROR_MORE_DATA) { // This printer name exceeds the maximum length and is invalid. continue; } - else if (lStatus != ERROR_SUCCESS) - { - ERR("RegEnumKeyExW failed for iteration %lu with status %ld!\n", i, lStatus); + else if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegEnumKeyExW failed for iteration %lu with status %lu!\n", i, dwErrorCode); continue; } // Open this Printer's registry key. - lStatus = RegOpenKeyExW(hKey, wszPrinterName, 0, KEY_READ, &hSubKey); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegOpenKeyExW failed for Printer \"%S\" with status %ld!\n", wszPrinterName, lStatus); + dwErrorCode = (DWORD)RegOpenKeyExW(hKey, wszPrinterName, 0, KEY_READ, &hSubKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed for Printer \"%S\" with status %lu!\n", wszPrinterName, dwErrorCode); continue; } @@ -142,6 +142,7 @@ pPrinter = DllAllocSplMem(sizeof(LOCAL_PRINTER)); if (!pPrinter) { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); goto Cleanup; } @@ -174,28 +175,28 @@ // Get the default DevMode. cbData = sizeof(DEVMODEW); - lStatus = RegQueryValueExW(hSubKey, L"Default DevMode", NULL, NULL, (PBYTE)&pPrinter->DefaultDevMode, &cbData); - if (lStatus != ERROR_SUCCESS || cbData != sizeof(DEVMODEW)) - { - ERR("Couldn't query a valid DevMode for Printer \"%S\", status is %ld, cbData is %lu!\n", wszPrinterName, lStatus, cbData); + dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Default DevMode", NULL, NULL, (PBYTE)&pPrinter->DefaultDevMode, &cbData); + if (dwErrorCode != ERROR_SUCCESS || cbData != sizeof(DEVMODEW)) + { + ERR("Couldn't query a valid DevMode for Printer \"%S\", status is %lu, cbData is %lu!\n", wszPrinterName, dwErrorCode, cbData); continue; } // Get the Attributes. cbData = sizeof(DWORD); - lStatus = RegQueryValueExW(hSubKey, L"Attributes", NULL, NULL, (PBYTE)&pPrinter->dwAttributes, &cbData); - if (lStatus != ERROR_SUCCESS) - { - ERR("Couldn't query Attributes for Printer \"%S\", status is %ld!\n", wszPrinterName, lStatus); + dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Attributes", NULL, NULL, (PBYTE)&pPrinter->dwAttributes, &cbData); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("Couldn't query Attributes for Printer \"%S\", status is %lu!\n", wszPrinterName, dwErrorCode); continue; } // Get the Status. cbData = sizeof(DWORD); - lStatus = RegQueryValueExW(hSubKey, L"Status", NULL, NULL, (PBYTE)&pPrinter->dwStatus, &cbData); - if (lStatus != ERROR_SUCCESS) - { - ERR("Couldn't query Status for Printer \"%S\", status is %ld!\n", wszPrinterName, lStatus); + dwErrorCode = (DWORD)RegQueryValueExW(hSubKey, L"Status", NULL, NULL, (PBYTE)&pPrinter->dwStatus, &cbData); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("Couldn't query Status for Printer \"%S\", status is %lu!\n", wszPrinterName, dwErrorCode); continue; } @@ -209,6 +210,8 @@ // Don't let the cleanup routines free this. pPrinter = NULL; } + + dwErrorCode = ERROR_SUCCESS; Cleanup: // Inside the loop @@ -238,6 +241,9 @@ // Outside the loop if (hKey) RegCloseKey(hKey); + + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); } Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c URL:
http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
============================================================================== --- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c [iso-8859-1] (original) +++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c [iso-8859-1] Tue Jul 7 17:06:48 2015 @@ -111,7 +111,7 @@ * * Initializes a singly linked list of locally available Print Processors. */ -void +BOOL InitializePrintProcessorList() { DWORD cbDatatypes; @@ -119,15 +119,14 @@ DWORD cchPrintProcessorPath; DWORD cchMaxSubKey; DWORD cchPrintProcessorName; + DWORD dwErrorCode; DWORD dwSubKeys; DWORD i; HINSTANCE hinstPrintProcessor; HKEY hKey = NULL; HKEY hSubKey = NULL; HKEY hSubSubKey = NULL; - LONG lStatus; PLOCAL_PRINT_PROCESSOR pPrintProcessor = NULL; - PWSTR pwszPrintProcessorName = NULL; WCHAR wszFileName[MAX_PATH]; WCHAR wszPrintProcessorPath[MAX_PATH]; @@ -136,36 +135,32 @@ // Prepare the path to the Print Processor directory. if (!LocalGetPrintProcessorDirectory(NULL, NULL, 1, (PBYTE)wszPrintProcessorPath, sizeof(wszPrintProcessorPath), &cchPrintProcessorPath)) - goto Cleanup; + { + dwErrorCode = GetLastError(); + goto Cleanup; + } cchPrintProcessorPath /= sizeof(WCHAR); wszPrintProcessorPath[cchPrintProcessorPath++] = L'\\'; // Open the environment registry key. - if (_OpenEnvironment(NULL, &hKey) != ERROR_SUCCESS) + dwErrorCode = _OpenEnvironment(NULL, &hKey); + if (dwErrorCode != ERROR_SUCCESS) goto Cleanup; // Open the "Print Processors" subkey. - lStatus = RegOpenKeyExW(hKey, L"Print Processors", 0, KEY_READ, &hSubKey); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegOpenKeyExW failed with status %ld!\n", lStatus); + dwErrorCode = (DWORD)RegOpenKeyExW(hKey, L"Print Processors", 0, KEY_READ, &hSubKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode); goto Cleanup; } // Get the number of Print Processors and maximum sub key length. - lStatus = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwSubKeys, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegQueryInfoKeyW failed with status %ld!\n", lStatus); - goto Cleanup; - } - - // Allocate a temporary buffer for the Print Processor names. - pwszPrintProcessorName = DllAllocSplMem((cchMaxSubKey + 1) * sizeof(WCHAR)); - if (!pwszPrintProcessorName) - { - ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + dwErrorCode = (DWORD)RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwSubKeys, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode); goto Cleanup; } @@ -191,36 +186,54 @@ pPrintProcessor = NULL; } + // Create a new LOCAL_PRINT_PROCESSOR structure for it. + pPrintProcessor = DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR)); + if (!pPrintProcessor) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + + // Allocate memory for the Print Monitor Name. + pPrintProcessor->pwszName = DllAllocSplMem((cchMaxSubKey + 1) * sizeof(WCHAR)); + if (!pPrintProcessor->pwszName) + { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; + ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); + goto Cleanup; + } + // Get the name of this Print Processor. cchPrintProcessorName = cchMaxSubKey + 1; - lStatus = RegEnumKeyExW(hSubKey, i, pwszPrintProcessorName, &cchPrintProcessorName, NULL, NULL, NULL, NULL); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegEnumKeyExW failed with status %ld!\n", lStatus); + dwErrorCode = (DWORD)RegEnumKeyExW(hSubKey, i, pPrintProcessor->pwszName, &cchPrintProcessorName, NULL, NULL, NULL, NULL); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegEnumKeyExW failed with status %ld!\n", dwErrorCode); continue; } // Open this Print Processor's registry key. - lStatus = RegOpenKeyExW(hSubKey, pwszPrintProcessorName, 0, KEY_READ, &hSubSubKey); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %ld!\n", pwszPrintProcessorName, lStatus); + dwErrorCode = (DWORD)RegOpenKeyExW(hSubKey, pPrintProcessor->pwszName, 0, KEY_READ, &hSubSubKey); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegOpenKeyExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor->pwszName, dwErrorCode); continue; } // Get the file name of the Print Processor. cbFileName = sizeof(wszFileName); - lStatus = RegQueryValueExW(hSubSubKey, L"Driver", NULL, NULL, (PBYTE)wszFileName, &cbFileName); - if (lStatus != ERROR_SUCCESS) - { - ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %ld!\n", pwszPrintProcessorName, lStatus); + dwErrorCode = (DWORD)RegQueryValueExW(hSubSubKey, L"Driver", NULL, NULL, (PBYTE)wszFileName, &cbFileName); + if (dwErrorCode != ERROR_SUCCESS) + { + ERR("RegQueryValueExW failed for Print Processor \"%S\" with status %lu!\n", pPrintProcessor->pwszName, dwErrorCode); continue; } // Verify that our buffer is large enough. if (cchPrintProcessorPath + cbFileName / sizeof(WCHAR) > MAX_PATH) { - ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName, pwszPrintProcessorName); + ERR("Print Processor directory \"%S\" for Print Processor \"%S\" is too long!\n", wszFileName, pPrintProcessor->pwszName); continue; } @@ -229,15 +242,11 @@ // Try to load it. hinstPrintProcessor = LoadLibraryW(wszPrintProcessorPath); - if (lStatus != ERROR_SUCCESS) + if (!hinstPrintProcessor) { ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", wszPrintProcessorPath, GetLastError()); continue; } - - // Create a new LOCAL_PRINT_PROCESSOR structure for it. - pPrintProcessor = DllAllocSplMem(sizeof(LOCAL_PRINT_PROCESSOR)); - pPrintProcessor->pwszName = AllocSplStr(pwszPrintProcessorName); // Get and verify all its function pointers. pPrintProcessor->pfnClosePrintProcessor = (PClosePrintProcessor)GetProcAddress(hinstPrintProcessor, "ClosePrintProcessor"); @@ -287,6 +296,7 @@ pPrintProcessor->pDatatypesInfo1 = DllAllocSplMem(cbDatatypes); if (!pPrintProcessor->pDatatypesInfo1) { + dwErrorCode = ERROR_NOT_ENOUGH_MEMORY; ERR("DllAllocSplMem failed with error %lu!\n", GetLastError()); goto Cleanup; } @@ -303,6 +313,8 @@ // Don't let the cleanup routines free this. pPrintProcessor = NULL; } + + dwErrorCode = ERROR_SUCCESS; Cleanup: // Inside the loop @@ -321,14 +333,14 @@ } // Outside the loop - if (pwszPrintProcessorName) - DllFreeSplStr(pwszPrintProcessorName); - if (hSubKey) RegCloseKey(hSubKey); if (hKey) RegCloseKey(hKey); + + SetLastError(dwErrorCode); + return (dwErrorCode == ERROR_SUCCESS); } /**
9 years, 5 months
1
0
0
0
← Newer
1
...
18
19
20
21
22
23
24
25
26
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
Results per page:
10
25
50
100
200