/[weechat]/weechat/src/gui/curses/gui-display.c
ViewVC logotype

Diff of /weechat/src/gui/curses/gui-display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.112 by flashcode, Wed Sep 14 08:39:14 2005 UTC revision 1.113 by flashcode, Thu Sep 15 08:21:37 2005 UTC
# Line 594  gui_display_line (t_gui_window *window, Line 594  gui_display_line (t_gui_window *window,
594      int word_length_with_spaces, word_length;      int word_length_with_spaces, word_length;
595      int skip_spaces;      int skip_spaces;
596            
     if (window->win_chat_cursor_y > window->win_chat_height - 1)  
         return 0;  
       
597      if (simulate)      if (simulate)
598      {      {
599          x = window->win_chat_cursor_x;          x = window->win_chat_cursor_x;
# Line 607  gui_display_line (t_gui_window *window, Line 604  gui_display_line (t_gui_window *window,
604      }      }
605      else      else
606      {      {
607            if (window->win_chat_cursor_y > window->win_chat_height - 1)
608                return 0;
609          x = window->win_chat_cursor_x;          x = window->win_chat_cursor_x;
610          y = window->win_chat_cursor_y;          y = window->win_chat_cursor_y;
611          num_lines = gui_display_line (window, line, 0, 1);          num_lines = gui_display_line (window, line, 0, 1);
# Line 682  gui_display_line (t_gui_window *window, Line 681  gui_display_line (t_gui_window *window,
681  }  }
682    
683  /*  /*
684     * gui_calculate_line_diff: returns pointer to line & offset for a difference
685     *                          with given line
686     */
687    
688    void
689    gui_calculate_line_diff (t_gui_window *window, t_gui_line **line, int *line_pos,
690                             int difference)
691    {
692        int backward, current_size;
693        
694        if (!line || !line_pos)
695            return;
696        
697        backward = (difference < 0);
698        
699        if (!(*line))
700        {
701            /* if looking backward, start at last line of buffer */
702            if (backward)
703            {
704                *line = window->buffer->last_line;
705                if (!(*line))
706                    return;
707                current_size = gui_display_line (window, *line, 0, 1);
708                if (current_size == 0)
709                    current_size = 1;
710                *line_pos = current_size - 1;
711            }
712            /* if looking forward, start at first line of buffer */
713            else
714            {
715                *line = window->buffer->lines;
716                if (!(*line))
717                    return;
718                *line_pos = 0;
719                current_size = gui_display_line (window, *line, 0, 1);
720            }
721        }
722        else
723            current_size = gui_display_line (window, *line, 0, 1);
724        
725        while ((*line) && (difference != 0))
726        {
727            /* looking backward */
728            if (backward)
729            {
730                if (*line_pos > 0)
731                    (*line_pos)--;
732                else
733                {
734                    *line = (*line)->prev_line;
735                    if (*line)
736                    {
737                        current_size = gui_display_line (window, *line, 0, 1);
738                        if (current_size == 0)
739                            current_size = 1;
740                        *line_pos = current_size - 1;
741                    }
742                }
743                difference++;
744            }
745            /* looking forward */
746            else
747            {
748                if (*line_pos < current_size - 1)
749                    (*line_pos)++;
750                else
751                {
752                    *line = (*line)->next_line;
753                    if (*line)
754                    {
755                        current_size = gui_display_line (window, *line, 0, 1);
756                        if (current_size == 0)
757                            current_size = 1;
758                        *line_pos = 0;
759                    }
760                }
761                difference--;
762            }
763        }
764        
765        /* first or last line reached */
766        if (!(*line))
767        {
768            if (backward)
769            {
770                /* first line reached */
771                *line = window->buffer->lines;
772                *line_pos = 0;
773            }
774            else
775            {
776                /* last line reached => consider we'll display all until the end */
777                *line_pos = 0;
778            }
779        }
780    }
781    
782    /*
783   * gui_draw_buffer_chat: draw chat window for a buffer   * gui_draw_buffer_chat: draw chat window for a buffer
784   */   */
785    
# Line 692  gui_draw_buffer_chat (t_gui_buffer *buff Line 790  gui_draw_buffer_chat (t_gui_buffer *buff
790      t_gui_line *ptr_line;      t_gui_line *ptr_line;
791      t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc;      t_irc_dcc *dcc_first, *dcc_selected, *ptr_dcc;
792      char format_empty[32];      char format_empty[32];
793      int i, j, lines_used, num_bars;      int i, j, line_pos, count, num_bars;
794      char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") };      char *unit_name[] = { N_("bytes"), N_("Kb"), N_("Mb"), N_("Gb") };
795      char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" };      char *unit_format[] = { "%.0Lf", "%.1Lf", "%.02Lf", "%.02Lf" };
796      long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 };      long unit_divide[] = { 1, 1024, 1024*1024, 1024*1024,1024 };
# Line 835  gui_draw_buffer_chat (t_gui_buffer *buff Line 933  gui_draw_buffer_chat (t_gui_buffer *buff
933              }              }
934              else              else
935              {              {
                 ptr_line = buffer->last_line;  
                 lines_used = 0;  
936                  ptr_win->win_chat_cursor_x = 0;                  ptr_win->win_chat_cursor_x = 0;
937                  ptr_win->win_chat_cursor_y = 0;                  ptr_win->win_chat_cursor_y = 0;
938                  while (ptr_line                  
939                      && (lines_used < (ptr_win->win_chat_height + ptr_win->sub_lines)))                  /* display at position of scrolling */
940                    if (ptr_win->start_line)
941                  {                  {
942                      lines_used += gui_display_line (ptr_win, ptr_line, 0, 1);                      ptr_line = ptr_win->start_line;
943                      ptr_line = ptr_line->prev_line;                      line_pos = ptr_win->start_line_pos;
944                  }                  }
945                  if (lines_used > (ptr_win->win_chat_height + ptr_win->sub_lines))                  else
946                  {                  {
947                      /* screen will be full (we'll display only end of 1st line) */                      /* look for first line to display, sarting from last line */
948                      ptr_line = (ptr_line) ? ptr_line->next_line : buffer->lines;                      ptr_line = NULL;
949                        line_pos = 0;
950                        gui_calculate_line_diff (ptr_win, &ptr_line, &line_pos,
951                                                 (-1) * (ptr_win->win_chat_height - 1));
952                    }
953    
954                    if (line_pos > 0)
955                    {
956                        /* display end of first line at top of screen */
957                      gui_display_line (ptr_win, ptr_line,                      gui_display_line (ptr_win, ptr_line,
958                                        gui_display_line (ptr_win, ptr_line, 0, 1) -                                        gui_display_line (ptr_win, ptr_line, 0, 1) -
959                                        (lines_used - (ptr_win->win_chat_height + ptr_win->sub_lines)), 0);;                                        line_pos, 0);
960                      ptr_line = ptr_line->next_line;                      ptr_line = ptr_line->next_line;
961                      ptr_win->first_line_displayed = 0;                      ptr_win->first_line_displayed = 0;
962                  }                  }
963                  else                  else
964                  {                      ptr_win->first_line_displayed =
965                      /* all lines are displayed */                          (ptr_line == ptr_win->buffer->lines);
                     if (!ptr_line)  
                     {  
                         ptr_win->first_line_displayed = 1;  
                         ptr_line = buffer->lines;  
                     }  
                     else  
                     {  
                         ptr_win->first_line_displayed = 0;  
                         ptr_line = ptr_line->next_line;  
                     }  
                 }  
966                                    
967                  /* display lines */                  /* display lines */
968                    count = 0;
969                  while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1))                  while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1))
970                  {                  {
971                      gui_display_line (ptr_win, ptr_line, 0, 0);                      count = gui_display_line (ptr_win, ptr_line, 0, 0);
972                      ptr_line = ptr_line->next_line;                      ptr_line = ptr_line->next_line;
973                  }                  }
974                                    
975                    /* check if last line of buffer is entirely displayed and scrolling */
976                    /* if so, disable scroll (to remove status bar indicator) */
977                    if (!ptr_line && ptr_win->start_line)
978                    {
979                        if (count == gui_display_line (ptr_win, ptr_win->buffer->last_line, 0, 1))
980                        {
981                            ptr_win->start_line = NULL;
982                            ptr_win->start_line_pos = 0;
983                        }
984                    }
985                    
986                  /* cursor is below end line of chat window? */                  /* cursor is below end line of chat window? */
987                  if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1)                  if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1)
988                  {                  {
# Line 1360  gui_draw_buffer_status (t_gui_buffer *bu Line 1466  gui_draw_buffer_status (t_gui_buffer *bu
1466          if (x < 0)          if (x < 0)
1467              x = 0;              x = 0;
1468          gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS_MORE);          gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS_MORE);
1469          if (ptr_win->sub_lines > 0)          if (ptr_win->start_line)
1470              mvwprintw (ptr_win->win_status, 0, x, "%s", string);              mvwprintw (ptr_win->win_status, 0, x, "%s", string);
1471          else          else
1472          {          {
# Line 1762  gui_switch_to_buffer (t_gui_window *wind Line 1868  gui_switch_to_buffer (t_gui_window *wind
1868      else      else
1869          window->win_status = newwin (1, window->win_width, window->win_y + window->win_height - 2, window->win_x);          window->win_status = newwin (1, window->win_width, window->win_y + window->win_height - 2, window->win_x);
1870            
1871      window->sub_lines = 0;      window->start_line = NULL;
1872        window->start_line_pos = 0;
1873            
1874      buffer->num_displayed++;      buffer->num_displayed++;
1875            
# Line 1774  gui_switch_to_buffer (t_gui_window *wind Line 1881  gui_switch_to_buffer (t_gui_window *wind
1881   */   */
1882    
1883  t_gui_buffer *  t_gui_buffer *
1884  gui_get_dcc_buffer ()  gui_get_dcc_buffer (t_gui_window *window)
1885  {  {
1886      t_gui_buffer *ptr_buffer;      t_gui_buffer *ptr_buffer;
1887            
# Line 1787  gui_get_dcc_buffer () Line 1894  gui_get_dcc_buffer ()
1894      if (ptr_buffer)      if (ptr_buffer)
1895          return ptr_buffer;          return ptr_buffer;
1896      else      else
1897          return gui_buffer_new (gui_current_window, NULL, NULL, 1, 0);          return gui_buffer_new (window, NULL, NULL, 1, 0);
1898  }  }
1899    
1900  /*  /*
# Line 1795  gui_get_dcc_buffer () Line 1902  gui_get_dcc_buffer ()
1902   */   */
1903    
1904  void  void
1905  gui_input_page_up ()  gui_input_page_up (t_gui_window *window)
1906  {  {
1907      if (!gui_ok)      if (!gui_ok)
1908          return;          return;
1909            
1910      if (!gui_current_window->first_line_displayed)      if (!window->first_line_displayed)
1911      {      {
1912          gui_current_window->sub_lines +=          gui_calculate_line_diff (window, &window->start_line,
1913              gui_current_window->win_chat_height - 1;                                   &window->start_line_pos,
1914          gui_draw_buffer_chat (gui_current_window->buffer, 0);                                   (window->start_line) ?
1915          gui_draw_buffer_status (gui_current_window->buffer, 0);                                   (-1) * (window->win_chat_height - 1) :
1916                                     (-1) * ((window->win_chat_height - 1) * 2));
1917            gui_draw_buffer_chat (window->buffer, 0);
1918            gui_draw_buffer_status (window->buffer, 0);
1919      }      }
1920  }  }
1921    
# Line 1814  gui_input_page_up () Line 1924  gui_input_page_up ()
1924   */   */
1925    
1926  void  void
1927  gui_input_page_down ()  gui_input_page_down (t_gui_window *window)
1928  {  {
1929        t_gui_line *ptr_line;
1930        int line_pos;
1931        
1932      if (!gui_ok)      if (!gui_ok)
1933          return;          return;
1934            
1935      if (gui_current_window->sub_lines > 0)      if (window->start_line)
1936      {      {
1937          gui_current_window->sub_lines -=          gui_calculate_line_diff (window, &window->start_line,
1938              gui_current_window->win_chat_height - 1;                                   &window->start_line_pos,
1939          if (gui_current_window->sub_lines < 0)                                   window->win_chat_height - 1);
1940              gui_current_window->sub_lines = 0;          
1941          gui_draw_buffer_chat (gui_current_window->buffer, 0);          /* check if we can display all */
1942          gui_draw_buffer_status (gui_current_window->buffer, 0);          ptr_line = window->start_line;
1943            line_pos = window->start_line_pos;
1944            gui_calculate_line_diff (window, &ptr_line,
1945                                     &line_pos,
1946                                     window->win_chat_height - 1);
1947            if (!ptr_line)
1948            {
1949                window->start_line = NULL;
1950                window->start_line_pos = 0;
1951            }
1952            
1953            gui_draw_buffer_chat (window->buffer, 0);
1954            gui_draw_buffer_status (window->buffer, 0);
1955      }      }
1956  }  }
1957    
# Line 1835  gui_input_page_down () Line 1960  gui_input_page_down ()
1960   */   */
1961    
1962  void  void
1963  gui_input_nick_beginning ()  gui_input_nick_beginning (t_gui_window *window)
1964  {  {
1965      if (!gui_ok)      if (!gui_ok)
1966          return;          return;
1967            
1968      if (gui_buffer_has_nicklist (gui_current_window->buffer))      if (gui_buffer_has_nicklist (window->buffer))
1969      {      {
1970          if (gui_current_window->win_nick_start > 0)          if (window->win_nick_start > 0)
1971          {          {
1972              gui_current_window->win_nick_start = 0;              window->win_nick_start = 0;
1973              gui_draw_buffer_nick (gui_current_window->buffer, 1);              gui_draw_buffer_nick (window->buffer, 1);
1974          }          }
1975      }      }
1976  }  }
# Line 1855  gui_input_nick_beginning () Line 1980  gui_input_nick_beginning ()
1980   */   */
1981    
1982  void  void
1983  gui_input_nick_end ()  gui_input_nick_end (t_gui_window *window)
1984  {  {
1985      int new_start;      int new_start;
1986            
1987      if (!gui_ok)      if (!gui_ok)
1988          return;          return;
1989            
1990      if (gui_buffer_has_nicklist (gui_current_window->buffer))      if (gui_buffer_has_nicklist (window->buffer))
1991      {      {
1992          new_start =          new_start =
1993              CHANNEL(gui_current_window->buffer)->nicks_count -              CHANNEL(window->buffer)->nicks_count - window->win_nick_height;
             gui_current_window->win_nick_height;  
1994          if (new_start < 0)          if (new_start < 0)
1995              new_start = 0;              new_start = 0;
1996          else if (new_start >= 1)          else if (new_start >= 1)
1997              new_start++;              new_start++;
1998                    
1999          if (new_start != gui_current_window->win_nick_start)          if (new_start != window->win_nick_start)
2000          {          {
2001              gui_current_window->win_nick_start = new_start;              window->win_nick_start = new_start;
2002              gui_draw_buffer_nick (gui_current_window->buffer, 1);              gui_draw_buffer_nick (window->buffer, 1);
2003          }          }
2004      }      }
2005  }  }
# Line 1885  gui_input_nick_end () Line 2009  gui_input_nick_end ()
2009   */   */
2010    
2011  void  void
2012  gui_input_nick_page_up ()  gui_input_nick_page_up (t_gui_window *window)
2013  {  {
2014      if (!gui_ok)      if (!gui_ok)
2015          return;          return;
2016            
2017      if (gui_buffer_has_nicklist (gui_current_window->buffer))      if (gui_buffer_has_nicklist (window->buffer))
2018      {      {
2019          if (gui_current_window->win_nick_start > 0)          if (window->win_nick_start > 0)
2020          {          {
2021              gui_current_window->win_nick_start -=              window->win_nick_start -= (window->win_nick_height - 1);
2022                  (gui_current_window->win_nick_height - 1);              if (window->win_nick_start <= 1)
2023              if (gui_current_window->win_nick_start <= 1)                  window->win_nick_start = 0;
2024                  gui_current_window->win_nick_start = 0;              gui_draw_buffer_nick (window->buffer, 1);
             gui_draw_buffer_nick (gui_current_window->buffer, 1);  
2025          }          }
2026      }      }
2027  }  }
# Line 1908  gui_input_nick_page_up () Line 2031  gui_input_nick_page_up ()
2031   */   */
2032    
2033  void  void
2034  gui_input_nick_page_down ()  gui_input_nick_page_down (t_gui_window *window)
2035  {  {
2036      if (!gui_ok)      if (!gui_ok)
2037          return;          return;
2038            
2039      if (gui_buffer_has_nicklist (gui_current_window->buffer))      if (gui_buffer_has_nicklist (window->buffer))
2040      {      {
2041          if ((CHANNEL(gui_current_window->buffer)->nicks_count >          if ((CHANNEL(window->buffer)->nicks_count > window->win_nick_height)
2042               gui_current_window->win_nick_height)              && (window->win_nick_start + window->win_nick_height - 1
2043              && (gui_current_window->win_nick_start +                  < CHANNEL(window->buffer)->nicks_count))
2044                  gui_current_window->win_nick_height - 1          {
2045                  < CHANNEL(gui_current_window->buffer)->nicks_count))              if (window->win_nick_start == 0)
2046          {                  window->win_nick_start += (window->win_nick_height - 1);
             if (gui_current_window->win_nick_start == 0)  
                 gui_current_window->win_nick_start +=  
                     (gui_current_window->win_nick_height - 1);  
2047              else              else
2048                  gui_current_window->win_nick_start +=                  window->win_nick_start += (window->win_nick_height - 2);
2049                      (gui_current_window->win_nick_height - 2);              gui_draw_buffer_nick (window->buffer, 1);
             gui_draw_buffer_nick (gui_current_window->buffer, 1);  
2050          }          }
2051      }      }
2052  }  }

Legend:
Removed from v.1.112  
changed lines
  Added in v.1.113

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26