Subversion Repositories Kolibri OS

Rev

Rev 5891 | Rev 5900 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.     use32
  2.     org     0
  3.     db      'MENUET01'
  4.     dd      1, @ENTRY, @end, @memory, @stack, @params, 0
  5.  
  6.     include "../../macros.inc"
  7.     include "../../cmp.inc"
  8.     include "../../proc32.inc"
  9.     include "../../dll.inc"
  10. ;    include "../../debug.inc"
  11.     include "../../notify.inc"
  12.     include "../../string.inc"
  13.  
  14.  LINEH      equ 12
  15.  MARGIN     equ 12
  16.  ICONS      equ 11
  17.  
  18. ;-------------------------------------------------------------------------------
  19.  
  20.  @ENTRY:
  21. ;; INIT HEAP
  22.     mcall   68, 11
  23.  
  24. ;; SAVE FOCUSED WINDOW
  25.     mcall   18, 7
  26.     mov     ecx, eax
  27.     mcall   9, buffer
  28.     m2m     dword [prev_pid], dword [buffer + 30]
  29.  
  30. ;; MAKE IT ALWAYS ON TOP
  31.     mcall   18, 25, 2, -1, 1
  32.  
  33. ;; SET STD PARAMS, IF IT NEEDS
  34.     mov     eax, @params
  35.     cmpne   byte [@params], 0, @f
  36.     mov     eax, sz_std
  37.   @@:
  38.     mov     [params.source], eax
  39.  
  40. ;; PARSE ARGUMENTS
  41.     mov     esi, 0
  42.     call    parse_text
  43.     call    parse_flags
  44.     movzx   ebx, [params.icon]
  45.  
  46. ;; GET PID
  47.     mcall   9, buffer, -1
  48.     mov     eax, dword [buffer + 30]
  49.  
  50. ;; CONVERT PID TO STR
  51.     mov     ebx, 10
  52.     mov     ecx, 0
  53.   @@:
  54.     mov     edx, 0
  55.     div     ebx
  56.     push    edx
  57.     inc     ecx
  58.     cmpne   eax, 0, @b
  59.  
  60.     mov     ebx, ctrl.name
  61.   @@:
  62.     pop     eax
  63.     add     al, "0"
  64.     mov     [ebx], al
  65.     inc     ebx
  66.     loop    @b
  67.  
  68.     mov     dword [ebx + 0], "-NOT"
  69.     mov     dword [ebx + 4], "IFY"
  70.  
  71. ;; LOAD LIBRARIES
  72.     stdcall dll.Load, @imports
  73.  
  74. ;; GET SIZE OF ICONS
  75.     mcall   70, fi
  76.     mov     edx, dword [buffer + 32]
  77.     shl     edx, 2
  78.  
  79. ;; ALLOCATE MEMORY FOR THIS
  80.     stdcall mem.Alloc, edx
  81.     mov     [img_data.rgb_obj], eax
  82.  
  83. ;; READ ICONS
  84.     mov     dword [fi + 00], 0
  85.     mov     dword [fi + 12], edx
  86.     mov     dword [fi + 16], eax
  87.     mcall   70, fi
  88.  
  89. ;; DECODE ICONS
  90.     stdcall dword [img.decode], dword [img_data.rgb_obj], ebx, 0
  91.     mov     dword [img_data.obj], eax
  92.     stdcall dword [img.to_rgb], dword [img_data.obj], dword [img_data.rgb_obj]
  93.     stdcall dword [img.destroy], dword [img_data.obj]
  94.  
  95.  
  96.  
  97. ;; CALC HEIGHT
  98.     mov     eax, [text.lines]
  99.     add     eax, 2
  100.     imul    eax, LINEH
  101.     mov     [window.height], eax
  102.  
  103. ;; CALC OFFSET OF TEXT
  104.     mov     dword [text.offset], MARGIN
  105.     cmpe    byte [params.icon], 0, @f
  106.     add     dword [text.offset], MARGIN + 24
  107.   @@:
  108.  
  109. ;; CALC WIDTH
  110.     mov     eax, [text.max_len]
  111.     dec     eax
  112.     imul    eax, 6
  113.     add     eax, MARGIN
  114.     add     eax, [text.offset]
  115.     mov     [window.width], eax
  116.  
  117.     mcall   14
  118.     mov     ebx, eax
  119.     movzx   ebx, bx
  120.     mov     [scr.height], ebx
  121.     shr     eax, 16
  122.     mov     [scr.width], eax
  123.     sub     eax, [window.width]
  124.     sub     eax, LINEH
  125.     mov     [window.x], eax
  126.  
  127. ;; CALC Y
  128.     mcall   68, 22, sz_shname, 256 + 512, 4 + 1 ;OPEN_ALWAYS AND WRITE
  129.     add     eax, 512
  130.     mov     [shm], eax
  131.  
  132.  s_search:
  133.     mov     eax, [shm]
  134.  
  135.     mov     ebx, 0
  136.     mov     ecx, [text.lines]
  137.     add     ecx, 3
  138.  
  139.     push    eax ebx
  140.  
  141.     mov     eax, [scr.height]
  142.     mov     edx, 0
  143.     mov     ebx, LINEH
  144.     div     ebx
  145.     mov     edx, eax
  146.     add     edx, [shm]
  147.     sub     edx, ecx
  148.     inc     edx
  149.  
  150.     pop     ebx eax
  151.  
  152.  s_area:
  153.     cmpe    [eax], byte 1, .is_1
  154.  
  155.  .is_0:
  156.     inc     ebx
  157.     cmpe    ebx, ecx, s_ok
  158.     jmp     .next
  159.  
  160.  .is_1:
  161.     mov     ebx, 0
  162.  
  163.  .next:
  164.     inc     eax
  165.     cmple   eax, edx, s_area
  166.  
  167.     mcall   5, 10
  168.     jmp     s_search
  169.  
  170.  s_ok:
  171.     sub     eax, ecx
  172.     inc     eax
  173.     mov     [shm.our], eax
  174.  
  175.     mov     edx, eax
  176.     sub     edx, [shm]
  177.     inc     edx
  178.     imul    edx, LINEH
  179.     mov     [window.y], edx
  180.  
  181.     push    eax ebx
  182.     mcall   48, 5
  183.     shr     ebx, 16
  184.     add     [window.y], ebx
  185.     pop     ebx eax
  186.  
  187.   @@:
  188.     mov     [eax], byte 1
  189.     inc     eax
  190.     loop    @b
  191.  
  192.  ;----------------------------
  193.  
  194. ;; SET EVENT MASK
  195.     mcall   40, 101b
  196.  
  197. ;; INIT TIMER
  198.     mov     eax, 60
  199.     imul    eax, [text.lines]
  200.     mov     [timer], eax
  201.     mov     dword [timer.step], 1
  202.     cmpne   byte [params.atcl], 1, @f
  203.     mov     dword [timer.step], 0
  204.   @@:
  205.  
  206. ;; INIT WINDOW
  207.     call    init_window
  208.  
  209. ;; RESTORE FOCUS
  210.     mcall   18, 21, [prev_pid]
  211.     mov     ecx, eax
  212.     mcall   18, 3
  213.  
  214.     jmp     redraw
  215.  
  216.  ;----------------------------
  217.  
  218.  update:
  219.     mcall   23, 10
  220.     cmpe    al, EV_REDRAW, redraw
  221.     cmpe    al, EV_BUTTON, button
  222.  
  223.     mov     edi, update
  224.  
  225. ;; TRY OPEN CONTROLLER
  226.     cmpe    byte [params.ctrl], 1, .fail_controller_open
  227.     mcall   68, 22, ctrl.name, , 0x01
  228.     cmpe    eax, 0, .fail_controller_open
  229.     mov     byte [params.ctrl], 1
  230.     mov     [ctrl.addr], eax
  231.  
  232. ;; COPY TEXT TO CTRL
  233.     add     eax, NTCTRL_TEXT
  234.     mov     ebx, text.buffer
  235.     mov     ecx, [text.lines]
  236.  .copy_start:
  237.     cmpe     ecx, 0, .copy_end
  238.     mov      dl, [ebx]
  239.     cmpne    dl, 0, @f
  240.     mov      dl, "|"
  241.     dec      ecx
  242.   @@:
  243.     mov      [eax], dl
  244.     inc      eax
  245.     inc      ebx
  246.     jmp      .copy_start
  247.  .copy_end:
  248.     mov      byte [eax - 1], 0
  249.  
  250. ;; COPY FLAGS TO CTRL
  251.     mov      eax, [ctrl.addr]
  252.     add      eax, NTCTRL_ICON
  253.     mov      dl, [params.icon]
  254.     mov      [eax], dl
  255.  
  256.     mov      eax, [ctrl.addr]
  257.     add      eax, NTCTRL_TITLE
  258.     mov      dl,  [params.title]
  259.     mov      [eax], dl
  260.  
  261. ;; SET CONTROLLER READY
  262.     mov     eax, [ctrl.addr]
  263.     add     eax, NTCTRL_READY
  264.     mov     byte [eax], 1
  265.  .fail_controller_open:
  266.  
  267.  
  268.     cmpe    [params.ctrl], 0, .no_ctrl
  269. ;; TEST TEXT
  270.     mov     eax, [ctrl.addr]
  271.     add     eax, NTCTRL_APPLY_TEXT
  272.     cmpne   byte [eax], 1, @f
  273.     mov     byte [eax], 0
  274.     mov     eax, [ctrl.addr]
  275.     add     eax, NTCTRL_TEXT
  276.     mov     esi, 1
  277.     call    parse_text
  278.     mov     edi, redraw
  279.   @@:
  280.  
  281. ;; TEST ICON
  282.     mov     eax, [ctrl.addr]
  283.     add     eax, NTCTRL_APPLY_ICON
  284.     cmpne   byte [eax], 1, @f
  285.     mov     eax, [ctrl.addr]
  286.     add     eax, NTCTRL_ICON
  287.     mov     dl, [eax]
  288.     mov     [params.icon], dl
  289.   @@:
  290.  
  291. ;; TEST TITLE
  292.     mov     eax, [ctrl.addr]
  293.     add     eax, NTCTRL_APPLY_TITLE
  294.     cmpne   byte [eax], 1, @f
  295.     mov     eax, [ctrl.addr]
  296.     add     eax, NTCTRL_TITLE
  297.     mov     dl, [eax]
  298.     mov     [params.title], dl
  299.   @@:
  300.  
  301. ;; TEST CLOSE
  302.     mov     eax, [ctrl.addr]
  303.     add     eax, NTCTRL_CLOSE
  304.     cmpe    byte [eax], 1, exit
  305.  
  306.  .no_ctrl:
  307.  
  308.     mov     eax, [timer.step]
  309.     sub     [timer], eax
  310.     cmpe    [timer], dword 0, exit
  311.     jmp     edi
  312.  
  313.  ;----------------------------
  314.  
  315.  exit:
  316.     mov     eax, [shm.our]
  317.     mov     ecx, [text.lines]
  318.     add     ecx, 3
  319.   @@:
  320.     mov     [eax], byte 0
  321.     inc     eax
  322.     loop    @b
  323.  
  324.     mcall   68, 23, sz_shname
  325.  
  326.     mcall   -1
  327.  
  328.  ;----------------------------
  329.  
  330.  button:
  331.     mcall   17
  332.     cmpe    byte [params.clcl], 0, exit
  333.     jmp     update
  334.  
  335.  ;----------------------------
  336.  
  337.  redraw:
  338.     call    draw_window
  339.     call    draw_text
  340.  
  341.     jmp     update
  342.  
  343.  ;----------------------------
  344.  
  345.  draw_window:
  346.     call    init_window
  347.  
  348.     movzx   ebx, bx
  349.     movzx   ecx, cx
  350.     inc     ebx
  351.     inc     ecx
  352.     mcall   8, , , 0x61000001
  353.  
  354.     mov     eax, 13
  355.     mov     ebx, [window.width]
  356.     mov     edx, 0x222222
  357.  
  358.     cmpe    [first_draw], byte 1, .draw_full
  359.     mov     [first_draw], byte 1
  360.     mov     esi, [window.height]
  361.     mov     ecx, LINEH
  362.   @@:
  363.     mcall
  364.     add     ecx, LINEH shl 16
  365.     sub     esi, LINEH
  366.     push    eax ebx
  367.     mcall   5, 1
  368.     pop     ebx eax
  369.     cmpne   esi, 0, @b
  370.  
  371.  .draw_full:
  372.     mcall
  373.  
  374.     mcall   , , 1, 0x121212
  375.  
  376.     mov     ecx, [window.height]
  377.     dec     ecx
  378.     shl     ecx, 16
  379.     inc     ecx
  380.     mcall
  381.  
  382.     mcall   , 1, [window.width]
  383.  
  384.     mov     ebx, [window.width]
  385.     dec     ebx
  386.     shl     ebx, 16
  387.     inc     ebx
  388.     mcall
  389.  
  390.     mcall   1, 1, 1
  391.     mov     ebx, [window.width]
  392.     sub     ebx, 2
  393.     mcall
  394.     mov     ecx, [window.height]
  395.     sub     ecx, 2
  396.     mcall
  397.     mov     ebx, 1
  398.     mcall
  399.  
  400.  ;-----
  401.  
  402.     mov     ecx, [scr.width]
  403.     inc     ecx
  404.  
  405.     mov     eax, 35
  406.     mov     ebx, ecx
  407.     imul    ebx, [window.y]
  408.     add     ebx, [window.x]
  409.     dec     ebx
  410.     mcall
  411.     push    eax
  412.  
  413.     mov     eax, 35
  414.     add     ebx, [window.width]
  415.     add     ebx, 2
  416.     mcall
  417.     push    eax
  418.  
  419.     mov     eax, 35
  420.     mov     edx, ecx
  421.     mov     esi, [window.height]
  422.     dec     esi
  423.     imul    edx, esi
  424.     add     ebx, edx
  425.     mcall
  426.     push    eax
  427.  
  428.     mov     eax, 35
  429.     sub     ebx, [window.width]
  430.     sub     ebx, 2
  431.     mcall
  432.     push    eax
  433.  
  434.  ;-----
  435.  
  436.     mov     eax, 1
  437.  
  438.     pop     edx
  439.     mov     ecx, [window.height]
  440.     dec     ecx
  441.     mcall   , 0
  442.  
  443.     pop     edx
  444.     mov     ebx, [window.width]
  445.     dec     ebx
  446.     mcall
  447.  
  448.     pop     edx
  449.     mcall   , , 0
  450.  
  451.     pop     edx
  452.     mcall   , 0
  453.  
  454.  ;-----
  455.  
  456.     cmpe    byte [params.icon], 0, @f
  457.     movzx   ebx, byte [params.icon]
  458.     dec     ebx
  459.     imul    ebx, 24 * 24 * 3
  460.     add     ebx, [img_data.rgb_obj]
  461.  
  462.     mov     edx, [window.height]
  463.     shr     edx, 1
  464.     sub     edx, 12
  465.     add     edx, LINEH shl 16
  466.  
  467.     mcall   7, , <24, 24>
  468.   @@:
  469.  
  470.     ret
  471.  
  472.  ;----------------------------
  473.  
  474.  draw_text:
  475.     mov     esi, [text.lines]
  476.  
  477.     mov     eax, 4
  478.     mov     ebx, [text.offset]
  479.     shl     ebx, 16
  480.     add     ebx, LINEH + (LINEH - 6) / 2
  481.     mov     edx, text.buffer
  482.  
  483.  .draw_lines:
  484.     mov     ecx, 0x80111111
  485.  
  486.     add     ebx, 0x00010000
  487.     dec     ebx
  488.     mcall
  489.     add     ebx, 2
  490.     mcall
  491.     sub     ebx, 0x00020000
  492.     mcall
  493.     sub     ebx, 2
  494.     mcall
  495.  
  496.     add     ebx, 0x00010001
  497.     mov     ecx, 0x80D0D0D0
  498.     mcall
  499.  
  500.     add     ebx, LINEH
  501.     dec     esi
  502.     cmpe    esi, 0, .draw_lines.end
  503.  
  504.     inc     edx
  505.   @@:
  506.     cmpe    [edx], byte 0, @f
  507.     inc     edx
  508.     jmp     @b
  509.   @@:
  510.     inc     edx
  511.     jmp     .draw_lines
  512.  
  513.  .draw_lines.end:
  514.  
  515.     cmpne   byte [params.title], 1, @f
  516.     mov     edx, text.buffer
  517.     mov     ecx, 0x80111111
  518.     and     ebx, 0xFFFF0000
  519.     add     ebx, 1 shl 16 + LINEH + (LINEH - 6) / 2
  520.     mcall
  521.  
  522.     mov     ecx, 0x80FFFFFF
  523.     sub     ebx, 0x00010000
  524.     mcall
  525.   @@:
  526.  
  527.     ret
  528.  
  529.  ;----------------------------
  530.  
  531.  init_window:
  532.     dec     dword [window.width]
  533.     dec     dword [window.height]
  534.     mcall   0, <[window.x], [window.width]>, <[window.y], [window.height]>, 0x61000000
  535.     inc     dword [window.width]
  536.     inc     dword [window.height]
  537.  
  538.     ret
  539.  
  540.  ;----------------------------
  541.  
  542.  parse_text:
  543.     mov     dword [text.max_len], 0
  544.     mov     dword [text.lines], 1
  545.     mov     ebx, text.buffer
  546.     mov     ecx, 0
  547.     mov     dl, 0
  548.     mov     dh, 0
  549.  
  550.     cmpe    esi, 1, .parse_loop
  551.     cmpne   byte [eax], "'", @f
  552.     mov     dl, "'"
  553.     mov     dh, 1
  554.   @@:
  555.     cmpne   byte [eax], '"', @f
  556.     mov     dl, '"'
  557.     mov     dh, 1
  558.   @@:
  559.     cmpne   dh, 1, @f
  560.     inc     eax
  561.   @@:
  562.  
  563.  .parse_loop:
  564.     cmpe    byte [eax],  0, .parse_loop.end
  565.     cmpe    byte [eax], dl, .parse_loop.end
  566.  
  567.     cmpe    byte [eax], 10, .newline
  568.     cmpe    esi, 1, .next_set_char
  569.     cmpne   byte [eax], "\", @f
  570.     cmpe    byte [eax + 1], dl, .quote
  571.     cmpe    byte [eax + 1], "n", .newline_esc
  572.     jmp     @f
  573.  
  574.  .quote:
  575.     inc     eax
  576.     jmp     .next_set_char
  577.  
  578.  .newline_esc:
  579.     inc     eax
  580.  
  581.  .newline:
  582.     mov     byte [ebx], 0
  583.     cmple   ecx, dword [text.max_len], .skip_max_len
  584.     mov     dword [text.max_len], ecx
  585.  .skip_max_len:
  586.     mov     ecx, 0
  587.     inc     dword [text.lines]
  588.     jmp     .next
  589.   @@:
  590.  
  591.  .next_set_char:
  592.     mov     dh, [eax]
  593.     mov     [ebx], dh
  594.  
  595.  .next:
  596.     inc     eax
  597.     inc     ebx
  598.     inc     ecx
  599.     jmp     .parse_loop
  600.  .parse_loop.end:
  601.  
  602.     cmple   ecx, dword [text.max_len], @f
  603.     mov     dword [text.max_len], ecx
  604.   @@:
  605.  
  606.     cmpge   [text.max_len], dword 25, @f
  607.     mov     [text.max_len], dword 25
  608.   @@:
  609.  
  610.     mov     [ebx], byte 0
  611.  
  612.     ret
  613.  
  614.  ;----------------------------
  615.  
  616.  parse_flags:
  617.     mov     byte [params.atcl], 0
  618.     mov     byte [params.title], 0
  619.     mov     byte [params.icon], 0
  620.  
  621.  .loop:
  622.     mov     dl, [eax]
  623.  
  624.     cmpe    dl, 0, .exit
  625.     cmpe    dl, "d", .set_atcl
  626.     cmpe    dl, "c", .set_clcl
  627.     cmpe    dl, "t", .set_title
  628.  
  629.     mov     bl, 1
  630.     mov     ecx, sz_icons
  631.   @@:
  632.     cmpe    dl, [ecx], .set_icon
  633.     inc     bl
  634.     inc     ecx
  635.     cmpne   [ecx], byte 0, @b
  636.     jmp     .next_char
  637.  
  638.  .set_atcl:
  639.     mov     byte [params.atcl], 1
  640.     jmp     .next_char
  641.  
  642.  .set_clcl:
  643.     mov     byte [params.clcl], 1
  644.     jmp     .next_char
  645.  
  646.  .set_title:
  647.     mov     byte [params.title], 1
  648.     jmp     .next_char
  649.  
  650.  .set_icon:
  651.     mov     [params.icon], bl
  652.  
  653.  .next_char:
  654.     inc     eax
  655.     jmp     .loop
  656.  
  657.  .exit:
  658.     ret
  659.  
  660.  ;----------------------------
  661.  
  662.  @imports:
  663.     library img, "libimg.obj"
  664.     import  img, img.to_rgb,  "img_to_rgb2", \
  665.                  img.decode,  "img_decode",  \
  666.                  img.destroy, "img_destroy"
  667.  
  668.  ;----------------------------
  669.  
  670.  sz_icons   db "AEWONIFCMDS", 0
  671.  sz_ifile   db "/sys/notify3.png", 0
  672.  sz_shname  db "notify-mem-v01", 0
  673.  sz_std     db "'NOTIFY 3\n",                 \
  674.                "d - disable auto-closing\n",  \
  675.                "c - disable click-closing\n", \
  676.                "t - title\n",                 \
  677.                " \n",                         \
  678.                "ICONS:\n",                    \
  679.                "A - application\n",           \
  680.                "E - error\n",                 \
  681.                "W - warning\n",               \
  682.                "O - ok\n",                    \
  683.                "N - network\n",               \
  684.                "I - info\n",                  \
  685.                "F - folder\n",                \
  686.                "C - component\n",             \
  687.                "M - mail\n",                  \
  688.                "D - download\n",              \
  689.                "S - audio player",            \
  690.                "' -td", 0
  691.  
  692.  fi:
  693.             dd 5
  694.             dd 0, 0, 0
  695.             dd buffer
  696.             db 0
  697.             dd sz_ifile
  698.  
  699.  ;----------------------------
  700.  
  701.  @end:
  702.  
  703. ;=====================================================================
  704.  
  705.  window:
  706.  .x        rd 1
  707.  .y        rd 1
  708.  .width    rd 1
  709.  .height   rd 1
  710.  
  711.  scr:
  712.  .width    rd 1
  713.  .height   rd 1
  714.  
  715.  text:
  716.  .buffer   rb 2048
  717.  .lines    rd 1
  718.  .max_len  rd 1
  719.  .offset   rd 1
  720.  
  721.  params:
  722.  .source   rd 1
  723.  .atcl     rb 1
  724.  .clcl     rb 1
  725.  .title    rb 1
  726.  .icon     rb 1
  727.  .ctrl     rb 1
  728.  
  729.  img_data:
  730.  .rgb_obj  rd 1
  731.  .obj      rd 1
  732.  
  733.  timer:
  734.  .value    rd 1
  735.  .step     rd 1
  736.  
  737.  shm:
  738.  .addr     rd 1
  739.  .our      rd 1
  740.  
  741.  ctrl:
  742.  .name     rb 31
  743.  .addr     rd 1
  744.  
  745.  buffer     rb 1024
  746.  first_draw rb 1
  747.  prev_pid   rd 1
  748.  
  749. ;=====================================================================
  750.             rb 2048
  751.  @stack:
  752.  @params    rb 2048
  753.  
  754.  @memory:
  755.