<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Making good progress on coming up to speed on Cocoa. Here's my latest doodle:</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(defclass test-window () (ns-window ns-view))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(defmethod initialize-instance :after ((w test-window) &rest args)</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><div> (ccl::with-autorelease-pool</div><div> (let* ((rect (ns:make-ns-rect 0 0 300 300))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (nsw (make-instance 'ns:ns-window</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> :with-content-rect rect</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> :style-mask (logior #$NSTitledWindowMask</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> #$NSClosableWindowMask</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> #$NSMiniaturizableWindowMask</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> #$NSResizableWindowMask)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> :backing #$NSBackingStoreBuffered</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> :defer t))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (nsv (#/autorelease (make-instance 'empty-view))))</div><div> (setf (slot-value w 'ns-window) nsw)</div><div> (setf (slot-value w 'ns-view) nsv)</div><div> (#/setTitle: nsw #@"Test")</div><div> (#/setContentView: nsw nsv)</div><div> (#/center nsw)</div><div> (#/orderFront: nsw nil)</div><div> (#/contentView nsw))))</div></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(defclass empty-view (ns:ns-view)</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"> ()</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"> (:metaclass ns:+ns-object))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf w (make-instance 'test-window))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf v (slot-value w 'ns-view))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf b (make-instance 'ns:ns-text-view :init-with-frame (ns:make-ns-rect 0 0 300 300)))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf ts (#/textStorage b))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(#/addSubview: v b)</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(#/insertText: b #@"foo baz bar bing biff")</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf monaco9 (#/fontWithName:size: (find-class 'ns:ns-font) #@"Monaco" 9.0))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf helvetica12 (#/fontWithName:size: (find-class 'ns:ns-font) #@"Helvetica" 12.0))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf fm (#/sharedFontManager (find-class 'ns:ns-font-manager)))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf monaco9-bold (#/convertFont:toHaveTrait: fm monaco9 #$NSBoldFontMask))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf helvetica12-italic (#/convertFont:toHaveTrait: fm helvetica12 #$NSItalicFontMask))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(setf helvetica12-bold (#/convertFont:toHaveTrait: fm helvetica12 #$NSBoldFontMask))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;"><br class="webkit-block-placeholder"></span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(#/setSelectedRange: b (ns:make-ns-range 3 5))</span></font></div><div><font class="Apple-style-span" face="Monaco" size="1"><span class="Apple-style-span" style="font-size: 9px;">(#/addAttribute:value:range: ts #@"NSFont" helvetica12-bold (#/selectedRange b))</span></font></div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>It brings up an editor window, inserts some text, and makes some of it bold. Anything I should be doing differently?</div><div><br class="webkit-block-placeholder"></div><div>I know at least one thing that I'm doing Wrong, namely, making the text bold by setting the font to a fixed bold font instead of scanning the selected range, pulling out the fonts that are already applied, and making them bold. But this seems like a lot of complexity to do something that it seems to me ought to be very simple, so I thought I'd post this code and get a mid-course correction before I dove in deeper.</div><div><br class="webkit-block-placeholder"></div><div>There's another thing that doesn't feel quite right, and that is having to gin up both an ns-window and an ns-view and make the ns-view be the ContentView of the ns-window. Back in the good old days of MCL, window inherited from view (so you could add subviews directly to a window), but ns-window doesn't inherit from ns-view so it seems this little jigjog is necessary. Is that right?</div><div><br class="webkit-block-placeholder"></div><div>Thanks!</div><div>rg</div><div><br class="webkit-block-placeholder"></div></body></html>