From http://www.jwz.org/xscreensaver/xscreensaver-5.24.tar.gz
[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   NSUserDefaultsController *globalDefaultsController;
57   NSDictionary *defaultOptions;
58   const XrmOptionDescRec *opts;
59   id xml_root, xml_parsing;
60
61 # ifdef USE_IPHONE
62   UITextField *active_text_field;
63   NSMutableArray *controls;
64   NSMutableArray *pref_ctls;    // UIControl objects, with index = c.tag
65   NSMutableArray *pref_keys;    // ...and their corresponding resources
66 #  ifdef USE_PICKER_VIEW
67   NSMutableArray *picker_values;
68 #  endif
69 # endif
70
71 }
72
73 - (id)initWithXML: (NSData *) xml_data
74           options: (const XrmOptionDescRec *) opts
75        controller: (NSUserDefaultsController *) prefs
76  globalController: (NSUserDefaultsController *) globalPrefs
77          defaults: (NSDictionary *) defs;
78
79 @end