Skip to content

Commit

Permalink
Merge pull request #692 from dart-windows/dart3
Browse files Browse the repository at this point in the history
Upgrade to support Dart 3
  • Loading branch information
timsneath committed May 7, 2023
2 parents 5312872 + 54f8315 commit 2581138
Show file tree
Hide file tree
Showing 32 changed files with 578 additions and 612 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A package that wraps some of the most common Win32 API calls using FFI to make
them accessible to Dart code without requiring a C compiler or the Windows SDK.
Part of the (Dart | Windows)[https://github.com/dart-windows] suite of Windows
Part of the [Dart | Windows](https://github.com/dart-windows) suite of Windows
packages.

[![pub package](https://img.shields.io/pub/v/win32.svg)](https://pub.dev/packages/win32)
Expand Down
4 changes: 3 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ linter:
comment_references: true
discarded_futures: true
directives_ordering: true
# invalid_case_patterns: true // Turn on when Dart 3 is stable
invalid_case_patterns: true
leading_newlines_in_multiline_strings: true
literal_only_boolean_expressions: true
no_default_cases: true
Expand All @@ -31,7 +31,9 @@ linter:
sort_child_properties_last: true
sort_unnamed_constructors_first: true
test_types_in_equals: true
type_literal_in_constant_pattern: true
unawaited_futures: true
unnecessary_breaks: true
unnecessary_lambdas: true
unnecessary_parenthesis: true
unnecessary_statements: true
Expand Down
3 changes: 2 additions & 1 deletion example/com_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

/// Return the current reference count.
Expand All @@ -21,7 +22,7 @@ int refCount(IUnknown unk) {
}

void main() {
final pTitle = TEXT('Dart Open File Dialog');
final pTitle = 'Dart Open File Dialog'.toNativeUtf16();

// Initialize COM
var hr = CoInitializeEx(
Expand Down
8 changes: 0 additions & 8 deletions example/customtitlebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,11 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);

free(sizeRect);
break;

case WM_ACTIVATE:
final titleBarRect = getTitlebarRect(hwnd);
InvalidateRect(hwnd, titleBarRect, FALSE);
free(titleBarRect);
break;

case WM_NCHITTEST:
// Let the default procedure handle resizing areas
Expand Down Expand Up @@ -434,7 +432,6 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {

case WM_PAINT:
paintWindow(hwnd);
break;

case WM_NCMOUSEMOVE:
final hoveredButton = GetWindowLongPtr(hwnd, GWLP_USERDATA);
Expand Down Expand Up @@ -470,7 +467,6 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {
free(titleBarRect);
free(cursorPoint);
}
break;

case WM_MOUSEMOVE:
final hoveredButton = GetWindowLongPtr(hwnd, GWLP_USERDATA);
Expand All @@ -481,7 +477,6 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {
free(titleBarRect);
SetWindowLongPtr(hwnd, GWLP_USERDATA, HoveredButton.none);
}
break;

case WM_NCLBUTTONDOWN:
// Clicks on buttons will be handled in WM_NCLBUTTONUP, but we still need
Expand All @@ -492,8 +487,6 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {
final hoveredButton = GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (hoveredButton != HoveredButton.none) return 0;

break;

case WM_NCLBUTTONUP:
final hoveredButton = GetWindowLongPtr(hwnd, GWLP_USERDATA);

Expand All @@ -510,7 +503,6 @@ int mainWindowProc(int hwnd, int msg, int wParam, int lParam) {
ShowWindow(hwnd, mode);
return 0;
}
break;

case WM_DESTROY:
PostQuitMessage(0);
Expand Down
2 changes: 0 additions & 2 deletions example/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ int mainWindowProc(int hWnd, int uMsg, int wParam, int lParam) {
ScrollWindow(hWnd, 0, -cyChar, rectScroll, rectScroll);
InvalidateRect(hWnd, nullptr, TRUE);

break;

case WM_PAINT:
final ps = calloc<PAINTSTRUCT>();
final hdc = BeginPaint(hWnd, ps);
Expand Down
4 changes: 0 additions & 4 deletions example/magnifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ int hostWndProc(int hWnd, int message, int wParam, int lParam) {
goPartialScreen();
}
}
break;

case WM_SYSCOMMAND:
if (GET_SC_WPARAM(wParam) == SC_MAXIMIZE) {
goFullScreen();
} else {
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

case WM_SIZE:
if (hwndMag != NULL) {
Expand All @@ -94,7 +91,6 @@ int hostWndProc(int hWnd, int message, int wParam, int lParam) {
magWindowRect.ref.bottom,
0);
}
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
Expand Down
3 changes: 0 additions & 3 deletions example/msgbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ void main() {
switch (result) {
case IDCANCEL:
print('Cancel pressed');
break;
case IDTRYAGAIN:
print('Try Again pressed');
break;
case IDCONTINUE:
print('Continue pressed');
break;
}
}
3 changes: 0 additions & 3 deletions example/notepad/notepad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ int mainWindowProc(int hwnd, int message, int wParam, int lParam) {
EnableMenuItem(wParam, IDM_EDIT_CUT, menuStyle);
EnableMenuItem(wParam, IDM_EDIT_COPY, menuStyle);
EnableMenuItem(wParam, IDM_EDIT_CLEAR, menuStyle);
break;

case 2: // Search menu
final menuStyle = hDlgModeless == NULL ? MF_ENABLED : MF_GRAYED;

EnableMenuItem(wParam, IDM_SEARCH_FIND, menuStyle);
EnableMenuItem(wParam, IDM_SEARCH_NEXT, menuStyle);
EnableMenuItem(wParam, IDM_SEARCH_REPLACE, menuStyle);
break;
}
return 0;

Expand Down Expand Up @@ -281,7 +279,6 @@ int dialogReturnProc(int hDlg, int msg, int wParam, int lParam) {
EndDialog(hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
Expand Down
12 changes: 0 additions & 12 deletions example/scroll.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,22 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {
// User clicked the left arrow.
case SB_LINELEFT:
si.ref.nPos -= 1;
break;

// User clicked the right arrow.
case SB_LINERIGHT:
si.ref.nPos += 1;
break;

// User clicked the scroll bar shaft left of the scroll box.
case SB_PAGELEFT:
si.ref.nPos -= si.ref.nPage;
break;

// User clicked the scroll bar shaft right of the scroll box.
case SB_PAGERIGHT:
si.ref.nPos += si.ref.nPage;
break;

// User dragged the scroll box.
case SB_THUMBTRACK:
si.ref.nPos = si.ref.nTrackPos;
break;

default:
break;
Expand Down Expand Up @@ -172,37 +167,30 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {
// User clicked the HOME keyboard key.
case SB_TOP:
si.ref.nPos = si.ref.nMin;
break;

// User clicked the END keyboard key.
case SB_BOTTOM:
si.ref.nPos = si.ref.nMax;
break;

// User clicked the top arrow.
case SB_LINEUP:
si.ref.nPos -= 1;
break;

// User clicked the bottom arrow.
case SB_LINEDOWN:
si.ref.nPos += 1;
break;

// User clicked the scroll bar shaft above the scroll box.
case SB_PAGEUP:
si.ref.nPos -= si.ref.nPage;
break;

// User clicked the scroll bar shaft below the scroll box.
case SB_PAGEDOWN:
si.ref.nPos += si.ref.nPage;
break;

// User dragged the scroll box.
case SB_THUMBTRACK:
si.ref.nPos = si.ref.nTrackPos;
break;

default:
break;
Expand Down
11 changes: 0 additions & 11 deletions example/snake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,13 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {
init(width, height);

free(rect);
break;

case WM_CLOSE:
isRunning = false;
break;

case WM_DESTROY:
KillTimer(hwnd, IDT_TIMER1);
isRunning = false;
break;

case WM_PAINT:
final ps = calloc<PAINTSTRUCT>();
Expand All @@ -489,7 +486,6 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {

free(rect);
free(ps);
break;

case WM_KEYDOWN:
{
Expand All @@ -499,31 +495,25 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {
direction.x = -1;
direction.y = 0;
}
break;
case VK_RIGHT:
if (direction.x != -1) {
direction.x = 1;
direction.y = 0;
}
break;
case VK_UP:
if (direction.y != 1) {
direction.x = 0;
direction.y = -1;
}
break;
case VK_DOWN:
if (direction.y != -1) {
direction.x = 0;
direction.y = 1;
}
break;
case VK_ESCAPE:
isRunning = false;
break;
}
}
break;

case WM_TIMER:
{
Expand All @@ -538,7 +528,6 @@ int mainWindowProc(int hwnd, int uMsg, int wParam, int lParam) {
return 0;
}
}
break;

default:
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
Expand Down
5 changes: 0 additions & 5 deletions example/spellcheck.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ void main(List<String> args) {
switch (error.correctiveAction) {
case CORRECTIVE_ACTION.DELETE:
print(' - delete');
break;

case CORRECTIVE_ACTION.NONE:
print('\n');
break;

case CORRECTIVE_ACTION.REPLACE:
final replacment = error.replacement;
print(' - replace with "${replacment.toDartString()}"');
WindowsDeleteString(replacment.address);
break;

case CORRECTIVE_ACTION.GET_SUGGESTIONS:
print(' - suggestions:');
Expand All @@ -99,8 +96,6 @@ void main(List<String> args) {
print('\t${suggestionPtr.value.toDartString()}');
WindowsDeleteString(suggestionPtr.value.address);
}

break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/sysinfo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ String getComputerName() {
Object getRegistryValue(int key, String subKey, String valueName) {
late Object dataValue;

final subKeyPtr = TEXT(subKey);
final valueNamePtr = TEXT(valueName);
final subKeyPtr = subKey.toNativeUtf16();
final valueNamePtr = valueName.toNativeUtf16();
final openKeyPtr = calloc<HANDLE>();
final dataType = calloc<DWORD>();

Expand Down
Loading

0 comments on commit 2581138

Please sign in to comment.