Subversion Repositories Kolibri OS

Rev

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