X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c78e7c70271608b076b1dbed201b1204e6898d4..124e17387cb8773949bc287e181594b6b2bbb07d:/src/qt/window.cpp diff --git a/src/qt/window.cpp b/src/qt/window.cpp index b2d90fbb12..603f29994f 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -1,610 +1,709 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: window.cpp -// Purpose: -// Author: Robert Roebling -// Created: 01/02/97 -// Id: -// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Name: windows.cpp +// Purpose: wxWindow +// Author: AUTHOR +// Modified by: +// Created: ??/??/98 +// RCS-ID: $Id$ +// Copyright: (c) AUTHOR +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - #ifdef __GNUG__ #pragma implementation "window.h" #endif -#include "wx/defs.h" -#include "wx/window.h" +#include "wx/setup.h" +#include "wx/menu.h" #include "wx/dc.h" -#include "wx/frame.h" +#include "wx/dcclient.h" +#include "wx/utils.h" #include "wx/app.h" +#include "wx/panel.h" #include "wx/layout.h" -#include "wx/utils.h" #include "wx/dialog.h" +#include "wx/listbox.h" +#include "wx/button.h" +#include "wx/settings.h" #include "wx/msgdlg.h" -#include "wx/dcclient.h" + +#include "wx/menuitem.h" +#include "wx/log.h" + +#if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" -#include "wx/mdi.h" -#include "wx/notebook.h" -#include "wx/statusbr.h" -#include +#endif -//----------------------------------------------------------------------------- -// data -//----------------------------------------------------------------------------- +#include extern wxList wxPendingDelete; -extern wxList wxTopLevelWindows; -//----------------------------------------------------------------------------- -// wxWindow implementation -//----------------------------------------------------------------------------- - -IMPLEMENT_DYNAMIC_CLASS(wxWindow,wxEvtHandler) +#if !USE_SHARED_LIBRARY +IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) - EVT_SIZE(wxWindow::OnSize) + EVT_CHAR(wxWindow::OnChar) + EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) END_EVENT_TABLE() +#endif + + +// Constructor wxWindow::wxWindow() { - m_parent = NULL; - m_children.DeleteContents( FALSE ); - m_x = 0; - m_y = 0; - m_width = 0; - m_height = 0; - m_retCode = 0; - m_eventHandler = this; - m_windowValidator = NULL; - m_windowId = -1; - m_cursor = new wxCursor( wxCURSOR_ARROW ); - m_font = *wxSWISS_FONT; - m_windowStyle = 0; - m_windowName = "noname"; - m_constraints = NULL; - m_constraintsInvolvedIn = NULL; - m_windowSizer = NULL; - m_sizerParent = NULL; - m_autoLayout = FALSE; - m_pDropTarget = NULL; -}; - -wxWindow::wxWindow( wxWindow *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, - long style, const wxString &name ) -{ - Create( parent, id, pos, size, style, name ); -}; - -bool wxWindow::Create( wxWindow *parent, wxWindowID id, - const wxPoint &pos, const wxSize &size, - long style, const wxString &name ) -{ - return TRUE; -}; - -wxWindow::~wxWindow(void) -{ - DestroyChildren(); - -// delete m_cursor; - - DeleteRelatedConstraints(); - if (m_constraints) - { - // This removes any dangling pointers to this window - // in other windows' constraintsInvolvedIn lists. - UnsetConstraints(m_constraints); - delete m_constraints; + // Generic + m_windowId = 0; + m_windowStyle = 0; + m_windowParent = NULL; + m_windowEventHandler = this; + m_windowName = ""; + m_windowCursor = *wxSTANDARD_CURSOR; + m_children = new wxList; m_constraints = NULL; - } - if (m_windowSizer) - { - delete m_windowSizer; + m_constraintsInvolvedIn = NULL; m_windowSizer = NULL; - } - // If this is a child of a sizer, remove self from parent - if (m_sizerParent) - m_sizerParent->RemoveChild((wxWindow *)this); - - // Just in case the window has been Closed, but - // we're then deleting immediately: don't leave - // dangling pointers. - wxPendingDelete.DeleteObject(this); - - // Just in case we've loaded a top-level window via - // wxWindow::LoadNativeDialog but we weren't a dialog - // class - wxTopLevelWindows.DeleteObject(this); - -}; + m_sizerParent = NULL; + m_autoLayout = FALSE; + m_windowValidator = NULL; + m_defaultItem = NULL; + m_returnCode = 0; + m_caretWidth = 0; m_caretHeight = 0; + m_caretEnabled = FALSE; + m_caretShown = FALSE; + m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; + m_foregroundColour = *wxBLACK; + m_defaultForegroundColour = *wxBLACK ; + m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; + +#if wxUSE_DRAG_AND_DROP + m_pDropTarget = NULL; +#endif +} -bool wxWindow::Close( bool force ) +// Destructor +wxWindow::~wxWindow() { - wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); - event.SetEventObject(this); - event.SetForce(force); + // Have to delete constraints/sizer FIRST otherwise + // sizers may try to look at deleted windows as they + // delete themselves. +#if wxUSE_CONSTRAINTS + DeleteRelatedConstraints(); + if (m_constraints) + { + // This removes any dangling pointers to this window + // in other windows' constraintsInvolvedIn lists. + UnsetConstraints(m_constraints); + delete m_constraints; + m_constraints = NULL; + } + if (m_windowSizer) + { + delete m_windowSizer; + m_windowSizer = NULL; + } + // If this is a child of a sizer, remove self from parent + if (m_sizerParent) + m_sizerParent->RemoveChild((wxWindow *)this); +#endif - return GetEventHandler()->ProcessEvent(event); -}; + if (m_windowParent) + m_windowParent->RemoveChild(this); -bool wxWindow::Destroy(void) -{ - m_hasVMT = FALSE; - delete this; - return TRUE; -}; + DestroyChildren(); + + // TODO: destroy the window -bool wxWindow::DestroyChildren(void) + delete m_children; + m_children = NULL; + + // Just in case the window has been Closed, but + // we're then deleting immediately: don't leave + // dangling pointers. + wxPendingDelete.DeleteObject(this); + + if ( m_windowValidator ) + delete m_windowValidator; +} + +// Destroy the window (delayed, if a managed window) +bool wxWindow::Destroy() { - if (GetChildren()) - { - wxNode *node; - while ((node = GetChildren()->First()) != (wxNode *)NULL) - { - wxWindow *child; - if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) - { - delete child; - if (GetChildren()->Member(child)) delete node; - }; - }; - }; - return TRUE; -}; + delete this; + return TRUE; +} + +// Constructor +bool wxWindow::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) +{ + // Generic + m_windowId = 0; + m_windowStyle = 0; + m_windowParent = NULL; + m_windowEventHandler = this; + m_windowName = ""; + m_windowCursor = *wxSTANDARD_CURSOR; + m_constraints = NULL; + m_constraintsInvolvedIn = NULL; + m_windowSizer = NULL; + m_sizerParent = NULL; + m_autoLayout = FALSE; + m_windowValidator = NULL; + +#if wxUSE_DRAG_AND_DROP + m_pDropTarget = NULL; +#endif + + m_caretWidth = 0; m_caretHeight = 0; + m_caretEnabled = FALSE; + m_caretShown = FALSE; + m_minSizeX = -1; + m_minSizeY = -1; + m_maxSizeX = -1; + m_maxSizeY = -1; + m_defaultItem = NULL; + m_windowParent = NULL; + if (!parent) + return FALSE; + + if (parent) parent->AddChild(this); + + m_returnCode = 0; + + SetName(name); + + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ; + m_foregroundColour = *wxBLACK; + m_defaultForegroundColour = *wxBLACK ; + m_defaultBackgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ; + + m_windowStyle = style; -void wxWindow::PrepareDC( wxDC &WXUNUSED(dc) ) + if ( id == -1 ) + m_windowId = (int)NewControlId(); + else + m_windowId = id; + + // TODO: create the window + + return TRUE; +} + +void wxWindow::SetFocus() { - // are we to set fonts here ? -}; + // TODO +} -void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags ) +void wxWindow::Enable(bool enable) { - - int newX = x; - int newY = y; - int newW = width; - int newH = height; - - if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) - { - if (newX == -1) newX = m_x; - if (newY == -1) newY = m_y; - if (newW == -1) newW = m_width; - if (newH == -1) newH = m_height; - }; - - if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) - { - if (newW == -1) newW = 80; - }; - - if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) - { - if (newH == -1) newH = 26; - }; - - if ((m_x != newX) || (m_y != newY) || (!m_sizeSet)) - { - m_x = newX; - m_y = newY; - // - }; - if ((m_width != newW) || (m_height != newH) || (!m_sizeSet)) - { - m_width = newW; - m_height = newH; - // - }; - - wxSizeEvent event( wxSize(m_width,m_height), GetId() ); - event.SetEventObject( this ); - ProcessEvent( event ); -}; + // TODO +} -void wxWindow::SetSize( int width, int height ) +void wxWindow::CaptureMouse() { - SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); -}; + // TODO +} -void wxWindow::Move( int x, int y ) +void wxWindow::ReleaseMouse() { - SetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); -}; + // TODO +} -void wxWindow::GetSize( int *width, int *height ) const +// Push/pop event handler (i.e. allow a chain of event handlers +// be searched) +void wxWindow::PushEventHandler(wxEvtHandler *handler) { - if (width) (*width) = m_width; - if (height) (*height) = m_height; -}; + handler->SetNextHandler(GetEventHandler()); + SetEventHandler(handler); +} -void wxWindow::SetClientSize( int width, int height ) +wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler) +{ + if ( GetEventHandler() ) + { + wxEvtHandler *handlerA = GetEventHandler(); + wxEvtHandler *handlerB = handlerA->GetNextHandler(); + handlerA->SetNextHandler(NULL); + SetEventHandler(handlerB); + if ( deleteHandler ) + { + delete handlerA; + return NULL; + } + else + return handlerA; + } + else + return NULL; +} + +#if wxUSE_DRAG_AND_DROP + +void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) { -}; + if ( m_pDropTarget != 0 ) { + m_pDropTarget->Revoke(m_hWnd); + delete m_pDropTarget; + } -void wxWindow::GetClientSize( int *width, int *height ) const + m_pDropTarget = pDropTarget; + if ( m_pDropTarget != 0 ) + m_pDropTarget->Register(m_hWnd); +} + +#endif + +// Old style file-manager drag&drop +void wxWindow::DragAcceptFiles(bool accept) { -}; + // TODO +} -void wxWindow::GetPosition( int *x, int *y ) const +// Get total size +void wxWindow::GetSize(int *x, int *y) const { - if (x) (*x) = m_x; - if (y) (*y) = m_y; -}; + // TODO +} -void wxWindow::ClientToScreen( int *x, int *y ) +void wxWindow::GetPosition(int *x, int *y) const { -}; + // TODO +} -void wxWindow::ScreenToClient( int *x, int *y ) +void wxWindow::ScreenToClient(int *x, int *y) const { -}; + // TODO +} -void wxWindow::Centre( int direction ) +void wxWindow::ClientToScreen(int *x, int *y) const { -}; + // TODO +} -void wxWindow::Fit(void) +void wxWindow::SetCursor(const wxCursor& cursor) { - int maxX = 0; - int maxY = 0; - wxNode *node = GetChildren()->First(); - while ( node ) + m_windowCursor = cursor; + if (m_windowCursor.Ok()) { - wxWindow *win = (wxWindow *)node->Data(); - int wx, wy, ww, wh; - win->GetPosition(&wx, &wy); - win->GetSize(&ww, &wh); - if ( wx + ww > maxX ) - maxX = wx + ww; - if ( wy + wh > maxY ) - maxY = wy + wh; - - node = node->Next(); + // TODO } - SetClientSize(maxX + 5, maxY + 10); -}; +} -void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) ) -{ - //if (GetAutoLayout()) Layout(); -}; -bool wxWindow::Show( bool show ) +// Get size *available for subwindows* i.e. excluding menu bar etc. +void wxWindow::GetClientSize(int *x, int *y) const { - return TRUE; -}; + // TODO +} -void wxWindow::Enable( bool enable ) +void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags) { - m_isEnabled = enable; -}; + // TODO +} -void wxWindow::MakeModal( bool modal ) +void wxWindow::SetClientSize(int width, int height) { + // TODO } -void wxWindow::SetFocus(void) +// For implementation purposes - sometimes decorations make the client area +// smaller +wxPoint wxWindow::GetClientAreaOrigin() const { -}; + return wxPoint(0, 0); +} -bool wxWindow::OnClose(void) +// Makes an adjustment to the window position (for example, a frame that has +// a toolbar that it manages itself). +void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) { - return TRUE; -}; + if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent()) + { + wxPoint pt(GetParent()->GetClientAreaOrigin()); + x += pt.x; y += pt.y; + } +} -void wxWindow::AddChild( wxWindow *child ) +bool wxWindow::Show(bool show) { -}; + // TODO + return FALSE; +} -wxList *wxWindow::GetChildren(void) +bool wxWindow::IsShown() const { - return (&m_children); -}; + // TODO + return FALSE; +} -void wxWindow::RemoveChild( wxWindow *child ) +int wxWindow::GetCharHeight() const { - if (GetChildren()) - GetChildren()->DeleteObject( child ); - child->m_parent = NULL; -}; + // TODO + return 0; +} -void wxWindow::SetReturnCode( int retCode ) +int wxWindow::GetCharWidth() const { - m_retCode = retCode; -}; + // TODO + return 0; +} -int wxWindow::GetReturnCode(void) +void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, + int *descent, int *externalLeading, const wxFont *theFont, bool) const { - return m_retCode; -}; + wxFont *fontToUse = (wxFont *)theFont; + if (!fontToUse) + fontToUse = (wxFont *) & m_windowFont; -wxWindow *wxWindow::GetParent(void) -{ - return m_parent; -}; + // TODO +} -wxEvtHandler *wxWindow::GetEventHandler(void) +void wxWindow::Refresh(bool eraseBack, const wxRectangle *rect) { - return m_eventHandler; -}; + // TODO +} -void wxWindow::SetEventhandler( wxEvtHandler *handler ) +// Responds to colour changes: passes event on to children. +void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) { - m_eventHandler = handler; -}; + wxNode *node = GetChildren()->First(); + while ( node ) + { + // Only propagate to non-top-level windows + wxWindow *win = (wxWindow *)node->Data(); + if ( win->GetParent() ) + { + wxSysColourChangedEvent event2; + event.m_eventObject = win; + win->GetEventHandler()->ProcessEvent(event2); + } -wxValidator *wxWindow::GetValidator(void) -{ - return m_windowValidator; -}; + node = node->Next(); + } +} -void wxWindow::SetValidator( wxValidator *validator ) +// This can be called by the app (or wxWindows) to do default processing for the current +// event. Save message/event info in wxWindow so they can be used in this function. +long wxWindow::Default() { - m_windowValidator = validator; -}; + // TODO + return 0; +} -bool wxWindow::IsBeingDeleted(void) +void wxWindow::InitDialog() { - return FALSE; -}; + wxInitDialogEvent event(GetId()); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); +} -void wxWindow::SetId( wxWindowID id ) +// Default init dialog behaviour is to transfer data to window +void wxWindow::OnInitDialog(wxInitDialogEvent& event) { - m_windowId = id; -}; + TransferDataToWindow(); +} -wxWindowID wxWindow::GetId(void) +// Caret manipulation +void wxWindow::CreateCaret(int w, int h) { - return m_windowId; -}; + m_caretWidth = w; + m_caretHeight = h; + m_caretEnabled = TRUE; +} -void wxWindow::SetCursor( const wxCursor &cursor ) +void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap)) { - if (*m_cursor == cursor) return; - (*m_cursor) = cursor; -}; + // TODO +} -void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) +void wxWindow::ShowCaret(bool show) { -}; + // TODO +} -bool wxWindow::IsExposed( long x, long y ) +void wxWindow::DestroyCaret() { - return (m_updateRegion.Contains( x, y ) != wxOutRegion ); -}; + // TODO + m_caretEnabled = FALSE; +} -bool wxWindow::IsExposed( long x, long y, long width, long height ) +void wxWindow::SetCaretPos(int x, int y) { - return (m_updateRegion.Contains( x, y, width, height ) != wxOutRegion ); -}; + // TODO +} -void wxWindow::Clear(void) +void wxWindow::GetCaretPos(int *x, int *y) const { -}; + // TODO +} -wxColour wxWindow::GetBackgroundColour(void) const +wxWindow *wxGetActiveWindow() { - return m_backgroundColour; -}; + // TODO + return NULL; +} -void wxWindow::SetBackgroundColour( const wxColour &colour ) +void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH)) { - m_backgroundColour = colour; -}; + m_minSizeX = minW; + m_minSizeY = minH; + m_maxSizeX = maxW; + m_maxSizeY = maxH; +} -bool wxWindow::Validate(void) +void wxWindow::Centre(int direction) { - wxNode *node = GetChildren()->First(); - while (node) - { - wxWindow *child = (wxWindow *)node->Data(); - if (child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this)) - { return FALSE; } - node = node->Next(); - }; - return TRUE; -}; + int x, y, width, height, panel_width, panel_height, new_x, new_y; -bool wxWindow::TransferDataToWindow(void) -{ - wxNode *node = GetChildren()->First(); - while (node) - { - wxWindow *child = (wxWindow *)node->Data(); - if (child->GetValidator() && /* child->GetValidator()->Ok() && */ - !child->GetValidator()->TransferToWindow() ) - { - wxMessageBox( "Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION ); - return FALSE; - }; - node = node->Next(); - }; - return TRUE; -}; + wxWindow *father = (wxWindow *)GetParent(); + if (!father) + return; -bool wxWindow::TransferDataFromWindow(void) -{ - wxNode *node = GetChildren()->First(); - while (node) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() ) - { return FALSE; } - node = node->Next(); - } - return TRUE; -}; + father->GetClientSize(&panel_width, &panel_height); + GetSize(&width, &height); + GetPosition(&x, &y); -void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) ) -{ - TransferDataToWindow(); -}; + new_x = -1; + new_y = -1; -void wxWindow::InitDialog(void) -{ - wxInitDialogEvent event(GetId()); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); -}; + if (direction & wxHORIZONTAL) + new_x = (int)((panel_width - width)/2); -void wxWindow::SetDropTarget( wxDropTarget *dropTarget ) -{ - if (m_pDropTarget) - { - m_pDropTarget->UnregisterWidget( dnd_widget ); - delete m_pDropTarget; - }; - m_pDropTarget = dropTarget; - if (m_pDropTarget) - { - }; -}; + if (direction & wxVERTICAL) + new_y = (int)((panel_height - height)/2); -wxDropTarget *wxWindow::GetDropTarget() const -{ - return m_pDropTarget; -}; + SetSize(new_x, new_y, -1, -1); -void wxWindow::SetFont( const wxFont &font ) -{ - m_font = font; -/* - ... -*/ -}; +} -wxFont *wxWindow::GetFont(void) +// Coordinates relative to the window +void wxWindow::WarpPointer (int x_pos, int y_pos) { - return &m_font; -}; + // TODO +} -void wxWindow::SetWindowStyleFlag( long flag ) +void wxWindow::OnEraseBackground(wxEraseEvent& event) { - m_windowStyle = flag; -}; + // TODO + Default(); +} -long wxWindow::GetWindowStyleFlag(void) const +int wxWindow::GetScrollPos(int orient) const { - return m_windowStyle; -}; + // TODO + return 0; +} -void wxWindow::CaptureMouse(void) +// This now returns the whole range, not just the number +// of positions that we can scroll. +int wxWindow::GetScrollRange(int orient) const { -}; + // TODO + return 0; +} -void wxWindow::ReleaseMouse(void) +int wxWindow::GetScrollThumb(int orient) const { -}; + // TODO + return 0; +} -void wxWindow::SetTitle( const wxString &WXUNUSED(title) ) +void wxWindow::SetScrollPos(int orient, int pos, bool refresh) { -}; + // TODO + return 0; +} -wxString wxWindow::GetTitle(void) const +// New function that will replace some of the above. +void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, + int range, bool refresh) { - return (wxString&)m_windowName; -}; + // TODO +} -wxString wxWindow::GetLabel(void) const +// Does a physical scroll +void wxWindow::ScrollWindow(int dx, int dy, const wxRectangle *rect) { - return GetTitle(); -}; + // TODO + return 0; +} -void wxWindow::SetName( const wxString &name ) +void wxWindow::SetFont(const wxFont& font) { - m_windowName = name; -}; + m_windowFont = font; -wxString wxWindow::GetName(void) const -{ - return (wxString&)m_windowName; -}; + if (!m_windowFont.Ok()) + return; + // TODO +} -bool wxWindow::IsShown(void) const +void wxWindow::OnChar(wxKeyEvent& event) { - return m_isShown; -}; + if ( event.KeyCode() == WXK_TAB ) { + // propagate the TABs to the parent - it's up to it to decide what + // to do with it + if ( GetParent() ) { + if ( GetParent()->ProcessEvent(event) ) + return; + } + } +} -bool wxWindow::IsRetained(void) +void wxWindow::OnPaint(wxPaintEvent& event) { - return FALSE; -}; + Default(); +} -wxWindow *wxWindow::FindWindow( long id ) +bool wxWindow::IsEnabled() const { - if (id == m_windowId) return this; - wxNode *node = m_children.First(); - while (node) - { - wxWindow *child = (wxWindow*)node->Data(); - wxWindow *res = child->FindWindow( id ); - if (res) return res; - node = node->Next(); - }; - return NULL; -}; + // TODO + return FALSE; +} -wxWindow *wxWindow::FindWindow( const wxString& name ) -{ - if (name == m_windowName) return this; - wxNode *node = m_children.First(); - while (node) - { - wxWindow *child = (wxWindow*)node->Data(); - wxWindow *res = child->FindWindow( name ); - if (res) return res; - node = node->Next(); - }; - return NULL; -}; +// Dialog support: override these and call +// base class members to add functionality +// that can't be done using validators. +// NOTE: these functions assume that controls +// are direct children of this window, not grandchildren +// or other levels of descendant. + +// Transfer values to controls. If returns FALSE, +// it's an application error (pops up a dialog) +bool wxWindow::TransferDataToWindow() +{ + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *child = (wxWindow *)node->Data(); + if ( child->GetValidator() && + !child->GetValidator()->TransferToWindow() ) + { + wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION); + return FALSE; + } + + node = node->Next(); + } + return TRUE; +} -void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible, - int range, bool WXUNUSED(refresh) ) +// Transfer values from controls. If returns FALSE, +// validation failed: don't quit +bool wxWindow::TransferDataFromWindow() +{ + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *child = (wxWindow *)node->Data(); + if ( child->GetValidator() && !child->GetValidator()->TransferFromWindow() ) + { + return FALSE; + } + + node = node->Next(); + } + return TRUE; +} + +bool wxWindow::Validate() { -}; + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *child = (wxWindow *)node->Data(); + if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) ) + { + return FALSE; + } -void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) ) + node = node->Next(); + } + return TRUE; +} + +// Get the window with the focus +wxWindow *wxWindow::FindFocus() { -}; + // TODO + return NULL; +} -int wxWindow::GetScrollThumb( int orient ) const +void wxWindow::AddChild(wxWindow *child) { -}; + GetChildren()->Append(child); + child->m_windowParent = this; +} -int wxWindow::GetScrollPos( int orient ) const +void wxWindow::RemoveChild(wxWindow *child) { -}; + if (GetChildren()) + GetChildren()->DeleteObject(child); + child->m_windowParent = NULL; +} -int wxWindow::GetScrollRange( int orient ) const +void wxWindow::DestroyChildren() { -}; + if (GetChildren()) { + wxNode *node; + while ((node = GetChildren()->First()) != (wxNode *)NULL) { + wxWindow *child; + if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) { + delete child; + if ( GetChildren()->Member(child) ) + delete node; + } + } /* while */ + } +} -void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) ) +void wxWindow::MakeModal(bool modal) { -}; + // Disable all other windows + if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame))) + { + wxNode *node = wxTopLevelWindows.First(); + while (node) + { + wxWindow *win = (wxWindow *)node->Data(); + if (win != this) + win->Enable(!modal); -//------------------------------------------------------------------------------------- -// Layout -//------------------------------------------------------------------------------------- + node = node->Next(); + } + } +} -wxLayoutConstraints *wxWindow::GetConstraints(void) const +// If nothing defined for this, try the parent. +// E.g. we may be a button loaded from a resource, with no callback function +// defined. +void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event) { - return m_constraints; -}; + if (GetEventHandler()->ProcessEvent(event) ) + return; + if (m_windowParent) + m_windowParent->GetEventHandler()->OnCommand(win, event); +} -void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) +void wxWindow::SetConstraints(wxLayoutConstraints *c) { if (m_constraints) { UnsetConstraints(m_constraints); delete m_constraints; } - m_constraints = constraints; + m_constraints = c; if (m_constraints) { // Make sure other windows know they're part of a 'meaningful relationship' @@ -625,34 +724,7 @@ void wxWindow::SetConstraints( wxLayoutConstraints *constraints ) if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this)) m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this); } -; } -; - -void wxWindow::SetAutoLayout( bool autoLayout ) -{ - m_autoLayout = autoLayout; -}; - -bool wxWindow::GetAutoLayout(void) const -{ - return m_autoLayout; -}; - -wxSizer *wxWindow::GetSizer(void) const -{ - return m_windowSizer; -}; - -void wxWindow::SetSizerParent( wxWindow *win ) -{ - m_sizerParent = win; -}; - -wxWindow *wxWindow::GetSizerParent(void) const -{ - return m_sizerParent; -}; // This removes any dangling pointers to this window // in other windows' constraintsInvolvedIn lists. @@ -697,7 +769,7 @@ void wxWindow::RemoveConstraintReference(wxWindow *otherWin) } // Reset any constraints that mention this window -void wxWindow::DeleteRelatedConstraints(void) +void wxWindow::DeleteRelatedConstraints() { if (m_constraintsInvolvedIn) { @@ -739,7 +811,7 @@ void wxWindow::SetSizer(wxSizer *sizer) * New version */ -bool wxWindow::Layout(void) +bool wxWindow::Layout() { if (GetConstraints()) { @@ -839,7 +911,7 @@ bool wxWindow::DoPhase(int phase) return TRUE; } -void wxWindow::ResetConstraints(void) +void wxWindow::ResetConstraints() { wxLayoutConstraints *constr = GetConstraints(); if (constr) @@ -894,10 +966,10 @@ void wxWindow::SetConstraintSizes(bool recurse) char *windowClass = this->GetClassInfo()->GetClassName(); wxString winName; - if (GetName() == "") - winName = "unnamed"; - else - winName = GetName(); + if (GetName() == "") + winName = "unnamed"; + else + winName = GetName(); wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName); if (!constr->left.GetDone()) wxDebugMsg(" unsatisfied 'left' constraint.\n"); @@ -928,7 +1000,7 @@ void wxWindow::SetConstraintSizes(bool recurse) void wxWindow::TransformSizerToActual(int *x, int *y) const { if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) || - m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) + m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) ) return; int xp, yp; @@ -940,16 +1012,16 @@ void wxWindow::TransformSizerToActual(int *x, int *y) const void wxWindow::SizerSetSize(int x, int y, int w, int h) { - int xx = x; - int yy = y; + int xx = x; + int yy = y; TransformSizerToActual(&xx, &yy); SetSize(xx, yy, w, h); } void wxWindow::SizerMove(int x, int y) { - int xx = x; - int yy = y; + int xx = x; + int yy = y; TransformSizerToActual(&xx, &yy); Move(xx, yy); } @@ -1037,12 +1109,173 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const GetPosition(x, y); } +bool wxWindow::Close(bool force) +{ + wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId); + event.SetEventObject(this); + event.SetForce(force); + + return GetEventHandler()->ProcessEvent(event); +} + +wxObject* wxWindow::GetChild(int number) const +{ + // Return a pointer to the Nth object in the window + if (!GetChildren()) + return(NULL) ; + wxNode *node = GetChildren()->First(); + int n = number; + while (node && n--) + node = node->Next() ; + if (node) + { + wxObject *obj = (wxObject *)node->Data(); + return(obj) ; + } + else + return NULL ; +} + +void wxWindow::OnDefaultAction(wxControl *initiatingItem) +{ + // Obsolete function +} + +void wxWindow::Clear() +{ + wxClientDC dc(this); + wxBrush brush(GetBackgroundColour(), wxSOLID); + dc.SetBackground(brush); + dc.Clear(); +} + +// Fits the panel around the items +void wxWindow::Fit() +{ + int maxX = 0; + int maxY = 0; + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *win = (wxWindow *)node->Data(); + int wx, wy, ww, wh; + win->GetPosition(&wx, &wy); + win->GetSize(&ww, &wh); + if ( wx + ww > maxX ) + maxX = wx + ww; + if ( wy + wh > maxY ) + maxY = wy + wh; + + node = node->Next(); + } + SetClientSize(maxX + 5, maxY + 5); +} + +void wxWindow::SetValidator(const wxValidator& validator) +{ + if ( m_windowValidator ) + delete m_windowValidator; + m_windowValidator = validator.Clone(); + + if ( m_windowValidator ) + m_windowValidator->SetWindow(this) ; +} + +// Find a window by id or name +wxWindow *wxWindow::FindWindow(long id) +{ + if ( GetId() == id) + return this; + + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *child = (wxWindow *)node->Data(); + wxWindow *found = child->FindWindow(id); + if ( found ) + return found; + node = node->Next(); + } + return NULL; +} + +wxWindow *wxWindow::FindWindow(const wxString& name) +{ + if ( GetName() == name) + return this; + + wxNode *node = GetChildren()->First(); + while ( node ) + { + wxWindow *child = (wxWindow *)node->Data(); + wxWindow *found = child->FindWindow(name); + if ( found ) + return found; + node = node->Next(); + } + return NULL; +} + +void wxWindow::OnIdle(wxIdleEvent& event) +{ +/* TODO: you may need to do something like this + * if your GUI doesn't generate enter/leave events + + // Check if we need to send a LEAVE event + if (m_mouseInWindow) + { + POINT pt; + ::GetCursorPos(&pt); + if (::WindowFromPoint(pt) != (HWND) GetHWND()) + { + // Generate a LEAVE event + m_mouseInWindow = FALSE; + MSWOnMouseLeave(pt.x, pt.y, 0); + } + } +*/ + + // This calls the UI-update mechanism (querying windows for + // menu/toolbar/control state information) + UpdateWindowUI(); +} + +// Raise the window to the top of the Z order +void wxWindow::Raise() +{ + // TODO +} + +// Lower the window to the bottom of the Z order +void wxWindow::Lower() +{ + // TODO +} + bool wxWindow::AcceptsFocus() const { - return IsEnabled() && IsShown(); + return IsShown() && IsEnabled(); +} + +// Update region access +wxRegion wxWindow::GetUpdateRegion() const +{ + return m_updateRegion; } -void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) ) +bool wxWindow::IsExposed(int x, int y, int w, int h) const { - UpdateWindowUI(); + return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion); } + +bool wxWindow::IsExposed(const wxPoint& pt) const +{ + return (m_updateRegion.Contains(pt) != wxOutRegion); +} + +bool wxWindow::IsExposed(const wxRect& rect) const +{ + return (m_updateRegion.Contains(rect) != wxOutRegion); +} + +