1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
// request.h
/******************************************************************************
*
* MiXViews - an X window system based sound & data editor/processor
*
* Copyright (c) 1993, 1994 Regents of the University of California
*
* Author: Douglas Scott
* Date: December 13, 1994
*
* Permission to use, copy and modify this software and its documentation
* for research and/or educational purposes and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation. The author reserves the right to distribute this
* software and its documentation. The University of California and the author
* make no representations about the suitability of this software for any
* purpose, and in no event shall University of California be liable for any
* damage, loss of data, or profits resulting from its use.
* It is provided "as is" without express or implied warranty.
*
******************************************************************************/
// a Request is sent from a Requestor to a Controller, giving it a set of
// QueryItems, which contain variables to assign values to, labels for querying
// for those variables, and a pointer to a function to check the entered chars.
// The Controller then passes the Request to the DialogConstructor, where the
// QueryItem instances are passed to the GUI components. After the parameters
// are set by the user, the Request hands those values back to the Requester.
// Many Requests are merely to display a message for the user, or ask for
// confirmation of some operation, or allow a simple choice. These contain
// "read-only" QueryItems which contain text strings to display.
// See query.h, requester.h, and dialog_ctor.h.
#ifndef REQUEST_H
#ifdef __GNUG__
#pragma interface
#endif
#define REQUEST_H
#include "localdefs.h"
#include <InterViews/resource.h>
#include "range.h"
class QueryItem;
struct QueryLink {
QueryLink(QueryItem *q);
virtual ~QueryLink();
QueryItem *element;
QueryLink *next;
};
class String;
class QueryList {
public:
QueryList(const char *lbl=nil);
virtual ~QueryList();
void append(QueryItem *);
void start() { current = head; }
boolean more() { return current != nil; }
void next() { if(more()) current = current->next; }
const char *label();
QueryItem* item() { return current->element; }
private:
QueryLink *tail();
private:
String *listLabel;
QueryLink *current;
QueryLink *head;
};
class QueryButton;
class ButtonList : public QueryList {
public:
ButtonList(const char *lbl=nil, Response defaultsTo=Yes)
: QueryList(lbl), default_response(defaultsTo) {}
virtual ~ButtonList() {}
QueryButton* item() { return (QueryButton *) QueryList::item(); }
Response defaultResponse() { return default_response; }
private:
Response default_response;
};
class QueryValue;
class ValueList : public QueryList {
public:
ValueList(const char *lbl=nil) : QueryList(lbl) {}
virtual ~ValueList() {}
QueryValue* item() { return (QueryValue *) QueryList::item(); }
};
class QueryChoice;
class ChoiceList : public QueryList {
public:
ChoiceList(const char *lbl=nil) : QueryList(lbl) {}
virtual ~ChoiceList() {}
QueryChoice* item() { return (QueryChoice *) QueryList::item(); }
};
enum RequestType { AlertType=0, ConfirmerType, ChoiceType, InputType };
struct QueryInfo;
struct QueryLabelInfo;
struct QueryButtonInfo;
class DialogConstructor;
class QueryReturn;
class QueryFile;
class RequestDelegate;
class Request : public Resource {
friend DialogConstructor;
public:
Request(const QueryInfo *, RequestDelegate *delegate=nil);
Request(const char *label, RequestDelegate *delegate=nil);
virtual ~Request();
boolean hasLabels() { return labelList != nil; }
boolean hasBrowser() { return browserQuery != nil; }
boolean hasValues() { return valueList != nil; }
boolean hasChoices() { return choiceList != nil; }
boolean useBell() { return bell; }
virtual boolean print(FILE *);
virtual RequestType type() { return InputType; } // default
void appendLabel(const char *);
void appendLabel(const char *, const char *);
void addFileBrowser(String* path, const char* suffixes=nil);
void appendValue(QueryValue *);
void appendValue(const char *, String* value);
void appendValue(const char *, int *, const Range& =AllIntegers,
boolean show=false);
void appendValue(const char *, unsigned short *,
const Range& =NonNegativeShorts, boolean show=false);
void appendValue(const char *, float *, const Range& =AllNumbers,
boolean show=false);
void appendValue(const char *, double *, const Range& =AllNumbers,
boolean show=false);
void appendChoice(const char *, const char *lbls, ChoiceValue* states,
boolean excl=true);
void appendButton(const char *, Response);
boolean checkValues();
void setBell(boolean b) { bell = b; }
protected:
Request() : myDelegate(nil) { init(); } // used by derived classes
void newLabelList();
void newValueList();
void newButtonList();
virtual void createLabelList(QueryLabelInfo *);
virtual void createButtonList(QueryButtonInfo *, Response r=Yes);
protected:
QueryList* labelList;
QueryFile* browserQuery;
ValueList* valueList;
ChoiceList* choiceList;
ButtonList* buttonList;
private:
void init();
private:
RequestDelegate *myDelegate;
boolean bell; // flag for bell ring
};
// subclass for requests which open browser for file selection
class FileRequest : public Request {
public:
FileRequest(const char* title, String* dir,
const char* suffix=nil, RequestDelegate *delegate=nil);
};
// intermediate, abstract base class for following classes
class MessageRequest : public Request {
protected:
MessageRequest(const char* m1, const char* m2, const char* m3);
};
// AlertRequest only asks for a message display and a single "ok" button
class AlertRequest : public MessageRequest {
typedef MessageRequest Super;
friend DialogConstructor;
public:
AlertRequest(const char* m1, const char* m2=nil, const char* m3=nil,
const char* =" ok ");
virtual RequestType type() { return AlertType; }
private:
void init(const char*);
};
// ConfirmRequest asks for a message display and a confirm-cancel button pair
class ConfirmRequest : public MessageRequest {
typedef MessageRequest Super;
friend DialogConstructor;
public:
ConfirmRequest(const char *m1, const char *m2=nil,
const char *m3=nil, Response r=Yes,
const char* ="confirm", const char* ="cancel");
virtual RequestType type() { return ConfirmerType; }
private:
void init(Response, const char*, const char*);
};
// ChoiceRequest asks for a message display and yes, no, and cancel buttons
class ChoiceRequest : public MessageRequest {
typedef MessageRequest Super;
friend DialogConstructor;
public:
ChoiceRequest(const char *m1, const char *m2=nil, const char *m3=nil,
Response r=Yes, const char* =" yes ", const char* =" no ",
const char* ="cancel");
virtual RequestType type() { return ChoiceType; }
private:
void init(Response, const char*, const char*, const char*);
};
extern QueryButtonInfo defaultInputButtonInfo[];
#endif
|