- (void)mouseDown:(NSEvent *)event
…
while([event type] != NSLeftMouseUp) {
…
Tuesday, March 9, 2010
NSTableView and mouseUp:
When you subclassing NSTableView you will never receive mouseUp event, because NSTableView implements custom event handling loop inside:
Thursday, December 31, 2009
SMS delivery status for iPhone
If you want to have SMS delivery status on your iPhone just start a message with exclamation mark like this:
! Hello.Delivery status is an option of GSM network, not phone. Enjoy!
Wednesday, December 23, 2009
Standalone widgets
You can easily create stand-alone version of any widget from your Mac OS X dashboard. It is really useful feature when you have USB-monitor attached. To do so go to Terminal.app and issue the following:
You need to logout and login back for changes to take effect. After it activate dashboard via keyboard (press F4), drag any widget and deactivate dashboard from keyboard while continuing to drag widget. A little USB display with widgets on it looks great! Widgets could be dragged back to dashboard using same technic.
defaults write com.apple.dashboard devmode YES
You need to logout and login back for changes to take effect. After it activate dashboard via keyboard (press F4), drag any widget and deactivate dashboard from keyboard while continuing to drag widget. A little USB display with widgets on it looks great! Widgets could be dragged back to dashboard using same technic.
Friday, December 18, 2009
Working with vim in international environments
When you are working with more than one keyboard input layout in your system you get bored switching it every time you entering command mode in vim. Here is simple source code to switch layout to english:
Every time you run this program it will switch your language to english. Later I will find out how to use it in vim. Keep in touch with the following gist: SwitchToEnglish.m
int main (int argc, const char *argv[])
{
TISInputSourceRef english = TISCopyInputSourceForLanguage(CFSTR("en-US"));
if (!english)
return 1;
return ((noErr == TISSelectInputSource(english))?0:2);
}
Every time you run this program it will switch your language to english. Later I will find out how to use it in vim. Keep in touch with the following gist: SwitchToEnglish.m
Tuesday, December 1, 2009
Capturing video
Suddenly I have found myself with MS Life Camera HD hooked up to MacPro and it is working good. And capturing video in Leopard is really easy, let's try: create a new project in XCode, add QTKit framework to the list of linked frameworks and create some class to handle window. Now you can get a list of all cameras in your system with:
Drop QTCaptureView on your window, connect it to some outlet (captureView_ in my case) and just go with the following code:
Just that simple, cool!
NSArray *cams = [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
Drop QTCaptureView on your window, connect it to some outlet (captureView_ in my case) and just go with the following code:
- (void)awakeFromNib
{
captureSession_ = [[QTCaptureSession alloc] init];
QTCaptureDevice *device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
NSError *err;
if (![device open:&err]) {
NSLog(@"Could not open device: %@", err);
return;
}
captureDeviceInput_ = [[QTCaptureDeviceInput alloc] initWithDevice:device];
if (![captureSession_ addInput:captureDeviceInput_ error:&err]) {
NSLog(@"Failed to add input %@", err);
return;
}
[captureView_ setCaptureSession:captureSession_];
[captureSession_ startRunning];
}
Just that simple, cool!
Sunday, November 8, 2009
NSTextView background problem
When you want to have a different background color in your NSTextView you model something like this:

But when it gets to real run in your application you suddenly get this:

It looks like background is not being drawn! So what is wrong with NSTextView? Nothing. When you checked draws background in interface builder you tell wrong object to do this job. Placing NSTextView from library pane places NSTextView inside NSScrollView and you tell NSScrollView to draw background. So when text changes it draws it's gray background and as nothing changed in scroll view it doesn't get drawn so it's background isn't drawn. All you need to do is select your text view:

and check draws background only for it. Note, that in interface builder your interface will look wrong but it will be right when you will actually run program!

But when it gets to real run in your application you suddenly get this:

It looks like background is not being drawn! So what is wrong with NSTextView? Nothing. When you checked draws background in interface builder you tell wrong object to do this job. Placing NSTextView from library pane places NSTextView inside NSScrollView and you tell NSScrollView to draw background. So when text changes it draws it's gray background and as nothing changed in scroll view it doesn't get drawn so it's background isn't drawn. All you need to do is select your text view:

and check draws background only for it. Note, that in interface builder your interface will look wrong but it will be right when you will actually run program!
Friday, October 30, 2009
Mouse up in NSSlider (System preferences like values)
There is a nice feature in Energy saver pane of System Preferences: humanized time value entry via sliders. When you drag slider it's exact value appears on the right and when you drop it numbers disappear. And that is good, because you have a one look feeling of quantity of time which will pass before computer or display should go to sleep and window isn't cluttered with rows of exact numerical values. Numbers are hidden, but when you need them they appear and give you a precise control. Just great! Let's implement this functionality. You don't need to subclass NSSlider for this, all code will reside in window controller. Set up variable for label and action for scroller:
By using a small trick with removing and then adding perform selector request to run loop we have a method which will only be fired if sliderMoved messages will stop to flow, and this is a situation when user stop dragging slider and free mouse button.
Start Interface Builder and model an interface with a text label and a slider. Instantiate your window controller class and connect label to controller's outlet named valueLabel_ and set slider's action to controller's action sliderMoved. Slider should have continuos flag set to fire periodically. Next implement the following methods in controller:
@interface SliderWindowController : NSObject {
IBOutlet NSTextField *valueLabel_;
}
- (IBAction)sliderMoved:(NSSlider *)sender;
@end
And hide value label just after awakened from nib:
- (void)hideUnnecessaryDetails:(id)sender
{
[valueLabel_ setHidden:YES];
}
- (IBAction)sliderMoved:(NSSlider *)sender
{
SEL hideUnnecessaryDetails = @selector(hideUnnecessaryDetails:);
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:hideUnnecessaryDetails object:sender];
[self performSelector:hideUnnecessaryDetails withObject:sender
afterDelay:0.0];
[valueLabel_ setHidden:NO];
}
- (void)awakeFromNib
{
[self hideUnnecessaryDetails:nil];
}
By using a small trick with removing and then adding perform selector request to run loop we have a method which will only be fired if sliderMoved messages will stop to flow, and this is a situation when user stop dragging slider and free mouse button.
Subscribe to:
Posts (Atom)