Skip to content

Commit

Permalink
macOS experiments: add NSToolbar to NSWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Dec 10, 2023
1 parent 9bf4da7 commit 3757232
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public static boolean isLoaded() {
public native static long getWindowPtr( Window window );

public native static void setWindowRoundedBorder( long windowPtr, float radius, float borderWidth, int borderColor );

public native static void setWindowToolbar( long windowPtr );
}
Binary file modified flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-arm64.dylib
100644 → 100755
Binary file not shown.
Binary file modified flatlaf-core/src/main/resources/com/formdev/flatlaf/natives/libflatlaf-macos-x86_64.dylib
100644 → 100755
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DemoFrame
setTitle( null );

// add gap to left side of toolbar
toolBar.add( Box.createHorizontalStrut( 70 ), 0 );
toolBar.add( Box.createHorizontalStrut( 80 ), 0 );
}

// enable full screen mode for this window (for Java 8 - 10; not necessary for Java 11+)
Expand Down Expand Up @@ -904,6 +904,54 @@ private void initComponents() {
buttonGroup1.add(radioButtonMenuItem3);
// JFormDesigner - End of component initialization //GEN-END:initComponents

backButton.addActionListener( e -> System.out.println( e ) );
backButton.addMouseListener( new MouseListener() {

@Override
public void mouseReleased( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m release" );
}

@Override
public void mousePressed( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m press" );
}

@Override
public void mouseExited( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m exit" );
}

@Override
public void mouseEntered( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m ent" );
}

@Override
public void mouseClicked( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m click" );
}
} );
backButton.addMouseMotionListener( new MouseMotionListener() {

@Override
public void mouseMoved( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m moved" );
}

@Override
public void mouseDragged( MouseEvent e ) {
// TODO Auto-generated method stub
System.out.println( "m drag" );
}
} );

// add "Users" button to menubar
FlatButton usersButton = new FlatButton();
usersButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/users.svg" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.formdev.flatlaf.fonts.jetbrains_mono.FlatJetBrainsMonoFont;
import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont;
import com.formdev.flatlaf.fonts.roboto_mono.FlatRobotoMonoFont;
import com.formdev.flatlaf.ui.FlatNativeMacLibrary;
import com.formdev.flatlaf.util.SystemInfo;

/**
Expand Down Expand Up @@ -117,6 +118,10 @@ public static void main( String[] args ) {
// show frame
frame.pack();
frame.setLocationRelativeTo( null );
if( SystemInfo.isMacOS && FlatNativeMacLibrary.isLoaded() ) {
long wp = FlatNativeMacLibrary.getWindowPtr( frame );
FlatNativeMacLibrary.setWindowToolbar( wp );
}
frame.setVisible( true );
} );
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions flatlaf-natives/flatlaf-natives-macos/src/main/objcpp/MacWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@

JNI_COCOA_EXIT()
}

extern "C"
JNIEXPORT void JNICALL Java_com_formdev_flatlaf_ui_FlatNativeMacLibrary_setWindowToolbar
( JNIEnv* env, jclass cls, jlong windowPtr )
{
if( windowPtr == 0 )
return;

JNI_COCOA_ENTER()

[FlatJNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
NSWindow* window = (NSWindow *) jlong_to_ptr( windowPtr );

NSLog( @"\n%@\n\n", [window.contentView.superview _subtreeDescription] );

NSToolbar* toolbar = [NSToolbar new];
window.toolbar = toolbar;

// TODO handle fullscreen

NSLog( @"\n%@\n\n", [window.contentView.superview _subtreeDescription] );
}];

JNI_COCOA_EXIT()
}

0 comments on commit 3757232

Please sign in to comment.