00001
00002
00003 #ifndef _GTEXTLOG_H_
00004 #define _GTEXTLOG_H_
00005
00006 #include "GTextView3.h"
00007
00008 #define M_LOG (M_USER + 0x3000)
00009
00010 class GTextLog : public GTextView3, public GStream
00011 {
00012 protected:
00013 bool RemoveReturns;
00014 GSemaphore Sem;
00015 GArray<char16*> Txt;
00016
00017 public:
00018 GTextLog(int id) : GTextView3(id, 0, 0, 2000, 1000)
00019 {
00020 RemoveReturns = true;
00021 Sunken(true);
00022 SetPourLargest(true);
00023 }
00024
00025 ~GTextLog()
00026 {
00027 if (Sem.Lock(_FL))
00028 {
00029 Txt.DeleteArrays();
00030 Sem.Unlock();
00031 }
00032 }
00033
00034 void Add(char16 *w)
00035 {
00036 int Len;
00037
00038 if (RemoveReturns)
00039 {
00040 char16 *i = w, *o = w;
00041 while (*i)
00042 {
00043 if (*i != '\r')
00044 {
00045 *o++ = *i++;
00046 }
00047 else
00048 {
00049 i++;
00050 }
00051 }
00052 *o = 0;
00053 Len = o - w;
00054 }
00055 else
00056 {
00057 Len = StrlenW(w);
00058 }
00059
00060 Insert(Size, w, Len);
00061 DeleteArray(w);
00062 Invalidate();
00063 SetCursor(Size, false);
00064 }
00065
00066 int64 SetSize(int64 s)
00067 {
00068 Name(0);
00069 return 0;
00070 }
00071
00072 int Write(void *Buffer, int Size, int Flags = 0)
00073 {
00074 char16 *w = LgiNewUtf8To16((char*)Buffer, Size);
00075 if (w)
00076 {
00077 if (InThread())
00078 {
00079 Add(w);
00080 }
00081 else if (Sem.Lock(_FL))
00082 {
00083 Txt.Add(w);
00084 Sem.Unlock();
00085 PostEvent(M_LOG);
00086 }
00087 }
00088 return Size;
00089 }
00090
00091 int OnEvent(GMessage *m)
00092 {
00093 if (MsgCode(m) == M_LOG)
00094 {
00095 if (Sem.Lock(_FL))
00096 {
00097 for (int i=0; i<Txt.Length(); i++)
00098 {
00099 Add(Txt[i]);
00100 }
00101 Txt.Length(0);
00102 Sem.Unlock();
00103 }
00104 }
00105
00106 return GTextView3::OnEvent(m);
00107 }
00108 };
00109
00110 #endif