Skip to content

Commit 91c6bd0

Browse files
committed
[windows] Add isResizable, setResizable Methods
1 parent 71d13b7 commit 91c6bd0

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.1.0
22

3+
- Implemented `isResizable`, `setResizable` Methods.
4+
- Implemented `isClosable`, `setClosable` Methods.
35
- Removed `terminate` Method.
46

57
## 0.0.5

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ class MainFlutterWindow: NSWindow {
283283
| `setSize` | Resizes the window to `width` and `height`. | ✔️ | ✔️ | ✔️ |
284284
| `setMinimumSize` | Sets the minimum size of window to `width` and `height`. | ✔️ | ✔️ | ✔️ |
285285
| `setMaximumSize` | Sets the maximum size of window to `width` and `height`. | ✔️ | ✔️ | ✔️ |
286-
| `isResizable` | Returns `bool` - Whether the window can be manually resized by the user. | ✔️ | ✔️ | |
287-
| `setResizable` | Sets whether the window can be manually resized by the user. | ✔️ | ✔️ | |
286+
| `isResizable` | Returns `bool` - Whether the window can be manually resized by the user. | ✔️ | ✔️ | ✔️ |
287+
| `setResizable` | Sets whether the window can be manually resized by the user. | ✔️ | ✔️ | ✔️ |
288288
| `isMovable` | Returns `bool` - Whether the window can be moved by user. On Linux always returns `true`. || ✔️ ||
289289
| `setMovable` | Sets whether the window can be moved by user. On Linux does nothing. || ✔️ ||
290290
| `isMinimizable` | Returns `bool` - Whether the window can be manually minimized by the user. On Linux always returns `true`. || ✔️ | ✔️ |

windows/window_manager.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class WindowManager
6565
void WindowManager::SetSize(const flutter::EncodableMap &args);
6666
void WindowManager::SetMinimumSize(const flutter::EncodableMap &args);
6767
void WindowManager::SetMaximumSize(const flutter::EncodableMap &args);
68+
bool WindowManager::IsResizable();
69+
void WindowManager::SetResizable(const flutter::EncodableMap &args);
6870
bool WindowManager::IsMinimizable();
6971
void WindowManager::SetMinimizable(const flutter::EncodableMap &args);
7072
bool WindowManager::IsClosable();
@@ -391,16 +393,20 @@ void WindowManager::SetMaximumSize(const flutter::EncodableMap &args)
391393
}
392394
}
393395

394-
bool WindowManager::IsAlwaysOnTop()
396+
bool WindowManager::IsResizable()
395397
{
396-
DWORD dwExStyle = GetWindowLong(GetMainWindow(), GWL_EXSTYLE);
397-
return (dwExStyle & WS_EX_TOPMOST) != 0;
398+
HWND hWnd = GetMainWindow();
399+
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
400+
return (gwlStyle & WS_THICKFRAME) != 0;
398401
}
399402

400-
void WindowManager::SetAlwaysOnTop(const flutter::EncodableMap &args)
403+
void WindowManager::SetResizable(const flutter::EncodableMap &args)
401404
{
402-
bool isAlwaysOnTop = std::get<bool>(args.at(flutter::EncodableValue("isAlwaysOnTop")));
403-
SetWindowPos(GetMainWindow(), isAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
405+
HWND hWnd = GetMainWindow();
406+
bool isResizable = std::get<bool>(args.at(flutter::EncodableValue("isResizable")));
407+
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
408+
gwlStyle = isResizable ? gwlStyle | WS_THICKFRAME : gwlStyle & ~WS_THICKFRAME;
409+
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
404410
}
405411

406412
bool WindowManager::IsMinimizable()
@@ -418,6 +424,7 @@ void WindowManager::SetMinimizable(const flutter::EncodableMap &args)
418424
gwlStyle = isMinimizable ? gwlStyle | WS_MINIMIZEBOX : gwlStyle & ~WS_MINIMIZEBOX;
419425
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
420426
}
427+
421428
bool WindowManager::IsClosable()
422429
{
423430
HWND hWnd = GetMainWindow();
@@ -434,6 +441,18 @@ void WindowManager::SetClosable(const flutter::EncodableMap &args)
434441
SetClassLong(hWnd, GCL_STYLE, gclStyle);
435442
}
436443

444+
bool WindowManager::IsAlwaysOnTop()
445+
{
446+
DWORD dwExStyle = GetWindowLong(GetMainWindow(), GWL_EXSTYLE);
447+
return (dwExStyle & WS_EX_TOPMOST) != 0;
448+
}
449+
450+
void WindowManager::SetAlwaysOnTop(const flutter::EncodableMap &args)
451+
{
452+
bool isAlwaysOnTop = std::get<bool>(args.at(flutter::EncodableValue("isAlwaysOnTop")));
453+
SetWindowPos(GetMainWindow(), isAlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
454+
}
455+
437456
std::string WindowManager::GetTitle()
438457
{
439458
int const bufferSize = 1 + GetWindowTextLength(GetMainWindow());

windows/window_manager_plugin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ void WindowManagerPlugin::HandleMethodCall(const flutter::MethodCall<flutter::En
315315
window_manager->SetMaximumSize(args);
316316
result->Success(flutter::EncodableValue(true));
317317
}
318+
else if (method_name.compare("isResizable") == 0)
319+
{
320+
bool value = window_manager->IsResizable();
321+
result->Success(flutter::EncodableValue(value));
322+
}
323+
else if (method_name.compare("setResizable") == 0)
324+
{
325+
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments());
326+
window_manager->SetResizable(args);
327+
result->Success(flutter::EncodableValue(true));
328+
}
318329
else if (method_name.compare("isMinimizable") == 0)
319330
{
320331
bool value = window_manager->IsMinimizable();

0 commit comments

Comments
 (0)