From 8bde880daf11fe7559d495282d11967d7926d54a Mon Sep 17 00:00:00 2001 From: 0CodErr <0CodErr@kolibrios.org> Date: Sat, 13 Oct 2018 07:54:18 +0000 Subject: [PATCH] add InputBox examples git-svn-id: svn://kolibrios.org@7457 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../libraries/InputBox/Examples/bcc/LScript.x | 23 ++ .../libraries/InputBox/Examples/bcc/make.bat | 7 + .../InputBox/Examples/bcc/test(InputBox)BCC.c | 192 +++++++++++++++ .../InputBox/Examples/uasm/LScript.x | 27 ++ .../libraries/InputBox/Examples/uasm/make.bat | 7 + .../Examples/uasm/test(InputBox)UASM.asm | 232 ++++++++++++++++++ 6 files changed, 488 insertions(+) create mode 100644 programs/develop/libraries/InputBox/Examples/bcc/LScript.x create mode 100644 programs/develop/libraries/InputBox/Examples/bcc/make.bat create mode 100644 programs/develop/libraries/InputBox/Examples/bcc/test(InputBox)BCC.c create mode 100644 programs/develop/libraries/InputBox/Examples/uasm/LScript.x create mode 100644 programs/develop/libraries/InputBox/Examples/uasm/make.bat create mode 100644 programs/develop/libraries/InputBox/Examples/uasm/test(InputBox)UASM.asm diff --git a/programs/develop/libraries/InputBox/Examples/bcc/LScript.x b/programs/develop/libraries/InputBox/Examples/bcc/LScript.x new file mode 100644 index 0000000000..30d3625172 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/bcc/LScript.x @@ -0,0 +1,23 @@ +PATH_SIZE = 1024; +PARAMS_SIZE = 256; +STACK_SIZE = 1024; + +SECTIONS +{ + .all : AT(0){ + LONG(0x554e454D); + LONG(0x31305445); + LONG(1); + LONG("_Main"); + LONG(END); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG($END + PATH_SIZE); + LONG($END); + *(.text) + *(.data) + } +END = .; + .bss ALIGN(16) : {*(.bss)} +$END = .; +} \ No newline at end of file diff --git a/programs/develop/libraries/InputBox/Examples/bcc/make.bat b/programs/develop/libraries/InputBox/Examples/bcc/make.bat new file mode 100644 index 0000000000..1fcadd1ac5 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/bcc/make.bat @@ -0,0 +1,7 @@ +Set KolibriOS="../../../../../../contrib/sdk/lib" +Set NAME=test(InputBox)BCC +@BCC32 -c %NAME%.c +@LINK -edit %NAME%.obj +@LD -T LScript.x %NAME%.obj -o %NAME%.kex -L %KolibriOS% -l KolibriOS +@OBJCOPY -O binary -j .all %NAME%.kex +@pause \ No newline at end of file diff --git a/programs/develop/libraries/InputBox/Examples/bcc/test(InputBox)BCC.c b/programs/develop/libraries/InputBox/Examples/bcc/test(InputBox)BCC.c new file mode 100644 index 0000000000..4f8707dbe9 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/bcc/test(InputBox)BCC.c @@ -0,0 +1,192 @@ +/* Event Constants */ +#define REDRAW_EVENT 1 +#define KEY_EVENT 2 +#define BUTTON_EVENT 3 + +/* Window Style Constants */ +#define WS_SKINNED_FIXED 0x4000000 +#define WS_COORD_CLIENT 0x20000000 +#define WS_CAPTION 0x10000000 + +/* Caption Style Constants */ +#define CS_MOVABLE 0 + +/* Charset specifiers for DrawText */ +#define DT_CP866_8X16 0x10000000 + +/* Fill styles for DrawText */ +#define DT_FILL_OPAQUE 0x40000000 + +/* Draw zero terminated string for DrawText */ +#define DT_ZSTRING 0x80000000 + +// Button identifiers +#define BUTTON_CLOSE 1 +#define SET_LEFT_BUTTON 1111 +#define SET_TOP_BUTTON 2222 +#define SET_CAPTION_BUTTON 3333 + +// Flags = [mouse|screen|parent][number|string] +#define IBF_STRING 0 // в буфер будет записана строка +#define IBF_NUMBER 1 // в буфер будет записано число +#define IBF_MOUSE_REL 0 // относительно положения указателя мыши +#define IBF_SCREEN_REL 8 // относительно экрана +#define IBF_PARENT_REL 16 // относительно родительского окна + +// Errors +#define IBE_NO_ERROR 0 // успешно, нет ошибки +#define IBE_NUMBER_OVERFLOW 1 // переполнение при вводе числа +#define IBE_RESULT_TOO_LONG 2 // результат не умещается в буфер + +#pragma pack(1) + +struct TButtonInput{ + union{ + struct{ + unsigned char MouseButton; + unsigned short ID; + unsigned char HiID; + }; + unsigned long Value; + }; +}; + +struct TKeyboardInput{ + union{ + struct{ + unsigned char Flag; + char Code; + union{ + char Scan; + unsigned short Control; + }; + }; + unsigned long Value; + }; +}; + +struct TSize{ + union{ + struct{ + unsigned short Height; + unsigned short Width; + }; + unsigned long Value; + }; +}; + +struct TBox{ + long Left; + long Top; + unsigned long SizeX; + unsigned long SizeY; +}; + +extern struct TButtonInput __stdcall GetButton(void); +extern struct TKeyboardInput __stdcall GetKey(void); +extern struct TSize __stdcall GetScreenSize(void); +extern unsigned long __stdcall WaitEvent(void); +extern void __stdcall BeginDraw(void); +extern void __stdcall EndDraw(void); +extern void __stdcall ThreadTerminate(void); + +extern void __stdcall DrawWindow(long Left, + long Top, + unsigned long Width, + unsigned long Height, + char* Caption, + unsigned long BackColor, + unsigned long Style, + unsigned long CapStyle); + +extern void __stdcall DrawText(long X, + long Y, + char* Text, + unsigned long ForeColor, + unsigned long BackColor, + unsigned long Flags, + unsigned long Count); + +extern void __stdcall DrawButton(long Left, + long Top, + unsigned long Width, + unsigned long Height, + unsigned long BackColor, + unsigned long Style, + unsigned long ID); + +extern void __stdcall SetWindowPos(long Left, long Top, unsigned long Width, unsigned long Height); +extern void* __stdcall LoadLibrary(char* Path); +extern void* __stdcall GetProcAddress(void* hLib, char* ProcName); +extern void __stdcall SetWindowCaption(char* Caption); +extern long __stdcall RunFile(char* Path, char* CmdLine); + +struct TSize Screen; +struct TBox Window; + +unsigned long err; + +char Buf[100]; +long NewPos; + +void* InputBoxLib; + +unsigned long __stdcall (* InputBox)(void* Buffer, char* Caption, char* Prompt, char* Default, + unsigned long Flags, unsigned long BufferSize, void* RedrawProc); + +void OnRedraw(void){ + BeginDraw(); + DrawWindow(Window.Left, Window.Top, Window.SizeX, Window.SizeY, "Test InputBox", 0xFFFFFF, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CS_MOVABLE); + + DrawButton(8, 60, 81, 33, 0x0FF0000, 0, SET_LEFT_BUTTON); + DrawButton(104, 60, 81, 33, 0x000FF00, 0, SET_TOP_BUTTON); + DrawButton(200, 60, 93, 33, 0x0FFFF00, 0, SET_CAPTION_BUTTON); + + DrawText(28, 72, "Set Left", 0, 0x0FFFFFF, DT_ZSTRING, 0); + DrawText(122, 72, "Set Top", 0, 0x0FFFFFF, DT_ZSTRING, 0); + DrawText(214, 72, "Set Caption", 0, 0x0FFFFFF, DT_ZSTRING, 0); + + EndDraw(); +} +/* -------------------------------------------------------- */ +void Main(){ + InputBoxLib = LoadLibrary("/sys/lib/InputBox.obj"); + InputBox = GetProcAddress(InputBoxLib, "InputBox"); + + Window.Left = 100; + Window.Top = 70; + Window.SizeX = 315; + Window.SizeY = 200; + + while(1){ + switch (WaitEvent()){ + case BUTTON_EVENT: + switch (GetButton().ID){ + case BUTTON_CLOSE: + ThreadTerminate(); + break; + case SET_LEFT_BUTTON: + err = InputBox(&NewPos, "Input", "Enter new left", "100", IBF_NUMBER + IBF_PARENT_REL, sizeof(NewPos), &OnRedraw); + if (err) RunFile("/sys/@notify", "Error"); + SetWindowPos(NewPos, -1, -1, -1); + break; + case SET_TOP_BUTTON: + err = InputBox(&NewPos, "Input", "Enter new top", "70", IBF_NUMBER + IBF_SCREEN_REL, sizeof(NewPos), &OnRedraw); + if (err) RunFile("/sys/@notify", "Error"); + SetWindowPos(-1, NewPos, -1, -1); + break; + case SET_CAPTION_BUTTON: + InputBox(&Buf, "Input", "Enter new caption", "Test InputBox", IBF_STRING + IBF_MOUSE_REL, sizeof(Buf), &OnRedraw); + SetWindowCaption(Buf); + break; + } + break; + case KEY_EVENT: + GetKey(); + break; + case REDRAW_EVENT: + OnRedraw(); + break; + } + } +} \ No newline at end of file diff --git a/programs/develop/libraries/InputBox/Examples/uasm/LScript.x b/programs/develop/libraries/InputBox/Examples/uasm/LScript.x new file mode 100644 index 0000000000..9bcdec43c9 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/uasm/LScript.x @@ -0,0 +1,27 @@ +PATH_SIZE = 1024; +PARAMS_SIZE = 256; +STACK_SIZE = 1024; + +AppParams = $END + PATH_SIZE; +AppPath = $END; + +SECTIONS +{ + .all : AT(0){ + LONG(0x554e454D); + LONG(0x31305445); + LONG(1); + LONG("@Main"); + LONG(END); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG(AppParams); + LONG(AppPath); + *(.text) + *(.rdata) + *(.data) + } +END = .; + .bss ALIGN(16) : {*(.bss)} +$END = .; +} \ No newline at end of file diff --git a/programs/develop/libraries/InputBox/Examples/uasm/make.bat b/programs/develop/libraries/InputBox/Examples/uasm/make.bat new file mode 100644 index 0000000000..8847842b80 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/uasm/make.bat @@ -0,0 +1,7 @@ +Set KolibriOS="../../../../../../contrib/sdk/lib" +Set Name=test(InputBox)UASM +@uasm32 -zt0 -coff %Name%.asm +@ld -T LScript.x %Name%.obj -o %Name%.kex -L %KolibriOS% -l KolibriOS +@objcopy -O binary -j .all %Name%.kex +@del %Name%.obj +@pause \ No newline at end of file diff --git a/programs/develop/libraries/InputBox/Examples/uasm/test(InputBox)UASM.asm b/programs/develop/libraries/InputBox/Examples/uasm/test(InputBox)UASM.asm new file mode 100644 index 0000000000..2f120cfad5 --- /dev/null +++ b/programs/develop/libraries/InputBox/Examples/uasm/test(InputBox)UASM.asm @@ -0,0 +1,232 @@ +.586 +.Model Flat, StdCall +Option CaseMap: None + +Public @Main + +FALSE = 0 +TRUE = Not FALSE + +CStr Macro QuotedText:VarArg +Local LocalText +.Const +LocalText db QuotedText,0 +.Code +ExitM +EndM + +RepArg Macro Arg + Local NewStr + Quot SubStr , 1, 1 + IfIdn Quot, <"> + .Data + NewStr db Arg,0 + .Code + ExitM + Else + ExitM + EndIf +EndM + +@ Macro Function:Req, Args:VarArg + Arg equ + For Var, + Arg CatStr Arg, <, RepArg(Var)> + EndM + Arg + ExitM +EndM + +WINDOW_BORDER_SIZE = 5 + +; Events +REDRAW_EVENT = 1 +KEY_EVENT = 2 +BUTTON_EVENT = 3 +BACKGROUND_EVENT = 5 +MOUSE_EVENT = 6 +IPC_EVENT = 7 +NETWORK_EVENT = 8 +DEBUG_EVENT = 9 + +; Window Style Constants +WS_SKINNED_FIXED = 4000000H +WS_COORD_CLIENT = 20000000H +WS_CAPTION = 10000000H + +; Caption Style Constants +CS_MOVABLE = 0 + +; Event Mask Constants +EM_REDRAW = 001H +EM_KEY = 002H +EM_BUTTON = 004H +EM_BACKGROUND = 010H +EM_MOUSE = 020H +EM_IPC = 040H +EM_NETWORK = 080H +EM_DEBUG = 100H + +; SharedMemoryOpen open\access flags +SHM_OPEN = 000H +SHM_OPEN_ALWAYS = 004H +SHM_CREATE = 008H +SHM_READ = 000H +SHM_WRITE = 001H + +; Draw zero terminated string for DrawText +DT_ZSTRING = 080000000H + +TRect Struct + Left SDword ? + Top SDword ? + Right SDword ? + Bottom SDword ? +TRect EndS + +TBox Struct + Left SDword ? + Top SDword ? + SizeX Dword ? + SizeY Dword ? +TBox EndS + +TSize Struct + SizeY Word ? + SizeX Word ? +TSize EndS + +TKeyboardInput Struct + Flag Byte ? + Code Byte ? + Union + Scan Byte ? + Control Word ? + EndS +TKeyboardInput EndS + +TButtonInput Struct + MouseButton Byte ? + ID Word ? + HiID Byte ? +TButtonInput EndS + +; Button identifiers +BUTTON_CLOSE = 1 +SET_LEFT_BUTTON = 1111 +SET_TOP_BUTTON = 2222 +SET_CAPTION_BUTTON = 3333 + +; Flags = [mouse|screen|parent][number|string] +IBF_STRING = 0 ; в буфер будет записана строка +IBF_NUMBER = 1 ; в буфер будет записано число +IBF_MOUSE_REL = 0 ; относительно положения указателя мыши +IBF_SCREEN_REL = 8 ; относительно экрана +IBF_PARENT_REL = 16 ; относительно родительского окна + +; Errors +IBE_NO_ERROR = 0 ; успешно, нет ошибки +IBE_NUMBER_OVERFLOW = 1 ; переполнение при вводе числа +IBE_RESULT_TOO_LONG = 2 ; результат не умещается в буфер + +GetButton Proto +GetKey Proto +WaitEvent Proto +BeginDraw Proto +EndDraw Proto +DrawWindow Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, Caption:Ptr, BackColor:Dword, Style:Dword, CapStyle:Dword +ThreadTerminate Proto +LoadLibrary Proto Path:Ptr +GetProcAddress Proto hLib:Ptr, ProcName:Ptr +SetEventMask Proto EventMask:Dword +GetScreenSize Proto +GetSkinHeight Proto +HeapAllocate Proto Bytes:Dword +DrawButton Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, BackColor:Dword, Style:Dword, ID:Dword +GetStandardColors Proto ColorTable:Ptr, TableSize:Dword +DrawText Proto X:SDword, Y:SDword, Text:Ptr, ForeColor:Dword, BackColor:Dword, Flags:Dword, Count:Dword +SetWindowCaption Proto Caption:Ptr +RunFile Proto Path:Ptr, CmdLine:Ptr +SetWindowPos Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword + +InputBox_proto TypeDef Proto Buffer:Ptr, Caption:Ptr, Prompt:Ptr, Default:Ptr, Flags:Dword, BufferSize:Dword, RedrawProc:Ptr +InputBox_proc TypeDef Ptr InputBox_proto + +; -------------------------------------------------------- ; +.Data? ; ------------------------------------------------- ; +; -------------------------------------------------------- ; +Extern AppParams: Byte +Extern AppPath: Byte + +Window TBox <> +Screen TSize <> + +Key TKeyboardInput <> +Button TButtonInput <> + +Buf Byte 100 Dup (?) +NewPos Dword ? + +InputBoxLib Dword ? +InputBox InputBox_proc ? + +; -------------------------------------------------------- ; +.Code ; -------------------------------------------------- ; +; -------------------------------------------------------- ; +OnRedraw Proc + Invoke BeginDraw + Invoke DrawWindow, Window.Left, Window.Top, Window.SizeX, Window.SizeY, CStr("Test InputBox"), 0FFFFFFH, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CS_MOVABLE + + Invoke DrawButton, 8, 60, 81, 33, 00FF0000H, 0, SET_LEFT_BUTTON + Invoke DrawButton, 104, 60, 81, 33, 0000FF00H, 0, SET_TOP_BUTTON + Invoke DrawButton, 200, 60, 93, 33, 00FFFF00H, 0, SET_CAPTION_BUTTON + + Invoke DrawText, 28, 72, CStr("Set Left"), 0, 00FFFFFFH, DT_ZSTRING, 0 + Invoke DrawText, 122, 72, CStr("Set Top"), 0, 00FFFFFFH, DT_ZSTRING, 0 + Invoke DrawText, 214, 72, CStr("Set Caption"), 0, 00FFFFFFH, DT_ZSTRING, 0 + + Invoke EndDraw + ret +OnRedraw Endp +; -------------------------------------------------------- ; +@Main: + mov InputBoxLib, @(LoadLibrary, CStr("/sys/lib/InputBox.obj")) + mov InputBox, @(GetProcAddress, InputBoxLib, CStr("InputBox")) + + mov Window.Left, 100 + mov Window.Top, 70 + mov Window.SizeX, 315 + mov Window.SizeY, 200 + + Invoke SetEventMask, EM_REDRAW + EM_KEY + EM_BUTTON + EM_MOUSE + + .Repeat + Invoke WaitEvent + .If eax == REDRAW_EVENT + Invoke OnRedraw + .ElseIf eax == KEY_EVENT + Invoke GetKey + .ElseIf eax == BUTTON_EVENT + mov Button, @(GetButton) + .If Button.ID == BUTTON_CLOSE + Invoke ThreadTerminate + .ElseIf Button.ID == SET_LEFT_BUTTON + Invoke InputBox, Offset NewPos, CStr("Input"), CStr("Enter new left"), CStr("100"), IBF_NUMBER + IBF_PARENT_REL, SizeOf(NewPos), Offset OnRedraw + .If eax != 0 + Invoke RunFile, CStr("/sys/@notify"), CStr("Error") + .EndIf + Invoke SetWindowPos, NewPos, -1, -1, -1 + .ElseIf Button.ID == SET_TOP_BUTTON + Invoke InputBox, Offset NewPos, CStr("Input"), CStr("Enter new top"), CStr("70"), IBF_NUMBER + IBF_SCREEN_REL, SizeOf(NewPos), Offset OnRedraw + .If eax != 0 + Invoke RunFile, CStr("/sys/@notify"), CStr("Error") + .EndIf + Invoke SetWindowPos, -1, NewPos, -1, -1 + .ElseIf Button.ID == SET_CAPTION_BUTTON + Invoke InputBox, Offset Buf, CStr("Input"), CStr("Enter new caption"), CStr("Test InputBox"), IBF_STRING + IBF_MOUSE_REL, SizeOf(Buf), Offset OnRedraw + Invoke SetWindowCaption, Offset Buf + .EndIf + .ElseIf eax == MOUSE_EVENT + .EndIf + .Until 0 +END