055d3a83baef7ab09db05c1a9f12a1baf13f8d7d
[xscreensaver] / OSX / XScreenSaverConfigSheet.h
1 /* xscreensaver, Copyright (c) 2006-2013 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 /* XScreenSaver uses XML files to describe the user interface for configuring
13    the various screen savers.  These files live in .../hacks/config/ and
14    say relatively high level things like: "there should be a checkbox
15    labelled "Leave Trails", and when it is checked, add the option '-trails'
16    to the command line when launching the program."
17
18    This code reads that XML and constructs a Cocoa interface from it.
19    The Cocoa controls are hooked up to NSUserDefaultsController to save
20    those settings into the MacOS preferences system.  The Cocoa preferences
21    names are the same as the resource names specified in the screenhack's
22    'options' array (we use that array to map the command line switches
23    specified in the XML to the resource names to use).
24  */
25
26 #ifdef USE_IPHONE
27 # import <Foundation/Foundation.h>
28 # import <UIKit/UIKit.h>
29 # define NSView UIView
30 # define NSUserDefaultsController NSUserDefaults
31 #else
32 # import <Cocoa/Cocoa.h>
33 #endif
34
35 #import "jwxyz.h"
36
37 #import <Foundation/NSXMLParser.h>
38
39 #undef USE_PICKER_VIEW
40
41 @interface XScreenSaverConfigSheet : 
42 # ifdef USE_IPHONE
43            UITableViewController <NSXMLParserDelegate,
44                                   UITextFieldDelegate
45 #  ifdef USE_PICKER_VIEW
46                                   , UIPickerViewDelegate
47                                   , UIPickerViewDataSource
48 #  endif
49                                   >
50 # else
51            NSWindow <NSXMLParserDelegate>
52 # endif
53 {
54   NSString *saver_name;
55   NSUserDefaultsController *userDefaultsController;
56   NSDictionary *defaultOptions;
57   const XrmOptionDescRec *opts;
58   id xml_root, xml_parsing;
59
60 # ifdef USE_IPHONE
61   UITextField *active_text_field;
62   NSMutableArray *controls;
63   NSMutableArray *pref_ctls;    // UIControl objects, with index = c.tag
64   NSMutableArray *pref_keys;    // ...and their corresponding resources
65 #  ifdef USE_PICKER_VIEW
66   NSMutableArray *picker_values;
67 #  endif
68 # endif
69
70 }
71
72 - (id)initWithXML: (NSData *) xml_data
73           options: (const XrmOptionDescRec *) opts
74        controller: (NSUserDefaultsController *) prefs
75          defaults: (NSDictionary *) defs;
76
77 @end