forked from KolibriOS/kolibrios
add InputBox examples
git-svn-id: svn://kolibrios.org@7457 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
507181f130
commit
8bde880daf
23
programs/develop/libraries/InputBox/Examples/bcc/LScript.x
Normal file
23
programs/develop/libraries/InputBox/Examples/bcc/LScript.x
Normal file
@ -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 = .;
|
||||
}
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
27
programs/develop/libraries/InputBox/Examples/uasm/LScript.x
Normal file
27
programs/develop/libraries/InputBox/Examples/uasm/LScript.x
Normal file
@ -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 = .;
|
||||
}
|
@ -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
|
@ -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 <Offset LocalText>
|
||||
EndM
|
||||
|
||||
RepArg Macro Arg
|
||||
Local NewStr
|
||||
Quot SubStr <Arg>, 1, 1
|
||||
IfIdn Quot, <">
|
||||
.Data
|
||||
NewStr db Arg,0
|
||||
.Code
|
||||
ExitM <ADDR NewStr>
|
||||
Else
|
||||
ExitM <Arg>
|
||||
EndIf
|
||||
EndM
|
||||
|
||||
@ Macro Function:Req, Args:VarArg
|
||||
Arg equ <Invoke Function>
|
||||
For Var, <Args>
|
||||
Arg CatStr Arg, <, RepArg(Var)>
|
||||
EndM
|
||||
Arg
|
||||
ExitM <eax>
|
||||
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
|
Loading…
Reference in New Issue
Block a user