2008-10-06 13:26:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
}
|
2008-09-29 00:47:50 +00:00
|
|
|
unit model;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils,
|
|
|
|
MacOSAll, objc, appkit, foundation;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TMyModel }
|
|
|
|
|
|
|
|
TMyModel = class
|
|
|
|
private
|
|
|
|
procedure LoadImages;
|
|
|
|
function GetResourcesDir: string;
|
|
|
|
public
|
|
|
|
{ Routines and variables for program resources }
|
|
|
|
imgOpen, imgSave, imgClose: NSImage;
|
|
|
|
ResourcesDir: string;
|
2008-10-06 15:44:57 +00:00
|
|
|
DocumentName: shortstring;
|
2008-09-29 00:47:50 +00:00
|
|
|
constructor Create;
|
|
|
|
end;
|
|
|
|
|
2008-10-06 15:44:57 +00:00
|
|
|
const
|
|
|
|
Str_Untitled = 'Untitled /1';
|
|
|
|
|
2008-09-29 00:47:50 +00:00
|
|
|
var
|
|
|
|
myModel: TMyModel;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
procedure TMyModel.LoadImages;
|
|
|
|
var
|
|
|
|
ImagePath: CFStringRef;
|
|
|
|
begin
|
|
|
|
ImagePath := CFStringCreateWithPascalString(nil, ResourcesDir + 'imgOpen.png', kCFStringEncodingUTF8);
|
|
|
|
imgOpen := NSImage.initWithContentsOfFile(ImagePath);
|
|
|
|
|
|
|
|
ImagePath := CFStringCreateWithPascalString(nil, ResourcesDir + 'imgSave.png', kCFStringEncodingUTF8);
|
|
|
|
imgSave := NSImage.initWithContentsOfFile(ImagePath);
|
|
|
|
|
|
|
|
ImagePath := CFStringCreateWithPascalString(nil, ResourcesDir + 'imgClose.png', kCFStringEncodingUTF8);
|
|
|
|
imgClose := NSImage.initWithContentsOfFile(ImagePath);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TMyModel.GetResourcesDir: string;
|
|
|
|
const
|
|
|
|
BundleResourcesDirectory = '/Contents/Resources/';
|
|
|
|
var
|
|
|
|
pathRef: CFURLRef;
|
|
|
|
pathCFStr: CFStringRef;
|
|
|
|
pathStr: shortstring;
|
|
|
|
begin
|
|
|
|
// Under Mac OS X we need to get the location of the bundle
|
|
|
|
pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
|
|
|
pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
|
|
|
|
CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
|
|
|
|
CFRelease(pathRef);
|
|
|
|
CFRelease(pathCFStr);
|
|
|
|
|
|
|
|
Result := pathStr + BundleResourcesDirectory;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TMyModel.Create;
|
|
|
|
begin
|
|
|
|
ResourcesDir := GetResourcesDir;
|
2008-10-06 02:46:47 +00:00
|
|
|
|
|
|
|
LoadImages;
|
2008-10-06 15:44:57 +00:00
|
|
|
|
|
|
|
DocumentName := Str_Untitled;
|
2008-09-29 00:47:50 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|