--- /dev/null
+\r
+#include "core.h"\r
+\r
+UI_TextBox *TextBox_Initialize(void)\r
+{\r
+ UI_TextBox *textbox;\r
+\r
+ textbox = (UI_TextBox *)System_CommonStruct_Allocate(SYSTEM_STRUCTID_TEXTBOX);\r
+ textbox->flags.bit.initialized = True;\r
+\r
+ textbox->forecol = 0xffffff;\r
+ textbox->backcol = 0xc6c6c6;\r
+\r
+ return textbox;\r
+}\r
+\r
+//bpp==0:\8e©\93®\91I\91ð(\8c»\8dÝ\82Ì\83V\83X\83e\83\80\83V\81[\83g\82Ì\90Ý\92è\82É\8d\87\82í\82¹\82é)\r
+uint TextBox_SetBuffer(UI_TextBox *textbox, uint xchars, uint ychars, uint bpp, UI_Sheet *parent)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetBuffer:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(xchars < 4 + 1 || ychars < 1){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetBuffer:Too small textbox.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ textbox->chars.x = xchars;\r
+ textbox->chars.y = ychars;\r
+ textbox->size_text_buf = textbox->chars.x * textbox->chars.y;\r
+\r
+ textbox->sheet = Sheet_Initialize();\r
+ Sheet_SetBuffer(textbox->sheet, Null, xchars << 3, ychars << 4, bpp);\r
+ Sheet_SetParent(textbox->sheet, parent);\r
+\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, 0, 0, (int)textbox->sheet->size.x - 1, (int)textbox->sheet->size.y - 1);\r
+\r
+ textbox->text_buf = System_Memory_Allocate(textbox->size_text_buf);\r
+ textbox->text_buf[0] = 0x00;\r
+\r
+ textbox->flags.bit.textbuffer_configured = True;\r
+\r
+ return 0;\r
+}\r
+\r
+uint TextBox_Show(UI_TextBox *textbox, uint height, int px, int py)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Show:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(textbox->sheet == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Show:Null textbox sheet.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ return Sheet_Show(textbox->sheet, height, px, py);\r
+}\r
+\r
+//char\82ð\93n\82·\82±\82Æ\82à\89Â\94\\81B\r
+//Break\8e\9e\82Ì\83L\81[\83R\81[\83h\82Í\96³\8e\8b\82µ\82Ä\89½\82à\93ü\97Í\82µ\82È\82¢\81ikeyid\82ð\92¼\90Ú\93n\82·\82¾\82¯\82Å\93ü\97Í\82ª\82Å\82«\82é\82æ\82¤\82É\82·\82é\82½\82ß\81j\81B\r
+//\83^\83u\95¶\8e\9a\82Í\81A\8bL\98^\82ª\83I\83t\82Ì\8e\9e\82Ì\82Ý\93ü\97Í\89Â\94\\81B\r
+uint TextBox_Put_Key(UI_TextBox *textbox, ushort keyid)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_Key:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_Key:Buffer not configured.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ if(!(keyid & KEYID_MASK_BREAK)){\r
+ if(keyid & KEYID_MASK_EXTENDED){ /*\90§\8cä\95¶\8e\9a*/\r
+ switch(keyid & KEYID_MASK_ID){\r
+ case KEYID_ENTER:\r
+ TextBox_Internal_Put_Character(textbox, '\n');\r
+ break;\r
+ case KEYID_BACKSPACE:\r
+ TextBox_Internal_Put_Character(textbox, '\b');\r
+ break;\r
+ case KEYID_TAB:\r
+ TextBox_Internal_Put_Character(textbox, '\t');\r
+ break;\r
+ }\r
+ return 0;\r
+ } else{ /*ASCII\95¶\8e\9a*/\r
+ TextBox_Internal_Put_Character(textbox, keyid & KEYID_MASK_ID);\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+uint TextBox_Put_String(UI_TextBox *textbox, const uchar s[])\r
+{\r
+ uint i;\r
+\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_String:Null textbox.\n");\r
+ #endif\r
+ return 0;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_String:Buffer not configured.\n");\r
+ #endif\r
+ return 0;\r
+ }\r
+\r
+ for(i = 0; s[i] != 0x00; i++){\r
+ TextBox_Internal_Put_Character(textbox, s[i]);\r
+ }\r
+ return i;\r
+}\r
+\r
+uint TextBox_Put_Character(UI_TextBox *textbox, uchar c)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_Character:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Put_Character:Buffer not configured.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ return TextBox_Internal_Put_Character(textbox, c);\r
+}\r
+\r
+//False->True\82Å\83o\83b\83t\83@\83\8a\83Z\83b\83g\81B\r
+bool TextBox_SetEnable_RecordInputText(UI_TextBox *textbox, bool enable)\r
+{\r
+ bool old;\r
+\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetEnable_RecordInputText:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetEnable_RecordInputText:Buffer not configured.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ old = textbox->flags.bit.record_input_text;\r
+\r
+ if(old != enable){\r
+ if(enable){\r
+ textbox->text_buf[0] = 0x00;\r
+ textbox->using_text_buf = 0;\r
+ textbox->location_cursor_record_started = textbox->location_cursor;\r
+ }\r
+ textbox->flags.bit.record_input_text = enable;\r
+ }\r
+\r
+ return old;\r
+}\r
+\r
+uint TextBox_SetEnable_CursorBlink(UI_TextBox *textbox, bool enable)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetEnable_CursorBlink:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_SetEnable_CursorBlink:Buffer not configured.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ textbox->flags.bit.cursor_blink = enable;\r
+ textbox->flags.bit.cursor_state = False;\r
+ TextBox_Internal_DrawCursor(textbox, False);\r
+ return 0;\r
+}\r
+\r
+uint TextBox_Cursor_Blink(UI_TextBox *textbox)\r
+{\r
+ if(textbox == Null){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Cursor_Blink:Null textbox.\n");\r
+ #endif\r
+ return 1;\r
+ }\r
+\r
+ if(!textbox->flags.bit.textbuffer_configured){\r
+ #ifdef CHNOSPROJECT_DEBUG_TEXTBOX\r
+ debug("TextBox_Cursor_Blink:Buffer not configured.\n");\r
+ #endif\r
+ return 2;\r
+ }\r
+\r
+ if(!textbox->flags.bit.cursor_blink){\r
+ return 3;\r
+ }\r
+\r
+ textbox->flags.bit.cursor_state = !textbox->flags.bit.cursor_state;\r
+ TextBox_Internal_DrawCursor(textbox, textbox->flags.bit.cursor_state);\r
+ return 0;\r
+}\r
+\r
+//--------//\r
+\r
+uint TextBox_Internal_Put_Character(UI_TextBox *textbox, uchar c)\r
+{\r
+ uint i;\r
+ uchar s[2];\r
+\r
+ s[1] = 0x00;\r
+\r
+ if(textbox->flags.bit.cursor_blink){\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ Sheet_RefreshSheet(textbox->sheet, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ }\r
+ /*ASCII\95¶\8e\9a*/\r
+ if(c == '\n'){\r
+ if(TextBox_Internal_Put_Character_TextBuffer(textbox, '\n')){\r
+ textbox->location_cursor.x = 0;\r
+ textbox->location_cursor.y += 16;\r
+ }\r
+ } else if(c == '\b'){\r
+ if(!(textbox->location_cursor.x <= 0 && textbox->location_cursor.y <= 0)){\r
+ if(TextBox_Internal_Put_Character_TextBuffer(textbox, '\b')){\r
+ textbox->location_cursor.x -= 8;\r
+ }\r
+ if(textbox->location_cursor.x < 0){\r
+ textbox->location_cursor.x = 0;\r
+ textbox->location_cursor.y -= 16;\r
+ if(textbox->flags.bit.record_input_text){\r
+ for(i = 0; i < textbox->using_text_buf; i++){\r
+ if(textbox->text_buf[textbox->using_text_buf - i - 1] == '\n'){\r
+ break;\r
+ }\r
+ textbox->location_cursor.x += 8;\r
+ if(textbox->location_cursor.x >= (int)textbox->sheet->size.x - (8 - 1)){\r
+ textbox->location_cursor.x = 0;\r
+ }\r
+ }\r
+ if(i == textbox->using_text_buf){\r
+ textbox->location_cursor.x += textbox->location_cursor_record_started.x;\r
+ if(textbox->location_cursor.x >= (int)textbox->sheet->size.x - (8 - 1)){\r
+ textbox->location_cursor.x -= textbox->sheet->size.x;\r
+ }\r
+ }\r
+ } else{\r
+ textbox->location_cursor.x = (int)textbox->sheet->size.x - 8;\r
+ }\r
+ }\r
+ }\r
+ } else if(c == '\t'){\r
+ if(!textbox->flags.bit.record_input_text && TextBox_Internal_Put_Character_TextBuffer(textbox, '\t')){\r
+ textbox->location_cursor.x += 8 * (4 - ((textbox->location_cursor.x >> 3) & 3));\r
+ }\r
+ if(textbox->location_cursor.x > (int)textbox->sheet->size.x){\r
+ textbox->location_cursor.x = 8 * 4;\r
+ textbox->location_cursor.y += 16;\r
+ } else if(textbox->location_cursor.x == (int)textbox->sheet->size.x){\r
+ textbox->location_cursor.x = 0;\r
+ textbox->location_cursor.y += 16;\r
+ }\r
+ } else if(c == '\r'){\r
+\r
+ } else if(TextBox_Internal_Put_Character_TextBuffer(textbox, c)){\r
+ s[0] = c;\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ Sheet_Drawing_Put_String(textbox->sheet, textbox->location_cursor.x, textbox->location_cursor.y, textbox->forecol, s);\r
+ Sheet_RefreshSheet(textbox->sheet, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ textbox->location_cursor.x += 8;\r
+ if(textbox->location_cursor.x >= (int)textbox->sheet->size.x - (8 - 1)){\r
+ textbox->location_cursor.x = 0;\r
+ textbox->location_cursor.y += 16;\r
+ }\r
+ }\r
+ if(textbox->location_cursor.y >= (int)textbox->sheet->size.y - (16 - 1)){\r
+ Sheet_Drawing_Scroll_Vertical(textbox->sheet, 16);\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, 0, (int)textbox->sheet->size.y - 16, (int)textbox->sheet->size.x - 1, (int)textbox->sheet->size.y - 1);\r
+ textbox->location_cursor.y -= 16;\r
+ Sheet_RefreshSheet_All(textbox->sheet);\r
+ }\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ Sheet_RefreshSheet(textbox->sheet, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+\r
+ return 0;\r
+}\r
+\r
+bool TextBox_Internal_Put_Character_TextBuffer(UI_TextBox *textbox, uchar c)\r
+{\r
+ if(!textbox->flags.bit.record_input_text){\r
+ return True;\r
+ }\r
+\r
+ switch(c){\r
+ case '\b':\r
+ if(textbox->using_text_buf > 0){\r
+ textbox->using_text_buf--;\r
+ textbox->text_buf[textbox->using_text_buf] = 0x00;\r
+ return True;\r
+ }\r
+ break;\r
+ default:\r
+ if(textbox->using_text_buf < textbox->size_text_buf - 1){\r
+ textbox->text_buf[textbox->using_text_buf] = c;\r
+ textbox->using_text_buf++;\r
+ textbox->text_buf[textbox->using_text_buf] = 0x00;\r
+ return True;\r
+ }\r
+ break;\r
+ }\r
+ return False;\r
+}\r
+\r
+uint TextBox_Internal_DrawCursor(UI_TextBox *textbox, bool cursor)\r
+{\r
+ if(cursor){\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->forecol, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ } else{\r
+ Sheet_Drawing_Fill_Rectangle(textbox->sheet, textbox->backcol, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+ }\r
+ Sheet_RefreshSheet(textbox->sheet, textbox->location_cursor.x, textbox->location_cursor.y, textbox->location_cursor.x + 8 - 1, textbox->location_cursor.y + 16 - 1);\r
+\r
+ return 0;\r
+}\r