2008-02-17 07:38:48 +00:00
|
|
|
{
|
|
|
|
simpleform.pas
|
|
|
|
|
2008-02-24 13:00:13 +00:00
|
|
|
This example shows how to use the PasCocoa bindings to create a
|
|
|
|
NSAutoreleasePool, initialize the application global variable, create
|
|
|
|
a simple window without contents and attach a close handler to it that
|
|
|
|
exits the application.
|
2008-02-17 07:38:48 +00:00
|
|
|
|
|
|
|
Compilation of this example requires the following options:
|
|
|
|
-k-framework -kcocoa -k-lobjc
|
|
|
|
|
|
|
|
This example project is released under public domain
|
|
|
|
|
|
|
|
AUTHORS: Felipe Monteiro de Carvalho
|
|
|
|
}
|
|
|
|
program simplewindow;
|
|
|
|
|
2008-03-04 09:16:58 +00:00
|
|
|
{$ifdef fpc}{$mode delphi}{$endif}
|
2008-02-17 07:38:48 +00:00
|
|
|
|
|
|
|
uses
|
|
|
|
objc, ctypes, FPCMacOSAll, AppKit, Foundation;
|
|
|
|
|
|
|
|
const
|
2008-03-02 02:17:37 +00:00
|
|
|
Str_Window_Title = 'This is the title';
|
|
|
|
Str_Window_Message = 'This is the message';
|
2008-02-17 07:38:48 +00:00
|
|
|
var
|
|
|
|
{ classes }
|
|
|
|
pool: NSAutoreleasePool;
|
|
|
|
MainWindow: NSWindow;
|
2008-03-02 02:17:37 +00:00
|
|
|
MainWindowView: NSView;
|
|
|
|
TextField: NSTextField;
|
2008-02-17 07:38:48 +00:00
|
|
|
{ strings }
|
|
|
|
CFTitle, CFMessage: CFStringRef;
|
|
|
|
{ sizes }
|
2008-03-02 02:17:37 +00:00
|
|
|
MainWindowRect, TextFieldRect: NSRect;
|
2008-02-17 07:38:48 +00:00
|
|
|
begin
|
2008-03-02 02:17:37 +00:00
|
|
|
{ Creates a AutoreleasePool for this thread. Every thread must have one }
|
2008-02-17 07:38:48 +00:00
|
|
|
pool := NSAutoreleasePool.Create;
|
|
|
|
|
2008-03-02 02:17:37 +00:00
|
|
|
{ Creates the application NSApp object }
|
2008-02-17 07:38:48 +00:00
|
|
|
NSApp := NSApplication.sharedApplication;
|
|
|
|
|
2008-03-02 02:17:37 +00:00
|
|
|
{ Creates a simple window }
|
2008-02-17 07:38:48 +00:00
|
|
|
MainWindowRect.origin.x := 300.0;
|
|
|
|
MainWindowRect.origin.y := 300.0;
|
|
|
|
MainWindowRect.size.width := 300.0;
|
|
|
|
MainWindowRect.size.height := 500.0;
|
|
|
|
|
2008-05-09 22:56:59 +00:00
|
|
|
MainWindow := NSWindow.initWithContentRect_styleMask_backing_defer(MainWindowRect,
|
2008-02-17 07:38:48 +00:00
|
|
|
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
|
2008-05-09 22:56:59 +00:00
|
|
|
NSBackingStoreBuffered, LongBool(NO));
|
2008-03-02 02:17:37 +00:00
|
|
|
|
|
|
|
{ Initializes the title of the window }
|
|
|
|
|
|
|
|
CFTitle := CFStringCreateWithPascalString(nil, Str_Window_Title, kCFStringEncodingUTF8);
|
|
|
|
MainWindow.setTitle(CFTitle);
|
|
|
|
|
|
|
|
{ Adds a NSTextField with a string }
|
2008-03-04 09:16:58 +00:00
|
|
|
|
|
|
|
CFMessage := CFStringCreateWithPascalString(nil, Str_Window_Message, kCFStringEncodingUTF8);
|
2008-03-02 02:17:37 +00:00
|
|
|
TextFieldRect.origin.x := 0.0;
|
2008-03-04 09:16:58 +00:00
|
|
|
TextFieldRect.origin.y := 200.0;
|
2008-03-02 02:17:37 +00:00
|
|
|
TextFieldRect.size.width := 300.0;
|
2008-03-04 09:16:58 +00:00
|
|
|
TextFieldRect.size.height := 100.0;
|
2008-03-02 02:17:37 +00:00
|
|
|
TextField := NSTextField.initWithFrame(TextFieldRect);
|
2008-03-04 09:16:58 +00:00
|
|
|
TextField.setStringValue(CFMessage);
|
2008-03-02 02:17:37 +00:00
|
|
|
MainWindowView := NSView.CreateWithHandle(MainWindow.contentView);
|
2008-07-31 15:23:56 +00:00
|
|
|
MainWindowView.addSubview(TextField.Handle);
|
2008-03-02 02:17:37 +00:00
|
|
|
|
|
|
|
{ Put's the window on the front z-order }
|
|
|
|
|
2008-02-17 07:38:48 +00:00
|
|
|
MainWindow.orderFrontRegardless;
|
|
|
|
|
|
|
|
{ Enters main message loop }
|
|
|
|
|
|
|
|
NSApp.run;
|
|
|
|
|
2008-03-02 02:17:37 +00:00
|
|
|
{ Releases the AutoreleasePool for this thread }
|
2008-02-17 07:38:48 +00:00
|
|
|
pool.Free;
|
|
|
|
end.
|
|
|
|
|