Subversion Repositories Kolibri OS

Rev

Rev 7039 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. Comment *--------------------+
  2. |                            |
  3. |    Run with OpenDialog     |
  4. |    UASM + KolibriOS.lib    |
  5. |                            |
  6. +----------------------------*
  7. .586
  8. .Model Flat, StdCall
  9. Option CaseMap: None
  10.  
  11. Public @Main
  12.  
  13. FALSE = 0
  14. TRUE  = Not FALSE
  15.  
  16. CStr Macro QuotedText:VarArg
  17. Local LocalText
  18. .Const
  19. LocalText db QuotedText,0
  20. .Code
  21. ExitM <Offset LocalText>
  22. EndM
  23.  
  24. IfDef     LANG_IT
  25.   szProgramRunSuccessfully equ <CStr("Programma eseguito correttamente")>
  26.   szFileNotFound           equ <CStr("File non trovato")>
  27.   szFileIsNotExecutable    equ <CStr("File non eseguibile")>
  28.   szTooManyProcesses       equ <CStr("Troppi processi")>
  29.   szAccessDenied           equ <CStr("Accesso negato")>
  30.   szOutOfMemory            equ <CStr("Memoria esaurita")>
  31.   szUnknownError           equ <CStr("Errore sconosciuto")>
  32.   szTypeNameOfProgram      equ <CStr("Digita il nome del programma per eseguirlo")>
  33.   szRun                    equ <CStr("Esegui")>
  34.   szTitle                  equ <CStr("Esegui")>
  35.   szPressF1                equ <CStr("Premere F1 per visualizzare le informazioni sui tasti di scelta rapida")>
  36.   szHelpInfo               equ <CStr("Insert                - il percorso da aprire la finestra di dialogo casella di modifica\n",\
  37.                                      "Ctrl + Insert         - aggiungi percorso alla posizione corrente del cursore\n",\
  38.                                      "Ctrl + Shift + Insert - aggiungi sempre un percorso senza virgolette")>
  39. ElseIfDef LANG_SP
  40.   szProgramRunSuccessfully equ <CStr("Programa ejecutado con exito")>
  41.   szFileNotFound           equ <CStr("Archivo no encontrado")>
  42.   szFileIsNotExecutable    equ <CStr("Archivo no es ejecutable")>
  43.   szTooManyProcesses       equ <CStr("Muchos procesos")>
  44.   szAccessDenied           equ <CStr("Acceso denegado")>
  45.   szOutOfMemory            equ <CStr("Memoria insuficiente")>
  46.   szUnknownError           equ <CStr("Error desconocido")>
  47.   szTypeNameOfProgram      equ <CStr("Tipo nombre del programa a ejecutar")>
  48.   szRun                    equ <CStr("Ejecutar")>
  49.   szTitle                  equ <CStr("Ejecutar")>
  50.   szPressF1                equ <CStr("Presione F1 para ver la informacion acerca de las teclas de acceso rapido")>
  51.   szHelpInfo               equ <CStr("Insert                - establecer la ruta de recuadro de dialogo en el cuadro de edicion\n",\
  52.                                      "Ctrl + Insert         - agregar ruta a la posicion actual del cursor\n",\
  53.                                      "Ctrl + Shift + Insert - siempre agregar la ruta sin las comillas")>
  54. ElseIfDef LANG_RU
  55.   szProgramRunSuccessfully equ <CStr("à®£à ¬¬  § ¯ã饭  ãᯥ譮")>
  56.   szFileNotFound           equ <CStr("” ©« ­¥ ­ ©¤¥­")>
  57.   szFileIsNotExecutable    equ <CStr("” ©« ­¥ ï¥âáï ¨á¯®«­ï¥¬ë¬")>
  58.   szTooManyProcesses       equ <CStr("‘«¨èª®¬ ¬­®£® ¯à®æ¥áᮢ")>
  59.   szAccessDenied           equ <CStr("„®áâ㯠§ ¯à¥é¥­")>
  60.   szOutOfMemory            equ <CStr("¥¤®áâ â®ç­® ¯ ¬ïâ¨")>
  61.   szUnknownError           equ <CStr("¥¨§¢¥áâ­ ï ®è¨¡ª ")>
  62.   szTypeNameOfProgram      equ <CStr("‚¢¥¤¨â¥ ­ §¢ ­¨¥ ¯à®£à ¬¬ë")>
  63.   szRun                    equ <CStr("‡ ¯ãáâ¨âì")>
  64.   szTitle                  equ <CStr("‡ ¯ã᪠¯à®£à ¬¬ë")>
  65.   szPressF1                equ <CStr(" ¦¬¨â¥ ª« ¢¨èã F1, çâ®¡ë ¯à®á¬®âà¥âì ¨­ä®à¬ æ¨î ® £®àïç¨å ª« ¢¨è å")>
  66.   szHelpInfo               equ <CStr("Insert                - ãáâ ­®¢¨âì ¯ãâì ¨§ ¤¨ «®£  ®âªàëâ¨ï ¢ ¯®«¥ ¢¢®¤ \n",\
  67.                                      "Ctrl + Insert         - ¤®¡ ¢¨âì ¯ãâì ¨§ ¤¨ «®£  ®âªàëâ¨ï ¢ ¯®«¥ ¢¢®¤  ¢ ⥪ãéãî ¯®§¨æ¨î ªãàá®à \n",\
  68.                                      "Ctrl + Shift + Insert - ¢á¥£¤  ¤®¡ ¢«ïâì ¯ãâì ¡¥§ ª ¢ë祪")>
  69. ElseIfDef LANG_EN
  70.   szProgramRunSuccessfully equ <CStr("Program run successfully")>
  71.   szFileNotFound           equ <CStr("File not found")>
  72.   szFileIsNotExecutable    equ <CStr("File is not executable")>
  73.   szTooManyProcesses       equ <CStr("Too many processes")>
  74.   szAccessDenied           equ <CStr("Access denied")>
  75.   szOutOfMemory            equ <CStr("Out of memory")>
  76.   szUnknownError           equ <CStr("Unknown error")>
  77.   szTypeNameOfProgram      equ <CStr("Type name of program to run")>
  78.   szRun                    equ <CStr("  Run ")>
  79.   szTitle                  equ <CStr("Run")>
  80.   szPressF1                equ <CStr("Press F1 to view information about the hot keys")>
  81.   szHelpInfo               equ <CStr("Insert                - set path from open dialog to edit box\n",\
  82.                                      "Ctrl + Insert         - add path from open dialog into edit box at the current cursor position\n",\
  83.                                      "Ctrl + Shift + Insert - always add path without quotes")>
  84. Else
  85.   .Err LANG_??
  86. EndIf
  87.  
  88. ; Events
  89. REDRAW_EVENT      = 1
  90. KEY_EVENT         = 2
  91. BUTTON_EVENT      = 3
  92. BACKGROUND_EVENT  = 5
  93. MOUSE_EVENT       = 6
  94. IPC_EVENT         = 7
  95. NETWORK_EVENT     = 8
  96. DEBUG_EVENT       = 9
  97.  
  98. ; Window Style Constants
  99. WS_SKINNED_FIXED  = 4000000H
  100. WS_COORD_CLIENT   = 20000000H
  101. WS_CAPTION        = 10000000H
  102.  
  103. ; Caption Style Constants
  104. CS_MOVABLE        = 0
  105.  
  106. ; Event Mask Constants
  107. EM_REDRAW         = 001H
  108. EM_KEY            = 002H
  109. EM_BUTTON         = 004H
  110. EM_BACKGROUND     = 010H
  111. EM_MOUSE          = 020H
  112. EM_IPC            = 040H
  113. EM_NETWORK        = 080H
  114. EM_DEBUG          = 100H
  115.  
  116. ; Draw zero terminated string for DrawText
  117. DT_ZSTRING        = 080000000H
  118.  
  119. ; Charset specifiers for DrawText
  120. DT_CP866_8X16     = 10000000H
  121.  
  122. ; bits for the GetControlKeyState
  123. LEFT_SHIFT_PRESSED  = 1
  124. RIGHT_SHIFT_PRESSED = 2
  125. LEFT_CTRL_PRESSED   = 4
  126. RIGHT_CTRL_PRESSED  = 8
  127.  
  128. TOpenDialog Struct
  129.   mode             Dword ?
  130.   procinfo         Dword ?
  131.   com_area_name    Dword ?
  132.   com_area         Dword ?
  133.   opendir_path     Dword ?
  134.   dir_default_path Dword ?
  135.   start_path       Dword ?
  136.   draw_Window      Dword ?
  137.   status           Dword ?
  138.   openfile_path    Dword ?
  139.   filename_area    Dword ?
  140.   filter_area      Dword ?
  141.   x_size           Word  ?
  142.   x_start          SWord ?
  143.   y_size           Word  ?
  144.   y_start          SWord ?
  145. TOpenDialog EndS
  146.  
  147. TEditBox Struct
  148.   x_size             Dword  ?
  149.   left               SDword ?
  150.   top                SDword ?
  151.   color              Dword  ?
  152.   shift_color        Dword  ?
  153.   focus_border_color Dword  ?
  154.   blur_border_color  Dword  ?
  155.   text_color         Dword  ?
  156.   max                Dword  ?
  157.   text               Dword  ?
  158.   mouse_variable     Dword  ?
  159.   flags              Dword  ?
  160.   count              Dword  ?
  161.   pos                Dword  ?
  162.   offs               Dword  ?
  163.   cl_curs_x          SWord  ?
  164.   cl_curs_y          SWord  ?
  165.   shift              Word   ?
  166.   shift_old          Word   ?
  167.   height             Dword  ?
  168.   char_width         Dword  ?
  169. TEditBox EndS
  170.  
  171. TStandartColors Struct
  172.   frames           Dword ?
  173.   grab             Dword ?
  174.   grab_button      Dword ?
  175.   grab_button_text Dword ?
  176.   grab_text        Dword ?
  177.   work             Dword ?
  178.   work_button      Dword ?
  179.   work_button_text Dword ?
  180.   work_text        Dword ?
  181.   work_graph       Dword ?
  182. TStandartColors EndS
  183.  
  184. TRect Struct
  185.   Left   SDword ?
  186.   Top    SDword ?
  187.   Right  SDword ?
  188.   Bottom SDword ?
  189. TRect EndS
  190.  
  191. TSize Struct
  192.   SizeY Word ?
  193.   SizeX Word ?
  194. TSize EndS
  195.  
  196. TKeyboardInput Struct
  197.   Flag Byte ?
  198.   Code Byte ?
  199.   Union
  200.     Scan    Byte ?
  201.     Control Word ?
  202.   EndS
  203. TKeyboardInput EndS
  204.  
  205. TButtonInput Struct
  206.   MouseButton Byte ?
  207.   ID          Word ?
  208.   HiID        Byte ?
  209. TButtonInput EndS
  210.  
  211. ; Button identifiers
  212. BUTTON_RUN        = 10
  213. BUTTON_BROWSE     = 20
  214.  
  215. KEY_SCAN_ENTER   = 01CH
  216. KEY_SCAN_INSERT  = 052H
  217. KEY_SCAN_F1      = 03BH
  218.  
  219. KEY_CODE_0 = 030H
  220.  
  221. PROC_INFO_BUFFER_SIZE      = 1024
  222. OPEN_FILE_PATH_BUFFER_SIZE = 4096
  223. FILE_NAME_AREA_BUFFER_SIZE = 1024
  224. OPEN_DIR_PATH_BUFFER_SIZE  = OPEN_FILE_PATH_BUFFER_SIZE - FILE_NAME_AREA_BUFFER_SIZE
  225.  
  226. EDIT1_TEXT_BUFFER_SIZE = 4096
  227. TMP_BUFFER_SIZE = 4096
  228.  
  229. GetButton          Proto
  230. GetKey             Proto
  231. WaitEvent          Proto
  232. BeginDraw          Proto
  233. EndDraw            Proto
  234. DrawWindow         Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, Caption:Ptr, BackColor:Dword, Style:Dword, CapStyle:Dword
  235. ThreadTerminate    Proto
  236. LoadLibrary        Proto Path:Ptr
  237. GetProcAddress     Proto hLib:Ptr, ProcName:Ptr
  238. SetEventMask       Proto EventMask:Dword
  239. GetScreenSize      Proto
  240. GetSkinHeight      Proto
  241. HeapAllocate       Proto Bytes:Dword
  242. DrawButton         Proto Left:SDword, Top:SDword, Right:SDword, Bottom:SDword, BackColor:Dword, Style:Dword, ID:Dword
  243. RunFile            Proto Path:Ptr, CmdLine:Ptr
  244. GetStandardColors  Proto ColorTable:Ptr, TableSize:Dword
  245. DrawText           Proto X:SDword, Y:SDword, Text:Ptr, ForeColor:Dword, BackColor:Dword, Flags:Dword, Count:Dword
  246. GetControlKeyState Proto
  247.  
  248. EditBoxDraw_proto     TypeDef Proto :Ptr
  249. EditBoxKey_proto      TypeDef Proto :Ptr
  250. EditBoxMouse_proto    TypeDef Proto :Ptr
  251. EditBoxSetText_proto  TypeDef Proto :Ptr, :Ptr
  252.  
  253. OpenDialogInit_proto  TypeDef Proto :Ptr
  254. OpenDialogStart_proto TypeDef Proto :Ptr
  255.  
  256. OpenDialogInit_proc   TypeDef Ptr OpenDialogInit_proto
  257. OpenDialogStart_proc  TypeDef Ptr OpenDialogStart_proto
  258.  
  259. EditBoxDraw_proc      TypeDef Ptr EditBoxDraw_proto
  260. EditBoxKey_proc       TypeDef Ptr EditBoxKey_proto
  261. EditBoxMouse_proc     TypeDef Ptr EditBoxMouse_proto
  262. EditBoxSetText_proc   TypeDef Ptr EditBoxSetText_proto
  263. ; -------------------------------------------------------- ;
  264. .Const; -------------------------------------------------- ;
  265. ; -------------------------------------------------------- ;
  266. szFFFFFFFFOpenDialog db "FFFFFFFF_open_dialog",0
  267. szSYS                db "/sys",0
  268. szOpenDialPath       db "/sys/File managers/opendial",0
  269. szEmpty              db 0
  270. ; -------------------------------------------------------- ;
  271. .Data; --------------------------------------------------- ;
  272. ; -------------------------------------------------------- ;
  273. FileFilter Dword 0
  274.  
  275. OD TOpenDialog <\
  276.       0,\
  277.       Offset ProcInfoBuffer,\
  278.       Offset szFFFFFFFFOpenDialog,\
  279.       0,\
  280.       Offset OpenDirPathBuffer,\
  281.       Offset szSYS,\
  282.       Offset szOpenDialPath,\
  283.       Offset OnRedraw,\
  284.       0,\
  285.       0,\
  286.       Offset FileNameAreaBuffer,\
  287.       Offset FileFilter,\
  288.       414,\
  289.       0,\
  290.       414,\
  291.       0\
  292. >
  293.  
  294. Edit1 TEditBox <\
  295.       0,\
  296.       5,\
  297.       26,\
  298.       00FFFFFFH,\
  299.       00A4C4E4H,\
  300.       0,\
  301.       0,\
  302.       DT_CP866_8X16,\
  303.       EDIT1_TEXT_BUFFER_SIZE,\
  304.       Offset Edit1TextBuffer,\
  305.       Offset Edit1MouseVariable,\
  306.       4002H,\
  307.       0,\
  308.       0,\
  309.       0,\
  310.       0,\
  311.       0,\
  312.       0,\
  313.       0\
  314. >
  315. ; -------------------------------------------------------- ;
  316. .Data? ; ------------------------------------------------- ;
  317. ; -------------------------------------------------------- ;
  318. Extern AppParams: Byte
  319. Extern AppPath:   Byte
  320.  
  321. BoxLib         Dword ?
  322. ProcLib        Dword ?
  323.  
  324. OpenDialogInit  OpenDialogInit_proc  ?
  325. OpenDialogStart OpenDialogStart_proc ?
  326.  
  327. EditBoxDraw     EditBoxDraw_proc     ?
  328. EditBoxKey      EditBoxKey_proc      ?
  329. EditBoxMouse    EditBoxMouse_proc    ?
  330. EditBoxSetText  EditBoxSetText_proc  ?
  331.  
  332. SC TStandartColors <>
  333. Window TRect <>
  334. Screen TSize <>
  335.  
  336. RunResult Dword ?
  337. RunParams Dword ?
  338. RunPath   Dword ?
  339.  
  340. AlwaysWithoutQuote Dword ?
  341. ClearBeforeInsert Dword ?
  342.  
  343. Key TKeyboardInput <>
  344. Button TButtonInput <>
  345.  
  346. FileNameAreaBuffer Byte FILE_NAME_AREA_BUFFER_SIZE Dup (?)
  347. OpenFilePathBuffer Byte OPEN_FILE_PATH_BUFFER_SIZE Dup (?)
  348. OpenDirPathBuffer  Byte OPEN_DIR_PATH_BUFFER_SIZE Dup (?)
  349. ProcInfoBuffer     Byte PROC_INFO_BUFFER_SIZE Dup (?)
  350.  
  351. Edit1MouseVariable Dword ?
  352. Edit1TextBuffer Byte EDIT1_TEXT_BUFFER_SIZE + 2 Dup (?) ; buffer for Edit1.text
  353. TmpBuffer Byte TMP_BUFFER_SIZE Dup (?) ; this buffer uses in StrInsert
  354. ; -------------------------------------------------------- ;
  355. .Code ; -------------------------------------------------- ;
  356. ; -------------------------------------------------------- ;
  357. OnRedraw Proc
  358.         Invoke BeginDraw
  359.         Invoke GetStandardColors, Offset SC, SizeOf(SC)
  360.  
  361.         mov    eax, SC.work_graph
  362.         mov    Edit1.focus_border_color, eax
  363.  
  364.         Invoke DrawWindow, Window.Left, Window.Top, Window.Right, Window.Bottom, szTitle, SC.work, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION, CS_MOVABLE
  365.         Invoke DrawText, 5, 5, szTypeNameOfProgram, SC.work_text, 0, DT_ZSTRING + DT_CP866_8X16, 0
  366. ; Browse button
  367.         mov    eax, Window.Right
  368.         sub    eax, 70
  369.         Invoke DrawButton, eax, 26, 52, 21, SC.work_button, 0, 20
  370.         mov    eax, Window.Right
  371.         sub    eax, 56
  372.         Invoke DrawText, eax, 29, CStr("..."), SC.work_button_text, 0, DT_ZSTRING + DT_CP866_8X16, 0
  373. ; Run button
  374.         mov    eax, Window.Right
  375.         sub    eax, 22
  376.         Invoke DrawButton, 5, 52, eax, 21, SC.work_button, 0, 10
  377.         mov    eax, Window.Right
  378.         shr    eax, 1
  379.         sub    eax, 40
  380.         Invoke DrawText, eax, 55, szRun, SC.work_button_text, 0, DT_ZSTRING + DT_CP866_8X16, 0
  381. ; Result text
  382.         Invoke DrawText, 5, 80, RunResult, SC.work_text, 0, DT_ZSTRING + DT_CP866_8X16, 0
  383.         Invoke EditBoxDraw, Offset Edit1
  384.         Invoke EndDraw
  385.         ret
  386. OnRedraw Endp
  387. ; -------------------------------------------------------- ;
  388. StrInsert Proc Uses esi edi Src:Ptr, Dst:Ptr, Pos:Dword
  389. Local TotalLength:Dword
  390.  
  391.         mov    TotalLength, 0
  392.  
  393.         mov    esi, Dst
  394.         mov    edi, Offset TmpBuffer
  395.         mov    ecx, Pos
  396.         add    TotalLength, ecx
  397.         rep    movsb
  398.  
  399.         mov    edi, Src
  400.         mov    ecx, 0FFFFFFFFH
  401.         xor    eax, eax
  402.         repne scasb
  403.         mov    eax, 0FFFFFFFEH
  404.         sub    eax, ecx
  405.         add    TotalLength, eax
  406.  
  407.         mov    esi, Src
  408.         mov    edi, Offset TmpBuffer
  409.         add    edi, Pos
  410.         mov    ecx, eax
  411.         rep    movsb
  412.  
  413.         push   edi
  414.  
  415.         mov    edi, Dst
  416.         add    edi, Pos
  417.         mov    ecx, 0FFFFFFFFH
  418.         xor    eax, eax
  419.         repne scasb
  420.         mov    eax, 0FFFFFFFEH
  421.         sub    eax, ecx
  422.         inc    eax
  423.         add    TotalLength, eax
  424.  
  425.         pop    edi
  426.  
  427.         mov    esi, Dst
  428.         add    esi, Pos
  429.         mov    ecx, eax
  430.         rep movsb
  431.  
  432.         mov    esi, Offset TmpBuffer
  433.         mov    edi, Dst
  434.         mov    ecx, TotalLength
  435.         rep movsb
  436.  
  437.         ret
  438. StrInsert Endp
  439. ; -------------------------------------------------------- ;
  440. OnButtonRun Proc
  441. Local TmpChar: Byte
  442. Local StartWithQuote: Dword
  443. ; need to split path & params
  444.         mov    eax, Edit1.text
  445. ; Skip Spaces
  446.         .While Byte Ptr [eax] == ' '
  447.           inc eax
  448.         .EndW
  449.         mov StartWithQuote, 0
  450. ; Skip Possible Quotation Mark
  451.         .If Byte Ptr [eax] == '"'
  452.           mov StartWithQuote, TRUE
  453.           inc eax
  454.         .EndIf
  455.         mov    RunPath, eax
  456. ; Find Space Or Quote Or EndOfString
  457.         .Repeat
  458.           .If Byte Ptr [eax] == ' '
  459.             .If !StartWithQuote
  460.               mov TmpChar, ' '
  461.               mov Byte Ptr [eax], 0
  462.               push eax ; save pointer
  463.               inc eax
  464. ; Skip Spaces
  465.               .While Byte Ptr [eax] == ' '
  466.                 inc eax
  467.               .EndW
  468.               .Break
  469.             .EndIf
  470.           .ElseIf Byte Ptr [eax] == '"'
  471.             mov TmpChar, '"'
  472.             mov Byte Ptr [eax], 0
  473.             push eax ; save pointer
  474.             inc eax
  475. ; Skip Spaces
  476.             .While Byte Ptr [eax] == ' '
  477.               inc eax
  478.             .EndW
  479. ; params can be written immediately after quotation mark
  480. ; without any spaces
  481. ; like this way: "path"params
  482.             .Break
  483.           .ElseIf Byte Ptr [eax] == 0
  484.             push eax ; save pointer
  485.             mov TmpChar, 0
  486.             .Break
  487.           .EndIf
  488.           inc eax
  489.         .Until 0
  490.         mov RunParams, eax
  491.         Invoke RunFile, RunPath, RunParams
  492.         test   eax, eax
  493.         .If SIGN?
  494.           .If eax == -5
  495.             mov RunResult, szFileNotFound
  496.           .ElseIf eax == -31
  497.             mov RunResult, szFileIsNotExecutable
  498.           .ElseIf eax == -32
  499.             mov RunResult, szTooManyProcesses
  500.           .ElseIf eax == -10
  501.             mov RunResult, szAccessDenied
  502.           .ElseIf eax == -30
  503.             mov RunResult, szOutOfMemory
  504.           .Else
  505.             mov RunResult, szUnknownError
  506.           .EndIf
  507.         .Else
  508.           mov RunResult, szProgramRunSuccessfully
  509.         .EndIf
  510.  
  511.         pop eax ; restore char changed by 0
  512.         mov cl, TmpChar
  513.         mov Byte Ptr [eax], cl
  514.  
  515.         Invoke  OnRedraw
  516.         ret
  517. OnButtonRun Endp
  518. ; -------------------------------------------------------- ;
  519. OnButtonBrowse Proc
  520. Local NeedQuote:Dword
  521.  
  522.         Invoke OpenDialogStart, Offset OD
  523.         .If OD.status != 0
  524.  
  525. ; need to check if spaces are in path and if so then quote path
  526.           mov eax, OD.openfile_path
  527. ; by default assume quote not needed
  528.           mov NeedQuote, 0
  529.           .While Byte Ptr [eax]
  530.             .If Byte Ptr [eax] == ' '
  531. ; need quote
  532.               mov NeedQuote, TRUE
  533.             .EndIf
  534.             inc eax
  535.           .EndW
  536. ; eax -> zero byte
  537.           .If NeedQuote && !AlwaysWithoutQuote
  538.             mov Byte Ptr [eax], '"'
  539.             mov Byte Ptr [eax + 1], 0
  540.             push eax ; save pointer
  541.             mov eax, OD.openfile_path
  542.             dec eax
  543.           .Else
  544.             mov eax, OD.openfile_path
  545.           .EndIf
  546.  
  547.           .If ClearBeforeInsert
  548.             Invoke EditBoxSetText, Offset Edit1, Offset szEmpty
  549.           .EndIf
  550.  
  551.           Invoke StrInsert, eax, Edit1.text, Edit1.pos
  552.  
  553.           .If NeedQuote && !AlwaysWithoutQuote
  554.             pop eax ; restore zero changed by quote
  555.             mov Byte Ptr [eax], 0
  556.           .EndIf
  557.  
  558.           Invoke EditBoxSetText, Offset Edit1, Edit1.text
  559.         .EndIf
  560.         ret
  561. OnButtonBrowse Endp
  562. ; -------------------------------------------------------- ;
  563. @Main:
  564.         Invoke SetEventMask, EM_REDRAW + EM_KEY + EM_BUTTON + EM_MOUSE
  565.         Invoke LoadLibrary, CStr("/sys/lib/box_lib.obj")
  566.         mov    BoxLib, eax
  567.         Invoke LoadLibrary, CStr("/sys/lib/proc_lib.obj")
  568.         mov    ProcLib, eax
  569.         Invoke GetProcAddress, BoxLib, CStr("edit_box")
  570.         mov    EditBoxDraw, eax
  571.         Invoke GetProcAddress, BoxLib, CStr("edit_box_key")
  572.         mov    EditBoxKey, eax
  573.         Invoke GetProcAddress, BoxLib, CStr("edit_box_mouse")
  574.         mov    EditBoxMouse, eax
  575.         Invoke GetProcAddress, BoxLib, CStr("edit_box_set_text")
  576.         mov    EditBoxSetText, eax
  577.         Invoke GetProcAddress, ProcLib, CStr("OpenDialog_init")
  578.         mov    OpenDialogInit, eax
  579.         Invoke GetProcAddress, ProcLib, CStr("OpenDialog_start")
  580.         mov    OpenDialogStart, eax
  581.  
  582. ; Copy command line parameters to EditBox
  583. ; Assume EDIT1_TEXT_BUFFER_SIZE > PARAMS_SIZE(defined in linker-script)    
  584.         Invoke EditBoxSetText, Offset Edit1, Offset AppParams                        
  585.        
  586. ; it need for case if spaces are present in filepath
  587.         lea    eax, [OpenFilePathBuffer + 1]
  588.         mov    OD.openfile_path, eax
  589.         mov    OpenFilePathBuffer, '"'
  590.  
  591.         Invoke OpenDialogInit, Offset OD
  592.  
  593.         Invoke GetScreenSize
  594.         mov    Screen, eax
  595.         shr    eax, 17
  596.         add    eax, 90
  597.         mov    Window.Right, eax
  598.  
  599.         Invoke GetSkinHeight
  600.         add    eax, 100
  601.         mov    Window.Bottom, eax
  602.  
  603.         movzx  eax, Screen.SizeX
  604.         sub    eax, Window.Right
  605.         shr    eax, 1
  606.         mov    Window.Left, eax
  607.  
  608.         movzx  eax, Screen.SizeY
  609.         sub    eax, Window.Bottom
  610.         sub    eax, 100
  611.         mov    Window.Top, eax
  612.  
  613.         mov    eax, Window.Right
  614.         sub    eax, 80
  615.         mov    Edit1.x_size, eax
  616.  
  617.         mov    RunResult, szPressF1
  618.  
  619.         .Repeat
  620.           Invoke WaitEvent
  621.           .If eax == REDRAW_EVENT
  622.             Invoke  OnRedraw
  623.           .ElseIf eax == KEY_EVENT
  624.             Invoke GetControlKeyState
  625.             .If eax & (RIGHT_SHIFT_PRESSED Or LEFT_SHIFT_PRESSED)
  626.               mov AlwaysWithoutQuote, TRUE
  627.             .Else
  628.               mov AlwaysWithoutQuote, FALSE
  629.             .EndIf
  630.             .If eax & (RIGHT_CTRL_PRESSED Or LEFT_CTRL_PRESSED)
  631.               mov ClearBeforeInsert, FALSE
  632.             .Else
  633.               mov ClearBeforeInsert, TRUE
  634.             .EndIf
  635.             Invoke GetKey
  636.             mov Key, eax
  637.             .If Key.Scan == KEY_SCAN_ENTER
  638.               Invoke OnButtonRun
  639.             ; need check Code cause numpad0.Scan = Insert.Scan
  640.             .ElseIf (Key.Scan == KEY_SCAN_INSERT) && \
  641.                     (Key.Code != KEY_CODE_0)
  642.               Invoke OnButtonBrowse
  643.             .ElseIf Key.Scan == KEY_SCAN_F1
  644.               Invoke RunFile, CStr("/SYS/@NOTIFY"), szHelpInfo
  645.             .Else
  646.               Invoke EditBoxKey, Offset Edit1
  647.             .EndIf
  648.           .ElseIf eax == BUTTON_EVENT
  649.             Invoke GetButton
  650.             mov Button, eax
  651.             .If Button.ID == 1
  652.               Invoke ThreadTerminate
  653.             .ElseIf Button.ID == BUTTON_RUN
  654.               Invoke OnButtonRun
  655.             .ElseIf Button.ID == BUTTON_BROWSE
  656.               Invoke OnButtonBrowse
  657.             .EndIf
  658.           .ElseIf eax == MOUSE_EVENT
  659.             Invoke EditBoxMouse, Offset Edit1
  660.           .EndIf
  661.         .Until 0
  662. END