00001 #include <gui/MessageBox.h>
00002 #include <gui/MessageQueue.h>
00003 #include <gui/Button.h>
00004 #include <gui/Button.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/ImageButton.h>
00014 #include <gui/CheckBox.h>
00015 #include <iostream>
00016
00017 using namespace SkyGI;
00018
00019 class DndSource : public View
00020 {
00021 public:
00022 DndSource(Window *pParent, const Rect& rRect);
00023 void Paint(const Rect& rDirty);
00024 void MouseDown(const InputEvent& nInputEvent);
00025
00026
00027 void SetImage(const String& szPath)
00028 {
00029 try
00030 {
00031 m_pImage = new Image(szPath);
00032 m_pPath = szPath;
00033 }
00034 catch (...)
00035 {
00036 }
00037 Invalidate();
00038
00039 }
00040
00041 private:
00042 Image *m_pImage;
00043 String m_pPath;
00044 };
00045
00046
00047 DndSource::DndSource(Window *pParent, const Rect& rRect) : View(pParent, rRect, WINDOW_LAYOUT_NOTHING)
00048 {
00049 SetBorder(new BorderSolid(0), BORDER_TYPE_ALL);
00050 }
00051
00052 void DndSource::Paint(const Rect& rDirty)
00053 {
00054 DrawBackground(rDirty);
00055 DrawBorder(GetBounds());
00056 if (m_pImage)
00057 GetPainter()->DrawImage(m_pImage, Point(Width()/2 - m_pImage->Width()/2,Height()/2 - m_pImage->Height()/2));
00058 }
00059
00060 void DndSource::MouseDown(const InputEvent& nInputEvent)
00061 {
00062 if (nInputEvent.m_nMouseButton == MOUSE_BUTTON_LEFT)
00063 {
00064 DataCollection pDataCollection;
00065
00066 pDataCollection.Add("file/path", m_pPath);
00067 Drag(m_pImage, Point(0,0), "file/path", pDataCollection);
00068 }
00069 }
00070
00071
00072 class DndDestination : public View
00073 {
00074 public:
00075 DndDestination(Window *pParent, const Rect& rRect);
00076 void Paint(const Rect& rDirty);
00077 void MouseMove(const InputEvent& nInputEvent);
00078 void MouseUp(const InputEvent& nInputEvent);
00079
00080 void SetImage(const String& szPath)
00081 {
00082 try
00083 {
00084 m_pImage = new Image(szPath);
00085 m_pPath = szPath;
00086 }
00087 catch (...)
00088 {
00089 }
00090 Invalidate();
00091 }
00092
00093 private:
00094 Image *m_pImage;
00095 String m_pPath;
00096 };
00097
00098 DndDestination::DndDestination(Window *pParent, const Rect& rRect) : View(pParent, rRect, WINDOW_LAYOUT_CENTER_H)
00099 {
00100 SetBorder(new BorderSolid(0), BORDER_TYPE_ALL);
00101 AllowDrop(true);
00102 }
00103
00104 void DndDestination::Paint(const Rect& rDirty)
00105 {
00106 DrawBackground(rDirty);
00107 DrawBorder(GetBounds());
00108 if (m_pImage)
00109 GetPainter()->DrawImage(m_pImage, Point(Width()/2 - m_pImage->Width()/2,Height()/2 - m_pImage->Height()/2));
00110 }
00111 void DndDestination::MouseMove(const InputEvent& nInputEvent)
00112 {
00113 if ((!nInputEvent.m_szDragMimeType.empty()) && (nInputEvent.m_szDragMimeType != String("file/path")))
00114 DenyDrop(true);
00115 }
00116
00117 void DndDestination::MouseUp(const InputEvent& nInputEvent)
00118 {
00119 if (!nInputEvent.m_szDragMimeType.empty())
00120 {
00121 if (nInputEvent.m_szDragMimeType != String("file/path"))
00122 {
00123 Drop(NULL, false);
00124 return;
00125 }
00126
00127 DataCollection *pDataCollection;
00128
00129 if (Drop(&pDataCollection, false) == true)
00130 {
00131 String szPath;
00132
00133 if (pDataCollection->Get("file/path", szPath) == true)
00134 SetImage(szPath);
00135 }
00136 }
00137 }
00138
00139
00140 class MyDndTest : public View
00141 {
00142 public:
00143 MyDndTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00144 DndSource *pSource[5];
00145 DndDestination *pDestination;
00146 };
00147
00148
00149 MyDndTest::MyDndTest(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00150 {
00151 StringView *pString;
00152
00153 pString = new StringView(this, Rect(0, 30, 0, 0), "Drag from here", WINDOW_LAYOUT_CENTER_H);
00154 pString->SetSize(pString->GetPreferredSize());
00155 pString->SetBackgroundStyle(BACKGROUND_STYLE_BRUSH);
00156 pString->SetBackgroundBrush(new BrushSolid(0x00FF00));
00157
00158 for (int i=0;i<5;i++)
00159 pSource[i] = new DndSource(this, Rect(20 + i* 50, 50, 60 + i* 50, 90));
00160
00161 pSource[0]->SetImage("/boot/addon/icons/skyos.ico");
00162 pSource[1]->SetImage("/boot/addon/icons/music.ico");
00163 pSource[2]->SetImage("/boot/addon/icons/comp.ico");
00164 pSource[3]->SetImage("/boot/addon/icons/netif.ico");
00165 pSource[4]->SetImage("/boot/addon/icons/start.ico");
00166
00167 pString = new StringView(this, Rect(0, 120, 0, 0), "to here", WINDOW_LAYOUT_CENTER_H);
00168 pString->SetSize(pString->GetPreferredSize());
00169
00170 pString->SetBackgroundStyle(BACKGROUND_STYLE_BRUSH);
00171 pString->SetBackgroundBrush(new BrushSolid(0xFF0000));
00172
00173 pDestination = new DndDestination(this, Rect(0,140,40,180));
00174
00175 }
00176
00177 void DndTest()
00178 {
00179 Rect r(Point(100, 100), Point(400, 440));
00180
00181 ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "Draw and Drop test", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00182
00183 pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00184 pApplicationWindow->AttachView(new MyDndTest(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00185 pApplicationWindow->Show();
00186 }
00187