<?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>notes &#187; webkit</title>
	<atom:link href="http://clearcapsule.com/blog/tag/webkit/feed/" rel="self" type="application/rss+xml" />
	<link>http://clearcapsule.com/blog</link>
	<description>on design, cocoa, and mac</description>
	<lastBuildDate>Tue, 03 Nov 2009 07:39:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>What&#8217;s in a cursor? Part I</title>
		<link>http://clearcapsule.com/blog/2009/10/whats-in-a-cursor-part-i/</link>
		<comments>http://clearcapsule.com/blog/2009/10/whats-in-a-cursor-part-i/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 09:42:27 +0000</pubDate>
		<dc:creator>nsobject</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://clearcapsule.com/blog/?p=17</guid>
		<description><![CDATA[NSTextView has a nice instance method: setAutomaticLinkDetectionEnabled:. When this is set to YES, the textview turns any properly formatted URL into a hyperlink in blue text with a single underline and the pointing hand cursor. It couldn&#8217;t be more straightforward. Query uses this extensively in its result views. With a little tweak here and there, [...]]]></description>
			<content:encoded><![CDATA[<p><code>NSTextView</code> has a nice instance method: <code>setAutomaticLinkDetectionEnabled:</code>. When this is set to <code>YES</code>, the textview turns any properly formatted URL into a hyperlink in blue text with a single underline and the pointing hand cursor. It couldn&#8217;t be more straightforward.</p>

<p><a href="http://clearcapsule.com/query/" target="_blank">Query</a> uses this extensively in its result views. With a little tweak here and there, it plays well with syntax coloring as well:
<img src="http://clearcapsule.com/blog/wp-content/uploads/2009/11/nstextview_cursor.png" alt="NSTextView link cursor" title="NSTextView link cursor" width="284" height="25" class="alignnone size-full wp-image-32" /></p>

<p>While it serves the purpose, it doesn&#8217;t feel quite alright. If you answer yes to any of the following:</p>

<ul>
  <li>Is your primary browser Safari?</li>
  <li>Do you use content readers such as <a href="http://www.newsgator.com/INDIVIDUALS/NETNEWSWIRE/" target="_blank">NetNewsWire</a>, <a href="newsfirerss" target="_blank">newsfire</a>, <a href="http://www.thinkmac.co.uk/newslife/" target="_blank">NewsLife</a>, etc.?</li>
  <li>Do you use site specific browsers such as <a href="http://fluidapp.com/" target="_blank">Fluid</a>, <a href="http://willmore.eu/software/gmailbrowser/" target="_blank">Gmail Browser</a>, <a href="http://mailplaneapp.com/" target="_blank">Mailplane</a>, etc.?</li>
</ul>

<p>you&#8217;re likely to find the default link cursor awkward, ever so slightly, because the same link will look like this in your favorite applications:
<img src="http://clearcapsule.com/blog/wp-content/uploads/2009/11/webkit_cursor.png" alt="WebKit link cursor" title="WebKit link cursor" width="285" height="27" class="alignnone size-full wp-image-35" /></p>

<p>It turns out that WebKit uses its own custom image for the pointing hand cursor: <code>/System/Library/Frameworks/WebKit.framework/WebCore.framework/Resources/linkCursor.png</code></p>

<p>If you are anything like me, you, too, can override the link cursor in your <code>NSTextView</code> subclass with <code>setLinkTextAttributes:</code> instance method.</p>

<p>Here&#8217;s a quick how-to:</p>

<ol>
  <li>Copy the custom cursor image into your project&#8217;s Resources folder.</li>
  <li>In the <code>awakeFromNib</code> method of your controller class, set this custom image as the link cursor:</li>
</ol>


<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>awakeFromNib
<span style="color: #002200;">&#123;</span>
  <span style="color: #11740a; font-style: italic;">/* do standard awakeFromNib stuff */</span>
&nbsp;
  <span style="color: #11740a; font-style: italic;">// prepare attributes</span>
  <span style="color: #400080;">NSCursor</span> <span style="color: #002200;">*</span>customLinkCursor
    <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSCursor</span> alloc<span style="color: #002200;">&#93;</span> initWithImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSImage</span> imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;linkCursor.png&quot;</span><span style="color: #002200;">&#93;</span> 
                                              withHotSpot<span style="color: #002200;">:</span>NSMakePoint<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>customLinkTextAttributes
    <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObject<span style="color: #002200;">:</span>customLinkCursor
                                  forKey<span style="color: #002200;">:</span>NSCursorAttributeName<span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>cutomLinkCursor release<span style="color: #002200;">&#93;</span>;
  customLinkCursor <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
&nbsp;
  <span style="color: #11740a; font-style: italic;">// myCustomTextView is an IBOutlet or an instance variable	</span>
  <span style="color: #002200;">&#91;</span>myCustomTextView setAutomaticLinkDetectionEnabled<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
  <span style="color: #002200;">&#91;</span>myCustomTextView setLinkTextAttributes<span style="color: #002200;">:</span>customLinkTextAttributes<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>


<p>Instead of copying the image file into your project, you could link to the local image in <code>WebCore.framework</code>. In my opinion, however, it would be a bit too much reliance on an unpublished feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://clearcapsule.com/blog/2009/10/whats-in-a-cursor-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
