1 /* 2 * Copyright (c) 2009 Mat Sutcliffe (oktal@gmx.co.uk) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 23 * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "EXTERN.h" 27 #include "perl.h" 28 #include "XSUB.h" 29 30 #include <agar/core.h> 31 #include <agar/gui.h> 32 #include "perl_agar.h" 33 34 static const AP_FlagNames flagNames[] = { 35 { "poll", AG_COMBO_POLL }, 36 { "tree", AG_COMBO_TREE }, 37 { "anyText", AG_COMBO_ANY_TEXT }, 38 { "scrollToSel", AG_COMBO_SCROLLTOSEL }, 39 { NULL, 0 } 40 }; 41 42 MODULE = Agar::Combo PACKAGE = Agar::Combo PREFIX = AG_ 43 PROTOTYPES: ENABLE 44 VERSIONCHECK: DISABLE 45 46 Agar::Combo 47 new(package, parent, label, ...) 48 const char * package 49 Agar::Widget parent 50 const char * label 51 PREINIT: 52 Uint flags = 0, wflags = 0; 53 CODE: 54 if ((items == 4 && SvTYPE(SvRV(ST(3))) != SVt_PVHV) || items > 4) { 55 Perl_croak(aTHX_ "Usage: Agar::Combo->new(parent,label,[{opts}])"); 56 } 57 if (items == 4) { 58 AP_MapHashToFlags(SvRV(ST(3)), flagNames, &flags); 59 AP_MapHashToFlags(SvRV(ST(3)), AP_WidgetFlagNames, &wflags); 60 } 61 RETVAL = AG_ComboNewS(parent, flags, label); 62 AGWIDGET(RETVAL)->flags |= wflags; 63 OUTPUT: 64 RETVAL 65 66 void 67 sizeHint(self, text, numItems) 68 Agar::Combo self 69 const char * text 70 int numItems 71 CODE: 72 AG_ComboSizeHint(self, text, numItems); 73 74 void 75 sizeHintPixels(self, w, h) 76 Agar::Combo self 77 int w 78 int h 79 CODE: 80 AG_ComboSizeHintPixels(self, w, h); 81 82 void 83 select(self, item) 84 Agar::Combo self 85 Agar::TlistItem item 86 CODE: 87 AG_ComboSelect(self, item); 88 89 void 90 selectText(self, text) 91 Agar::Combo self 92 const char * text 93 CODE: 94 AG_ComboSelectText(self, text); 95 96 Agar::Tlist 97 list(self) 98 Agar::Combo self 99 CODE: 100 RETVAL = self->list; 101 OUTPUT: 102 RETVAL 103 104 Agar::Textbox 105 tbox(self) 106 Agar::Combo self 107 CODE: 108 RETVAL = self->tbox; 109 OUTPUT: 110 RETVAL 111 112 Agar::Button 113 button(self) 114 Agar::Combo self 115 CODE: 116 RETVAL = self->button; 117 OUTPUT: 118 RETVAL 119 120 void 121 setFlag(self, name) 122 Agar::Combo self 123 const char * name 124 CODE: 125 if (AP_SetNamedFlag(name, flagNames, &(self->flags))) { 126 AP_SetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 127 } 128 129 void 130 unsetFlag(self, name) 131 Agar::Combo self 132 const char * name 133 CODE: 134 if (AP_UnsetNamedFlag(name, flagNames, &(self->flags))) { 135 AP_UnsetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 136 } 137 138 Uint 139 getFlag(self, name) 140 Agar::Combo self 141 const char * name 142 CODE: 143 if (AP_GetNamedFlag(name, flagNames, self->flags, &RETVAL)) { 144 if (AP_GetNamedFlag(name, AP_WidgetFlagNames, AGWIDGET(self)->flags, 145 &RETVAL)) { XSRETURN_UNDEF; } 146 } 147 OUTPUT: 148 RETVAL 149 150