Subversion Repositories Kolibri OS

Rev

Rev 3248 | 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.     pixmap = (int*)win->ctx->pixmap->data;
  81.     pixmap+= CAPTION_HEIGHT*win->w;
  82.     src = res_border_left;
  83.  
  84.     for(fr->left.t; i < fr->left.b; i++)
  85.     {
  86.         for(j = 0; j < FRAME_WIDTH; j++)
  87.             pixmap[j] = src[j];
  88.  
  89.         pixmap+= win->ctx->pixmap->pitch/4;
  90.     };
  91.  
  92.  
  93.     pixmap = (int*)win->ctx->pixmap->data;
  94.     pixmap+= (CAPTION_HEIGHT+1)*win->w - FRAME_WIDTH;
  95.     src = res_border_right;
  96.  
  97.     for(i=fr->right.t; i < fr->right.b; i++)
  98.     {
  99.         for(j = 0; j < FRAME_WIDTH; j++)
  100.             pixmap[j] = src[j];
  101.  
  102.         pixmap+= win->ctx->pixmap->pitch/4;
  103.     };
  104.  
  105.     pixmap = (int*)win->ctx->pixmap->data;
  106.  
  107.     pixmap+= fr->bottom.t * win->w;
  108.  
  109.     for(i=0; i < FRAME_WIDTH; i++)
  110.     {
  111.         for(j = 0; j < win->w; j++)
  112.             pixmap[j] = 0x808080;
  113.  
  114.         pixmap+= win->ctx->pixmap->pitch/4;
  115.     };
  116.  
  117.     ctrl_t *child;
  118.     child  = (ctrl_t*)fr->child.next;
  119.  
  120.     while( &child->link != &fr->child)
  121.     {
  122.         send_message(child, 1, 0, 0);
  123.         child = (ctrl_t*)child->link.next;
  124.     };
  125.  
  126.     return 0;
  127. };
  128.  
  129. int frame_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
  130. {
  131.     static  pos_t spos;
  132.     static  track_mode;
  133.  
  134.     uint32_t cursor;
  135.     ctrl_t   *child;
  136.  
  137.     frame_t  *fr  = (frame_t*)ctrl;
  138.     window_t *win = (window_t*)fr->parent;
  139.     rect_t  *rc = NULL;
  140.     int  x, y;
  141.  
  142.     if(win->win_state == FULLSCREEN)
  143.         return 0;
  144.    
  145.     x = ((pos_t)arg2).x;
  146.     y = ((pos_t)arg2).y;
  147.  
  148.  
  149. //    child = get_child(ctrl, x, y);
  150. //    if(child)
  151. //    {
  152. //        return send_message(child, msg, 0, arg2);
  153. //    };
  154.  
  155.     if( (msg == MSG_LBTNDOWN) ||
  156.         (msg == MSG_MOUSEMOVE) )
  157.     {
  158.         x = ((pos_t)arg2).x;
  159.         y = ((pos_t)arg2).y;
  160.  
  161.         if( pt_in_rect(&fr->left, x, y))
  162.         {
  163.             rc = &fr->left;
  164.             if( (y+24) > win->h)
  165.                  cursor = cursor_nesw;
  166.             else
  167.                 cursor = cursor_we;
  168.             set_cursor(cursor);
  169.             main_cursor = cursor;
  170.         }
  171.         else if( pt_in_rect(&fr->right, x, y))
  172.         {
  173. //            printf("pos x%d y%d\n", x, y);
  174.  
  175.             rc = &fr->right;
  176.             if( (y+24) > win->h)
  177.                  cursor = cursor_nwse;
  178.             else
  179.                  cursor = cursor_we;
  180. //            printf("Set cursor %x\n", cursor);
  181.             set_cursor(cursor);
  182.             main_cursor = cursor;
  183.         }
  184.         else if( pt_in_rect(&fr->bottom, x, y))
  185.         {
  186.             rc = &fr->bottom;
  187.             cursor = cursor_ns;
  188.             if(x+24 > win->w)
  189.                 cursor = cursor_nwse;
  190.             else if(x < rc->l+24)
  191.                 cursor = cursor_nesw;
  192.             set_cursor(cursor);
  193.             main_cursor = cursor;
  194.         }
  195.     };
  196.  
  197.     switch( msg )
  198.     {
  199.         case MSG_LBTNDOWN:
  200.             if( rc != NULL)
  201.             {
  202.                 int relx, rely;
  203.  
  204.                 capture_mouse(ctrl);
  205.                 spos = get_cursor_pos();
  206.                 fr->track = rc;
  207.  
  208.                 relx = spos.x - win->rc.l;
  209.                 rely = spos.y - win->rc.t;
  210. //                printf("relx %d rely %d\n", relx, rely);
  211.  
  212.                 if(fr->track == &fr->left ||
  213.                    fr->track == &fr->right)
  214.                 {
  215.                     if(rely+24 > win->h)
  216.                         track_mode = 1;
  217.                 };
  218.                 if(fr->track == &fr->bottom)
  219.                 {
  220.                     if(relx < 24)
  221.                         track_mode = 2;
  222.                     else if(relx+24 > win->w)
  223.                        track_mode = 3;
  224.                 }
  225.  
  226.                 break;
  227.             };
  228.  
  229.         case MSG_LBTNUP:
  230.             release_mouse();
  231.             fr->track     = NULL;
  232.             track_mode    = 0;
  233.             break;
  234.  
  235.         case MSG_MOUSEMOVE:
  236.             if(mouse_capture == ctrl)
  237.             {
  238.                 pos_t npos;
  239.                 npos = get_cursor_pos();
  240. //                printf("cursor pos %dx%d\n", npos.x, npos.y);
  241.  
  242.                 if( npos.val != spos.val)
  243.                 {
  244.                     int w, h;
  245.  
  246.                     rect_t nrc = win->rc;
  247.                     spos = npos;
  248.  
  249.                     if(fr->track == &fr->left)
  250.                     {
  251.                         nrc.l = npos.x-2;
  252.                         if(nrc.l < 0)
  253.                             nrc.l = 0;
  254.                         if(track_mode==1)
  255.                             nrc.b = npos.y+2;
  256.                     }
  257.                     else if(fr->track == &fr->right)
  258.                     {
  259.                         nrc.r = npos.x+2;
  260.                         if(track_mode==1)
  261.                             nrc.b = npos.y+2;
  262.                     }
  263.                     else if(fr->track == &fr->bottom)
  264.                     {
  265.                         nrc.b = npos.y+2;
  266.                         if(track_mode==2)
  267.                             nrc.l = npos.x-2;
  268.                         else if (track_mode==3)
  269.                             nrc.r = npos.x+2;
  270.                     };
  271.  
  272.                     w = nrc.r - nrc.l;
  273.                     h = nrc.b - nrc.t;
  274.  
  275.                     if(w <310)
  276.                         w = 310;
  277.                     if(h < 120)
  278.                         h = 120;
  279.  
  280.                     __asm__ __volatile__(
  281.                     "int $0x40"
  282.                     ::"a"(67), "b"(nrc.l), "c"(nrc.t),
  283.                     "d"(w-1),"S"(h-1) );
  284.                 };
  285.             }
  286.     };
  287.  
  288.     return 1;
  289. }
  290.  
  291.