2008-03-04 09:19:17 +00:00
|
|
|
{
|
|
|
|
statusitem.pas
|
|
|
|
|
|
|
|
This example shows how to create a window with several buttons which will
|
|
|
|
control a NSStatusItem (a menubar extras icon).
|
|
|
|
|
|
|
|
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 statusitem;
|
|
|
|
|
|
|
|
{$mode delphi}
|
|
|
|
|
2008-06-24 02:01:19 +00:00
|
|
|
{$linkframework Cocoa}
|
|
|
|
{$linklib objc}
|
|
|
|
|
2008-03-04 09:19:17 +00:00
|
|
|
uses
|
2008-09-29 00:47:50 +00:00
|
|
|
objc, ctypes, MacOSAll, AppKit, Foundation, controller, cocoa_pkg;
|
2008-03-04 09:19:17 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
Str_Window_Title = 'StatusItem example project';
|
|
|
|
Str_Show_Button = 'Show StatusItem';
|
2008-03-10 11:51:50 +00:00
|
|
|
Str_Hide_Button = 'Hide StatusItem';
|
2008-05-09 19:51:36 +00:00
|
|
|
Str_Close_Button = 'Exit Program';
|
2008-03-04 09:19:17 +00:00
|
|
|
begin
|
|
|
|
{ Creates the AutoreleasePool }
|
|
|
|
pool := NSAutoreleasePool.Create;
|
|
|
|
|
|
|
|
{ Creates the application NSApp object }
|
|
|
|
NSApp := NSApplication.sharedApplication;
|
|
|
|
|
|
|
|
{ Creates a simple window }
|
|
|
|
|
|
|
|
MainWindowRect.origin.x := 300.0;
|
|
|
|
MainWindowRect.origin.y := 300.0;
|
|
|
|
MainWindowRect.size.width := 300.0;
|
|
|
|
MainWindowRect.size.height := 500.0;
|
|
|
|
|
2008-05-09 19:51:36 +00:00
|
|
|
MainWindow := NSWindow.initWithContentRect_styleMask_backing_defer(MainWindowRect,
|
2008-03-04 09:19:17 +00:00
|
|
|
NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
|
2008-05-09 19:51:36 +00:00
|
|
|
NSBackingStoreBuffered, LongBool(NO));
|
2008-03-04 09:19:17 +00:00
|
|
|
MainWindowView := NSView.CreateWithHandle(MainWindow.contentView);
|
|
|
|
|
|
|
|
CFTitle := CFStringCreateWithPascalString(nil, Str_Window_Title, kCFStringEncodingUTF8);
|
|
|
|
MainWindow.setTitle(CFTitle);
|
|
|
|
|
2008-03-11 23:52:48 +00:00
|
|
|
{ Initializes the controller object }
|
2008-03-07 11:33:19 +00:00
|
|
|
|
2008-03-11 23:52:48 +00:00
|
|
|
myController := TMyController.Create();
|
2008-03-07 11:33:19 +00:00
|
|
|
|
2008-03-10 11:51:50 +00:00
|
|
|
{ Adds the buttons }
|
|
|
|
|
2008-03-12 01:29:11 +00:00
|
|
|
myController.CreateButton(MainWindowView, Str_Show_Button,
|
2008-03-10 11:51:50 +00:00
|
|
|
50.0, MainWindowRect.size.height - 50.0, 200.0, 25.0,
|
2008-03-11 23:52:48 +00:00
|
|
|
Str_doShowStatusItem, myController);
|
2008-03-10 11:51:50 +00:00
|
|
|
|
2008-03-12 01:29:11 +00:00
|
|
|
myController.CreateButton(MainWindowView, Str_Hide_Button,
|
2008-03-10 11:51:50 +00:00
|
|
|
50.0, MainWindowRect.size.height - 100.0, 200.0, 25.0,
|
2008-03-11 23:52:48 +00:00
|
|
|
Str_doHideStatusItem, myController);
|
2008-03-04 09:19:17 +00:00
|
|
|
|
2008-05-09 19:51:36 +00:00
|
|
|
myController.CreateButton(MainWindowView, Str_Close_Button,
|
|
|
|
50.0, MainWindowRect.size.height - 150.0, 200.0, 25.0,
|
|
|
|
Str_doClose, myController);
|
|
|
|
|
2008-03-04 09:19:17 +00:00
|
|
|
{ Enters main message loop }
|
|
|
|
|
|
|
|
MainWindow.orderFrontRegardless;
|
|
|
|
|
2008-06-06 01:32:06 +00:00
|
|
|
NSApp.setDelegate(myController.Handle);
|
2008-03-11 23:52:48 +00:00
|
|
|
|
2008-03-04 09:19:17 +00:00
|
|
|
NSApp.run;
|
|
|
|
|
|
|
|
{ Releases the AutoreleasePool }
|
|
|
|
pool.Free;
|
|
|
|
end.
|
|
|
|
|