<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Th30z - Coding on the Fly &#187; Mac OS X</title>
	<atom:link href="http://th30z.netsons.org/tag/mac-os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://th30z.netsons.org</link>
	<description>Matteo Bertozzi, Objective-C, Cocoa, C, C++, Qt4, iPhone, Mac OS X, Open Moko, Matteo Bertozzi Development</description>
	<lastBuildDate>Sun, 22 Nov 2009 09:47:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Grand Central Dispatch: First Look</title>
		<link>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/</link>
		<comments>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 05:00:32 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Grand Central Dispatch]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1202</guid>
		<description><![CDATA[In the last years I&#8217;ve always used a &#8220;parallel task&#8221; approach foreach loops that I&#8217;ve in the code, not always to speedup but even to clean-up the code. How to do it? Wrapping threads and Thread Pool like in this C# Parallel Forech Code.
Snow Leopard has introduced a new BSD-level infrastructure, with simple and efficient [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Grand_Central_Dispatch"><img src="http://th30z.netsons.org/wp-content/uploads/GDC-Logo.png" alt="Mac OS X Grand Central Dispatch" title="Mac OS X Grand Central Dispatch" width="118" height="106" class="alignright size-full wp-image-1207" /></a>In the last years I&#8217;ve always used a &#8220;parallel task&#8221; approach foreach loops that I&#8217;ve in the code, not always to speedup but even to clean-up the code. <em>How to do it? Wrapping threads and Thread Pool like in this <a href="http://th30z.netsons.org/2008/12/c-parallel-foreach-using-thread-pool/">C# Parallel Forech Code</a></em>.</p>
<p><strong>Snow Leopard</strong> has introduced a new BSD-level infrastructure, with simple and efficient API to do this job. Here a little usage preview.</p>
<p><strong>Block objects</strong> are a C-based language feature that you can use in your C, Objective-C, and C++ code. Blocks make it easy to define a self-contained unit of work. Blocks are something like Actions (delegate {}) in C#. <em>Very useful to embed function in loops.</em></p>
<p>Blocks looks like a &#8220;private&#8221; function pointer, but you can access to the &#8220;parent&#8221; vars. (<em>If you&#8217;re a Python coder, you&#8217;ve exactly the same thing</em>).<br />
<code></p>
<pre>
/* Blocks in Python...
 * def main():
 *    a = 10
 *    def test(k):
 *        print a, k
 *    test(128)
 */
int main (int argc, const char *argv[]) {
  int a = 12;

  void (^test_block) (int) = ^(int k) {
    printf("A Block: PARENT(%d) ARG(%d)\n", a, k);
  };

  test_block(128);

  return 0;
}
</pre>
<p></code></p>
<p>The <strong>GCD</strong> queue API provides <strong>dispatch queues</strong> from which threads take tasks to be executed. Because the threads are managed by GCD, Mac OS X can optimize the number of threads based upon available memory, number of currently active CPU cores, and so on. This shifts a great deal of the burden of power and resource management to the operating system itself, freeing your application to focus on the actual work to be accomplished.<br />
<code></p>
<pre>
#include &lt;dispatch/dispatch.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

#define ITEM_VMIN       (1)
#define ITEM_VMAX       (200)
#define NR_ITEMS        (100)

static void __fill_item (void *items, size_t n) {
  int *i_items = (int *)items;
  i_items[n] = (ITEM_VMIN + (int)(ITEM_VMAX * ((double)rand() / RAND_MAX)));
}

static void __work_on_item (void *items, size_t n) {
  int *i_items = (int *)items;
  i_items[n] *= 100;  /* Do some Computation on this Item */
}

int main (int argc, const char *argv[]) {
  dispatch_queue_t queue;
  int data[NR_ITEMS];

  /* Get Global Dispatch Queue */
  queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

  /* Initialize data Elements, and run computation on each element */
  dispatch_apply_f(NR_ITEMS, queue, data, __fill_item);
  dispatch_apply_f(NR_ITEMS, queue, data, __work_on_item);

  /* Brief review of the items */
  dispatch_apply(NR_ITEMS, queue, ^(size_t n) {
    printf(&quot;Results: Item %lu = %d\n&quot;, n, data[n]);
  });

  return 0;
}
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/grand-central-dispatch-first-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac OS X 10.6 Snow Leopard</title>
		<link>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/</link>
		<comments>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 09:59:49 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Screenshots]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=1195</guid>
		<description><![CDATA[It&#8217;s finally here.  Mac OS X Snow Leopard, The world&#8217;s most advanced operating system. Finely tuned.

Ok, It&#8217;s one week later&#8230; but I&#8217;ve installed it just right now. Maybe tomorrow morning an usage example of Grand Central Dispatch.
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s finally here.  <a title="Apple Mac OS X Snow Leopard" href="http://www.apple.com/mac">Mac OS X Snow Leopard</a>, <em>The world&#8217;s most advanced operating system. Finely tuned.</em></p>
<p style="text-align: left;"><a href="http://th30z.netsons.org/wp-content/uploads/SnowLeopard-01.png"><img class="aligncenter size-large wp-image-1194" title="Mac OS X 10.6 Snow Leopard" src="http://th30z.netsons.org/wp-content/uploads/SnowLeopard-01-1024x640.png" alt="Mac OS X 10.6 Snow Leopard" width="553" height="346" /></a><br />
Ok, It&#8217;s one week later&#8230; but I&#8217;ve installed it just right now. Maybe tomorrow morning an usage example of <a title="Grand Central Dispatch" href="http://en.wikipedia.org/wiki/Grand_Central_Dispatch">Grand Central Dispatch</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/09/mac-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Sidebar with Badges, Take 2</title>
		<link>http://th30z.netsons.org/2009/03/cocoa-sidebar-with-badges-take-2/</link>
		<comments>http://th30z.netsons.org/2009/03/cocoa-sidebar-with-badges-take-2/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 15:13:42 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=588</guid>
		<description><![CDATA[Do you remember the Cocoa Sidebar? No, Take a Look at this post Cocoa Sidebar with Badges.
Joel asked me to revise the Sidebar, allowing to add/remove and do other operation at any time.
I&#8217;ve rewritten all the code of the Sidebar, and I&#8217;ve added a couple of new features, like the default action handler and obviously the ability [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar.png"><img class="size-medium wp-image-403 alignleft" title="Cocoa Sidebar" src="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar-237x350.png" alt="Cocoa Sidebar" width="166" height="245" /></a>Do you remember the Cocoa Sidebar? No, Take a Look at this post <a href="http://th30z.netsons.org/2008/12/cocoa-sidebar-with-badges/">Cocoa Sidebar with Badges</a><a>.</a></p>
<p>Joel asked me to revise the Sidebar, allowing to add/remove and do other operation at any time.</p>
<p>I&#8217;ve rewritten all the code of the Sidebar, and I&#8217;ve added a couple of new features, like the default action handler and obviously the ability to add, remove items and badges at any time.</p>
<p>All the past features, like Drag &amp; Drop are still present, but there&#8217;s something else to do to improve it. If You&#8217;ve suggestions, patches or something else post a comment or send me a mail!</p>
<p>The Source Code is Available Here: <a href="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar2.zip">Cocoa Sidebar 2 Source Code</a>.</p>
<p><em>Update 10 March 2008 &#8211; Source Updated with Fixes.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/03/cocoa-sidebar-with-badges-take-2/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Cocoa: Drag &amp; Drop</title>
		<link>http://th30z.netsons.org/2009/02/cocoa-drag-drop/</link>
		<comments>http://th30z.netsons.org/2009/02/cocoa-drag-drop/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 10:58:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Drag & Drop]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=554</guid>
		<description><![CDATA[Today a simple example of Drag &#38; Drop with Cocoa and NSView. The screenshot below shows two groups. In the first one, you can drop the photos on your filesystem, taken from Desktop or Finder. In the second group, you can only drop the first group image.

You can find the source code here: Drag &#38; [...]]]></description>
			<content:encoded><![CDATA[<p>Today a simple example of Drag &amp; Drop with Cocoa and NSView. The screenshot below shows two groups. In the first one, you can drop the photos on your filesystem, taken from Desktop or Finder. In the second group, you can only drop the first group image.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddrop.png"><img class="aligncenter size-medium wp-image-555" title="Cocoa Drag &amp; Drop Test App" src="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddrop-350x175.png" alt="Cocoa Drag &amp; Drop Test App" width="350" height="175" /></a></p>
<p>You can find the source code here: <a href="http://th30z.netsons.org/wp-content/uploads/cocoa-draganddroptest.zip">Drag &amp; Drop Test Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/02/cocoa-drag-drop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WebKit: Google Maps</title>
		<link>http://th30z.netsons.org/2009/02/webkit-google-maps/</link>
		<comments>http://th30z.netsons.org/2009/02/webkit-google-maps/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 17:12:51 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=512</guid>
		<description><![CDATA[Following the Google StreetView post, another example on How Cocoa Application can Interact with Google. Today the WebKit shows Google Maps.

Like iPhoto &#8216;09 you can select you Map Type (Terrain, Satellite, Hybrid) and you can Zoom In or Zoom Out using controls of your Application.

You can Find the Source Code Here: Cocoa Google Maps.
]]></description>
			<content:encoded><![CDATA[<p>Following the <a href="http://th30z.netsons.org/2009/01/webkit-google-streetview/">Google StreetView</a> post, another example on How Cocoa Application can Interact with Google. Today the WebKit shows Google Maps.<br />
<a href="http://th30z.netsons.org/wp-content/uploads/cocoa-googlemaps-alisoviejo.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoa-googlemaps-alisoviejo-350x265.png" alt="Cocoa Google Maps - Aliso Viejo" title="Cocoa Google Maps - Aliso Viejo" width="350" height="265" class="aligncenter size-medium wp-image-513" /></a><br />
Like iPhoto &#8216;09 you can select you Map Type (Terrain, Satellite, Hybrid) and you can Zoom In or Zoom Out using controls of your Application.<br />
<a href="http://th30z.netsons.org/wp-content/uploads/cocoa-googlemaps-redwood.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoa-googlemaps-redwood-350x276.png" alt="Cocoa Google Maps - Red Wood" title="Cocoa Google Maps - Red Wood" width="350" height="276" class="aligncenter size-medium wp-image-514" /></a><br />
You can Find the Source Code Here: <a href='http://th30z.netsons.org/wp-content/uploads/cocoa-googlemaps.zip'>Cocoa Google Maps</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/02/webkit-google-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebKit: Google StreetView</title>
		<link>http://th30z.netsons.org/2009/01/webkit-google-streetview/</link>
		<comments>http://th30z.netsons.org/2009/01/webkit-google-streetview/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 08:56:38 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[StreetView]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=469</guid>
		<description><![CDATA[Last iPhoto &#8216;09 presented at MacWorld contains a couple of interesting Features: Faces and Places. Today, I&#8217;ve a little bit of free time to play with my Mac, and the topic is How to embed Google StreetView into a Cocoa Application.

The Solution is using WebKit and Google Maps API. We&#8217;ve a simple HTML file that [...]]]></description>
			<content:encoded><![CDATA[<p>Last <a href="http://www.apple.com/ilife/iphoto/">iPhoto</a> &#8216;09 presented at MacWorld contains a couple of interesting Features: Faces and Places. Today, I&#8217;ve a little bit of free time to play with my Mac, and the topic is How to embed <a href="http://maps.google.com/help/maps/streetview/">Google StreetView</a> into a Cocoa Application.<br />
<a href="http://th30z.netsons.org/wp-content/uploads/cocoa-streetview-cuppertino.png"><img class="aligncenter size-medium wp-image-466" title="Cocoa Streetview Cuppertino" src="http://th30z.netsons.org/wp-content/uploads/cocoa-streetview-cuppertino-350x276.png" alt="Cocoa Streetview Cuppertino" width="350" height="276" /></a><br />
The Solution is using WebKit and <a href="http://code.google.com/apis/maps/">Google Maps API</a>. We&#8217;ve a simple HTML file that contains StreetView &#8220;Canvas&#8221; and a couple of javascript methods that interact with GStreetviewPanorama Object.<br />
<a href="http://th30z.netsons.org/wp-content/uploads/cocoa-streetview-sanfrancisco.png"><img class="aligncenter size-medium wp-image-467" title="Cocoa Streetview San Francisco" src="http://th30z.netsons.org/wp-content/uploads/cocoa-streetview-sanfrancisco-350x276.png" alt="Cocoa Streetview San Francisco" width="350" height="276" /></a><br />
The Source Code is Available Here: <a href='http://th30z.netsons.org/wp-content/uploads/googlestreetview.zip'>Cocoa StreetView Source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2009/01/webkit-google-streetview/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WebKit: Dynamic Content</title>
		<link>http://th30z.netsons.org/2008/12/webkit-dynamic-content/</link>
		<comments>http://th30z.netsons.org/2008/12/webkit-dynamic-content/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 10:42:57 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=427</guid>
		<description><![CDATA[Today I&#8217;ve played a bit with WebKit. I Want do something like Cocoa VBox View and NSScrollView but with more flexibility. Below you can see the example result.

The interesting part of this example is How to manage WebKit content,  and how to add something dynamically.
I use webView:decidePolicyForNavigationAction:request:frame:decisionListener: of WebPolicyDelegate Protocol to handle my custom [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve played a bit with <strong>WebKit</strong>. I Want do something like <a href="http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/">Cocoa VBox View and NSScrollView</a> but with more flexibility. Below you can see the example result.</p>
<p><a href="http://th30z.netsons.org/wp-content/uploads/webkitdynamiccontent.png"  title="WebKit Dynamic Content"><img src="http://th30z.netsons.org/wp-content/uploads/webkitdynamiccontent.png" alt="WebKit Dynamic Content" title="WebKit Dynamic Content" width="597" height="394" class="aligncenter size-full wp-image-424" /></a></p>
<p>The interesting part of this example is How to manage WebKit content,  and how to add something dynamically.</p>
<p>I use <em>webView:decidePolicyForNavigationAction:request:frame:decisionListener:</em> of <strong>WebPolicyDelegate Protocol</strong> to handle my custom requests, in this way&#8230;</p>
<pre>
- (void)webView:(WebView *)sender
    decidePolicyForNavigationAction:(NSDictionary *)actionInformation
   request:(NSURLRequest *)request frame:(WebFrame *)frame
   decisionListener:(id)listener
{
    if ([[[request URL] path] isEqualToString:@"PATH to Handle"]) {
        [listener ignore];
        // Handle Request
    } else {
         [listener use];
    }
}
</pre>
<p>&#8230;Then with a little bit of JavaScript I&#8217;ll set my dynamic content loaded from Database or somewhere else.</p>
<pre>
NSArray *args = [NSArray arrayWithObjects:@"Item1Content",
                                  @"Hi, I'm Test 1 Content", nil];
[[webKit windowScriptObject] callWebScriptMethod:@"fillElement"
                               withArguments:args];
</pre>
<p>The <strong>fillElement</strong> method is a simple JS function like this <em>document.getElementById(elem).innerHTML = data;</em></p>
<p>Here you can find the <a href="http://th30z.netsons.org/wp-content/uploads/testwebkit.zip">Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/12/webkit-dynamic-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Sidebar with Badges</title>
		<link>http://th30z.netsons.org/2008/12/cocoa-sidebar-with-badges/</link>
		<comments>http://th30z.netsons.org/2008/12/cocoa-sidebar-with-badges/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 05:31:11 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=402</guid>
		<description><![CDATA[Yesterday, I&#8217;ve written a simple Sidebar controller that can saves you some time and trouble with Cocoa Source List. Nodes and Folders can be drag and dropped into other folders or near other items and you can easily set badges on nodes.
/p>
You can find the example Source Code Here.
And below you can see hot to [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I&#8217;ve written a simple Sidebar controller that can saves you some time and trouble with Cocoa Source List. Nodes and Folders can be drag and dropped into other folders or near other items and you can easily set badges on nodes.<br />
<div id="attachment_403" class="wp-caption aligncenter" style="width: 284px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar.png" alt="Cocoa Sidebar" title="Cocoa Sidebar" width="274" height="403" class="size-full wp-image-403" /></a><p class="wp-caption-text">Cocoa Sidebar</p></div></p>
<p>You can find the example <a href="http://th30z.netsons.org/wp-content/uploads/cocoa-sidebar.zip">Source Code</a> Here.</p>
<p>And below you can see hot to add folders, nodes and set badges.</p>
<pre>
- (void)populateOutlineContents:(id)inObject {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  [sidebar addRootFolder:@"1" name:@"DEVICES"];
  [sidebar addChild:@"1.1" name:@"Machintosh HD"
               icon:[NSImage imageNamed:NSImageNameComputer]
             action:@selector(buttonPres:) target:self];

  [sidebar addRootFolder:@"2" name:@"PLACES"];
  [sidebar addChild:@"2.1"
                url:NSHomeDirectory()
             action:@selector(buttonPres:) target:self];

  [sidebar addRootFolder:@"3" name:@"OTHER."];
  [sidebar addChild:@"3.1" name:@"Bonjour"
               icon:[NSImage imageNamed:NSImageNameBonjour]
             action:@selector(buttonPres:) target:self];
  [sidebar addChild:@"3.2" name:@"Users"
               icon:[NSImage imageNamed:NSImageNameUserGroup]
             action:@selector(buttonPres:) target:self];

  [sidebar clearSelection];

  // Add Badge to Node with Key
  [sidebar setBadge:@"2.1" count:5];
  [sidebar setBadge:@"3.2" count:7];

  [pool release];
}

- (void)buttonPres:(id)sender {
  NSLog(@"Button Press %@", [sender nodeTitle]);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/12/cocoa-sidebar-with-badges/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Objective-C: SQLite Wrapper</title>
		<link>http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/</link>
		<comments>http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 06:41:15 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=317</guid>
		<description><![CDATA[I&#8217;ve written a simple SQLite Wrapper with two Examples one for Mac and one for the iPhone. The Wrapper class has the same source code for both platforms.
Here you can find the Mac Example Source Code and the iPhone Example Source Code.

This is a simple usage example:

Sqlite *sqlite = [[Sqlite alloc] init];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a simple SQLite Wrapper with two Examples one for Mac and one for the iPhone. <em>The Wrapper class has the same source code for both platforms</em>.</p>
<p>Here you can find the <a href="http://th30z.netsons.org/wp-content/uploads/mac-testsqlite.zip">Mac Example Source Code</a> and the <a href="http://th30z.netsons.org/wp-content/uploads/iphone-testsqlite.zip">iPhone Example Source Code</a>.</p>
<div><a href="http://th30z.netsons.org/wp-content/uploads/iphonesqlitetest.png"><img src="http://th30z.netsons.org/wp-content/uploads/iphonesqlitetest-188x350.png" alt="iPhone Test SQLite App" title="iPhone Test SQLite App" width="188" height="350" class="aligncenter size-medium wp-image-318" /></a></div>
<p>This is a simple usage example:</p>
<pre>
Sqlite *sqlite = [[Sqlite alloc] init];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                             NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory
                        stringByAppendingPathComponent:@"SQLiteTest.db"];
if (![sqlite open:writableDBPath])
  return;

[sqlite executeNonQuery:@"CREATE TABLE test (key TEXT NOT NULL, value TEXT);"];
[sqlite executeNonQuery:@"DELETE FROM test;"];
[sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?);",
                        [Sqlite createUuid], @"PROVA"];
[sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?);",
                         [Sqlite createUuid], @"PROVA 2"];
[sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?);",
                         [Sqlite createUuid], @"PROVA 3"];

NSArray *results = [sqlite executeQuery:@"SELECT * FROM test;"];
for (NSDictionary *dictionary in results) {
  NSLog(@"Row");
  for (NSString *key in [dictionary keyEnumerator])
      NSLog(@" - %@ %@", key, [dictionary objectForKey:key]);
}

[results release];
[sqlite release];
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Cocoa: VBox View and NSScrollView</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 09:19:11 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSScrollView]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=299</guid>
		<description><![CDATA[Following the post of yesterday, today I&#8217;ve implemented a simple VBoxView (Vertical Box Layout) that allow you to lines up NSViews vertically.
br />
Here you can find the example Source Code.
]]></description>
			<content:encoded><![CDATA[<p>Following the post of yesterday, today I&#8217;ve implemented a simple VBoxView (Vertical Box Layout) that allow you to lines up NSViews vertically.<br />
<div id="attachment_300" class="wp-caption aligncenter" style="width: 567px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoascrollablensview.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoascrollablensview.png" alt="Cocoa Scrollable NSViews VBox" title="Cocoa Scrollable NSViews VBox" width="557" height="329" class="size-full wp-image-300" /></a><p class="wp-caption-text">Cocoa Scrollable NSViews VBox</p></div><br />
Here you can find the example <a href="http://th30z.netsons.org/wp-content/uploads/cocoavboxscrollview.zip">Source Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-vbox-view-and-nsscrollview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cocoa: Drawing Images, Texts and Shadows</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 10:23:17 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=286</guid>
		<description><![CDATA[Today I&#8217;m playing a bit with Quartz and Cocoa Drawing system (that is based on Quartz).
I&#8217;ve made a simple example that you can see below where I&#8217;ve used custom NSView that draws an Image and a Bezier Path with some text inside, and around the Bezier Path there&#8217;s a Shadow.
&#8230;And this is the drawRect method [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m playing a bit with Quartz and Cocoa Drawing system (that is based on Quartz).</p>
<p>I&#8217;ve made a simple example that you can see below where I&#8217;ve used custom NSView that draws an Image and a Bezier Path with some text inside, and around the Bezier Path there&#8217;s a Shadow.</p>
<div id="attachment_287" class="wp-caption aligncenter" style="width: 577px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoansviewdrawings.png"><img src="http://th30z.netsons.org/wp-content/uploads/cocoansviewdrawings.png" alt="Cocoa Drawing Example" title="Cocoa Drawing Example" width="567" height="243" class="size-full wp-image-287" /></a><p class="wp-caption-text">Cocoa Drawing Example</p></div>
<p>&#8230;And this is the drawRect method source code of the custom NSView.</p>
<pre>
- (void)drawRect:(NSRect)frameRect {
  [NSGraphicsContext saveGraphicsState];

  [[NSColor colorWithCalibratedRed:0.64 green:0.66 blue:0.71 alpha:1.0] set];
  NSRectFill(frameRect);

  /* Draw Shadow */
  NSShadow *shadow = [[NSShadow alloc] init];
  [shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:0.5]];
  [shadow setShadowOffset:NSMakeSize(4.0, -4.0)];
  [shadow setShadowBlurRadius:3.0];
  [shadow set];

  /* Draw Control */
  NSRect myRect = NSMakeRect(80, 50, frameRect.size.width - 120, 60);
  NSBezierPath *path = [NSBezierPath bezierPath];
  [path setLineJoinStyle:NSRoundLineJoinStyle];
  [path appendBezierPathWithRoundedRect:myRect xRadius:8.0 yRadius:8.0];    

  [path moveToPoint:NSMakePoint(80, 75)];
  [path lineToPoint:NSMakePoint(65, 85)];
  [path lineToPoint:NSMakePoint(80, 95)];

  NSColor *startingColor = [NSColor colorWithCalibratedRed:0.90
                                             green:0.92 blue:0.85 alpha:1.0];
  NSColor *endingColor = [NSColor colorWithCalibratedRed:0.81
                                           green:0.83 blue:0.76 alpha:1.0];
  NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:startingColor
                                 endingColor:endingColor] autorelease];
  [path fill];
  [gradient drawInBezierPath:path angle:90];

  [NSGraphicsContext restoreGraphicsState];

  [shadow release];

  NSImage *image = [NSImage imageNamed:NSImageNameUser];
  [image drawInRect:NSMakeRect(15, 50, 50, 50) fromRect:NSZeroRect
                operation:NSCompositeSourceOver fraction:1.0];

  NSString *string = [NSString stringWithString:@"Text\nMore Text"];
  [string drawInRect:NSMakeRect(90, 60, frameRect.size.width - 140, 45)
                        withAttributes:nil];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-drawing-images-texts-and-shadows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Filterbar Control</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 19:30:10 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=273</guid>
		<description><![CDATA[This morning I&#8217;ve created this FilterBar (take a look at the picture below). You can add custom NSView and you can manage you groups with delegates.
Below, I&#8217;ve added a movie&#8230; but it doesn&#8217;t [sizeToFit] the page&#8230; so here is the link of Cocoa Filterbar Demo. And here you can find the Cocoa Filterbar Souce.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_cocoafilterbardemo_736833499"
			class="flashmovie"
			width="400"
			height="100%">
	<param name="movie" value="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf"
			name="fm_cocoafilterbardemo_736833499"
			width="400"
			height="100%">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>]]></description>
			<content:encoded><![CDATA[<p>This morning I&#8217;ve created this <strong>FilterBar</strong> (take a look at the picture below). You can add custom NSView and you can manage you groups with delegates.</p>
<div id="attachment_274" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.png"><img class="size-full wp-image-274" title="Cocoa Filterbar Demo" src="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.png" alt="Cocoa Filterbar Demo" width="500" height="134" /></a><p class="wp-caption-text">Cocoa Filterbar Demo</p></div>
<p>Below, I&#8217;ve added a movie&#8230; but it doesn&#8217;t [sizeToFit] the page&#8230; so here is the link of <a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf">Cocoa Filterbar Demo</a>. And here you can find the <a href="http://th30z.netsons.org/wp-content/uploads/cocoafilterbar.zip">Cocoa Filterbar Souce</a>.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_cocoafilterbardemo_815330238"
			class="flashmovie"
			width="100%"
			height="100%">
	<param name="movie" value="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://th30z.netsons.org/wp-content/uploads/cocoafilterbardemo.swf"
			name="fm_cocoafilterbardemo_815330238"
			width="100%"
			height="100%">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-filterbar-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Horizontal Box</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 17:43:24 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[NSView]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=264</guid>
		<description><![CDATA[It&#8217;s a couple of days that I&#8217;m searching for something like QHBoxLayout (Qt Horizonal Box Layout) in Cocoa. There&#8217;s NSMatrix that do something like this&#8230; but it uses NSCell and it sets the same size for all the cells, so this is not what I want. My solution is a simple NSView subclass&#8230;

This is the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a couple of days that I&#8217;m searching for something like QHBoxLayout (Qt Horizonal Box Layout) in Cocoa. There&#8217;s <em>NSMatrix</em> that do something like this&#8230; but it uses <em>NSCell</em> and it sets the same size for all the cells, so this is not what I want. My solution is a simple <em>NSView subclass</em>&#8230;</p>
<div id="attachment_265" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/testcocoahbox.png"><img class="size-full wp-image-265" title="Cocoa Horizontal Box" src="http://th30z.netsons.org/wp-content/uploads/testcocoahbox.png" alt="Example: Cocoa Horizontal Box" width="500" height="185" /></a><p class="wp-caption-text">Example: Cocoa Horizontal Box</p></div>
<p><span id="more-264"></span><br />
This is the HBox Source&#8230;</p>
<pre>@interface HBox : NSView {
    NSUInteger hspace;
}

@property (readwrite, assign) NSUInteger space;

- (id)initWithFrame:(NSRect)frameRect;

- (void)clearItems;

- (void)addItem:(NSControl *)itemView;
- (void)removeItemAtIndex:(NSUInteger)index;

- (void)moveItem:(NSView *)view space:(NSInteger)space;
- (void)moveItems:(NSInteger) space fromIndex:(NSUInteger)index;
@end</pre>
<pre>@implementation HBox

@synthesize space = hspace;

- (id)initWithFrame:(NSRect)frameRect {
    if ((self = [super initWithFrame:frameRect])) {
        hspace = 4;
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

- (void)clearItems {
    NSArray *subviewArray = [self subviews];
    NSUInteger subviewCount = [subviewArray count];

    while (subviewCount-- &gt; 0) {
        NSView *view = [subviewArray objectAtIndex:0];
        [view removeFromSuperview];
        [view release];
    }

    [self setNeedsDisplay:YES];
}

- (void)removeItemAtIndex:(NSUInteger)index {
    NSView *view = [[self subviews] objectAtIndex:index];
    int viewWidth = -1 * [view frame].size.width - hspace;
    [view removeFromSuperview];
    [view release];

    [self moveItems:viewWidth fromIndex:index];
    [self setNeedsDisplay:YES];
}

- (void)moveItem:(NSView *)view space:(NSInteger)space {
    NSRect rect = [view frame];
    rect.origin.x += space;
    [view setFrame:rect];
}

- (void)moveItems:(NSInteger) space fromIndex:(NSUInteger)index {
    NSArray *subviewArray = [self subviews];
    NSUInteger subviewCount = [subviewArray count];

    for (; index &lt; subviewCount; ++index)
        [self moveItem:[subviewArray objectAtIndex:index] space:space];
}

- (void)addItem:(NSControl *)itemView {
    [itemView sizeToFit];

    NSRect itemFrame = [itemView frame];
    NSView *lastView = [[self subviews] lastObject];
    if (lastView != nil) {
        itemFrame.origin.x = [lastView frame].origin.x +
                             [lastView frame].size.width +
                             hspace;
    } else {
        itemFrame.origin.x = [self bounds].origin.x + hspace;
    }
    itemFrame.origin.y = [self bounds].origin.y;
    [itemView setFrame:itemFrame];

    [self addSubview:itemView];
    [self setNeedsDisplay:YES];
}

@end</pre>
<p>And This is a simple &#8220;Main&#8221; to test the HBox.</p>
<pre>
- (NSTextField *)createTextField:(NSString *)text {
    NSTextField *field = [[NSTextField alloc] init];
    [field setStringValue:text];
    return [field retain];
}

- (NSButton *)createButton:(NSString *)caption {
    NSButton *button = [[NSButton alloc] init];
    [button setBezelStyle:NSRecessedBezelStyle];
    [button setButtonType:NSPushOnPushOffButton];
    [[button cell] setHighlightsBy:(NSCellIsBordered | NSCellIsInsetButton)];
    [button setShowsBorderOnlyWhileMouseInside:YES];
    [button setButtonType:NSOnOffButton];
    [button setTitle:caption];

    return [button retain];
}

- (void)awakeFromNib {
    [box addItem:[self createTextField:@"Label 1"]];
    [box addItem:[self createButton:@"Button 1"]];
    [box removeItemAtIndex:0];
    [box addItem:[self createTextField:@"Label 2"]];
    [box addItem:[self createButton:@"Say"]];
}
</pre>
<p>Download Here the <a href='http://th30z.netsons.org/wp-content/uploads/testcocoahbox.zip'>Test Cocoa HBox Source</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-horizontal-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Look: Look before you launch</title>
		<link>http://th30z.netsons.org/2008/11/quick-look-look-before-you-launch/</link>
		<comments>http://th30z.netsons.org/2008/11/quick-look-look-before-you-launch/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 14:10:37 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[QuickLook]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=254</guid>
		<description><![CDATA[Quick Look is a technology introduced in Mac OS X version 10.5 that enables client applications, such as Spotlight and the Finder, to display thumbnail images and full-size previews of documents.
Here you can Find the source code example: TestQuickLook.zip
]]></description>
			<content:encoded><![CDATA[<p>Quick Look is a technology introduced in Mac OS X version 10.5 that enables client applications, such as Spotlight and the Finder, to display thumbnail images and full-size previews of documents.</p>
<div id="attachment_255" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/picture-7.png"><img class="size-full wp-image-255" title="Quick Look Example" src="http://th30z.netsons.org/wp-content/uploads/picture-7.png" alt="Quick Look Example" width="500" height="379" /></a><p class="wp-caption-text">Quick Look Example</p></div>
<p>Here you can Find the source code example: <a title="TestQuickLook.zip" href="http://th30z.netsons.org/wp-content/uploads/TestQuickLook.zip">TestQuickLook.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/quick-look-look-before-you-launch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoa: Controls Gallery</title>
		<link>http://th30z.netsons.org/2008/11/cocoa-controls-gallery/</link>
		<comments>http://th30z.netsons.org/2008/11/cocoa-controls-gallery/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 10:38:20 +0000</pubDate>
		<dc:creator>Matteo Bertozzi</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://th30z.netsons.org/?p=245</guid>
		<description><![CDATA[Today I don&#8217;t have inspiration&#8230;
So, I don&#8217;t have some code to publish now, but i&#8217;ve made a couple of screenshots that contain some of Cocoa&#8217;s Controls.

Ok&#8230; thanks for this Gallery, but it will be helpful have olso Objects Type&#8230;.
And&#8230; last thing, different types of Windows.
]]></description>
			<content:encoded><![CDATA[<p>Today I don&#8217;t have inspiration&#8230;</p>
<p>So, I don&#8217;t have some code to publish now, but i&#8217;ve made a couple of screenshots that contain some of Cocoa&#8217;s Controls.</p>
<div id="attachment_244" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-controls-105.png"><img class="size-full wp-image-244" title="Cocoa Controls" src="http://th30z.netsons.org/wp-content/uploads/cocoa-controls-105.png" alt="Cocoa Controls" width="500" height="419" /></a><p class="wp-caption-text">Cocoa Controls</p></div>
<p><span id="more-245"></span></p>
<p>Ok&#8230; thanks for this Gallery, but it will be helpful have olso Objects Type&#8230;.</p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 300px"><a href="http://th30z.netsons.org/wp-content/uploads/ib-cocoa-controls-105.png"><img class="size-medium wp-image-250" title="Cocoa Controls - Interface Builder" src="http://th30z.netsons.org/wp-content/uploads/ib-cocoa-controls-105-290x350.png" alt="Cocoa Controls - Interface Builder" width="290" height="350" /></a><p class="wp-caption-text">Cocoa Controls - Interface Builder</p></div>
<p>And&#8230; last thing, different types of Windows.</p>
<div id="attachment_249" class="wp-caption aligncenter" style="width: 510px"><a href="http://th30z.netsons.org/wp-content/uploads/cocoa-windows-105.png"><img class="size-full wp-image-249" title="Cocoa (Hud, Textured, Panel) Window" src="http://th30z.netsons.org/wp-content/uploads/cocoa-windows-105.png" alt="Cocoa (Hud, Textured, Panel) Window" width="500" height="228" /></a><p class="wp-caption-text">Cocoa (HUD, Textured, Panel) Window</p></div>
]]></content:encoded>
			<wfw:commentRss>http://th30z.netsons.org/2008/11/cocoa-controls-gallery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
