-
Notifications
You must be signed in to change notification settings - Fork 851
Add CascadeWindows wrapper #1999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3027,6 +3027,73 @@ BOOLAPI GetCaretPos(POINT *OUTPUT); | |
| // @pyswig |ShowCaret|Shows the caret at its current position | ||
| BOOLAPI ShowCaret(HWND hWnd); // @pyparm <o PyHANDLE>|hWnd||Window that owns the caret, can be 0. | ||
|
|
||
| %{ | ||
| // @pyswig WORD|CascadeWindows|Cascade windows | ||
| static PyObject *PyCascadeWindows(PyObject *self, PyObject *args) | ||
| { | ||
| PyObject *hwndObject, *rectObject = Py_None, *childrenObject = Py_None; | ||
| UINT how = 0, childCount = 0; | ||
| RECT rect, *rectPtr = NULL; | ||
| HWND hwnd, *children = NULL; | ||
| WORD res = 0; | ||
| if (!PyArg_ParseTuple(args, "OI|OO:CascadeWindows", | ||
| &hwndObject, //@pyparm <o PyHANDLE>|hwnd||Window handle | ||
| &how, //@pyparm int|wHow||Cascade flag (win32con) | ||
| &rectObject, //@pyparm <o PyHANDLE>|rect||Rectangle area (can be None) | ||
| &childrenObject) //@pyparm <o PyHANDLE>|children||Tuple of child windows (can be None) | ||
| ) | ||
| return NULL; | ||
| if (!PyWinObject_AsHANDLE(hwndObject, (HANDLE*)&hwnd)) | ||
| return NULL; | ||
| // Parse out rectangle object | ||
| if (rectObject != Py_None) { | ||
| if (!PyArg_ParseTuple(rectObject, "llll", | ||
| &rect.left, &rect.top, &rect.right, &rect.bottom) | ||
| ) | ||
| return NULL; | ||
| rectPtr = ▭ | ||
| } | ||
|
|
||
| if (PyTuple_Check(childrenObject)) { | ||
| childCount = (UINT)(PyTuple_GET_SIZE(childrenObject)); | ||
| if (childCount) { | ||
| children = (HWND*)(malloc(sizeof(HWND) * childCount)); | ||
| if (!children) { | ||
| PyErr_NoMemory(); | ||
| return NULL; | ||
| } | ||
| for (UINT i = 0; i < childCount; ++i) { | ||
| if (!PyWinObject_AsHANDLE(PyTuple_GetItem(childrenObject, i), (HANDLE*)(&children[i]))) { | ||
| free(children); | ||
| return NULL; | ||
| } | ||
| } | ||
| } | ||
| } else if (childrenObject != Py_None) { | ||
| PyErr_SetString(PyExc_TypeError, "The child windows object is neither a tuple nor None"); | ||
| return NULL; | ||
| } | ||
| Py_BEGIN_ALLOW_THREADS; | ||
| res = CascadeWindows(hwnd, how, rectPtr, childCount, children); | ||
| Py_END_ALLOW_THREADS; | ||
| if (children) { | ||
| free(children); | ||
| } | ||
| if (!res) { | ||
| DWORD gle = GetLastError(); | ||
| // Only fail if GetLastError() != 0. In theory, there could be cases when function returns 0, | ||
| // but it's not a failure (there are no windows to cascade). | ||
| if (gle) { | ||
| PyWin_SetAPIError("CascadeWindows", gle); | ||
| return NULL; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume it is intentional that zero will be returned if GetLastError() returns zero, rather than an exception? (The docs on the api function aren't really that clear) - but maybe a comment makes sense? |
||
| } | ||
| } | ||
| return PyLong_FromLong(res); | ||
| } | ||
| %} | ||
| %native (CascadeWindows) PyCascadeWindows; | ||
|
|
||
|
|
||
| // @pyswig boolean|ShowWindow|Shows or hides a window and changes its state | ||
| BOOL ShowWindow( | ||
| HWND hWnd, // @pyparm int|hWnd||The handle to the window | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should null-check here?