Archive for the ‘Programming’ Category

WebView printing

Friday, October 13th, 2006

Printing a WebView seems simple. It responds to print:. So everything’s almost done for you. Just make sure you have the print menu items correctly hooked up to the print: first responder, right? Wrong. Sending the print: message to the WebView will result in only the visible rect being printed. Anything off screen will not print.

To get the entire page to print you need to send print: to the WebView’s documentView: [[[[theWebView mainFrame] frameView] documentView] print:sender]. The entire page will then be printed.

One other gotcha that I had to figure out was printing images. The images are being displayed inside table cells and are defined in the page’s CSS. All CSS images are displayed as background images and a WebView does not print background images by default. You have to turn on the option before sending print:.

WebPreferences* prefs = [theWebView preferences];
[prefs setShouldPrintBackgrounds: YES];

Now all of the images will display and print correctly for me.

Date formatters

Wednesday, June 14th, 2006

I ran into the new mode of operation for NSDateFormatter for the first time tonight and I’m really happy about the changes.  Formatting a date using the format the user configured in the International preferences panel in System Preferences is now 2 lines of code.  You don’t have to look up the format strings in user defaults anymore.  Just call setDateStyle: to set the date format and setTimeStyle: to set the time format.  Valid styles are: NSDateFormatterNoStyle, NSDateFormatterShortStyle, NSDateFormatterMediumStyle, NSDateFormatterLongStyle, and NSDateFormatterFullStyle.  They also added a couple new convenience methods and allowed for a bit more configurability, but the date styles should generally be used so that the user’s settings are respected. 

The only bad part about the new mode is that for the time being Interface Builder only uses the old v10.0 behavior and not the new v10.4 mode.  A formatter for a table column or other UI element has to be manually added in code.  Hopefully the new mode gets added to IB soon.

Hole Punching

Thursday, March 9th, 2006

Just a reminder note for if I ever run into the issue (or want the effect).  NSRectFill sets the current color to the pixels of a rect replacing anything below them.  So if you use a color with an alpha value less then 1, a “hole” will be punched completely through the window.  An NSBezierPath ([[NSBezierPath bezierPathWithRect: rect] fill]) or NSRectFillUsingOperation(NSRect aRect, 
NSCompositingOperation op) should be used instead.

Java Curriculums

Tuesday, January 3rd, 2006

Joel writes about the The Perils of JavaSchools and I couldn’t agree with him more.  It is something that I’ve thought for awhile now due to my education.  I was about half way though my college career when ASU made the switch from C/C++ to Java and I saw a big decline in the quality of my classmates.
(more…)

Favorite File Templates

Sunday, December 4th, 2005

Daniel over at Red Sweater gives a nice little tip for adding a favorites section at the top of Xcode’s new file window.  Since 95% of the time I’m using 1 of 3 templates it should save a couple seconds here and there.  Plus hunting through the list is a pain sometimes.

Frameworks part uno

Tuesday, November 8th, 2005

As with the CoreData entry I’m going to keep this as a running tips/reminders on creating frameworks.  There seems to be a real lack of information regarding them.  Some of the things that seem basic don’t appear to be documented.

(more…)

CoreData Tips

Monday, August 8th, 2005

I’m going to keep this entry as a running tips/reminders on using CoreData for myself.  i’ll be updating as I come across new things to add.  Please leave comments if you have any cool or informative CD tips to add or if you see that I’m doing something really stupid in one of mine.

(more…)

Mailing Lists

Sunday, July 10th, 2005

I decided today to switch all of my mailing lists over to a gmail account.  I wanted to consolidate them all into one incoming email address since I’m sick of replies bouncing due to an unsubscribed email address.  I figured I’d use gmail to let google pick up the tab and so I could use the searching capabilities if I ever need to. I quickly realized what a pain in the ass Apple’s mailing list site is to use.  I had to first unsubscribe to each list I’m on (about a dozen) by entering in the current email address (which I had to look up to verify which account each one was coming in on).  Then subscribe to the new one.  That had repeated for each one.  On top of that, lists.apple.com was running super slow today.  Was literally taking 45 seconds for each page to load.  Now I’m waiting for a subscribe and an unsubscribe email to process for each one.  Lots of fun.

What I’d love to see is an “account” page.  Let me log into the mailing list site once.  Create a profile.  Then simply check and uncheck a box next to each list to subscribe and unsubscribe.  A 30 minute exercise in tedium would be reduces to 30 seconds.  All I would have had to do today is change my profile’s email address. They could even tie it into my ADC account.  Although I would want to option to set an email address for the mailing lists that is separate from the mail ADC email address.  It’s time to make some of these simple everyday tasks easier then the outdated interfaces that have been used for the last 12 years.

All in One Xcode

Tuesday, July 5th, 2005

I really like the All-in-One window feature of Xcode 2.  It has quickly become my favorite windowing mode.  The big thing that I wish it did is “contextual” toolbars in the project view that are dependent on the type of file being edited.  That way I can have the add entity, add relationship, and add attribute items in the toolbar when I’m editing a model but not when I’m editing code.  Like wise, I’d like to have the new breakpoint item when editing code, but not when I’m editing a model.  Looks like it’s time for another feature request bug report.

Xcode macros

Friday, June 10th, 2005

Here’s a cool Xcode trick that I never knew it could do. Type any of the prefixes below and then type control-. (period) to expand them to the full text. Control-/ will then select the next placeholder like it does for code completion. This is a really cool feature. Now I just have to remember all of the prefixes. Thanks go out to Scott for pointing it out.

Obj-C

@try == Try / Catch Block
@catch ==  Catch Block
@finally == Finally Block
log == NSLog() Call
a == Alloc / Init Call
aa ==  Array Declaration
ma ==  Mutable Array Declaration
fora == Array For Loop
init ==  Init Method Definition
dealloc == Dealloc Method Definition
nss == NSString
nsms == NSMutableString
nsma == NSMutableArray
nsd == NSDictionary
nsmd == NSMutableDictionary

C

if == If Block
ifelse == If / Else Block
elseif == Else If Block
for == For Loop
fori == For i Loop
while == While Loop
do == Do While Loop
switch == Switch Block
case == Case Block
else == Else Block
enum == Enum Definition
struct == Struct Definition
union == Union Definition
typedef == Type Definition
printf == Printf() Call
pm == #Pragma Mark
pim == #Import Statement (System)
pimf == #Import Statement (Framework)
pin == #Include Statement
pins == #Include Statement (System)
pif == #If Block
pifd == #Ifdef Block
pife == #If / Else Block
pifde = #Ifdef / Else Block
pifz == #If 0 Block
copyright == Copyright Comment
comment ==  Comment Selection
cseparator == Separator Comment

C++

pifdcpp == #Ifdef __cplusplus Block
pifdecpp == #Ifdef _cplusplus / Else Block
static_cast == Static Cast
dynamic_cast == Dynamic Cast
reinterpret_cast == Reinterpret Cast
try == Try / Catch Block
catch == Catch Block
cout == Cout Statement
coutm == Cout Message
namespace == Namespace Definition
class == Class Definition
extern == Extern \"C\" Statement
externb == Extern \"C\" Block

Java - note: many of the C/C++ macros work for Java

try == Try / Catch Block
catch == Catch Block
finally == Finally Block
println == Println() Call
synchronized == Synchronized Block

HTML

b == Bold
i == Italics
u == Underline
big == Bigger
small == Smaller
title == Title
strike == Strikethrough
sub == Subscript
sup == Superscript
tt == Typewriter Text
code == Code
center == Center
h1 == Heading 1
h2 == Heading 2
h3 == Heading 3
h4 == Heading 4
h5 == Heading 5
h6 == Heading 6
hr == Horizontal rule
a == Link
at == Link With Target
aa == Anchor
ol == Ordered List
ul == Ordered List
li == List Item