Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. .586
  2. .Model Flat, StdCall
  3. Option CaseMap: None
  4.  
  5. Public @Main
  6.  
  7. FALSE = 0
  8. TRUE  = Not FALSE
  9.  
  10. CStr Macro QuotedText:VarArg
  11. Local LocalText
  12. .Const
  13. LocalText db QuotedText,0
  14. .Code
  15. ExitM <Offset LocalText>
  16. EndM
  17.  
  18. RepArg Macro Arg
  19.   Local NewStr
  20.     Quot SubStr <Arg>, 1, 1
  21.   IfIdn Quot, <">
  22.    .Data
  23.      NewStr db Arg,0
  24.    .Code
  25.    ExitM <ADDR NewStr>
  26.  Else
  27.    ExitM <Arg>
  28.  EndIf
  29. EndM
  30.  
  31. @ Macro Function:Req, Args:VarArg
  32.  Arg equ <Invoke Function>
  33.  For Var, <Args>
  34.    Arg CatStr Arg, <, RepArg(Var)>
  35.  EndM
  36.  Arg
  37.  ExitM <eax>
  38. EndM
  39.  
  40. WINDOW_BORDER_SIZE = 5
  41.  
  42. ; Events
  43. REDRAW_EVENT      = 1
  44. KEY_EVENT         = 2
  45. BUTTON_EVENT      = 3
  46. BACKGROUND_EVENT  = 5
  47. MOUSE_EVENT       = 6
  48. IPC_EVENT         = 7
  49. NETWORK_EVENT     = 8
  50. DEBUG_EVENT       = 9
  51.  
  52. ; Window Style Constants
  53. WS_SKINNED_FIXED  = 4000000H
  54. WS_COORD_CLIENT   = 20000000H
  55. WS_CAPTION        = 10000000H
  56.  
  57. ; Caption Style Constants
  58. CS_MOVABLE        = 0
  59.  
  60. ; Event Mask Constants
  61. EM_REDRAW         = 001H
  62. EM_KEY            = 002H
  63. EM_BUTTON         = 004H
  64. EM_BACKGROUND     = 010H
  65. EM_MOUSE          = 020H
  66. EM_IPC            = 040H
  67. EM_NETWORK        = 080H
  68. EM_DEBUG          = 100H
  69.  
  70. ; SharedMemoryOpen open\access flags
  71. SHM_OPEN          = 000H
  72. SHM_OPEN_ALWAYS   = 004H
  73. SHM_CREATE        = 008H
  74. SHM_READ          = 000H
  75. SHM_WRITE         = 001H
  76.  
  77. ; Draw zero terminated string for DrawText
  78. DT_ZSTRING        = 080000000H
  79.  
  80. TRect Struct
  81.  Left   SDword ?
  82.  Top    SDword ?
  83.  Right  SDword ?
  84.  Bottom SDword ?
  85. TRect EndS
  86.  
  87. TBox Struct
  88.  Left  SDword ?
  89.  Top   SDword ?
  90.  SizeX Dword  ?
  91.  SizeY Dword  ?
  92. TBox EndS
  93.  
  94. TSize Struct
  95.  SizeY Word ?
  96.  SizeX Word ?
  97. TSize EndS
  98.  
  99. TKeyboardInput Struct
  100.  Flag Byte ?
  101.  Code Byte ?
  102.  Union
  103.    Scan    Byte ?
  104.    Control Word ?
  105.  EndS
  106. TKeyboardInput EndS
  107.  
  108. TButtonInput Struct
  109.  MouseButton Byte ?
  110.  ID          Word ?
  111.  HiID        Byte ?
  112. TButtonInput EndS
  113.  
  114. ; Button identifiers
  115. BUTTON_CLOSE       = 1
  116. SET_LEFT_BUTTON    = 1111
  117. SET_TOP_BUTTON     = 2222
  118. SET_CAPTION_BUTTON = 3333
  119.  
  120. ; Flags = [mouse|screen|parent][number|string]
  121. IBF_STRING = 0      ; â áóôåð áóäåò çàïèñàíà ñòðîêà
  122. IBF_NUMBER = 1      ; â áóôåð áóäåò çàïèñàíî ÷èñëî
  123. IBF_MOUSE_REL = 0   ; îòíîñèòåëüíî ïîëîæåíèÿ óêàçàòåëÿ ìûøè
  124. IBF_SCREEN_REL = 8  ; îòíîñèòåëüíî ýêðàíà
  125. IBF_PARENT_REL = 16 ; îòíîñèòåëüíî ðîäèòåëüñêîãî îêíà
  126.  
  127. ; Errors
  128. IBE_NO_ERROR = 0        ; óñïåøíî, íåò îøèáêè
  129. IBE_NUMBER_OVERFLOW = 1 ; ïåðåïîëíåíèå ïðè ââîäå ÷èñëà
  130. IBE_RESULT_TOO_LONG = 2 ; ðåçóëüòàò íå óìåùàåòñÿ â áóôåð
  131.  
  132. GetButton          Proto
  133. GetKey             Proto
  134. WaitEvent          Proto
  135. BeginDraw          Proto
  136. EndDraw            Proto
  137. DrawWindow         Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, Caption:Ptr, BackColor:Dword, Style:Dword, CapStyle:Dword
  138. ThreadTerminate    Proto
  139. LoadLibrary        Proto Path:Ptr
  140. GetProcAddress     Proto hLib:Ptr, ProcName:Ptr
  141. SetEventMask       Proto EventMask:Dword
  142. GetScreenSize      Proto
  143. GetSkinHeight      Proto
  144. HeapAllocate       Proto Bytes:Dword
  145. DrawButton         Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, BackColor:Dword, Style:Dword, ID:Dword
  146. GetStandardColors  Proto ColorTable:Ptr, TableSize:Dword
  147. DrawText           Proto X:SDword, Y:SDword, Text:Ptr, ForeColor:Dword, BackColor:Dword, Flags:Dword, Count:Dword
  148. SetWindowCaption   Proto Caption:Ptr
  149. RunFile            Proto Path:Ptr, CmdLine:Ptr
  150. SetWindowPos       Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword
  151.  
  152. InputBox_proto TypeDef Proto Buffer:Ptr, Caption:Ptr, Prompt:Ptr, Default:Ptr, Flags:Dword, BufferSize:Dword, RedrawProc:Ptr
  153. InputBox_proc  TypeDef Ptr InputBox_proto
  154.  
  155. ; -------------------------------------------------------- ;
  156. .Data? ; ------------------------------------------------- ;
  157. ; -------------------------------------------------------- ;
  158. Extern AppParams: Byte
  159. Extern AppPath:   Byte
  160.  
  161. Window TBox <>
  162. Screen TSize <>
  163.  
  164. Key TKeyboardInput <>
  165. Button TButtonInput <>
  166.  
  167. Buf Byte 100 Dup (?)
  168. NewPos Dword ?
  169.  
  170. InputBoxLib Dword ?
  171. InputBox InputBox_proc ?
  172.  
  173. ; -------------------------------------------------------- ;
  174. .Code ; -------------------------------------------------- ;
  175. ; -------------------------------------------------------- ;
  176. OnRedraw Proc
  177.  Invoke BeginDraw
  178.  Invoke DrawWindow, Window.Left, Window.Top, Window.SizeX, Window.SizeY, CStr("Test InputBox"), 0FFFFFFH, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CS_MOVABLE
  179.  
  180.  Invoke DrawButton, 8, 60, 81, 33, 00FF0000H, 0, SET_LEFT_BUTTON
  181.  Invoke DrawButton, 104, 60, 81, 33, 0000FF00H, 0, SET_TOP_BUTTON
  182.  Invoke DrawButton, 200, 60, 93, 33, 00FFFF00H, 0, SET_CAPTION_BUTTON
  183.  
  184.  Invoke DrawText, 28, 72,  CStr("Set Left"), 0, 00FFFFFFH, DT_ZSTRING, 0
  185.  Invoke DrawText, 122, 72, CStr("Set Top"), 0, 00FFFFFFH, DT_ZSTRING, 0
  186.  Invoke DrawText, 214, 72, CStr("Set Caption"), 0, 00FFFFFFH, DT_ZSTRING, 0
  187.  
  188.  Invoke EndDraw
  189.  ret
  190. OnRedraw Endp
  191. ; -------------------------------------------------------- ;
  192. @Main:
  193.  mov InputBoxLib,  @(LoadLibrary, CStr("/sys/lib/InputBox.obj"))
  194.  mov InputBox, @(GetProcAddress, InputBoxLib, CStr("InputBox"))  
  195.  
  196.  mov Window.Left, 100
  197.  mov Window.Top, 70
  198.  mov Window.SizeX, 315
  199.  mov Window.SizeY, 200
  200.  
  201.  Invoke SetEventMask, EM_REDRAW + EM_KEY + EM_BUTTON + EM_MOUSE
  202.  
  203.  .Repeat
  204.    Invoke WaitEvent
  205.    .If eax == REDRAW_EVENT
  206.      Invoke  OnRedraw
  207.    .ElseIf eax == KEY_EVENT
  208.      Invoke GetKey
  209.    .ElseIf eax == BUTTON_EVENT
  210.      mov Button, @(GetButton)
  211.      .If Button.ID == BUTTON_CLOSE
  212.        Invoke ThreadTerminate
  213.      .ElseIf Button.ID == SET_LEFT_BUTTON
  214.        Invoke InputBox, Offset NewPos, CStr("Input"), CStr("Enter new left"), CStr("100"), IBF_NUMBER + IBF_PARENT_REL, SizeOf(NewPos), Offset OnRedraw
  215.        .If eax != 0
  216.          Invoke RunFile, CStr("/sys/@notify"), CStr("Error")
  217.        .EndIf
  218.        Invoke SetWindowPos, NewPos, -1, -1, -1
  219.      .ElseIf Button.ID == SET_TOP_BUTTON
  220.        Invoke InputBox, Offset NewPos, CStr("Input"), CStr("Enter new top"), CStr("70"), IBF_NUMBER + IBF_SCREEN_REL, SizeOf(NewPos), Offset OnRedraw
  221.        .If eax != 0
  222.          Invoke RunFile, CStr("/sys/@notify"), CStr("Error")
  223.        .EndIf
  224.        Invoke SetWindowPos, -1, NewPos, -1, -1
  225.      .ElseIf Button.ID == SET_CAPTION_BUTTON
  226.        Invoke InputBox, Offset Buf, CStr("Input"), CStr("Enter new caption"), CStr("Test InputBox"), IBF_STRING + IBF_MOUSE_REL, SizeOf(Buf), Offset OnRedraw
  227.        Invoke SetWindowCaption, Offset Buf
  228.      .EndIf
  229.    .ElseIf eax == MOUSE_EVENT
  230.    .EndIf
  231.  .Until 0
  232. END
  233.