You've already forked lazarus-ccr
Improves texteditor example
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@583 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -24,11 +24,11 @@ type
|
||||
constructor Create; override;
|
||||
procedure AddMethods; override;
|
||||
{ Objective-c Methods }
|
||||
class procedure doShowStatusitem(_self: objc.id; _cmd: objc.SEL; sender: objc.id); cdecl; static;
|
||||
class procedure doHideStatusitem(_self: objc.id; _cmd: objc.SEL; sender: objc.id); cdecl; static;
|
||||
class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; static;
|
||||
class procedure doShowStatusitem(_self: objc.id; _cmd: objc.SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure doHideStatusitem(_self: objc.id; _cmd: objc.SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
|
||||
_cmd: SEL; theApplication: objc.id): cbool; cdecl; static;
|
||||
_cmd: SEL; theApplication: objc.id): cbool; cdecl; //static;
|
||||
{ Other helper functions }
|
||||
function GetResourcesDir: string;
|
||||
function CreateButton(AView: NSView; ATitle: shortstring;
|
||||
|
4
bindings/pascocoa/examples/texteditor/applemenu.nib/classes.nib
generated
Normal file
4
bindings/pascocoa/examples/texteditor/applemenu.nib/classes.nib
generated
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
IBClasses = ({CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; });
|
||||
IBVersion = 1;
|
||||
}
|
21
bindings/pascocoa/examples/texteditor/applemenu.nib/info.nib
generated
Normal file
21
bindings/pascocoa/examples/texteditor/applemenu.nib/info.nib
generated
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>69 85 356 240 0 0 1280 778 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>29</key>
|
||||
<string>69 330 338 44 0 0 1280 778 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>446.1</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>29</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8S2167</string>
|
||||
</dict>
|
||||
</plist>
|
BIN
bindings/pascocoa/examples/texteditor/applemenu.nib/keyedobjects.nib
generated
Normal file
BIN
bindings/pascocoa/examples/texteditor/applemenu.nib/keyedobjects.nib
generated
Normal file
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
rm *.o
|
||||
rm *.ppu
|
||||
rm *.bak
|
||||
rm *.ppu
|
||||
rm *.o
|
||||
rm *.compiled
|
@ -27,7 +27,6 @@ type
|
||||
class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure doOpenFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure doSaveFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class procedure doSaveFileAs(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
|
||||
_cmd: SEL; theApplication: objc.id): cbool; cdecl; //static;
|
||||
end;
|
||||
@ -36,7 +35,6 @@ const
|
||||
Str_doClose = 'doClose:';
|
||||
Str_doOpenFile = 'doOpenFile:';
|
||||
Str_doSaveFile = 'doSaveFile:';
|
||||
Str_doSaveFileAs = 'doSaveFileAs:';
|
||||
Str_applicationShouldTerminateAfterLastWindowClosed = 'applicationShouldTerminateAfterLastWindowClosed:';
|
||||
|
||||
var
|
||||
@ -64,8 +62,7 @@ begin
|
||||
AddMethod(Str_doClose, 'v@:@', Pointer(doClose));
|
||||
AddMethod(Str_doOpenFile, 'v@:@', Pointer(doOpenFile));
|
||||
AddMethod(Str_doSaveFile, 'v@:@', Pointer(doSaveFile));
|
||||
AddMethod(Str_doSaveFileAs, 'v@:@', Pointer(doSaveFileAs));
|
||||
AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'b@:@',
|
||||
AddMethod(Str_applicationShouldTerminateAfterLastWindowClosed, 'B@:@',
|
||||
Pointer(applicationShouldTerminateAfterLastWindowClosed));
|
||||
end;
|
||||
|
||||
@ -123,12 +120,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TMyController.doSaveFileAs(_self: objc.id; _cmd: SEL;
|
||||
sender: objc.id); cdecl;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
class function TMyController.applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
|
||||
_cmd: SEL; theApplication: objc.id): cbool; cdecl;
|
||||
begin
|
||||
|
@ -19,6 +19,7 @@ else
|
||||
mkdir $appfolder/Contents
|
||||
mkdir $appfolder/Contents/MacOS
|
||||
mkdir $appfolder/Contents/Resources
|
||||
mkdir $appfolder/Contents/Resources/English.lproj
|
||||
#
|
||||
# Instead of copying executable into .app folder after each compile,
|
||||
# simply create a symbolic link to executable.
|
||||
@ -27,9 +28,10 @@ else
|
||||
cp imgOpen.png $appfolder/Contents/Resources/
|
||||
cp imgSave.png $appfolder/Contents/Resources/
|
||||
cp imgClose.png $appfolder/Contents/Resources/
|
||||
cp -r applemenu.nib $appfolder/Contents/Resources/English.lproj/
|
||||
#
|
||||
# Create PkgInfo file.
|
||||
echo "APPLMAG#" >$appfolder/Contents/PkgInfo
|
||||
echo "TXTEDIT#" >$appfolder/Contents/PkgInfo
|
||||
#
|
||||
# Create information property list file (Info.plist).
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>' >$plistfile
|
||||
@ -47,11 +49,13 @@ else
|
||||
echo ' <key>CFBundleInfoDictionaryVersion</key>' >>$plistfile
|
||||
echo ' <string>6.0</string>' >>$plistfile
|
||||
echo ' <key>CFBundlePackageType</key>' >>$plistfile
|
||||
echo ' <string>APPL</string>' >>$plistfile
|
||||
echo ' <string>EDIT</string>' >>$plistfile
|
||||
echo ' <key>CFBundleSignature</key>' >>$plistfile
|
||||
echo ' <string>MAG#</string>' >>$plistfile
|
||||
echo ' <string>TXT#</string>' >>$plistfile
|
||||
echo ' <key>CFBundleVersion</key>' >>$plistfile
|
||||
echo ' <string>1.0</string>' >>$plistfile
|
||||
echo ' <key>NSMainNibFile</key>' >>$plistfile
|
||||
echo ' <string>applemenu</string>' >>$plistfile
|
||||
echo '</dict>' >>$plistfile
|
||||
echo '</plist>' >>$plistfile
|
||||
fi
|
||||
|
@ -62,9 +62,9 @@ end;
|
||||
|
||||
constructor TMyModel.Create;
|
||||
begin
|
||||
LoadImages;
|
||||
|
||||
ResourcesDir := GetResourcesDir;
|
||||
|
||||
LoadImages;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -5,6 +5,7 @@ unit mytoolbar;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
MacOSAll, objc, appkit, foundation;
|
||||
|
||||
type
|
||||
@ -16,15 +17,14 @@ type
|
||||
{ Extra binding functions }
|
||||
constructor Create; override;
|
||||
procedure AddMethods; override;
|
||||
procedure AttachEventHandlers;
|
||||
{ Toolbar items }
|
||||
OpenToolbarItem, SaveToolbarItem, CloseToolbarItem: NSToolbarItem;
|
||||
{ Objective-c Methods }
|
||||
// class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static;
|
||||
class function toolbarAllowedItemIdentifiers(_self: objc.id;
|
||||
_cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl;// static;
|
||||
class function toolbarDefaultItemIdentifiers(_self: objc.id;
|
||||
_cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl;// static;
|
||||
class function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar
|
||||
(_self: objc.id; _cmd: SEL; toolbar: objc.id;
|
||||
itemIdentifier: CFStringRef; flag: CBOOL): objc.id; cdecl;// static;
|
||||
end;
|
||||
|
||||
const
|
||||
@ -34,6 +34,11 @@ const
|
||||
|
||||
var
|
||||
OpenToolbarItemIdentifier, SaveToolbarItemIdentifier, CloseToolbarItemIdentifier: CFStringRef;
|
||||
myToolbarController: TMyToolbarController;
|
||||
|
||||
function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar
|
||||
(_self: objc.id; _cmd: SEL; toolbar: objc.id;
|
||||
itemIdentifier: CFStringRef; flag: OBJC_BOOL): objc.id; cdecl;// static;
|
||||
|
||||
implementation
|
||||
|
||||
@ -54,14 +59,39 @@ begin
|
||||
OpenToolbarItemIdentifier := CFStringCreateWithPascalString(nil, 'OpenID', kCFStringEncodingUTF8);
|
||||
SaveToolbarItemIdentifier := CFStringCreateWithPascalString(nil, 'SaveID', kCFStringEncodingUTF8);
|
||||
CloseToolbarItemIdentifier := CFStringCreateWithPascalString(nil, 'CloseID', kCFStringEncodingUTF8);
|
||||
|
||||
{ Create toolbar items }
|
||||
OpenToolbarItem := NSToolbarItem.initWithItemIdentifier(OpenToolbarItemIdentifier);
|
||||
// [toolbarItem setLabel:@"Save"];
|
||||
// [toolbarItem setPaletteLabel:[toolbarItem label]];
|
||||
// [toolbarItem setToolTip:@"Save Your Passwords"];}
|
||||
OpenToolbarItem.setImage(myModel.imgOpen.Handle);
|
||||
|
||||
SaveToolbarItem := NSToolbarItem.initWithItemIdentifier(SaveToolbarItemIdentifier);
|
||||
SaveToolbarItem.setImage(myModel.imgSave.Handle);
|
||||
|
||||
CloseToolbarItem := NSToolbarItem.initWithItemIdentifier(CloseToolbarItemIdentifier);
|
||||
CloseToolbarItem.setImage(myModel.imgClose.Handle);
|
||||
end;
|
||||
|
||||
procedure TMyToolbarController.AddMethods;
|
||||
begin
|
||||
AddMethod(Str_toolbarAllowedItemIdentifiers, '@@:@', Pointer(toolbarAllowedItemIdentifiers));
|
||||
AddMethod(Str_toolbarDefaultItemIdentifiers, '@@:@', Pointer(toolbarDefaultItemIdentifiers));
|
||||
// AddMethod(Str_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar,
|
||||
// '@@:@@L', Pointer(toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar));
|
||||
AddMethod(Str_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar,
|
||||
'@@:@@c', @toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar);
|
||||
end;
|
||||
|
||||
procedure TMyToolbarController.AttachEventHandlers;
|
||||
begin
|
||||
OpenToolbarItem.setTarget(myController.Handle);
|
||||
OpenToolbarItem.setAction(sel_registerName(PChar('doOpenFile:')));
|
||||
|
||||
SaveToolbarItem.setTarget(myController.Handle);
|
||||
SaveToolbarItem.setAction(sel_registerName(PChar('doSaveFile:')));
|
||||
|
||||
CloseToolbarItem.setTarget(myController.Handle);
|
||||
CloseToolbarItem.setAction(sel_registerName(PChar('doClose:')));
|
||||
end;
|
||||
|
||||
class function TMyToolbarController.toolbarAllowedItemIdentifiers(_self: objc.id;
|
||||
@ -69,11 +99,14 @@ class function TMyToolbarController.toolbarAllowedItemIdentifiers(_self: objc.id
|
||||
var
|
||||
toolbarItems: array[0..4] of CFStringRef;
|
||||
begin
|
||||
WriteLn('OpenToolbarItemIdentifier: ', IntToHex(Cardinal(OpenToolbarItemIdentifier), 8));
|
||||
WriteLn('SaveToolbarItemIdentifier: ', IntToHex(Cardinal(SaveToolbarItemIdentifier), 8));
|
||||
WriteLn('NSToolbarSpaceItemIdentifier: ', IntToHex(Cardinal(NSToolbarSpaceItemIdentifier), 8));
|
||||
WriteLn('CloseToolbarItemIdentifier: ', IntToHex(Cardinal(CloseToolbarItemIdentifier), 8));
|
||||
toolbarItems[0] := OpenToolbarItemIdentifier;
|
||||
toolbarItems[1] := SaveToolbarItemIdentifier;
|
||||
// toolbarItems[2] := NSToolbarSpaceItemIdentifier;
|
||||
toolbarItems[2] := CloseToolbarItemIdentifier;
|
||||
toolbarItems[3] := nil;
|
||||
toolbarItems[2] := NSToolbarSpaceItemIdentifier;
|
||||
toolbarItems[3] := CloseToolbarItemIdentifier;
|
||||
toolbarItems[4] := nil;
|
||||
|
||||
Result := CFArrayCreate(nil, @toolbarItems[0], 4, nil);
|
||||
@ -85,48 +118,23 @@ begin
|
||||
Result := toolbarAllowedItemIdentifiers(_self, _cmd, toolbar);
|
||||
end;
|
||||
|
||||
class function TMyToolbarController.toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(_self: objc.id;
|
||||
function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(_self: objc.id;
|
||||
_cmd: SEL; toolbar: objc.id {NSToolbar}; itemIdentifier: CFStringRef;
|
||||
flag: CBOOL): objc.id {NSToolbarItem}; cdecl;
|
||||
var
|
||||
toolbarItem: NSToolbarItem;
|
||||
flag: OBJC_BOOL): objc.id {NSToolbarItem}; cdecl;
|
||||
begin
|
||||
WriteLn('toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar: ', IntToHex(Cardinal(itemIdentifier), 8));
|
||||
|
||||
with myToolbarController do
|
||||
begin
|
||||
if CFStringCompare(itemIdentifier, OpenToolbarItemIdentifier, kCFCompareCaseInsensitive) = kCFCompareEqualTo then
|
||||
begin
|
||||
toolbarItem := NSToolbarItem.initWithItemIdentifier(itemIdentifier);
|
||||
// [toolbarItem setLabel:@"Save"];
|
||||
// [toolbarItem setPaletteLabel:[toolbarItem label]];
|
||||
// [toolbarItem setToolTip:@"Save Your Passwords"];}
|
||||
toolbarItem.setImage(myModel.imgOpen.Handle);
|
||||
toolbarItem.setTarget(myController.Handle);
|
||||
toolbarItem.setAction(sel_registerName(PChar('doOpenFile:')));
|
||||
end
|
||||
Result := OpenToolbarItem.autorelease
|
||||
else if CFStringCompare(itemIdentifier, SaveToolbarItemIdentifier, kCFCompareCaseInsensitive) = kCFCompareEqualTo then
|
||||
begin
|
||||
toolbarItem := NSToolbarItem.initWithItemIdentifier(itemIdentifier);
|
||||
|
||||
toolbarItem.setImage(myModel.imgSave.Handle);
|
||||
toolbarItem.setTarget(myController.Handle);
|
||||
toolbarItem.setAction(sel_registerName(PChar('doSaveFile:')));
|
||||
end
|
||||
Result := SaveToolbarItem.autorelease
|
||||
else if CFStringCompare(itemIdentifier, CloseToolbarItemIdentifier, kCFCompareCaseInsensitive) = kCFCompareEqualTo then
|
||||
begin
|
||||
toolbarItem := NSToolbarItem.initWithItemIdentifier(itemIdentifier);
|
||||
|
||||
toolbarItem.setImage(myModel.imgClose.Handle);
|
||||
toolbarItem.setTarget(myController.Handle);
|
||||
toolbarItem.setAction(sel_registerName(PChar('doCloseFile:')));
|
||||
end
|
||||
Result := CloseToolbarItem.autorelease
|
||||
else
|
||||
begin
|
||||
Result := nil;
|
||||
Exit
|
||||
end;
|
||||
|
||||
Result := ToolbarItem.autorelease;
|
||||
{ ToolbarItem.Handle := 0;
|
||||
ToolbarItem.Free;}
|
||||
// Result := Result. [toolbarItem autorelease];
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -4,13 +4,14 @@
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="6"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
<ActiveEditorIndexAtStart Value="7"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
<Language Value=""/>
|
||||
<CharSet Value=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
@ -29,33 +30,213 @@
|
||||
<PackageName Value="cocoa_pkg"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="5">
|
||||
<Units Count="9">
|
||||
<Unit0>
|
||||
<Filename Value="texteditor.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="texteditor"/>
|
||||
<CursorPos X="15" Y="44"/>
|
||||
<TopLine Value="31"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="model.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="model"/>
|
||||
<CursorPos X="33" Y="63"/>
|
||||
<TopLine Value="48"/>
|
||||
<EditorIndex Value="5"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="view.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="view"/>
|
||||
<CursorPos X="28" Y="217"/>
|
||||
<TopLine Value="204"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="controller.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="controller"/>
|
||||
<CursorPos X="25" Y="30"/>
|
||||
<TopLine Value="19"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<UsageCount Value="31"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="mytoolbar"/>
|
||||
<CursorPos X="1" Y="106"/>
|
||||
<TopLine Value="97"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<UsageCount Value="26"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<Filename Value="../../../objc/objc.pas"/>
|
||||
<UnitName Value="objc"/>
|
||||
<CursorPos X="14" Y="48"/>
|
||||
<TopLine Value="29"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit5>
|
||||
<Unit6>
|
||||
<Filename Value="../../foundation/foundation.pas"/>
|
||||
<UnitName Value="foundation"/>
|
||||
<CursorPos X="30" Y="12"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="3"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit6>
|
||||
<Unit7>
|
||||
<Filename Value="../../appkit/NSToolbarItem.inc"/>
|
||||
<CursorPos X="49" Y="5"/>
|
||||
<TopLine Value="4"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit7>
|
||||
<Unit8>
|
||||
<Filename Value="../../appkit/appkit.pas"/>
|
||||
<UnitName Value="appkit"/>
|
||||
<CursorPos X="16" Y="12"/>
|
||||
<TopLine Value="1"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<UsageCount Value="12"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit8>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="73" Column="1" TopLine="61"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="74" Column="1" TopLine="62"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="75" Column="1" TopLine="63"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="76" Column="1" TopLine="64"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="78" Column="1" TopLine="66"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="72" Column="1" TopLine="67"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="74" Column="92" TopLine="61"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="8" Column="12" TopLine="1"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="126" Column="30" TopLine="115"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="21" Column="55" TopLine="2"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="101" Column="111" TopLine="92"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="75" Column="5" TopLine="52"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="101" Column="20" TopLine="90"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="102" Column="13" TopLine="89"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="65" Column="1" TopLine="58"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="20" Column="34" TopLine="8"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="mytoolbar.pas"/>
|
||||
<Caret Line="37" Column="22" TopLine="28"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="99" Column="12" TopLine="80"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="108" Column="1" TopLine="85"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="20" Column="22" TopLine="9"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="178" Column="5" TopLine="155"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="181" Column="5" TopLine="158"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="23" Column="27" TopLine="13"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="219" Column="1" TopLine="210"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="23" Column="8" TopLine="14"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="218" Column="1" TopLine="209"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="131" Column="1" TopLine="114"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="116" Column="44" TopLine="104"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="view.pas"/>
|
||||
<Caret Line="192" Column="35" TopLine="180"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="controller.pas"/>
|
||||
<Caret Line="74" Column="15" TopLine="59"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="8"/>
|
||||
|
@ -17,8 +17,8 @@ program texteditor;
|
||||
uses
|
||||
Math,
|
||||
objc, ctypes, MacOSAll, AppKit, Foundation,
|
||||
controller, model, view,
|
||||
cocoa_pkg, mytoolbar;
|
||||
{$ifndef WITHOUT_PKG}cocoa_pkg,{$endif}
|
||||
controller, model, view, mytoolbar;
|
||||
|
||||
var
|
||||
pool: NSAutoreleasePool;
|
||||
@ -33,20 +33,28 @@ begin
|
||||
{ Creates the application NSApp object }
|
||||
NSApp := NSApplication.sharedApplication;
|
||||
|
||||
{ Initializes the controller, view and model objects }
|
||||
{ Initializes the model object,
|
||||
must be after the view so that the resources are loaded }
|
||||
|
||||
myModel := TMyModel.Create();
|
||||
|
||||
{ Initializes the view object }
|
||||
|
||||
myView := TMyView.Create;
|
||||
myView.CreateUserInterface;
|
||||
|
||||
{ The controller needs to be the last to be creates for an unknown reason,
|
||||
and we can only attach the events after the controller is created }
|
||||
|
||||
myController := TMyController.Create();
|
||||
myModel := TMyModel.Create();
|
||||
myView := TMyView.Create();
|
||||
|
||||
{ Creates the user interface }
|
||||
|
||||
myView.CreateUserInterface();
|
||||
|
||||
myView.MainWindow.orderFrontRegardless;
|
||||
myView.AttachEventHandlers();
|
||||
myToolbarController.AttachEventHandlers();
|
||||
|
||||
{ Enters main message loop }
|
||||
|
||||
myView.MainWindow.orderFrontRegardless;
|
||||
|
||||
NSApp.setDelegate(myController.Handle);
|
||||
|
||||
NSApp.run;
|
||||
|
@ -16,27 +16,29 @@ type
|
||||
TMyView = class
|
||||
private
|
||||
{ Other helper functions }
|
||||
procedure AddToMenubar(menu: NSMenu);
|
||||
|
||||
function CreateAppleMenu(): NSMenu;
|
||||
function CreateFileMenu(): NSMenu;
|
||||
procedure CreateMainMenu();
|
||||
function CreateMenuItem(ATitle: shortstring): NSMenuItem;
|
||||
|
||||
function CreateToolbar(AOwnerView: NSView; AX, AY, AWidth, AHeight: Double): NSToolbar;
|
||||
function CreateMainMenu(): NSMenu;
|
||||
function CreateMenuItem(ATitle: shortstring;
|
||||
ACallbackName: string; ACallbackClass: NSObject): NSMenuItem;
|
||||
function CreateTextField(): NSTextField;
|
||||
public
|
||||
{ classes }
|
||||
MainWindow: NSWindow;
|
||||
MainWindowView: NSView;
|
||||
Toolbar: NSToolbar;
|
||||
ToolbarController: TMyToolbarController;
|
||||
MainMenu: NSMenu;
|
||||
TextField: NSTextField;
|
||||
FileMenuItem, OpenItem, SaveItem, SaveAsItem, ExitItem: NSMenuItem;
|
||||
FileMenu: NSMenu;
|
||||
MainMenu, AppleMenu, ServicesMenu, FileMenu: NSMenu;
|
||||
OpenItem, SaveItem, SaveAsItem, ExitItem: NSMenuItem;
|
||||
{ strings and sizes}
|
||||
CFWindowTitle, CFEmptyString: CFStringRef;
|
||||
MainWindowRect: NSRect;
|
||||
MenuTitle: CFStringRef;
|
||||
{ methods }
|
||||
procedure CreateUserInterface();
|
||||
procedure AttachEventHandlers();
|
||||
end;
|
||||
|
||||
var
|
||||
@ -82,10 +84,114 @@ begin
|
||||
|
||||
{ Add the main menu }
|
||||
|
||||
MainMenu := CreateMainMenu();
|
||||
CreateMainMenu();
|
||||
end;
|
||||
|
||||
NSApp.setAppleMenu(MainMenu.Handle);
|
||||
NSApp.setMainMenu(MainMenu.Handle);
|
||||
procedure TMyView.AttachEventHandlers();
|
||||
begin
|
||||
OpenItem.setTarget(myController.Handle);
|
||||
OpenItem.setAction(sel_registerName(PChar('doOpenFile:')));
|
||||
|
||||
SaveItem.setTarget(myController.Handle);
|
||||
SaveItem.setAction(sel_registerName(PChar('doSaveFile:')));
|
||||
|
||||
ExitItem.setTarget(myController.Handle);
|
||||
ExitItem.setAction(sel_registerName(PChar('doClose:')));
|
||||
end;
|
||||
|
||||
function TMyView.CreateAppleMenu(): NSMenu;
|
||||
var
|
||||
AppleMenuTitle, ServicesMenuTitle: CFStringRef;
|
||||
begin
|
||||
AppleMenuTitle := CFStringCreateWithPascalString(nil, 'Apple Menu', kCFStringEncodingUTF8);
|
||||
ServicesMenuTitle := CFStringCreateWithPascalString(nil, 'Services', kCFStringEncodingUTF8);
|
||||
|
||||
{ Creates the Apple menu }
|
||||
|
||||
Result := NSMenu.initWithTitle(AppleMenuTitle);
|
||||
|
||||
{ Add the services submenu }
|
||||
|
||||
ServicesMenu := NSMenu.initWithTitle(ServicesMenuTitle);
|
||||
NSApp.setServicesMenu(ServicesMenu.Handle);
|
||||
|
||||
{
|
||||
NSMenuItem *menuitem;
|
||||
// Create the application (Apple) menu.
|
||||
NSMenu *menuApp = [[NSMenu alloc] initWithTitle: @""];
|
||||
|
||||
NSMenu *menuServices = [[NSMenu alloc] initWithTitle: @"Services"];
|
||||
[NSApp setServicesMenu:menuServices];
|
||||
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:nil keyEquivalent:@","];
|
||||
[menuApp addItem: menuitem];
|
||||
SetPreferencesMenuItem(menuitem);
|
||||
[menuApp addItem: [NSMenuItem separatorItem]];
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle: @"Services"
|
||||
action:nil keyEquivalent:@""];
|
||||
[menuitem setSubmenu:menuServices];
|
||||
[menuApp addItem: menuitem];
|
||||
[menuitem release];
|
||||
|
||||
[menuApp addItem: [NSMenuItem separatorItem]];
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle:@"Hide"
|
||||
action:@selector(hide:) keyEquivalent:@""];
|
||||
[menuitem setTarget: NSApp];
|
||||
[menuApp addItem: menuitem];
|
||||
[menuitem release];
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle:@"Hide Others"
|
||||
action:@selector(hideOtherApplications:) keyEquivalent:@""];
|
||||
[menuitem setTarget: NSApp];
|
||||
[menuApp addItem: menuitem];
|
||||
[menuitem release];
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle:@"Show All"
|
||||
action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||
[menuitem setTarget: NSApp];
|
||||
[menuApp addItem: menuitem];
|
||||
[menuitem release];
|
||||
[menuApp addItem: [NSMenuItem separatorItem]];
|
||||
menuitem = [[NSMenuItem alloc] initWithTitle:@"Quit"
|
||||
action:@selector(terminate:) keyEquivalent:@"q"];
|
||||
[menuitem setTarget: NSApp];
|
||||
[menuApp addItem: menuitem];
|
||||
SetQuitMenuItem(menuitem);
|
||||
[menuitem release];
|
||||
|
||||
[NSApp setAppleMenu:menuApp];
|
||||
AddToMenubar(menuApp);
|
||||
[menuApp release];
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
end;
|
||||
|
||||
function TMyView.CreateFileMenu(): NSMenu;
|
||||
var
|
||||
MenuTitle: CFStringRef;
|
||||
begin
|
||||
MenuTitle := CFStringCreateWithPascalString(nil, 'File', kCFStringEncodingUTF8);
|
||||
|
||||
{ Creates the file menu }
|
||||
|
||||
Result := NSMenu.initWithTitle(MenuTitle);
|
||||
|
||||
{ Adds items to it }
|
||||
|
||||
OpenItem := CreateMenuItem('Open');
|
||||
Result.addItem(OpenItem.Handle);
|
||||
SaveItem := CreateMenuItem('Save');
|
||||
Result.addItem(SaveItem.Handle);
|
||||
ExitItem := CreateMenuItem('Exit');
|
||||
Result.addItem(ExitItem.Handle);
|
||||
end;
|
||||
|
||||
procedure TMyView.AddToMenubar(menu: NSMenu);
|
||||
var
|
||||
dummyItem: NSMenuItem;
|
||||
begin
|
||||
dummyItem := NSMenuItem.initWithTitle_action_keyEquivalent(CFEmptyString, nil, CFEmptyString);
|
||||
dummyItem.setSubmenu(menu.Handle);
|
||||
MainMenu.addItem(dummyItem.Handle);
|
||||
dummyItem.Free;
|
||||
end;
|
||||
|
||||
{@@
|
||||
@ -94,42 +200,29 @@ function TMyView.CreateToolbar(AOwnerView: NSView; AX, AY, AWidth,
|
||||
AHeight: Double): NSToolbar;
|
||||
begin
|
||||
Result := NSToolbar.initWithIdentifier(CFEmptyString);
|
||||
ToolbarController := TMyToolbarController.Create;
|
||||
Result.setDelegate(ToolbarController.Handle);
|
||||
myToolbarController := TMyToolbarController.Create;
|
||||
Result.setDelegate(myToolbarController.Handle);
|
||||
end;
|
||||
|
||||
{@@
|
||||
}
|
||||
function TMyView.CreateMainMenu(): NSMenu;
|
||||
procedure TMyView.CreateMainMenu();
|
||||
begin
|
||||
MenuTitle := CFStringCreateWithPascalString(nil, 'Title', kCFStringEncodingUTF8);
|
||||
WriteLn('CreateMenu');
|
||||
Result := NSMenu.initWithTitle(CFEmptyString);
|
||||
WriteLn('Menu Created');
|
||||
MainMenu := NSMenu.initWithTitle(CFEmptyString);
|
||||
|
||||
{ Creates the file menu }
|
||||
NSApp.setMainMenu(MainMenu.Handle);
|
||||
|
||||
FileMenu := NSMenu.initWithTitle(MenuTitle);
|
||||
FileMenuItem := NSMenuItem.initWithTitle_action_keyEquivalent(CFEmptyString, nil, CFEmptyString);
|
||||
FileMenuItem.setSubmenu(FileMenu.Handle);
|
||||
Result.addItem(FileMenuItem.Handle);
|
||||
AppleMenu := CreateAppleMenu();
|
||||
NSApp.setAppleMenu(AppleMenu.Handle);
|
||||
AddToMenubar(AppleMenu);
|
||||
|
||||
{ Adds items to it }
|
||||
|
||||
OpenItem := CreateMenuItem('Open', 'doOpenFile:', myController);
|
||||
FileMenu.addItem(OpenItem.Handle);
|
||||
OpenItem := CreateMenuItem('Save', 'doSaveFile:', myController);
|
||||
FileMenu.addItem(OpenItem.Handle);
|
||||
OpenItem := CreateMenuItem('Save As', 'doSaveFileAs:', myController);
|
||||
FileMenu.addItem(OpenItem.Handle);
|
||||
OpenItem := CreateMenuItem('Exit', 'doClose:', myController);
|
||||
FileMenu.addItem(OpenItem.Handle);
|
||||
FileMenu := CreateFileMenu();
|
||||
AddToMenubar(FileMenu);
|
||||
end;
|
||||
|
||||
{@@
|
||||
}
|
||||
function TMyView.CreateMenuItem(ATitle: shortstring;
|
||||
ACallbackName: string; ACallbackClass: NSObject): NSMenuItem;
|
||||
function TMyView.CreateMenuItem(ATitle: shortstring): NSMenuItem;
|
||||
var
|
||||
ItemText: CFStringRef;
|
||||
KeyText: CFStringRef;
|
||||
@ -139,8 +232,6 @@ begin
|
||||
WriteLn(' ItemText: ', IntToHex(Int64(ItemText), 8), ' ATitle: ', ATitle);
|
||||
|
||||
Result := NSMenuItem.initWithTitle_action_keyEquivalent(ItemText, nil, KeyText);
|
||||
Result.setTarget(ACallbackClass.Handle);
|
||||
Result.setAction(sel_registerName(PChar(ACallbackName)));
|
||||
end;
|
||||
|
||||
function TMyView.CreateTextField(): NSTextField;
|
||||
|
Reference in New Issue
Block a user