Subversion Repositories Kolibri OS

Rev

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