1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-10-03 11:16:01 -04:00
|
|
|
// Name: samples/docview/view.cpp
|
|
|
|
// Purpose: View classes implementation
|
1998-05-22 15:57:05 -04:00
|
|
|
// Author: Julian Smart
|
2008-10-03 11:16:01 -04:00
|
|
|
// Modified by: Vadim Zeitlin: merge with the MDI version and general cleanup
|
1998-05-22 15:57:05 -04:00
|
|
|
// Created: 04/01/98
|
2008-10-03 11:16:01 -04:00
|
|
|
// Copyright: (c) 1998 Julian Smart
|
|
|
|
// (c) 2008 Vadim Zeitlin
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-22 15:57:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2008-10-03 11:16:01 -04:00
|
|
|
#include "wx/wx.h"
|
1998-05-22 15:57:05 -04:00
|
|
|
#endif
|
|
|
|
|
1998-09-25 11:28:18 -04:00
|
|
|
#if !wxUSE_DOC_VIEW_ARCHITECTURE
|
2008-10-03 11:16:01 -04:00
|
|
|
#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
|
1998-05-22 15:57:05 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "docview.h"
|
|
|
|
#include "doc.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// DrawingView implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(DrawingView, wxView);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(DrawingView, wxView)
|
2008-10-03 11:16:01 -04:00
|
|
|
EVT_MENU(wxID_CUT, DrawingView::OnCut)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
// What to do when a view is created. Creates actual
|
|
|
|
// windows for displaying the view.
|
2010-11-09 19:36:39 -05:00
|
|
|
bool DrawingView::OnCreate(wxDocument *doc, long flags)
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2010-11-09 19:36:39 -05:00
|
|
|
if ( !wxView::OnCreate(doc, flags) )
|
|
|
|
return false;
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
MyApp& app = wxGetApp();
|
|
|
|
if ( app.GetMode() != MyApp::Mode_Single )
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
// create a new window and canvas inside it
|
2010-11-09 19:36:39 -05:00
|
|
|
wxFrame* frame = app.CreateChildFrame(this, true);
|
|
|
|
wxASSERT(frame == GetFrame());
|
|
|
|
m_canvas = new MyCanvas(this);
|
2011-06-22 18:57:59 -04:00
|
|
|
frame->Show();
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2008-10-03 11:16:01 -04:00
|
|
|
else // single document mode
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
// reuse the existing window and canvas
|
|
|
|
m_canvas = app.GetMainWindowCanvas();
|
|
|
|
m_canvas->SetView(this);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
// Initialize the edit menu Undo and Redo items
|
2008-10-03 11:16:01 -04:00
|
|
|
doc->GetCommandProcessor()->SetEditMenu(app.GetMainWindowEditMenu());
|
2000-07-15 15:51:35 -04:00
|
|
|
doc->GetCommandProcessor()->Initialize();
|
|
|
|
}
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2004-05-27 14:07:04 -04:00
|
|
|
return true;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// Sneakily gets used for default print/preview as well as drawing on the
|
|
|
|
// screen.
|
1998-05-22 15:57:05 -04:00
|
|
|
void DrawingView::OnDraw(wxDC *dc)
|
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
dc->SetPen(*wxBLACK_PEN);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// simply draw all lines of all segments
|
|
|
|
const DoodleSegments& segments = GetDocument()->GetSegments();
|
|
|
|
for ( DoodleSegments::const_iterator i = segments.begin();
|
|
|
|
i != segments.end();
|
|
|
|
++i )
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
const DoodleLines& lines = i->GetLines();
|
2010-09-30 07:44:45 -04:00
|
|
|
for ( DoodleLines::const_iterator j = lines.begin();
|
2008-10-03 11:16:01 -04:00
|
|
|
j != lines.end();
|
|
|
|
++j )
|
|
|
|
{
|
|
|
|
const DoodleLine& line = *j;
|
|
|
|
|
|
|
|
dc->DrawLine(line.x1, line.y1, line.x2, line.y2);
|
|
|
|
}
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-04-06 09:57:23 -04:00
|
|
|
DrawingDocument* DrawingView::GetDocument()
|
|
|
|
{
|
|
|
|
return wxStaticCast(wxView::GetDocument(), DrawingDocument);
|
|
|
|
}
|
|
|
|
|
2009-09-24 12:04:06 -04:00
|
|
|
void DrawingView::OnUpdate(wxView* sender, wxObject* hint)
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2009-09-24 12:04:06 -04:00
|
|
|
wxView::OnUpdate(sender, hint);
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( m_canvas )
|
2008-04-06 09:57:23 -04:00
|
|
|
m_canvas->Refresh();
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up windows used for displaying the view.
|
|
|
|
bool DrawingView::OnClose(bool deleteWindow)
|
|
|
|
{
|
2010-07-23 19:33:27 -04:00
|
|
|
if ( !wxView::OnClose(deleteWindow) )
|
2004-05-27 14:07:04 -04:00
|
|
|
return false;
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2004-05-27 14:07:04 -04:00
|
|
|
Activate(false);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// Clear the canvas in single-window mode in which it stays alive
|
|
|
|
if ( wxGetApp().GetMode() == MyApp::Mode_Single )
|
|
|
|
{
|
|
|
|
m_canvas->ClearBackground();
|
|
|
|
m_canvas->ResetView();
|
|
|
|
m_canvas = NULL;
|
|
|
|
|
2010-11-09 19:36:39 -05:00
|
|
|
if (GetFrame())
|
|
|
|
wxStaticCast(GetFrame(), wxFrame)->SetTitle(wxTheApp->GetAppDisplayName());
|
2008-10-03 11:16:01 -04:00
|
|
|
}
|
|
|
|
else // not single window mode
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( deleteWindow )
|
2010-11-09 19:36:39 -05:00
|
|
|
{
|
|
|
|
GetFrame()->Destroy();
|
|
|
|
SetFrame(NULL);
|
|
|
|
}
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2004-05-27 14:07:04 -04:00
|
|
|
return true;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
1998-07-27 16:50:48 -04:00
|
|
|
void DrawingView::OnCut(wxCommandEvent& WXUNUSED(event) )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
DrawingDocument * const doc = GetDocument();
|
|
|
|
|
|
|
|
doc->GetCommandProcessor()->Submit(new DrawingRemoveSegmentCommand(doc));
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// TextEditView implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(TextEditView, wxView);
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(TextEditView, wxView)
|
2008-04-06 13:02:25 -04:00
|
|
|
EVT_MENU(wxID_COPY, TextEditView::OnCopy)
|
|
|
|
EVT_MENU(wxID_PASTE, TextEditView::OnPaste)
|
|
|
|
EVT_MENU(wxID_SELECTALL, TextEditView::OnSelectAll)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
2008-04-06 13:02:25 -04:00
|
|
|
|
2010-11-09 19:36:39 -05:00
|
|
|
bool TextEditView::OnCreate(wxDocument *doc, long flags)
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2010-11-09 19:36:39 -05:00
|
|
|
if ( !wxView::OnCreate(doc, flags) )
|
|
|
|
return false;
|
2008-10-03 11:16:01 -04:00
|
|
|
|
2010-11-09 19:36:39 -05:00
|
|
|
wxFrame* frame = wxGetApp().CreateChildFrame(this, false);
|
|
|
|
wxASSERT(frame == GetFrame());
|
|
|
|
m_text = new wxTextCtrl(frame, wxID_ANY, "",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
frame->Show();
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2004-05-27 14:07:04 -04:00
|
|
|
return true;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
void TextEditView::OnDraw(wxDC *WXUNUSED(dc))
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
// nothing to do here, wxTextCtrl draws itself
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEditView::OnClose(bool deleteWindow)
|
|
|
|
{
|
2010-07-23 19:33:27 -04:00
|
|
|
if ( !wxView::OnClose(deleteWindow) )
|
2004-05-27 14:07:04 -04:00
|
|
|
return false;
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2004-05-27 14:07:04 -04:00
|
|
|
Activate(false);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( wxGetApp().GetMode() == MyApp::Mode_Single )
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
m_text->Clear();
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2008-10-03 11:16:01 -04:00
|
|
|
else // not single window mode
|
|
|
|
{
|
|
|
|
if ( deleteWindow )
|
2010-11-09 19:36:39 -05:00
|
|
|
{
|
|
|
|
GetFrame()->Destroy();
|
|
|
|
SetFrame(NULL);
|
|
|
|
}
|
2008-10-03 11:16:01 -04:00
|
|
|
}
|
2004-05-27 14:07:04 -04:00
|
|
|
return true;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyCanvas implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-22 15:57:05 -04:00
|
|
|
|
2014-03-30 03:07:55 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
1998-05-22 15:57:05 -04:00
|
|
|
EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
|
2014-03-30 03:07:55 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
1998-05-22 15:57:05 -04:00
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
2008-10-03 11:16:01 -04:00
|
|
|
MyCanvas::MyCanvas(wxView *view, wxWindow *parent)
|
2010-11-09 19:36:39 -05:00
|
|
|
: wxScrolledWindow(parent ? parent : view->GetFrame())
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2008-04-06 09:57:23 -04:00
|
|
|
m_view = view;
|
2008-10-03 11:16:01 -04:00
|
|
|
m_currentSegment = NULL;
|
|
|
|
m_lastMousePos = wxDefaultPosition;
|
|
|
|
|
|
|
|
SetCursor(wxCursor(wxCURSOR_PENCIL));
|
|
|
|
|
|
|
|
// this is completely arbitrary and is done just for illustration purposes
|
|
|
|
SetVirtualSize(1000, 1000);
|
|
|
|
SetScrollRate(20, 20);
|
|
|
|
|
|
|
|
SetBackgroundColour(*wxWHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
MyCanvas::~MyCanvas()
|
|
|
|
{
|
|
|
|
delete m_currentSegment;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define the repainting behaviour
|
|
|
|
void MyCanvas::OnDraw(wxDC& dc)
|
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( m_view )
|
2008-04-06 09:57:23 -04:00
|
|
|
m_view->OnDraw(& dc);
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// This implements a tiny doodling program. Drag the mouse using the left
|
|
|
|
// button.
|
1998-05-22 15:57:05 -04:00
|
|
|
void MyCanvas::OnMouseEvent(wxMouseEvent& event)
|
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( !m_view )
|
2000-07-15 15:51:35 -04:00
|
|
|
return;
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
wxClientDC dc(this);
|
|
|
|
PrepareDC(dc);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
dc.SetPen(*wxBLACK_PEN);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
const wxPoint pt(event.GetLogicalPosition(dc));
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// is this the end of the current segment?
|
|
|
|
if ( m_currentSegment && event.LeftUp() )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( !m_currentSegment->IsEmpty() )
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
|
|
|
// We've got a valid segment on mouse left up, so store it.
|
2008-10-03 11:16:01 -04:00
|
|
|
DrawingDocument * const
|
|
|
|
doc = wxStaticCast(m_view->GetDocument(), DrawingDocument);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
doc->GetCommandProcessor()->Submit(
|
|
|
|
new DrawingAddSegmentCommand(doc, *m_currentSegment));
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
doc->Modify(true);
|
2000-07-15 15:51:35 -04:00
|
|
|
}
|
2008-10-03 11:16:01 -04:00
|
|
|
|
2010-06-20 14:18:23 -04:00
|
|
|
wxDELETE(m_currentSegment);
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
// is this the start of a new segment?
|
|
|
|
if ( m_lastMousePos != wxDefaultPosition && event.Dragging() )
|
1998-05-22 15:57:05 -04:00
|
|
|
{
|
2008-10-03 11:16:01 -04:00
|
|
|
if ( !m_currentSegment )
|
|
|
|
m_currentSegment = new DoodleSegment;
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
m_currentSegment->AddLine(m_lastMousePos, pt);
|
2008-04-06 09:57:23 -04:00
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
dc.DrawLine(m_lastMousePos, pt);
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2008-10-03 11:16:01 -04:00
|
|
|
m_lastMousePos = pt;
|
1998-05-22 15:57:05 -04:00
|
|
|
}
|
|
|
|
|
2009-09-24 12:04:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-05-13 10:37:06 -04:00
|
|
|
// ImageCanvas implementation
|
2009-09-24 12:04:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a constructor for my canvas
|
2010-11-09 19:36:39 -05:00
|
|
|
ImageCanvas::ImageCanvas(wxView* view)
|
|
|
|
: wxScrolledWindow(view->GetFrame())
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
|
|
|
m_view = view;
|
2010-11-09 19:36:39 -05:00
|
|
|
SetScrollRate( 10, 10 );
|
2009-09-24 12:04:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define the repainting behaviour
|
2010-05-13 10:37:06 -04:00
|
|
|
void ImageCanvas::OnDraw(wxDC& dc)
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
|
|
|
if ( m_view )
|
|
|
|
m_view->OnDraw(& dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2010-05-13 10:37:06 -04:00
|
|
|
// ImageView implementation
|
2009-09-24 12:04:06 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_DYNAMIC_CLASS(ImageView, wxView);
|
2009-09-24 12:04:06 -04:00
|
|
|
|
2010-05-13 10:37:06 -04:00
|
|
|
ImageDocument* ImageView::GetDocument()
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2010-05-13 10:37:06 -04:00
|
|
|
return wxStaticCast(wxView::GetDocument(), ImageDocument);
|
2009-09-24 12:04:06 -04:00
|
|
|
}
|
|
|
|
|
2010-11-09 19:36:39 -05:00
|
|
|
bool ImageView::OnCreate(wxDocument* doc, long flags)
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2010-11-09 19:36:39 -05:00
|
|
|
if ( !wxView::OnCreate(doc, flags) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxFrame* frame = wxGetApp().CreateChildFrame(this, false);
|
|
|
|
wxASSERT(frame == GetFrame());
|
|
|
|
m_canvas = new ImageCanvas(this);
|
|
|
|
frame->Show();
|
|
|
|
|
2009-09-24 12:04:06 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-13 10:37:06 -04:00
|
|
|
void ImageView::OnUpdate(wxView* sender, wxObject* hint)
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
|
|
|
wxView::OnUpdate(sender, hint);
|
2010-05-13 10:37:06 -04:00
|
|
|
wxImage image = GetDocument()->GetImage();
|
|
|
|
if ( image.IsOk() )
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2010-05-13 10:37:06 -04:00
|
|
|
m_canvas->SetVirtualSize(image.GetWidth(), image.GetHeight());
|
2009-09-24 12:04:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-13 10:37:06 -04:00
|
|
|
void ImageView::OnDraw(wxDC* dc)
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2010-05-13 10:37:06 -04:00
|
|
|
wxImage image = GetDocument()->GetImage();
|
|
|
|
if ( image.IsOk() )
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2012-01-19 17:17:17 -05:00
|
|
|
dc->DrawBitmap(wxBitmap(image), 0, 0, true /* use mask */);
|
2009-09-24 12:04:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-13 10:37:06 -04:00
|
|
|
bool ImageView::OnClose(bool deleteWindow)
|
2009-09-24 12:04:06 -04:00
|
|
|
{
|
2010-07-23 19:33:27 -04:00
|
|
|
if ( !wxView::OnClose(deleteWindow) )
|
2009-09-24 12:04:06 -04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Activate(false);
|
|
|
|
|
|
|
|
if ( wxGetApp().GetMode() == MyApp::Mode_Single )
|
|
|
|
{
|
|
|
|
GetDocument()->DeleteContents();
|
|
|
|
}
|
|
|
|
else // not single window mode
|
|
|
|
{
|
|
|
|
if ( deleteWindow )
|
2010-11-09 19:36:39 -05:00
|
|
|
{
|
|
|
|
GetFrame()->Destroy();
|
|
|
|
SetFrame(NULL);
|
|
|
|
}
|
2009-09-24 12:04:06 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-26 20:09:37 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ImageDetailsView
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ImageDetailsView::ImageDetailsView(ImageDetailsDocument *doc)
|
|
|
|
: wxView()
|
|
|
|
{
|
|
|
|
SetDocument(doc);
|
|
|
|
|
|
|
|
m_frame = wxGetApp().CreateChildFrame(this, false);
|
|
|
|
m_frame->SetTitle("Image Details");
|
|
|
|
|
|
|
|
wxPanel * const panel = new wxPanel(m_frame);
|
|
|
|
wxFlexGridSizer * const sizer = new wxFlexGridSizer(2, wxSize(5, 5));
|
|
|
|
const wxSizerFlags
|
|
|
|
flags = wxSizerFlags().Align(wxALIGN_CENTRE_VERTICAL).Border();
|
|
|
|
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, "Image &file:"), flags);
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, doc->GetFilename()), flags);
|
|
|
|
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, "Image &type:"), flags);
|
|
|
|
wxString typeStr;
|
|
|
|
switch ( doc->GetType() )
|
|
|
|
{
|
|
|
|
case wxBITMAP_TYPE_PNG:
|
|
|
|
typeStr = "PNG";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxBITMAP_TYPE_JPEG:
|
|
|
|
typeStr = "JPEG";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
typeStr = "Unknown";
|
|
|
|
}
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, typeStr), flags);
|
|
|
|
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, "Image &size:"), flags);
|
|
|
|
wxSize size = doc->GetSize();
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY,
|
|
|
|
wxString::Format("%d*%d", size.x, size.y)),
|
|
|
|
flags);
|
|
|
|
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, "Number of unique &colours:"),
|
|
|
|
flags);
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY,
|
|
|
|
wxString::Format("%lu", doc->GetNumColours())),
|
|
|
|
flags);
|
|
|
|
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY, "Uses &alpha:"), flags);
|
|
|
|
sizer->Add(new wxStaticText(panel, wxID_ANY,
|
|
|
|
doc->HasAlpha() ? "Yes" : "No"), flags);
|
|
|
|
|
|
|
|
panel->SetSizer(sizer);
|
|
|
|
m_frame->SetClientSize(panel->GetBestSize());
|
|
|
|
m_frame->Show(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageDetailsView::OnDraw(wxDC * WXUNUSED(dc))
|
|
|
|
{
|
|
|
|
// nothing to do here, we use controls to show our information
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageDetailsView::OnClose(bool deleteWindow)
|
|
|
|
{
|
|
|
|
if ( wxGetApp().GetMode() != MyApp::Mode_Single && deleteWindow )
|
|
|
|
{
|
|
|
|
delete m_frame;
|
|
|
|
m_frame = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|