+- (void)newGame:(id)sender
+{
+ [self processButton:'n' x:-1 y:-1];
+}
+- (void)restartGame:(id)sender
+{
+ [self processButton:'r' x:-1 y:-1];
+}
+- (void)undoMove:(id)sender
+{
+ [self processButton:'u' x:-1 y:-1];
+}
+- (void)redoMove:(id)sender
+{
+ [self processButton:'r'&0x1F x:-1 y:-1];
+}
+
+- (void)clearTypeMenu
+{
+ while ([typemenu numberOfItems] > 1)
+ [typemenu removeItemAtIndex:0];
+}
+
+- (void)becomeKeyWindow
+{
+ int n;
+
+ [self clearTypeMenu];
+
+ [super becomeKeyWindow];
+
+ n = midend_num_presets(me);
+
+ if (n > 0) {
+ [typemenu insertItem:[NSMenuItem separatorItem] atIndex:0];
+ while (n--) {
+ char *name;
+ game_params *params;
+ DataMenuItem *item;
+
+ midend_fetch_preset(me, n, &name, ¶ms);
+
+ item = [[[DataMenuItem alloc]
+ initWithTitle:[NSString stringWithCString:name]
+ action:NULL keyEquivalent:@""]
+ autorelease];
+
+ [item setEnabled:YES];
+ [item setTarget:self];
+ [item setAction:@selector(presetGame:)];
+ [item setPayload:params];
+
+ [typemenu insertItem:item atIndex:0];
+ }
+ }
+}
+
+- (void)resignKeyWindow
+{
+ [self clearTypeMenu];
+ [super resignKeyWindow];
+}
+
+- (void)close
+{
+ [self clearTypeMenu];
+ [super close];
+}
+
+- (void)resizeForNewGameParams
+{
+ NSSize size = {0,0};
+ int w, h;
+
+ midend_size(me, &w, &h);
+ size.width = w;
+ size.height = h;
+
+ NSDisableScreenUpdates();
+ [self setContentSize:size];
+ [self setupContentView];
+ NSEnableScreenUpdates();
+}
+
+- (void)presetGame:(id)sender
+{
+ game_params *params = [sender getPayload];
+
+ midend_set_params(me, params);
+ midend_new_game(me);
+
+ [self resizeForNewGameParams];
+}
+