Flu_Chat_Buffer.H 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // $Id: Flu_Chat_Buffer.h,v 1.5 2003/08/20 16:29:40 jbryan Exp $
  2. /***************************************************************
  3. * FLU - FLTK Utility Widgets
  4. * Copyright (C) 2002 Ohio Supercomputer Center, Ohio State University
  5. *
  6. * This file and its content is protected by a software license.
  7. * You should have received a copy of this license with this file.
  8. * If not, please contact the Ohio Supercomputer Center immediately:
  9. * Attn: Jason Bryan Re: FLU 1224 Kinnear Rd, Columbus, Ohio 43212
  10. *
  11. ***************************************************************/
  12. #ifndef _FLU_CHAT_BUFFER_H
  13. #define _FLU_CHAT_BUFFER_H
  14. /* fltk includes */
  15. #include <FL/Fl.H>
  16. #include <FL/Fl_Widget.H>
  17. #include <FL/Fl_Scrollbar.H>
  18. #include "FLU/Flu_Enumerations.H"
  19. //! A class for drawing text messages in the style of a "chat buffer"
  20. /*! This class is pretty much only useful for chatting. */
  21. class FLU_EXPORT Flu_Chat_Buffer : public Fl_Widget
  22. {
  23. class FLU_EXPORT MessageInfo
  24. {
  25. public:
  26. char type;
  27. char *handle;
  28. char *message;
  29. int handleW, messageW, height;
  30. };
  31. public:
  32. //! Normal FLTK widget constructor
  33. Flu_Chat_Buffer( int x, int y, int w, int h, const char *label = 0 );
  34. //! Default destructor
  35. virtual ~Flu_Chat_Buffer();
  36. //! Add a system message to the chat buffer using the system font and color
  37. void addSystemMessage( const char *msg );
  38. //! Add a message from a remote person to the chat buffer using the remote font and color
  39. void addRemoteMessage( const char *handle, const char *msg );
  40. //! Add a message from a local person to the chat buffer using the local font and color
  41. void addLocalMessage( const char *handle, const char *msg );
  42. //! Clear the contents of the buffer and set the maximum number of lines it can contain to \b maximumLines
  43. void clear( int maximumLines = 500 );
  44. //! Set the font and color to use when printing system messages
  45. /*! Default is FL_HELVETICA_ITALIC, FL_BLACK */
  46. inline void setSystemStyle( Fl_Font f, Fl_Color c )
  47. { systemFont = f; systemColor = c; }
  48. //! Set the font and color to use when printing the handle from a remote message
  49. /*! Default is FL_HELVETICA_BOLD, FL_RED */
  50. inline void setRemoteHandleStyle( Fl_Font f, Fl_Color c )
  51. { remoteHandleFont = f; remoteHandleColor = c; }
  52. //! Set the font and color to use when printing the handle from a local message
  53. /*! Default is FL_HELVETICA_BOLD, FL_BLUE */
  54. inline void setLocalHandleStyle( Fl_Font f, Fl_Color c )
  55. { localHandleFont = f; localHandleColor = c; }
  56. //! Set the font and color to use when printing a remote message
  57. /*! Default is FL_HELVETICA, FL_RED */
  58. inline void setRemoteMessageStyle( Fl_Font f, Fl_Color c )
  59. { remoteMessageFont = f; remoteMessageColor = c; }
  60. //! Set the font and color to use when printing a local message
  61. //! Default is FL_HELVETICA, FL_BLUE */
  62. inline void setLocalMessageStyle( Fl_Font f, Fl_Color c )
  63. { localMessageFont = f; localMessageColor = c; }
  64. //! FLTK resize of this widget
  65. virtual void resize( int x, int y, int w, int h );
  66. DECLARE_CLASS_CHEAP_RTTI_2(Flu_Chat_Buffer, Fl_Widget)
  67. protected:
  68. inline static void _scrollbarCB( Fl_Widget* w, void* arg )
  69. { ((Flu_Chat_Buffer*)arg)->scrollbarCB(); }
  70. void scrollbarCB();
  71. Fl_Font systemFont, remoteHandleFont, localHandleFont,
  72. remoteMessageFont, localMessageFont;
  73. Fl_Color systemColor, remoteHandleColor, localHandleColor,
  74. remoteMessageColor, localMessageColor;
  75. MessageInfo *buffer;
  76. int maxLines, totalLines, currentLine;
  77. bool recomputeFootprint;
  78. virtual void draw();
  79. Fl_Scrollbar *scrollbar;
  80. void _addMessage( char type, char *handle, char *msg );
  81. void _computeMessageFootprint();
  82. };
  83. #endif