Subversion Repositories Kolibri OS

Rev

Rev 4438 | Rev 5372 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "winlib.h"
  6.  
  7. #define CAPTION_CORNER_W    8
  8. #define FRAME_WIDTH         7
  9.  
  10. extern uint32_t  main_cursor;
  11.  
  12. extern uint32_t  cursor_ns;
  13. extern uint32_t  cursor_we;
  14. extern uint32_t  cursor_nwse;
  15. extern uint32_t  cursor_nesw;
  16.  
  17. extern ctrl_t  *mouse_capture;
  18.  
  19. static int frame_proc(ctrl_t *ctrl, uint32_t msg,
  20.                       uint32_t arg1, uint32_t arg2);
  21.  
  22. void adjust_frame(window_t *win)
  23. {
  24.     frame_t *fr = &win->frame;
  25.  
  26.     fr->left.l  = 0;
  27.     fr->left.t  = win->client.t;
  28.     fr->left.r  = FRAME_WIDTH;
  29.     fr->left.b  = win->h-FRAME_WIDTH;
  30.  
  31.     fr->right.l = win->w - FRAME_WIDTH;
  32.     fr->right.t = win->client.t;
  33.     fr->right.r = win->w;
  34.     fr->right.b = win->h-FRAME_WIDTH;
  35.  
  36.     fr->bottom.l = 0;
  37.     fr->bottom.t = win->h - FRAME_WIDTH;
  38.     fr->bottom.r = win->w;
  39.     fr->bottom.b = win->h;
  40.  
  41.     win->client.l = FRAME_WIDTH;
  42.     win->client.r = win->w - FRAME_WIDTH;
  43. //    win->client.b = win->h - FRAME_WIDTH;
  44. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  45. //            fr->left.l,fr->left.t,fr->left.r,fr->left.b);
  46. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  47. //            fr->right.l,fr->right.t,fr->right.r,fr->right.b);
  48. //    printf("Left: l:%d t:%d r:%d b:%d\n",
  49. //            fr->bottom.l,fr->bottom.t,fr->bottom.r,fr->bottom.b);
  50.  
  51. };
  52.  
  53. void init_frame(window_t *win)
  54. {
  55.     frame_t *fr = &win->frame;
  56.  
  57.     link_initialize(&fr->link);
  58.     list_initialize(&fr->child);
  59.  
  60.     fr->handler = frame_proc;
  61.     fr->parent  = (ctrl_t*)win;
  62.  
  63.     adjust_frame(win);
  64. };
  65.  
  66.  
  67. extern int res_border_left[];
  68. extern int res_border_right[];
  69.  
  70. int draw_frame(window_t *win)
  71. {
  72.     int *pixmap, *src;
  73.     int  i, j;
  74.  
  75.     int w;
  76.  
  77.     frame_t *fr = &win->frame;
  78.  
  79.     pixmap = (int*)win->ctx->pixmap->data;
  80.     pixmap+= CAPTION_HEIGHT*win->w;
  81.     src = res_border_left;
  82.  
  83.     for(fr->left.t; i < fr->left.b; i++)
  84.     {
  85.         for(j = 0; j < FRAME_WIDTH; j++)
  86.             pixmap[j] = src[j];
  87.  
  88.         pixmap+= win->ctx->pixmap->pitch/4;
  89.     };
  90.  
  91.  
  92.     pixmap = (int*)win->ctx->pixmap->data;
  93.     pixmap+= (CAPTION_HEIGHT+1)*win->w - FRAME_WIDTH;
  94.     src = res_border_right;
  95.  
  96.     for(i=fr->right.t; i < fr->right.b; i++)
  97.     {
  98.         for(j = 0; j < FRAME_WIDTH; j++)
  99.             pixmap[j] = src[j];
  100.  
  101.         pixmap+= win->ctx->pixmap->pitch/4;
  102.     };
  103.  
  104.     pixmap = (int*)win->ctx->pixmap->data;
  105.  
  106.     pixmap+= fr->bottom.t * win->w;
  107.  
  108.     for(i=0; i < FRAME_WIDTH; i++)
  109.     {
  110.         for(j = 0; j < win->w; j++)
  111.             pixmap[j] = 0x808080;
  112.  
  113.         pixmap+= win->ctx->pixmap->pitch/4;
  114.     };
  115.  
  116.     ctrl_t *child;
  117.     child  = (ctrl_t*)fr->child.next;
  118.  
  119.     while( &child->link != &fr->child)
  120.     {
  121.         send_message(child, 1, 0, 0);
  122.         child = (ctrl_t*)child->link.next;
  123.     };
  124.  
  125.     return 0;
  126. };
  127.  
  128. int frame_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
  129. {
  130.     static  pos_t spos;
  131.     static  track_mode;
  132.  
  133.     uint32_t cursor;
  134.     ctrl_t   *child;
  135.  
  136.     frame_t  *fr  = (frame_t*)ctrl;
  137.     window_t *win = (window_t*)fr->parent;
  138.     rect_t  *rc = NULL;
  139.     int  x, y;
  140.  
  141.     if(win->win_state == FULLSCREEN)
  142.         return 0;
  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 = GetMousePos(POS_SCREEN);
  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 = GetMousePos(POS_SCREEN);
  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 <310)
  275.                         w = 310;
  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.