-
Notifications
You must be signed in to change notification settings - Fork 4
/
wxSingleChoiceDialog.cpp
194 lines (149 loc) · 4.61 KB
/
wxSingleChoiceDialog.cpp
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
/*
* wxSingleChoiceDialog.cpp
*
* Created on: 08.12.2013
* Author: hanmac
*/
#include "wxAnyChoiceDialog.hpp"
#include "wxSingleChoiceDialog.hpp"
#include "wxApp.hpp"
VALUE rb_cWXSingleChoiceDialog;
#if wxUSE_CHOICEDLG
#define _self unwrap<wxSingleChoiceDialog*>(self)
namespace RubyWX {
namespace SingleChoiceDialog {
APP_PROTECT(wxSingleChoiceDialog)
macro_attr(Selection,int)
singlereturn(GetStringSelection)
/*
* call-seq:
* SingleChoiceDialog.new(parent, name, [options])
* SingleChoiceDialog.new(parent, [options])
*
* creates a new SingleChoiceDialog widget.
* ===Arguments
* * parent of this window or nil
* * name is a String describing a resource in a loaded xrc
*
* *options: Hash with possible options to set:
* * choices [string]
* * selection Integer
* * message String
* * caption String
*
*/
DLL_LOCAL VALUE _initialize(int argc,VALUE *argv,VALUE self)
{
VALUE parent,name,hash;
rb_scan_args(argc, argv, "11:",&parent,&name,&hash);
if(!_created && !rb_obj_is_kind_of(hash,rb_cString)){
int style(wxCHOICEDLG_STYLE);
wxArrayString choices;
wxString message(wxEmptyString);
wxString caption(wxEmptyString);
if(rb_obj_is_kind_of(hash,rb_cHash)){
set_hash_option(hash,"style",style);
set_hash_option(hash,"choices",choices);
set_hash_option(hash,"message",message);
set_hash_option(hash,"caption",caption);
}
_self->Create(unwrap<wxWindow*>(parent),message,caption,choices,(void **)NULL,style);
}
rb_call_super(argc,argv);
if(rb_obj_is_kind_of(hash,rb_cHash)) {
set_ruby_option(hash, "selection", _setSelection, self);
}
return self;
}
/*
* call-seq:
* single_choice(message, caption, choices, [options]) -> String/Integer
*
* creates a new SingleChoiceDialog widget.
* ===Arguments
* * message for the Dialog. String
* * caption for the Dialog. String
* * choices [string]
*
* *options: Hash with possible options to set:
* *
* * selection Integer
* * parent of this window or nil
* * x of the dialog Integer
* * y of the dialog Integer
* * width of the dialog Integer
* * height of the dialog Integer
* * center if the dialog is center aligned true/false
* * index if the dialog should return index instead of String true/false
*
*/
VALUE _GetSingleChoice(int argc,VALUE *argv,VALUE self)
{
VALUE message,caption,choices,hash;
rb_scan_args(argc, argv, "30:",&message,&caption,&choices,&hash);
app_protected();
wxWindow *parent = NULL;
int x(wxDefaultCoord);
int y(wxDefaultCoord);
bool centre(true);
int width(wxCHOICE_WIDTH);
int height(wxCHOICE_HEIGHT);
int selection(-1);
bool index(false);
wxArrayString cchoices = unwrap<wxArrayString>(choices);
wxString cmessage = unwrap<wxString>(message);
wxString ccaption = unwrap<wxString>(caption);
if(rb_obj_is_kind_of(hash,rb_cHash))
{
set_hash_option(hash,"parent",parent);
set_hash_option(hash,"x",x);
set_hash_option(hash,"y",y);
set_hash_option(hash,"center",centre);
set_hash_option(hash,"width",width);
set_hash_option(hash,"height",height);
set_hash_option(hash,"index",index);
if(set_hash_option(hash,"selection",selection))
if(!check_index(selection,cchoices.GetCount()))
return Qnil;
}
if(index) {
return wrap(wxGetSingleChoiceIndex(
cmessage, ccaption, cchoices,
parent, x, y, centre, width, height, selection
));
}else {
return wrap(wxGetSingleChoice(
cmessage, ccaption, cchoices,
parent, x, y, centre, width, height, selection
));
}
}
}
}
#endif
/* Document-attr: selection
* Integer/nil the index of the current selected choice, or nil if none is selected.
*/
/* Document-attr: string_selection
* String the current selected choice, empty string if none is selected
*/
DLL_LOCAL void Init_WXSingleChoiceDialog(VALUE rb_mWX)
{
#if 0
rb_cWXAnyChoiceDialog = rb_define_class_under(rb_mWX,"AnyChoiceDialog",rb_cWXDialog);
#endif
#if wxUSE_CHOICEDLG
using namespace RubyWX::SingleChoiceDialog;
rb_cWXSingleChoiceDialog = rb_define_class_under(rb_mWX,"SingleChoiceDialog",rb_cWXAnyChoiceDialog);
rb_define_alloc_func(rb_cWXSingleChoiceDialog,_alloc);
#if 0
rb_define_attr(rb_cWXSingleChoiceDialog,"selection",1,1);
rb_define_attr(rb_cWXSingleChoiceDialog,"string_selection",1,0);
#endif
rb_define_method(rb_cWXSingleChoiceDialog,"initialize",RUBY_METHOD_FUNC(_initialize),-1);
rb_define_attr_method(rb_cWXSingleChoiceDialog,"selection",_getSelection,_setSelection);
rb_define_attr_method(rb_cWXSingleChoiceDialog,"string_selection",_getSelection,NULL);
rb_define_module_function(rb_mWX,"single_choice",RUBY_METHOD_FUNC(_GetSingleChoice),-1);
registerInfo<wxSingleChoiceDialog>(rb_cWXSingleChoiceDialog);
#endif
}