// Name: window.cpp
// Purpose:
// Author: Robert Roebling
-// Id: $id$
+// Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/msgdlg.h"
#include "wx/dcclient.h"
#include "wx/dnd.h"
-#include "wx/mdi.h"
#include "wx/menu.h"
-#include "wx/notebook.h"
#include "wx/statusbr.h"
#include "wx/intl.h"
-#include "wx/gtk/win_gtk.h"
#include "gdk/gdkprivate.h"
#include "gdk/gdkkeysyms.h"
if (gdk_event->count > 0) return;
/*
- printf( "OnExpose from " );
+ printf( "OnExpose from " );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() );
printf( ".\n" );
// "drop_data_available_event"
//-----------------------------------------------------------------------------
-static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWindow *win )
+static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win )
{
if (!win->HasVMT()) return;
int x = 0;
int y = 0;
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
- win->GetDropTarget()->Drop( event, x, y );
+
+ printf( "Drop data is of type %s.\n", event->data_type );
+
+ win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
}
/*
*/
}
+//-----------------------------------------------------------------------------
+// InsertChild for wxWindow.
+//-----------------------------------------------------------------------------
+
+// Callback for wxWindow. This very strange beast has to be used because
+// C++ has no virtual methods in a constructor. We have to emulate a
+// virtual function here as wxNotebook requires a different way to insert
+// a child in it. I had opted for creating a wxNotebookPage window class
+// which would have made this superflouus (such in the MDI window system),
+// but no-one is listening to me...
+
+static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
+{
+ gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
+ GTK_WIDGET(child->m_widget),
+ child->m_x,
+ child->m_y );
+
+ gtk_widget_set_usize( GTK_WIDGET(child->m_widget),
+ child->m_width,
+ child->m_height );
+}
+
//-----------------------------------------------------------------------------
// wxWindow
//-----------------------------------------------------------------------------
m_isEnabled = TRUE;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
- m_hasOwnStyle = FALSE;
m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
+ m_insertCallback = wxInsertChildInWindow;
}
+wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ long style, const wxString &name )
+{
+ m_insertCallback = wxInsertChildInWindow;
+ 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 )
m_isEnabled = TRUE;
m_needParent = TRUE;
- m_cursor = (wxCursor *) NULL;
-
PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
gtk_widget_show( m_wxwindow );
+
+ if (m_parent) m_parent->AddChild( this );
+ (m_parent->m_insertCallback)( m_parent, this );
+
PostCreation();
Show( TRUE );
DestroyChildren();
+ if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
+
if (m_scrollGC) gdk_gc_unref( m_scrollGC );
if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
{
if (m_needParent && (parent == NULL))
wxFatalError( "Need complete parent.", name );
-
+
m_widget = (GtkWidget *) NULL;
m_hasVMT = FALSE;
m_parent = parent;
m_children.DeleteContents( FALSE );
- m_x = (int)pos.x;
- m_y = (int)pos.y;
+
m_width = size.x;
if (m_width == -1) m_width = 20;
m_height = size.y;
if (m_height == -1) m_height = 20;
+
+ m_x = (int)pos.x;
+ m_y = (int)pos.y;
+
+ if (!m_needParent) // some reasonable defaults
+ {
+ if (m_x == -1)
+ {
+ m_x = (gdk_screen_width () - m_width) / 2;
+ if (m_x < 10) m_x = 10;
+ }
+ if (m_y == -1)
+ {
+ m_y = (gdk_screen_height () - m_height) / 2;
+ if (m_y < 10) m_y = 10;
+ }
+ }
+
m_minWidth = -1;
m_minHeight = -1;
m_maxWidth = -1;
m_cursor = new wxCursor( wxCURSOR_ARROW );
m_font = *wxSWISS_FONT;
// m_backgroundColour = wxWHITE;
- m_foregroundColour = wxBLACK;
+// m_foregroundColour = wxBLACK;
m_windowStyle = style;
m_windowName = name;
m_constraints = (wxLayoutConstraints *) NULL;
m_pDropTarget = (wxDropTarget *) NULL;
m_resizing = FALSE;
m_windowValidator = (wxValidator *) NULL;
- m_hasOwnStyle = FALSE;
+ m_scrollGC = (GdkGC*) NULL;
+ m_widgetStyle = (GtkStyle*) NULL;
}
void wxWindow::PostCreation()
{
- if (m_parent) m_parent->AddChild( this );
-
if (m_wxwindow)
{
gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event",
// are we to set fonts here ?
}
+wxPoint wxWindow::GetClientAreaOrigin() const
+{
+ return wxPoint(0,0);
+}
+
+void wxWindow::AdjustForParentClientOrigin( int& x, int& y, int sizeFlags )
+{
+ if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
+ {
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ x += pt.x;
+ y += pt.y;
+ }
+}
+
void wxWindow::ImplementSetSize()
{
if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
void wxWindow::ImplementSetPosition()
{
- if (IS_KIND_OF(this,wxFrame) || IS_KIND_OF(this,wxDialog))
- {
- if ((m_x != -1) || (m_y != -1))
- gtk_widget_set_uposition( m_widget, m_x, m_y );
- return;
- }
-
if (!m_parent)
{
wxFAIL_MSG( "wxWindow::SetSize error.\n" );
if (newH == -1) newH = 26;
}
+ AdjustForParentClientOrigin( newX, newY, sizeFlags );
+
if ((m_x != newX) || (m_y != newY) || (!m_sizeSet))
{
m_x = newX;
m_y = newY;
ImplementSetPosition();
}
+
if ((m_width != newW) || (m_height != newH) || (!m_sizeSet))
{
m_width = newW;
{
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
- if (x) (*x) = m_x;
- if (y) (*y) = m_y;
+ int xx = m_x;
+ int yy = m_y;
+
+ if (GetParent())
+ {
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ xx -= pt.x;
+ yy -= pt.y;
+ }
+
+ if (x) (*x) = xx;
+ if (y) (*y) = yy;
}
void wxWindow::ClientToScreen( int *x, int *y )
}
}
+ wxPoint pt(GetClientAreaOrigin());
+ org_x += pt.x;
+ org_y += pt.y;
+
if (x) *x += org_x;
if (y) *y += org_y;
}
}
}
+ wxPoint pt(GetClientAreaOrigin());
+ org_x -= pt.x;
+ org_y -= pt.y;
+
if (x) *x -= org_x;
if (y) *y -= org_y;
}
void wxWindow::AddChild( wxWindow *child )
{
wxASSERT_MSG( (m_widget != NULL), "invalid window" );
- wxASSERT_MSG( (m_wxwindow != NULL), "window need client area" );
wxASSERT_MSG( (child != NULL), "invalid child" );
- wxASSERT_MSG( (child->m_widget != NULL), "invalid child" );
-
- // Addchild is (often) called before the program
- // has left the parents constructor so that no
- // virtual tables work yet. The approach below
- // practically imitates virtual tables, i.e. it
- // implements a different AddChild() behaviour
- // for wxFrame, wxDialog, wxWindow and
- // wxMDIParentFrame.
-
- // wxFrame and wxDialog as children aren't placed into the parents
-
- if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) &&
- (!IS_KIND_OF(child,wxMDIChildFrame)))
- {
- m_children.Append( child );
-
- if ((child->m_x != -1) && (child->m_y != -1))
- gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y );
-
- return;
- }
-
- // In the case of an wxMDIChildFrame descendant, we use the
- // client windows's AddChild()
-
- if (IS_KIND_OF(this,wxMDIParentFrame))
- {
- if (IS_KIND_OF(child,wxMDIChildFrame))
- {
- wxMDIClientWindow *client = ((wxMDIParentFrame*)this)->GetClientWindow();
- if (client)
- {
- client->AddChild( child );
- return;
- }
- }
- }
-
- // wxNotebook is very special, so it has a private AddChild()
-
- if (IS_KIND_OF(this,wxNotebook))
- {
- wxNotebook *tab = (wxNotebook*)this;
- tab->AddChild( child );
- return;
- }
-
- // wxFrame has a private AddChild
-
- if (IS_KIND_OF(this,wxFrame) && !IS_KIND_OF(this,wxMDIChildFrame))
- {
- wxFrame *frame = (wxFrame*)this;
- frame->AddChild( child );
- return;
- }
-
- // All the rest
m_children.Append( child );
- if (m_wxwindow) gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget,
- child->m_x, child->m_y );
-
- gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height );
}
wxList *wxWindow::GetChildren()
void wxWindow::RemoveChild( wxWindow *child )
{
- if (GetChildren())
- GetChildren()->DeleteObject( child );
+ if (GetChildren()) GetChildren()->DeleteObject( child );
child->m_parent = (wxWindow *) NULL;
}
return m_backgroundColour;
}
-void wxWindow::SetBackgroundColourHelper( GdkWindow *window )
-{
- if (!m_backgroundColour.Ok()) return;
-
- m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
- gdk_window_set_background( window, m_backgroundColour.GetColor() );
- gdk_window_clear( window );
-}
-
void wxWindow::SetBackgroundColour( const wxColour &colour )
{
wxCHECK_RET( m_widget != NULL, "invalid window" );
m_backgroundColour = colour;
+ if (!m_backgroundColour.Ok()) return;
- GtkWidget *widget = m_wxwindow == NULL ? m_widget : m_wxwindow;
- SetBackgroundColourHelper( widget->window );
+ if (m_wxwindow)
+ {
+ GdkWindow *window = m_wxwindow->window;
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
+ gdk_window_set_background( window, m_backgroundColour.GetColor() );
+ gdk_window_clear( window );
+ }
+
+ ApplyWidgetStyle();
}
wxColour wxWindow::GetForegroundColour() const
void wxWindow::SetForegroundColour( const wxColour &colour )
{
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
+
m_foregroundColour = colour;
+ if (!m_foregroundColour.Ok()) return;
+
+ ApplyWidgetStyle();
+}
+
+GtkStyle *wxWindow::GetWidgetStyle()
+{
+ if (m_widgetStyle) gtk_style_unref( m_widgetStyle );
+
+ m_widgetStyle =
+ gtk_style_copy(
+ gtk_widget_get_style( m_widget ) );
+
+ return m_widgetStyle;
+}
+
+void wxWindow::SetWidgetStyle()
+{
+ GtkStyle *style = GetWidgetStyle();
+
+ gdk_font_unref( style->font );
+ style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+
+ if (m_foregroundColour.Ok())
+ {
+ m_foregroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
+ style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor();
+ style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor();
+ }
+
+ if (m_backgroundColour.Ok())
+ {
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( m_widget->window ) );
+ style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor();
+ style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor();
+ }
+}
+
+void wxWindow::ApplyWidgetStyle()
+{
}
bool wxWindow::Validate()
void wxWindow::InitDialog()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
wxInitDialogEvent event(GetId());
event.SetEventObject( this );
bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_MSG( m_widget != NULL, FALSE, "invalid window" );
+ wxCHECK_MSG( menu != NULL, FALSE, "invalid popup-menu" );
+
SetInvokingWindow( menu, this );
gtk_menu_popup(
GTK_MENU(menu->m_menu),
void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
GtkWidget *dnd_widget = GetConnectWidget();
void wxWindow::SetFont( const wxFont &font )
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
if (((wxFont*)&font)->Ok())
m_font = font;
else
m_font = *wxSWISS_FONT;
-
- GtkStyle *style = (GtkStyle*) NULL;
- if (!m_hasOwnStyle)
- {
- m_hasOwnStyle = TRUE;
- style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
- }
- else
- {
- style = gtk_widget_get_style( m_widget );
- }
-
- gdk_font_unref( style->font );
- style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
-
- gtk_widget_set_style( m_widget, style );
+
+ ApplyWidgetStyle();
}
wxFont *wxWindow::GetFont()
void wxWindow::CaptureMouse()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
- wxASSERT_MSG( (g_capturing == FALSE), "CaptureMouse called twice" );
+ wxCHECK_RET( g_capturing == FALSE, "CaptureMouse called twice" );
GtkWidget *connect_widget = GetConnectWidget();
gtk_grab_add( connect_widget );
void wxWindow::ReleaseMouse()
{
- wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+ wxCHECK_RET( m_widget != NULL, "invalid window" );
- wxASSERT_MSG( (g_capturing == TRUE), "ReleaseMouse called twice" );
+ wxCHECK_RET( g_capturing == TRUE, "ReleaseMouse called twice" );
GtkWidget *connect_widget = GetConnectWidget();
gtk_grab_remove( connect_widget );