xref: /petsc/systems/Apple/iOS/examples/Basic/Classes/iphoneViewController.m (revision c20d77252dee0f9c80fc6f8b1a6f948e11175edb) !
1fce0c873SBarry Smith//
2fce0c873SBarry Smith//  iphoneViewController.m
3fce0c873SBarry Smith//  iphone
4fce0c873SBarry Smith//
5fce0c873SBarry Smith//  Created by Barry Smith on 5/12/10.
6fce0c873SBarry Smith//  Copyright __MyCompanyName__ 2010. All rights reserved.
7fce0c873SBarry Smith//
8fce0c873SBarry Smith
9fce0c873SBarry Smith#import "iphoneViewController.h"
10fce0c873SBarry Smith#include "PETSc/petsc.h"
11fce0c873SBarry Smith
12fce0c873SBarry Smith@implementation iphoneViewController
13fce0c873SBarry Smith@synthesize textField;
14fce0c873SBarry Smith@synthesize textView;
15fce0c873SBarry Smith@synthesize outPut;
16fce0c873SBarry Smith
17fce0c873SBarry Smith
18fce0c873SBarry Smith/*
19fce0c873SBarry Smith// The designated initializer. Override to perform setup that is required before the view is loaded.
20fce0c873SBarry Smith- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
21fce0c873SBarry Smith    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
22fce0c873SBarry Smith        // Custom initialization
23fce0c873SBarry Smith    }
24fce0c873SBarry Smith    return self;
25fce0c873SBarry Smith}
26fce0c873SBarry Smith*/
27fce0c873SBarry Smith
28fce0c873SBarry Smith/*
29fce0c873SBarry Smith// Implement loadView to create a view hierarchy programmatically, without using a nib.
30fce0c873SBarry Smith- (void)loadView {
31fce0c873SBarry Smith}
32fce0c873SBarry Smith*/
33fce0c873SBarry Smith
34fce0c873SBarry Smith
35fce0c873SBarry Smith/*
36fce0c873SBarry Smith// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
37fce0c873SBarry Smith- (void)viewDidLoad {
38fce0c873SBarry Smith    [super viewDidLoad];
39fce0c873SBarry Smith}
40fce0c873SBarry Smith*/
41fce0c873SBarry Smith
42fce0c873SBarry Smith
43fce0c873SBarry Smith/*
44fce0c873SBarry Smith// Override to allow orientations other than the default portrait orientation.
45fce0c873SBarry Smith- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
46fce0c873SBarry Smith    // Return YES for supported orientations
47fce0c873SBarry Smith    return (interfaceOrientation == UIInterfaceOrientationPortrait);
48fce0c873SBarry Smith}
49fce0c873SBarry Smith*/
50fce0c873SBarry Smith
51fce0c873SBarry Smith- (void)didReceiveMemoryWarning {
52fce0c873SBarry Smith	// Releases the view if it doesn't have a superview.
53fce0c873SBarry Smith    [super didReceiveMemoryWarning];
54fce0c873SBarry Smith
55fce0c873SBarry Smith	// Release any cached data, images, etc that aren't in use.
56fce0c873SBarry Smith}
57fce0c873SBarry Smith
58fce0c873SBarry Smith- (void)viewDidUnload {
59fce0c873SBarry Smith	// Release any retained subviews of the main view.
60fce0c873SBarry Smith	// e.g. self.myOutlet = nil;
61fce0c873SBarry Smith}
62fce0c873SBarry Smith
63fce0c873SBarry Smith
64fce0c873SBarry Smith- (void)dealloc {
65fce0c873SBarry Smith  [textField release];
66fce0c873SBarry Smith    [super dealloc];
67fce0c873SBarry Smith}
68fce0c873SBarry Smith
69fce0c873SBarry SmithUITextView *globalTextView;
70fce0c873SBarry Smith
71fce0c873SBarry Smith/*
72fce0c873SBarry Smith   This is called by PETSc for all print calls.
73fce0c873SBarry Smith
74fce0c873SBarry Smith   Simply addeds to the NSString in globalTextView and it gets displayed in the UITextView in the display
75fce0c873SBarry Smith*/
76fce0c873SBarry SmithPetscErrorCode PetscVFPrintfiPhone(FILE *fd,const char *format,va_list Argp)
77fce0c873SBarry Smith{
78fce0c873SBarry Smith  size_t len;
79fce0c873SBarry Smith  char   str[1024];
80fce0c873SBarry Smith
81fce0c873SBarry Smith  PetscVSNPrintf(str,1024,format,&len,Argp);
82fce0c873SBarry Smith  globalTextView.text = [NSString stringWithFormat:@"%@%s", globalTextView.text,str];
83fce0c873SBarry Smith  return 0;
84fce0c873SBarry Smith}
85fce0c873SBarry Smith
86fce0c873SBarry Smith#define main ex19
87fce0c873SBarry Smith#define help help19
88fce0c873SBarry Smith#define Field Field19
89fce0c873SBarry Smith#define PETSC_APPLE_FRAMEWORK
90*c4762a1bSJed Brown#include "../../../../../../src/snes/tutorials/ex19.c"
91fce0c873SBarry Smith#undef main
92fce0c873SBarry Smith#undef help
93fce0c873SBarry Smith#undef Field
94fce0c873SBarry Smith#define main ex48
95fce0c873SBarry Smith#define help help48
96fce0c873SBarry Smith#define Field Field48
97*c4762a1bSJed Brown#include "../../../../../../src/snes/tutorials/ex48.c"
98fce0c873SBarry Smith
99fce0c873SBarry Smith/*
100fce0c873SBarry Smith    This is called each time one hits return in the TextField.
101fce0c873SBarry Smith
102fce0c873SBarry Smith    Converts the string to a collection of arguments that are then passed on to PETSc
103fce0c873SBarry Smith*/
104fce0c873SBarry Smith- (BOOL) textFieldShouldReturn: (UITextField*) theTextField {
105fce0c873SBarry Smith  [theTextField resignFirstResponder]; /* makes the keyboard disappear */
106fce0c873SBarry Smith  textView.text = @"";   /* clears the UITextView */
107fce0c873SBarry Smith  globalTextView = textView;   /* we make this class member a global so can use in PetscVFPrintfiPhone() */
108fce0c873SBarry Smith  textView.font = [UIFont fontWithName:@"Courier" size:8.0]; /* make the font size in the UITextView a more reasonable size  and use fixed width*/
109fce0c873SBarry Smith
110fce0c873SBarry Smith  const char *str = [textField.text UTF8String];
111fce0c873SBarry Smith  char **args;
112fce0c873SBarry Smith  int argc;
113fce0c873SBarry Smith  PetscBool flg1,flg2;
114fce0c873SBarry Smith
115fce0c873SBarry Smith  PetscErrorCode ierr = PetscStrToArray(str,' ',&argc,&args);
116fce0c873SBarry Smith  ierr = PetscStrncmp(str, "./ex19", 6, &flg1);
117fce0c873SBarry Smith  ierr = PetscStrncmp(str, "./ex48", 6, &flg2);
118fce0c873SBarry Smith  if (flg1) {
119fce0c873SBarry Smith    ex19(argc,args);
120fce0c873SBarry Smith  } else if (flg2) {
121fce0c873SBarry Smith    ex48(argc,args);
122fce0c873SBarry Smith  } else {
123fce0c873SBarry Smith    textView.text =@"Must start with ./ex19 or ./ex48";
124fce0c873SBarry Smith    ierr = PetscStrToArrayDestroy(argc,args);
125fce0c873SBarry Smith    return YES;
126fce0c873SBarry Smith  }
127fce0c873SBarry Smith  ierr = PetscStrToArrayDestroy(argc,args);
128fce0c873SBarry Smith  return YES;
129fce0c873SBarry Smith}
130fce0c873SBarry Smith
131fce0c873SBarry Smith@end
132