Compare commits

..

1 Commits

Author SHA1 Message Date
Bryan Petty
28a8aca9a1 This commit was manufactured by cvs2svn to create tag
'WXGTK_OLD_FOCUS_CODE'.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/WXGTK_OLD_FOCUS_CODE@11391 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2001-08-16 13:18:51 +00:00
19 changed files with 7832 additions and 13716 deletions

View File

@@ -1,90 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/scrolwin.h
// Purpose: wxGenericScrolledWindow class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_SCROLLWIN_H_
#define _WX_GENERIC_SCROLLWIN_H_
// ----------------------------------------------------------------------------
// headers and constants
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/panel.h"
extern WXDLLEXPORT_DATA(const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ----------------------------------------------------------------------------
// wxGenericScrolledWindow
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxGenericScrolledWindow : public wxPanel,
public wxScrollHelper
{
public:
wxGenericScrolledWindow() : wxScrollHelper(this) { }
wxGenericScrolledWindow(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
: wxScrollHelper(this)
{
Create(parent, winid, pos, size, style, name);
}
virtual ~wxGenericScrolledWindow();
bool Create(wxWindow *parent,
wxWindowID winid,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
virtual void DoSetVirtualSize(int x, int y);
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
protected:
// this is needed for wxEVT_PAINT processing hack described in
// wxScrollHelperEvtHandler::ProcessEvent()
void OnPaint(wxPaintEvent& event);
// we need to return a special WM_GETDLGCODE value to process just the
// arrows but let the other navigation characters through
#ifdef __WXMSW__
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
#endif // __WXMSW__
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGenericScrolledWindow)
DECLARE_EVENT_TABLE()
};
#endif // _WX_GENERIC_SCROLLWIN_H_

View File

@@ -1,193 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/scrolwin.h
// Purpose: wxScrolledWindow class
// Author: Robert Roebling
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_SCROLLWIN_H_
#define _WX_GTK_SCROLLWIN_H_
// ----------------------------------------------------------------------------
// headers and constants
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/panel.h"
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ----------------------------------------------------------------------------
// wxScrolledWindow
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxScrolledWindow : public wxPanel
{
public:
wxScrolledWindow()
{ Init(); }
wxScrolledWindow(wxWindow *parent,
wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
{ Create(parent, id, pos, size, style, name); }
void Init();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
// Normally the wxScrolledWindow will scroll itself, but in
// some rare occasions you might want it to scroll another
// window (e.g. a child of it in order to scroll only a portion
// the area between the scrollbars (spreadsheet: only cell area
// will move).
virtual void SetTargetWindow( wxWindow *target, bool pushEventHandler = FALSE );
virtual wxWindow *GetTargetWindow() const;
// Set the scrolled area of the window.
virtual void DoSetVirtualSize( int x, int y );
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
// Length of page in user units
// Default action is to set the virtual size and alter scrollbars
// accordingly.
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY,
int xPos = 0, int yPos = 0,
bool noRefresh = FALSE );
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
// Enable/disable Windows scrolling in either direction.
// If TRUE, wxWidgets scrolls the canvas and only a bit of
// the canvas is invalidated; no Clear() is necessary.
// If FALSE, the whole canvas is invalidated and a Clear() is
// necessary. Disable for when the scroll increment is used
// to actually scroll a non-constant distance
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start
virtual void GetViewStart(int *x, int *y) const;
// translate between scrolled and unscrolled coordinates
void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcScrolledPosition(x, y, xx, yy); }
wxPoint CalcScrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcUnscrolledPosition(x, y, xx, yy); }
wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
// Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) {}
// Override this function if you don't want to have wxScrolledWindow
// automatically change the origin according to the scroll position.
void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
// Adjust the scrollbars
virtual void AdjustScrollbars();
// Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
double GetScaleX() const { return m_scaleX; }
double GetScaleY() const { return m_scaleY; }
// implementation from now on
void OnScroll(wxScrollWinEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnChar(wxKeyEvent& event);
void GtkVScroll( float value, unsigned int scroll_type );
void GtkHScroll( float value, unsigned int scroll_type );
void GtkVConnectEvent();
void GtkHConnectEvent();
void GtkVDisconnectEvent();
void GtkHDisconnectEvent();
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
// Overridden from wxWidgets due callback being static
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
virtual void DoPrepareDC(wxDC& dc);
protected:
wxWindow *m_targetWindow;
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
// FIXME: these next four members are duplicated in the GtkAdjustment
// members of wxWindow. Can they be safely removed from here?
int m_xScrollPosition;
int m_yScrollPosition;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
double m_scaleY,m_scaleX;
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxScrolledWindow)
};
#endif
// _WX_GTK_SCROLLWIN_H_
// vi:sts=4:sw=4:et

View File

@@ -7,25 +7,26 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __GTKWINDOWH__
#define __GTKWINDOWH__
// helper structure that holds class that holds GtkIMContext object and
// some additional data needed for key events processing
struct wxGtkIMData;
#ifdef __GNUG__
#pragma interface
#endif
//-----------------------------------------------------------------------------
// callback definition for inserting a window (internal)
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxWindowGTK;
class wxWindowGTK;
typedef void (*wxInsertChildFunction)( wxWindowGTK*, wxWindowGTK* );
//-----------------------------------------------------------------------------
// wxWindowGTK
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxWindowGTK : public wxWindowBase
class wxWindowGTK : public wxWindowBase
{
public:
// creating the window
@@ -64,19 +65,18 @@ public:
virtual bool Reparent( wxWindowBase *newParent );
virtual void WarpPointer(int x, int y);
virtual void CaptureMouse();
virtual void ReleaseMouse();
virtual void Refresh( bool eraseBackground = TRUE,
const wxRect *rect = (const wxRect *) NULL );
virtual void Update();
virtual void ClearBackground();
virtual void Clear();
virtual bool SetBackgroundColour( const wxColour &colour );
virtual bool SetForegroundColour( const wxColour &colour );
virtual bool SetCursor( const wxCursor &cursor );
virtual bool SetFont( const wxFont &font );
virtual bool SetBackgroundStyle(wxBackgroundStyle style) ;
virtual int GetCharHeight() const;
virtual int GetCharWidth() const;
virtual void GetTextExtent(const wxString& string,
@@ -103,143 +103,110 @@ public:
virtual void SetDropTarget( wxDropTarget *dropTarget );
#endif // wxUSE_DRAG_AND_DROP
#ifdef __WXGTK20__
virtual void AddChild( wxWindowBase *child );
virtual void RemoveChild( wxWindowBase *child );
#endif
// implementation
// --------------
virtual WXWidget GetHandle() const { return m_widget; }
// I don't want users to override what's done in idle so everything that
// has to be done in idle time in order for wxGTK to work is done in
// OnInternalIdle
/* I don't want users to override what's done in idle so everything that
has to be done in idle time in order for wxGTK to work is done in
OnInternalIdle */
virtual void OnInternalIdle();
// Internal represention of Update()
void GtkUpdate();
// For compatibility across platforms (not in event table)
void OnIdle(wxIdleEvent& WXUNUSED(event)) {}
/* For compatibility across platforms (not in event table) */
void OnIdle(wxIdleEvent& WXUNUSED(event)) {};
// wxGTK-specific: called recursively by Enable,
// to give widgets an oppprtunity to correct their colours after they
// have been changed by Enable
virtual void OnParentEnable( bool WXUNUSED(enable) ) {}
virtual void OnParentEnable( bool WXUNUSED(enable) ) {};
// Used by all window classes in the widget creation process.
/* used by all window classes in the widget creation process */
bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size );
void PostCreation();
// Internal addition of child windows. differs from class
// to class not by using virtual functions but by using
// the m_insertCallback.
/* internal addition of child windows. differs from class
to class not by using virtual functions but by using
the m_insertCallback */
void DoAddChild(wxWindowGTK *child);
// This methods sends wxPaintEvents to the window. It reads the
// update region, breaks it up into rects and sends an event
// for each rect. It is also responsible for background erase
// events and NC paint events. It is called from "draw" and
// "expose" handlers as well as from ::Update()
void GtkSendPaintEvents();
/* the methods below are required because many native widgets
are composed of several subwidgets and setting a style for
the widget means setting it for all subwidgets as well.
also, it is nor clear, which native widget is the top
widget where (most of) the input goes. even tooltips have
to be applied to all subwidgets. */
// The methods below are required because many native widgets
// are composed of several subwidgets and setting a style for
// the widget means setting it for all subwidgets as well.
// also, it is nor clear, which native widget is the top
// widget where (most of) the input goes. even tooltips have
// to be applied to all subwidgets.
virtual GtkWidget* GetConnectWidget();
virtual bool IsOwnGtkWindow( GdkWindow *window );
void ConnectWidget( GtkWidget *widget );
#ifdef __WXGTK20__
// Returns the default context which usually is anti-aliased
PangoContext *GtkGetPangoDefaultContext();
/* creates a new widget style if none is there
and sets m_widgetStyle to this value. */
GtkStyle *GetWidgetStyle();
// Returns the X11 context which renders on the X11 client
// side (which can be remote) and which usually is not
// anti-aliased and is thus faster
// MR: Now returns the default pango_context for the widget as GtkGetPangoDefaultContext to
// not depend on libpangox - which is completely deprecated.
//BCI: Remove GtkGetPangoX11Context and m_x11Context completely when symbols may be removed
PangoContext *GtkGetPangoX11Context();
PangoContext *m_x11Context; // MR: Now unused
#endif
/* called by SetFont() and SetXXXColour etc */
void SetWidgetStyle();
/* overridden in many GTK widgets */
virtual void ApplyWidgetStyle();
#if wxUSE_TOOLTIPS
virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip );
#endif // wxUSE_TOOLTIPS
// Called from GTK signales handlers. it indicates that
// called from GTK signales handlers. it indicates that
// the layouting functions have to be called later on
// (i.e. in idle time, implemented in OnInternalIdle() ).
void GtkUpdateSize() { m_sizeSet = FALSE; }
// fix up the mouse event coords, used by wxListBox only so far
virtual void FixUpMouseEvent(GtkWidget * WXUNUSED(widget),
wxCoord& WXUNUSED(x),
wxCoord& WXUNUSED(y)) { }
// is this window transparent for the mouse events (as wxStaticBox is)?
virtual bool IsTransparentForMouse() const { return FALSE; }
// is this a radiobutton (used by radiobutton code itself only)?
virtual bool IsRadioButton() const { return FALSE; }
// position and size of the window
int m_x, m_y;
int m_width, m_height;
int m_oldClientWidth,m_oldClientHeight;
// see the docs in src/gtk/window.cpp
GtkWidget *m_widget; // mostly the widget seen by the rest of GTK
GtkWidget *m_wxwindow; // mostly the client area as per wxWidgets
/* see the docs in src/gtk/window.cpp */
GtkWidget *m_widget;
GtkWidget *m_wxwindow;
// this widget will be queried for GTK's focus events
GtkWidget *m_focusWidget;
#ifdef __WXGTK20__
wxGtkIMData *m_imData;
#else // GTK 1
#ifdef HAVE_XIM
// XIM support for wxWidgets
#if HAVE_XIM
/* XIM support for wxWindows */
GdkIC *m_ic;
GdkICAttr *m_icattr;
#endif // HAVE_XIM
#endif // GTK 2/1
#ifndef __WXGTK20__
// The area to be cleared (and not just refreshed)
// We cannot make this distinction under GTK 2.0.
wxRegion m_clearRegion;
#endif
// scrolling stuff
/* scrolling stuff */
GtkAdjustment *m_hAdjust,*m_vAdjust;
float m_oldHorizontalPos;
float m_oldVerticalPos;
// extra (wxGTK-specific) flags
bool m_needParent:1; // ! wxFrame, wxDialog, wxNotebookPage ?
bool m_noExpose:1; // wxGLCanvas has its own redrawing
bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size"
bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */
bool m_noExpose:1; /* wxGLCanvas has its own redrawing */
bool m_nativeSizeEvent:1; /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */
bool m_hasScrolling:1;
bool m_hasVMT:1;
bool m_sizeSet:1;
bool m_resizing:1;
bool m_acceptsFocus:1; // true if not static
bool m_hasFocus:1; // true if == FindFocus()
bool m_isScrolling:1; // dragging scrollbar thumb?
bool m_clipPaintRegion:1; // TRUE after ScrollWindow()
#ifdef __WXGTK20__
bool m_dirtyTabOrder:1; // tab order changed, GTK focus
// chain needs update
#endif
bool m_needsStyleChange:1; // May not be able to change
// background style until OnIdle
bool m_isStaticBox:1; /* faster than IS_KIND_OF */
bool m_isRadioButton:1; /* faster than IS_KIND_OF */
bool m_isFrame:1; /* faster than IS_KIND_OF */
bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */
bool m_isScrolling;
bool m_clipPaintRegion; /* TRUE after ScrollWindow() */
bool m_queuedFullRedraw; /* TRUE after DoMoveWindow */
// these are true if the style were set before the widget was realized
// (typcally in the constructor) but the actual GTK style must not be set
// before the widget has been "realized"
bool m_delayedForegroundColour:1;
bool m_delayedBackgroundColour:1;
// contains GTK's widgets internal information about non-default widget
// font and colours. we create one for each widget that gets any
// non-default attribute set via SetFont() or SetForegroundColour() /
// SetBackgroundColour().
GtkStyle *m_widgetStyle;
// C++ has no virtual methods in the constrcutor of any class but we need
// different methods of inserting a child window into a wxFrame,
@@ -258,43 +225,18 @@ public:
virtual void DoSetClientSize(int width, int height);
virtual void DoMoveWindow(int x, int y, int width, int height);
virtual void DoCaptureMouse();
virtual void DoReleaseMouse();
#if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip );
#endif // wxUSE_TOOLTIPS
protected:
// common part of all ctors (not virtual because called from ctor)
// common part of all ctors (can't be virtual because called from ctor)
void Init();
#ifdef __WXGTK20__
virtual void DoMoveInTabOrder(wxWindow *win, MoveKind move);
// Copies m_children tab order to GTK focus chain:
void RealizeTabOrder();
#endif
// Called by ApplyWidgetStyle (which is called by SetFont() and
// SetXXXColour etc to apply style changed to native widgets) to create
// modified GTK style with non-standard attributes. If forceStyle=true,
// creates empty GtkRcStyle if there are no modifications, otherwise
// returns NULL in such case.
GtkRcStyle *CreateWidgetStyle(bool forceStyle = false);
// Overridden in many GTK widgets who have to handle subwidgets
virtual void ApplyWidgetStyle(bool forceStyle = false);
// helper function to ease native widgets wrapping, called by
// ApplyWidgetStyle -- override this, not ApplyWidgetStyle
virtual void DoApplyWidgetStyle(GtkRcStyle *style);
private:
DECLARE_DYNAMIC_CLASS(wxWindowGTK)
DECLARE_NO_COPY_CLASS(wxWindowGTK)
};
extern WXDLLIMPEXP_CORE wxWindow *wxFindFocusedChild(wxWindowGTK *win);
extern wxWindow *wxFindFocusedChild(wxWindowGTK *win);
#endif // __GTKWINDOWH__

View File

@@ -1,193 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/scrolwin.h
// Purpose: wxScrolledWindow class
// Author: Robert Roebling
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_SCROLLWIN_H_
#define _WX_GTK_SCROLLWIN_H_
// ----------------------------------------------------------------------------
// headers and constants
// ----------------------------------------------------------------------------
#include "wx/window.h"
#include "wx/panel.h"
WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
// default scrolled window style
#ifndef wxScrolledWindowStyle
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
#endif
// ----------------------------------------------------------------------------
// wxScrolledWindow
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxScrolledWindow : public wxPanel
{
public:
wxScrolledWindow()
{ Init(); }
wxScrolledWindow(wxWindow *parent,
wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
{ Create(parent, id, pos, size, style, name); }
void Init();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr);
// Normally the wxScrolledWindow will scroll itself, but in
// some rare occasions you might want it to scroll another
// window (e.g. a child of it in order to scroll only a portion
// the area between the scrollbars (spreadsheet: only cell area
// will move).
virtual void SetTargetWindow( wxWindow *target, bool pushEventHandler = FALSE );
virtual wxWindow *GetTargetWindow() const;
// Set the scrolled area of the window.
virtual void DoSetVirtualSize( int x, int y );
// wxWindow's GetBestVirtualSize returns the actual window size,
// whereas we want to return the virtual size
virtual wxSize GetBestVirtualSize() const;
// Return the size best suited for the current window
// (this isn't a virtual size, this is a sensible size for the window)
virtual wxSize DoGetBestSize() const;
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
// Length of page in user units
// Default action is to set the virtual size and alter scrollbars
// accordingly.
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY,
int xPos = 0, int yPos = 0,
bool noRefresh = FALSE );
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
// Enable/disable Windows scrolling in either direction.
// If TRUE, wxWidgets scrolls the canvas and only a bit of
// the canvas is invalidated; no Clear() is necessary.
// If FALSE, the whole canvas is invalidated and a Clear() is
// necessary. Disable for when the scroll increment is used
// to actually scroll a non-constant distance
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start
virtual void GetViewStart(int *x, int *y) const;
// translate between scrolled and unscrolled coordinates
void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcScrolledPosition(x, y, xx, yy); }
wxPoint CalcScrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcUnscrolledPosition(x, y, xx, yy); }
wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
// Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) {}
// Override this function if you don't want to have wxScrolledWindow
// automatically change the origin according to the scroll position.
void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }
// lay out the window and its children
virtual bool Layout();
// Adjust the scrollbars
virtual void AdjustScrollbars();
// Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
double GetScaleX() const { return m_scaleX; }
double GetScaleY() const { return m_scaleY; }
// implementation from now on
void OnScroll(wxScrollWinEvent& event);
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnChar(wxKeyEvent& event);
void GtkVScroll( float value, unsigned int scroll_type );
void GtkHScroll( float value, unsigned int scroll_type );
void GtkVConnectEvent();
void GtkHConnectEvent();
void GtkVDisconnectEvent();
void GtkHDisconnectEvent();
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
// Overridden from wxWidgets due callback being static
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
virtual void DoPrepareDC(wxDC& dc);
protected:
wxWindow *m_targetWindow;
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
// FIXME: these next four members are duplicated in the GtkAdjustment
// members of wxWindow. Can they be safely removed from here?
int m_xScrollPosition;
int m_yScrollPosition;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
double m_scaleY,m_scaleX;
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxScrolledWindow)
};
#endif
// _WX_GTK_SCROLLWIN_H_
// vi:sts=4:sw=4:et

View File

@@ -7,25 +7,26 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __GTKWINDOWH__
#define __GTKWINDOWH__
// helper structure that holds class that holds GtkIMContext object and
// some additional data needed for key events processing
struct wxGtkIMData;
#ifdef __GNUG__
#pragma interface
#endif
//-----------------------------------------------------------------------------
// callback definition for inserting a window (internal)
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxWindowGTK;
class wxWindowGTK;
typedef void (*wxInsertChildFunction)( wxWindowGTK*, wxWindowGTK* );
//-----------------------------------------------------------------------------
// wxWindowGTK
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxWindowGTK : public wxWindowBase
class wxWindowGTK : public wxWindowBase
{
public:
// creating the window
@@ -64,19 +65,18 @@ public:
virtual bool Reparent( wxWindowBase *newParent );
virtual void WarpPointer(int x, int y);
virtual void CaptureMouse();
virtual void ReleaseMouse();
virtual void Refresh( bool eraseBackground = TRUE,
const wxRect *rect = (const wxRect *) NULL );
virtual void Update();
virtual void ClearBackground();
virtual void Clear();
virtual bool SetBackgroundColour( const wxColour &colour );
virtual bool SetForegroundColour( const wxColour &colour );
virtual bool SetCursor( const wxCursor &cursor );
virtual bool SetFont( const wxFont &font );
virtual bool SetBackgroundStyle(wxBackgroundStyle style) ;
virtual int GetCharHeight() const;
virtual int GetCharWidth() const;
virtual void GetTextExtent(const wxString& string,
@@ -103,143 +103,110 @@ public:
virtual void SetDropTarget( wxDropTarget *dropTarget );
#endif // wxUSE_DRAG_AND_DROP
#ifdef __WXGTK20__
virtual void AddChild( wxWindowBase *child );
virtual void RemoveChild( wxWindowBase *child );
#endif
// implementation
// --------------
virtual WXWidget GetHandle() const { return m_widget; }
// I don't want users to override what's done in idle so everything that
// has to be done in idle time in order for wxGTK to work is done in
// OnInternalIdle
/* I don't want users to override what's done in idle so everything that
has to be done in idle time in order for wxGTK to work is done in
OnInternalIdle */
virtual void OnInternalIdle();
// Internal represention of Update()
void GtkUpdate();
// For compatibility across platforms (not in event table)
void OnIdle(wxIdleEvent& WXUNUSED(event)) {}
/* For compatibility across platforms (not in event table) */
void OnIdle(wxIdleEvent& WXUNUSED(event)) {};
// wxGTK-specific: called recursively by Enable,
// to give widgets an oppprtunity to correct their colours after they
// have been changed by Enable
virtual void OnParentEnable( bool WXUNUSED(enable) ) {}
virtual void OnParentEnable( bool WXUNUSED(enable) ) {};
// Used by all window classes in the widget creation process.
/* used by all window classes in the widget creation process */
bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size );
void PostCreation();
// Internal addition of child windows. differs from class
// to class not by using virtual functions but by using
// the m_insertCallback.
/* internal addition of child windows. differs from class
to class not by using virtual functions but by using
the m_insertCallback */
void DoAddChild(wxWindowGTK *child);
// This methods sends wxPaintEvents to the window. It reads the
// update region, breaks it up into rects and sends an event
// for each rect. It is also responsible for background erase
// events and NC paint events. It is called from "draw" and
// "expose" handlers as well as from ::Update()
void GtkSendPaintEvents();
/* the methods below are required because many native widgets
are composed of several subwidgets and setting a style for
the widget means setting it for all subwidgets as well.
also, it is nor clear, which native widget is the top
widget where (most of) the input goes. even tooltips have
to be applied to all subwidgets. */
// The methods below are required because many native widgets
// are composed of several subwidgets and setting a style for
// the widget means setting it for all subwidgets as well.
// also, it is nor clear, which native widget is the top
// widget where (most of) the input goes. even tooltips have
// to be applied to all subwidgets.
virtual GtkWidget* GetConnectWidget();
virtual bool IsOwnGtkWindow( GdkWindow *window );
void ConnectWidget( GtkWidget *widget );
#ifdef __WXGTK20__
// Returns the default context which usually is anti-aliased
PangoContext *GtkGetPangoDefaultContext();
/* creates a new widget style if none is there
and sets m_widgetStyle to this value. */
GtkStyle *GetWidgetStyle();
// Returns the X11 context which renders on the X11 client
// side (which can be remote) and which usually is not
// anti-aliased and is thus faster
// MR: Now returns the default pango_context for the widget as GtkGetPangoDefaultContext to
// not depend on libpangox - which is completely deprecated.
//BCI: Remove GtkGetPangoX11Context and m_x11Context completely when symbols may be removed
PangoContext *GtkGetPangoX11Context();
PangoContext *m_x11Context; // MR: Now unused
#endif
/* called by SetFont() and SetXXXColour etc */
void SetWidgetStyle();
/* overridden in many GTK widgets */
virtual void ApplyWidgetStyle();
#if wxUSE_TOOLTIPS
virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip );
#endif // wxUSE_TOOLTIPS
// Called from GTK signales handlers. it indicates that
// called from GTK signales handlers. it indicates that
// the layouting functions have to be called later on
// (i.e. in idle time, implemented in OnInternalIdle() ).
void GtkUpdateSize() { m_sizeSet = FALSE; }
// fix up the mouse event coords, used by wxListBox only so far
virtual void FixUpMouseEvent(GtkWidget * WXUNUSED(widget),
wxCoord& WXUNUSED(x),
wxCoord& WXUNUSED(y)) { }
// is this window transparent for the mouse events (as wxStaticBox is)?
virtual bool IsTransparentForMouse() const { return FALSE; }
// is this a radiobutton (used by radiobutton code itself only)?
virtual bool IsRadioButton() const { return FALSE; }
// position and size of the window
int m_x, m_y;
int m_width, m_height;
int m_oldClientWidth,m_oldClientHeight;
// see the docs in src/gtk/window.cpp
GtkWidget *m_widget; // mostly the widget seen by the rest of GTK
GtkWidget *m_wxwindow; // mostly the client area as per wxWidgets
/* see the docs in src/gtk/window.cpp */
GtkWidget *m_widget;
GtkWidget *m_wxwindow;
// this widget will be queried for GTK's focus events
GtkWidget *m_focusWidget;
#ifdef __WXGTK20__
wxGtkIMData *m_imData;
#else // GTK 1
#ifdef HAVE_XIM
// XIM support for wxWidgets
#if HAVE_XIM
/* XIM support for wxWindows */
GdkIC *m_ic;
GdkICAttr *m_icattr;
#endif // HAVE_XIM
#endif // GTK 2/1
#ifndef __WXGTK20__
// The area to be cleared (and not just refreshed)
// We cannot make this distinction under GTK 2.0.
wxRegion m_clearRegion;
#endif
// scrolling stuff
/* scrolling stuff */
GtkAdjustment *m_hAdjust,*m_vAdjust;
float m_oldHorizontalPos;
float m_oldVerticalPos;
// extra (wxGTK-specific) flags
bool m_needParent:1; // ! wxFrame, wxDialog, wxNotebookPage ?
bool m_noExpose:1; // wxGLCanvas has its own redrawing
bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size"
bool m_needParent:1; /* ! wxFrame, wxDialog, wxNotebookPage ? */
bool m_noExpose:1; /* wxGLCanvas has its own redrawing */
bool m_nativeSizeEvent:1; /* wxGLCanvas sends wxSizeEvent upon "alloc_size" */
bool m_hasScrolling:1;
bool m_hasVMT:1;
bool m_sizeSet:1;
bool m_resizing:1;
bool m_acceptsFocus:1; // true if not static
bool m_hasFocus:1; // true if == FindFocus()
bool m_isScrolling:1; // dragging scrollbar thumb?
bool m_clipPaintRegion:1; // TRUE after ScrollWindow()
#ifdef __WXGTK20__
bool m_dirtyTabOrder:1; // tab order changed, GTK focus
// chain needs update
#endif
bool m_needsStyleChange:1; // May not be able to change
// background style until OnIdle
bool m_isStaticBox:1; /* faster than IS_KIND_OF */
bool m_isRadioButton:1; /* faster than IS_KIND_OF */
bool m_isFrame:1; /* faster than IS_KIND_OF */
bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */
bool m_isScrolling;
bool m_clipPaintRegion; /* TRUE after ScrollWindow() */
bool m_queuedFullRedraw; /* TRUE after DoMoveWindow */
// these are true if the style were set before the widget was realized
// (typcally in the constructor) but the actual GTK style must not be set
// before the widget has been "realized"
bool m_delayedForegroundColour:1;
bool m_delayedBackgroundColour:1;
// contains GTK's widgets internal information about non-default widget
// font and colours. we create one for each widget that gets any
// non-default attribute set via SetFont() or SetForegroundColour() /
// SetBackgroundColour().
GtkStyle *m_widgetStyle;
// C++ has no virtual methods in the constrcutor of any class but we need
// different methods of inserting a child window into a wxFrame,
@@ -258,43 +225,18 @@ public:
virtual void DoSetClientSize(int width, int height);
virtual void DoMoveWindow(int x, int y, int width, int height);
virtual void DoCaptureMouse();
virtual void DoReleaseMouse();
#if wxUSE_TOOLTIPS
virtual void DoSetToolTip( wxToolTip *tip );
#endif // wxUSE_TOOLTIPS
protected:
// common part of all ctors (not virtual because called from ctor)
// common part of all ctors (can't be virtual because called from ctor)
void Init();
#ifdef __WXGTK20__
virtual void DoMoveInTabOrder(wxWindow *win, MoveKind move);
// Copies m_children tab order to GTK focus chain:
void RealizeTabOrder();
#endif
// Called by ApplyWidgetStyle (which is called by SetFont() and
// SetXXXColour etc to apply style changed to native widgets) to create
// modified GTK style with non-standard attributes. If forceStyle=true,
// creates empty GtkRcStyle if there are no modifications, otherwise
// returns NULL in such case.
GtkRcStyle *CreateWidgetStyle(bool forceStyle = false);
// Overridden in many GTK widgets who have to handle subwidgets
virtual void ApplyWidgetStyle(bool forceStyle = false);
// helper function to ease native widgets wrapping, called by
// ApplyWidgetStyle -- override this, not ApplyWidgetStyle
virtual void DoApplyWidgetStyle(GtkRcStyle *style);
private:
DECLARE_DYNAMIC_CLASS(wxWindowGTK)
DECLARE_NO_COPY_CLASS(wxWindowGTK)
};
extern WXDLLIMPEXP_CORE wxWindow *wxFindFocusedChild(wxWindowGTK *win);
extern wxWindow *wxFindFocusedChild(wxWindowGTK *win);
#endif // __GTKWINDOWH__

View File

@@ -1,238 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/scrolwin.h
// Purpose: wxScrolledWindow, wxScrolledControl and wxScrollHelper
// Author: Vadim Zeitlin
// Modified by:
// Created: 30.08.00
// RCS-ID: $Id$
// Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_SCROLWIN_H_BASE_
#define _WX_SCROLWIN_H_BASE_
#include "wx/window.h"
class WXDLLEXPORT wxScrollHelperEvtHandler;
class WXDLLEXPORT wxTimer;
// ----------------------------------------------------------------------------
// wxScrollHelper: this class implements the scrolling logic which is used by
// wxScrolledWindow and wxScrolledControl. It is a mix-in: just derive from it
// to implement scrolling in your class.
// ----------------------------------------------------------------------------
#if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
class WXDLLEXPORT wxScrollHelper
{
public:
// ctor and dtor
wxScrollHelper(wxWindow *winToScroll = (wxWindow *)NULL);
void SetWindow(wxWindow *winToScroll);
virtual ~wxScrollHelper();
// configure the scrolling
virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY,
int xPos = 0, int yPos = 0,
bool noRefresh = false );
// scroll to the given (in logical coords) position
virtual void Scroll(int x, int y);
// get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
// get the size of one logical unit in physical ones
virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX,
int *pixelsPerUnitY) const;
// Enable/disable Windows scrolling in either direction. If true, wxWidgets
// scrolls the canvas and only a bit of the canvas is invalidated; no
// Clear() is necessary. If false, the whole canvas is invalidated and a
// Clear() is necessary. Disable for when the scroll increment is used to
// actually scroll a non-constant distance
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start
virtual void GetViewStart(int *x, int *y) const;
// Set the scale factor, used in PrepareDC
void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
double GetScaleX() const { return m_scaleX; }
double GetScaleY() const { return m_scaleY; }
// translate between scrolled and unscrolled coordinates
void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcScrolledPosition(x, y, xx, yy); }
wxPoint CalcScrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
{ DoCalcUnscrolledPosition(x, y, xx, yy); }
wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
{
wxPoint p2;
DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
return p2;
}
virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
// Adjust the scrollbars
virtual void AdjustScrollbars(void);
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
// Normally the wxScrolledWindow will scroll itself, but in some rare
// occasions you might want it to scroll [part of] another window (e.g. a
// child of it in order to scroll only a portion the area between the
// scrollbars (spreadsheet: only cell area will move).
virtual void SetTargetWindow(wxWindow *target);
virtual wxWindow *GetTargetWindow() const;
void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
wxRect GetTargetRect() const { return m_rectToScroll; }
// Override this function to draw the graphic (or just process EVT_PAINT)
virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
// change the DC origin according to the scroll position.
virtual void DoPrepareDC(wxDC& dc);
// are we generating the autoscroll events?
bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; }
// stop generating the scroll events when mouse is held outside the window
void StopAutoScrolling();
// this method can be overridden in a derived class to forbid sending the
// auto scroll events - note that unlike StopAutoScrolling() it doesn't
// stop the timer, so it will be called repeatedly and will typically
// return different values depending on the current mouse position
//
// the base class version just returns true
virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
// the methods to be called from the window event handlers
void HandleOnScroll(wxScrollWinEvent& event);
void HandleOnSize(wxSizeEvent& event);
void HandleOnPaint(wxPaintEvent& event);
void HandleOnChar(wxKeyEvent& event);
void HandleOnMouseEnter(wxMouseEvent& event);
void HandleOnMouseLeave(wxMouseEvent& event);
#if wxUSE_MOUSEWHEEL
void HandleOnMouseWheel(wxMouseEvent& event);
#endif // wxUSE_MOUSEWHEEL
// FIXME: this is needed for now for wxPlot compilation, should be removed
// once it is fixed!
void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
protected:
// get pointer to our scroll rect if we use it or NULL
const wxRect *GetScrollRect() const
{
return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
}
// get the size of the target window
wxSize GetTargetSize() const
{
return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
: m_targetWindow->GetClientSize();
}
void GetTargetSize(int *w, int *h)
{
wxSize size = GetTargetSize();
if ( w )
*w = size.x;
if ( h )
*h = size.y;
}
// change just the target window (unlike SetWindow which changes m_win as
// well)
void DoSetTargetWindow(wxWindow *target);
// delete the event handler we installed
void DeleteEvtHandler();
double m_scaleX;
double m_scaleY;
wxWindow *m_win,
*m_targetWindow;
wxRect m_rectToScroll;
wxTimer *m_timerAutoScroll;
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
int m_xScrollPosition;
int m_yScrollPosition;
int m_xScrollLines;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
#if wxUSE_MOUSEWHEEL
int m_wheelRotation;
#endif // wxUSE_MOUSEWHEEL
wxScrollHelperEvtHandler *m_handler;
DECLARE_NO_COPY_CLASS(wxScrollHelper)
};
#endif
// ----------------------------------------------------------------------------
// wxScrolledWindow: a wxWindow which knows how to scroll
// ----------------------------------------------------------------------------
#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
#include "wx/gtk/scrolwin.h"
#else // !wxGTK
#include "wx/generic/scrolwin.h"
class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
{
public:
wxScrolledWindow() { }
wxScrolledWindow(wxWindow *parent,
wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxScrolledWindowStyle,
const wxString& name = wxPanelNameStr)
: wxGenericScrolledWindow(parent, winid, pos, size, style, name)
{
}
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
};
#define wxSCROLLED_WINDOW_IS_GENERIC 1
#endif
#endif
// _WX_SCROLWIN_H_BASE_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

715
src/gtk/combobox.cpp Normal file
View File

@@ -0,0 +1,715 @@
/////////////////////////////////////////////////////////////////////////////
// Name: combobox.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "combobox.h"
#endif
#include "wx/combobox.h"
#if wxUSE_COMBOBOX
#include "wx/settings.h"
#include "wx/intl.h"
#include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED
#include <gdk/gdk.h>
#include <gtk/gtk.h>
//-----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//-----------------------------------------------------------------------------
// "select"
//-----------------------------------------------------------------------------
static void
gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
{
if (g_isIdle) wxapp_install_idle_handler();
if (!combo->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
if (combo->m_alreadySent)
{
combo->m_alreadySent = FALSE;
return;
}
combo->m_alreadySent = TRUE;
int curSelection = combo->GetSelection();
if (combo->m_prevSelection != curSelection)
{
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
}
combo->m_prevSelection = curSelection;
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
event.SetInt( curSelection );
event.SetString( combo->GetStringSelection() );
event.SetEventObject( combo );
combo->GetEventHandler()->ProcessEvent( event );
}
//-----------------------------------------------------------------------------
// "changed"
//-----------------------------------------------------------------------------
static void
gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
{
if (g_isIdle) wxapp_install_idle_handler();
if (!combo->m_hasVMT) return;
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
event.SetString( combo->GetValue() );
event.SetEventObject( combo );
combo->GetEventHandler()->ProcessEvent( event );
}
//-----------------------------------------------------------------------------
// wxComboBox
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
BEGIN_EVENT_TABLE(wxComboBox, wxControl)
EVT_SIZE(wxComboBox::OnSize)
EVT_CHAR(wxComboBox::OnChar)
END_EVENT_TABLE()
bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
const wxPoint& pos, const wxSize& size,
int n, const wxString choices[],
long style, const wxValidator& validator,
const wxString& name )
{
m_alreadySent = FALSE;
m_needParent = TRUE;
m_acceptsFocus = TRUE;
m_prevSelection = 0;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator, name ))
{
wxFAIL_MSG( wxT("wxComboBox creation failed") );
return FALSE;
}
m_widget = gtk_combo_new();
// make it more useable
gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
// and case-sensitive
gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE );
for (int i = 0; i < n; i++)
{
/* don't send first event, which GTK sends aways when
inserting the first item */
m_alreadySent = TRUE;
GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() );
m_clientDataList.Append( (wxObject*)NULL );
m_clientObjectList.Append( (wxObject*)NULL );
gtk_container_add( GTK_CONTAINER(list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
gtk_widget_show( list_item );
}
m_parent->DoAddChild( this );
PostCreation();
ConnectWidget( GTK_COMBO(m_widget)->button );
if (!value.IsNull()) SetValue( value );
if (style & wxCB_READONLY)
gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE );
gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
wxSize size_best( DoGetBestSize() );
wxSize new_size( size );
if (new_size.x == -1)
new_size.x = size_best.x;
if (new_size.y == -1)
new_size.y = size_best.y;
if (new_size.y > size_best.y)
new_size.y = size_best.y;
if ((new_size.x != size.x) || (new_size.y != size.y))
SetSize( new_size.x, new_size.y );
SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE );
return TRUE;
}
wxComboBox::~wxComboBox()
{
wxNode *node = m_clientObjectList.First();
while (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
node = node->Next();
}
m_clientObjectList.Clear();
m_clientDataList.Clear();
}
void wxComboBox::AppendCommon( const wxString &item )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GtkWidget *list_item = gtk_list_item_new_with_label( item.mbc_str() );
gtk_container_add( GTK_CONTAINER(list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
if (GTK_WIDGET_REALIZED(m_widget))
{
gtk_widget_realize( list_item );
gtk_widget_realize( GTK_BIN(list_item)->child );
if (m_widgetStyle) ApplyWidgetStyle();
}
gtk_widget_show( list_item );
}
void wxComboBox::Append( const wxString &item )
{
m_clientDataList.Append( (wxObject*) NULL );
m_clientObjectList.Append( (wxObject*) NULL );
AppendCommon( item );
}
void wxComboBox::Append( const wxString &item, void *clientData )
{
m_clientDataList.Append( (wxObject*) clientData );
m_clientObjectList.Append( (wxObject*)NULL );
AppendCommon( item );
}
void wxComboBox::Append( const wxString &item, wxClientData *clientData )
{
m_clientDataList.Append( (wxObject*) NULL );
m_clientObjectList.Append( (wxObject*) clientData );
AppendCommon( item );
}
void wxComboBox::SetClientData( int n, void* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return;
node->SetData( (wxObject*) clientData );
}
void* wxComboBox::GetClientData( int n )
{
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return NULL;
return node->Data();
}
void wxComboBox::SetClientObject( int n, wxClientData* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
wxNode *node = m_clientObjectList.Nth( n );
if (!node) return;
wxClientData *cd = (wxClientData*) node->Data();
if (cd) delete cd;
node->SetData( (wxObject*) clientData );
}
wxClientData* wxComboBox::GetClientObject( int n )
{
wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return (wxClientData*) NULL;
return (wxClientData*) node->Data();
}
void wxComboBox::Clear()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_clear_items( GTK_LIST(list), 0, Number() );
wxNode *node = m_clientObjectList.First();
while (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
node = node->Next();
}
m_clientObjectList.Clear();
m_clientDataList.Clear();
}
void wxComboBox::Delete( int n )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = g_list_nth( listbox->children, n );
if (!child)
{
wxFAIL_MSG(wxT("wrong index"));
return;
}
GList *list = g_list_append( (GList*) NULL, child->data );
gtk_list_remove_items( listbox, list );
g_list_free( list );
wxNode *node = m_clientObjectList.Nth( n );
if (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
m_clientObjectList.DeleteNode( node );
}
node = m_clientDataList.Nth( n );
if (node)
{
m_clientDataList.DeleteNode( node );
}
}
int wxComboBox::FindString( const wxString &item )
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
if (item == wxString(label->label,*wxConvCurrent))
return count;
count++;
child = child->next;
}
return wxNOT_FOUND;
}
int wxComboBox::GetSelection() const
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *selection = GTK_LIST(list)->selection;
if (selection)
{
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child)
{
if (child->data == selection->data) return count;
count++;
child = child->next;
}
}
return -1;
}
wxString wxComboBox::GetString( int n ) const
{
wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
wxString str;
GList *child = g_list_nth( GTK_LIST(list)->children, n );
if (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
str = wxString(label->label,*wxConvCurrent);
}
else
{
wxFAIL_MSG( wxT("wxComboBox: wrong index") );
}
return str;
}
wxString wxComboBox::GetStringSelection() const
{
wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *selection = GTK_LIST(list)->selection;
if (selection)
{
GtkBin *bin = GTK_BIN( selection->data );
wxString tmp = wxString(GTK_LABEL( bin->child )->label,*wxConvCurrent);
return tmp;
}
wxFAIL_MSG( wxT("wxComboBox: no selection") );
return wxT("");
}
int wxComboBox::Number() const
{
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child) { count++; child = child->next; }
return count;
}
void wxComboBox::SetSelection( int n )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
DisableEvents();
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
gtk_list_select_item( GTK_LIST(list), n );
m_prevSelection = n;
EnableEvents();
}
void wxComboBox::SetStringSelection( const wxString &string )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
int res = FindString( string );
if (res == -1) return;
SetSelection( res );
}
wxString wxComboBox::GetValue() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
wxString tmp = wxString(gtk_entry_get_text( GTK_ENTRY(entry) ),*wxConvCurrent);
return tmp;
}
void wxComboBox::SetValue( const wxString& value )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
wxString tmp = wxT("");
if (!value.IsNull()) tmp = value;
gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() );
}
void wxComboBox::Copy()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::Cut()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::Paste()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::SetInsertionPoint( long pos )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
}
void wxComboBox::SetInsertionPointEnd()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
SetInsertionPoint( -1 );
}
long wxComboBox::GetInsertionPoint() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
return (long) GTK_EDITABLE(entry)->current_pos;
}
long wxComboBox::GetLastPosition() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
int pos = GTK_ENTRY(entry)->text_length;
return (long) pos-1;
}
void wxComboBox::Replace( long from, long to, const wxString& value )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
// FIXME: not quite sure how to do this method right in multibyte mode
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
if (value.IsNull()) return;
gint pos = (gint)to;
gtk_editable_insert_text( GTK_EDITABLE(entry), value.mbc_str(), value.Length(), &pos );
}
void wxComboBox::Remove(long from, long to)
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
}
void wxComboBox::SetSelection( long from, long to )
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
}
void wxComboBox::SetEditable( bool editable )
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_entry_set_editable( GTK_ENTRY(entry), editable );
}
void wxComboBox::OnChar( wxKeyEvent &event )
{
if ( event.KeyCode() == WXK_RETURN )
{
wxString value = GetValue();
if ( Number() == 0 )
{
// make Enter generate "selected" event if there is only one item
// in the combobox - without it, it's impossible to select it at
// all!
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( 0 );
event.SetString( value );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
else
{
// add the item to the list if it's not there yet
if ( FindString(value) == wxNOT_FOUND )
{
Append(value);
SetStringSelection(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( Number() - 1 );
event.SetString( value );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
//else: do nothing, this will open the listbox
}
}
event.Skip();
}
void wxComboBox::DisableEvents()
{
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_signal_disconnect_by_func( GTK_OBJECT(child->data),
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
child = child->next;
}
}
void wxComboBox::EnableEvents()
{
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_signal_connect( GTK_OBJECT(child->data), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
child = child->next;
}
}
void wxComboBox::OnSize( wxSizeEvent &event )
{
event.Skip();
#if 0
int w = 21;
gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
#endif // 0
}
void wxComboBox::ApplyWidgetStyle()
{
SetWidgetStyle();
// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
GtkBin *bin = GTK_BIN(child->data);
gtk_widget_set_style( bin->child, m_widgetStyle );
child = child->next;
}
}
GtkWidget* wxComboBox::GetConnectWidget()
{
return GTK_COMBO(m_widget)->entry;
}
bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
{
return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
(window == GTK_COMBO(m_widget)->button->window ) );
}
wxSize wxComboBox::DoGetBestSize() const
{
wxSize ret( wxControl::DoGetBestSize() );
// we know better our horizontal extent: it depends on the longest string
// in the combobox
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
size_t count = Number();
for ( size_t n = 0; n < count; n++ )
{
width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str());
if ( width > ret.x )
ret.x = width;
}
}
// empty combobox should have some reasonable default size too
if ( ret.x < 100 )
ret.x = 100;
return ret;
}
#endif

File diff suppressed because it is too large Load Diff

122
src/gtk/statbmp.cpp Normal file
View File

@@ -0,0 +1,122 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statbmp.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statbmp.h"
#endif
#include "wx/defs.h"
#if wxUSE_STATBMP
#include "wx/statbmp.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// wxStaticBitmap
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
wxStaticBitmap::wxStaticBitmap(void)
{
}
wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
Create( parent, id, bitmap, pos, size, style, name );
}
void wxStaticBitmap::CreatePixmapWidget()
{
wxCHECK_RET( m_bitmap.Ok(), wxT("should only be called if we have a bitmap") );
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
/* insert GTK representation */
(*m_parent->m_insertCallback)(m_parent, this);
gtk_widget_show( m_widget );
PostCreation();
}
bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
m_needParent = TRUE;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxXX creation failed") );
return FALSE;
}
m_bitmap = bitmap;
if (m_bitmap.Ok())
{
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
SetBestSize( size );
}
else
{
m_widget = gtk_label_new( "Bitmap" );
PostCreation();
}
m_parent->DoAddChild( this );
Show( TRUE );
return TRUE;
}
void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
{
bool hasWidget = m_bitmap.Ok();
m_bitmap = bitmap;
if (m_bitmap.Ok())
{
if (!hasWidget)
{
gtk_widget_destroy( m_widget );
/* recreate m_widget because we've created a label
and not a bitmap above */
CreatePixmapWidget();
}
else
{
GdkBitmap *mask = (GdkBitmap *) NULL;
if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
}
SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
}
}
#endif // wxUSE_STATBMP

1468
src/gtk/textctrl.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

715
src/gtk1/combobox.cpp Normal file
View File

@@ -0,0 +1,715 @@
/////////////////////////////////////////////////////////////////////////////
// Name: combobox.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "combobox.h"
#endif
#include "wx/combobox.h"
#if wxUSE_COMBOBOX
#include "wx/settings.h"
#include "wx/intl.h"
#include "wx/textctrl.h" // for wxEVT_COMMAND_TEXT_UPDATED
#include <gdk/gdk.h>
#include <gtk/gtk.h>
//-----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//-----------------------------------------------------------------------------
// "select"
//-----------------------------------------------------------------------------
static void
gtk_combo_clicked_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
{
if (g_isIdle) wxapp_install_idle_handler();
if (!combo->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
if (combo->m_alreadySent)
{
combo->m_alreadySent = FALSE;
return;
}
combo->m_alreadySent = TRUE;
int curSelection = combo->GetSelection();
if (combo->m_prevSelection != curSelection)
{
GtkWidget *list = GTK_COMBO(combo->m_widget)->list;
gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection );
}
combo->m_prevSelection = curSelection;
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, combo->GetId() );
event.SetInt( curSelection );
event.SetString( combo->GetStringSelection() );
event.SetEventObject( combo );
combo->GetEventHandler()->ProcessEvent( event );
}
//-----------------------------------------------------------------------------
// "changed"
//-----------------------------------------------------------------------------
static void
gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo )
{
if (g_isIdle) wxapp_install_idle_handler();
if (!combo->m_hasVMT) return;
wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() );
event.SetString( combo->GetValue() );
event.SetEventObject( combo );
combo->GetEventHandler()->ProcessEvent( event );
}
//-----------------------------------------------------------------------------
// wxComboBox
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl)
BEGIN_EVENT_TABLE(wxComboBox, wxControl)
EVT_SIZE(wxComboBox::OnSize)
EVT_CHAR(wxComboBox::OnChar)
END_EVENT_TABLE()
bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
const wxPoint& pos, const wxSize& size,
int n, const wxString choices[],
long style, const wxValidator& validator,
const wxString& name )
{
m_alreadySent = FALSE;
m_needParent = TRUE;
m_acceptsFocus = TRUE;
m_prevSelection = 0;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, validator, name ))
{
wxFAIL_MSG( wxT("wxComboBox creation failed") );
return FALSE;
}
m_widget = gtk_combo_new();
// make it more useable
gtk_combo_set_use_arrows_always( GTK_COMBO(m_widget), TRUE );
// and case-sensitive
gtk_combo_set_case_sensitive( GTK_COMBO(m_widget), TRUE );
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_set_selection_mode( GTK_LIST(list), GTK_SELECTION_MULTIPLE );
for (int i = 0; i < n; i++)
{
/* don't send first event, which GTK sends aways when
inserting the first item */
m_alreadySent = TRUE;
GtkWidget *list_item = gtk_list_item_new_with_label( choices[i].mbc_str() );
m_clientDataList.Append( (wxObject*)NULL );
m_clientObjectList.Append( (wxObject*)NULL );
gtk_container_add( GTK_CONTAINER(list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
gtk_widget_show( list_item );
}
m_parent->DoAddChild( this );
PostCreation();
ConnectWidget( GTK_COMBO(m_widget)->button );
if (!value.IsNull()) SetValue( value );
if (style & wxCB_READONLY)
gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE );
gtk_signal_connect( GTK_OBJECT(GTK_COMBO(m_widget)->entry), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
wxSize size_best( DoGetBestSize() );
wxSize new_size( size );
if (new_size.x == -1)
new_size.x = size_best.x;
if (new_size.y == -1)
new_size.y = size_best.y;
if (new_size.y > size_best.y)
new_size.y = size_best.y;
if ((new_size.x != size.x) || (new_size.y != size.y))
SetSize( new_size.x, new_size.y );
SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW ) );
SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE );
return TRUE;
}
wxComboBox::~wxComboBox()
{
wxNode *node = m_clientObjectList.First();
while (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
node = node->Next();
}
m_clientObjectList.Clear();
m_clientDataList.Clear();
}
void wxComboBox::AppendCommon( const wxString &item )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GtkWidget *list_item = gtk_list_item_new_with_label( item.mbc_str() );
gtk_container_add( GTK_CONTAINER(list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
if (GTK_WIDGET_REALIZED(m_widget))
{
gtk_widget_realize( list_item );
gtk_widget_realize( GTK_BIN(list_item)->child );
if (m_widgetStyle) ApplyWidgetStyle();
}
gtk_widget_show( list_item );
}
void wxComboBox::Append( const wxString &item )
{
m_clientDataList.Append( (wxObject*) NULL );
m_clientObjectList.Append( (wxObject*) NULL );
AppendCommon( item );
}
void wxComboBox::Append( const wxString &item, void *clientData )
{
m_clientDataList.Append( (wxObject*) clientData );
m_clientObjectList.Append( (wxObject*)NULL );
AppendCommon( item );
}
void wxComboBox::Append( const wxString &item, wxClientData *clientData )
{
m_clientDataList.Append( (wxObject*) NULL );
m_clientObjectList.Append( (wxObject*) clientData );
AppendCommon( item );
}
void wxComboBox::SetClientData( int n, void* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return;
node->SetData( (wxObject*) clientData );
}
void* wxComboBox::GetClientData( int n )
{
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return NULL;
return node->Data();
}
void wxComboBox::SetClientObject( int n, wxClientData* clientData )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
wxNode *node = m_clientObjectList.Nth( n );
if (!node) return;
wxClientData *cd = (wxClientData*) node->Data();
if (cd) delete cd;
node->SetData( (wxObject*) clientData );
}
wxClientData* wxComboBox::GetClientObject( int n )
{
wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
wxNode *node = m_clientDataList.Nth( n );
if (!node) return (wxClientData*) NULL;
return (wxClientData*) node->Data();
}
void wxComboBox::Clear()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_clear_items( GTK_LIST(list), 0, Number() );
wxNode *node = m_clientObjectList.First();
while (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
node = node->Next();
}
m_clientObjectList.Clear();
m_clientDataList.Clear();
}
void wxComboBox::Delete( int n )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkList *listbox = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = g_list_nth( listbox->children, n );
if (!child)
{
wxFAIL_MSG(wxT("wrong index"));
return;
}
GList *list = g_list_append( (GList*) NULL, child->data );
gtk_list_remove_items( listbox, list );
g_list_free( list );
wxNode *node = m_clientObjectList.Nth( n );
if (node)
{
wxClientData *cd = (wxClientData*)node->Data();
if (cd) delete cd;
m_clientObjectList.DeleteNode( node );
}
node = m_clientDataList.Nth( n );
if (node)
{
m_clientDataList.DeleteNode( node );
}
}
int wxComboBox::FindString( const wxString &item )
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
if (item == wxString(label->label,*wxConvCurrent))
return count;
count++;
child = child->next;
}
return wxNOT_FOUND;
}
int wxComboBox::GetSelection() const
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *selection = GTK_LIST(list)->selection;
if (selection)
{
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child)
{
if (child->data == selection->data) return count;
count++;
child = child->next;
}
}
return -1;
}
wxString wxComboBox::GetString( int n ) const
{
wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
wxString str;
GList *child = g_list_nth( GTK_LIST(list)->children, n );
if (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkLabel *label = GTK_LABEL( bin->child );
str = wxString(label->label,*wxConvCurrent);
}
else
{
wxFAIL_MSG( wxT("wxComboBox: wrong index") );
}
return str;
}
wxString wxComboBox::GetStringSelection() const
{
wxCHECK_MSG( m_widget != NULL, wxT(""), wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *selection = GTK_LIST(list)->selection;
if (selection)
{
GtkBin *bin = GTK_BIN( selection->data );
wxString tmp = wxString(GTK_LABEL( bin->child )->label,*wxConvCurrent);
return tmp;
}
wxFAIL_MSG( wxT("wxComboBox: no selection") );
return wxT("");
}
int wxComboBox::Number() const
{
wxCHECK_MSG( m_widget != NULL, 0, wxT("invalid combobox") );
GtkWidget *list = GTK_COMBO(m_widget)->list;
GList *child = GTK_LIST(list)->children;
int count = 0;
while (child) { count++; child = child->next; }
return count;
}
void wxComboBox::SetSelection( int n )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
DisableEvents();
GtkWidget *list = GTK_COMBO(m_widget)->list;
gtk_list_unselect_item( GTK_LIST(list), m_prevSelection );
gtk_list_select_item( GTK_LIST(list), n );
m_prevSelection = n;
EnableEvents();
}
void wxComboBox::SetStringSelection( const wxString &string )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
int res = FindString( string );
if (res == -1) return;
SetSelection( res );
}
wxString wxComboBox::GetValue() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
wxString tmp = wxString(gtk_entry_get_text( GTK_ENTRY(entry) ),*wxConvCurrent);
return tmp;
}
void wxComboBox::SetValue( const wxString& value )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
wxString tmp = wxT("");
if (!value.IsNull()) tmp = value;
gtk_entry_set_text( GTK_ENTRY(entry), tmp.mbc_str() );
}
void wxComboBox::Copy()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_copy_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_copy_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::Cut()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_cut_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_cut_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::Paste()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
#if defined(__WXGTK13__) || (GTK_MINOR_VERSION > 0)
gtk_editable_paste_clipboard( GTK_EDITABLE(entry) );
#else
gtk_editable_paste_clipboard( GTK_EDITABLE(entry), 0 );
#endif
}
void wxComboBox::SetInsertionPoint( long pos )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_entry_set_position( GTK_ENTRY(entry), (int)pos );
}
void wxComboBox::SetInsertionPointEnd()
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
SetInsertionPoint( -1 );
}
long wxComboBox::GetInsertionPoint() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
return (long) GTK_EDITABLE(entry)->current_pos;
}
long wxComboBox::GetLastPosition() const
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
int pos = GTK_ENTRY(entry)->text_length;
return (long) pos-1;
}
void wxComboBox::Replace( long from, long to, const wxString& value )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
// FIXME: not quite sure how to do this method right in multibyte mode
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
if (value.IsNull()) return;
gint pos = (gint)to;
gtk_editable_insert_text( GTK_EDITABLE(entry), value.mbc_str(), value.Length(), &pos );
}
void wxComboBox::Remove(long from, long to)
{
wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_delete_text( GTK_EDITABLE(entry), (gint)from, (gint)to );
}
void wxComboBox::SetSelection( long from, long to )
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to );
}
void wxComboBox::SetEditable( bool editable )
{
GtkWidget *entry = GTK_COMBO(m_widget)->entry;
gtk_entry_set_editable( GTK_ENTRY(entry), editable );
}
void wxComboBox::OnChar( wxKeyEvent &event )
{
if ( event.KeyCode() == WXK_RETURN )
{
wxString value = GetValue();
if ( Number() == 0 )
{
// make Enter generate "selected" event if there is only one item
// in the combobox - without it, it's impossible to select it at
// all!
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( 0 );
event.SetString( value );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
else
{
// add the item to the list if it's not there yet
if ( FindString(value) == wxNOT_FOUND )
{
Append(value);
SetStringSelection(value);
// and generate the selected event for it
wxCommandEvent event( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
event.SetInt( Number() - 1 );
event.SetString( value );
event.SetEventObject( this );
GetEventHandler()->ProcessEvent( event );
}
//else: do nothing, this will open the listbox
}
}
event.Skip();
}
void wxComboBox::DisableEvents()
{
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_signal_disconnect_by_func( GTK_OBJECT(child->data),
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
child = child->next;
}
}
void wxComboBox::EnableEvents()
{
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_signal_connect( GTK_OBJECT(child->data), "select",
GTK_SIGNAL_FUNC(gtk_combo_clicked_callback), (gpointer)this );
child = child->next;
}
}
void wxComboBox::OnSize( wxSizeEvent &event )
{
event.Skip();
#if 0
int w = 21;
gtk_widget_set_usize( GTK_COMBO(m_widget)->entry, m_width-w-1, m_height );
gtk_widget_set_uposition( GTK_COMBO(m_widget)->button, m_x+m_width-w, m_y );
gtk_widget_set_usize( GTK_COMBO(m_widget)->button, w, m_height );
#endif // 0
}
void wxComboBox::ApplyWidgetStyle()
{
SetWidgetStyle();
// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle );
gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle );
gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle );
GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list );
GList *child = list->children;
while (child)
{
gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle );
GtkBin *bin = GTK_BIN(child->data);
gtk_widget_set_style( bin->child, m_widgetStyle );
child = child->next;
}
}
GtkWidget* wxComboBox::GetConnectWidget()
{
return GTK_COMBO(m_widget)->entry;
}
bool wxComboBox::IsOwnGtkWindow( GdkWindow *window )
{
return ( (window == GTK_ENTRY( GTK_COMBO(m_widget)->entry )->text_area) ||
(window == GTK_COMBO(m_widget)->button->window ) );
}
wxSize wxComboBox::DoGetBestSize() const
{
wxSize ret( wxControl::DoGetBestSize() );
// we know better our horizontal extent: it depends on the longest string
// in the combobox
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
size_t count = Number();
for ( size_t n = 0; n < count; n++ )
{
width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str());
if ( width > ret.x )
ret.x = width;
}
}
// empty combobox should have some reasonable default size too
if ( ret.x < 100 )
ret.x = 100;
return ret;
}
#endif

File diff suppressed because it is too large Load Diff

122
src/gtk1/statbmp.cpp Normal file
View File

@@ -0,0 +1,122 @@
/////////////////////////////////////////////////////////////////////////////
// Name: statbmp.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "statbmp.h"
#endif
#include "wx/defs.h"
#if wxUSE_STATBMP
#include "wx/statbmp.h"
#include "gdk/gdk.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// wxStaticBitmap
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
wxStaticBitmap::wxStaticBitmap(void)
{
}
wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
Create( parent, id, bitmap, pos, size, style, name );
}
void wxStaticBitmap::CreatePixmapWidget()
{
wxCHECK_RET( m_bitmap.Ok(), wxT("should only be called if we have a bitmap") );
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
/* insert GTK representation */
(*m_parent->m_insertCallback)(m_parent, this);
gtk_widget_show( m_widget );
PostCreation();
}
bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
const wxPoint &pos, const wxSize &size,
long style, const wxString &name )
{
m_needParent = TRUE;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxXX creation failed") );
return FALSE;
}
m_bitmap = bitmap;
if (m_bitmap.Ok())
{
GdkBitmap *mask = (GdkBitmap *) NULL;
if ( m_bitmap.GetMask() )
mask = m_bitmap.GetMask()->GetBitmap();
m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
SetBestSize( size );
}
else
{
m_widget = gtk_label_new( "Bitmap" );
PostCreation();
}
m_parent->DoAddChild( this );
Show( TRUE );
return TRUE;
}
void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
{
bool hasWidget = m_bitmap.Ok();
m_bitmap = bitmap;
if (m_bitmap.Ok())
{
if (!hasWidget)
{
gtk_widget_destroy( m_widget );
/* recreate m_widget because we've created a label
and not a bitmap above */
CreatePixmapWidget();
}
else
{
GdkBitmap *mask = (GdkBitmap *) NULL;
if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
}
SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
}
}
#endif // wxUSE_STATBMP

1468
src/gtk1/textctrl.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff