00001 #include <gui/MessageBox.h>
00002 #include <gui/MessageQueue.h>
00003 #include <gui/Button.h>
00004 #include <gui/TextView.h>
00005 #include <gui/TopView.h>
00006 #include <gui/Exceptions.h>
00007 #include <gui/Window.h>
00008 #include <gui/StringView.h>
00009 #include <gui/ApplicationWindow.h>
00010 #include <gui/Application.h>
00011 #include <gui/Menu.h>
00012 #include <gui/StatusBar.h>
00013 #include <gui/CheckBox.h>
00014 #include <gui/EventThread.h>
00015 #include <os/Clipboard.h>
00016 #include <iostream>
00017
00018 using namespace SkyGI;
00019
00020 #define ID_ADD 10000
00021
00022 class MyEventThread : public EventThread
00023 {
00024 public:
00025 MyEventThread(TextView *pWorkView, TextView *pMessageView, const String& szName);
00026 bool HandleMessage(const Message *pMessage);
00027 bool Work();
00028
00029
00030 TextView *_pWorkView;
00031 TextView *_pMessageView;
00032
00033 int iWorkCounter;
00034 int iMessageCounter;
00035 };
00036
00037 MyEventThread::MyEventThread(TextView *pWorkView, TextView *pMessageView, const String& szName) : EventThread(szName)
00038 {
00039 iWorkCounter = iMessageCounter = 0;
00040
00041 _pWorkView = pWorkView;
00042 _pMessageView = pMessageView;
00043
00044 }
00045
00046 bool MyEventThread::Work()
00047 {
00048 char str[255];
00049
00050 iWorkCounter++;
00051 sprintf(str, "%d", iWorkCounter);
00052
00053 _pWorkView->Set(str);
00054
00055 if ((iWorkCounter % 5) == 0)
00056 {
00057 Message pMessage(10000, 0, 0, Rect(), NULL);
00058
00059 pMessage.SendToThread(Thread::GetPid());
00060 }
00061 return true;
00062 }
00063
00064 bool MyEventThread::HandleMessage(const Message *pMessage)
00065 {
00066 if (pMessage->m_iType == 10000)
00067 {
00068 char str[255];
00069
00070 iMessageCounter++;
00071 sprintf(str, "%d", iMessageCounter);
00072
00073 _pMessageView->Set(str);
00074 }
00075
00076 return EventThread::HandleMessage(pMessage);
00077 }
00078
00079
00080 class MyEventThreadTest : public View
00081 {
00082 public:
00083 MyEventThreadTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00084 ~MyEventThreadTest();
00085
00086 MyEventThread *pEventThread;
00087
00088 TextView *pWorkView;
00089 TextView *pMessageView;
00090 };
00091
00092 MyEventThreadTest::~MyEventThreadTest()
00093 {
00094 delete pEventThread;
00095
00096
00097 }
00098
00099
00100 MyEventThreadTest::MyEventThreadTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00101 {
00102
00103
00104 StringView *pStringView;
00105
00106 pStringView = new StringView(this, Rect(), "Work counter:", 0);
00107 pStringView->SetRect(Point(10, 10), pStringView->GetPreferredSize());
00108
00109 pWorkView = new TextView(this, Rect(10, 30, 200, 50), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00110 pWorkView->SetFocus();
00111
00112 pStringView = new StringView(this, Rect(), "Msg counter:", 0);
00113 pStringView->SetRect(Point(10, 60), pStringView->GetPreferredSize());
00114
00115 pMessageView = new TextView(this, Rect(10, 80, 200, 100), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00116
00117 pEventThread = new MyEventThread(pWorkView, pMessageView, "EventThread");
00118 pEventThread->Start();
00119 }
00120
00121 void EventThreadTest()
00122 {
00123 Rect r(Point(100, 100), Point(400, 440));
00124
00125 ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "EventThreads", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00126
00127 pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00128 pApplicationWindow->AttachView(new MyEventThreadTest(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00129 pApplicationWindow->Show();
00130 }
00131