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 <iostream>
00015
00016 using namespace SkyGI;
00017
00018 #define ID_ADD 10000
00019 #define ID_PARSE 10001
00020
00021 class MyTextView : public View
00022 {
00023 public:
00024 MyTextView(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00025 void OnCommand(const MessageCommand *pMessage);
00026
00027 TextView *pEdit;
00028 TextView *pPassword;
00029 TextView *pTextView;
00030 void OnContextMenu(const InputEvent& nInputEvent)
00031 {
00032 }
00033
00034 CheckBox *pCheckBox;
00035 CheckBox *pCheckBoxScroll;
00036 };
00037
00038 void MyTextView::OnCommand(const MessageCommand *pMessage)
00039 {
00040
00041 switch (pMessage->GetID())
00042 {
00043 case ID_ADD:
00044 pTextView->Append(pEdit->GetBuffer()[0].szText, pCheckBox->Get());
00045 if (pCheckBoxScroll->Get())
00046 pTextView->ScrollDown();
00047 break;
00048 case ID_PARSE:
00049 String tmp;
00050
00051 if (pTextView->GetSelectedText(&tmp) == true)
00052 {
00053 MessageBox pMessageBox("Selected text",
00054 tmp, MESSAGEBOX_FLAG_OK | MESSAGEBOX_FLAG_INFO);
00055
00056 pMessageBox.Run();
00057
00058 }
00059 break;
00060 }
00061 }
00062
00063 MyTextView::MyTextView(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00064 {
00065 StringView *pStringView;
00066
00067 pStringView = new StringView(this, Rect(), "Text to add:", 0);
00068 pStringView->SetRect(Point(10, 10), pStringView->GetPreferredSize());
00069 pStringView->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00070 pEdit = new TextView(this, Rect(10, 30, 200, 50), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00071 pEdit->Set("A single line TextView");
00072 pEdit->SetFocus();
00073 pEdit->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00074
00075 pStringView = new StringView(this, Rect(), "Password:", 0);
00076 pStringView->SetRect(Point(10, 60), pStringView->GetPreferredSize());
00077 pStringView->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00078
00079 pPassword = new TextView(this, Rect(10, 80, 200, 100), WINDOW_LAYOUT_FOLLOW_RIGHT , TEXTVIEW_FLAG_SINGLE_LINE);
00080 pPassword->SetPasswordMode(true);
00081 pPassword->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00082
00083 Font *pFont = new Font(DEFAULT_FONT_FIXED);
00084 pTextView = new TextView(this, Rect(10, 120, 220, 220), WINDOW_LAYOUT_FOLLOW_BOTTOM | WINDOW_LAYOUT_SAME_WIDTH, 0);
00085 pTextView->SetFont(pFont);
00086 pTextView->LoadDocument("/boot/programs/testsuite/skygi/skygi.h");
00087 pTextView->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00088
00089 DocumentParser_SyntaxC *pDocumentParser = new DocumentParser_SyntaxC();
00090 pTextView->SetDocumentParser(pDocumentParser);
00091
00092 Button* pButton = new Button(this, Rect(), "Add Text", WINDOW_LAYOUT_FOLLOW_BOTTOM | WINDOW_LAYOUT_FOLLOW_TOP, new MessageCommand(ID_ADD));
00093 pButton->SetRect(Point(10, 240), pButton->GetPreferredSize());
00094
00095 pButton = new Button(this, Rect(), "Get selected text", WINDOW_LAYOUT_FOLLOW_BOTTOM | WINDOW_LAYOUT_FOLLOW_TOP, new MessageCommand(ID_PARSE));
00096 pButton->SetRect(Point(10, 270), pButton->GetPreferredSize());
00097
00098 pCheckBox = new CheckBox(this, Rect(), "as new line", WINDOW_LAYOUT_FOLLOW_BOTTOM | WINDOW_LAYOUT_FOLLOW_TOP, 0);
00099 pCheckBox->SetRect(Point(10 + pButton->Width() + 20, 240), pCheckBox->GetPreferredSize());
00100 pCheckBox->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00101
00102 pCheckBoxScroll = new CheckBox(this, Rect(), "scroll to bottom on add", WINDOW_LAYOUT_FOLLOW_BOTTOM | WINDOW_LAYOUT_FOLLOW_TOP, 0);
00103 pCheckBoxScroll->SetRect(Point(10 + pButton->Width() + 20, 270), pCheckBoxScroll->GetPreferredSize());
00104 pCheckBoxScroll->SetBackgroundStyle(BACKGROUND_STYLE_PARENT_DRAW);
00105
00106 SetBackgroundStyle(BACKGROUND_STYLE_BRUSH);
00107 SetBackgroundBrush(new BrushImage(new Image("/boot/addon/backgrnd/Images/green.jpg")));
00108
00109 }
00110
00111 void TextViewTest()
00112 {
00113 Rect r(Point(100, 100), Point(400, 440));
00114
00115 ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "TextView", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00116
00117 pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00118 pApplicationWindow->AttachView(new MyTextView(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00119 pApplicationWindow->Show();
00120 }
00121