Newer
Older
/***********************************************************************
* FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
* Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information please contact the author by e-mail
* at "lyle@users.sourceforge.net".
***********************************************************************/
/***********************************************************************
* $Id: FXRuby.cpp 2933 2008-12-29 20:19:33Z lyle $
***********************************************************************/
#ifdef _MSC_VER
#pragma warning (disable : 4786)
#endif
#include "FXRbCommon.h"
#ifndef RUBY_1_9
#include "version.h"
#if RUBY_VERSION_CODE < 167
#define RB_RESCUE2_BROKEN_PROTOTYPE 1
#endif
// The prototype for st_foreach() changed at Ruby version 1.8.2
#if RUBY_VERSION_CODE < 182
#define ST_BROKEN_PROTOTYPES 1
#endif
#endif /* RUBY_1_9 */
#include "impl.h"
#ifdef __CYGWIN__
#include <io.h> // for get_osf_handle()
#endif
#ifdef HAVE_SIGNAL_H
#include <signal.h> // for definitions of SIGINT, etc.
#endif
#ifndef RUBY_1_9
extern "C" {
#include "rubyio.h" // for GetOpenFile(), etc.
}
#else
#include "ruby/io.h"
#endif
// Symbol table functions from Ruby. If we included "st.h" directly
// we'd be dealing with broken prototypes anyways, so just duplicate
// the needed declarations here with the correct prototypes.
#if defined(ST_BROKEN_PROTOTYPES)
extern "C" {
struct st_table;
typedef char * st_data_t; /* this type changed to unsigned long at Ruby 1.8.2 */
st_table *st_init_strtable();
st_table *st_init_numtable();
int st_lookup(st_table *table, st_data_t key, st_data_t *value);
int st_insert(st_table *table, st_data_t key, st_data_t value);
int st_delete(st_table *table, st_data_t *key, st_data_t *value);
void st_foreach(st_table *table, int (*func)(st_data_t, st_data_t, st_data_t), st_data_t arg);
}
#else
#ifdef RUBY_1_9
#include "ruby/st.h"
#else
extern "C" {
#include "st.h"
}
#endif /* RUBY_1_9 */
#endif /* ST_BROKEN_PROTOTYPES */
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
// Opaque type declaration from SWIG runtime
struct swig_type_info;
// Wrapper around SWIG_TypeQuery() that caches results for performance
swig_type_info *FXRbTypeQuery(const char *desc){
FXASSERT(desc!=0);
static st_table *types=st_init_strtable();
swig_type_info *typeinfo=0;
if(st_lookup(types,reinterpret_cast<st_data_t>(const_cast<char*>(desc)),reinterpret_cast<st_data_t *>(&typeinfo))==0){
typeinfo=SWIG_Ruby_TypeQuery(desc);
st_insert(types,reinterpret_cast<st_data_t>(strdup(desc)),reinterpret_cast<st_data_t>(typeinfo));
}
FXASSERT(typeinfo!=0);
return typeinfo;
}
/**
* The FXRuby_Objects hash table basically maps C++ objects to Ruby instances.
* Each key in the table is a pointer to a C++ object we've seen before, and
* the corresponding value is an FXRubyObjDesc struct (see below) that tells
* us which Ruby instance corresponds to that C++ object.
*/
static st_table * FXRuby_Objects;
/**
* Each value in the FXRuby_Objects hash table is an instance of this
* struct. It identifies the Ruby instance associated with a C++ object.
* It also indicates whether this is merely a "borrowed" reference to
* some C++ object (i.e. it's not one we need to destroy later).
*/
struct FXRubyObjDesc {
VALUE obj;
bool borrowed;
};
/**
* FXRbNewPointerObj() is a wrapper around SWIG_Ruby_NewPointerObj() that also
* registers this C++ object & Ruby instance pair in our FXRuby_Objects
* hash table. This function should only get called for methods that return
* a reference to an already-existing C++ object (i.e. one that FOX "owns")
* and for that reason we mark these objects as "borrowed".
*/
VALUE FXRbNewPointerObj(void *ptr,swig_type_info* ty){
if(ptr!=0){
FXASSERT(ty!=0);
VALUE obj;
FXRubyObjDesc *desc;
if(FXMALLOC(&desc,FXRubyObjDesc,1)){
obj=SWIG_Ruby_NewPointerObj(ptr,ty,1);
desc->obj=obj;
desc->borrowed=true;
st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t>(desc));
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
return obj;
}
else{
FXASSERT(FALSE);
return Qnil;
}
}
else{
return Qnil;
}
}
/**
* FXRbIsBorrowed() returns true if the specified C++ object is one that
* FOX owns (i.e. it's borrowed).
*/
bool FXRbIsBorrowed(void* ptr){
FXASSERT(ptr!=0);
FXRubyObjDesc *desc;
if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(ptr),reinterpret_cast<st_data_t *>(&desc))!=0){
return desc->borrowed;
}
else{
return true;
}
}
/**
* FXRbConvertPtr() is just a wrapper around SWIG_Ruby_ConvertPtr().
*/
void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){
void *ptr;
SWIG_Ruby_ConvertPtr(obj,&ptr,ty,1);
return ptr;
}
// Should we catch exceptions thrown by message handlers?
FXbool FXRbCatchExceptions=FALSE;
// Returns an FXInputHandle for this Ruby file object
FXInputHandle FXRbGetReadFileHandle(VALUE obj) {
#ifdef RUBY_1_9
rb_io_t *fptr;
GetOpenFile(obj, fptr);
FILE *fpr=fptr->stdio_file;
#else
OpenFile *fptr;
GetOpenFile(obj, fptr);
FILE *fpr=GetReadFile(fptr);
#endif /* RUBY_1_9 */
#ifdef WIN32
#ifdef __CYGWIN__
return (FXInputHandle) get_osfhandle(fileno(fpr));
#else
return (FXInputHandle) _get_osfhandle(_fileno(fpr));
#endif
#else
return (FXInputHandle) fileno(fpr);
#endif
}
// Returns an FXInputHandle for this Ruby file object
FXInputHandle FXRbGetWriteFileHandle(VALUE obj) {
#ifdef RUBY_1_9
rb_io_t *fptr;
GetOpenFile(obj, fptr);
FILE *fpw=fptr->stdio_file;
#else
OpenFile *fptr;
GetOpenFile(obj, fptr);
FILE *fpw=GetWriteFile(fptr);
#endif /* RUBY_1_9 */
#ifdef WIN32
#ifdef __CYGWIN__
return (FXInputHandle) get_osfhandle(fileno(fpw));
#else
return (FXInputHandle) _get_osfhandle(_fileno(fpw));
#endif
#else
return (FXInputHandle) fileno(fpw);
#endif
}
// Register this Ruby class instance
void FXRbRegisterRubyObj(VALUE rubyObj,const void* foxObj) {
FXASSERT(!NIL_P(rubyObj));
FXASSERT(foxObj!=0);
FXRubyObjDesc* desc;
FXTRACE((1,"FXRbRegisterRubyObj(rubyObj=%d,foxObj=%p)\n",static_cast<int>(rubyObj),foxObj));
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
if(FXMALLOC(&desc,FXRubyObjDesc,1)){
desc->obj=rubyObj;
desc->borrowed=false;
st_insert(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t>(desc));
}
else{
FXASSERT(FALSE);
}
FXASSERT(FXRbGetRubyObj(foxObj,false)==rubyObj);
}
/**
* Remove this mapping between a Ruby instance and a C++ object
*/
void FXRbUnregisterRubyObj(const void* foxObj){
if(foxObj!=0){
FXRubyObjDesc* desc;
if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
DATA_PTR(desc->obj)=0;
FXFREE(&desc);
st_delete(FXRuby_Objects,reinterpret_cast<st_data_t *>(const_cast<void**>(&foxObj)),reinterpret_cast<st_data_t *>(0));
FXASSERT(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(0))==0);
}
}
}
VALUE to_ruby(const FXObject* obj){
if(obj!=0){
FXString className=obj->getClassName();
if(className.length()>3){
if(className.left(4)=="FXRb"){ className.replace(0,4,"FX"); }
}
FXString desc=className+" *";
return FXRbGetRubyObj(obj,desc.text());
}
return Qnil;
}
/**
* Return the registered Ruby class instance associated with this
* FOX object, or Qnil if not found.
*/
VALUE FXRbGetRubyObj(const void *foxObj,bool searchBoth){
FXRubyObjDesc* desc;
if(foxObj!=0 && st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
FXASSERT(desc!=0);
if(searchBoth){
return desc->obj;
}
else{
return desc->borrowed ? Qnil : desc->obj;
}
}
else{
return Qnil;
}
}
/**
* Return the registered Ruby class instance associated with this
* FOX object, or a new registered instance if not found.
*/
VALUE FXRbGetRubyObj(const void *foxObj,swig_type_info* ty){
if(foxObj!=0){
VALUE rbObj=FXRbGetRubyObj(foxObj,true);
return NIL_P(rbObj) ? FXRbNewPointerObj(const_cast<void*>(foxObj),ty) : rbObj;
}
else{
return Qnil;
}
}
VALUE FXRbGetRubyObj(const void *foxObj,const char *type){
if(foxObj!=0){
FXASSERT(type!=0);
VALUE rbObj=FXRbGetRubyObj(foxObj,true);
return NIL_P(rbObj) ? FXRbNewPointerObj(const_cast<void*>(foxObj),FXRbTypeQuery(type)) : rbObj;
}
else{
return Qnil;
}
}
/**
* Look up the Ruby instance associated with this C++ object, if any, and mark
* that instance as in use.
*
* We previously only marked those Ruby instances that were "non-borrowed"
* references to C++ objects, as a way to reduce the number of Ruby instances
* on the heap.
*/
void FXRbGcMark(void *obj){
if(obj){
/**
* If the 2nd argument to FXRbGetRubyObj() is false, we only mark
* non-borrowed references. This has led to problems in the past
* (see e.g. SourceForge Bug #703721). I think the correct solution
* is to mark any Ruby reference this object, "borrowed" or not;
* so the 2nd argument to FXRbGetRubyObj() is now true.
*
* If you feel compelled to change this back to FXGetRubyObj(obj,false),
* please think about it first. Especially make sure that the shutter.rb
* example program works if you invoke the GC in ShutterWindow#create;
* make sure that the shutter items' contents don't get blown away!
*/
VALUE value=FXRbGetRubyObj(obj,true);
if(!NIL_P(value)){
rb_gc_mark(value);
}
}
}
//----------------------------------------------------------------------
// Returns a Ruby array of floats
VALUE FXRbMakeArray(const FXfloat* values,FXint size){
VALUE result=rb_ary_new();
for(FXint i=0; i<size; i++)
rb_ary_push(result,rb_float_new(values[i]));
return result;
}
// Returns a Ruby array of floats
VALUE FXRbMakeArray(const FXdouble* values,FXint size){
VALUE result=rb_ary_new();
for(FXint i=0; i<size; i++)
rb_ary_push(result,rb_float_new(values[i]));
return result;
}
// Returns a Ruby array of integers
VALUE FXRbMakeArray(const FXint* values,FXint size){
VALUE result=rb_ary_new();
for(FXint i=0; i<size; i++)
rb_ary_push(result,INT2NUM(values[i]));
return result;
}
// Returns a Ruby array of integers
VALUE FXRbMakeArray(const FXuint* values,FXint size){
VALUE result=rb_ary_new();
for(FXint i=0; i<size; i++)
rb_ary_push(result,UINT2NUM(values[i]));
return result;
}
// Returns a Ruby array of integers
VALUE FXRbMakeArray(const FXchar* dashpattern,FXuint dashlength){
VALUE result=rb_ary_new();
for(FXuint i=0; i<dashlength; i++)
rb_ary_push(result,INT2NUM(dashpattern[i]));
return result;
}
// Returns a Ruby array of FXArcs
VALUE FXRbMakeArray(const FXArc* arcs,FXuint narcs){
VALUE result=rb_ary_new();
for(FXuint i=0; i<narcs; i++)
rb_ary_push(result,FXRbGetRubyObj(&arcs[i],"FXArc *"));
return result;
}
// Returns a Ruby array of FXPoints
VALUE FXRbMakeArray(const FXPoint* points,FXuint npoints){
VALUE result=rb_ary_new();
for(FXuint i=0; i<npoints; i++)
rb_ary_push(result,FXRbGetRubyObj(&points[i],"FXPoint *"));
return result;
}
// Returns a Ruby array of FXRectangles
VALUE FXRbMakeArray(const FXRectangle* rectangles,FXuint nrectangles){
VALUE result=rb_ary_new();
for(FXuint i=0; i<nrectangles; i++)
rb_ary_push(result,FXRbGetRubyObj(&rectangles[i],"FXRectangle *"));
return result;
}
// Returns a Ruby array of FXSegments
VALUE FXRbMakeArray(const FXSegment* segments,FXuint nsegments){
VALUE result=rb_ary_new();
for(FXuint i=0; i<nsegments; i++)
rb_ary_push(result,FXRbGetRubyObj(&segments[i],"FXSegment *"));
return result;
}
// Returns a Ruby array of FXColor values
VALUE FXRbMakeColorArray(const FXColor* colors,FXint w,FXint h){
VALUE result=rb_ary_new();
FXint size=w*h;
for(FXuint i=0; i<size; i++)
rb_ary_push(result,to_ruby(colors[i]));
return result;
}
//----------------------------------------------------------------------
/**
* Based on the sender object's class and the selector, convert the message
* data stored in the void pointer (ptr) to a suitable Ruby object.
*
* This function is used when we need to pass message data into a Ruby
* code block (or method) that is acting as a FOX message handler.
*/
static VALUE FXRbConvertMessageData(FXObject* sender,FXObject* recv,FXSelector sel,void* ptr){
FXTRACE((1,"FXRbConvertMessageData(%s(%p),FXSEL(%s,%d),%p)\n",sender->getClassName(),sender,FXDebugTarget::messageTypeName[FXSELTYPE(sel)],FXSELID(sel),ptr));
FXInputHandle fff;
FXushort type=FXSELTYPE(sel);
FXushort id=FXSELID(sel);
FXASSERT(type!=SEL_NONE);
FXASSERT(type!=SEL_LAST);
if(type==SEL_KEYPRESS ||
type==SEL_KEYRELEASE ||
type==SEL_LEFTBUTTONPRESS ||
type==SEL_LEFTBUTTONRELEASE ||
type==SEL_MIDDLEBUTTONPRESS ||
type==SEL_MIDDLEBUTTONRELEASE ||
type==SEL_RIGHTBUTTONPRESS ||
type==SEL_RIGHTBUTTONRELEASE ||
type==SEL_MOTION ||
type==SEL_ENTER ||
type==SEL_LEAVE ||
type==SEL_FOCUSIN ||
type==SEL_FOCUSOUT ||
type==SEL_KEYMAP ||
type==SEL_UNGRABBED ||
type==SEL_PAINT ||
type==SEL_CREATE ||
type==SEL_DESTROY ||
type==SEL_UNMAP ||
type==SEL_MAP ||
type==SEL_CONFIGURE ||
type==SEL_SELECTION_LOST ||
type==SEL_SELECTION_GAINED ||
type==SEL_SELECTION_REQUEST ||
type==SEL_RAISED ||
type==SEL_LOWERED ||
type==SEL_MOUSEWHEEL ||
type==SEL_BEGINDRAG ||
type==SEL_ENDDRAG ||
type==SEL_TIMEOUT ||
type==SEL_CLIPBOARD_LOST ||
type==SEL_CLIPBOARD_GAINED ||
type==SEL_CLIPBOARD_REQUEST ||
type==SEL_CHORE ||
type==SEL_FOCUS_SELF ||
type==SEL_FOCUS_RIGHT ||
type==SEL_FOCUS_LEFT ||
type==SEL_FOCUS_DOWN ||
type==SEL_FOCUS_UP ||
type==SEL_FOCUS_NEXT ||
type==SEL_FOCUS_PREV ||
type==SEL_DND_ENTER ||
type==SEL_DND_LEAVE ||
type==SEL_DND_DROP ||
type==SEL_DND_MOTION ||
type==SEL_DND_REQUEST ||
type==SEL_PICKED ||
type==SEL_SESSION_NOTIFY ||
type==SEL_SESSION_CLOSED) {
return to_ruby(reinterpret_cast<FXEvent*>(ptr));
}
else if(type==SEL_DRAGGED && !sender->isMemberOf(FXMETACLASS(FXGLViewer))){
return to_ruby(reinterpret_cast<FXEvent*>(ptr));
}
else if(type==SEL_SIGNAL){
return to_ruby(static_cast<int>(reinterpret_cast<long>(ptr)));
}
else if(type==SEL_IO_READ ||
type==SEL_IO_WRITE ||
type==SEL_IO_EXCEPT){
#ifdef WIN32
fff=reinterpret_cast<FXInputHandle>(ptr);
#else
fff=static_cast<FXInputHandle>(reinterpret_cast<long>(ptr));
#endif
return Qnil;
}
else if(type==SEL_CLOSE ||
type==SEL_DELETE ||
type==SEL_MINIMIZE ||
type==SEL_RESTORE ||
type==SEL_MAXIMIZE ||
type==SEL_UPDATE ||
type==SEL_QUERY_HELP ||
type==SEL_QUERY_TIP){
FXASSERT(ptr==0);
return Qnil;
}
else if(sender->isMemberOf(FXMETACLASS(FX4Splitter))){
if(type==SEL_CHANGED||type==SEL_COMMAND) return Qnil;
}
else if(sender->isMemberOf(FXMETACLASS(FXArrowButton))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXuint>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXPicker))){
if(type==SEL_COMMAND || type==SEL_CHANGED) return to_ruby(reinterpret_cast<FXPoint*>(ptr));
}
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
else if(sender->isMemberOf(FXMETACLASS(FXButton))){
if(type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_COMMAND) return to_ruby(static_cast<FXuint>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXCheckButton))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXuchar>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXColorBar))){
if(type==SEL_CHANGED || type==SEL_COMMAND){
FXfloat* hsv=reinterpret_cast<FXfloat*>(ptr);
return rb_ary_new3(3,to_ruby(hsv[0]),to_ruby(hsv[1]),to_ruby(hsv[2]));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXColorDialog))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(static_cast<FXColor>(reinterpret_cast<unsigned long>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXColorRing))){
if(type==SEL_CHANGED || type==SEL_COMMAND){
FXfloat* hsv=reinterpret_cast<FXfloat*>(ptr);
return rb_ary_new3(3,to_ruby(hsv[0]),to_ruby(hsv[1]),to_ruby(hsv[2]));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXColorSelector))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(static_cast<FXColor>(reinterpret_cast<unsigned long>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXColorWell))){
if(type==SEL_CHANGED ||
type==SEL_COMMAND ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED) {
VALUE v=to_ruby(static_cast<FXColor>(reinterpret_cast<unsigned long>(ptr)));
return v;
}
}
else if(sender->isMemberOf(FXMETACLASS(FXColorWheel))){
if(type==SEL_CHANGED || type==SEL_COMMAND){
FXfloat* hsv=reinterpret_cast<FXfloat*>(ptr);
return rb_ary_new3(3,to_ruby(hsv[0]),to_ruby(hsv[1]),to_ruby(hsv[2]));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXComboBox))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXchar*>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXDataTarget))){
if(type==SEL_COMMAND || type==SEL_CHANGED){
if(recv->isMemberOf(FXMETACLASS(FXWindow))){
switch(id){
case FXWindow::ID_SETINTVALUE:
return to_ruby(*reinterpret_cast<FXint*>(ptr));
case FXWindow::ID_SETREALVALUE:
return to_ruby(*reinterpret_cast<FXdouble*>(ptr));
case FXWindow::ID_SETSTRINGVALUE:
return to_ruby(*reinterpret_cast<FXString*>(ptr));
case FXWindow::ID_GETINTVALUE:
case FXWindow::ID_GETREALVALUE:
case FXWindow::ID_GETSTRINGVALUE:
FXASSERT(FALSE);
break;
default:
FXASSERT(FALSE);
}
}
else{
// It's not a window object...
FXASSERT(sender->isMemberOf(FXMETACLASS(FXRbDataTarget)));
return dynamic_cast<FXRbDataTarget*>(sender)->getValue();
}
}
}
else if(sender->isMemberOf(FXMETACLASS(FXDial))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXDirBox))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXchar*>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXDockBar))){
if(type==SEL_DOCKED || type==SEL_FLOATED) return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXDockSite *"));
}
else if(sender->isMemberOf(FXMETACLASS(FXFileList))){
if (type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXFoldingList))){
if(type==SEL_COLLAPSED ||
type==SEL_EXPANDED ||
type==SEL_COMMAND ||
type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_OPENED ||
type==SEL_CLOSED ||
type==SEL_SELECTED ||
type==SEL_DESELECTED ||
type==SEL_INSERTED ||
type==SEL_DELETED){
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXFoldingItem *"));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXGLViewer))){
if(type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_DRAGGED){
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXGLObject *"));
}
else if(type==SEL_COMMAND){
if(id==FXWindow::ID_QUERY_MENU)
return to_ruby(reinterpret_cast<FXEvent*>(ptr));
else
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXGLObject *"));
}
else if(type==SEL_LASSOED ||
type==SEL_INSERTED ||
type==SEL_DELETED ||
type==SEL_SELECTED ||
type==SEL_DESELECTED){
VALUE ary=rb_ary_new();
// FXGLObject** objlist=reinterpret_cast<FXGLObject**>(ptr);
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
// FIXME: objlist is a NULL-terminated array of pointers to FXGLObject
return ary;
}
}
else if(sender->isMemberOf(FXMETACLASS(FXGradientBar))){
if(type==SEL_CHANGED){
return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(type==SEL_SELECTED || type==SEL_DESELECTED){
return Qnil;
}
}
else if(sender->isMemberOf(FXMETACLASS(FXHeader))){
if(type==SEL_COMMAND ||
type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_REPLACED ||
type==SEL_INSERTED ||
type==SEL_DELETED) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXIconList))){
if(type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_COMMAND ||
type==SEL_SELECTED ||
type==SEL_DESELECTED ||
type==SEL_REPLACED ||
type==SEL_INSERTED ||
type==SEL_DELETED) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXKnob))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXList))){
if(type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_SELECTED ||
type==SEL_DESELECTED ||
type==SEL_REPLACED ||
type==SEL_INSERTED ||
type==SEL_DELETED ||
type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXListBox))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
else if(type==SEL_CHANGED) return Qnil;
}
else if(sender->isMemberOf(FXMETACLASS(FXMDIChild))){
if(type==SEL_MINIMIZE ||
type==SEL_MAXIMIZE ||
type==SEL_CLOSE ||
type==SEL_RESTORE){
return Qnil;
}
else if(type==SEL_SELECTED ||
type==SEL_DESELECTED){
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXMDIChild *"));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXMDIClient))){
if(type==SEL_CHANGED) return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXMDIChild *"));
}
else if(sender->isMemberOf(FXMETACLASS(FXMenuCheck))){
if(type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXuval>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXMenuRadio))){
if(type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXuval>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXMenuCommand))){
if(type==SEL_COMMAND) return to_ruby(true);
}
else if(sender->isMemberOf(FXMETACLASS(FXOption))){
if(type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXEvent*>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXOptionMenu))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXRadioButton))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXuchar>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXRealSlider))){
if(type==SEL_CHANGED || type==SEL_COMMAND)
return to_ruby(*(reinterpret_cast<FXdouble *>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXRealSpinner))){
if(type==SEL_COMMAND || type==SEL_CHANGED) return to_ruby(*(reinterpret_cast<FXdouble *>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXRecentFiles))){
if(type==SEL_COMMAND) return to_ruby(reinterpret_cast<FXchar*>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXRuler))){
if(type==SEL_CHANGED) return Qnil;
}
else if(sender->isMemberOf(FXMETACLASS(FXScrollBar))){
if(type==SEL_CHANGED || type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXShutter))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXSlider))){
if(type==SEL_CHANGED || type==SEL_COMMAND)
return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXSpinner))){
if(type==SEL_CHANGED || type==SEL_COMMAND)
return to_ruby(static_cast<FXint>(reinterpret_cast<long>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXSplitter))){
if(type==SEL_CHANGED || type==SEL_COMMAND)
return to_ruby(reinterpret_cast<FXWindow *>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXSwitcher))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXTabBar))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXTable))){
if(type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_CHANGED ||
type==SEL_COMMAND ||
type==SEL_SELECTED ||
type == SEL_DESELECTED) return to_ruby(reinterpret_cast<FXTablePos*>(ptr));
else if(type == SEL_INSERTED ||
type == SEL_DELETED ||
type == SEL_REPLACED){
return to_ruby(reinterpret_cast<FXTableRange*>(ptr));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXText))){
if (type == SEL_COMMAND) {
switch(id){
case FXText::ID_COPY_SEL:
case FXText::ID_PASTE_SEL:
case FXText::ID_DELETE_SEL:
return Qnil;
break;
default:
FXASSERT(FALSE);
return reinterpret_cast<VALUE>(ptr); // pass-through as is
}
}
else if(type==SEL_CHANGED){
return to_ruby(static_cast<FXint>(reinterpret_cast<FXival>(ptr)));
}
else if(type==SEL_SELECTED ||
type == SEL_DESELECTED) {
FXint* what=reinterpret_cast<FXint*>(ptr);
FXASSERT(what!=0);
VALUE ary=rb_ary_new();
rb_ary_push(ary,to_ruby(what[0])); // start position of text
rb_ary_push(ary,to_ruby(what[1])); // length of text
return ary;
}
else if(type==SEL_INSERTED || type==SEL_DELETED || type==SEL_REPLACED) {
return to_ruby(reinterpret_cast<FXTextChange*>(ptr));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXTextField))){
if(type==SEL_CHANGED ||
type==SEL_COMMAND ||
type==SEL_VERIFY) return to_ruby(reinterpret_cast<FXchar*>(ptr));
}
else if(sender->isMemberOf(FXMETACLASS(FXToggleButton))){
if(type==SEL_COMMAND) return to_ruby(static_cast<FXuchar>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXToolBarTab))){
if (type==SEL_COMMAND) return to_ruby(static_cast<FXbool>(reinterpret_cast<FXuval>(ptr)));
}
else if(sender->isMemberOf(FXMETACLASS(FXTopWindow))){
if(type==SEL_MINIMIZE ||
type==SEL_MAXIMIZE ||
type==SEL_RESTORE ||
type==SEL_CLOSE){
return Qnil;
}
else if (type==SEL_SESSION_NOTIFY ||
type==SEL_SESSION_CLOSED) {
return to_ruby(reinterpret_cast<FXEvent*>(ptr));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXTreeList))){
if(type==SEL_COLLAPSED ||
type==SEL_EXPANDED ||
type==SEL_COMMAND ||
type==SEL_CHANGED ||
type==SEL_CLICKED ||
type==SEL_DOUBLECLICKED ||
type==SEL_TRIPLECLICKED ||
type==SEL_OPENED ||
type==SEL_CLOSED ||
type==SEL_SELECTED ||
type==SEL_DESELECTED ||
type==SEL_INSERTED ||
type==SEL_DELETED){
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXTreeItem *"));
}
}
else if(sender->isMemberOf(FXMETACLASS(FXTreeListBox))){
if(type==SEL_CHANGED || type==SEL_COMMAND)
return FXRbGetRubyObj(ptr,FXRbTypeQuery("FXTreeItem *"));
}
#ifdef WITH_FXSCINTILLA
else if(sender->isMemberOf(FXMETACLASS(FXScintilla))){
if(type==SEL_COMMAND){
return FXRbGetRubyObj(ptr,FXRbTypeQuery("SCNotification *"));
}
}
#endif
else{
FXTRACE((100,"%s:%d: message data passed through as-is\n",__FILE__,__LINE__));
return reinterpret_cast<VALUE>(ptr); // pass-through as is
}
FXTRACE((100,"%s:%d: message data passed through as-is\n",__FILE__,__LINE__));
return reinterpret_cast<VALUE>(ptr); // pass-through as is
}
/**
* When a Ruby instance (e.g. one of your widgets) calls handle() on another
* object, e.g.
*
* def onUpdAnswer(sender, sel, ptr)
* if theAnswerIsTwo?
* sender.handle(self, FXSEL(SEL_COMMAND,FXWindow::ID_SETVALUE), 2)
* else
* sender.handle(self, FXSEL(SEL_COMMAND,FXWindow::ID_SETVALUE), 3)
* end
* return 1
* end
*
* it's usually the case that this will get passed along to the underlying
* C++ object. In that case, we need to convert the message data (e.g. the
* Fixnums "2" or "3" in the example above) from Ruby objects back into
* the appropriate C++ objects. That's what this function is for.
*/
void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
void *ptr;
static FXint intValue;
static FXint intRange[2];
static FXdouble realValue;
static FXdouble realRange[2];
static FXString stringValue;
static FXColor colorValue;
FXushort type=FXSELTYPE(key);
FXushort id=FXSELID(key);
// Extract the FOX object (the receiver) from this Ruby instance
FXObject* obj;
Data_Get_Struct(recv,FXObject,obj);
FXASSERT(type!=SEL_NONE);
FXASSERT(type!=SEL_LAST);
switch(type){
case SEL_KEYPRESS:
case SEL_KEYRELEASE:
case SEL_LEFTBUTTONPRESS:
case SEL_LEFTBUTTONRELEASE:
case SEL_MIDDLEBUTTONPRESS:
case SEL_MIDDLEBUTTONRELEASE:
case SEL_RIGHTBUTTONPRESS:
case SEL_RIGHTBUTTONRELEASE:
case SEL_MOTION:
case SEL_ENTER:
case SEL_LEAVE:
case SEL_FOCUSIN:
case SEL_FOCUSOUT:
case SEL_KEYMAP:
case SEL_UNGRABBED:
case SEL_PAINT:
case SEL_CREATE:
case SEL_DESTROY:
case SEL_UNMAP:
case SEL_MAP:
case SEL_CONFIGURE:
case SEL_SELECTION_LOST:
case SEL_SELECTION_GAINED:
case SEL_SELECTION_REQUEST:
case SEL_RAISED:
case SEL_LOWERED:
case SEL_MOUSEWHEEL:
case SEL_BEGINDRAG:
case SEL_ENDDRAG:
case SEL_LASSOED:
case SEL_TIMEOUT:
case SEL_CLIPBOARD_LOST:
case SEL_CLIPBOARD_GAINED:
case SEL_CLIPBOARD_REQUEST:
case SEL_CHORE:
case SEL_FOCUS_SELF:
case SEL_FOCUS_RIGHT:
case SEL_FOCUS_LEFT:
case SEL_FOCUS_DOWN:
case SEL_FOCUS_UP:
case SEL_FOCUS_NEXT:
case SEL_FOCUS_PREV:
case SEL_DND_ENTER:
case SEL_DND_LEAVE:
case SEL_DND_DROP:
case SEL_DND_MOTION:
case SEL_DND_REQUEST:
case SEL_PICKED:
SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
return ptr;
case SEL_IO_READ:
case SEL_IO_WRITE:
case SEL_IO_EXCEPT:
return 0; // should be an FXInputHandle?
case SEL_SIGNAL:
return reinterpret_cast<void*>(static_cast<long>(NUM2INT(value)));
case SEL_CLOSE:
case SEL_DELETE:
case SEL_MINIMIZE:
case SEL_RESTORE:
case SEL_MAXIMIZE:
case SEL_UPDATE:
case SEL_QUERY_TIP:
case SEL_QUERY_HELP:
return NULL;
case SEL_VERIFY:
return reinterpret_cast<void*>(StringValuePtr(value));
case SEL_CLICKED:
case SEL_DOUBLECLICKED:
case SEL_TRIPLECLICKED:
case SEL_CHANGED:
case SEL_DESELECTED:
case SEL_SELECTED:
case SEL_INSERTED:
case SEL_REPLACED:
case SEL_DELETED:
case SEL_OPENED:
case SEL_CLOSED:
case SEL_EXPANDED:
case SEL_COLLAPSED:
return NULL;
default:
/* Ignore */
break;
}
if(type==SEL_COMMAND){
// Handle FXText-specific messages
if(obj->isMemberOf(FXMETACLASS(FXText))){
switch(id){
case FXText::ID_COPY_SEL:
case FXText::ID_PASTE_SEL:
case FXText::ID_DELETE_SEL:
return NULL;
default:
break;
}
}
// Handle FXTextField-specific message
if(obj->isMemberOf(FXMETACLASS(FXTextField))){
switch(id){
case FXTextField::ID_INSERT_STRING:
return reinterpret_cast<void*>(StringValuePtr(value));;
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
default:
break;
}
}
// Handle messages applicable to all FXWindow descendants
if(obj->isMemberOf(FXMETACLASS(FXWindow))){
switch(id){
case FXWindow::ID_HIDE:
case FXWindow::ID_SHOW:
case FXWindow::ID_TOGGLESHOWN:
case FXWindow::ID_LOWER:
case FXWindow::ID_RAISE:
case FXWindow::ID_DELETE:
case FXWindow::ID_DISABLE:
case FXWindow::ID_ENABLE:
case FXWindow::ID_UNCHECK:
case FXWindow::ID_CHECK:
case FXWindow::ID_UNKNOWN:
case FXWindow::ID_UPDATE:
case FXWindow::ID_AUTOSCROLL:
case FXWindow::ID_QUERY_MENU:
case FXWindow::ID_HOTKEY:
case FXWindow::ID_ACCEL:
case FXWindow::ID_UNPOST:
case FXWindow::ID_POST:
case FXWindow::ID_MDI_TILEHORIZONTAL:
case FXWindow::ID_MDI_TILEVERTICAL:
case FXWindow::ID_MDI_CASCADE:
case FXWindow::ID_MDI_MAXIMIZE:
case FXWindow::ID_MDI_MINIMIZE:
case FXWindow::ID_MDI_RESTORE:
case FXWindow::ID_MDI_CLOSE:
case FXWindow::ID_MDI_WINDOW:
case FXWindow::ID_MDI_MENUWINDOW:
case FXWindow::ID_MDI_MENUMINIMIZE:
case FXWindow::ID_MDI_MENURESTORE:
case FXWindow::ID_MDI_MENUCLOSE:
case FXWindow::ID_MDI_NEXT:
case FXWindow::ID_MDI_PREV:
return NULL;
case FXWindow::ID_SETVALUE:
if(obj->isMemberOf(FXMETACLASS(FXButton)) ||
obj->isMemberOf(FXMETACLASS(FXCheckButton)) ||
obj->isMemberOf(FXMETACLASS(FXDial)) ||
obj->isMemberOf(FXMETACLASS(FXRadioButton)) ||
obj->isMemberOf(FXMETACLASS(FXShutter)) ||
obj->isMemberOf(FXMETACLASS(FXSpinner)) ||
obj->isMemberOf(FXMETACLASS(FXTabBar)) ||
obj->isMemberOf(FXMETACLASS(FXToggleButton)) ||
obj->isMemberOf(FXMETACLASS(FXScrollBar)) ||
obj->isMemberOf(FXMETACLASS(FXSlider)) ||
obj->isMemberOf(FXMETACLASS(FXSwitcher))){
return reinterpret_cast<void*>(static_cast<long>(NUM2INT(value)));
}
else if(obj->isMemberOf(FXMETACLASS(FXColorSelector)) ||
obj->isMemberOf(FXMETACLASS(FXColorWell))){
return reinterpret_cast<void*>(static_cast<unsigned long>(NUM2UINT(value)));
}
else if(obj->isMemberOf(FXMETACLASS(FXProgressBar))){
return reinterpret_cast<void*>(static_cast<unsigned long>(NUM2UINT(value)));
}
else if(obj->isMemberOf(FXMETACLASS(FXComboBox)) ||
obj->isMemberOf(FXMETACLASS(FXTextField)) ||
obj->isMemberOf(FXMETACLASS(FXDirBox)) ||
obj->isMemberOf(FXMETACLASS(FXDirList)) ||
obj->isMemberOf(FXMETACLASS(FXDriveBox)) ||
obj->isMemberOf(FXMETACLASS(FXFileList))){
return reinterpret_cast<void*>(StringValuePtr(value));
}
else if(obj->isMemberOf(FXMETACLASS(FXMenuCheck))){
return reinterpret_cast<void*>(static_cast<FXuval>(RTEST(value) ? 1 : 0));
}
else if(obj->isMemberOf(FXMETACLASS(FXMenuRadio))){
return reinterpret_cast<void*>(static_cast<FXuval>(RTEST(value) ? 1 : 0));
else if(obj->isMemberOf(FXMETACLASS(FXMenuCommand))){
return reinterpret_cast<void*>(static_cast<FXuval>(RTEST(value) ? 1 : 0));
}
return NULL;
case FXWindow::ID_HSCROLLED:
case FXWindow::ID_VSCROLLED:
return reinterpret_cast<void*>(static_cast<unsigned long>(NUM2UINT(value)));
case FXWindow::ID_SETINTVALUE:
if(obj->isMemberOf(FXMETACLASS(FXColorWell))){
colorValue=NUM2UINT(value);
return reinterpret_cast<void*>(&colorValue);
}
else{
intValue=NUM2INT(value);
return reinterpret_cast<void*>(&intValue);
}
case FXWindow::ID_SETREALVALUE:
realValue=NUM2DBL(value);
return reinterpret_cast<void*>(&realValue);
case FXWindow::ID_SETSTRINGVALUE:
stringValue=FXString(StringValuePtr(value));
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
return reinterpret_cast<void*>(&stringValue);
case FXWindow::ID_SETINTRANGE:
intRange[0]=NUM2INT(rb_ary_entry(value,0));
intRange[1]=NUM2INT(rb_ary_entry(value,1));
return reinterpret_cast<void*>(intRange);
case FXWindow::ID_SETREALRANGE:
realRange[0]=NUM2DBL(rb_ary_entry(value,0));
realRange[1]=NUM2DBL(rb_ary_entry(value,1));
return reinterpret_cast<void*>(realRange);
case FXWindow::ID_GETINTVALUE:
case FXWindow::ID_GETREALVALUE:
case FXWindow::ID_GETSTRINGVALUE:
case FXWindow::ID_GETINTRANGE:
case FXWindow::ID_GETREALRANGE:
return NULL;
default:
// Pass this data along as-is
break;
}
}
}
if(type==SEL_CHANGED){
if(obj->isMemberOf(FXMETACLASS(FXPicker))){
SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXPoint *"),1);
return ptr;
}
return 0;
}
if(type==SEL_DRAGGED){
SWIG_Ruby_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
return ptr;
}
// Pass through as-is
return reinterpret_cast<void*>(value);
}
static ID id_assocs;
/**
* Look up the name of the message handler function for this
* receiver and message (type, id) combination and return it;
* or return zero if the designated receiver doesn't handle this
* message.
*/
ID FXRbLookupHandler(FXObject* recv,FXSelector key){
FXTRACE((100,"FXRbLookupHandler(recv=%p(%s),FXSEL(%d,%d))\n",recv,recv->getClassName(),FXSELTYPE(key),FXSELID(key)));
ID id=0;
VALUE rubyObj=to_ruby(recv);
FXASSERT((recv==0 && rubyObj==Qnil) || (recv!=0 && rubyObj!=Qnil));
if(rb_ivar_defined(rubyObj,id_assocs)==Qtrue){
VALUE assocs=rb_ivar_get(rubyObj,id_assocs);
VALUE entry;
FXSelector keylo,keyhi;
for(long i=0;i<RARRAY_LEN(assocs);i++){
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
entry=rb_ary_entry(assocs,i);
keylo=NUM2UINT(rb_ary_entry(entry,0));
keyhi=NUM2UINT(rb_ary_entry(entry,1));
if(keylo<=key && key<=keyhi){
id=SYM2ID(rb_ary_entry(entry,2));
FXASSERT(id!=0);
break;
}
}
}
return id;
}
struct FXRbHandleArgs {
VALUE recv;
VALUE id;
int nargs;
VALUE sender;
VALUE key;
VALUE data;
};
static VALUE handle_body(VALUE args){
FXRbHandleArgs* hArgs=reinterpret_cast<FXRbHandleArgs*>(args);
FXASSERT(hArgs!=0);
return rb_funcall(hArgs->recv,hArgs->id,hArgs->nargs,hArgs->sender,hArgs->key,hArgs->data);
}
static ID id_backtrace;
static VALUE handle_rescue(VALUE args,VALUE error){
VALUE info=rb_gv_get("$!");
VALUE errat=rb_funcall(info,id_backtrace,0);
VALUE mesg=RARRAY_PTR(errat)[0];
StringValuePtr(mesg),
RSTRING_PTR(rb_obj_as_string(info)),
for(int i=1;i<RARRAY_LEN(errat);i++){
if(TYPE(RARRAY_PTR(errat)[i])==T_STRING){
fprintf(stderr,"\tfrom %s\n",StringValuePtr(RARRAY_PTR(errat)[i]));
}
}
return Qnil;
}
// Call the designated function and return its result (which should be a long).
long FXRbHandleMessage(FXObject* recv,ID func,FXObject* sender,FXSelector key,void* ptr){
FXRbHandleArgs hArgs;
hArgs.recv=to_ruby(recv);
hArgs.sender=to_ruby(sender);
hArgs.key=to_ruby(key);
hArgs.data=FXRbConvertMessageData(sender,recv,key,ptr);
hArgs.id=func;
hArgs.nargs=3;
VALUE retval;
FXTRACE((100,"FXRbHandleMessage(recv=%p(%s),FXSEL(%s,%d)\n",recv,recv->getClassName(),FXDebugTarget::messageTypeName[FXSELTYPE(key)],FXSELID(key)));
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
if(FXRbCatchExceptions){
#ifdef RB_RESCUE2_BROKEN_PROTOTYPE
retval=rb_rescue2((VALUE(*)()) handle_body, reinterpret_cast<VALUE>(&hArgs),
(VALUE(*)()) handle_rescue, Qnil,
rb_eStandardError, rb_eNameError, 0);
#else
retval=rb_rescue2((VALUE(*)(ANYARGS)) handle_body, reinterpret_cast<VALUE>(&hArgs),
(VALUE(*)(ANYARGS)) handle_rescue, Qnil,
rb_eStandardError, rb_eNameError, 0);
#endif
}
else{
retval=handle_body(reinterpret_cast<VALUE>(&hArgs));
}
/**
* Process the return value. For boolean return values, convert "true"
* to 1 and "false" to zero. For numeric types, convert it to a long value
* but trap the result to either 0 or 1 since these are usually what
* FOX is looking for. For any other type result (including nil) return 1.
* Thanks to Ted Meng for this suggestion.
*/
long lresult;
switch(TYPE(retval)){
case T_TRUE:
lresult=1;
break;
case T_FALSE:
lresult=0;
break;
case T_BIGNUM:
lresult=1;
break;
case T_FIXNUM:
case T_FLOAT:
lresult=(NUM2LONG(retval) == 0) ? 0 : 1; // trap any numeric result to either 0 or 1
break;
default:
lresult=1;
}
return lresult;
}
//----------------------------------------------------------------------
static ID id_begin;
static ID id_end;
static ID id_exclude_endp;
void FXRbRange2LoHi(VALUE range,FXint& lo,FXint& hi){
if(Qtrue!=rb_obj_is_instance_of(range,rb_cRange)){
rb_raise(rb_eTypeError,"wrong argument type %s (expected %s)",rb_class2name(CLASS_OF(range)),rb_class2name(rb_cRange));
}
else{
VALUE beg=rb_funcall(range,id_begin,0,NULL);
VALUE end=rb_funcall(range,id_end,0,NULL);
VALUE excl=rb_funcall(range,id_exclude_endp,0,NULL);
lo=NUM2INT(beg);
hi=NUM2INT(end);
if(excl==Qtrue){
hi--;
}
}
}
void FXRbRange2LoHi(VALUE range,FXdouble& lo,FXdouble& hi){
if(Qtrue!=rb_obj_is_instance_of(range,rb_cRange)){
rb_raise(rb_eTypeError,"wrong argument type %s (expected %s)",rb_class2name(CLASS_OF(range)),rb_class2name(rb_cRange));
}
else{
VALUE beg=rb_funcall(range,id_begin,0,NULL);
VALUE end=rb_funcall(range,id_end,0,NULL);
VALUE excl=rb_funcall(range,id_exclude_endp,0,NULL);
lo=NUM2DBL(beg);
hi=NUM2DBL(end);
if(excl==Qtrue){
hi--;
}
}
}
//----------------------------------------------------------------------
void FXRbCallVoidMethod(FXObject* recv, ID func) {
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
rb_funcall(obj,func,0,NULL);
}
void FXRbCallVoidMethod(FXDC* recv,ID func) {
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
rb_funcall(obj,func,0,NULL);
}
//----------------------------------------------------------------------
bool FXRbCallBoolMethod(const FXObject* recv,ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE v=rb_funcall(obj,func,0,NULL);
return (v==Qtrue);
}
//----------------------------------------------------------------------
// Call function with "FXint" return value
FXint FXRbCallIntMethod(const FXObject* recv,ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,0,NULL);
return static_cast<FXint>(NUM2INT(result));
}
//----------------------------------------------------------------------
// Call function with "FXGLObject*" return value
FXGLObject* FXRbCallGLObjectMethod(FXGLObject* recv,ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,0,NULL);
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
}
FXGLObject* FXRbCallGLObjectMethod(FXGLViewer* recv,ID func,FXint x,FXint y){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
}
FXGLObject* FXRbCallGLObjectMethod(FXGLObject* recv,ID func,FXuint* path,FXint n){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,1,FXRbMakeArray(path,n));
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
// Call function with "FXGLObject**" return value
FXGLObject** FXRbCallGLObjectArrayMethod(FXGLViewer* recv,ID func,FXint x,FXint y,FXint w,FXint h){
FXGLObject** objects=NULL;
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,4,INT2NUM(x),INT2NUM(y),INT2NUM(w),INT2NUM(h));
if(!NIL_P(result)){
Check_Type(result,T_ARRAY);
if(FXMALLOC(&objects,FXGLObject*,RARRAY_LEN(result)+1)){
for(long i=0; i<RARRAY_LEN(result); i++){
objects[i]=reinterpret_cast<FXGLObject*>(DATA_PTR(rb_ary_entry(result,i)));
}
objects[RARRAY_LEN(result)]=0;
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
}
}
return objects; // caller must free this
}
//----------------------------------------------------------------------
FXTableItem* FXRbCallTableItemMethod(FXTable* recv,ID func,const FXString& text,FXIcon* icon,void* ptr){
VALUE itemData=(ptr==0)?Qnil:reinterpret_cast<VALUE>(ptr);
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,3,to_ruby(text),to_ruby(icon),itemData);
return NIL_P(result)?0:reinterpret_cast<FXTableItem*>(DATA_PTR(result));
}
FXTableItem* FXRbCallTableItemMethod(FXTable* recv,ID func,FXint row,FXint col,FXbool notify){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,3,to_ruby(row),to_ruby(col),to_ruby(notify));
return NIL_P(result)?0:reinterpret_cast<FXTableItem*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
FXTreeItem* FXRbCallTreeItemMethod(const FXTreeList* recv,ID func,FXint x,FXint y){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXTreeItem*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
FXFoldingItem* FXRbCallFoldingItemMethod(const FXFoldingList* recv,ID func,FXint x,FXint y){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXFoldingItem*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
FXFileAssoc* FXRbCallFileAssocMethod(const FXFileDict* recv,ID func,const char* pathname){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,1,rb_str_new2(pathname));
return NIL_P(result) ? 0 : reinterpret_cast<FXFileAssoc*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
FXIcon* FXRbCallIconMethod(const FXTableItem* recv,ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
if(!NIL_P(obj)){
VALUE result=rb_funcall(obj,func,0,NULL);
return NIL_P(result) ? 0 : reinterpret_cast<FXIcon*>(DATA_PTR(result));
}
else{
return 0;
}
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
}
//----------------------------------------------------------------------
FXWindow* FXRbCallWindowMethod(const FXTableItem* recv,ID func,FXTable* table){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,1,to_ruby(table));
return NIL_P(result) ? 0 : reinterpret_cast<FXWindow*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
// Call function with "FXRange" return value
FXRangef FXRbCallRangeMethod(FXObject* recv,ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,0,NULL);
return *reinterpret_cast<FXRangef*>(DATA_PTR(result));
}
//----------------------------------------------------------------------
// Call functions with FXString return value
FXString FXRbCallStringMethod(const FXObject* recv, ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,0,NULL);
return FXString(StringValuePtr(result));
}
//----------------------------------------------------------------------
// Call functions with const FXchar* return value
const FXchar* FXRbCallCStringMethod(const FXObject* recv, ID func, const FXchar* message, const FXchar* hint){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,2,to_ruby(message),to_ruby(hint));
return NIL_P(result) ? 0 : StringValuePtr(result);
}
// Call functions with const FXchar* return value
const FXchar* FXRbCallCStringMethod(const FXObject* recv, ID func, const FXchar* context, const FXchar* message, const FXchar* hint){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,3,to_ruby(context),to_ruby(message),to_ruby(hint));
return NIL_P(result) ? 0 : StringValuePtr(result);
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
}
//----------------------------------------------------------------------
// Call functions with FXwchar return value
FXwchar FXRbCallWCharMethod(const FXObject* recv, ID func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,0,NULL);
return static_cast<FXwchar>(NUM2ULONG(result));
}
//----------------------------------------------------------------------
// Special destructors to handle order dependencies
FXRbMenuCommand::~FXRbMenuCommand(){
FXAccelTable *table;
FXWindow *owner;
if(acckey){
owner=getShell()->getOwner();
if(owner){
table=owner->getAccelTable();
if(table && table!=reinterpret_cast<FXAccelTable*>(-1)){
table->removeAccel(acckey);
}
}
}
acckey=(FXHotKey)NULL;
FXRbUnregisterRubyObj(this);
}
FXRbMenuCheck::~FXRbMenuCheck(){
FXAccelTable *table;
FXWindow *owner;
if(acckey){
owner=getShell()->getOwner();
if(owner){
table=owner->getAccelTable();
if(table && table!=reinterpret_cast<FXAccelTable*>(-1)){
table->removeAccel(acckey);
}
}
}
acckey=(FXHotKey)NULL;
FXRbUnregisterRubyObj(this);
}
FXRbMenuRadio::~FXRbMenuRadio(){
FXAccelTable *table;
FXWindow *owner;
if(acckey){
owner=getShell()->getOwner();
if(owner){
table=owner->getAccelTable();
if(table && table!=reinterpret_cast<FXAccelTable*>(-1)){
table->removeAccel(acckey);
}
}
}
acckey=(FXHotKey)NULL;
FXRbUnregisterRubyObj(this);
}
//----------------------------------------------------------------------
// Visit all of the items between fm and to (inclusive), plus their
// child items, and add to the items list
void FXRbTreeList::enumerateItem(FXTreeItem* item,FXObjectListOf<FXTreeItem>& items){
// Add this item to the list
items.append(item);
// Add this item's children
FXRbTreeList::enumerateItems(item->getFirst(),item->getLast(),items);
}
// Visit all of the items between fm and to (inclusive), plus their
// child items, and add to the items list
void FXRbTreeList::enumerateItems(FXTreeItem* fm,FXTreeItem* to,FXObjectListOf<FXTreeItem>& items){
register FXTreeItem *item;
if(fm && to){
do{
item=fm;
fm=fm->getNext();
FXRbTreeList::enumerateItem(item,items);
}
while(item!=to);
}
}
//----------------------------------------------------------------------
/**
* Visit all of the items between fm and to (inclusive), plus their
* child items, and add to the items list.
*/
void FXRbFoldingList::enumerateItem(FXFoldingItem* item,FXObjectListOf<FXFoldingItem>& items){
// Add this item to the list
items.append(item);
// Add this item's children
FXRbFoldingList::enumerateItems(item->getFirst(),item->getLast(),items);
}
/**
* Visit all of the items between fm and to (inclusive), plus their
* child items, and add to the items list.
*/
void FXRbFoldingList::enumerateItems(FXFoldingItem* fm,FXFoldingItem* to,FXObjectListOf<FXFoldingItem>& items){
register FXFoldingItem *item;
if(fm && to){
do{
item=fm;
fm=fm->getNext();
FXRbFoldingList::enumerateItem(item,items);
}
while(item!=to);
}
}
//----------------------------------------------------------------------
static ID id_cmp;
// Sort function stand-in for FXComboBox
FXint FXRbComboBox::sortFunc(const FXListItem* a,const FXListItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXListItem*>(a), "FXListItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXListItem*>(b), "FXListItem *");
VALUE result=rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Sort function stand-in for FXFoldingList
FXint FXRbFoldingList::sortFunc(const FXFoldingItem* a,const FXFoldingItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXFoldingItem*>(a), "FXFoldingItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXFoldingItem*>(b), "FXFoldingItem *");
VALUE result=rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Sort function stand-in for FXIconList
FXint FXRbIconList::sortFunc(const FXIconItem* a,const FXIconItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXIconItem*>(a), "FXIconItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXIconItem*>(b), "FXIconItem *");
VALUE result = rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Sort function stand-in for FXList
FXint FXRbList::sortFunc(const FXListItem* a,const FXListItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXListItem*>(a), "FXListItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXListItem*>(b), "FXListItem *");
VALUE result=rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Sort function stand-in for FXListBox
FXint FXRbListBox::sortFunc(const FXListItem* a,const FXListItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXListItem*>(a), "FXListItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXListItem*>(b), "FXListItem *");
VALUE result=rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Sort function stand-in for FXTreeList
FXint FXRbTreeList::sortFunc(const FXTreeItem* a,const FXTreeItem* b){
VALUE itemA = FXRbGetRubyObj(const_cast<FXTreeItem*>(a), "FXTreeItem *");
VALUE itemB = FXRbGetRubyObj(const_cast<FXTreeItem*>(b), "FXTreeItem *");
VALUE result=rb_funcall(itemA,id_cmp,1,itemB);
return static_cast<FXint>(NUM2INT(result));
}
// Feedback buffer sort routine stand-in for FXGLViewer
FXbool FXRbGLViewer::sortProc(FXfloat*& buffer,FXint& used,FXint& size){
return TRUE;
}
//----------------------------------------------------------------------
// Copied from the Ruby 1.8.6 sources (signal.c)
const char *signm;
int signo;
} siglist [] = {
{"EXIT", 0},
{"HUP", SIGHUP},
{"INT", SIGINT},
{"QUIT", SIGQUIT},
{"ILL", SIGILL},
{"TRAP", SIGTRAP},
{"IOT", SIGIOT},
{"ABRT", SIGABRT},
{"EMT", SIGEMT},
{"FPE", SIGFPE},
{"KILL", SIGKILL},
{"BUS", SIGBUS},
{"SEGV", SIGSEGV},
{"SYS", SIGSYS},
{"PIPE", SIGPIPE},
{"ALRM", SIGALRM},
{"TERM", SIGTERM},
{"URG", SIGURG},
{"STOP", SIGSTOP},
{"TSTP", SIGTSTP},
{"CONT", SIGCONT},
{"CHLD", SIGCHLD},
{"CLD", SIGCLD},
{"CLD", SIGCHLD},
# endif
#endif
#ifdef SIGTTIN
{"TTIN", SIGTTIN},
{"TTOU", SIGTTOU},
{"IO", SIGIO},
{"XCPU", SIGXCPU},
{"XFSZ", SIGXFSZ},
{"VTALRM", SIGVTALRM},
{"PROF", SIGPROF},
{"WINCH", SIGWINCH},
{"USR1", SIGUSR1},
{"USR2", SIGUSR2},
{"LOST", SIGLOST},
{"MSG", SIGMSG},
{"PWR", SIGPWR},
{"POLL", SIGPOLL},
{"DANGER", SIGDANGER},
{"MIGRATE", SIGMIGRATE},
{"PRE", SIGPRE},
{"GRANT", SIGGRANT},
{"RETRACT", SIGRETRACT},
{"SOUND", SIGSOUND},
{"INFO", SIGINFO},
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
};
FXint FXRbSignalNameToNumber(const char* s){
#ifdef HAVE_SIGNAL_H
const char *nm=s;
if(strncmp("SIG",nm,3)==0){
nm+=3;
}
for(signals* sigs=siglist;sigs->signm;sigs++){
if(strcmp(sigs->signm,nm)==0)
return sigs->signo;
}
#endif /* HAVE_SIGNAL_H */
return 0;
}
//----------------------------------------------------------------------
/*
* The Ruby header files define a TYPE(x) macro that conflicts with the
* TYPE template parameter used in FXArray.h and FXElement.h.
*/
#ifdef TYPE
#undef TYPE
#endif
#include <new>
#include "FXArray.h"
#include "FXElement.h"
static st_table * appSensitiveObjs;
static st_table * appSensitiveDCs;
void FXRbRegisterAppSensitiveObject(FXObject* obj){
FXASSERT(obj!=0);
FXTRACE((100,"%s:%d: FXRbRegisterAppSensitiveObject(obj=%p(%s))\n",__FILE__,__LINE__,obj,obj->getClassName()));
st_insert(appSensitiveObjs,reinterpret_cast<st_data_t>(obj),(st_data_t)0);
FXASSERT(st_lookup(appSensitiveObjs,reinterpret_cast<st_data_t>(obj),reinterpret_cast<st_data_t *>(0))!=0);
}
void FXRbRegisterAppSensitiveObject(FXDC* dc){
FXASSERT(dc!=0);
FXTRACE((100,"%s:%d: FXRbRegisterAppSensitiveObject(dc=%p)\n",__FILE__,__LINE__,dc));
st_insert(appSensitiveDCs,reinterpret_cast<st_data_t>(dc),(st_data_t)0);
FXASSERT(st_lookup(appSensitiveDCs,reinterpret_cast<st_data_t>(dc),reinterpret_cast<st_data_t *>(0))!=0);
}
void FXRbUnregisterAppSensitiveObject(FXObject* obj){
FXASSERT(obj!=0);
FXTRACE((100,"%s:%d: FXRbUnregisterAppSensitiveObject(obj=%p(%s))\n",__FILE__,__LINE__,obj,obj->getClassName()));
st_delete(appSensitiveObjs,reinterpret_cast<st_data_t *>(&obj),reinterpret_cast<st_data_t *>(0));
FXASSERT(st_lookup(appSensitiveObjs,reinterpret_cast<st_data_t>(obj),reinterpret_cast<st_data_t *>(0))==0);
}
void FXRbUnregisterAppSensitiveObject(FXDC* dc){
FXASSERT(dc!=0);
FXTRACE((100,"%s:%d: FXRbUnregisterAppSensitiveObject(dc=%p)\n",__FILE__,__LINE__,dc));
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
st_delete(appSensitiveDCs,reinterpret_cast<st_data_t *>(&dc),reinterpret_cast<st_data_t *>(0));
FXASSERT(st_lookup(appSensitiveDCs,reinterpret_cast<st_data_t>(dc),reinterpret_cast<st_data_t *>(0))==0);
}
#ifdef ST_BROKEN_PROTOTYPES
static int st_cbfunc_obj(st_data_t key,st_data_t,st_data_t arg){
#else
static int st_cbfunc_obj(st_data_t key,st_data_t,st_data_t arg,int){
#endif
FXASSERT(key!=0);
FXASSERT(arg!=0);
FXObjectListOf<FXObject> *pObjectList=reinterpret_cast<FXObjectListOf<FXObject>*>(arg);
FXObject *pObject=reinterpret_cast<FXObject*>(key);
pObjectList->append(pObject);
return 0;
}
#ifdef ST_BROKEN_PROTOTYPES
static int st_cbfunc_dc(st_data_t key,st_data_t,st_data_t arg){
#else
static int st_cbfunc_dc(st_data_t key,st_data_t,st_data_t arg,int){
#endif
FXASSERT(key!=0);
FXASSERT(arg!=0);
FXArray<FXDC*> *pDCArray=reinterpret_cast<FXArray<FXDC*>*>(arg);
FXDC *pDC=reinterpret_cast<FXDC*>(key);
pDCArray->append(pDC);
return 0;
}
void FXRbDestroyAppSensitiveObjects(){
FXTRACE((100,"%s:%d: Begin destroying objects that hold references to the FXApp...\n",__FILE__,__LINE__));
FXObjectListOf<FXObject> objs;
#ifdef ST_BROKEN_PROTOTYPES
st_foreach(appSensitiveObjs,st_cbfunc_obj,reinterpret_cast<st_data_t>(&objs));
#else
st_foreach(appSensitiveObjs,reinterpret_cast<int (*)(ANYARGS)>(st_cbfunc_obj),reinterpret_cast<st_data_t>(&objs));
#endif
for(FXint i=0;i<objs.no();i++){
if(objs[i]->isMemberOf(FXMETACLASS(FXRbCursor))){
if(dynamic_cast<FXRbCursor*>(objs[i])->ownedByApp)
continue;
}
else if(objs[i]->isMemberOf(FXMETACLASS(FXRbCURCursor))){
if(dynamic_cast<FXRbCURCursor*>(objs[i])->ownedByApp)
continue;
}
else if(objs[i]->isMemberOf(FXMETACLASS(FXRbGIFCursor))){
if(dynamic_cast<FXRbGIFCursor*>(objs[i])->ownedByApp)
continue;
}
else if(objs[i]->isMemberOf(FXMETACLASS(FXRbFont))){
if(dynamic_cast<FXRbFont*>(objs[i])->ownedByApp)
continue;
}
else if(objs[i]->isMemberOf(FXMETACLASS(FXRbGLVisual))){
if(dynamic_cast<FXRbGLVisual*>(objs[i])->ownedByApp)
continue;
}
else if(objs[i]->isMemberOf(FXMETACLASS(FXRbVisual))){
if(dynamic_cast<FXRbVisual*>(objs[i])->ownedByApp)
continue;
}
delete objs[i];
}
FXArray<FXDC*> dcs;
#ifdef ST_BROKEN_PROTOTYPES
st_foreach(appSensitiveDCs,st_cbfunc_dc,reinterpret_cast<st_data_t>(&dcs));
#else
st_foreach(appSensitiveDCs,reinterpret_cast<int (*)(ANYARGS)>(st_cbfunc_dc),reinterpret_cast<st_data_t>(&dcs));
#endif
for(FXint j=0;j<dcs.no();j++){
delete dcs[j];
}
FXTRACE((100,"%s:%d: Finished destroying objects that hold references to the FXApp.\n",__FILE__,__LINE__));
}
//----------------------------------------------------------------------
extern "C" void Init_core(void);
extern "C" void Init_dc(void);
extern "C" void Init_dialogs(void);
extern "C" void Init_frames(void);
extern "C" void Init_fx3d(void);
extern "C" void Init_image(void);
extern "C" void Init_iconlist(void);
extern "C" void Init_icons(void);
extern "C" void Init_label(void);
extern "C" void Init_layout(void);
extern "C" void Init_list(void);
extern "C" void Init_mdi(void);
extern "C" void Init_menu(void);
#ifdef WITH_FXSCINTILLA
extern "C" void Init_scintilla(void);
#endif
extern "C" void Init_table(void);
extern "C" void Init_text(void);
extern "C" void Init_treelist(void);
extern "C" void Init_ui(void);
#ifdef USE_RB_REQUIRE
#define REQUIRE(fname) rb_require((fname))
#else
#define REQUIRE(fname) rb_funcall(rb_mKernel,rb_intern("require"),1,rb_str_new2((fname)))
#endif
Lyle Johnson
committed
extern "C" void
#if defined _WIN32
__declspec(dllexport)
#endif
Init_fox16(void) {
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
Init_core();
Init_dc();
Init_frames();
Init_layout();
Init_label();
Init_ui();
Init_iconlist();
Init_list();
Init_dialogs();
Init_image();
Init_icons();
Init_menu();
Init_mdi();
Init_fx3d();
#ifdef WITH_FXSCINTILLA
Init_scintilla();
#endif
Init_table();
Init_text();
Init_treelist();
REQUIRE("fox16/core");
REQUIRE("fox16/dict");
REQUIRE("fox16/settings");
REQUIRE("fox16/iterators");
REQUIRE("fox16/keys");
REQUIRE("fox16/aliases");
REQUIRE("fox16/responder2");
REQUIRE("fox16/glgroup");
REQUIRE("fox16/execute_nonmodal");
REQUIRE("fox16/version");
REQUIRE("fox16/kwargs");
REQUIRE("fox16/exceptions_for_fxerror");
id_assocs=rb_intern("@assocs");
id_backtrace=rb_intern("backtrace");
id_cmp=rb_intern("<=>");
id_begin=rb_intern("begin");
id_end=rb_intern("end");
id_exclude_endp=rb_intern("exclude_end?");
FXRuby_Objects=st_init_numtable();
appSensitiveObjs=st_init_numtable();
appSensitiveDCs=st_init_numtable();
}