From 255792efdbcda6b1f2b6cd154f8962ca226e5805 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 14 Aug 2000 19:08:46 +0000 Subject: [PATCH] more files added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8103 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/univ/control.h | 46 +++++++++++ include/wx/univ/stattext.h | 60 ++++++++++++++ src/univ/control.cpp | 79 +++++++++++++++++++ src/univ/files.lst | 6 ++ src/univ/stattext.cpp | 155 +++++++++++++++++++++++++++++++++++++ src/univ/theme.cpp | 98 +++++++++++++++++++++++ 6 files changed, 444 insertions(+) create mode 100644 include/wx/univ/control.h create mode 100644 include/wx/univ/stattext.h create mode 100644 src/univ/control.cpp create mode 100644 src/univ/files.lst create mode 100644 src/univ/stattext.cpp create mode 100644 src/univ/theme.cpp diff --git a/include/wx/univ/control.h b/include/wx/univ/control.h new file mode 100644 index 0000000000..c1b5b347be --- /dev/null +++ b/include/wx/univ/control.h @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/univ/control.h +// Purpose: universal wxControl: adds handling of mnemonics +// Author: Vadim Zeitlin +// Modified by: +// Created: 14.08.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_UNIV_CONTROL_H_ +#define _WX_UNIV_CONTROL_H_ + +#ifdef __GNUG__ + #pragma interface "control.h" +#endif + +class WXDLLEXPORT wxControl : public wxControlBase +{ +public: + wxControl(); + + wxControl(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxControlNameStr) + { + Create(parent, id, pos, size, style, validator, name); + } + + // this function will filter out '&' characters and will put the + // accelerator char (the one immediately after '&') into m_chAccel + virtual void SetLabel(const wxString &label); + virtual wxString GetLabel() const; + +protected: + wxString m_label; + wxChar m_chAccel; + +private: + DECLARE_DYNAMIC_CLASS(wxControl) +}; + +#endif // _WX_UNIV_CONTROL_H_ diff --git a/include/wx/univ/stattext.h b/include/wx/univ/stattext.h new file mode 100644 index 0000000000..b992c0524a --- /dev/null +++ b/include/wx/univ/stattext.h @@ -0,0 +1,60 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/univ/stattext.h +// Purpose: wxStaticText +// Author: Vadim Zeitlin +// Modified by: +// Created: 14.08.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_UNIV_STATTEXT_H_ +#define _WX_UNIV_STATTEXT_H_ + +#ifdef __GNUG__ + #pragma interface "stattext.h" +#endif + +class WXDLLEXPORT wxStaticText : wxStaticTextBase +{ +public: + // usual ctor + wxStaticText(wxWindow *parent, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize) + { + Create(parent, -1, label, pos, size, 0, wxStaticTextNameStr); + } + + // full form + wxStaticText(wxWindow *parent, + wxWindowID id, + const wxString& label, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString &name = wxStaticTextNameStr) + { + Create(parent, id, label, pos, size, style, name); + } + + // function ctor + bool Create(wxWindow *parent, + wxWindowID id, + const wxString &label, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = 0, + const wxString &name = wxStaticTextNameStr); + +protected: + // calculate the optimal size for the label + virtual wxSize DoGetBestSize() const; + + // draw the control + virtual void DoDraw(wxDC& dc, wxRenderer *renderer); +}; + +#endif // _WX_UNIV_STATTEXT_H_ diff --git a/src/univ/control.cpp b/src/univ/control.cpp new file mode 100644 index 0000000000..7df9b6fbc0 --- /dev/null +++ b/src/univ/control.cpp @@ -0,0 +1,79 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/univ/control.cpp +// Purpose: universal wxControl: adds handling of mnemonics +// Author: Vadim Zeitlin +// Modified by: +// Created: 14.08.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +#ifdef __GNUG__ + #pragma implementation "control.h" +#endif + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_CONTROLS + +#ifndef WX_PRECOMP + #include "wx/control.h" +#endif + +// ============================================================================ +// implementation +// ============================================================================ + +IMPLEMENT_DYNAMIC_CLASS(wxControl, wxWindow) + +// ---------------------------------------------------------------------------- +// creation +// ---------------------------------------------------------------------------- + +wxControl::wxControl() +{ +} + +// ---------------------------------------------------------------------------- +// mnemonics handling +// ---------------------------------------------------------------------------- + +void wxControl::SetLabel( const wxString &label ) +{ + // the character following MNEMONIC_PREFIX is the accelerator for this + // control unless it is MNEMONIC_PREFIX too - this allows to insert + // literal MNEMONIC_PREFIX chars into the label + static const wxChar MNEMONIC_PREFIX = _T('&'); + + m_label.Empty(); + for ( const wxChar *pc = label; *pc != wxT('\0'); pc++ ) + { + if ( *pc == MNEMONIC_PREFIX ) + { + pc++; // skip it + if ( *pc != MNEMONIC_PREFIX ) + m_chAccel = *pc; + } + m_label << *pc; + } +} + +wxString wxControl::GetLabel() const +{ + return m_label; +} + +#endif // wxUSE_CONTROLS diff --git a/src/univ/files.lst b/src/univ/files.lst new file mode 100644 index 0000000000..2de9af461a --- /dev/null +++ b/src/univ/files.lst @@ -0,0 +1,6 @@ +UNIVOBJS = winuniv.o \ + control.o \ + stattext.o \ + theme.o + +# themes/win32.cpp diff --git a/src/univ/stattext.cpp b/src/univ/stattext.cpp new file mode 100644 index 0000000000..5293eaa4e1 --- /dev/null +++ b/src/univ/stattext.cpp @@ -0,0 +1,155 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: univ/stattext.cpp +// Purpose: wxStaticText +// Author: Vadim Zeitlin +// Modified by: +// Created: 14.08.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "stattext.h" +#endif + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_STATTEXT + +#ifndef WX_PRECOMP + #include "wx/dc.h" + #include "wx/stattext.h" + #include "wx/validate.h" +#endif + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// creation +// ---------------------------------------------------------------------------- + +bool wxStaticText::Create(wxWindow *parent, + wxWindowID id, + const wxString &label, + const wxPoint &pos, + const wxSize &size, + long style, + const wxString &name) +{ + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) + return FALSE; + + SetLabel(label); + + if ( size.x == -1 || size.y == -1 ) + { + wxSize sizeBest = DoGetBestSize(); + SetSize(size.x == -1 ? sizeBest.x : size.x, + size.y == -1 ? sizeBest.y : size.y); + } + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// size management +// ---------------------------------------------------------------------------- + +wxSize wxStaticText::DoGetBestSize() const +{ + wxString text = GetLabel(); + + int widthTextMax = 0, widthLine, + heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; + + wxString curLine; + for ( const wxChar *pc = text; ; pc++ ) { + if ( *pc == _T('\n') || *pc == _T('\0') ) { + if ( !curLine ) { + // we can't use GetTextExtent - it will return 0 for both width + // and height and an empty line should count in height + // calculation + if ( !heightLineDefault ) + heightLineDefault = heightLine; + if ( !heightLineDefault ) + GetTextExtent(_T("W"), NULL, &heightLineDefault); + + heightTextTotal += heightLineDefault; + } + else { + GetTextExtent(curLine, &widthLine, &heightLine); + if ( widthLine > widthTextMax ) + widthTextMax = widthLine; + heightTextTotal += heightLine; + } + + if ( *pc == _T('\n') ) { + curLine.Empty(); + } + else { + // the end of string + break; + } + } + else { + curLine += *pc; + } + } + + return wxSize(widthTextMax, heightTextTotal); +} + +// ---------------------------------------------------------------------------- +// drawing +// ---------------------------------------------------------------------------- + +void wxStaticText::DoDraw(wxDC& dc, wxRenderer *renderer) +{ + // get the position of the label start + const wxString text = GetLabel(); + + wxCoord heightLine; + dc.GetTextExtent(text[0u], NULL, &heightLine); + + wxCoord x = 0, + y = heightLine; + + // split the string into lines and draw each of them separately + wxString curLine; + for ( const wxChar *pc = text; ; pc++ ) + { + if ( *pc == _T('\n') || *pc == _T('\0') ) + { + if ( !curLine.empty() ) + { + dc.DrawText(curLine, x, y); + } + + if ( *pc == _T('\0') ) + break; + + y += heightLine; + } + else + { + curLine += *pc; + } + } +} + +#endif // wxUSE_STATTEXT diff --git a/src/univ/theme.cpp b/src/univ/theme.cpp new file mode 100644 index 0000000000..6a03e17186 --- /dev/null +++ b/src/univ/theme.cpp @@ -0,0 +1,98 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: univ/theme.cpp +// Purpose: implementation of wxTheme +// Author: Vadim Zeitlin +// Modified by: +// Created: 06.08.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// =========================================================================== +// declarations +// =========================================================================== + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "theme.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/univ/renderer.h" + #include "wx/univ/theme.h" +#endif // WX_PRECOMP + +// ---------------------------------------------------------------------------- +// dummy theme class +// ---------------------------------------------------------------------------- + +class wxDummyRenderer : public wxRenderer +{ +public: + virtual void DrawLabel(wxDC& dc, wxWindow *window) { } + virtual void DrawBorder(wxDC& dc, wxWindow *window) { } +}; + +class wxDummyTheme : public wxTheme +{ +public: + wxDummyTheme() + { + m_renderer = new wxDummyRenderer; + } + + virtual ~wxDummyTheme() + { + delete m_renderer; + } + + virtual wxRenderer *GetRenderer() { return m_renderer; } + virtual wxInputHandler *GetInputHandler() { return NULL; } + virtual wxColourScheme *GetColourScheme() { return NULL; } + +private: + wxDummyRenderer *m_renderer; +}; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// creation of the default theme (called by wxApp::OnInitGui) +// ---------------------------------------------------------------------------- + +wxTheme *wxTheme::ms_theme = (wxTheme *)NULL; + +/* static */ bool wxTheme::CreateDefault() +{ + ms_theme = new wxDummyTheme; + + return TRUE; +} + +/* static */ wxTheme *wxTheme::Set(wxTheme *theme) +{ + wxTheme *themeOld = ms_theme; + ms_theme = theme; + return themeOld; +} + +// ---------------------------------------------------------------------------- +// wxTheme dtor +// ---------------------------------------------------------------------------- + +wxTheme::~wxTheme() +{ +}