Motif wxNotebook about done; added print/preview to OGLEdit sample

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-10-27 17:58:46 +00:00
parent 31811e1aca
commit 0280030162
20 changed files with 290 additions and 65 deletions

View File

@@ -40,8 +40,8 @@ public:
inline void SetLabel(const wxString& str) { m_controlLabel = str; }
inline wxString GetLabel(void) const { return m_controlLabel; }
inline void SetFont(wxFont *f) { m_labelFont = f; }
inline wxFont *GetFont(void) const { return m_labelFont; }
inline void SetFont(const wxFont& f) { m_labelFont = f; }
inline wxFont *GetFont(void) const { return (wxFont*) & m_labelFont; }
inline void SetSelected(bool sel) { m_isSelected = sel; }
inline bool IsSelected(void) const { return m_isSelected; }
@@ -68,7 +68,7 @@ protected:
wxTabView* m_view;
wxString m_controlLabel;
bool m_isSelected;
wxFont* m_labelFont;
wxFont m_labelFont;
int m_offsetX; // Offsets from top-left of tab view area (the area below the tabs)
int m_offsetY;
int m_width;
@@ -188,11 +188,11 @@ public:
inline void SetVerticalTabTextSpacing(int s) { m_tabVerticalTextSpacing = s; }
inline int GetVerticalTabTextSpacing() const { return m_tabVerticalTextSpacing; }
inline wxFont *GetTabFont() const { return m_tabFont; }
inline void SetTabFont(wxFont *f) { m_tabFont = f; }
inline wxFont *GetTabFont() const { return (wxFont*) & m_tabFont; }
inline void SetTabFont(const wxFont& f) { m_tabFont = f; }
inline wxFont *GetSelectedTabFont() const { return m_tabSelectedFont; }
inline void SetSelectedTabFont(wxFont *f) { m_tabSelectedFont = f; }
inline wxFont *GetSelectedTabFont() const { return (wxFont*) & m_tabSelectedFont; }
inline void SetSelectedTabFont(const wxFont& f) { m_tabSelectedFont = f; }
// Find the node and the column at which this control is positioned.
wxNode *FindTabNodeAndColumn(wxTabControl *control, int *col) const ;
@@ -253,8 +253,8 @@ protected:
wxPen* m_backgroundPen;
wxBrush* m_backgroundBrush;
wxFont* m_tabFont;
wxFont* m_tabSelectedFont;
wxFont m_tabFont;
wxFont m_tabSelectedFont;
int m_noTabs;

View File

@@ -49,6 +49,9 @@ public:
int GetSelection() const { return m_nSel; }
int GetOldSelection() const { return m_nOldSel; }
void SetSelection(int sel) { m_nSel = sel; }
void SetOldSelection(int oldSel) { m_nOldSel = oldSel; }
private:
int m_nSel, // currently selected page
m_nOldSel; // previously selected page
@@ -73,22 +76,7 @@ public:
// Called when a tab is activated
virtual void OnTabActivate(int activateId, int deactivateId);
/*
// Specific to this class
void AddTabWindow(int id, wxWindow *window);
wxWindow *GetTabWindow(int id) const ;
void ClearWindows(bool deleteWindows = TRUE);
inline wxWindow *GetCurrentWindow() const { return m_currentWindow; }
void ShowWindowForTab(int id);
*/
protected:
/*
// List of panels, one for each tab. Indexed
// by tab ID.
wxList m_tabWindows;
wxWindow* m_currentWindow;
*/
wxNotebook* m_notebook;
};
@@ -204,6 +192,7 @@ public:
virtual void ChangeFont(bool keepOriginalSize = TRUE);
virtual void ChangeBackgroundColour();
virtual void ChangeForegroundColour();
virtual wxRect GetAvailableClientSize();
protected:
// common part of all ctors

View File

@@ -190,6 +190,7 @@ END_EVENT_TABLE()
MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size):
wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL)
{
SetBackgroundColour(wxColour("WHITE"));
}
// Define the repainting behaviour

View File

@@ -81,12 +81,14 @@ void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
// Add some panels
wxPanel *panel1 = new wxPanel(notebook, -1);
// panel1->SetBackgroundColour(wxColour("RED"));
(void)new wxButton(panel1, -1, "Press me", wxPoint(10, 10));
(void)new wxTextCtrl(panel1, -1, "1234", wxPoint(10, 40), wxSize(120, 150));
notebook->AddPage(panel1, "Cat");
wxPanel *panel2 = new wxPanel(notebook, -1);
panel2->SetBackgroundColour(wxColour("BLUE"));
wxString animals[] = { "Fox", "Hare", "Rabbit", "Sabre-toothed tiger", "T Rex" };
(void)new wxListBox(panel2, -1, wxPoint(5, 5), wxSize(170, 80), 5, animals);
@@ -95,6 +97,14 @@ void MyApp::InitTabView(wxNotebook* notebook, wxWindow* window)
wxTE_MULTILINE);
notebook->AddPage(panel2, "Dog");
wxPanel *panel3 = new wxPanel(notebook, -1);
panel3->SetBackgroundColour(wxColour("WHITE"));
notebook->AddPage(panel3, "Goat");
wxPanel *panel4 = new wxPanel(notebook, -1);
panel4->SetBackgroundColour(wxColour("YELLOW"));
notebook->AddPage(panel4, "Sheep");
}
BEGIN_EVENT_TABLE(MyDialog, wxDialog)

View File

@@ -1087,7 +1087,7 @@ void wxListMainWindow::OnRenameAccept()
void wxListMainWindow::OnMouse( wxMouseEvent &event )
{
if (GetParent()->ProcessEvent( event)) return;
if (GetParent()->GetEventHandler()->ProcessEvent( event)) return;
if (!m_current) return;
if (m_dirty) return;
@@ -1402,7 +1402,7 @@ void wxListMainWindow::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
wxFocusEvent event( wxEVT_SET_FOCUS, GetParent()->GetId() );
event.SetEventObject( GetParent() );
GetParent()->ProcessEvent( event );
GetParent()->GetEventHandler()->ProcessEvent( event );
}
void wxListMainWindow::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
@@ -2054,7 +2054,7 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
bool wxListMainWindow::OnListNotify( wxListEvent &event )
{
if (GetParent()) GetParent()->ProcessEvent( event );
if (GetParent()) GetParent()->GetEventHandler()->ProcessEvent( event );
return FALSE;
}

View File

@@ -43,7 +43,6 @@ wxTabControl::wxTabControl(wxTabView *v)
{
m_view = v;
m_isSelected = FALSE;
m_labelFont = (wxFont *) NULL;
m_offsetX = 0;
m_offsetY = 0;
m_width = 0;
@@ -86,7 +85,11 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
dc.SetBrush(*m_view->GetBackgroundBrush());
// Add 1 because the pen is transparent. Under Motif, may be different.
#ifdef __WXMOTIF__
dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + tabHeightInc));
#else
dc.DrawRectangle(tabX, tabY, (GetWidth()+1), (GetHeight() + 1 + tabHeightInc));
#endif
}
// Draw highlight and shadow
@@ -152,6 +155,10 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
if ( GetRowPosition() < (maxPositions - 1) )
topY = tabY + GetHeight() + tabHeightInc;
#ifdef __WXMOTIF__
topY -= 1;
#endif
// Shadow
dc.DrawLine((tabX + GetWidth()), tabY, (tabX + GetWidth()), topY);
// Draw black line to emphasize shadow
@@ -170,6 +177,10 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
if (tabBeneath && tabBeneath->IsSelected())
subtractThis = (m_view->GetTabSelectionHeight() - m_view->GetTabHeight());
#ifdef __WXMOTIF__
subtractThis += 1;
#endif
// Draw only to next tab down.
dc.DrawLine((tabX + GetWidth()), tabY,
(tabX + GetWidth()), (tabY + GetHeight() + tabHeightInc - subtractThis));
@@ -510,13 +521,14 @@ wxTabView::wxTabView(long style)
m_shadowPen = wxGREY_PEN;
m_backgroundPen = wxLIGHT_GREY_PEN;
m_backgroundBrush = wxLIGHT_GREY_BRUSH;
m_tabFont = wxTheFontList->FindOrCreateFont(9, wxSWISS, wxNORMAL, wxNORMAL);
m_tabSelectedFont = wxTheFontList->FindOrCreateFont(9, wxSWISS, wxNORMAL, wxBOLD);
m_tabFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
m_tabSelectedFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
m_window = (wxWindow *) NULL;
}
wxTabView::~wxTabView()
{
ClearTabs(TRUE);
}
// Automatically positions tabs
@@ -578,7 +590,7 @@ wxTabControl *wxTabView::AddTab(int id, const wxString& label, wxTabControl *exi
tabControl->SetSize(GetTabWidth(), GetTabHeight());
tabControl->SetId(id);
tabControl->SetLabel(label);
tabControl->SetFont(GetTabFont());
tabControl->SetFont(* GetTabFont());
tabLayer->Append(tabControl);
m_noTabs ++;
@@ -779,7 +791,12 @@ void wxTabView::Draw(wxDC& dc)
dc.DrawLine(
(GetViewRect().x),
(GetViewRect().y + GetViewRect().height + 1),
#if defined(__WXMOTIF__)
(GetViewRect().x + GetViewRect().width + 1),
#else
(GetViewRect().x + GetViewRect().width + 2),
#endif
(GetViewRect().y + GetViewRect().height + 1)
);

View File

@@ -112,8 +112,6 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, width, height);
m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW);
ChangeBackgroundColour();
return TRUE;
@@ -751,10 +749,41 @@ void wxListBox::ChangeFont(bool keepOriginalSize)
void wxListBox::ChangeBackgroundColour()
{
wxWindow::ChangeBackgroundColour();
Widget parent = XtParent ((Widget) m_mainWidget);
Widget hsb, vsb;
XtVaGetValues (parent,
XmNhorizontalScrollBar, &hsb,
XmNverticalScrollBar, &vsb,
NULL);
/* TODO: should scrollbars be affected? Should probably have separate
* function to change them (by default, taken from wxSystemSettings)
DoChangeBackgroundColour((WXWidget) hsb, m_backgroundColour, TRUE);
DoChangeBackgroundColour((WXWidget) vsb, m_backgroundColour, TRUE);
*/
DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
}
void wxListBox::ChangeForegroundColour()
{
wxWindow::ChangeForegroundColour();
Widget parent = XtParent ((Widget) m_mainWidget);
Widget hsb, vsb;
XtVaGetValues (parent,
XmNhorizontalScrollBar, &hsb,
XmNverticalScrollBar, &vsb,
NULL);
/* TODO: should scrollbars be affected? Should probably have separate
* function to change them (by default, taken from wxSystemSettings)
DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
*/
}

View File

@@ -26,6 +26,9 @@
#include <wx/notebook.h>
#include <wx/dcclient.h>
#include <Xm/Xm.h>
#include <wx/motif/private.h>
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
@@ -96,16 +99,9 @@ bool wxNotebook::Create(wxWindow *parent,
{
// base init
SetName(name);
SetParent(parent);
m_windowId = id == -1 ? NewControlId() : id;
// style
m_windowStyle = style;
if ( parent != NULL )
parent->AddChild(this);
// It's like a normal window...
if (!wxWindow::Create(parent, id, pos, size, style, name))
return FALSE;
@@ -137,6 +133,9 @@ int wxNotebook::GetRowCount() const
int wxNotebook::SetSelection(int nPage)
{
if (nPage == -1)
return 0;
wxASSERT( IS_VALID_PAGE(nPage) );
ChangePage(m_nSelection, nPage);
@@ -250,6 +249,7 @@ bool wxNotebook::InsertPage(int nPage,
wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
m_tabView->AddTab(nPage, strText);
pPage->Show(FALSE);
/*
if (bSelect)
@@ -323,10 +323,14 @@ void wxNotebook::OnSize(wxSizeEvent& event)
unsigned int nCount = m_aPages.Count();
for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
wxNotebookPage *pPage = m_aPages[nPage];
pPage->SetSize(rect.x + 2, rect.y + 2, rect.width - 2, rect.height - 2);
if (pPage->IsShown())
{
wxRect clientRect = GetAvailableClientSize();
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
if ( pPage->GetAutoLayout() )
pPage->Layout();
}
}
Refresh();
}
@@ -401,12 +405,20 @@ void wxNotebook::ChangePage(int nOldSel, int nSel)
if ( nOldSel != -1 ) {
m_aPages[nOldSel]->Show(FALSE);
m_aPages[nOldSel]->Lower();
}
wxNotebookPage *pPage = m_aPages[nSel];
wxRect clientRect = GetAvailableClientSize();
pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
pPage->Show(TRUE);
pPage->Raise();
pPage->SetFocus();
Refresh();
m_nSelection = nSel;
}
@@ -438,6 +450,23 @@ void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event) )
m_tabView->Draw(dc);
}
wxRect wxNotebook::GetAvailableClientSize()
{
int cw, ch;
GetClientSize(& cw, & ch);
int tabHeight = m_tabView->GetTotalTabHeight();
// TODO: these margins should be configurable.
wxRect rect;
rect.x = 6;
rect.y = tabHeight + 6;
rect.width = cw - 12;
rect.height = ch - 4 - rect.y ;
return rect;
}
/*
* wxNotebookTabView
*/
@@ -448,8 +477,6 @@ wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabVie
{
m_notebook = notebook;
// m_currentWindow = (wxWindow *) NULL;
m_notebook->SetTabView(this);
SetWindow(m_notebook);
@@ -457,7 +484,6 @@ wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style): wxTabVie
wxNotebookTabView::~wxNotebookTabView(void)
{
// ClearWindows(TRUE);
}
// Called when a tab is activated
@@ -466,15 +492,43 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
if (!m_notebook)
return;
wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
event.SetEventObject(m_notebook);
event.SetSelection(activateId);
event.SetOldSelection(deactivateId);
m_notebook->GetEventHandler()->ProcessEvent(event);
/*
wxWindow *oldWindow = ((deactivateId == -1) ? 0 : m_notebook->GetPage(deactivateId));
wxWindow *newWindow = m_notebook->GetPage(activateId);
if (oldWindow)
{
oldWindow->Show(FALSE);
oldWindow->Lower();
}
if (newWindow)
{
newWindow->Show(TRUE);
newWindow->Raise();
int cw, ch;
m_notebook->GetClientSize(& cw, & ch);
int tabHeight = GetTotalTabHeight();
wxRect rect;
rect.x = 4;
rect.y = tabHeight + 4;
rect.width = cw - 8;
rect.height = ch - 4 - rect.y ;
newWindow->SetSize(rect.x + 2, rect.y + 2, rect.width - 2, rect.height - 2);
newWindow->Refresh();
}
// TODO: only refresh the tab area.
m_notebook->Refresh();
*/
}
#if 0

View File

@@ -74,7 +74,8 @@ wxColour wxSystemSettings::GetSystemColour(int index)
case wxSYS_COLOUR_INFOBK:
case wxSYS_COLOUR_APPWORKSPACE:
{
return *wxWHITE;
return wxColour("LIGHT GREY");
// return *wxWHITE;
}
}
return *wxWHITE;

View File

@@ -646,11 +646,47 @@ void wxTextCtrl::ChangeFont(bool keepOriginalSize)
void wxTextCtrl::ChangeBackgroundColour()
{
wxWindow::ChangeBackgroundColour();
Widget parent = XtParent ((Widget) m_mainWidget);
Widget hsb, vsb;
XtVaGetValues (parent,
XmNhorizontalScrollBar, &hsb,
XmNverticalScrollBar, &vsb,
NULL);
/* TODO: should scrollbars be affected? Should probably have separate
* function to change them (by default, taken from wxSystemSettings)
if (hsb)
DoChangeBackgroundColour((WXWidget) hsb, m_backgroundColour, TRUE);
if (vsb)
DoChangeBackgroundColour((WXWidget) vsb, m_backgroundColour, TRUE);
*/
DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
}
void wxTextCtrl::ChangeForegroundColour()
{
wxWindow::ChangeForegroundColour();
Widget parent = XtParent ((Widget) m_mainWidget);
Widget hsb, vsb;
XtVaGetValues (parent,
XmNhorizontalScrollBar, &hsb,
XmNverticalScrollBar, &vsb,
NULL);
/* TODO: should scrollbars be affected? Should probably have separate
* function to change them (by default, taken from wxSystemSettings)
if (hsb)
DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
if (vsb)
DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
*/
DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
}
static void wxTextWindowChangedProc (Widget w, XtPointer clientData, XtPointer ptr)

View File

@@ -740,6 +740,8 @@ bool wxWindow::Show(bool show)
{
if (m_borderWidget || m_scrolledWindow)
{
if (m_drawingArea)
XtMapWidget((Widget) m_drawingArea);
XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
}
else
@@ -751,6 +753,8 @@ bool wxWindow::Show(bool show)
{
if (m_borderWidget || m_scrolledWindow)
{
if (m_drawingArea)
XtUnmapWidget((Widget) m_drawingArea);
XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
}
else
@@ -1387,7 +1391,18 @@ void wxWindow::RemoveChild(wxWindow *child)
void wxWindow::DestroyChildren()
{
if (GetChildren()) {
if (GetChildren())
{
wxNode *node = GetChildren()->First();
while (node)
{
wxNode* next = node->Next();
wxWindow* child = (wxWindow*) node->Data();
delete child;
node = next;
}
GetChildren()->Clear();
#if 0
wxNode *node;
while ((node = GetChildren()->First()) != (wxNode *)NULL) {
wxWindow *child;
@@ -1397,6 +1412,7 @@ void wxWindow::DestroyChildren()
delete node;
}
} /* while */
#endif
}
}

View File

@@ -854,7 +854,7 @@ bool wxApp::SendIdleEvents(wxWindow* win)
wxIdleEvent event;
event.SetEventObject(win);
win->ProcessEvent(event);
win->GetEventHandler()->ProcessEvent(event);
if (event.MoreRequested())
needMore = TRUE;

View File

@@ -242,7 +242,7 @@ bool wxControl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
event.SetEventType(eventType);
event.SetEventObject(this);
if ( !ProcessEvent(event) )
if ( !GetEventHandler()->ProcessEvent(event) )
return FALSE;
return TRUE;
#else

View File

@@ -544,7 +544,7 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
{
wxSysColourChangedEvent event2;
event2.SetEventObject( m_frameStatusBar );
m_frameStatusBar->ProcessEvent(event2);
m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
}
// Propagate the event to the non-top-level children

View File

@@ -508,7 +508,7 @@ void wxMenu::ProcessCommand(wxCommandEvent & event)
// Try the window the menu was popped up from (and up
// through the hierarchy)
if ( !processed && GetInvokingWindow())
processed = GetInvokingWindow()->ProcessEvent(event);
processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event);
}
extern wxMenu *wxCurrentPopupMenu;

View File

@@ -398,7 +398,7 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
// pass to the parent
if ( GetParent() ) {
event.SetCurrentFocus(this);
GetParent()->ProcessEvent(event);
GetParent()->GetEventHandler()->ProcessEvent(event);
}
}
}
@@ -453,7 +453,7 @@ bool wxNotebook::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
event.SetEventObject(this);
event.SetInt(LOWORD(wParam));
return ProcessEvent(event);
return GetEventHandler()->ProcessEvent(event);
}
// ----------------------------------------------------------------------------

View File

@@ -252,7 +252,7 @@ bool wxSpinButton::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
event.eventObject = this;
event.SetEventType(eventType);
if ( !ProcessEvent(event) )
if ( !GetEventHandler()->ProcessEvent(event) )
return FALSE;
*/
return TRUE;

View File

@@ -1034,7 +1034,7 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
: wxEVT_SET_FOCUS,
m_windowId);
event.SetEventObject( this );
ProcessEvent(event);
GetEventHandler()->ProcessEvent(event);
}
break;
@@ -1083,7 +1083,7 @@ bool wxTextCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam)
event.SetEventObject( this );
event.SetEventType(eventType);
if ( !ProcessEvent(event) )
if ( !GetEventHandler()->ProcessEvent(event) )
return FALSE;
return TRUE;

View File

@@ -3575,7 +3575,7 @@ void wxWindow::OnChar(wxKeyEvent& event)
// propagate the TABs to the parent - it's up to it to decide what
// to do with it
if ( GetParent() ) {
if ( GetParent()->ProcessEvent(event) )
if ( GetParent()->GetEventHandler()->ProcessEvent(event) )
return;
}
}

View File

@@ -66,10 +66,81 @@ bool DiagramView::OnCreate(wxDocument *doc, long flags)
return TRUE;
}
#define CENTER FALSE // Place the drawing to the center of the page
// Sneakily gets used for default print/preview
// as well as drawing on the screen.
void DiagramView::OnDraw(wxDC *dc)
{
/* You might use THIS code if you were scaling
* graphics of known size to fit on the page.
*/
float w, h;
// We need to adjust for the graphic size, a formula will be added
float maxX = 900;
float maxY = 700;
// A better way of find the maxium values would be to search through
// the linked list
// Let's have at least 10 device units margin
float marginX = 10;
float marginY = 10;
// Add the margin to the graphic size
maxX += (2 * marginX);
maxY += (2 * marginY);
// Get the size of the DC in pixels
dc->GetSize (&w, &h);
// Calculate a suitable scaling factor
float scaleX = (float) (w / maxX);
float scaleY = (float) (h / maxY);
// Use x or y scaling factor, whichever fits on the DC
float actualScale = wxMin (scaleX, scaleY);
float posX, posY;
// Calculate the position on the DC for centring the graphic
if (CENTER == TRUE) // center the drawing
{
posX = (float) ((w - (200 * actualScale)) / 2.0);
posY = (float) ((h - (200 * actualScale)) / 2.0);
}
else // Use defined presets
{
posX = 10;
posY = 35;
}
// Set the scale and origin
dc->SetUserScale (actualScale, actualScale);
dc->SetDeviceOrigin (posX, posY);
// This part was added to preform the print preview and printing functions
dc->BeginDrawing(); // Allows optimization of drawing code under MS Windows.
wxDiagram *diagram_p=((DiagramDocument*)GetDocument())->GetDiagram(); // Get the current diagram
if (diagram_p->GetShapeList())
{
wxCursor *old_cursor = NULL;
wxNode *current = diagram_p->GetShapeList()->First();
while (current) // Loop through the entire list of shapes
{
wxShape *object = (wxShape *)current->Data();
if (!object->GetParent())
{
object->Draw(* dc); // Draw the shape onto our printing dc
}
current = current->Next(); // Procede to the next shape in the list
}
}
dc->EndDrawing(); // Allows optimization of drawing code under MS Windows.
}
void DiagramView::OnUpdate(wxView *sender, wxObject *hint)
@@ -167,6 +238,7 @@ void DiagramView::OnEditLabel(wxCommandEvent& event)
}
}
/*
* Window implementations
*/