Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #import <Foundation/Foundation.h>
  2. #import <AppKit/AppKit.h>
  3. #import <WebKit/WebKit.h>
  4.  
  5. #import "TinyController.h"
  6.  
  7. int main (int argc, const char * argv[]) {
  8. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9.  
  10. NSApp = [NSApplication sharedApplication];
  11.  
  12. TinyController * controller = [[TinyController alloc] init];
  13. [NSApp setDelegate:controller];
  14.  
  15. [controller navigate:[NSString stringWithCString:(argc > 1 ? argv[1] : "http://ya.ru/")]];
  16.  
  17. [NSApp run];
  18.  
  19. [controller release];
  20. [NSApp release];
  21. [pool release];
  22.  
  23. return EXIT_SUCCESS;
  24. }
  25.  
  26. #import <Foundation/Foundation.h>
  27. #import <AppKit/AppKit.h>
  28. #import <WebKit/WebKit.h>
  29.  
  30. @interface TinyController : NSObject {
  31. NSWindow * window;
  32. WebView * view;
  33. }
  34.  
  35. -(id)init;
  36. -(void)dealloc;
  37.  
  38. -(void)navigate:(NSString *)url_string;
  39.  
  40. -(void)applicationDidFinishLaunching:(NSNotification *)notification;
  41. -(void)windowWillClose:(NSNotification *)notification;
  42. -(void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame;
  43.  
  44. @end
  45.  
  46. #import "TinyController.h"
  47.  
  48. @implementation TinyController
  49.  
  50. -(id)init {
  51. [super init];
  52.  
  53. NSRect geometry = NSMakeRect(0,0,1024,768);
  54.  
  55. view = [[WebView alloc] initWithFrame:geometry];
  56. [view setFrameLoadDelegate:self];
  57.  
  58. window = [[NSWindow alloc] initWithContentRect:geometry
  59. styleMask:NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask
  60. backing:NSBackingStoreBuffered
  61. defer:NO];
  62. [window setTitle:@"Tiny Browser"];
  63.  
  64. [window setContentView:view];
  65. [window setInitialFirstResponder:view];
  66. [window setDelegate:self];
  67. [window center];
  68.  
  69. return self;
  70. }
  71.  
  72. -(void)dealloc {
  73. [window release];
  74. [view release];
  75.  
  76. [super dealloc];
  77. }
  78.  
  79. -(void)navigate:(NSString *)url_string {
  80. [[view mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url_string]]];
  81. }
  82.  
  83. -(void)applicationDidFinishLaunching:(NSNotification *)notification {
  84. [NSApp activateIgnoringOtherApps:YES];
  85. [window makeKeyAndOrderFront:self];
  86. }
  87.  
  88. -(void)windowWillClose:(NSNotification *)notification {
  89. [NSApp terminate:self];
  90. }
  91.  
  92. -(void)webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
  93. NSLog(@"%@ %@",[error localizedFailureReason],[error localizedDescription]);
  94. }
  95.  
  96. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement