/[pcsx2_0.9.7]/trunk/common/include/Utilities/wxGuiTools.h
ViewVC logotype

Diff of /trunk/common/include/Utilities/wxGuiTools.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/common/include/Utilities/wxGuiTools.h	2010/09/07 03:24:11	31
+++ trunk/common/include/Utilities/wxGuiTools.h	2010/09/07 11:08:22	62
@@ -15,6 +15,16 @@
 
 #pragma once
 
+// ----------------------------------------------------------------------------
+// wxGuiTools.h
+//
+// This file is meant to contain utility classes for users of the wxWidgets library.
+// All classes in this file are dependent on wxBase and wxCore libraries!  Meaning
+// you will have to use wxCore header files and link against wxCore (GUI) to build
+// them.  For tools which require only wxBase, see wxBaseTools.h
+// ----------------------------------------------------------------------------
+
+
 #if wxUSE_GUI
 
 #include "Dependencies.h"
@@ -28,6 +38,19 @@
 class pxCheckBox;
 class wxSpinCtrl;
 
+namespace pxSizerFlags
+{
+	static const int StdPadding = 4;
+
+	extern wxSizerFlags StdSpace();
+	extern wxSizerFlags StdCenter();
+	extern wxSizerFlags StdExpand();
+	extern wxSizerFlags TopLevelBox();
+	extern wxSizerFlags SubGroup();
+	extern wxSizerFlags StdButton();
+	extern wxSizerFlags Checkbox();
+};
+
 #define wxSF		wxSizerFlags()
 
 // --------------------------------------------------------------------------------------
@@ -58,6 +81,11 @@
 		return Apply( _flgs );
 	}
 
+	wxSizerFlags Expand() const
+	{
+		return Apply().Expand();
+	}
+
 	wxSizerFlags Border( int dir, int padding ) const
 	{
 		return Apply().Border( dir, padding );
@@ -110,12 +138,12 @@
 	}
 };
 
-static __forceinline wxSizerFlags pxProportion( int prop )
+static __fi wxSizerFlags pxProportion( int prop )
 {
 	return wxSizerFlags( prop );
 }
 
-static __forceinline wxSizerFlags pxBorder( int dir, int pad )
+static __fi wxSizerFlags pxBorder( int dir=wxALL, int pad=pxSizerFlags::StdPadding )
 {
 	return wxSizerFlags().Border( dir, pad );
 }
@@ -269,33 +297,226 @@
 	target->Add( src.window, src.flags );
 }
 
-// ----------------------------------------------------------------------------
-// wxGuiTools.h
-//
-// This file is meant to contain utility classes for users of the wxWidgets library.
-// All classes in this file are dependent on wxBase and wxCore libraries!  Meaning
-// you will have to use wxCore header files and link against wxCore (GUI) to build
-// them.  For tools which require only wxBase, see wxBaseTools.h
-// ----------------------------------------------------------------------------
-
-namespace pxSizerFlags
-{
-	static const int StdPadding = 5;
-
-	extern wxSizerFlags StdSpace();
-	extern wxSizerFlags StdCenter();
-	extern wxSizerFlags StdExpand();
-	extern wxSizerFlags TopLevelBox();
-	extern wxSizerFlags SubGroup();
-	extern wxSizerFlags StdButton();
-	extern wxSizerFlags Checkbox();
-};
 
 BEGIN_DECLARE_EVENT_TYPES()
 	// Added to the event queue by pxDialogWithHelpers
 	DECLARE_EVENT_TYPE( pxEvt_OnDialogCreated, -1 )
 END_DECLARE_EVENT_TYPES()
 
+
+// --------------------------------------------------------------------------------------
+//  pxDialogCreationFlags
+// --------------------------------------------------------------------------------------
+class pxDialogCreationFlags
+{
+public:
+	wxSize			MinimumSize;
+	wxOrientation	BoxSizerOrient;
+
+	bool			isResizable;
+	bool			hasContextHelp;
+	bool			hasCaption;
+	bool			hasMinimizeBox;
+	bool			hasMaximizeBox;
+	bool			hasSystemMenu;
+	bool			hasCloseBox;
+
+public:
+	virtual ~pxDialogCreationFlags() throw() {}
+	
+	pxDialogCreationFlags()
+	{
+		MinimumSize		= wxDefaultSize;
+		BoxSizerOrient	= wxVERTICAL;
+		isResizable		= false;
+		hasContextHelp	= false;
+
+		hasCloseBox		= true;
+		hasSystemMenu	= true;
+		hasMinimizeBox	= false;
+		hasMaximizeBox	= false;
+		hasCaption		= true;
+	}
+
+	pxDialogCreationFlags& SetSizerOrient( wxOrientation orient )
+	{
+		BoxSizerOrient = orient;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetResize( bool enable=true )
+	{
+		isResizable = enable;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetMinimize( bool enable=true )
+	{
+		hasMinimizeBox = enable;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetMaximize( bool enable=true )
+	{
+		hasMaximizeBox = enable;
+		return *this;
+	}
+
+	// NOTE: Enabling system menu on dialogs usually doesn't work, and might cause
+	// other unwanted behavior, such as a missing close button.
+	pxDialogCreationFlags& SetSystemMenu( bool enable=true )
+	{
+		hasSystemMenu = enable;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetCaption( bool enable=true )
+	{
+		hasCaption = enable;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetCloseBox( bool enable=true )
+	{
+		hasCloseBox = enable;
+		return *this;
+	}
+
+	pxDialogCreationFlags SetContextHelp( bool enabled=true )
+	{
+		hasContextHelp = enabled;
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetMinWidth( int width )
+	{
+		if( width > MinimumSize.x ) MinimumSize.SetWidth( width );
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetMinHeight( int height )
+	{
+		if( height > MinimumSize.y ) MinimumSize.SetHeight( height );
+		return *this;
+	}
+
+	pxDialogCreationFlags& SetMinSize( const wxSize& size )
+	{
+		return SetMinWidth(size.x).SetMinHeight(size.y);
+	}
+
+
+	pxDialogCreationFlags Horizontal() const
+	{
+		return pxDialogCreationFlags(*this).SetSizerOrient( wxHORIZONTAL );
+	}
+
+	pxDialogCreationFlags Vertical() const
+	{
+		return pxDialogCreationFlags(*this).SetSizerOrient( wxVERTICAL );
+	}
+	
+	pxDialogCreationFlags NoSizer() const
+	{
+		return pxDialogCreationFlags(*this).SetSizerOrient( (wxOrientation)0 );
+	}
+
+	pxDialogCreationFlags Resize( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetResize( enable );
+	}
+
+	pxDialogCreationFlags Minimize( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetMinimize( enable );
+	}
+
+	pxDialogCreationFlags Maximize( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetMaximize( enable );
+	}
+
+	// NOTE: Enabling system menu on dialogs usually doesn't work, and might cause
+	// other unwanted behavior, such as a missing close button.
+	pxDialogCreationFlags SystemMenu( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetSystemMenu( false );
+	}
+
+	pxDialogCreationFlags Caption( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetCaption( enable );
+	}
+
+	pxDialogCreationFlags CloseBox( bool enable=true ) const
+	{
+		return pxDialogCreationFlags(*this).SetCloseBox( enable );
+	}
+
+	pxDialogCreationFlags NoResize() const
+	{
+		return pxDialogCreationFlags(*this).SetResize( false );
+	}
+
+	pxDialogCreationFlags NoMinimize() const
+	{
+		return pxDialogCreationFlags(*this).SetMinimize( false );
+	}
+
+	pxDialogCreationFlags NoMaximize() const
+	{
+		return pxDialogCreationFlags(*this).SetMaximize( false );
+	}
+
+	pxDialogCreationFlags NoSystemMenu() const
+	{
+		return pxDialogCreationFlags(*this).SetSystemMenu( false );
+	}
+
+	pxDialogCreationFlags NoCaption() const
+	{
+		return pxDialogCreationFlags(*this).SetCaption( false );
+	}
+
+	pxDialogCreationFlags NoCloseBox() const
+	{
+		return pxDialogCreationFlags(*this).SetCloseBox( false );
+	}
+
+	pxDialogCreationFlags MinWidth( int width ) const
+	{
+		return pxDialogCreationFlags(*this).SetMinWidth( width );
+	}
+
+	pxDialogCreationFlags MinHeight( int height ) const
+	{
+		return pxDialogCreationFlags(*this).SetMinHeight( height );
+	}
+
+	pxDialogCreationFlags MinSize( const wxSize& size ) const
+	{
+		return pxDialogCreationFlags(*this).SetMinSize( size );
+	}
+
+	pxDialogCreationFlags MinSize( int width, int height ) const
+	{
+		return pxDialogCreationFlags(*this).SetMinWidth( width ).SetMinHeight( height );
+	}
+	
+	int GetWxWindowFlags() const
+	{
+		int retval = 0;
+		if( isResizable )		retval |= wxRESIZE_BORDER;
+		if( hasCaption )		retval |= wxCAPTION;
+		if( hasMaximizeBox )	retval |= wxMAXIMIZE_BOX;
+		if( hasMinimizeBox )	retval |= wxMINIMIZE_BOX;
+		if( hasSystemMenu )		retval |= wxSYSTEM_MENU;
+		if( hasCloseBox )		retval |= wxCLOSE_BOX;
+		
+		return retval;
+	}
+};
+
 // --------------------------------------------------------------------------------------
 //  wxDialogWithHelpers
 // --------------------------------------------------------------------------------------
@@ -305,16 +526,15 @@
 
 protected:
 	bool				m_hasContextHelp;
-	int					m_idealWidth;
 	wxBoxSizer*			m_extraButtonSizer;
-	
+	wxRect				m_CreatedRect;
+
 public:
 	wxDialogWithHelpers();
-	wxDialogWithHelpers(wxWindow* parent, const wxString& title, bool hasContextHelp=false, bool resizable=false );
-	wxDialogWithHelpers(wxWindow* parent, const wxString& title, wxOrientation orient);
+	wxDialogWithHelpers(wxWindow* parent, const wxString& title, const pxDialogCreationFlags& cflags = pxDialogCreationFlags() );
 	virtual ~wxDialogWithHelpers() throw();
 
-    void Init();
+    void Init( const pxDialogCreationFlags& cflags );
 	void AddOkCancel( wxSizer& sizer, bool hasApply=false );
 	void AddOkCancel( wxSizer* sizer=NULL, bool hasApply=false );
 
@@ -328,18 +548,23 @@
 	// screenshots to disk)
 	virtual wxString GetDialogName() const;
 
-	virtual pxStaticText*		Text( const wxString& label );
-	virtual pxStaticHeading*	Heading( const wxString& label );
-
-	virtual wxDialogWithHelpers& SetIdealWidth( int newWidth ) { m_idealWidth = newWidth; return *this; }
+	virtual wxStaticText&	Label( const wxString& label );
+	virtual pxStaticText&	Text( const wxString& label );
+	virtual pxStaticText&	Heading( const wxString& label );
 
-	int GetIdealWidth() const { return m_idealWidth; }
-	bool HasIdealWidth() const { return m_idealWidth != wxDefaultCoord; }
+	wxDialogWithHelpers& SetMinWidth( int newWidth );
+	wxDialogWithHelpers& SetMinHeight( int newHeight );
+	
+	int GetCharHeight() const;
 
 protected:
 	void OnDialogCreated( wxCommandEvent& evt );
 	void OnOkCancel(wxCommandEvent& evt);
 	void OnCloseWindow(wxCloseEvent& event);
+
+	bool ShouldPreventAppExit() const { return false; }
+
+	void DoAutoCenter();
 };
 
 // --------------------------------------------------------------------------------------
@@ -363,9 +588,6 @@
 {
 	DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanelWithHelpers)
 
-protected:
-	int		m_idealWidth;
-
 public:
 	wxPanelWithHelpers( wxWindow* parent, wxOrientation orient, const wxString& staticBoxLabel );
 	wxPanelWithHelpers( wxWindow* parent, wxOrientation orient );
@@ -374,13 +596,11 @@
 
 	wxPanelWithHelpers* AddFrame( const wxString& label, wxOrientation orient=wxVERTICAL );
 
-	pxStaticText*		Text( const wxString& label );
-	pxStaticHeading*	Heading( const wxString& label );
+	wxStaticText&	Label( const wxString& label );
+	pxStaticText&	Text( const wxString& label );
+	pxStaticText&	Heading( const wxString& label );
 
-	// TODO : Propagate to children?
-	wxPanelWithHelpers& SetIdealWidth( int width ) { m_idealWidth = width;  return *this; }
-	int GetIdealWidth() const { return m_idealWidth; }
-	bool HasIdealWidth() const { return m_idealWidth != wxDefaultCoord; }
+	virtual wxPanelWithHelpers& SetMinWidth( int newWidth );
 
 protected:
 	void Init();
@@ -401,13 +621,15 @@
 class pxTextWrapperBase
 {
 protected:
-	bool	m_eol;
-	int		m_linecount;
+	bool		m_eol;
+	int			m_linecount;
+	wxString	m_indent;
 
 public:
 	virtual ~pxTextWrapperBase() throw() { }
 
-    pxTextWrapperBase()
+    pxTextWrapperBase( const wxString& indent=wxEmptyString )
+		: m_indent( indent )
 	{
 		m_eol = false;
 		m_linecount = 0;
@@ -444,10 +666,13 @@
 	typedef pxTextWrapperBase _parent;
 
 protected:
-	wxString m_text;
+	wxString	m_text;
 
 public:
-	pxTextWrapper() : pxTextWrapperBase() { }
+	pxTextWrapper( const wxString& wrapPrefix=wxEmptyString )
+		: pxTextWrapperBase( wrapPrefix )
+	{ }
+
 	virtual ~pxTextWrapper() throw() { }
 
     const wxString& GetResult() const
@@ -456,10 +681,11 @@
     }
 
 	pxTextWrapper& Wrap( const wxWindow& win, const wxString& text, int widthMax );
+	pxTextWrapper& Wrap( const wxWindow* win, const wxString& text, int widthMax );
 
 protected:
-    virtual void OnOutputLine(const wxString& line);
-    virtual void OnNewLine();
+    void OnOutputLine(const wxString& line);
+    void OnNewLine();
 };
 
 // --------------------------------------------------------------------------------------
@@ -478,25 +704,14 @@
 	void _DoWrite( const wxChar* msg );
 
 public:
-	pxWindowTextWriter( wxDC& dc )
-		: m_dc( dc )
-	{
-		m_curpos = wxPoint();
-		m_align = wxALIGN_CENTER;
-		m_leading = 2;
-		
-		OnFontChanged();	
-	}
-
-	virtual ~pxWindowTextWriter() throw()
-	{
-	
-	}
+	pxWindowTextWriter( wxDC& dc );
+	virtual ~pxWindowTextWriter() throw() { }
 	
 	virtual void OnFontChanged();
 
 	pxWindowTextWriter& WriteLn();
-	pxWindowTextWriter& WriteLn( const wxChar* fmt, ... );
+	pxWindowTextWriter& FormatLn( const wxChar* fmt, ... );
+	pxWindowTextWriter& WriteLn( const wxChar* fmt );
 	pxWindowTextWriter& SetFont( const wxFont& font );
 	pxWindowTextWriter& Align( const wxAlignment& align );
 		
@@ -590,7 +805,7 @@
 
 extern void pxFitToDigits( wxWindow* win, int digits );
 extern void pxFitToDigits( wxSpinCtrl* win, int digits );
-extern wxTextCtrl* CreateNumericalTextCtrl( wxWindow* parent, int digits );
+extern wxTextCtrl* CreateNumericalTextCtrl( wxWindow* parent, int digits, long flags = wxTE_RIGHT );
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////
@@ -598,11 +813,16 @@
 extern bool pxDialogExists( const wxString& name );
 extern bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos );
 extern wxRect wxGetDisplayArea();
+extern wxString pxGetAppName();
+
+extern int pxGetCharHeight( const wxWindow* wind, int rows=1 );
+extern int pxGetCharHeight( const wxWindow& wind, int rows=1 );
 
 extern wxString pxFormatToolTipText( wxWindow* wind, const wxString& src );
 extern void pxSetToolTip( wxWindow* wind, const wxString& src );
 extern void pxSetToolTip( wxWindow& wind, const wxString& src );
 extern wxFont pxGetFixedFont( int ptsize=8, int weight=wxNORMAL );
 
+extern pxDialogCreationFlags pxDialogFlags();
 
 #endif

 

  ViewVC Help
Powered by ViewVC 1.1.22