1--- Controller.m 2011-06-16 10:35:03.000000000 +0200 2+++ /home/multix/Desktop/Controller.m 2011-06-16 10:38:09.000000000 +0200 3@@ -42,9 +42,11 @@ 4 5 + (NSPanel *)prog_ind 6 { 7- if(_prog_ind_panel==nil){ 8+ if(_prog_ind_panel==nil) 9+ { 10 NSRect pi_frame = 11 NSMakeRect(0, 0, PROG_IND_WIDTH, PROG_IND_HEIGHT); 12+ KnobView *_prog_ind; 13 14 _prog_ind_panel = 15 [[NSPanel alloc] 16@@ -54,8 +56,7 @@ 17 defer:NO]; 18 [_prog_ind_panel setReleasedWhenClosed:NO]; 19 20- KnobView *_prog_ind = 21- [[KnobView alloc] initWithFrame:pi_frame]; 22+ _prog_ind = [[KnobView alloc] initWithFrame:pi_frame]; 23 [_prog_ind_panel setContentView:_prog_ind]; 24 25 [_prog_ind_panel setTitle:_(@"Computing Sudoku")]; 26@@ -184,12 +188,14 @@ 27 - makeInputPanel 28 { 29 int m = NSTitledWindowMask; 30- 31- NSRect frame = 32- {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; 33+ int x; 34+ float margin; 35+ NSButton *button; 36+ NSRect allframe ; 37+ NSRect frame = {{ 0, BUTTON_HEIGHT + DIGIT_FIELD_DIM}, { SDK_DIM, SDK_DIM} }; 38 sdkview = [[SudokuView alloc] initWithFrame:frame]; 39 40- NSRect allframe = frame; 41+ allframe = frame; 42 allframe.size.height += BUTTON_HEIGHT + DIGIT_FIELD_DIM; 43 44 enterPanel = 45@@ -202,10 +208,9 @@ 46 47 [[enterPanel contentView] addSubview:sdkview]; 48 49- float margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; 50+ margin = (SDK_DIM - DIGIT_FIELD_DIM*10)/2; 51 assert(margin>0); 52 53- int x; 54 for(x=1; x<=10; x++){ 55 DigitSource *dgs = 56 [[DigitSource alloc] 57@@ -216,13 +221,12 @@ 58 } 59 60 61- NSButton *button = [NSButton new]; 62+ button = [NSButton new]; 63 [button setTitle:_(@"Enter")]; 64 [button setTarget:self]; 65 [button setAction:@selector(actionEnter:)]; 66 67- [button 68- setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 69+ [button setFrame:NSMakeRect(0, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 70 71 [[enterPanel contentView] addSubview:button]; 72 73@@ -231,8 +235,7 @@ 74 [button setTarget:self]; 75 [button setAction:@selector(actionReset:)]; 76 77- [button 78- setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 79+ [button setFrame:NSMakeRect(SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 80 81 [[enterPanel contentView] addSubview:button]; 82 83@@ -241,8 +244,7 @@ 84 [button setTarget:self]; 85 [button setAction:@selector(actionCancel:)]; 86 87- [button 88- setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 89+ [button setFrame:NSMakeRect(2*SDK_DIM/3, 0, SDK_DIM/3, BUTTON_HEIGHT)]; 90 91 [[enterPanel contentView] addSubview:button]; 92 93@@ -255,40 +257,50 @@ 94 95 - actionEnter:(id)sender 96 { 97- [[NSApplication sharedApplication] 98- stopModal]; 99+ BOOL success; 100+ NSDocumentController *dc; 101+ Document *doc; 102+ Sudoku *sdk; 103+ Sudoku *user; 104+ NSPanel *pi_panel; 105+ KnobView *pi; 106+ NSModalSession solveSession; 107+ float percent, dir; 108+ NSDate *end; 109+ 110+ [[NSApplication sharedApplication] stopModal]; 111 [enterPanel orderOut:self]; 112 113 [palette orderFront:self]; 114 115- NSApplication *app = [NSApplication sharedApplication]; 116- 117- NSDocumentController *dc = 118- [NSDocumentController sharedDocumentController]; 119+ dc = [NSDocumentController sharedDocumentController]; 120 [dc newDocument:self]; 121 122- Document *doc = [dc currentDocument]; 123- Sudoku *sdk = [doc sudoku], *user = [sdkview sudoku]; 124+ doc = [dc currentDocument]; 125+ sdk = [doc sudoku]; 126+ user = [sdkview sudoku]; 127 128 [sdk copyStateFromSource:user]; 129 [sdk guessToClues]; 130 // [sdk cluesToPuzzle]; 131 132- NSPanel *pi_panel = [Controller prog_ind]; 133- KnobView *pi = [pi_panel contentView]; 134+ pi_panel = [Controller prog_ind]; 135+ pi = [pi_panel contentView]; 136 137 [pi_panel makeKeyAndOrderFront:self]; 138 139- NSModalSession solveSession; 140- solveSession = [app beginModalSessionForWindow:pi_panel]; 141+ solveSession = [[NSApplication sharedApplication] beginModalSessionForWindow:pi_panel]; 142 143- float percent = 0, dir = 1; 144+ percent = 0; 145+ dir = 1; 146 147- BOOL success; 148- NSDate *end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; 149+ end = [NSDate dateWithTimeIntervalSinceNow:MAX_SOLVE_SECS]; 150 151+ success = NO; 152 do { 153 int tick; 154+ NSDate *now; 155+ 156 for(tick=0; tick<TICK_ITER; tick++){ 157 [pi setPercent:percent]; 158 [pi display]; 159@@ -305,9 +317,9 @@ 160 dir = +1; 161 } 162 163- [app runModalSession:solveSession]; 164+ [[NSApplication sharedApplication] runModalSession:solveSession]; 165 166- NSDate *now = [NSDate date]; 167+ now = [NSDate date]; 168 if([now laterDate:end]==now){ 169 break; 170 } 171@@ -316,7 +328,7 @@ 172 } while(success==NO); 173 174 [pi_panel orderOut:self]; 175- [app endModalSession:solveSession]; 176+ [[NSApplication sharedApplication] endModalSession:solveSession]; 177 178 if(success==NO){ 179 NSRunAlertPanel(_(@"Solve failed"), 180@@ -401,6 +413,7 @@ 181 182 - makeDigitPalette 183 { 184+ int x, y; 185 NSRect pbounds = 186 NSMakeRect(0, 0, 2*DIGIT_FIELD_DIM, 5*DIGIT_FIELD_DIM); 187 188@@ -425,7 +438,6 @@ 189 [palette setFrameAutosaveName: @"SudokuDigitPalette"]; 190 191 192- int x, y; 193 for(x=0; x<2; x++){ 194 for(y=0; y<5; y++){ 195 DigitSource *dgs = 196