Subversion Repositories Kolibri OS

Rev

Rev 2693 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include "system.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include "winlib.h"
  7.  
  8. #define CAPTION_CORNER_W    8
  9. #define FRAME_WIDTH         7
  10.  
  11. extern uint32_t  main_cursor;
  12.  
  13. extern uint32_t  cursor_ns;
  14. extern uint32_t  cursor_we;
  15. extern uint32_t  cursor_nwse;
  16. extern uint32_t  cursor_nesw;
  17.  
  18. extern ctrl_t  *mouse_capture;
  19.  
  20. static int frame_proc(ctrl_t *ctrl, uint32_t msg,
  21.                       uint32_t arg1, uint32_t arg2);
  22.  
  23. void adjust_frame(window_t *win)
  24. {
  25.     frame_t *fr = &win->frame;
  26.  
  27.     fr->left.l  = 0;
  28.     fr->left.t  = win->client.t;
  29.     fr->left.r  = FRAME_WIDTH;
  30.     fr->left.b  = win->h-FRAME_WIDTH;
  31.  
  32.     fr->right.l = win->w - FRAME_WIDTH;
  33.     fr->right.t = win->client.t;
  34.     fr->right.r = win->w;
  35.     fr->right.b = win->h-FRAME_WIDTH;
  36.  
  37.     fr->bottom.l = 0;
  38.     fr->bottom.t = win->h - FRAME_WIDTH;
  39.     fr->bottom.r = win->w;
  40.     fr->bottom.b = win->h;
  41.  
  42.     win->client.l = FRAME_WIDTH;
  43.     win->client.r = win->w - FRAME_WIDTH;
  44. //    win->client.b = win->h - FRAME_WIDTH;
  45. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  46. //            fr->left.l,fr->left.t,fr->left.r,fr->left.b);
  47. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  48. //            fr->right.l,fr->right.t,fr->right.r,fr->right.b);
  49. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  50. //            fr->bottom.l,fr->bottom.t,fr->bottom.r,fr->bottom.b);
  51.  
  52. };
  53.  
  54. void init_frame(window_t *win)
  55. {
  56.     frame_t *fr = &win->frame;
  57.  
  58.     link_initialize(&fr->link);
  59.     list_initialize(&fr->child);
  60.  
  61.     fr->handler = frame_proc;
  62.     fr->parent  = (ctrl_t*)win;
  63.  
  64.     adjust_frame(win);
  65. };
  66.  
  67.  
  68. extern int res_border_left[];
  69. extern int res_border_right[];
  70.  
  71. int draw_frame(window_t *win)
  72. {
  73.     int *pixmap, *src;
  74.     int  i, j;
  75.  
  76.     int w;
  77.  
  78.     frame_t *fr = &win->frame;
  79.  
  80.  
  81.     pixmap = win->ctx->pixmap;
  82.     pixmap+= CAPTION_HEIGHT*win->w;
  83.     src = res_border_left;
  84.  
  85.     for(fr->left.t; i < fr->left.b; i++)
  86.     {
  87.         for(j = 0; j < FRAME_WIDTH; j++)
  88.             pixmap[j] = src[j];
  89.  
  90.         pixmap+= win->ctx->stride/4;
  91.     };
  92.  
  93.  
  94.     pixmap = win->ctx->pixmap;
  95.     pixmap+= (CAPTION_HEIGHT+1)*win->w - FRAME_WIDTH;
  96.     src = res_border_right;
  97.  
  98.     for(i=fr->right.t; i < fr->right.b; i++)
  99.     {
  100.         for(j = 0; j < FRAME_WIDTH; j++)
  101.             pixmap[j] = src[j];
  102.  
  103.         pixmap+= win->ctx->stride/4;
  104.     };
  105.  
  106.     pixmap = win->ctx->pixmap;
  107.  
  108.     pixmap+= fr->bottom.t * win->w;
  109.  
  110.     for(i=0; i < FRAME_WIDTH; i++)
  111.     {
  112.         for(j = 0; j < win->w; j++)
  113.             pixmap[j] = 0x808080;
  114.  
  115.         pixmap+= win->ctx->stride/4;
  116.     };
  117.  
  118.     ctrl_t *child;
  119.     child  = (ctrl_t*)fr->child.next;
  120.  
  121.     while( &child->link != &fr->child)
  122.     {
  123.         send_message(child, 1, 0, 0);
  124.         child = (ctrl_t*)child->link.next;
  125.     };
  126.  
  127.     return 0;
  128. };
  129.  
  130. int frame_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
  131. {
  132.     static  pos_t spos;
  133.     static  track_mode;
  134.  
  135.     uint32_t cursor;
  136.     ctrl_t   *child;
  137.  
  138.     frame_t  *fr  = (frame_t*)ctrl;
  139.     window_t *win = (window_t*)fr->parent;
  140.     rect_t  *rc = NULL;
  141.     int  x, y;
  142.  
  143.     x = ((pos_t)arg2).x;
  144.     y = ((pos_t)arg2).y;
  145.  
  146.  
  147. //    child = get_child(ctrl, x, y);
  148. //    if(child)
  149. //    {
  150. //        return send_message(child, msg, 0, arg2);
  151. //    };
  152.  
  153.     if( (msg == MSG_LBTNDOWN) ||
  154.         (msg == MSG_MOUSEMOVE) )
  155.     {
  156.         x = ((pos_t)arg2).x;
  157.         y = ((pos_t)arg2).y;
  158.  
  159.         if( pt_in_rect(&fr->left, x, y))
  160.         {
  161.             rc = &fr->left;
  162.             if( (y+24) > win->h)
  163.                  cursor = cursor_nesw;
  164.             else
  165.                 cursor = cursor_we;
  166.             set_cursor(cursor);
  167.             main_cursor = cursor;
  168.         }
  169.         else if( pt_in_rect(&fr->right, x, y))
  170.         {
  171. //            printf("pos x%d y%d\n", x, y);
  172.  
  173.             rc = &fr->right;
  174.             if( (y+24) > win->h)
  175.                  cursor = cursor_nwse;
  176.             else
  177.                  cursor = cursor_we;
  178. //            printf("Set cursor %x\n", cursor);
  179.             set_cursor(cursor);
  180.             main_cursor = cursor;
  181.         }
  182.         else if( pt_in_rect(&fr->bottom, x, y))
  183.         {
  184.             rc = &fr->bottom;
  185.             cursor = cursor_ns;
  186.             if(x+24 > win->w)
  187.                 cursor = cursor_nwse;
  188.             else if(x < rc->l+24)
  189.                 cursor = cursor_nesw;
  190.             set_cursor(cursor);
  191.             main_cursor = cursor;
  192.         }
  193.     };
  194.  
  195.     switch( msg )
  196.     {
  197.         case MSG_LBTNDOWN:
  198.             if( rc != NULL)
  199.             {
  200.                 int relx, rely;
  201.  
  202.                 capture_mouse(ctrl);
  203.                 spos = get_cursor_pos();
  204.                 fr->track = rc;
  205.  
  206.                 relx = spos.x - win->rc.l;
  207.                 rely = spos.y - win->rc.t;
  208. //                printf("relx %d rely %d\n", relx, rely);
  209.  
  210.                 if(fr->track == &fr->left ||
  211.                    fr->track == &fr->right)
  212.                 {
  213.                     if(rely+24 > win->h)
  214.                         track_mode = 1;
  215.                 };
  216.                 if(fr->track == &fr->bottom)
  217.                 {
  218.                     if(relx < 24)
  219.                         track_mode = 2;
  220.                     else if(relx+24 > win->w)
  221.                        track_mode = 3;
  222.                 }
  223.  
  224.                 break;
  225.             };
  226.  
  227.         case MSG_LBTNUP:
  228.             release_mouse();
  229.             fr->track     = NULL;
  230.             track_mode    = 0;
  231.             break;
  232.  
  233.         case MSG_MOUSEMOVE:
  234.             if(mouse_capture == ctrl)
  235.             {
  236.                 pos_t npos;
  237.                 npos = get_cursor_pos();
  238. //                printf("cursor pos %dx%d\n", npos.x, npos.y);
  239.  
  240.                 if( npos.val != spos.val)
  241.                 {
  242.                     int w, h;
  243.  
  244.                     rect_t nrc = win->rc;
  245.                     spos = npos;
  246.  
  247.                     if(fr->track == &fr->left)
  248.                     {
  249.                         nrc.l = npos.x-2;
  250.                         if(nrc.l < 0)
  251.                             nrc.l = 0;
  252.                         if(track_mode==1)
  253.                             nrc.b = npos.y+2;
  254.                     }
  255.                     else if(fr->track == &fr->right)
  256.                     {
  257.                         nrc.r = npos.x+2;
  258.                         if(track_mode==1)
  259.                             nrc.b = npos.y+2;
  260.                     }
  261.                     else if(fr->track == &fr->bottom)
  262.                     {
  263.                         nrc.b = npos.y+2;
  264.                         if(track_mode==2)
  265.                             nrc.l = npos.x-2;
  266.                         else if (track_mode==3)
  267.                             nrc.r = npos.x+2;
  268.                     };
  269.  
  270.                     w = nrc.r - nrc.l;
  271.                     h = nrc.b - nrc.t;
  272.  
  273.                     if(w <310)
  274.                         w = 310;
  275.                     if(h < 120)
  276.                         h = 120;
  277.  
  278.                     __asm__ __volatile__(
  279.                     "int $0x40"
  280.                     ::"a"(67), "b"(nrc.l), "c"(nrc.t),
  281.                     "d"(w-1),"S"(h-1) );
  282.                 };
  283.             }
  284.     };
  285.  
  286.     return 1;
  287. }
  288.  
  289.