Skip to content

Review EM_* message correctness#1234

Merged
RussKie merged 2 commits intodotnet:masterfrom
RussKie:Review_791
Jun 28, 2019
Merged

Review EM_* message correctness#1234
RussKie merged 2 commits intodotnet:masterfrom
RussKie:Review_791

Conversation

@RussKie
Copy link
Contributor

@RussKie RussKie commented Jun 26, 2019

Proposed changes

Fixes #994

@RussKie RussKie requested a review from a team as a code owner June 26, 2019 07:57
@RussKie RussKie requested review from JeremyKuhne and sharwell June 26, 2019 07:57
@RussKie
Copy link
Contributor Author

RussKie commented Jun 26, 2019

/cc: @hughbe

@hughbe
Copy link
Contributor

hughbe commented Jun 26, 2019

I'm so sorry you had to do this!

@RussKie
Copy link
Contributor Author

RussKie commented Jun 26, 2019

Apologies accepted 🤝 😃

It would be great if you could strive for smaller and targeted PRs in the future.

@weltkante
Copy link
Contributor

wow, its really unfortunate that the windows header files #define the same macro name with two different values! (richedit.h vs. winuser.h)

You might want to add some comments to the definition class to make sure these mistakes are not repeated

@RussKie
Copy link
Contributor Author

RussKie commented Jun 26, 2019

You might want to add some comments to the definition class to make sure these mistakes are not repeated

Please feel free to add comments where you feel appropriate.

@weltkante
Copy link
Contributor

@RussKie sorry having to ask, but how do you want me to do that? Comment on the PR with the "suggested change" function? Separate PR after this is merged? Some other way to add changes to a not-yet-merged PR I don't know of?

@RussKie
Copy link
Contributor Author

RussKie commented Jun 26, 2019

Comment on the PR with the "suggested change"

That will work.

Everyone is welcome to review and comment on all submissions.

@RussKie
Copy link
Contributor Author

RussKie commented Jun 26, 2019

@Olina-Zhang I've run the same code as provided in #994 and it appears to be working:
image

The different value is probably due to the default font change (#656).

Copy link
Member

@JeremyKuhne JeremyKuhne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the current schedule I don't think you need to address my comment for 3.0 as I'm only 99% sure. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These first four EM_GETLIMITTEXT , EM_POSFROMCHAR, EM_CHARFROMPOS, and EM_SCROLLCARET are a little odd. The "normal" definitions should work with the RichEdit control from what the headers/docs seem to indicate. It may be safer and less confusing to remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 These existed in the original definition:
image

Their values (as defined in richedit.h) are different from those defined in winuser.h (thanks @weltkante for the pointers). Though looking at the definitions in richedit.h the messages are conditionally defined:

#ifndef EM_GETLIMITTEXT
#define EM_GETLIMITTEXT 		(WM_USER + 37)
#endif

#ifndef EM_POSFROMCHAR	
#define EM_POSFROMCHAR			(WM_USER + 38)
#define EM_CHARFROMPOS			(WM_USER + 39)
#endif

#ifndef EM_SCROLLCARET
#define EM_SCROLLCARET			(WM_USER + 49)
#endif

Do you think it is safe to remove these four messages?
How can we test (I'm outside my depth here)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #ifndef is probably just there to suppress macro redefinition warnings. Depending on which version is imported first the RTF messages may be visible to C/C++ code. However I don't know if its even possible to import richedit.h without winuser.h - when I try to import richedit.h as the only header VS intellisense still says its using the version from winuser.h - so it may be the case that those particular conflicting messages never actually are used in C/C++ code. In this case it would be safe to remove I think.

I'll have another look and try to verify the #include order to make sure whether it is possible to use the RTF version at all in C/C++

Copy link
Contributor

@weltkante weltkante Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can verify that its impossible to include richedit.h before winuser.h in the windows 10 headers because richedit.h includes winuser.h indirectly.

1>------ Rebuild All started: Project: TestProject, Configuration: Debug Win32 ------
1>test.cpp
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\Richedit.h
1>Note: including file:  C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared\wtypes.h
1>Note: including file:   c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\rpc.h
1>Note: including file:    C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\windows.h
1>Note: including file:     C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\winuser.h

Therefore C/C++ code will never see the RTF-specific conflicting messages due to the #ifndef never being true.

I think its safe to drop these constants from WinForms if native code never can use them short of redefining the constant under another name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks heaps for the investigation!

@Olina-Zhang
Copy link
Member

@RussKie, we will verify issue #994 when fixed .net core build is ready.

RussKie added 2 commits June 28, 2019 10:12
As part the dotnet#791 refactor EM_* messages got mixed with RTB.EM_* messages
that led to an issue described in dotnet#994.

* Restore correct EM_ messagest
* Separate RTB.EM_ messages
* Update RichTextBox to use RTB.EM_* messages

Fixes dotnet#994
internal static partial class Interop
{
/// <summary>
/// RichTextBox Control Messages. Note that some messages have the same name but different value compared to normal Edit Control Messages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the second part of the comment isn't relevant now that you've removed the dupes. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is still relevant, since there dups in richedit.h; if someone decides to copy them they may be (more) aware.

@RussKie RussKie merged commit d6d6887 into dotnet:master Jun 28, 2019
@RussKie RussKie deleted the Review_791 branch June 28, 2019 01:04
@ghost ghost locked as resolved and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextBox and MaskedTextBox.GetPositionFromCharIndex() and MaskedTextBox.GetCharIndexFromPosition() methods return the incorrect values

6 participants