Improves pascocoa and texteditor example

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@584 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2008-10-06 13:26:48 +00:00
parent b6a6f21e34
commit ce8ee9bb1f
10 changed files with 191 additions and 158 deletions

3
bindings/objc/clean.sh Executable file
View File

@ -0,0 +1,3 @@
rm *.o
rm *.ppu
rm *.bak

View File

@ -39,6 +39,8 @@ uses ctypes, unix;
{$include malloc.inc} {$include malloc.inc}
{.$include zone.inc} {.$include zone.inc}
{ Extra declarations }
implementation implementation
{ Macros from error.h } { Macros from error.h }

View File

@ -14,13 +14,15 @@
{$include NSText.inc} {$include NSText.inc}
{$include NSToolbar.inc} {$include NSToolbar.inc}
//APPKIT_EXTERN NSString *NSToolbarSeparatorItemIdentifier; var
//APPKIT_EXTERN NSString *NSToolbarSpaceItemIdentifier; NSToolbarSeparatorItemIdentifier: CFStringRef; cvar; external;
//APPKIT_EXTERN NSString *NSToolbarFlexibleSpaceItemIdentifier; NSToolbarSpaceItemIdentifier: CFStringRef; cvar; external;
//APPKIT_EXTERN NSString *NSToolbarShowColorsItemIdentifier; // Shows the color panel. NSToolbarFlexibleSpaceItemIdentifier: CFStringRef; cvar; external;
//APPKIT_EXTERN NSString *NSToolbarShowFontsItemIdentifier; // Shows the font panel. NSToolbarShowColorsItemIdentifier: CFStringRef; cvar; external; // Shows the color panel.
//APPKIT_EXTERN NSString *NSToolbarCustomizeToolbarItemIdentifier; // Puts the current toolbar into customize mode. NSToolbarShowFontsItemIdentifier: CFStringRef; cvar; external; // Shows the font panel.
//APPKIT_EXTERN NSString *NSToolbarPrintItemIdentifier; // Sends printDocument: to firstResponder, but you can change this in toolbarWillAddItem: if you need to do so. NSToolbarCustomizeToolbarItemIdentifier: CFStringRef; cvar; external; // Puts the current toolbar into customize mode.
NSToolbarPrintItemIdentifier: CFStringRef; cvar; external; // Sends printDocument: to firstResponder, but you can change this in toolbarWillAddItem: if you need to do so.
const const
NSToolbarItemVisibilityPriorityStandard = 0; NSToolbarItemVisibilityPriorityStandard = 0;
NSToolbarItemVisibilityPriorityLow = 1000; NSToolbarItemVisibilityPriorityLow = 1000;

View File

@ -9,7 +9,7 @@
unit appkit; unit appkit;
{$ifdef fpc} {$ifdef fpc}
{$mode delphi} {$mode objfpc}
{$packrecords c} {$packrecords c}
{$endif} {$endif}

View File

@ -1,6 +1,8 @@
{ {
controller.pas controller.pas
Controller class for the texteditor example.
This example project is released under public domain This example project is released under public domain
AUTHORS: Felipe Monteiro de Carvalho AUTHORS: Felipe Monteiro de Carvalho
@ -24,11 +26,11 @@ type
constructor Create; override; constructor Create; override;
procedure AddMethods; override; procedure AddMethods; override;
{ Objective-c Methods } { Objective-c Methods }
class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static; class procedure doClose(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
class procedure doOpenFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static; class procedure doOpenFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
class procedure doSaveFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; //static; class procedure doSaveFile(_self: objc.id; _cmd: SEL; sender: objc.id); cdecl; {$ifndef VER2_2_2}static;{$endif}
class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id; class function applicationShouldTerminateAfterLastWindowClosed(_self: objc.id;
_cmd: SEL; theApplication: objc.id): cbool; cdecl; //static; _cmd: SEL; theApplication: objc.id): cbool; cdecl; {$ifndef VER2_2_2}static;{$endif}
end; end;
const const
@ -93,13 +95,13 @@ var
begin begin
{ Show dialog } { Show dialog }
if SavePanel.runModal = NSFileHandlingPanelOKButton then if OpenPanel.runModal = NSFileHandlingPanelOKButton then
begin begin
{ Now move the contents of the file to the edit control } { Now move the contents of the edit control to the file }
FileContents := NSString.initWithContentsOfFile(OpenPanel.filename); FileContents := NSString.CreateWithHandle(objc.id(myView.TextField.StringValue));
FileContents.writeToFile_atomically(SavePanel.filename, False); myView.TextField.setStringValue(CFStringRef(FileContents.Handle));
end; end;
end; end;
@ -110,13 +112,13 @@ var
begin begin
{ Show dialog } { Show dialog }
if OpenPanel.runModal = NSFileHandlingPanelOKButton then if SavePanel.runModal = NSFileHandlingPanelOKButton then
begin begin
{ Now move the contents of the edit control to the file } { Now move the contents of the file to the edit control }
FileContents := NSString.CreateWithHandle(objc.id(myView.TextField.StringValue)); FileContents := NSString.initWithContentsOfFile(OpenPanel.filename);
myView.TextField.setStringValue(CFStringRef(FileContents.Handle)); FileContents.writeToFile_atomically(SavePanel.filename, False);
end; end;
end; end;

View File

@ -1,3 +1,12 @@
{
model.pas
Model class for the texteditor class. Holds and manages resource files and user data.
This example project is released under public domain
AUTHORS: Felipe Monteiro de Carvalho
}
unit model; unit model;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}

View File

@ -1,3 +1,12 @@
{
mytoolbar.pas
Toolbar controller class. Creates and manages the toolbar.
This example project is released under public domain
AUTHORS: Felipe Monteiro de Carvalho
}
unit mytoolbar; unit mytoolbar;
{$mode delphi}{$STATIC ON} {$mode delphi}{$STATIC ON}
@ -17,14 +26,15 @@ type
{ Extra binding functions } { Extra binding functions }
constructor Create; override; constructor Create; override;
procedure AddMethods; override; procedure AddMethods; override;
{ Public routines }
procedure AttachEventHandlers; procedure AttachEventHandlers;
{ Toolbar items } { Toolbar items }
OpenToolbarItem, SaveToolbarItem, CloseToolbarItem: NSToolbarItem; OpenToolbarItem, SaveToolbarItem, CloseToolbarItem: NSToolbarItem;
{ Objective-c Methods } { Objective-c Methods }
class function toolbarAllowedItemIdentifiers(_self: objc.id; class function toolbarAllowedItemIdentifiers(_self: objc.id;
_cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl;// static; _cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl; {$ifndef VER2_2_2}static;{$endif}
class function toolbarDefaultItemIdentifiers(_self: objc.id; class function toolbarDefaultItemIdentifiers(_self: objc.id;
_cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl;// static; _cmd: SEL; toolbar: objc.id {NSToolbar}): CFArrayRef; cdecl; {$ifndef VER2_2_2}static;{$endif}
end; end;
const const
@ -38,7 +48,7 @@ var
function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar
(_self: objc.id; _cmd: SEL; toolbar: objc.id; (_self: objc.id; _cmd: SEL; toolbar: objc.id;
itemIdentifier: CFStringRef; flag: OBJC_BOOL): objc.id; cdecl;// static; itemIdentifier: CFStringRef; flag: objc.BOOL): objc.id; cdecl;// static;
implementation implementation
@ -62,15 +72,15 @@ begin
{ Create toolbar items } { Create toolbar items }
OpenToolbarItem := NSToolbarItem.initWithItemIdentifier(OpenToolbarItemIdentifier); OpenToolbarItem := NSToolbarItem.initWithItemIdentifier(OpenToolbarItemIdentifier);
// [toolbarItem setLabel:@"Save"]; OpenToolbarItem.setToolTip(CFStringCreateWithPascalString(nil, 'Open', kCFStringEncodingUTF8));
// [toolbarItem setPaletteLabel:[toolbarItem label]];
// [toolbarItem setToolTip:@"Save Your Passwords"];}
OpenToolbarItem.setImage(myModel.imgOpen.Handle); OpenToolbarItem.setImage(myModel.imgOpen.Handle);
SaveToolbarItem := NSToolbarItem.initWithItemIdentifier(SaveToolbarItemIdentifier); SaveToolbarItem := NSToolbarItem.initWithItemIdentifier(SaveToolbarItemIdentifier);
SaveToolbarItem.setToolTip(CFStringCreateWithPascalString(nil, 'Save', kCFStringEncodingUTF8));
SaveToolbarItem.setImage(myModel.imgSave.Handle); SaveToolbarItem.setImage(myModel.imgSave.Handle);
CloseToolbarItem := NSToolbarItem.initWithItemIdentifier(CloseToolbarItemIdentifier); CloseToolbarItem := NSToolbarItem.initWithItemIdentifier(CloseToolbarItemIdentifier);
CloseToolbarItem.setToolTip(CFStringCreateWithPascalString(nil, 'Exit', kCFStringEncodingUTF8));
CloseToolbarItem.setImage(myModel.imgClose.Handle); CloseToolbarItem.setImage(myModel.imgClose.Handle);
end; end;
@ -94,15 +104,19 @@ begin
CloseToolbarItem.setAction(sel_registerName(PChar('doClose:'))); CloseToolbarItem.setAction(sel_registerName(PChar('doClose:')));
end; end;
{@@
Lists all of the items in the toolbar by their identifiers.
This method is necessary to implement a toolbar.
}
class function TMyToolbarController.toolbarAllowedItemIdentifiers(_self: objc.id; class function TMyToolbarController.toolbarAllowedItemIdentifiers(_self: objc.id;
_cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl; _cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl;
var var
toolbarItems: array[0..4] of CFStringRef; toolbarItems: array[0..4] of CFStringRef;
begin begin
WriteLn('OpenToolbarItemIdentifier: ', IntToHex(Cardinal(OpenToolbarItemIdentifier), 8)); { WriteLn('OpenToolbarItemIdentifier: ', IntToHex(Cardinal(OpenToolbarItemIdentifier), 8));
WriteLn('SaveToolbarItemIdentifier: ', IntToHex(Cardinal(SaveToolbarItemIdentifier), 8)); WriteLn('SaveToolbarItemIdentifier: ', IntToHex(Cardinal(SaveToolbarItemIdentifier), 8));
WriteLn('NSToolbarSpaceItemIdentifier: ', IntToHex(Cardinal(NSToolbarSpaceItemIdentifier), 8)); WriteLn('NSToolbarSpaceItemIdentifier: ', IntToHex(Cardinal(NSToolbarSpaceItemIdentifier), 8));
WriteLn('CloseToolbarItemIdentifier: ', IntToHex(Cardinal(CloseToolbarItemIdentifier), 8)); WriteLn('CloseToolbarItemIdentifier: ', IntToHex(Cardinal(CloseToolbarItemIdentifier), 8));}
toolbarItems[0] := OpenToolbarItemIdentifier; toolbarItems[0] := OpenToolbarItemIdentifier;
toolbarItems[1] := SaveToolbarItemIdentifier; toolbarItems[1] := SaveToolbarItemIdentifier;
toolbarItems[2] := NSToolbarSpaceItemIdentifier; toolbarItems[2] := NSToolbarSpaceItemIdentifier;
@ -112,17 +126,27 @@ begin
Result := CFArrayCreate(nil, @toolbarItems[0], 4, nil); Result := CFArrayCreate(nil, @toolbarItems[0], 4, nil);
end; end;
{@@
Returns which items are available by default in the toolbar.
Other items exist in the toolbar but are optional.
We simply return the same items from toolbarAllowedItemIdentifiers.
}
class function TMyToolbarController.toolbarDefaultItemIdentifiers(_self: objc.id; class function TMyToolbarController.toolbarDefaultItemIdentifiers(_self: objc.id;
_cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl; _cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl;
begin begin
Result := toolbarAllowedItemIdentifiers(_self, _cmd, toolbar); Result := toolbarAllowedItemIdentifiers(_self, _cmd, toolbar);
end; end;
{@@
Returns the NSToolbarItem for each item.
Note that we should return an item in our cache instead of creating a new one
everytime this routine is called.
}
function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(_self: objc.id; function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(_self: objc.id;
_cmd: SEL; toolbar: objc.id {NSToolbar}; itemIdentifier: CFStringRef; _cmd: SEL; toolbar: objc.id {NSToolbar}; itemIdentifier: CFStringRef;
flag: OBJC_BOOL): objc.id {NSToolbarItem}; cdecl; flag: objc.BOOL): objc.id {NSToolbarItem}; cdecl;
begin begin
WriteLn('toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar: ', IntToHex(Cardinal(itemIdentifier), 8)); // WriteLn('toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar: ', IntToHex(Cardinal(itemIdentifier), 8));
with myToolbarController do with myToolbarController do
begin begin

View File

@ -6,7 +6,7 @@
<General> <General>
<MainUnit Value="0"/> <MainUnit Value="0"/>
<TargetFileExt Value=""/> <TargetFileExt Value=""/>
<ActiveEditorIndexAtStart Value="7"/> <ActiveEditorIndexAtStart Value="1"/>
</General> </General>
<VersionInfo> <VersionInfo>
<ProjectVersion Value=""/> <ProjectVersion Value=""/>
@ -30,211 +30,229 @@
<PackageName Value="cocoa_pkg"/> <PackageName Value="cocoa_pkg"/>
</Item1> </Item1>
</RequiredPackages> </RequiredPackages>
<Units Count="9"> <Units Count="12">
<Unit0> <Unit0>
<Filename Value="texteditor.pas"/> <Filename Value="texteditor.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="texteditor"/> <UnitName Value="texteditor"/>
<CursorPos X="15" Y="44"/> <CursorPos X="9" Y="15"/>
<TopLine Value="31"/> <TopLine Value="1"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="31"/> <UsageCount Value="37"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="model.pas"/> <Filename Value="model.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="model"/> <UnitName Value="model"/>
<CursorPos X="33" Y="63"/> <CursorPos X="1" Y="4"/>
<TopLine Value="48"/> <TopLine Value="1"/>
<EditorIndex Value="5"/> <EditorIndex Value="5"/>
<UsageCount Value="31"/> <UsageCount Value="37"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="view"/> <UnitName Value="view"/>
<CursorPos X="28" Y="217"/> <CursorPos X="1" Y="221"/>
<TopLine Value="204"/> <TopLine Value="74"/>
<EditorIndex Value="7"/> <EditorIndex Value="7"/>
<UsageCount Value="31"/> <UsageCount Value="37"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="controller.pas"/> <Filename Value="controller.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="controller"/> <UnitName Value="controller"/>
<CursorPos X="25" Y="30"/> <CursorPos X="19" Y="98"/>
<TopLine Value="19"/> <TopLine Value="85"/>
<EditorIndex Value="6"/> <EditorIndex Value="6"/>
<UsageCount Value="31"/> <UsageCount Value="37"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="mytoolbar"/> <UnitName Value="mytoolbar"/>
<CursorPos X="1" Y="106"/> <CursorPos X="51" Y="126"/>
<TopLine Value="97"/> <TopLine Value="115"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<UsageCount Value="26"/> <UsageCount Value="32"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="../../../objc/objc.pas"/> <Filename Value="../../../objc/objc.pas"/>
<UnitName Value="objc"/> <UnitName Value="objc"/>
<CursorPos X="14" Y="48"/> <CursorPos X="50" Y="3"/>
<TopLine Value="29"/> <TopLine Value="27"/>
<EditorIndex Value="4"/> <EditorIndex Value="2"/>
<UsageCount Value="12"/> <UsageCount Value="15"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="../../foundation/foundation.pas"/> <Filename Value="../../foundation/foundation.pas"/>
<UnitName Value="foundation"/> <UnitName Value="foundation"/>
<CursorPos X="30" Y="12"/> <CursorPos X="30" Y="8"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<EditorIndex Value="3"/> <UsageCount Value="11"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="../../appkit/NSToolbarItem.inc"/> <Filename Value="../../appkit/NSToolbarItem.inc"/>
<CursorPos X="49" Y="5"/> <CursorPos X="49" Y="5"/>
<TopLine Value="4"/> <TopLine Value="4"/>
<UsageCount Value="10"/> <UsageCount Value="9"/>
</Unit7> </Unit7>
<Unit8> <Unit8>
<Filename Value="../../appkit/appkit.pas"/> <Filename Value="../../appkit/appkit.pas"/>
<UnitName Value="appkit"/> <UnitName Value="appkit"/>
<CursorPos X="16" Y="12"/> <CursorPos X="28" Y="9"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<EditorIndex Value="2"/> <UsageCount Value="11"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit8> </Unit8>
<Unit9>
<Filename Value="../../../objc/objc.inc"/>
<CursorPos X="13" Y="60"/>
<TopLine Value="46"/>
<EditorIndex Value="3"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="../../appkit/NSApplication.inc"/>
<CursorPos X="31" Y="1047"/>
<TopLine Value="1041"/>
<UsageCount Value="10"/>
</Unit10>
<Unit11>
<Filename Value="../../appkit/NSAlert.inc"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="28"/>
<EditorIndex Value="4"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit11>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="73" Column="1" TopLine="61"/> <Caret Line="76" Column="1" TopLine="64"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="74" Column="1" TopLine="62"/> <Caret Line="78" Column="1" TopLine="66"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="75" Column="1" TopLine="63"/> <Caret Line="72" Column="1" TopLine="67"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="76" Column="1" TopLine="64"/> <Caret Line="74" Column="92" TopLine="61"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="78" Column="1" TopLine="66"/> <Caret Line="8" Column="12" TopLine="1"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="72" Column="1" TopLine="67"/> <Caret Line="126" Column="30" TopLine="115"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="74" Column="92" TopLine="61"/> <Caret Line="21" Column="55" TopLine="2"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="8" Column="12" TopLine="1"/> <Caret Line="101" Column="111" TopLine="92"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="126" Column="30" TopLine="115"/> <Caret Line="75" Column="5" TopLine="52"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="mytoolbar.pas"/> <Filename Value="view.pas"/>
<Caret Line="21" Column="55" TopLine="2"/> <Caret Line="101" Column="20" TopLine="90"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="mytoolbar.pas"/> <Filename Value="view.pas"/>
<Caret Line="101" Column="111" TopLine="92"/> <Caret Line="102" Column="13" TopLine="89"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="75" Column="5" TopLine="52"/> <Caret Line="65" Column="1" TopLine="58"/>
</Position12> </Position12>
<Position13> <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"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="20" Column="34" TopLine="8"/> <Caret Line="20" Column="34" TopLine="8"/>
</Position16> </Position13>
<Position17> <Position14>
<Filename Value="mytoolbar.pas"/> <Filename Value="mytoolbar.pas"/>
<Caret Line="37" Column="22" TopLine="28"/> <Caret Line="37" Column="22" TopLine="28"/>
</Position14>
<Position15>
<Filename Value="view.pas"/>
<Caret Line="99" Column="12" TopLine="80"/>
</Position15>
<Position16>
<Filename Value="view.pas"/>
<Caret Line="108" Column="1" TopLine="85"/>
</Position16>
<Position17>
<Filename Value="view.pas"/>
<Caret Line="20" Column="22" TopLine="9"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="99" Column="12" TopLine="80"/> <Caret Line="178" Column="5" TopLine="155"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="108" Column="1" TopLine="85"/> <Caret Line="181" Column="5" TopLine="158"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="20" Column="22" TopLine="9"/> <Caret Line="23" Column="27" TopLine="13"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="178" Column="5" TopLine="155"/> <Caret Line="219" Column="1" TopLine="210"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="181" Column="5" TopLine="158"/> <Caret Line="23" Column="8" TopLine="14"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="23" Column="27" TopLine="13"/> <Caret Line="218" Column="1" TopLine="209"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="219" Column="1" TopLine="210"/> <Caret Line="131" Column="1" TopLine="114"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="23" Column="8" TopLine="14"/> <Caret Line="116" Column="44" TopLine="104"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="view.pas"/> <Filename Value="view.pas"/>
<Caret Line="218" Column="1" TopLine="209"/> <Caret Line="192" Column="35" TopLine="180"/>
</Position26> </Position26>
<Position27> <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"/> <Filename Value="controller.pas"/>
<Caret Line="74" Column="15" TopLine="59"/> <Caret Line="74" Column="15" TopLine="59"/>
</Position27>
<Position28>
<Filename Value="../../../objc/objc.pas"/>
<Caret Line="27" Column="12" TopLine="19"/>
</Position28>
<Position29>
<Filename Value="mytoolbar.pas"/>
<Caret Line="149" Column="9" TopLine="134"/>
</Position29>
<Position30>
<Filename Value="view.pas"/>
<Caret Line="218" Column="77" TopLine="200"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>

View File

@ -49,7 +49,7 @@ begin
myController := TMyController.Create(); myController := TMyController.Create();
myView.AttachEventHandlers(); myView.AttachEventHandlers();
myToolbarController.AttachEventHandlers(); myToolbarController.AttachEventHandlers(); // Created in myView.CreateUserInterface
{ Enters main message loop } { Enters main message loop }

View File

@ -1,3 +1,12 @@
{
view.pas
View class of the texteditor example. Creates the user interface.
This example project is released under public domain
AUTHORS: Felipe Monteiro de Carvalho
}
unit view; unit view;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
@ -87,6 +96,8 @@ begin
CreateMainMenu(); CreateMainMenu();
end; end;
{@@
}
procedure TMyView.AttachEventHandlers(); procedure TMyView.AttachEventHandlers();
begin begin
OpenItem.setTarget(myController.Handle); OpenItem.setTarget(myController.Handle);
@ -99,6 +110,8 @@ begin
ExitItem.setAction(sel_registerName(PChar('doClose:'))); ExitItem.setAction(sel_registerName(PChar('doClose:')));
end; end;
{@@
}
function TMyView.CreateAppleMenu(): NSMenu; function TMyView.CreateAppleMenu(): NSMenu;
var var
AppleMenuTitle, ServicesMenuTitle: CFStringRef; AppleMenuTitle, ServicesMenuTitle: CFStringRef;
@ -114,56 +127,10 @@ begin
ServicesMenu := NSMenu.initWithTitle(ServicesMenuTitle); ServicesMenu := NSMenu.initWithTitle(ServicesMenuTitle);
NSApp.setServicesMenu(ServicesMenu.Handle); 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; end;
{@@
}
function TMyView.CreateFileMenu(): NSMenu; function TMyView.CreateFileMenu(): NSMenu;
var var
MenuTitle: CFStringRef; MenuTitle: CFStringRef;
@ -184,6 +151,8 @@ begin
Result.addItem(ExitItem.Handle); Result.addItem(ExitItem.Handle);
end; end;
{@@
}
procedure TMyView.AddToMenubar(menu: NSMenu); procedure TMyView.AddToMenubar(menu: NSMenu);
var var
dummyItem: NSMenuItem; dummyItem: NSMenuItem;
@ -234,6 +203,9 @@ begin
Result := NSMenuItem.initWithTitle_action_keyEquivalent(ItemText, nil, KeyText); Result := NSMenuItem.initWithTitle_action_keyEquivalent(ItemText, nil, KeyText);
end; end;
{@@
Creates an autosized NSTextField
}
function TMyView.CreateTextField(): NSTextField; function TMyView.CreateTextField(): NSTextField;
var var
ClientRect: NSRect; ClientRect: NSRect;
@ -244,6 +216,7 @@ begin
ClientRect.size.height := 500.0; ClientRect.size.height := 500.0;
Result := NSTextField.initWithFrame(ClientRect); Result := NSTextField.initWithFrame(ClientRect);
Result.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
MainWindowView.addSubview(Result.Handle); MainWindowView.addSubview(Result.Handle);
end; end;