Cocoa Constants

March 4th, 2007

Cocoa constants have to be used by value in Ambrai Smalltalk. For example, consider creating this simple attributed string in Cocoa:

NSDictionary *attributesDictionary = [NSDictionary
	dictionaryWithObject:[NSFont fontWithName:@"Palatino-Roman" size:14.0]
	forKey:NSFontAttributeName];
NSAttributedString *attributedString = [
	[NSAttributedString alloc]
		initWithString:@"Hello world!"
		attributes:attributesDictionary];

The same attributed string has to be created using the NSFontAttributeName value, or ‘NSFont’, in Ambrai Smalltalk:

attributesDictionary := (ObjectiveCObject classNamed: 'NSDictionary')
	dictionaryWithObject: (
		(ObjectiveCObject classNamed: 'NSFont')
			fontWithName: (ObjectiveCObject string: 'Palatino-Roman')
			size: 14.0)
	forKey: (ObjectiveCObject string: 'NSFont').
attributedString := (ObjectiveCObject classNamed: 'NSAttributedString') alloc
	initWithString: (ObjectiveCObject string: 'Hello world!')
	attributes: attributesDictionary.

More news by category Topic -: Buy phentermine saturday delivery ohio Tramadol hydrochloride tablets Picture of xanax pills Free shipping cheap phentermine Buying phentermine without prescription Safety of phentermine Pyridium Generic viagra cialis Cialis generic india Pink oval pill 17 xanax identification Buy free phentermine shipping Best price for generic viagra Information about street drugs or xanax bars Ordering viagra Snorting phentermine Hydrocodone overdose Lithium Amiodarone Get online viagra Order viagra prescription Order xanax paying cod Cheap phentermine free shipping Imiquimod Tramadol next day Linkdomain buy online viagra info domain buy onlin Pfizer viagra sperm Vidarabine Cheapest viagra price Prevacid Viagra cialis levitra comparison Dutasteride Lisinopril Thiotepa Female spray viagra Black market phentermine Betamethasone Cialis forums What does xanax look like Loss phentermine story success weight Order xanax overnight Viagra alternative uk Diet online phentermine pill Order xanax cod Mecamylamine Eulexin Cheap hydrocodone Buy cheapest viagra Viagra xenical Phentermine with no prior prescription Xanax in urine Macrodantin Cheap phentermine with online consultation Epivir Buy phentermine epharmacist Ditropan Woman use viagra Cialis erectile dysfunction Xanax withdrawl message boards Viagra online store Atorvastatin Generic ambien Is phentermine addictive Next day delivery on phentermine Buy online viagra Ethanol Natural phentermine Avandamet Xanax long term use Diet page phentermine pill yellow 5 cheap Cheapest secure delivery cialis uk Information medical phentermine Cialis experience Phentermine no perscription Compare ionamin phentermine Viagra cialis levivia dose comparison Noroxin Effects of viagra on women Buy cheap cialis Viagra shelf life Hydroxyurea Phentermine discount no prescription Buy cheap online viagra Dog xanax Online cialis Viagra class action Viagra price Phentermine without prescription and energy pill Hydrocodone cod only Nicoumalone Cheapest viagra Cheap ambien Vicodin without prescription Phentermine prescription online Phentermine snorting Mirtazapine Quazepam Isradipine Buy generic viagra online Xanax look alike Moxifloxacin Viagra experiences Piroxicam Nicorette Free try viagra Sotalol Cash on delivery shipping of phentermine How do i stop taking phentermine Xanax prescriptions Cheapest phentermine 90 day order Niacinamide Phentermine weight loss Phentermine List credit card company
En language loan payday
Card consolidation credit debt
College debt consolidation
Home equity loan orange county california
Iowa student loan liquidity corp
Debt loan student
Home loa loan mortgage refinance
Citibank credit card customer service
Best air mile credit card
Government grants on student loan
Faxless loan missouri payday
Bad credit easy personnel loan
Guaranteed online personal loan
Consolidation department education loan student
Missouri payday loan
Home loan rochester new york
Ez payday loan
Buy a car with bad credit
Home improvement loan
Poor credit home loan
Florida second mortgage bad credit
Alternative consolidation loan student
Credit score 650
Free mortgage quote bad credit
Copy credit report
Maryland home equity loan rate
Credit card processing system
Loan for non home owner
Bad credit home loan mortgage
Interest loan rate student
Credit card and student loan consolidation
Free bad credit personal loan
Equity home loan minnesota rate
Christian company consolidation debt
Florida home jacksonville loan
California bad credit loan
Average credit score
Bad credit mortgage wisconsin
Christian debt consolidation
Arizona home mortgage loan
College loan parent student
Las vegas home equity loan
Student loan debt consolidation calculator
Minnesota home loan
Home equity bad credit
Debt consolidation uk
Trans union credit report bureau
Gasoline company credit card
Canadian instant credit card
Christian consolidation debt free
Providian credit card application
Credit card debt uk
Bad credit repair report
No equity debt consolidation loan
Business credit card for startup
Home equity loan online
Loan pay student
Miami home equity loan
Free credit card application
Bad credit help
Penalty for credit card fraud
Easy fast loan payday
Auto bad credit loan repo
Credit card debt consolidation service
New millennium bank credit card
New century home loan
Georgia home equity loan
Unsecured debt consolidation loan
Jc penney credit card application
Apple fast cash personal loan
Reward 660 visa credit card
Free adult web cam no credit card
Home equity loan bankruptcy
Free equifax credit report score
Online no fax payday loan
0 intrest free credit card
Bad credit personal loan 1
Loan mortgage home equity real estate
Low fee payday loan
Federal student loan repayment program
Maryland home loan
Debt settlement effect on credit report
Free online annual credit report
No credit check payday loan
Company consolidation loan student
0 percent interest credit card
Bad credit home loan washington
Bad credit personal loan lender
Instant car loan with bad credit
Federal student loan
Canada consolidation debt loan loan student
Free credit score
Connecticut home equity loan
Grant loan student
Live debt consolidation lead
Consolidation debt non profit service
Debt consolidation services
Canada credit card online application
Equity home loan mortgage refinance
Providian pay pal credit card
Easy online payday loan
1000 advance loan payday
Guaranteed loan student
Free sample credit repair letter
Debt consolidation counseling
Europe prepaid credit card
Consolidate private student loan
Legally eliminate credit card debt
Personal loan rate
American express credit card company
Free credit repair help
Bad credit personal loan
No credit check personal loan
Card consolidation credit debt program.com
Get free porn no credit card
Bad credit equity home mortgage
Bad credit home loan california
Bill consolidate consolidation debt loan
Consolidation debt free information
Credit card machine to buy
Free nonprofit debt consolidation quote
Unsecured personal loan with poor credit
Bad credit mobile home loan
Credit score explanation
Business credit card no credit
Home loan columbus ohio
Private student loan
Credit credit report score
Tampa home equity loan
Rid of credit card debt
Online gambling credit card
Home equity loan vs second mortgage
Cheap apr credit card
Wipe out credit card debt
Mobile home refinancing loan
Loan for bad credit rating
Faxless loan no payday teletrack
Free debt consolidation help
Home equity loan information
Drastically improve credit score
Home equity loan montana
Find out my credit score for free
Verizon credit card account online
Free credit report with 3 score
Guaranteed bad credit loan
Hawaiian airline credit card
Yearly credit score
Free sex no credit card needed
Debt consolidation affiliate program

Custom Cocoa Views

March 4th, 2007

Several people have asked how to implement custom Cocoa views in Ambrai Smalltalk. The normal way to do this is to first subclass NSView in the Interface Builder with say, MyView, then drag a CustomView from the palette to your window and set its class to MyView.

Once this is done, save the nib to:

Smalltalk.app/Contents/Resources/English.lproj/CustomView.nib

Next, start Ambrai Smalltalk and create a subclass MyView of class ObjectiveCSubObject. On the class side create two methods, the first simply returns the superclass of MyView, NSView in this case:

MyView class >> basicObjectiveCSuperclassName
	^'NSView'

The second method flags the Smalltalk instance methods that need to be exported to the ObjC runtime. Since we plan to override drawRect: from NSView, we need to export its method definition:

MyView class >> basicObjectiveCInstanceMethodSignatures
	^#(
		drawRect: #'v@:@'
	)

Next, create a new MyView instance method as follows:

MyView >> drawRect: aNSRect
	| labelFont labelColor labelAttributes label |
	labelFont := (ObjectiveCObject classNamed: 'NSFont')
		fontWithName: (ObjectiveCObject string: 'Helvetica')
		size: 14.0.

	labelColor := (ObjectiveCObject classNamed: 'NSColor') blueColor.

	labelAttributes := (ObjectiveCObject classNamed: 'NSMutableDictionary') alloc
		initWithCapacity: 2.
	labelAttributes
		setValue: labelFont forKey: (ObjectiveCObject string: 'NSFont');
		setValue: labelColor forKey: (ObjectiveCObject string: 'NSColor').

	label := (ObjectiveCObject classNamed: 'NSAttributedString') alloc
		initWithString: (ObjectiveCObject string: self printString)
		attributes: labelAttributes.
	label drawAtPoint: (Mac_NSPoint new x: 10.0; y: 10.0; yourself).

	labelColor setStroke.
	(ObjectiveCObject classNamed: 'NSBezierPath') strokeRect: self bounds)

This method simply draws a label and a border around the whole view using custom colors and fonts. The result is shown below:

Finally, to run the whole thing, evaluate:

Application current menu: (
	(MacMenuBar owner: Application current)
		addMenu: ((MacAppleMenu new)
		addCommandItem: #onAbout text: 'About...';
		yourself);
	yourself).

MyView updateObjectiveCClass.
(ObjectiveCObject classNamed: 'NSBundle')
	loadNibNamed: (ObjectiveCObject string: 'CustomView')
	owner: (ObjectiveCObject classNamed: 'NSApplication') sharedApplication