From: Ron Lee Date: Tue, 14 Mar 2000 19:47:10 +0000 (+0000) Subject: renamed dragimag sample X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/11e2dfd37dcac4e8c155807de8e1ba222c3e83fb renamed dragimag sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6715 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/dragimag/Makefile.in b/samples/dragimag/Makefile.in index 4396949711..1e8c6416bf 100644 --- a/samples/dragimag/Makefile.in +++ b/samples/dragimag/Makefile.in @@ -1,21 +1,11 @@ -# -# File: makefile.unx -# Author: Julian Smart -# Created: 1998 -# Updated: -# Copyright: (c) 1998 Julian Smart -# -# "%W% %G%" -# -# Makefile for dragimag example (UNIX). +# Purpose: makefile for dragimag example (UNIX). +# Created: 2000-03-15 top_srcdir = @top_srcdir@/.. top_builddir = ../.. program_dir = samples/dragimag -PROGRAM=test - -DATAFILES = backgrnd.png shape01.png shape02.png shape03.png +PROGRAM=dragimag OBJECTS=$(PROGRAM).o diff --git a/samples/dragimag/dragimag.cpp b/samples/dragimag/dragimag.cpp new file mode 100644 index 0000000000..2ef5db853c --- /dev/null +++ b/samples/dragimag/dragimag.cpp @@ -0,0 +1,512 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: dragimag.cpp +// Purpose: wxDragImage sample +// Author: Julian Smart +// Modified by: +// Created: 28/2/2000 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include "wx/image.h" + +// Under Windows, change this to 1 +// to use wxGenericDragImage + +#define wxUSE_GENERIC_DRAGIMAGE 0 + +#if wxUSE_GENERIC_DRAGIMAGE +#include "wx/generic/dragimgg.h" +#define wxDragImage wxGenericDragImage +#else +#include "wx/dragimag.h" +#endif + +#include "dragimag.h" + +#if defined(__WXGTK__) || defined(__WXMOTIF__) +#include "mondrian.xpm" +#include "dragicon.xpm" +#endif + +// main program + +IMPLEMENT_APP(MyApp) + +// MyCanvas + +IMPLEMENT_CLASS(MyCanvas, wxScrolledWindow) + +BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) + EVT_PAINT(MyCanvas::OnPaint) + EVT_ERASE_BACKGROUND(MyCanvas::OnEraseBackground) + EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent) +END_EVENT_TABLE() + +MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, + const wxPoint &pos, const wxSize &size ) + : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) +{ + SetBackgroundColour(* wxWHITE); + + SetCursor(wxCursor(wxCURSOR_ARROW)); + + m_dragMode = TEST_DRAG_NONE; + m_draggedShape = (DragShape*) NULL; + m_dragImage = (wxDragImage*) NULL; + m_currentlyHighlighted = (DragShape*) NULL; +} + +MyCanvas::~MyCanvas() +{ + ClearShapes(); + + if (m_dragImage) + delete m_dragImage; +} + +void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) +{ + wxPaintDC dc( this ); + PrepareDC( dc ); + + DrawShapes(dc); + +} + +void MyCanvas::OnEraseBackground(wxEraseEvent& event) +{ + if (wxGetApp().GetBackgroundBitmap().Ok()) + { + wxSize sz = GetClientSize(); + wxRect rect(0, 0, sz.x, sz.y); + + if (event.GetDC()) + { + wxGetApp().TileBitmap(rect, *(event.GetDC()), wxGetApp().GetBackgroundBitmap()); + } + else + { + wxClientDC dc(this); + wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap()); + } + } + else + event.Skip(); // The official way of doing it +} + +void MyCanvas::OnMouseEvent(wxMouseEvent& event) +{ + if (event.LeftDown()) + { + DragShape* shape = FindShape(event.GetPosition()); + if (shape) + { + // We tentatively start dragging, but wait for + // mouse movement before dragging properly. + + m_dragMode = TEST_DRAG_START; + m_dragStartPos = event.GetPosition(); + m_draggedShape = shape; + } + } + else if (event.LeftUp() && m_dragMode != TEST_DRAG_NONE) + { + // Finish dragging + + m_dragMode = TEST_DRAG_NONE; + + if (!m_draggedShape || !m_dragImage) + return; + + wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), + m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); + + m_draggedShape->SetPosition(newPos); + + m_dragImage->Hide(); + m_dragImage->EndDrag(); + delete m_dragImage; + m_dragImage = NULL; + + wxClientDC dc(this); + if (m_currentlyHighlighted) + { + m_currentlyHighlighted->Draw(dc); + } + m_draggedShape->SetShow(TRUE); + m_draggedShape->Draw(dc); + + m_currentlyHighlighted = (DragShape*) NULL; + + m_draggedShape = (DragShape*) NULL; + } + else if (event.Dragging() && m_dragMode != TEST_DRAG_NONE) + { + if (m_dragMode == TEST_DRAG_START) + { + // We will start dragging if we've moved beyond a couple of pixels + + int tolerance = 2; + int dx = abs(event.GetPosition().x - m_dragStartPos.x); + int dy = abs(event.GetPosition().y - m_dragStartPos.y); + if (dx <= tolerance && dy <= tolerance) + return; + + wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), + m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); + + // Start the drag. + m_dragMode = TEST_DRAG_DRAGGING; + + if (m_dragImage) + delete m_dragImage; + + // Erase the dragged shape from the canvas + m_draggedShape->SetShow(FALSE); + wxClientDC dc(this); + EraseShape(m_draggedShape, dc); + DrawShapes(dc); + + switch (m_draggedShape->GetDragMethod()) + { + case SHAPE_DRAG_BITMAP: + { + wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); + m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND), hotSpot); + break; + } + case SHAPE_DRAG_TEXT: + { + wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); + m_dragImage = new wxDragImage("Dragging some test text", wxCursor(wxCURSOR_HAND), hotSpot); + break; + } + case SHAPE_DRAG_ICON: + { + wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); + + // Can anyone explain why this test is necessary, + // to prevent a gcc error? +#ifdef __WXMOTIF__ + wxIcon icon(dragicon_xpm); +#else + wxIcon icon(wxICON(dragicon)); +#endif + + m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND), hotSpot); + break; + } + } + + bool fullScreen = FALSE; + if (wxGetApp().GetUseScreen()) + { + newPos = ClientToScreen(newPos); + fullScreen = TRUE; + } + + bool retValue; + + if (fullScreen) + // This line uses the whole screen... + retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, TRUE); + // while this line restricts dragging to the parent frame. + // retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, GetParent()); + else + retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this); + + if (!retValue) + { + delete m_dragImage; + m_dragImage = (wxDragImage*) NULL; + m_dragMode = TEST_DRAG_NONE; + } + m_dragImage->Move(newPos); + m_dragImage->Show(); + } + else if (m_dragMode == TEST_DRAG_DRAGGING) + { + // We're currently dragging. See if we're over another shape. + DragShape* onShape = FindShape(event.GetPosition()); + + bool mustUnhighlightOld = FALSE; + bool mustHighlightNew = FALSE; + + if (m_currentlyHighlighted) + { + if ((onShape == (DragShape*) NULL) || (m_currentlyHighlighted != onShape)) + mustUnhighlightOld = TRUE; + } + + if (onShape && (onShape != m_currentlyHighlighted) && onShape->IsShown()) + mustHighlightNew = TRUE; + + if (mustUnhighlightOld || mustHighlightNew) + m_dragImage->Hide(); + + // Now with the drag image switched off, we can change the window contents. + + if (mustUnhighlightOld) + { + wxClientDC clientDC(this); + m_currentlyHighlighted->Draw(clientDC); + m_currentlyHighlighted = (DragShape*) NULL; + } + if (mustHighlightNew) + { + wxClientDC clientDC(this); + m_currentlyHighlighted = onShape; + m_currentlyHighlighted->Draw(clientDC, wxINVERT); + } + + wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), + m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); + + if (wxGetApp().GetUseScreen()) + { + newPos = ClientToScreen(newPos); + } + + // Move and show the image again + m_dragImage->Move(newPos); + + if (mustUnhighlightOld || mustHighlightNew) + m_dragImage->Show(); + } + } +} + +void MyCanvas::DrawShapes(wxDC& dc) +{ + wxNode* node = m_displayList.First(); + while (node) + { + DragShape* shape = (DragShape*) node->Data(); + if (shape->IsShown()) + shape->Draw(dc); + node = node->Next(); + } +} + +void MyCanvas::EraseShape(DragShape* shape, wxDC& dc) +{ + wxSize sz = GetClientSize(); + wxRect rect(0, 0, sz.x, sz.y); + + wxRect rect2(shape->GetRect()); + dc.SetClippingRegion(rect2.x, rect2.y, rect2.width, rect2.height); + + wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap()); + + dc.DestroyClippingRegion(); +} + +void MyCanvas::ClearShapes() +{ + wxNode* node = m_displayList.First(); + while (node) + { + DragShape* shape = (DragShape*) node->Data(); + delete shape; + node = node->Next(); + } + m_displayList.Clear(); +} + +DragShape* MyCanvas::FindShape(const wxPoint& pt) const +{ + wxNode* node = m_displayList.First(); + while (node) + { + DragShape* shape = (DragShape*) node->Data(); + if (shape->HitTest(pt)) + return shape; + node = node->Next(); + } + return (DragShape*) NULL; +} + +// MyFrame + +IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) + +BEGIN_EVENT_TABLE(MyFrame,wxFrame) + EVT_MENU (wxID_ABOUT, MyFrame::OnAbout) + EVT_MENU (wxID_EXIT, MyFrame::OnQuit) +END_EVENT_TABLE() + +MyFrame::MyFrame() + : wxFrame( (wxFrame *)NULL, -1, "wxDragImage sample", + wxPoint(20,20), wxSize(470,360) ) +{ + wxMenu *file_menu = new wxMenu(); + file_menu->Append( wxID_ABOUT, "&About..."); + file_menu->Append( TEST_USE_SCREEN, "&Use whole screen for dragging", "Use whole screen", TRUE); + file_menu->Append( wxID_EXIT, "E&xit"); + + wxMenuBar *menu_bar = new wxMenuBar(); + menu_bar->Append(file_menu, "&File"); + + SetMenuBar( menu_bar ); + + CreateStatusBar(2); + int widths[] = { -1, 100 }; + SetStatusWidths( 2, widths ); + + m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); +} + +void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) +{ + Close( TRUE ); +} + +void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) +{ + (void)wxMessageBox( "wxDragImage demo\n" + "Julian Smart (c) 2000", + "About wxDragImage Demo", wxICON_INFORMATION | wxOK ); +} + +//----------------------------------------------------------------------------- +// MyApp +//----------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(MyApp, wxApp) + EVT_MENU(TEST_USE_SCREEN, MyApp::OnUseScreen) +END_EVENT_TABLE() + +MyApp::MyApp() +{ + // Drag across whole screen + m_useScreen = FALSE; +} + +bool MyApp::OnInit() +{ +#if wxUSE_LIBPNG + wxImage::AddHandler( new wxPNGHandler ); +#endif + + wxImage image; + if (image.LoadFile("backgrnd.png", wxBITMAP_TYPE_PNG)) + { + m_background = image.ConvertToBitmap(); + } + + + MyFrame *frame = new MyFrame(); + + wxString rootName("shape0"); + + int i; + for (i = 1; i < 4; i++) + { + wxString filename; + filename.Printf("%s%d.png", (const char*) rootName, i); + if (image.LoadFile(filename, wxBITMAP_TYPE_PNG)) + { + DragShape* newShape = new DragShape(image.ConvertToBitmap()); + newShape->SetPosition(wxPoint(i*50, i*50)); + + if (i == 2) + newShape->SetDragMethod(SHAPE_DRAG_TEXT); + else if (i == 3) + newShape->SetDragMethod(SHAPE_DRAG_ICON); + else + newShape->SetDragMethod(SHAPE_DRAG_BITMAP); + frame->GetCanvas()->GetDisplayList().Append(newShape); + } + } + +#if 0 + // Under Motif or GTK, this demonstrates that + // wxScreenDC only gets the root window content. + // We need to be able to copy the overall content + // for full-screen dragging to work. + int w, h; + wxDisplaySize(& w, & h); + wxBitmap bitmap(w, h); + + wxScreenDC dc; + wxMemoryDC memDC; + memDC.SelectObject(bitmap); + memDC.Blit(0, 0, w, h, & dc, 0, 0); + memDC.SelectObject(wxNullBitmap); + m_background = bitmap; +#endif + + frame->Show( TRUE ); + + return TRUE; +} + +bool MyApp::TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap) +{ + int w = bitmap.GetWidth(); + int h = bitmap.GetHeight(); + + int i, j; + for (i = rect.x; i < rect.x + rect.width; i += w) + { + for (j = rect.y; j < rect.y + rect.height; j+= h) + dc.DrawBitmap(bitmap, i, j); + } + return TRUE; +} + +void MyApp::OnUseScreen(wxCommandEvent& event) +{ + m_useScreen = !m_useScreen; +} + +// DragShape + +DragShape::DragShape(const wxBitmap& bitmap) +{ + m_bitmap = bitmap; + m_pos.x = 0; + m_pos.y = 0; + m_dragMethod = SHAPE_DRAG_BITMAP; + m_show = TRUE; +} + +DragShape::~DragShape() +{ +} + +bool DragShape::HitTest(const wxPoint& pt) const +{ + wxRect rect(GetRect()); + return rect.Inside(pt.x, pt.y); +} + +bool DragShape::Draw(wxDC& dc, int op) +{ + if (m_bitmap.Ok()) + { + wxMemoryDC memDC; + memDC.SelectObject(m_bitmap); + + dc.Blit(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), + & memDC, 0, 0, op, TRUE); + + return TRUE; + } + else + return FALSE; +} + diff --git a/samples/dragimag/dragimag.def b/samples/dragimag/dragimag.def new file mode 100644 index 0000000000..6a2bb3d0b8 --- /dev/null +++ b/samples/dragimag/dragimag.def @@ -0,0 +1,7 @@ +NAME Dragimag +DESCRIPTION 'wxWindows dragimag sample' +EXETYPE WINDOWS +CODE PRELOAD MOVEABLE DISCARDABLE +DATA PRELOAD MOVEABLE MULTIPLE +HEAPSIZE 4048 +STACKSIZE 16000 diff --git a/samples/dragimag/dragimag.h b/samples/dragimag/dragimag.h new file mode 100644 index 0000000000..bba436184e --- /dev/null +++ b/samples/dragimag/dragimag.h @@ -0,0 +1,156 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: dragimag.h +// Purpose: wxDragImage sample +// Author: Julian Smart +// Modified by: +// Created: 28/2/2000 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_DRAGIMAGSAMPLE_ +#define _WX_DRAGIMAGSAMPLE_ + +// derived classes + +class MyFrame; +class MyApp; +class MyCanvas; +class DragShape; + +// MyFrame + +class MyFrame: public wxFrame +{ +public: + MyFrame(); + + void OnAbout( wxCommandEvent &event ); + void OnQuit( wxCommandEvent &event ); + + MyCanvas* GetCanvas() const { return m_canvas; } + void SetCanvas(MyCanvas* canvas) { m_canvas = canvas; } + +private: + MyCanvas* m_canvas; + + DECLARE_DYNAMIC_CLASS(MyFrame) + DECLARE_EVENT_TABLE() +}; + +// MyApp + +class MyApp: public wxApp +{ +public: + MyApp(); + virtual bool OnInit(); + +//// Operations + + // Tile the bitmap + bool TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap); + +//// Accessors + wxBitmap& GetBackgroundBitmap() const { return (wxBitmap&) m_background; } + + bool GetUseScreen() const { return m_useScreen; } + void SetUseScreen(bool useScreen) { m_useScreen = useScreen; } + + void OnUseScreen(wxCommandEvent& event); + +protected: + wxBitmap m_background; + bool m_useScreen; + +DECLARE_EVENT_TABLE() +}; + +DECLARE_APP(MyApp) + +#define TEST_USE_SCREEN 100 + +// MyCanvas + +// Dragging modes +#define TEST_DRAG_NONE 0 +#define TEST_DRAG_START 1 +#define TEST_DRAG_DRAGGING 2 + +class MyCanvas: public wxScrolledWindow +{ +public: + MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); + ~MyCanvas(); + + void OnPaint( wxPaintEvent &event ); + void OnEraseBackground(wxEraseEvent& event); + void OnMouseEvent(wxMouseEvent& event); + + void DrawShapes(wxDC& dc); + void EraseShape(DragShape* shape, wxDC& dc); + void ClearShapes(); + DragShape* FindShape(const wxPoint& pt) const; + + wxList& GetDisplayList() { return m_displayList; } + +protected: + +private: + wxList m_displayList; // A list of DragShapes + int m_dragMode; + DragShape* m_draggedShape; + DragShape* m_currentlyHighlighted; // The shape that's being highlighted + wxPoint m_dragStartPos; + wxDragImage* m_dragImage; + + DECLARE_CLASS(MyCanvas) + DECLARE_EVENT_TABLE() +}; + + +// Ways to drag a shape + +#define SHAPE_DRAG_BITMAP 1 +#define SHAPE_DRAG_TEXT 2 +#define SHAPE_DRAG_ICON 3 + +// Shape + +class DragShape: public wxObject +{ +public: + DragShape(const wxBitmap& bitmap); + ~DragShape(); + +//// Operations + + bool HitTest(const wxPoint& pt) const; + bool Draw(wxDC& dc, int op = wxCOPY); + +//// Accessors + + wxPoint GetPosition() const { return m_pos; } + void SetPosition(const wxPoint& pos) { m_pos = pos; } + + wxRect GetRect() const { return wxRect(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight()); } + + wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } + void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } + + int GetDragMethod() const { return m_dragMethod; } + void SetDragMethod(int method) { m_dragMethod = method; } + + bool IsShown() const { return m_show; } + void SetShow(bool show) { m_show = show; } + +protected: + wxPoint m_pos; + wxBitmap m_bitmap; + int m_dragMethod; + bool m_show; +}; + +#endif + // _WX_DRAGIMAGSAMPLE_ diff --git a/samples/dragimag/dragimag.rc b/samples/dragimag/dragimag.rc new file mode 100644 index 0000000000..754a072235 --- /dev/null +++ b/samples/dragimag/dragimag.rc @@ -0,0 +1,5 @@ +mondrian ICON "mondrian.ico" +dragicon ICON "dragicon.ico" + +#include "wx/msw/wx.rc" + diff --git a/samples/dragimag/makefile.b32 b/samples/dragimag/makefile.b32 index 95ddc80d76..071c350074 100644 --- a/samples/dragimag/makefile.b32 +++ b/samples/dragimag/makefile.b32 @@ -1,15 +1,9 @@ -# -# File: makefile.b32 -# Author: Julian Smart -# Created: 1999 -# Updated: -# Copyright: -# -# Makefile : Builds sample for 32-bit BC++ +# Purpose: makefile for dragimag example (BC++ 32bit) +# Created: 2000-03-15 WXDIR = $(WXWIN) -TARGET=test +TARGET=dragimag OBJECTS = $(TARGET).obj !include $(WXDIR)\src\makeprog.b32 diff --git a/samples/dragimag/makefile.bcc b/samples/dragimag/makefile.bcc index 669f01905a..69a8b50dce 100644 --- a/samples/dragimag/makefile.bcc +++ b/samples/dragimag/makefile.bcc @@ -1,10 +1,5 @@ -# -# File: makefile.bcc -# Author: Julian Smart -# Created: 1998 -# Updated: -# -# Builds a BC++ 16-bit sample +# Purpose: makefile for dragimag example (BC++ 16bit) +# Created: 2000-03-15 !if "$(WXWIN)" == "" !error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx @@ -12,7 +7,7 @@ WXDIR = $(WXWIN) -TARGET=test +TARGET=dragimag OBJECTS=$(TARGET).obj !include $(WXDIR)\src\makeprog.bcc diff --git a/samples/dragimag/makefile.dos b/samples/dragimag/makefile.dos index 983ef2da8b..271446849e 100644 --- a/samples/dragimag/makefile.dos +++ b/samples/dragimag/makefile.dos @@ -1,16 +1,9 @@ -# -# File: makefile.dos -# Author: Julian Smart -# Created: 1998 -# Updated: -# -# Makefile : Builds 16-bit sample, VC++ 1.5 -# Use FINAL=1 argument to nmake to build final version with no debugging -# info +# Purpose: makefile for dragimag example (VC++ 1.5x) +# Created: 2000-03-15 WXDIR = $(WXWIN) -TARGET=test +TARGET=dragimag OBJECTS=$(TARGET).obj !include $(WXDIR)\src\makeprog.msc diff --git a/samples/dragimag/makefile.g95 b/samples/dragimag/makefile.g95 index b4a920f047..dd6a09ce52 100644 --- a/samples/dragimag/makefile.g95 +++ b/samples/dragimag/makefile.g95 @@ -1,16 +1,10 @@ -# -# File: makefile.g95 -# Author: Julian Smart -# Created: 1999 -# Updated: -# Copyright: (c) Julian Smart, 1999 -# -# Makefile for wxWindows sample (Cygwin/Mingw32). +# Purpose: makefile for dragimag example (Cygwin/Mingw32) +# Created: #03.01.00 WXDIR = ../.. -TARGET=test +TARGET=dragimag OBJECTS = $(TARGET).o -include $(WXDIR)/src/makeprog.g95 +include $(WXDIR)\src\makeprog.g95 diff --git a/samples/dragimag/makefile.sc b/samples/dragimag/makefile.sc index 9f70cf6b36..7a02278dc4 100644 --- a/samples/dragimag/makefile.sc +++ b/samples/dragimag/makefile.sc @@ -1,16 +1,17 @@ -# Symantec C++ makefile +# Purpose: makefile for dragimag example (Symantec C++) +# Created: 2000-03-15 WXDIR = $(WXWIN) WXLIB = $(WXDIR)\lib\wx.lib INCDIR = $(WXDIR)\include INCLUDE=$(INCDIR) -TARGET=test +TARGET=dragimag include $(WXDIR)\src\makesc.env -test.exe: test.obj $(DEFFILE) test.res +dragimag.exe: dragimag.obj $(DEFFILE) dragimag.res *$(CC) $(LDFLAGS) -o$@ $** $(LIBS) - *$(RC) -k test.res + *$(RC) -k dragimag.res sc32.def: echo EXETYPE NT > sc32.def diff --git a/samples/dragimag/makefile.sl b/samples/dragimag/makefile.sl index c604d39654..45beba2c35 100644 --- a/samples/dragimag/makefile.sl +++ b/samples/dragimag/makefile.sl @@ -1,11 +1,7 @@ -# -# File: makefile.sl -# Author: Julian Smart -# Created: 1998 -# -# Makefile : Builds a wxWindows sample for Salford C++, WIN32 +# Purpose: makefile for dragimag example (Salford C++) +# Created: 2000-03-15 -PROGRAM = test +PROGRAM = dragimag OBJECTS = $(PROGRAM).obj include ..\..\src\makeprog.sl @@ -14,5 +10,5 @@ all: wx $(TARGET) wx: cd $(WXDIR)\src\msw ^ mk32 -f makefile.sl all - cd $(WXDIR)\samples\test + cd $(WXDIR)\samples\dragimag diff --git a/samples/dragimag/makefile.twn b/samples/dragimag/makefile.twn index 76ab72b692..00061d4198 100644 --- a/samples/dragimag/makefile.twn +++ b/samples/dragimag/makefile.twn @@ -1,13 +1,5 @@ -# -# File: makefile.unx -# Author: Julian Smart -# Created: 1993 -# Updated: -# Copyright: (c) 1993, AIAI, University of Edinburgh -# -# "%W% %G%" -# -# Makefile for test example (UNIX). +# Purpose: makefile for dragimag example (TWIN) +# Created: 2000-03-15 WXDIR = ../.. @@ -15,29 +7,29 @@ WXDIR = ../.. # this central makefile. include $(WXDIR)/src/maketwin.env -OBJECTS = $(OBJDIR)/test.$(OBJSUFF) $(OBJDIR)/test_resources.$(OBJSUFF) +OBJECTS = $(OBJDIR)/dragimag.$(OBJSUFF) $(OBJDIR)/dragimag.$(OBJSUFF) -all: $(OBJDIR) test$(GUISUFFIX)$(EXESUFF) +all: $(OBJDIR) dragimag$(GUISUFFIX)$(EXESUFF) wx: $(OBJDIR): mkdir $(OBJDIR) -test$(GUISUFFIX)$(EXESUFF): $(OBJECTS) $(WXLIB) - $(CC) $(LDFLAGS) -o test$(GUISUFFIX)$(EXESUFF) $(OBJECTS) $(LDLIBS) +dragimag$(GUISUFFIX)$(EXESUFF): $(OBJECTS) $(WXLIB) + $(CC) $(LDFLAGS) -o dragimag$(GUISUFFIX)$(EXESUFF) $(OBJECTS) $(LDLIBS) -$(OBJDIR)/test.$(OBJSUFF): test.$(SRCSUFF) - $(CC) -c $(CPPFLAGS) -o $@ test.$(SRCSUFF) +$(OBJDIR)/dragimag.$(OBJSUFF): dragimag.$(SRCSUFF) + $(CC) -c $(CPPFLAGS) -o $@ dragimag.$(SRCSUFF) -test_resources.c: test.rc - $(RESCOMP) $(RCINPUTSWITCH) test.rc $(RCOUTPUTSWITCH) test_resources.c $(RESFLAGS) +dragimag.c: dragimag.rc + $(RESCOMP) $(RCINPUTSWITCH) dragimag.rc $(RCOUTPUTSWITCH) dragimag.c $(RESFLAGS) -$(OBJDIR)/test_resources.$(OBJSUFF): test_resources.c - $(CC) -c $(CPPFLAGS) -o $@ test_resources.c +$(OBJDIR)/dragimag.$(OBJSUFF): dragimag.c + $(CC) -c $(CPPFLAGS) -o $@ dragimag.c -#$(OBJDIR)/test_resources.o: test.rc -# $(RESCOMP) $(RCINPUTSWITCH) test.rc $(RCOUTPUTSWITCH) $(OBJDIR)/test_resources.o $(RESFLAGS) +#$(OBJDIR)/dragimag.o: dragimag.rc +# $(RESCOMP) $(RCINPUTSWITCH) dragimag.rc $(RCOUTPUTSWITCH) $(OBJDIR)/dragimag.o $(RESFLAGS) clean: - rm -f $(OBJECTS) test$(GUISUFFIX).exe core *.rsc *.res + rm -f $(OBJECTS) dragimag$(GUISUFFIX).exe core *.rsc *.res diff --git a/samples/dragimag/makefile.unx b/samples/dragimag/makefile.unx index 21cab3c677..7022f314df 100644 --- a/samples/dragimag/makefile.unx +++ b/samples/dragimag/makefile.unx @@ -1,21 +1,9 @@ -# -# File: Makefile for samples -# Author: Robert Roebling -# Created: 1999 -# Updated: -# Copyright: (c) 1998 Robert Roebling -# -# This makefile requires a Unix version of wxWindows -# to be installed on your system. This is most often -# done typing "make install" when using the complete -# sources of wxWindows or by installing the two -# RPM packages wxGTK.XXX.rpm and wxGTK-devel.XXX.rpm -# under Linux. -# +# Purpose: makefile for dragimag example (Unix) +# Created: 2000-03-15 CC = gcc -PROGRAM = test +PROGRAM = dragimag OBJECTS = $(PROGRAM).o @@ -31,5 +19,5 @@ all: $(PROGRAM) $(PROGRAM): $(OBJECTS) $(CC) -o $(PROGRAM) $(OBJECTS) `wx-config --libs` -clean: +clean: rm -f *.o $(PROGRAM) diff --git a/samples/dragimag/makefile.va b/samples/dragimag/makefile.va index 3cfa8cb8a8..899e5224f1 100644 --- a/samples/dragimag/makefile.va +++ b/samples/dragimag/makefile.va @@ -15,7 +15,7 @@ WXUSINGDLL=0 !include $(WXDIR)\src\makeva.env -PROGRAM=$D\test +PROGRAM=$D\dragimag OBJECTS = $(PROGRAM).obj !if [md $D] diff --git a/samples/dragimag/makefile.vc b/samples/dragimag/makefile.vc index 4ada748eda..9352089a18 100644 --- a/samples/dragimag/makefile.vc +++ b/samples/dragimag/makefile.vc @@ -1,17 +1,10 @@ -# -# File: makefile.vc -# Author: Julian Smart -# Created: 1999 -# Updated: -# Copyright: (c) Julian Smart -# -# Makefile : Builds sample (VC++, WIN32) -# Use FINAL=1 argument to nmake to build final version with no debug info. +# Purpose: makefile for dragimag example (VC++ 32bit) +# Created: 2000-03-15 # Set WXDIR for your system WXDIR = $(WXWIN) -PROGRAM=test +PROGRAM=dragimag OBJECTS = $(PROGRAM).obj !include $(WXDIR)\src\makeprog.vc diff --git a/samples/dragimag/makefile.wat b/samples/dragimag/makefile.wat index 81a83e42a9..8be0d5aec8 100644 --- a/samples/dragimag/makefile.wat +++ b/samples/dragimag/makefile.wat @@ -1,13 +1,9 @@ -# -# Makefile for WATCOM -# -# Created by Julian Smart, January 1999 -# -# +# Purpose: makefile for dragimag example (Watcom) +# Created: 2000-03-15 WXDIR = $(%WXWIN) -PROGRAM = test +PROGRAM = dragimag OBJECTS = $(PROGRAM).obj !include $(WXDIR)\src\makeprog.wat diff --git a/samples/dragimag/test.cpp b/samples/dragimag/test.cpp deleted file mode 100644 index 08acf09f1d..0000000000 --- a/samples/dragimag/test.cpp +++ /dev/null @@ -1,512 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: test.cpp -// Purpose: wxDragImage sample -// Author: Julian Smart -// Modified by: -// Created: 28/2/2000 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -// For compilers that support precompilation, includes "wx/wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -#include -#endif - -#include - -// Under Windows, change this to 1 -// to use wxGenericDragImage - -#define wxUSE_GENERIC_DRAGIMAGE 0 - -#if wxUSE_GENERIC_DRAGIMAGE -#include -#define wxDragImage wxGenericDragImage -#else -#include -#endif - -#include "test.h" - -#if defined(__WXGTK__) || defined(__WXMOTIF__) -#include "mondrian.xpm" -#include "dragicon.xpm" -#endif - -// main program - -IMPLEMENT_APP(MyApp) - -// MyCanvas - -IMPLEMENT_CLASS(MyCanvas, wxScrolledWindow) - -BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) - EVT_PAINT(MyCanvas::OnPaint) - EVT_ERASE_BACKGROUND(MyCanvas::OnEraseBackground) - EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent) -END_EVENT_TABLE() - -MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size ) - : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) -{ - SetBackgroundColour(* wxWHITE); - - SetCursor(wxCursor(wxCURSOR_ARROW)); - - m_dragMode = TEST_DRAG_NONE; - m_draggedShape = (DragShape*) NULL; - m_dragImage = (wxDragImage*) NULL; - m_currentlyHighlighted = (DragShape*) NULL; -} - -MyCanvas::~MyCanvas() -{ - ClearShapes(); - - if (m_dragImage) - delete m_dragImage; -} - -void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) -{ - wxPaintDC dc( this ); - PrepareDC( dc ); - - DrawShapes(dc); - -} - -void MyCanvas::OnEraseBackground(wxEraseEvent& event) -{ - if (wxGetApp().GetBackgroundBitmap().Ok()) - { - wxSize sz = GetClientSize(); - wxRect rect(0, 0, sz.x, sz.y); - - if (event.GetDC()) - { - wxGetApp().TileBitmap(rect, *(event.GetDC()), wxGetApp().GetBackgroundBitmap()); - } - else - { - wxClientDC dc(this); - wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap()); - } - } - else - event.Skip(); // The official way of doing it -} - -void MyCanvas::OnMouseEvent(wxMouseEvent& event) -{ - if (event.LeftDown()) - { - DragShape* shape = FindShape(event.GetPosition()); - if (shape) - { - // We tentatively start dragging, but wait for - // mouse movement before dragging properly. - - m_dragMode = TEST_DRAG_START; - m_dragStartPos = event.GetPosition(); - m_draggedShape = shape; - } - } - else if (event.LeftUp() && m_dragMode != TEST_DRAG_NONE) - { - // Finish dragging - - m_dragMode = TEST_DRAG_NONE; - - if (!m_draggedShape || !m_dragImage) - return; - - wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), - m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); - - m_draggedShape->SetPosition(newPos); - - m_dragImage->Hide(); - m_dragImage->EndDrag(); - delete m_dragImage; - m_dragImage = NULL; - - wxClientDC dc(this); - if (m_currentlyHighlighted) - { - m_currentlyHighlighted->Draw(dc); - } - m_draggedShape->SetShow(TRUE); - m_draggedShape->Draw(dc); - - m_currentlyHighlighted = (DragShape*) NULL; - - m_draggedShape = (DragShape*) NULL; - } - else if (event.Dragging() && m_dragMode != TEST_DRAG_NONE) - { - if (m_dragMode == TEST_DRAG_START) - { - // We will start dragging if we've moved beyond a couple of pixels - - int tolerance = 2; - int dx = abs(event.GetPosition().x - m_dragStartPos.x); - int dy = abs(event.GetPosition().y - m_dragStartPos.y); - if (dx <= tolerance && dy <= tolerance) - return; - - wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), - m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); - - // Start the drag. - m_dragMode = TEST_DRAG_DRAGGING; - - if (m_dragImage) - delete m_dragImage; - - // Erase the dragged shape from the canvas - m_draggedShape->SetShow(FALSE); - wxClientDC dc(this); - EraseShape(m_draggedShape, dc); - DrawShapes(dc); - - switch (m_draggedShape->GetDragMethod()) - { - case SHAPE_DRAG_BITMAP: - { - wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); - m_dragImage = new wxDragImage(m_draggedShape->GetBitmap(), wxCursor(wxCURSOR_HAND), hotSpot); - break; - } - case SHAPE_DRAG_TEXT: - { - wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); - m_dragImage = new wxDragImage("Dragging some test text", wxCursor(wxCURSOR_HAND), hotSpot); - break; - } - case SHAPE_DRAG_ICON: - { - wxPoint hotSpot(event.GetPosition().x - newPos.x, event.GetPosition().y - newPos.y); - - // Can anyone explain why this test is necessary, - // to prevent a gcc error? -#ifdef __WXMOTIF__ - wxIcon icon(dragicon_xpm); -#else - wxIcon icon(wxICON(dragicon)); -#endif - - m_dragImage = new wxDragImage(icon, wxCursor(wxCURSOR_HAND), hotSpot); - break; - } - } - - bool fullScreen = FALSE; - if (wxGetApp().GetUseScreen()) - { - newPos = ClientToScreen(newPos); - fullScreen = TRUE; - } - - bool retValue; - - if (fullScreen) - // This line uses the whole screen... - retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, TRUE); - // while this line restricts dragging to the parent frame. - // retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this, GetParent()); - else - retValue = m_dragImage->BeginDrag(wxPoint(0, 0), this); - - if (!retValue) - { - delete m_dragImage; - m_dragImage = (wxDragImage*) NULL; - m_dragMode = TEST_DRAG_NONE; - } - m_dragImage->Move(newPos); - m_dragImage->Show(); - } - else if (m_dragMode == TEST_DRAG_DRAGGING) - { - // We're currently dragging. See if we're over another shape. - DragShape* onShape = FindShape(event.GetPosition()); - - bool mustUnhighlightOld = FALSE; - bool mustHighlightNew = FALSE; - - if (m_currentlyHighlighted) - { - if ((onShape == (DragShape*) NULL) || (m_currentlyHighlighted != onShape)) - mustUnhighlightOld = TRUE; - } - - if (onShape && (onShape != m_currentlyHighlighted) && onShape->IsShown()) - mustHighlightNew = TRUE; - - if (mustUnhighlightOld || mustHighlightNew) - m_dragImage->Hide(); - - // Now with the drag image switched off, we can change the window contents. - - if (mustUnhighlightOld) - { - wxClientDC clientDC(this); - m_currentlyHighlighted->Draw(clientDC); - m_currentlyHighlighted = (DragShape*) NULL; - } - if (mustHighlightNew) - { - wxClientDC clientDC(this); - m_currentlyHighlighted = onShape; - m_currentlyHighlighted->Draw(clientDC, wxINVERT); - } - - wxPoint newPos(m_draggedShape->GetPosition().x + (event.GetPosition().x - m_dragStartPos.x), - m_draggedShape->GetPosition().y + (event.GetPosition().y - m_dragStartPos.y)); - - if (wxGetApp().GetUseScreen()) - { - newPos = ClientToScreen(newPos); - } - - // Move and show the image again - m_dragImage->Move(newPos); - - if (mustUnhighlightOld || mustHighlightNew) - m_dragImage->Show(); - } - } -} - -void MyCanvas::DrawShapes(wxDC& dc) -{ - wxNode* node = m_displayList.First(); - while (node) - { - DragShape* shape = (DragShape*) node->Data(); - if (shape->IsShown()) - shape->Draw(dc); - node = node->Next(); - } -} - -void MyCanvas::EraseShape(DragShape* shape, wxDC& dc) -{ - wxSize sz = GetClientSize(); - wxRect rect(0, 0, sz.x, sz.y); - - wxRect rect2(shape->GetRect()); - dc.SetClippingRegion(rect2.x, rect2.y, rect2.width, rect2.height); - - wxGetApp().TileBitmap(rect, dc, wxGetApp().GetBackgroundBitmap()); - - dc.DestroyClippingRegion(); -} - -void MyCanvas::ClearShapes() -{ - wxNode* node = m_displayList.First(); - while (node) - { - DragShape* shape = (DragShape*) node->Data(); - delete shape; - node = node->Next(); - } - m_displayList.Clear(); -} - -DragShape* MyCanvas::FindShape(const wxPoint& pt) const -{ - wxNode* node = m_displayList.First(); - while (node) - { - DragShape* shape = (DragShape*) node->Data(); - if (shape->HitTest(pt)) - return shape; - node = node->Next(); - } - return (DragShape*) NULL; -} - -// MyFrame - -IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) - -BEGIN_EVENT_TABLE(MyFrame,wxFrame) - EVT_MENU (wxID_ABOUT, MyFrame::OnAbout) - EVT_MENU (wxID_EXIT, MyFrame::OnQuit) -END_EVENT_TABLE() - -MyFrame::MyFrame() - : wxFrame( (wxFrame *)NULL, -1, "wxDragImage sample", - wxPoint(20,20), wxSize(470,360) ) -{ - wxMenu *file_menu = new wxMenu(); - file_menu->Append( wxID_ABOUT, "&About..."); - file_menu->Append( TEST_USE_SCREEN, "&Use whole screen for dragging", "Use whole screen", TRUE); - file_menu->Append( wxID_EXIT, "E&xit"); - - wxMenuBar *menu_bar = new wxMenuBar(); - menu_bar->Append(file_menu, "&File"); - - SetMenuBar( menu_bar ); - - CreateStatusBar(2); - int widths[] = { -1, 100 }; - SetStatusWidths( 2, widths ); - - m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) ); -} - -void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) -{ - Close( TRUE ); -} - -void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) -{ - (void)wxMessageBox( "wxDragImage demo\n" - "Julian Smart (c) 2000", - "About wxDragImage Demo", wxICON_INFORMATION | wxOK ); -} - -//----------------------------------------------------------------------------- -// MyApp -//----------------------------------------------------------------------------- - -BEGIN_EVENT_TABLE(MyApp, wxApp) - EVT_MENU(TEST_USE_SCREEN, MyApp::OnUseScreen) -END_EVENT_TABLE() - -MyApp::MyApp() -{ - // Drag across whole screen - m_useScreen = FALSE; -} - -bool MyApp::OnInit() -{ -#if wxUSE_LIBPNG - wxImage::AddHandler( new wxPNGHandler ); -#endif - - wxImage image; - if (image.LoadFile("backgrnd.png", wxBITMAP_TYPE_PNG)) - { - m_background = image.ConvertToBitmap(); - } - - - MyFrame *frame = new MyFrame(); - - wxString rootName("shape0"); - - int i; - for (i = 1; i < 4; i++) - { - wxString filename; - filename.Printf("%s%d.png", (const char*) rootName, i); - if (image.LoadFile(filename, wxBITMAP_TYPE_PNG)) - { - DragShape* newShape = new DragShape(image.ConvertToBitmap()); - newShape->SetPosition(wxPoint(i*50, i*50)); - - if (i == 2) - newShape->SetDragMethod(SHAPE_DRAG_TEXT); - else if (i == 3) - newShape->SetDragMethod(SHAPE_DRAG_ICON); - else - newShape->SetDragMethod(SHAPE_DRAG_BITMAP); - frame->GetCanvas()->GetDisplayList().Append(newShape); - } - } - -#if 0 - // Under Motif or GTK, this demonstrates that - // wxScreenDC only gets the root window content. - // We need to be able to copy the overall content - // for full-screen dragging to work. - int w, h; - wxDisplaySize(& w, & h); - wxBitmap bitmap(w, h); - - wxScreenDC dc; - wxMemoryDC memDC; - memDC.SelectObject(bitmap); - memDC.Blit(0, 0, w, h, & dc, 0, 0); - memDC.SelectObject(wxNullBitmap); - m_background = bitmap; -#endif - - frame->Show( TRUE ); - - return TRUE; -} - -bool MyApp::TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap) -{ - int w = bitmap.GetWidth(); - int h = bitmap.GetHeight(); - - int i, j; - for (i = rect.x; i < rect.x + rect.width; i += w) - { - for (j = rect.y; j < rect.y + rect.height; j+= h) - dc.DrawBitmap(bitmap, i, j); - } - return TRUE; -} - -void MyApp::OnUseScreen(wxCommandEvent& event) -{ - m_useScreen = !m_useScreen; -} - -// DragShape - -DragShape::DragShape(const wxBitmap& bitmap) -{ - m_bitmap = bitmap; - m_pos.x = 0; - m_pos.y = 0; - m_dragMethod = SHAPE_DRAG_BITMAP; - m_show = TRUE; -} - -DragShape::~DragShape() -{ -} - -bool DragShape::HitTest(const wxPoint& pt) const -{ - wxRect rect(GetRect()); - return rect.Inside(pt.x, pt.y); -} - -bool DragShape::Draw(wxDC& dc, int op) -{ - if (m_bitmap.Ok()) - { - wxMemoryDC memDC; - memDC.SelectObject(m_bitmap); - - dc.Blit(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), - & memDC, 0, 0, op, TRUE); - - return TRUE; - } - else - return FALSE; -} - diff --git a/samples/dragimag/test.def b/samples/dragimag/test.def deleted file mode 100644 index 59f0db711d..0000000000 --- a/samples/dragimag/test.def +++ /dev/null @@ -1,7 +0,0 @@ -NAME Minimal -DESCRIPTION 'Minimal wxWindows application' -EXETYPE WINDOWS -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD MOVEABLE MULTIPLE -HEAPSIZE 4048 -STACKSIZE 16000 diff --git a/samples/dragimag/test.h b/samples/dragimag/test.h deleted file mode 100644 index 6d94bf49bf..0000000000 --- a/samples/dragimag/test.h +++ /dev/null @@ -1,156 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: test.h -// Purpose: wxDragImage sample -// Author: Julian Smart -// Modified by: -// Created: 28/2/2000 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifndef _WX_DRAGIMAGSAMPLE_ -#define _WX_DRAGIMAGSAMPLE_ - -// derived classes - -class MyFrame; -class MyApp; -class MyCanvas; -class DragShape; - -// MyFrame - -class MyFrame: public wxFrame -{ -public: - MyFrame(); - - void OnAbout( wxCommandEvent &event ); - void OnQuit( wxCommandEvent &event ); - - MyCanvas* GetCanvas() const { return m_canvas; } - void SetCanvas(MyCanvas* canvas) { m_canvas = canvas; } - -private: - MyCanvas* m_canvas; - - DECLARE_DYNAMIC_CLASS(MyFrame) - DECLARE_EVENT_TABLE() -}; - -// MyApp - -class MyApp: public wxApp -{ -public: - MyApp(); - virtual bool OnInit(); - -//// Operations - - // Tile the bitmap - bool TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap); - -//// Accessors - wxBitmap& GetBackgroundBitmap() const { return (wxBitmap&) m_background; } - - bool GetUseScreen() const { return m_useScreen; } - void SetUseScreen(bool useScreen) { m_useScreen = useScreen; } - - void OnUseScreen(wxCommandEvent& event); - -protected: - wxBitmap m_background; - bool m_useScreen; - -DECLARE_EVENT_TABLE() -}; - -DECLARE_APP(MyApp) - -#define TEST_USE_SCREEN 100 - -// MyCanvas - -// Dragging modes -#define TEST_DRAG_NONE 0 -#define TEST_DRAG_START 1 -#define TEST_DRAG_DRAGGING 2 - -class MyCanvas: public wxScrolledWindow -{ -public: - MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size ); - ~MyCanvas(); - - void OnPaint( wxPaintEvent &event ); - void OnEraseBackground(wxEraseEvent& event); - void OnMouseEvent(wxMouseEvent& event); - - void DrawShapes(wxDC& dc); - void EraseShape(DragShape* shape, wxDC& dc); - void ClearShapes(); - DragShape* FindShape(const wxPoint& pt) const; - - wxList& GetDisplayList() { return m_displayList; } - -protected: - -private: - wxList m_displayList; // A list of DragShapes - int m_dragMode; - DragShape* m_draggedShape; - DragShape* m_currentlyHighlighted; // The shape that's being highlighted - wxPoint m_dragStartPos; - wxDragImage* m_dragImage; - - DECLARE_CLASS(MyCanvas) - DECLARE_EVENT_TABLE() -}; - - -// Ways to drag a shape - -#define SHAPE_DRAG_BITMAP 1 -#define SHAPE_DRAG_TEXT 2 -#define SHAPE_DRAG_ICON 3 - -// Shape - -class DragShape: public wxObject -{ -public: - DragShape(const wxBitmap& bitmap); - ~DragShape(); - -//// Operations - - bool HitTest(const wxPoint& pt) const; - bool Draw(wxDC& dc, int op = wxCOPY); - -//// Accessors - - wxPoint GetPosition() const { return m_pos; } - void SetPosition(const wxPoint& pos) { m_pos = pos; } - - wxRect GetRect() const { return wxRect(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight()); } - - wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } - void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } - - int GetDragMethod() const { return m_dragMethod; } - void SetDragMethod(int method) { m_dragMethod = method; } - - bool IsShown() const { return m_show; } - void SetShow(bool show) { m_show = show; } - -protected: - wxPoint m_pos; - wxBitmap m_bitmap; - int m_dragMethod; - bool m_show; -}; - -#endif - // _WX_DRAGIMAGSAMPLE_ diff --git a/samples/dragimag/test.rc b/samples/dragimag/test.rc deleted file mode 100644 index 754a072235..0000000000 --- a/samples/dragimag/test.rc +++ /dev/null @@ -1,5 +0,0 @@ -mondrian ICON "mondrian.ico" -dragicon ICON "dragicon.ico" - -#include "wx/msw/wx.rc" -