/[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.78 by flashcode, Tue Feb 22 22:31:57 2005 UTC revision 1.79 by flashcode, Sat Feb 26 11:10:20 2005 UTC
# Line 378  gui_draw_buffer_title (t_gui_buffer *buf Line 378  gui_draw_buffer_title (t_gui_buffer *buf
378  }  }
379    
380  /*  /*
381   * gui_get_line_num_splits: returns number of lines on window   * gui_display_new_line: display a new line
  *                          (depending on window width and type (server/channel)  
  *                          for alignment)  
382   */   */
383    
384  int  void
385  gui_get_line_num_splits (t_gui_window *window, t_gui_line *line)  gui_display_new_line (t_gui_window *window, int num_lines, int count,
386                          int *lines_displayed, int simulate)
387  {  {
388      int length, width;      char format_empty[32];
389            
390      /* TODO: modify arbitraty value for non aligning messages on time/nick? */      if ((count == 0) || (*lines_displayed >= num_lines - count))
     if (line->length_align >= window->win_chat_width - 5)  
391      {      {
392          length = line->length;          if ((!simulate) && (window->win_chat_cursor_x <= window->win_chat_width - 1))
393          width = window->win_chat_width;          {
394                snprintf (format_empty, 32, "%%-%ds",
395                          window->win_chat_width - window->win_chat_cursor_x);
396                wprintw (window->win_chat, format_empty, " ");
397            }
398            window->win_chat_cursor_y++;
399      }      }
400      else      window->win_chat_cursor_x = 0;
401        (*lines_displayed)++;
402    }
403    
404    /*
405     * gui_message_get_next_char: returns next char of message at offset
406     */
407    
408    void
409    gui_message_get_next_char (t_gui_message **message, int *offset)
410    {
411        if (!(*message))
412            return;
413        (*offset)++;
414        if (!((*message)->message[*offset]))
415      {      {
416          length = line->length - line->length_align;          *message = (*message)->next_message;
417          width = window->win_chat_width - line->length_align;          *offset = 0;
418      }      }
       
     if (length == 0)  
         return 1;  
     else  
         return (length % width == 0) ? (length / width) : ((length / width) + 1);  
419  }  }
420    
421  /*  /*
422   * gui_display_end_of_line: display end of a line in the chat window   * gui_display_word: display a word on chat buffer
423   */   */
424    
425  void  void
426  gui_display_end_of_line (t_gui_window *window, t_gui_line *line, int count)  gui_display_word (t_gui_window *window, t_gui_line *line,
427                      t_gui_message *message, int offset,
428                      t_gui_message *end_msg, int end_offset,
429                      int num_lines, int count, int *lines_displayed, int simulate)
430  {  {
431      int lines_displayed, num_lines, offset, remainder, num_displayed;      char format_align[32];
432      t_gui_message *ptr_message;      char saved_char_end, saved_char;
433      char saved_char, format_align[32], format_empty[32];      int end_of_word, chars_to_display, num_displayed;
434        
435        if (window->win_chat_cursor_y > window->win_chat_height - 1)
436            return;
437            
438      snprintf (format_align, 32, "%%-%ds", line->length_align);      snprintf (format_align, 32, "%%-%ds", line->length_align);
439      num_lines = gui_get_line_num_splits (window, line);      
440      ptr_message = line->messages;      saved_char_end = '\0';
441      offset = 0;      if (end_msg)
442      lines_displayed = 0;      {
443      while (ptr_message)          saved_char_end = end_msg->message[end_offset + 1];
444            end_msg->message[end_offset + 1] = '\0';
445        }
446        
447        end_of_word = 0;
448        while (!end_of_word)
449      {      {
450          /* set text color if beginning of message */          /* set text color if beginning of message */
451          if (offset == 0)          if (!simulate)
452              gui_window_set_color (window->win_chat, ptr_message->color);              gui_window_set_color (window->win_chat, message->color);
453                    
454          /* insert spaces for align text under time/nick */          /* insert spaces for align text under time/nick */
455          if ((lines_displayed > 0) && (window->win_chat_cursor_x == 0))          if ((line->length_align > 0) &&
456                (window->win_chat_cursor_x == 0) &&
457                (*lines_displayed > 0) &&
458                /* TODO: modify arbitraty value for non aligning messages on time/nick? */
459                (line->length_align < (window->win_chat_width - 5)))
460          {          {
461              if (lines_displayed >= num_lines - count)              if (!simulate)
462                  mvwprintw (window->win_chat,                  mvwprintw (window->win_chat,
463                             window->win_chat_cursor_y,                             window->win_chat_cursor_y,
464                             window->win_chat_cursor_x,                             window->win_chat_cursor_x,
465                             format_align, " ");                             format_align, " ");
466              window->win_chat_cursor_x += line->length_align;              window->win_chat_cursor_x += line->length_align;
467          }          }
468                    
469          remainder = strlen (ptr_message->message + offset);          chars_to_display = strlen (message->message + offset);
470          if (window->win_chat_cursor_x + remainder >  
471              window->win_chat_width - 1)          /* too long for current line */
472            if (window->win_chat_cursor_x + chars_to_display > window->win_chat_width)
473          {          {
474              num_displayed = window->win_chat_width -              num_displayed = window->win_chat_width - window->win_chat_cursor_x;
475                  window->win_chat_cursor_x;              saved_char = message->message[offset + num_displayed];
476              if (num_displayed < 0)              message->message[offset + num_displayed] = '\0';
477                  return;              if ((!simulate) &&
478              saved_char = ptr_message->message[offset + num_displayed];                  ((count == 0) || (*lines_displayed >= num_lines - count)))
             ptr_message->message[offset + num_displayed] = '\0';  
             if (lines_displayed >= num_lines - count)  
479                  mvwprintw (window->win_chat,                  mvwprintw (window->win_chat,
480                             window->win_chat_cursor_y,                             window->win_chat_cursor_y,
481                             window->win_chat_cursor_x,                             window->win_chat_cursor_x,
482                             "%s", ptr_message->message + offset);                             "%s", message->message + offset);
483              ptr_message->message[offset + num_displayed] = saved_char;              message->message[offset + num_displayed] = saved_char;
484              offset += num_displayed;              offset += num_displayed;
485          }          }
486          else          else
487          {          {
488              num_displayed = remainder;  
489              if (lines_displayed >= num_lines - count)              num_displayed = chars_to_display;
490                if ((!simulate) &&
491                    ((count == 0) || (*lines_displayed >= num_lines - count)))
492                  mvwprintw (window->win_chat,                  mvwprintw (window->win_chat,
493                             window->win_chat_cursor_y,                             window->win_chat_cursor_y,
494                             window->win_chat_cursor_x,                             window->win_chat_cursor_x,
495                             "%s", ptr_message->message + offset);                             "%s", message->message + offset);
496              ptr_message = ptr_message->next_message;              if (message == end_msg)
497              offset = 0;              {
498                    offset = end_offset;
499                    if (end_msg)
500                        end_msg->message[end_offset + 1] = saved_char_end;
501                    gui_message_get_next_char (&message, &offset);
502                }
503                else
504                {
505                    message = message->next_message;
506                    offset = 0;
507                }
508          }          }
509            
510          window->win_chat_cursor_x += num_displayed;          window->win_chat_cursor_x += num_displayed;
511          if (!ptr_message ||          
512              (window->win_chat_cursor_x > (window->win_chat_width - 1)))          /* display new line? */
513            if (!message ||
514                ((window->win_chat_cursor_y <= window->win_chat_height - 1) &&
515                (window->win_chat_cursor_x > (window->win_chat_width - 1))))
516                gui_display_new_line (window, num_lines, count,
517                                      lines_displayed, simulate);
518            
519            /* end of word? */
520            if (!message || (message->prev_message == end_msg) ||
521                ((message == end_msg) && (offset > end_offset)))
522                end_of_word = 1;
523        }
524            
525        if (end_msg)
526            end_msg->message[end_offset + 1] = saved_char_end;
527    }
528    
529    /*
530     * gui_get_word_info: returns info about next word: beginning, end, length
531     */
532    
533    void
534    gui_get_word_info (t_gui_message *message, int offset,
535                       t_gui_message **word_start_msg, int *word_start_offset,
536                       t_gui_message **word_end_msg, int *word_end_offset,
537                       int *word_length_with_spaces, int *word_length)
538    {
539        *word_start_msg = NULL;
540        *word_start_offset = 0;
541        *word_end_msg = NULL;
542        *word_end_offset = 0;
543        *word_length_with_spaces = 0;
544        *word_length = 0;
545        
546        /* leading spaces */
547        while (message && (message->message[offset] == ' '))
548        {
549            (*word_length_with_spaces)++;
550            gui_message_get_next_char (&message, &offset);
551        }
552        
553        /* not only spaces? */
554        if (message)
555        {
556            *word_start_msg = message;
557            *word_start_offset = offset;
558            
559            /* find end of word */
560            while (message && (message->message[offset]) && (message->message[offset] != ' '))
561          {          {
562              if (lines_displayed >= num_lines - count)              *word_end_msg = message;
563              {              *word_end_offset = offset;
564                  if (window->win_chat_cursor_x <= window->win_chat_width - 1)              (*word_length_with_spaces)++;
565                  {              (*word_length)++;
566                      snprintf (format_empty, 32, "%%-%ds",              gui_message_get_next_char (&message, &offset);
                               window->win_chat_width - window->win_chat_cursor_x);  
                     wprintw (window->win_chat, format_empty, " ");  
                 }  
                 window->win_chat_cursor_y++;  
             }  
             window->win_chat_cursor_x = 0;  
             lines_displayed++;  
567          }          }
568      }      }
569  }  }
570    
571  /*  /*
572   * gui_display_line: display a line in the chat window   * gui_display_line: display a line in the chat window
573   *                   if stop_at_end == 1, screen will not scroll and then we   *                   if count == 0, display whole line
574   *                   exit since chat window is full   *                   if count > 0, display 'count' lines (beginning from the end)
575   *                   returns: 1 if stop_at_end == 0 or screen not full   *                   if simulate == 1, nothing is displayed (for counting how
576   *                            0 if screen is full and if stop_at_end == 1   *                                     many lines would have been lines displayed)
577     *                   returns: number of lines displayed (or simulated)
578   */   */
579    
580  int  int
581  gui_display_line (t_gui_window *window, t_gui_line *line, int stop_at_end)  gui_display_line (t_gui_window *window, t_gui_line *line, int count, int simulate)
582  {  {
583      int offset, remainder, num_displayed;      int num_lines, x, y, offset, lines_displayed;
584      t_gui_message *ptr_message;      t_gui_message *ptr_message, *word_start_msg, *word_end_msg;
585      char saved_char, format_align[32], format_empty[32];      int word_start_offset, word_end_offset;
586        int word_length_with_spaces, word_length;
587        int skip_spaces;
588        
589        if (window->win_chat_cursor_y > window->win_chat_height - 1)
590            return 0;
591        
592        if (simulate)
593        {
594            x = window->win_chat_cursor_x;
595            y = window->win_chat_cursor_y;
596            window->win_chat_cursor_x = 0;
597            window->win_chat_cursor_y = 0;
598            num_lines = 0;
599        }
600        else
601        {
602            x = window->win_chat_cursor_x;
603            y = window->win_chat_cursor_y;
604            num_lines = gui_display_line (window, line, 0, 1);
605            window->win_chat_cursor_x = x;
606            window->win_chat_cursor_y = y;
607        }
608            
     snprintf (format_align, 32, "%%-%ds", line->length_align);  
609      ptr_message = line->messages;      ptr_message = line->messages;
610      offset = 0;      offset = 0;
611        lines_displayed = 0;
612      while (ptr_message)      while (ptr_message)
613      {      {
614          /* cursor is below end line of chat window */          skip_spaces = 0;
615          if (window->win_chat_cursor_y > window->win_chat_height - 1)          gui_get_word_info (ptr_message, offset,
616                               &word_start_msg, &word_start_offset,
617                               &word_end_msg, &word_end_offset,
618                               &word_length_with_spaces, &word_length);
619            
620            /* spaces + word too long for current line */
621            if ((window->win_chat_cursor_x + word_length_with_spaces > window->win_chat_width - 1)
622                && (word_length < window->win_chat_width - line->length_align))
623          {          {
624              /*if (!stop_at_end)              gui_display_new_line (window, num_lines, count,
625                  wscrl (buffer->window->win_chat, +1);*/                                    &lines_displayed, simulate);
626              window->win_chat_cursor_x = 0;              ptr_message = word_start_msg;
627              window->win_chat_cursor_y = window->win_chat_height - 1;              offset = word_start_offset;
             if (stop_at_end)  
                 return 0;  
             window->first_line_displayed = 0;  
628          }          }
629                    
630          /* set text color if beginning of message */          /* word is exactly width => we'll skip next leading spaces for next line */
631          if (offset == 0)          if (word_length == window->win_chat_width - line->length_align)
632              gui_window_set_color (window->win_chat, ptr_message->color);              skip_spaces = 1;
633                    
634          /* insert spaces for align text under time/nick */          /* display word */
635          if ((window->win_chat_cursor_x == 0) &&          gui_display_word (window, line,
636              (!(ptr_message->type & MSG_TYPE_TIME)) &&                            ptr_message, offset,
637              (!(ptr_message->type & MSG_TYPE_NICK)) &&                            word_end_msg, word_end_offset,
638              (line->length_align > 0) &&                            num_lines, count, &lines_displayed, simulate);
             /* TODO: modify arbitraty value for non aligning messages on time/nick? */  
             (line->length_align < (window->win_chat_width - 5)))  
         {  
             mvwprintw (window->win_chat,  
                        window->win_chat_cursor_y,  
                        window->win_chat_cursor_x,  
                        format_align, " ");  
             window->win_chat_cursor_x += line->length_align;  
         }  
639                    
640          remainder = strlen (ptr_message->message + offset);          /* move pointer after end of word */
641          if (window->win_chat_cursor_x + remainder > window->win_chat_width)          ptr_message = word_end_msg;
642          {          offset = word_end_offset;
643              num_displayed = window->win_chat_width -          gui_message_get_next_char (&ptr_message, &offset);
644                  window->win_chat_cursor_x;          
645              saved_char = ptr_message->message[offset + num_displayed];          /* skip leading spaces? */
646              ptr_message->message[offset + num_displayed] = '\0';          if (skip_spaces)
             mvwprintw (window->win_chat,  
                        window->win_chat_cursor_y,  
                        window->win_chat_cursor_x,  
                        "%s", ptr_message->message + offset);  
             ptr_message->message[offset + num_displayed] = saved_char;  
             offset += num_displayed;  
         }  
         else  
         {  
             num_displayed = remainder;  
             mvwprintw (window->win_chat,  
                        window->win_chat_cursor_y,  
                        window->win_chat_cursor_x,  
                        "%s", ptr_message->message + offset);  
             offset = 0;  
             ptr_message = ptr_message->next_message;  
         }  
         window->win_chat_cursor_x += num_displayed;  
         if (!ptr_message ||  
             (window->win_chat_cursor_x > (window->win_chat_width - 1)))  
647          {          {
648              if (!ptr_message ||              while (ptr_message && (ptr_message->message[offset] == ' '))
649                  ((window->win_chat_cursor_y <= window->win_chat_height - 1) &&                  gui_message_get_next_char (&ptr_message, &offset);
                 (window->win_chat_cursor_x > window->win_chat_width - 1)))  
             {  
                 if (window->win_chat_cursor_x <= window->win_chat_width - 1)  
                 {  
                     snprintf (format_empty, 32, "%%-%ds",  
                               window->win_chat_width - window->win_chat_cursor_x);  
                     wprintw (window->win_chat, format_empty, " ");  
                 }  
                 window->win_chat_cursor_y++;  
             }  
             window->win_chat_cursor_x = 0;  
650          }          }
651      }      }
652      return 1;      
653        if (simulate)
654        {
655            window->win_chat_cursor_x = x;
656            window->win_chat_cursor_y = y;
657        }
658        
659        return lines_displayed;
660  }  }
661    
662  /*  /*
# Line 700  gui_draw_buffer_chat (t_gui_buffer *buff Line 774  gui_draw_buffer_chat (t_gui_buffer *buff
774                  while (ptr_line                  while (ptr_line
775                      && (lines_used < (ptr_win->win_chat_height + ptr_win->sub_lines)))                      && (lines_used < (ptr_win->win_chat_height + ptr_win->sub_lines)))
776                  {                  {
777                      lines_used += gui_get_line_num_splits (ptr_win, ptr_line);                      lines_used += gui_display_line (ptr_win, ptr_line, 0, 1);
778                      ptr_line = ptr_line->prev_line;                      ptr_line = ptr_line->prev_line;
779                  }                  }
780                  ptr_win->win_chat_cursor_x = 0;                  ptr_win->win_chat_cursor_x = 0;
# Line 709  gui_draw_buffer_chat (t_gui_buffer *buff Line 783  gui_draw_buffer_chat (t_gui_buffer *buff
783                  {                  {
784                      /* screen will be full (we'll display only end of 1st line) */                      /* screen will be full (we'll display only end of 1st line) */
785                      ptr_line = (ptr_line) ? ptr_line->next_line : buffer->lines;                      ptr_line = (ptr_line) ? ptr_line->next_line : buffer->lines;
786                      gui_display_end_of_line (ptr_win, ptr_line,                      gui_display_line (ptr_win, ptr_line,
787                                               gui_get_line_num_splits (ptr_win, ptr_line) -                                        gui_display_line (ptr_win, ptr_line, 0, 1) -
788                                               (lines_used - (ptr_win->win_chat_height + ptr_win->sub_lines)));                                        (lines_used - (ptr_win->win_chat_height + ptr_win->sub_lines)), 0);
789                      ptr_line = ptr_line->next_line;                      ptr_line = ptr_line->next_line;
790                      ptr_win->first_line_displayed = 0;                      ptr_win->first_line_displayed = 0;
791                  }                  }
# Line 729  gui_draw_buffer_chat (t_gui_buffer *buff Line 803  gui_draw_buffer_chat (t_gui_buffer *buff
803                          ptr_line = ptr_line->next_line;                          ptr_line = ptr_line->next_line;
804                      }                      }
805                  }                  }
806                  while (ptr_line)                  
807                    /* display lines */
808                    while (ptr_line && (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1))
809                  {                  {
810                      if (!gui_display_line (ptr_win, ptr_line, 1))                      gui_display_line (ptr_win, ptr_line, 0, 0);
                         break;  
                       
811                      ptr_line = ptr_line->next_line;                      ptr_line = ptr_line->next_line;
812                  }                  }
813                  /*if (ptr_win->win_chat_cursor_y <= ptr_win->win_chat_height - 1)                  
814                      buffer->sub_lines = 0;*/                  /* cursor is below end line of chat window? */
815                    if (ptr_win->win_chat_cursor_y > ptr_win->win_chat_height - 1)
816                    {
817                        ptr_win->win_chat_cursor_x = 0;
818                        ptr_win->win_chat_cursor_y = ptr_win->win_chat_height - 1;
819                    }
820              }              }
821              wrefresh (ptr_win->win_chat);              wrefresh (ptr_win->win_chat);
822              refresh ();              refresh ();

Legend:
Removed from v.1.78  
changed lines
  Added in v.1.79

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