Skip to content

Commit 030bf99

Browse files
feat: Implement display popups
1 parent 0872794 commit 030bf99

8 files changed

Lines changed: 80 additions & 1 deletion

File tree

flutter-lib/lib/src/gen/display.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:json_annotation/json_annotation.dart';
2+
import 'menu.dart';
23
import 'shell.dart';
34

45
part 'display.g.dart';
@@ -8,6 +9,7 @@ class VDisplay {
89
String? swt;
910
int? id;
1011
List<VShell>? shells;
12+
List<VMenu>? popups;
1113

1214
VDisplay();
1315

flutter-lib/lib/src/gen/display.g.dart

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flutter-lib/lib/src/impl/display_evolve.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class _DisplaySwtState extends State<DisplaySwt> {
104104

105105
return Stack(children: [
106106
for (final s in mainShells) Positioned.fill(child: gen.mapWidgetFromValue(s)),
107+
for (final popup in (_display.popups ?? []))
108+
Positioned.fill(child: gen.mapWidgetFromValue(popup)),
107109
if (dialogShells.any(_isModal))
108110
Positioned.fill(
109111
child: ColoredBox(

swt_native/src/macos/java/org/eclipse/swt/widgets/DartMenu.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ public void setLocation(int x, int y) {
884884
this.x = x;
885885
this.y = y;
886886
hasLocation = true;
887+
if (location == null || location.x != x || location.y != y) {
888+
location = new Point(x, y);
889+
dirty();
890+
}
887891
}
888892

889893
/**

swt_native/src/main/java/org/eclipse/swt/widgets/ControlHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static Point toDisplay(DartControl dartControl, int x, int y) {
2525
if (ancestor != null) {
2626
return ancestor.toDisplay(x + offset[0], y + offset[1]);
2727
}
28-
return dartControl.display.map(dartControl.getApi(), null, x, y);
28+
return new Point(x + offset[0], y + offset[1]);
2929
}
3030

3131
static Point toControl(DartControl dartControl, int x, int y) {

swt_native/src/web/java/org/eclipse/swt/widgets/DartDisplay.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ void addPopup(Menu menu) {
488488
popups = newPopups;
489489
}
490490
popups[index] = menu;
491+
if (displayBridge != null) {
492+
displayBridge.sendDisplayUpdate(this);
493+
}
491494
}
492495

493496
void addSkinnableWidget(Widget widget) {
@@ -985,6 +988,20 @@ public static Display findDisplay(Thread thread) {
985988
*/
986989
public Shell getActiveShell() {
987990
checkDevice();
991+
Control focus = getFocusControl();
992+
if (focus != null && !focus.isDisposed()) {
993+
Shell shell = focus.getShell();
994+
if (shell != null && !shell.isDisposed() && shell.getVisible()) {
995+
return shell;
996+
}
997+
}
998+
Shell[] currentShells = getShells();
999+
for (int i = currentShells.length - 1; i >= 0; i--) {
1000+
Shell shell = currentShells[i];
1001+
if (shell != null && !shell.isDisposed() && shell.getVisible()) {
1002+
return shell;
1003+
}
1004+
}
9881005
return null;
9891006
}
9901007

@@ -2684,6 +2701,9 @@ void removePopup(Menu menu) {
26842701
for (int i = 0; i < popups.length; i++) {
26852702
if (popups[i] == menu) {
26862703
popups[i] = null;
2704+
if (displayBridge != null) {
2705+
displayBridge.sendDisplayUpdate(this);
2706+
}
26872707
return;
26882708
}
26892709
}

swt_native/src/web/java/org/eclipse/swt/widgets/DartMenu.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ public void setLocation(int x, int y) {
884884
this.x = x;
885885
this.y = y;
886886
hasLocation = true;
887+
if (location == null || location.x != x || location.y != y) {
888+
location = new Point(x, y);
889+
dirty();
890+
}
887891
}
888892

889893
/**
@@ -968,6 +972,27 @@ public void setVisible(boolean visible) {
968972
checkWidget();
969973
if ((getApi().style & (SWT.BAR | SWT.DROP_DOWN)) != 0)
970974
return;
975+
if (visible) {
976+
if (!hasLocation) {
977+
Point menuLocation = display.getCursorLocation();
978+
if (menuLocation == null || (menuLocation.x == 0 && menuLocation.y == 0)) {
979+
Control owner = findOwnerControl();
980+
if (owner != null && !owner.isDisposed()) {
981+
Point ownerSize = owner.getSize();
982+
int yOffset = ownerSize != null ? ownerSize.y : 0;
983+
menuLocation = owner.toDisplay(0, yOffset);
984+
}
985+
}
986+
if (menuLocation != null) {
987+
x = menuLocation.x;
988+
y = menuLocation.y;
989+
location = menuLocation;
990+
hasLocation = true;
991+
dirty();
992+
}
993+
}
994+
hasLocation = false;
995+
}
971996
this.visible = newValue;
972997
if (visible) {
973998
((DartDisplay) display.getImpl()).addPopup(this.getApi());

swt_native/src/web/java/org/eclipse/swt/widgets/VDisplay.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class VDisplay {
1313
public long id;
1414
public String swt;
1515
public Shell[] shells;
16+
public Menu[] popups;
1617

1718
protected VDisplay() {
1819
}
@@ -29,6 +30,16 @@ public static VDisplay of(DartDisplay display) {
2930
}
3031
}
3132
v.shells = visible.toArray(Shell[]::new);
33+
Menu[] displayPopups = display.popups;
34+
ArrayList<Menu> popupList = new ArrayList<>();
35+
if (displayPopups != null) {
36+
for (Menu menu : displayPopups) {
37+
if (menu != null && !menu.isDisposed()) {
38+
popupList.add(menu);
39+
}
40+
}
41+
}
42+
v.popups = popupList.toArray(Menu[]::new);
3243
return v;
3344
}
3445

@@ -66,6 +77,17 @@ public static void write(JsonWriter writer, VDisplay v) {
6677
}
6778
writer.writeByte((byte) ']');
6879
}
80+
writer.writeAscii(",\"popups\":");
81+
if (v.popups == null || v.popups.length == 0) {
82+
writer.writeAscii("[]");
83+
} else {
84+
writer.writeByte((byte) '[');
85+
for (int i = 0; i < v.popups.length; i++) {
86+
if (i > 0) writer.writeByte((byte) ',');
87+
VMenu.MenuJson.write(writer, v.popups[i]);
88+
}
89+
writer.writeByte((byte) ']');
90+
}
6991
writer.writeByte((byte) '}');
7092
}
7193
}

0 commit comments

Comments
 (0)