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 { "multiLine", AG_TEXTBOX_MULTILINE }, 36 { "static", AG_TEXTBOX_STATIC }, 37 { "password", AG_TEXTBOX_PASSWORD }, 38 { "abandonFocus", AG_TEXTBOX_ABANDON_FOCUS }, 39 { "intOnly", AG_TEXTBOX_INT_ONLY }, 40 { "floatOnly", AG_TEXTBOX_FLT_ONLY }, 41 { "catchTab", AG_TEXTBOX_CATCH_TAB }, 42 { "noEmacs", AG_TEXTBOX_NOEMACS }, 43 { "noWordSeek", AG_TEXTBOX_NOWORDSEEK }, 44 { "noLatin1", AG_TEXTBOX_NOLATIN1 }, 45 { NULL, 0 } 46 }; 47 48 MODULE = Agar::Textbox PACKAGE = Agar::Textbox PREFIX = AG_ 49 PROTOTYPES: ENABLE 50 VERSIONCHECK: DISABLE 51 52 Agar::Textbox 53 new(package, parent, label, ...) 54 const char * package 55 Agar::Widget parent 56 const char * label 57 PREINIT: 58 Uint flags = 0, wflags = 0; 59 CODE: 60 if ((items == 4 && SvTYPE(SvRV(ST(3))) != SVt_PVHV) || items > 4) { 61 Perl_croak(aTHX_ "Usage: Agar::Textbox->new(parent,label,[{opts}])"); 62 } 63 if (items == 4) { 64 AP_MapHashToFlags(SvRV(ST(3)), flagNames, &flags); 65 AP_MapHashToFlags(SvRV(ST(3)), AP_WidgetFlagNames, &wflags); 66 } 67 RETVAL = AG_TextboxNewS(parent, flags, label); 68 AGWIDGET(RETVAL)->flags |= wflags; 69 OUTPUT: 70 RETVAL 71 72 void 73 sizeHint(self, text) 74 Agar::Textbox self 75 const char * text 76 CODE: 77 AG_TextboxSizeHint(self, text); 78 79 void 80 sizeHintPixels(self, w, h) 81 Agar::Textbox self 82 Uint w 83 Uint h 84 CODE: 85 AG_TextboxSizeHintPixels(self, w, h); 86 87 void 88 sizeHintLines(self, numLines) 89 Agar::Textbox self 90 Uint numLines 91 CODE: 92 AG_TextboxSizeHintLines(self, numLines); 93 94 int 95 getCursorPos(self) 96 Agar::Textbox self 97 CODE: 98 RETVAL = AG_TextboxGetCursorPos(self); 99 OUTPUT: 100 RETVAL 101 102 void 103 setFlag(self, name) 104 Agar::Textbox self 105 const char * name 106 CODE: 107 if (AP_SetNamedFlag(name, flagNames, &(self->flags))) { 108 AP_SetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 109 } 110 111 void 112 unsetFlag(self, name) 113 Agar::Textbox self 114 const char * name 115 CODE: 116 if (AP_UnsetNamedFlag(name, flagNames, &(self->flags))) { 117 AP_UnsetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 118 } 119 120 Uint 121 getFlag(self, name) 122 Agar::Textbox self 123 const char * name 124 CODE: 125 if (AP_GetNamedFlag(name, flagNames, self->flags, &RETVAL)) { 126 if (AP_GetNamedFlag(name, AP_WidgetFlagNames, AGWIDGET(self)->flags, 127 &RETVAL)) { XSRETURN_UNDEF; } 128 } 129 OUTPUT: 130 RETVAL 131 132