Subversion Repositories Kolibri OS

Rev

Rev 3068 | 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.     x = ((pos_t)arg2).x;
  143.     y = ((pos_t)arg2).y;
  144.  
  145.  
  146. //    child = get_child(ctrl, x, y);
  147. //    if(child)
  148. //    {
  149. //        return send_message(child, msg, 0, arg2);
  150. //    };
  151.  
  152.     if( (msg == MSG_LBTNDOWN) ||
  153.         (msg == MSG_MOUSEMOVE) )
  154.     {
  155.         x = ((pos_t)arg2).x;
  156.         y = ((pos_t)arg2).y;
  157.  
  158.         if( pt_in_rect(&fr->left, x, y))
  159.         {
  160.             rc = &fr->left;
  161.             if( (y+24) > win->h)
  162.                  cursor = cursor_nesw;
  163.             else
  164.                 cursor = cursor_we;
  165.             set_cursor(cursor);
  166.             main_cursor = cursor;
  167.         }
  168.         else if( pt_in_rect(&fr->right, x, y))
  169.         {
  170. //            printf("pos x%d y%d\n", x, y);
  171.  
  172.             rc = &fr->right;
  173.             if( (y+24) > win->h)
  174.                  cursor = cursor_nwse;
  175.             else
  176.                  cursor = cursor_we;
  177. //            printf("Set cursor %x\n", cursor);
  178.             set_cursor(cursor);
  179.             main_cursor = cursor;
  180.         }
  181.         else if( pt_in_rect(&fr->bottom, x, y))
  182.         {
  183.             rc = &fr->bottom;
  184.             cursor = cursor_ns;
  185.             if(x+24 > win->w)
  186.                 cursor = cursor_nwse;
  187.             else if(x < rc->l+24)
  188.                 cursor = cursor_nesw;
  189.             set_cursor(cursor);
  190.             main_cursor = cursor;
  191.         }
  192.     };
  193.  
  194.     switch( msg )
  195.     {
  196.         case MSG_LBTNDOWN:
  197.             if( rc != NULL)
  198.             {
  199.                 int relx, rely;
  200.  
  201.                 capture_mouse(ctrl);
  202.                 spos = get_cursor_pos();
  203.                 fr->track = rc;
  204.  
  205.                 relx = spos.x - win->rc.l;
  206.                 rely = spos.y - win->rc.t;
  207. //                printf("relx %d rely %d\n", relx, rely);
  208.  
  209.                 if(fr->track == &fr->left ||
  210.                    fr->track == &fr->right)
  211.                 {
  212.                     if(rely+24 > win->h)
  213.                         track_mode = 1;
  214.                 };
  215.                 if(fr->track == &fr->bottom)
  216.                 {
  217.                     if(relx < 24)
  218.                         track_mode = 2;
  219.                     else if(relx+24 > win->w)
  220.                        track_mode = 3;
  221.                 }
  222.  
  223.                 break;
  224.             };
  225.  
  226.         case MSG_LBTNUP:
  227.             release_mouse();
  228.             fr->track     = NULL;
  229.             track_mode    = 0;
  230.             break;
  231.  
  232.         case MSG_MOUSEMOVE:
  233.             if(mouse_capture == ctrl)
  234.             {
  235.                 pos_t npos;
  236.                 npos = get_cursor_pos();
  237. //                printf("cursor pos %dx%d\n", npos.x, npos.y);
  238.  
  239.                 if( npos.val != spos.val)
  240.                 {
  241.                     int w, h;
  242.  
  243.                     rect_t nrc = win->rc;
  244.                     spos = npos;
  245.  
  246.                     if(fr->track == &fr->left)
  247.                     {
  248.                         nrc.l = npos.x-2;
  249.                         if(nrc.l < 0)
  250.                             nrc.l = 0;
  251.                         if(track_mode==1)
  252.                             nrc.b = npos.y+2;
  253.                     }
  254.                     else if(fr->track == &fr->right)
  255.                     {
  256.                         nrc.r = npos.x+2;
  257.                         if(track_mode==1)
  258.                             nrc.b = npos.y+2;
  259.                     }
  260.                     else if(fr->track == &fr->bottom)
  261.                     {
  262.                         nrc.b = npos.y+2;
  263.                         if(track_mode==2)
  264.                             nrc.l = npos.x-2;
  265.                         else if (track_mode==3)
  266.                             nrc.r = npos.x+2;
  267.                     };
  268.  
  269.                     w = nrc.r - nrc.l;
  270.                     h = nrc.b - nrc.t;
  271.  
  272.                     if(w <310)
  273.                         w = 310;
  274.                     if(h < 120)
  275.                         h = 120;
  276.  
  277.                     __asm__ __volatile__(
  278.                     "int $0x40"
  279.                     ::"a"(67), "b"(nrc.l), "c"(nrc.t),
  280.                     "d"(w-1),"S"(h-1) );
  281.                 };
  282.             }
  283.     };
  284.  
  285.     return 1;
  286. }
  287.  
  288.