wxFrameBase class for wxMSW and wxGTK

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4595 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-16 21:31:40 +00:00
parent 40779a03e7
commit 7c0ea335c7
22 changed files with 1153 additions and 1120 deletions

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: framecmn.cpp
// Name: common/framecmn.cpp
// Purpose: common (for all platforms) wxFrame functions
// Author: Julian Smart, Vadim Zeitlin
// Created: 01/02/97
@@ -8,28 +8,369 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "framebase.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#pragma hdrstop
#endif
#include "wx/frame.h"
#include "wx/menu.h"
#include "wx/menuitem.h"
#include "wx/dcclient.h"
void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) )
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#endif
#if wxUSE_STATUSBAR
#include "wx/statusbr.h"
#endif
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxFrameBase, wxWindow)
EVT_IDLE(wxFrameBase::OnIdle)
EVT_CLOSE(wxFrameBase::OnCloseWindow)
EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
EVT_SIZE(wxFrameBase::OnSize)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// construction/destruction
// ----------------------------------------------------------------------------
wxFrameBase::wxFrameBase()
{
m_frameMenuBar = NULL;
#if wxUSE_TOOLBAR
m_frameToolBar = NULL;
#endif // wxUSE_TOOLBAR
#if wxUSE_STATUSBAR
m_frameStatusBar = NULL;
#endif // wxUSE_STATUSBAR
}
bool wxFrameBase::Destroy()
{
// delayed destruction: the frame will be deleted during the next idle
// loop iteration
if ( !wxPendingDelete.Member(this) )
wxPendingDelete.Append(this);
return TRUE;
}
wxFrame *wxFrameBase::New(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
return new wxFrame(parent, id, title, pos, size, style, name);
}
void wxFrameBase::DeleteAllBars()
{
if ( m_frameMenuBar )
{
delete m_frameMenuBar;
m_frameMenuBar = (wxMenuBar *) NULL;
}
#if wxUSE_STATUSBAR
if ( m_frameStatusBar )
{
delete m_frameStatusBar;
m_frameStatusBar = (wxStatusBar *) NULL;
}
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
if ( m_frameToolBar )
{
delete m_frameToolBar;
m_frameToolBar = (wxToolBar *) NULL;
}
#endif // wxUSE_TOOLBAR
}
// ----------------------------------------------------------------------------
// misc
// ----------------------------------------------------------------------------
// make the window modal (all other windows unresponsive)
void wxFrameBase::MakeModal(bool modal)
{
if ( modal )
{
wxEnableTopLevelWindows(FALSE);
Enable(TRUE); // keep this window enabled
}
else
{
wxEnableTopLevelWindows(TRUE);
}
}
bool wxFrameBase::ProcessCommand(int id)
{
wxMenuBar *bar = GetMenuBar();
if ( !bar )
return FALSE;
wxMenuItem *item = bar->FindItem(id);
if ( item && item->IsCheckable() )
{
item->Toggle();
}
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
commandEvent.SetInt(id);
commandEvent.SetEventObject(this);
return GetEventHandler()->ProcessEvent(commandEvent);
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
// default resizing behaviour - if only ONE subwindow, resize to fill the
// whole client area
void wxFrameBase::OnSize(wxSizeEvent& event)
{
// if we're using constraints - do use them
#if wxUSE_CONSTRAINTS
if ( GetAutoLayout() )
{
Layout();
}
else
#endif
{
// do we have _exactly_ one child?
wxWindow *child = (wxWindow *)NULL;
for ( wxWindowList::Node *node = GetChildren().GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
// exclude top level and managed windows (status bar isn't
// currently in the children list except under wxMac anyhow, but
// it makes no harm to test for it)
if ( !win->IsTopLevel()
#if wxUSE_STATUSBAR
&& (win != GetStatusBar())
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
&& (win != GetToolBar())
#endif // wxUSE_TOOLBAR
)
{
if ( child )
{
return; // it's our second subwindow - nothing to do
}
child = win;
}
}
// do we have any children at all?
if ( child )
{
// exactly one child - set it's size to fill the whole frame
int clientW, clientH;
DoGetClientSize(&clientW, &clientH);
// for whatever reasons, wxGTK wants to have a small offset - it
// probably looks better with it?
#ifdef __WXGTK__
static const int ofs = 0;
#else
static const int ofs = 1;
#endif
child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
}
}
}
// The default implementation for the close window event.
void wxFrameBase::OnCloseWindow(wxCloseEvent& event)
{
Destroy();
}
void wxFrameBase::OnMenuHighlight(wxMenuEvent& event)
{
#if wxUSE_STATUSBAR
if ( GetStatusBar() )
{
// if no help string found, we will clear the status bar text
wxString helpString;
int menuId = event.GetMenuId();
if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ )
{
wxMenuBar *menuBar = GetMenuBar();
if ( menuBar )
{
// it's ok if we don't find the item because it might belong
// to the popup menu
wxMenuItem *item = menuBar->FindItem(menuId);
if ( item )
helpString = item->GetHelp();
}
}
// set status text even if the string is empty - this will at least
// remove the string from the item which was previously selected
SetStatusText(helpString);
}
#endif // wxUSE_STATUSBAR
}
// ----------------------------------------------------------------------------
// status bar stuff
// ----------------------------------------------------------------------------
#if wxUSE_STATUSBAR
wxStatusBar* wxFrameBase::CreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
// the main status bar can only be created once (or else it should be
// deleted before calling CreateStatusBar() again)
wxCHECK_MSG( !m_frameStatusBar, (wxStatusBar *)NULL,
wxT("recreating status bar in wxFrame") );
m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
if ( m_frameStatusBar )
PositionStatusBar();
return m_frameStatusBar;
}
wxStatusBar *wxFrameBase::OnCreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
wxStatusBar *statusBar = new wxStatusBar(this, id,
wxPoint(0, 0), wxSize(100, 20),
style, name);
// Set the height according to the font and the border size
wxClientDC dc(statusBar);
dc.SetFont(statusBar->GetFont());
long y;
dc.GetTextExtent( "X", NULL, &y );
int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY());
statusBar->SetSize( -1, -1, 100, height );
statusBar->SetFieldsCount(number);
return statusBar;
}
void wxFrameBase::SetStatusText(const wxString& text, int number)
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
m_frameStatusBar->SetStatusText(text, number);
}
void wxFrameBase::SetStatusWidths(int n, const int widths_field[] )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
m_frameStatusBar->SetStatusWidths(n, widths_field);
PositionStatusBar();
}
#endif // wxUSE_STATUSBAR
// ----------------------------------------------------------------------------
// toolbar stuff
// ----------------------------------------------------------------------------
#if wxUSE_TOOLBAR
wxToolBar* wxFrameBase::CreateToolBar(long style,
wxWindowID id,
const wxString& name)
{
// the main toolbar can't be recreated (unless it was explicitly deeleted
// before)
wxCHECK_MSG( !m_frameToolBar, (wxToolBar *)NULL,
wxT("recreating toolbar in wxFrame") );
m_frameToolBar = OnCreateToolBar(style, id, name);
return m_frameToolBar;
}
wxToolBar* wxFrameBase::OnCreateToolBar(long style,
wxWindowID id,
const wxString& name)
{
return new wxToolBar(this, id,
wxDefaultPosition, wxDefaultSize,
style, name);
}
#endif // wxUSE_TOOLBAR
// ----------------------------------------------------------------------------
// Menu UI updating
// ----------------------------------------------------------------------------
void wxFrameBase::OnIdle(wxIdleEvent& WXUNUSED(event) )
{
DoMenuUpdates();
}
// update all menus
void wxFrame::DoMenuUpdates()
void wxFrameBase::DoMenuUpdates()
{
wxMenuBar* bar = GetMenuBar();
if ( bar != NULL )
if ( bar != NULL )
{
int nCount = bar->GetMenuCount();
for (int n = 0; n < nCount; n++)
@@ -38,32 +379,32 @@ void wxFrame::DoMenuUpdates()
}
// update a menu and all submenus recursively
void wxFrame::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin))
void wxFrameBase::DoMenuUpdates(wxMenu* menu, wxWindow* WXUNUSED(focusWin))
{
wxEvtHandler* evtHandler = GetEventHandler();
wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst();
while (node)
{
wxMenuItem* item = node->GetData();
if ( !item->IsSeparator() )
wxEvtHandler* evtHandler = GetEventHandler();
wxMenuItemList::Node* node = menu->GetMenuItems().GetFirst();
while (node)
{
wxWindowID id = item->GetId();
wxUpdateUIEvent event(id);
event.SetEventObject( this );
wxMenuItem* item = node->GetData();
if ( !item->IsSeparator() )
{
wxWindowID id = item->GetId();
wxUpdateUIEvent event(id);
event.SetEventObject( this );
if (evtHandler->ProcessEvent(event))
{
if (event.GetSetText())
menu->SetLabel(id, event.GetText());
if (event.GetSetChecked())
menu->Check(id, event.GetChecked());
if (event.GetSetEnabled())
menu->Enable(id, event.GetEnabled());
}
if (evtHandler->ProcessEvent(event))
{
if (event.GetSetText())
menu->SetLabel(id, event.GetText());
if (event.GetSetChecked())
menu->Check(id, event.GetChecked());
if (event.GetSetEnabled())
menu->Enable(id, event.GetEnabled());
}
if (item->GetSubMenu())
DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL);
if (item->GetSubMenu())
DoMenuUpdates(item->GetSubMenu(), (wxWindow*) NULL);
}
node = node->GetNext();
}
node = node->GetNext();
}
}

View File

@@ -2164,8 +2164,8 @@ void wxListMainWindow::CalculatePositions()
int y = 1;
int entireHeight = m_lines.Number() * lineSpacing + 2;
int scroll_pos = GetScrollPos( wxVERTICAL );
int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
#if wxUSE_GENERIC_LIST_EXTENSIONS
int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
#else
SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
#endif
@@ -2312,18 +2312,22 @@ void wxListMainWindow::DeleteAllItems( void )
{
m_dirty = TRUE;
m_current = (wxListLineData *) NULL;
// to make the deletion of all items faster, we don't send the
// notifications in this case: this is compatible with wxMSW and
// documented in DeleteAllItems() description
#if 0
wxNode *node = m_lines.First();
while (node)
{
wxListLineData *line = (wxListLineData*)node->Data();
// to make the deletion of all items faster, we don't send the
// notifications in this case: this is compatible with wxMSW and
// documented in DeleteAllItems() description
//DeleteLine( line );
DeleteLine( line );
node = node->Next();
}
#endif // 0
m_lines.Clear();
}

View File

@@ -7,6 +7,14 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "frame.h"
#endif
@@ -17,10 +25,10 @@
#include "wx/app.h"
#include "wx/menu.h"
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#include "wx/toolbar.h"
#endif
#if wxUSE_STATUSBAR
#include "wx/statusbr.h"
#include "wx/statusbr.h"
#endif
#include "wx/dcclient.h"
@@ -31,31 +39,37 @@
#include "gdk/gdkkeysyms.h"
#include "gdk/gdkx.h"
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
const int wxMENU_HEIGHT = 27;
const int wxSTATUS_HEIGHT = 25;
const int wxPLACE_HOLDER = 0;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
extern int g_openDialogs;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
// ----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
extern wxList wxPendingDelete;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// debug
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifdef __WXDEBUG__
@@ -63,6 +77,14 @@ extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// GTK callbacks
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// "focus" from m_window
//-----------------------------------------------------------------------------
@@ -190,9 +212,9 @@ gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *ev
if (g_isIdle)
wxapp_install_idle_handler();
if (!win->m_hasVMT)
if (!win->m_hasVMT)
return FALSE;
#if (GTK_MINOR_VERSION > 0)
int x = 0;
int y = 0;
@@ -280,10 +302,11 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
}
/* reset the icon */
if (win->m_icon != wxNullIcon)
wxIcon iconOld = win->GetIcon();
if ( iconOld != wxNullIcon )
{
wxIcon icon( win->m_icon );
win->m_icon = wxNullIcon;
wxIcon icon( iconOld );
win->SetIcon( wxNullIcon );
win->SetIcon( icon );
}
@@ -305,6 +328,10 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
return FALSE;
}
// ----------------------------------------------------------------------------
// wxFrame itself
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// InsertChild for wxFrame
//-----------------------------------------------------------------------------
@@ -361,28 +388,12 @@ static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
parent->UpdateSize();
}
//-----------------------------------------------------------------------------
// wxFrame
//-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_SIZE(wxFrame::OnSize)
EVT_IDLE(wxFrame::OnIdle)
EVT_CLOSE(wxFrame::OnCloseWindow)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
// ----------------------------------------------------------------------------
// wxFrame creation
// ----------------------------------------------------------------------------
void wxFrame::Init()
{
m_frameMenuBar = (wxMenuBar *) NULL;
#if wxUSE_STATUSBAR
m_frameStatusBar = (wxStatusBar *) NULL;
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
m_frameToolBar = (wxToolBar *) NULL;
#endif // wxUSE_TOOLBAR
m_sizeSet = FALSE;
m_miniEdge = 0;
m_miniTitle = 0;
@@ -393,18 +404,13 @@ void wxFrame::Init()
m_isFrame = TRUE;
}
wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
Init();
Create( parent, id, title, pos, size, style, name );
}
bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
bool wxFrame::Create( wxWindow *parent,
wxWindowID id,
const wxString &title,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name )
{
wxTopLevelWindows.Append( this );
@@ -490,18 +496,7 @@ wxFrame::~wxFrame()
{
m_isBeingDeleted = TRUE;
if (m_frameMenuBar) delete m_frameMenuBar;
m_frameMenuBar = (wxMenuBar *) NULL;
#if wxUSE_STATUSBAR
if (m_frameStatusBar) delete m_frameStatusBar;
m_frameStatusBar = (wxStatusBar *) NULL;
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
if (m_frameToolBar) delete m_frameToolBar;
m_frameToolBar = (wxToolBar *) NULL;
#endif // wxUSE_TOOLBAR
DeleteAllBars();
wxTopLevelWindows.DeleteObject( this );
@@ -512,6 +507,10 @@ wxFrame::~wxFrame()
wxTheApp->ExitMainLoop();
}
// ----------------------------------------------------------------------------
// overridden wxWindow methods
// ----------------------------------------------------------------------------
bool wxFrame::Show( bool show )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -529,15 +528,6 @@ bool wxFrame::Show( bool show )
return wxWindow::Show( show );
}
bool wxFrame::Destroy()
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this);
return TRUE;
}
void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -546,7 +536,8 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
/* avoid recursions */
if (m_resizing) return;
if (m_resizing)
return;
m_resizing = TRUE;
int old_x = m_x;
@@ -606,19 +597,6 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
m_resizing = FALSE;
}
void wxFrame::Centre( int direction )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
int x = 0;
int y = 0;
if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
Move( x, y );
}
void wxFrame::DoGetClientSize( int *width, int *height ) const
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -700,7 +678,8 @@ void wxFrame::DoSetClientSize( int width, int height )
DoSetSize( -1, -1, width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0 );
}
void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y),
int width, int height )
{
// due to a bug in gtk, x,y are always 0
// m_x = x;
@@ -810,15 +789,14 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
m_frameStatusBar->m_width = ww;
m_frameStatusBar->m_height = hh;
gtk_pizza_set_size( GTK_PIZZA(m_wxwindow),
m_frameStatusBar->m_widget,
xx, yy, ww, hh );
m_frameStatusBar->m_widget,
xx, yy, ww, hh );
}
#endif
/* we actually set the size of a frame here and no-where else */
gtk_widget_set_usize( m_widget, m_width, m_height );
m_sizeSet = TRUE;
// send size event to frame
@@ -868,50 +846,9 @@ void wxFrame::OnInternalIdle()
wxWindow::OnInternalIdle();
}
void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
{
Destroy();
}
void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
#if wxUSE_CONSTRAINTS
if (GetAutoLayout())
{
Layout();
}
else
#endif // wxUSE_CONSTRAINTS
{
/* do we have exactly one child? */
wxWindow *child = (wxWindow *)NULL;
for ( wxNode *node = GetChildren().First(); node; node = node->Next() )
{
wxWindow *win = (wxWindow *)node->Data();
if ( !wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) )
{
if (child)
{
/* it's the second one: do nothing */
return;
}
child = win;
}
}
/* no children at all? */
if (child)
{
/* yes: set it's size to fill all the frame */
int client_x, client_y;
DoGetClientSize( &client_x, &client_y );
child->SetSize( 1, 1, client_x-2, client_y-2 );
}
}
}
// ----------------------------------------------------------------------------
// menu/tool/status bar stuff
// ----------------------------------------------------------------------------
void wxFrame::SetMenuBar( wxMenuBar *menuBar )
{
@@ -951,50 +888,17 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
m_sizeSet = FALSE;
}
wxMenuBar *wxFrame::GetMenuBar() const
{
return m_frameMenuBar;
}
void wxFrame::OnMenuHighlight(wxMenuEvent& event)
{
#if wxUSE_STATUSBAR
if (GetStatusBar())
{
// if no help string found, we will clear the status bar text
wxString helpString;
int menuId = event.GetMenuId();
if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ )
{
wxMenuBar *menuBar = GetMenuBar();
if ( menuBar )
{
// it's ok if we don't find the item because it might belong to
// the popup menu
wxMenuItem *item = menuBar->FindItem(menuId);
if ( item )
helpString = item->GetHelp();
}
}
SetStatusText(helpString);
}
#endif // wxUSE_STATUSBAR
}
#if wxUSE_TOOLBAR
wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_MSG( m_frameToolBar == NULL, FALSE, wxT("recreating toolbar in wxFrame") );
m_insertInClientArea = FALSE;
m_frameToolBar = OnCreateToolBar( style, id, name );
m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name );
if (m_frameToolBar) GetChildren().DeleteObject( m_frameToolBar );
if (m_frameToolBar)
GetChildren().DeleteObject( m_frameToolBar );
m_insertInClientArea = TRUE;
@@ -1003,14 +907,10 @@ wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& na
return m_frameToolBar;
}
wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name )
{
return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name );
}
void wxFrame::SetToolBar(wxToolBar *toolbar)
{
m_frameToolBar = toolbar;
wxFrameBase::SetToolBar(toolbar);
if (m_frameToolBar)
{
/* insert into toolbar area if not already there */
@@ -1025,97 +925,34 @@ void wxFrame::SetToolBar(wxToolBar *toolbar)
}
}
wxToolBar *wxFrame::GetToolBar() const
{
return m_frameToolBar;
}
#endif // wxUSE_TOOLBAR
#if wxUSE_STATUSBAR
wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
wxStatusBar* wxFrame::CreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, wxT("recreating status bar in wxFrame") );
m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
// because it will change when toolbar is added
m_sizeSet = FALSE;
return m_frameStatusBar;
return wxFrameBase::CreateStatusBar( number, style, id, name );
}
wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
{
wxStatusBar *statusBar = (wxStatusBar *) NULL;
statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name);
// Set the height according to the font and the border size
wxClientDC dc(statusBar);
dc.SetFont( statusBar->GetFont() );
long x, y;
dc.GetTextExtent( "X", &x, &y );
int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
statusBar->SetSize( -1, -1, 100, height );
statusBar->SetFieldsCount( number );
return statusBar;
}
wxStatusBar *wxFrame::GetStatusBar() const
{
return m_frameStatusBar;
}
void wxFrame::SetStatusText(const wxString& text, int number)
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
m_frameStatusBar->SetStatusText(text, number);
}
void wxFrame::SetStatusWidths(int n, const int widths_field[] )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
m_frameStatusBar->SetStatusWidths(n, widths_field);
}
#endif // wxUSE_STATUSBAR
void wxFrame::Command( int id )
{
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
commandEvent.SetInt( id );
commandEvent.SetEventObject( this );
wxMenuBar *bar = GetMenuBar();
if (!bar) return;
wxMenuItem *item = bar->FindItem(id) ;
if (item && item->IsCheckable())
{
bar->Check(id, !bar->IsChecked(id)) ;
}
wxEvtHandler* evtHandler = GetEventHandler();
evtHandler->ProcessEvent(commandEvent);
}
// ----------------------------------------------------------------------------
// frame title/icon
// ----------------------------------------------------------------------------
void wxFrame::SetTitle( const wxString &title )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
m_title = title;
if (m_title.IsNull()) m_title = wxT("");
gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
}
@@ -1123,10 +960,13 @@ void wxFrame::SetIcon( const wxIcon &icon )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
m_icon = icon;
if (!icon.Ok()) return;
wxFrameBase::SetIcon(icon);
if (!m_widget->window) return;
if ( !m_icon.Ok() )
return;
if (!m_widget->window)
return;
wxMask *mask = icon.GetMask();
GdkBitmap *bm = (GdkBitmap *) NULL;
@@ -1135,10 +975,19 @@ void wxFrame::SetIcon( const wxIcon &icon )
gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
}
// ----------------------------------------------------------------------------
// frame state: maximized/iconized/normal (TODO)
// ----------------------------------------------------------------------------
void wxFrame::Maximize(bool WXUNUSED(maximize))
{
}
bool wxFrame::IsMaximized() const
{
return FALSE;
}
void wxFrame::Restore()
{
}

View File

@@ -185,7 +185,7 @@ extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll;
extern wxCursor g_globalCursor;
static wxWindow *g_captureWindow = (wxWindow*) NULL;
static wxWindow *g_focusWindow = (wxWindow*) NULL;
extern wxWindow *g_focusWindow = (wxWindow*) NULL;
// if we detect that the app has got/lost the focus, we set this variable to
// either TRUE or FALSE and an activate event will be sent during the next

View File

@@ -7,6 +7,14 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "frame.h"
#endif
@@ -17,10 +25,10 @@
#include "wx/app.h"
#include "wx/menu.h"
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#include "wx/toolbar.h"
#endif
#if wxUSE_STATUSBAR
#include "wx/statusbr.h"
#include "wx/statusbr.h"
#endif
#include "wx/dcclient.h"
@@ -31,31 +39,37 @@
#include "gdk/gdkkeysyms.h"
#include "gdk/gdkx.h"
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
const int wxMENU_HEIGHT = 27;
const int wxSTATUS_HEIGHT = 25;
const int wxPLACE_HOLDER = 0;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
extern int g_openDialogs;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
// ----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
extern wxList wxPendingDelete;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// debug
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifdef __WXDEBUG__
@@ -63,6 +77,14 @@ extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// GTK callbacks
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// "focus" from m_window
//-----------------------------------------------------------------------------
@@ -190,9 +212,9 @@ gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *ev
if (g_isIdle)
wxapp_install_idle_handler();
if (!win->m_hasVMT)
if (!win->m_hasVMT)
return FALSE;
#if (GTK_MINOR_VERSION > 0)
int x = 0;
int y = 0;
@@ -280,10 +302,11 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
}
/* reset the icon */
if (win->m_icon != wxNullIcon)
wxIcon iconOld = win->GetIcon();
if ( iconOld != wxNullIcon )
{
wxIcon icon( win->m_icon );
win->m_icon = wxNullIcon;
wxIcon icon( iconOld );
win->SetIcon( wxNullIcon );
win->SetIcon( icon );
}
@@ -305,6 +328,10 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
return FALSE;
}
// ----------------------------------------------------------------------------
// wxFrame itself
// ----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// InsertChild for wxFrame
//-----------------------------------------------------------------------------
@@ -361,28 +388,12 @@ static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
parent->UpdateSize();
}
//-----------------------------------------------------------------------------
// wxFrame
//-----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_SIZE(wxFrame::OnSize)
EVT_IDLE(wxFrame::OnIdle)
EVT_CLOSE(wxFrame::OnCloseWindow)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
// ----------------------------------------------------------------------------
// wxFrame creation
// ----------------------------------------------------------------------------
void wxFrame::Init()
{
m_frameMenuBar = (wxMenuBar *) NULL;
#if wxUSE_STATUSBAR
m_frameStatusBar = (wxStatusBar *) NULL;
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
m_frameToolBar = (wxToolBar *) NULL;
#endif // wxUSE_TOOLBAR
m_sizeSet = FALSE;
m_miniEdge = 0;
m_miniTitle = 0;
@@ -393,18 +404,13 @@ void wxFrame::Init()
m_isFrame = TRUE;
}
wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
Init();
Create( parent, id, title, pos, size, style, name );
}
bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
bool wxFrame::Create( wxWindow *parent,
wxWindowID id,
const wxString &title,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name )
{
wxTopLevelWindows.Append( this );
@@ -490,18 +496,7 @@ wxFrame::~wxFrame()
{
m_isBeingDeleted = TRUE;
if (m_frameMenuBar) delete m_frameMenuBar;
m_frameMenuBar = (wxMenuBar *) NULL;
#if wxUSE_STATUSBAR
if (m_frameStatusBar) delete m_frameStatusBar;
m_frameStatusBar = (wxStatusBar *) NULL;
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
if (m_frameToolBar) delete m_frameToolBar;
m_frameToolBar = (wxToolBar *) NULL;
#endif // wxUSE_TOOLBAR
DeleteAllBars();
wxTopLevelWindows.DeleteObject( this );
@@ -512,6 +507,10 @@ wxFrame::~wxFrame()
wxTheApp->ExitMainLoop();
}
// ----------------------------------------------------------------------------
// overridden wxWindow methods
// ----------------------------------------------------------------------------
bool wxFrame::Show( bool show )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -529,15 +528,6 @@ bool wxFrame::Show( bool show )
return wxWindow::Show( show );
}
bool wxFrame::Destroy()
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this);
return TRUE;
}
void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -546,7 +536,8 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
/* avoid recursions */
if (m_resizing) return;
if (m_resizing)
return;
m_resizing = TRUE;
int old_x = m_x;
@@ -606,19 +597,6 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
m_resizing = FALSE;
}
void wxFrame::Centre( int direction )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
int x = 0;
int y = 0;
if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
Move( x, y );
}
void wxFrame::DoGetClientSize( int *width, int *height ) const
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -700,7 +678,8 @@ void wxFrame::DoSetClientSize( int width, int height )
DoSetSize( -1, -1, width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0 );
}
void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y),
int width, int height )
{
// due to a bug in gtk, x,y are always 0
// m_x = x;
@@ -810,15 +789,14 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
m_frameStatusBar->m_width = ww;
m_frameStatusBar->m_height = hh;
gtk_pizza_set_size( GTK_PIZZA(m_wxwindow),
m_frameStatusBar->m_widget,
xx, yy, ww, hh );
m_frameStatusBar->m_widget,
xx, yy, ww, hh );
}
#endif
/* we actually set the size of a frame here and no-where else */
gtk_widget_set_usize( m_widget, m_width, m_height );
m_sizeSet = TRUE;
// send size event to frame
@@ -868,50 +846,9 @@ void wxFrame::OnInternalIdle()
wxWindow::OnInternalIdle();
}
void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
{
Destroy();
}
void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
#if wxUSE_CONSTRAINTS
if (GetAutoLayout())
{
Layout();
}
else
#endif // wxUSE_CONSTRAINTS
{
/* do we have exactly one child? */
wxWindow *child = (wxWindow *)NULL;
for ( wxNode *node = GetChildren().First(); node; node = node->Next() )
{
wxWindow *win = (wxWindow *)node->Data();
if ( !wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) )
{
if (child)
{
/* it's the second one: do nothing */
return;
}
child = win;
}
}
/* no children at all? */
if (child)
{
/* yes: set it's size to fill all the frame */
int client_x, client_y;
DoGetClientSize( &client_x, &client_y );
child->SetSize( 1, 1, client_x-2, client_y-2 );
}
}
}
// ----------------------------------------------------------------------------
// menu/tool/status bar stuff
// ----------------------------------------------------------------------------
void wxFrame::SetMenuBar( wxMenuBar *menuBar )
{
@@ -951,50 +888,17 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
m_sizeSet = FALSE;
}
wxMenuBar *wxFrame::GetMenuBar() const
{
return m_frameMenuBar;
}
void wxFrame::OnMenuHighlight(wxMenuEvent& event)
{
#if wxUSE_STATUSBAR
if (GetStatusBar())
{
// if no help string found, we will clear the status bar text
wxString helpString;
int menuId = event.GetMenuId();
if ( menuId != wxID_SEPARATOR && menuId != -2 /* wxID_TITLE */ )
{
wxMenuBar *menuBar = GetMenuBar();
if ( menuBar )
{
// it's ok if we don't find the item because it might belong to
// the popup menu
wxMenuItem *item = menuBar->FindItem(menuId);
if ( item )
helpString = item->GetHelp();
}
}
SetStatusText(helpString);
}
#endif // wxUSE_STATUSBAR
}
#if wxUSE_TOOLBAR
wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_MSG( m_frameToolBar == NULL, FALSE, wxT("recreating toolbar in wxFrame") );
m_insertInClientArea = FALSE;
m_frameToolBar = OnCreateToolBar( style, id, name );
m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name );
if (m_frameToolBar) GetChildren().DeleteObject( m_frameToolBar );
if (m_frameToolBar)
GetChildren().DeleteObject( m_frameToolBar );
m_insertInClientArea = TRUE;
@@ -1003,14 +907,10 @@ wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& na
return m_frameToolBar;
}
wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name )
{
return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name );
}
void wxFrame::SetToolBar(wxToolBar *toolbar)
{
m_frameToolBar = toolbar;
wxFrameBase::SetToolBar(toolbar);
if (m_frameToolBar)
{
/* insert into toolbar area if not already there */
@@ -1025,97 +925,34 @@ void wxFrame::SetToolBar(wxToolBar *toolbar)
}
}
wxToolBar *wxFrame::GetToolBar() const
{
return m_frameToolBar;
}
#endif // wxUSE_TOOLBAR
#if wxUSE_STATUSBAR
wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
wxStatusBar* wxFrame::CreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, wxT("recreating status bar in wxFrame") );
m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
// because it will change when toolbar is added
m_sizeSet = FALSE;
return m_frameStatusBar;
return wxFrameBase::CreateStatusBar( number, style, id, name );
}
wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
{
wxStatusBar *statusBar = (wxStatusBar *) NULL;
statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name);
// Set the height according to the font and the border size
wxClientDC dc(statusBar);
dc.SetFont( statusBar->GetFont() );
long x, y;
dc.GetTextExtent( "X", &x, &y );
int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
statusBar->SetSize( -1, -1, 100, height );
statusBar->SetFieldsCount( number );
return statusBar;
}
wxStatusBar *wxFrame::GetStatusBar() const
{
return m_frameStatusBar;
}
void wxFrame::SetStatusText(const wxString& text, int number)
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
m_frameStatusBar->SetStatusText(text, number);
}
void wxFrame::SetStatusWidths(int n, const int widths_field[] )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
m_frameStatusBar->SetStatusWidths(n, widths_field);
}
#endif // wxUSE_STATUSBAR
void wxFrame::Command( int id )
{
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
commandEvent.SetInt( id );
commandEvent.SetEventObject( this );
wxMenuBar *bar = GetMenuBar();
if (!bar) return;
wxMenuItem *item = bar->FindItem(id) ;
if (item && item->IsCheckable())
{
bar->Check(id, !bar->IsChecked(id)) ;
}
wxEvtHandler* evtHandler = GetEventHandler();
evtHandler->ProcessEvent(commandEvent);
}
// ----------------------------------------------------------------------------
// frame title/icon
// ----------------------------------------------------------------------------
void wxFrame::SetTitle( const wxString &title )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
m_title = title;
if (m_title.IsNull()) m_title = wxT("");
gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
}
@@ -1123,10 +960,13 @@ void wxFrame::SetIcon( const wxIcon &icon )
{
wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
m_icon = icon;
if (!icon.Ok()) return;
wxFrameBase::SetIcon(icon);
if (!m_widget->window) return;
if ( !m_icon.Ok() )
return;
if (!m_widget->window)
return;
wxMask *mask = icon.GetMask();
GdkBitmap *bm = (GdkBitmap *) NULL;
@@ -1135,10 +975,19 @@ void wxFrame::SetIcon( const wxIcon &icon )
gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
}
// ----------------------------------------------------------------------------
// frame state: maximized/iconized/normal (TODO)
// ----------------------------------------------------------------------------
void wxFrame::Maximize(bool WXUNUSED(maximize))
{
}
bool wxFrame::IsMaximized() const
{
return FALSE;
}
void wxFrame::Restore()
{
}

View File

@@ -185,7 +185,7 @@ extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll;
extern wxCursor g_globalCursor;
static wxWindow *g_captureWindow = (wxWindow*) NULL;
static wxWindow *g_focusWindow = (wxWindow*) NULL;
extern wxWindow *g_focusWindow = (wxWindow*) NULL;
// if we detect that the app has got/lost the focus, we set this variable to
// either TRUE or FALSE and an activate event will be sent during the next

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////
// Name: frame.cpp
// Name: msw/frame.cpp
// Purpose: wxFrame
// Author: Julian Smart
// Modified by:
@@ -9,8 +9,16 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "frame.h"
#pragma implementation "frame.h"
#endif
// For compilers that support precompilation, includes "wx.h".
@@ -32,69 +40,87 @@
#endif // WX_PRECOMP
#include "wx/msw/private.h"
#include "wx/statusbr.h"
#include "wx/toolbar.h"
#if wxUSE_STATUSBAR
#include "wx/statusbr.h"
#if wxUSE_NATIVE_STATUSBAR
#include "wx/msw/statbr95.h"
#endif
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#endif // wxUSE_TOOLBAR
#include "wx/menuitem.h"
#include "wx/log.h"
#if wxUSE_NATIVE_STATUSBAR
#include "wx/msw/statbr95.h"
#endif
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
extern wxWindowList wxModelessWindows;
extern wxList WXDLLEXPORT wxPendingDelete;
extern wxChar wxFrameClassName[];
extern wxMenu *wxCurrentPopupMenu;
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxFrame, wxWindow)
EVT_SIZE(wxFrame::OnSize)
EVT_ACTIVATE(wxFrame::OnActivate)
EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
EVT_IDLE(wxFrame::OnIdle)
EVT_CLOSE(wxFrame::OnCloseWindow)
BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
EVT_ACTIVATE(wxFrame::OnActivate)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
#endif
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// static class members
// ----------------------------------------------------------------------------
#if wxUSE_NATIVE_STATUSBAR
bool wxFrame::m_useNativeStatusBar = TRUE;
#else
bool wxFrame::m_useNativeStatusBar = FALSE;
#endif
wxFrame::wxFrame()
{
m_frameToolBar = NULL ;
m_frameMenuBar = NULL;
m_frameStatusBar = NULL;
// ----------------------------------------------------------------------------
// creation/destruction
// ----------------------------------------------------------------------------
m_iconized = FALSE;
}
bool wxFrame::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
void wxFrame::Init()
{
m_iconized = FALSE;
#if wxUSE_TOOLTIPS
m_hwndToolTip = 0;
#endif
}
bool wxFrame::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
SetName(name);
m_windowStyle = style;
m_frameMenuBar = NULL;
m_frameToolBar = NULL ;
m_frameToolBar = NULL;
m_frameStatusBar = NULL;
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
// m_icon = NULL;
if ( id > -1 )
m_windowId = id;
else
@@ -131,13 +157,7 @@ wxFrame::~wxFrame()
m_isBeingDeleted = TRUE;
wxTopLevelWindows.DeleteObject(this);
if (m_frameStatusBar)
delete m_frameStatusBar;
if (m_frameMenuBar)
delete m_frameMenuBar;
/* New behaviour March 1998: check if it's the last top-level window */
// if (wxTheApp && (this == wxTheApp->GetTopWindow()))
DeleteAllBars();
if (wxTheApp && (wxTopLevelWindows.Number() == 0))
{
@@ -167,12 +187,14 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
RECT rect;
::GetClientRect(GetHwnd(), &rect);
#if wxUSE_STATUSBAR
if ( GetStatusBar() )
{
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
rect.bottom -= statusY;
}
#endif // wxUSE_STATUSBAR
wxPoint pt(GetClientAreaOrigin());
rect.bottom -= pt.y;
@@ -202,12 +224,14 @@ void wxFrame::DoSetClientSize(int width, int height)
int actual_width = rect2.right - rect2.left - rect.right + width;
int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
#if wxUSE_STATUSBAR
if ( GetStatusBar() )
{
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
actual_height += statusY;
}
#endif // wxUSE_STATUSBAR
wxPoint pt(GetClientAreaOrigin());
actual_width += pt.y;
@@ -244,63 +268,56 @@ void wxFrame::DoGetPosition(int *x, int *y) const
*y = point.y;
}
// ----------------------------------------------------------------------------
// variations around ::ShowWindow()
// ----------------------------------------------------------------------------
void wxFrame::DoShowWindow(int nShowCmd)
{
::ShowWindow(GetHwnd(), nShowCmd);
m_iconized = nShowCmd == SW_MINIMIZE;
}
bool wxFrame::Show(bool show)
{
int cshow;
if (show)
cshow = SW_SHOW;
else
cshow = SW_HIDE;
DoShowWindow(show ? SW_SHOW : SW_HIDE);
if (!show)
{
// Try to highlight the correct window (the parent)
HWND hWndParent = 0;
if (GetParent())
if ( show )
{
hWndParent = (HWND) GetParent()->GetHWND();
if (hWndParent)
::BringWindowToTop(hWndParent);
::BringWindowToTop(GetHwnd());
wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
}
else
{
// Try to highlight the correct window (the parent)
if ( GetParent() )
{
HWND hWndParent = GetHwndOf(GetParent());
if (hWndParent)
::BringWindowToTop(hWndParent);
}
}
}
ShowWindow(GetHwnd(), (BOOL)cshow);
if (show)
{
BringWindowToTop(GetHwnd());
wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
event.SetEventObject( this );
GetEventHandler()->ProcessEvent(event);
}
return TRUE;
return TRUE;
}
void wxFrame::Iconize(bool iconize)
{
if (!iconize)
Show(TRUE);
int cshow;
if (iconize)
cshow = SW_MINIMIZE;
else
cshow = SW_RESTORE;
ShowWindow(GetHwnd(), (BOOL)cshow);
m_iconized = iconize;
DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
}
// Equivalent to maximize/restore in Windows
void wxFrame::Maximize(bool maximize)
{
Show(TRUE);
int cshow;
if (maximize)
cshow = SW_MAXIMIZE;
else
cshow = SW_RESTORE;
ShowWindow(GetHwnd(), cshow);
m_iconized = FALSE;
DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
}
void wxFrame::Restore()
{
DoShowWindow(SW_RESTORE);
}
bool wxFrame::IsIconized() const
@@ -312,103 +329,62 @@ bool wxFrame::IsIconized() const
// Is it maximized?
bool wxFrame::IsMaximized() const
{
return (::IsZoomed(GetHwnd()) != 0) ;
return (::IsZoomed(GetHwnd()) != 0);
}
void wxFrame::SetIcon(const wxIcon& icon)
{
m_icon = icon;
wxFrameBase::SetIcon(icon);
#if defined(__WIN95__)
if ( m_icon.Ok() )
SendMessage(GetHwnd(), WM_SETICON,
(WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
#endif
if ( m_icon.Ok() )
{
SendMessage(GetHwnd(), WM_SETICON,
(WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
}
#endif // __WIN95__
}
#if wxUSE_STATUSBAR
wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
const wxString& name)
wxStatusBar *wxFrame::OnCreateStatusBar(int number,
long style,
wxWindowID id,
const wxString& name)
{
wxStatusBar *statusBar = NULL;
#if wxUSE_NATIVE_STATUSBAR
if (UsesNativeStatusBar())
if ( UsesNativeStatusBar() )
{
statusBar = new wxStatusBar95(this, id, style);
}
else
#endif
{
statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20),
style, name);
// Set the height according to the font and the border size
wxClientDC dc(statusBar);
dc.SetFont(statusBar->GetFont());
long x, y;
dc.GetTextExtent("X", &x, &y);
int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
statusBar->SetSize(-1, -1, 100, height);
statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
}
statusBar->SetFieldsCount(number);
return statusBar;
}
wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id,
const wxString& name)
{
// VZ: calling CreateStatusBar twice is an error - why anyone would do it?
wxCHECK_MSG( m_frameStatusBar == NULL, FALSE,
wxT("recreating status bar in wxFrame") );
m_frameStatusBar = OnCreateStatusBar(number, style, id,
name);
if ( m_frameStatusBar )
{
PositionStatusBar();
return m_frameStatusBar;
}
else
return NULL;
}
void wxFrame::SetStatusText(const wxString& text, int number)
{
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") );
m_frameStatusBar->SetStatusText(text, number);
}
void wxFrame::SetStatusWidths(int n, const int widths_field[])
{
wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") );
m_frameStatusBar->SetStatusWidths(n, widths_field);
PositionStatusBar();
return statusBar;
}
void wxFrame::PositionStatusBar()
{
// native status bar positions itself
if (m_frameStatusBar
// native status bar positions itself
if ( m_frameStatusBar
#if wxUSE_NATIVE_STATUSBAR
&& !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
&& !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
#endif
)
{
int w, h;
GetClientSize(&w, &h);
int sw, sh;
m_frameStatusBar->GetSize(&sw, &sh);
)
{
int w, h;
GetClientSize(&w, &h);
int sw, sh;
m_frameStatusBar->GetSize(&sw, &sh);
// Since we wish the status bar to be directly under the client area,
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
m_frameStatusBar->SetSize(0, h, w, sh);
}
// Since we wish the status bar to be directly under the client area,
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
m_frameStatusBar->SetSize(0, h, w, sh);
}
}
#endif // wxUSE_STATUSBAR
@@ -546,53 +522,6 @@ bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow
return TRUE;
}
// Default resizing behaviour - if only ONE subwindow, resize to client
// rectangle size
void wxFrame::OnSize(wxSizeEvent& event)
{
// if we're using constraints - do use them
#if wxUSE_CONSTRAINTS
if ( GetAutoLayout() )
{
Layout();
return;
}
#endif
// do we have _exactly_ one child?
wxWindow *child = NULL;
for ( wxWindowList::Node *node = GetChildren().GetFirst();
node;
node = node->GetNext() )
{
wxWindow *win = node->GetData();
if ( !win->IsTopLevel()
#if wxUSE_STATUSBAR
&& (win != GetStatusBar())
#endif // wxUSE_STATUSBAR
#if wxUSE_TOOLBAR
&& (win != GetToolBar())
#endif // wxUSE_TOOLBAR
)
{
if ( child )
return; // it's our second subwindow - nothing to do
child = win;
}
}
if ( child ) {
// we have exactly one child - set it's size to fill the whole frame
int clientW, clientH;
GetClientSize(&clientW, &clientH);
int x = 0;
int y = 0;
child->SetSize(x, y, clientW, clientH);
}
}
// Default activation behaviour - set the focus for the first child
// subwindow found.
void wxFrame::OnActivate(wxActivateEvent& event)
@@ -622,66 +551,11 @@ void wxFrame::OnActivate(wxActivateEvent& event)
}
}
// The default implementation for the close window event.
void wxFrame::OnCloseWindow(wxCloseEvent& event)
{
Destroy();
}
// Destroy the window (delayed, if a managed window)
bool wxFrame::Destroy()
{
if (!wxPendingDelete.Member(this))
wxPendingDelete.Append(this);
return TRUE;
}
// Default menu selection behaviour - display a help string
void wxFrame::OnMenuHighlight(wxMenuEvent& event)
{
if (GetStatusBar())
{
wxString help;
int menuId = event.GetMenuId();
if ( menuId != -1 )
{
wxMenuBar *menuBar = GetMenuBar();
if (menuBar && menuBar->FindItem(menuId))
{
help = menuBar->GetHelpString(menuId);
}
}
// set status text even if the string is empty - this will at
// least remove the string from the item which was previously
// selected
SetStatusText(help);
}
}
wxMenuBar *wxFrame::GetMenuBar() const
{
return m_frameMenuBar;
}
bool wxFrame::ProcessCommand(int id)
{
wxMenuBar *bar = GetMenuBar() ;
if ( !bar )
return FALSE;
wxMenuItem *item = bar->FindItem(id);
if ( item && item->IsCheckable() )
{
item->Toggle();
}
wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
commandEvent.SetInt( id );
commandEvent.SetEventObject( this );
return GetEventHandler()->ProcessEvent(commandEvent);
}
// ----------------------------------------------------------------------------
// wxFrame size management: we exclude the areas taken by menu/status/toolbars
// from the client area, so the client area is what's really available for the
// frame contents
// ----------------------------------------------------------------------------
// Checks if there is a toolbar, and returns the first free client position
wxPoint wxFrame::GetClientAreaOrigin() const
@@ -728,28 +602,20 @@ void wxFrame::DoClientToScreen(int *x, int *y) const
wxWindow::DoClientToScreen(x, y);
}
// ----------------------------------------------------------------------------
// tool/status bar stuff
// ----------------------------------------------------------------------------
#if wxUSE_TOOLBAR
wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
{
wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
wxT("recreating toolbar in wxFrame") );
wxToolBar* toolBar = OnCreateToolBar(style, id, name);
if (toolBar)
if ( wxFrameBase::CreateToolBar(style, id, name) )
{
SetToolBar(toolBar);
PositionToolBar();
return toolBar;
}
else
{
return NULL;
}
}
wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
{
return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
return m_frameToolBar;
}
void wxFrame::PositionToolBar()
@@ -757,32 +623,39 @@ void wxFrame::PositionToolBar()
RECT rect;
::GetClientRect(GetHwnd(), &rect);
#if wxUSE_STATUSBAR
if ( GetStatusBar() )
{
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
rect.bottom -= statusY;
int statusX, statusY;
GetStatusBar()->GetClientSize(&statusX, &statusY);
rect.bottom -= statusY;
}
#endif // wxUSE_STATUSBAR
if (GetToolBar())
if ( GetToolBar() )
{
int tw, th;
GetToolBar()->GetSize(& tw, & th);
GetToolBar()->GetSize(&tw, &th);
if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
{
// Use the 'real' MSW position
GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS);
th = rect.bottom;
}
else
{
// Use the 'real' MSW position
GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS);
tw = rect.right;
}
// Use the 'real' MSW position here
GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
}
}
#endif // wxUSE_TOOLBAR
// ----------------------------------------------------------------------------
// frame state (iconized/maximized/...)
// ----------------------------------------------------------------------------
// propagate our state change to all child frames: this allows us to emulate X
// Windows behaviour where child frames float independently of the parent one
// on the desktop, but are iconized/restored with it
@@ -801,20 +674,6 @@ void wxFrame::IconizeChildFrames(bool bIconize)
}
}
// make the window modal (all other windows unresponsive)
void wxFrame::MakeModal(bool modal)
{
if (modal) {
wxEnableTopLevelWindows(FALSE);
Enable(TRUE); // keep this window enabled
}
else {
wxEnableTopLevelWindows(TRUE);
}
}
// ===========================================================================
// message processing
// ===========================================================================

View File

@@ -35,7 +35,9 @@
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/statusbr.h"
#if wxUSE_STATUSBAR
#include "wx/statusbr.h"
#endif
#include "wx/settings.h"
#include "wx/intl.h"
#include "wx/log.h"
@@ -44,10 +46,14 @@
#include "wx/mdi.h"
#include "wx/msw/private.h"
#if wxUSE_NATIVE_STATUSBAR
#if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
#include "wx/msw/statbr95.h"
#endif
#if wxUSE_TOOLBAR
#include "wx/toolbar.h"
#endif // wxUSE_TOOLBAR
#include <string.h>
// ---------------------------------------------------------------------------

View File

@@ -95,7 +95,7 @@ static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBar95, wxToolBarBase)
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
#endif
BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)

View File

@@ -56,7 +56,7 @@
#endif
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBarMSW, wxToolBarBase)
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
BEGIN_EVENT_TABLE(wxToolBarMSW, wxToolBarBase)
EVT_SIZE(wxToolBarMSW::OnSize)