From: Vadim Zeitlin Date: Sun, 10 Sep 2000 16:30:16 +0000 (+0000) Subject: wxTipWindow added and is now used by wxSimpleHelpProvider X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/01fa3fe74d0fadc5126fc27fb5729f08b10da606 wxTipWindow added and is now used by wxSimpleHelpProvider git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8318 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 4c41322c02..488c004db6 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -101,6 +101,7 @@ numdlgg.cpp G tbarsmpl.cpp G textdlgg.cpp G tipdlg.cpp G +tipwin.cpp G treectlg.cpp G treelay.cpp G wizard.cpp G @@ -722,6 +723,7 @@ thread.h W B time.h W B timer.h W B tipdlg.h W +tipwin.h W tokenzr.h W B toolbar.h W tooltip.h W diff --git a/include/wx/tipwin.h b/include/wx/tipwin.h new file mode 100644 index 0000000000..feaddc11b6 --- /dev/null +++ b/include/wx/tipwin.h @@ -0,0 +1,48 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/tipwin.h +// Purpose: wxTipWindow is a window like the one typically used for +// showing the tooltips +// Author: Vadim Zeitlin +// Modified by: +// Created: 10.09.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_TIPWIN_H_ +#define _WX_TIPWIN_H_ + +#ifdef __GNUG__ + #pragma interface "tipwin.h" +#endif + +#include "wx/frame.h" + +// ---------------------------------------------------------------------------- +// wxTipWindow +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxTipWindow : public wxFrame +{ +public: + wxTipWindow(wxWindow *parent, + const wxString& text, + wxCoord maxLength = 100); + +protected: + // event handlers + void OnPaint(wxPaintEvent& event); + void OnMouseClick(wxMouseEvent& event); + + // calculate the client rect we need to display the text + void Adjust(const wxString& text, wxCoord maxLength); + +private: + wxArrayString m_textLines; + wxCoord m_heightLine; + + DECLARE_EVENT_TABLE() +}; + +#endif // _WX_TIPWIN_H_ diff --git a/samples/help/demo.cpp b/samples/help/demo.cpp index ae8ff74766..266f3a3da3 100644 --- a/samples/help/demo.cpp +++ b/samples/help/demo.cpp @@ -635,7 +635,7 @@ MyModalDialog::MyModalDialog(wxWindow *parent) wxDefaultPosition, wxSize(300, 100), wxTE_MULTILINE); text->SetHelpText(_("Type text here if you have got nothing more " - "more interesting to do")); + "interesting to do")); sizerTop->Add(text, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); sizerTop->Add(sizerRow, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); diff --git a/src/common/cshelp.cpp b/src/common/cshelp.cpp index c9a033d8a6..375e9f7ce6 100644 --- a/src/common/cshelp.cpp +++ b/src/common/cshelp.cpp @@ -31,10 +31,7 @@ #if wxUSE_HELP #ifndef WX_PRECOMP - // FIXME: temporary needed for wxSimpleHelpProvider compilation, to be - // removed later - #include "wx/intl.h" - #include "wx/msgdlg.h" + #include "wx/tipwin.h" #endif #include "wx/app.h" @@ -307,8 +304,7 @@ bool wxSimpleHelpProvider::ShowHelp(wxWindowBase *window) wxString text = GetHelp(window); if ( !text.empty() ) { - wxMessageBox(text, _("Help"), wxICON_INFORMATION | wxOK, - (wxWindow *)window); + new wxTipWindow((wxWindow *)window, text); return TRUE; } diff --git a/src/files.lst b/src/files.lst index 14b8289f11..8a7b8b0fb2 100644 --- a/src/files.lst +++ b/src/files.lst @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 20:17, 2000/03/31 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BASE.T! ALL_SOURCES = \ common/init.cpp \ @@ -48,6 +48,7 @@ ALL_SOURCES = \ common/textfile.cpp \ common/timercmn.cpp \ common/tokenzr.cpp \ + common/treebase.cpp \ common/txtstrm.cpp \ common/unzip.c \ common/url.cpp \ @@ -190,6 +191,7 @@ BASE_OBJS = \ textfile.o \ timercmn.o \ tokenzr.o \ + treebase.o \ txtstrm.o \ unzip.o \ url.o \ @@ -248,6 +250,7 @@ BASE_DEPS = \ textfile.d \ timercmn.d \ tokenzr.d \ + treebase.d \ txtstrm.d \ unzip.d \ url.d \ @@ -313,6 +316,7 @@ BASE_DEPS = \ textfile.d \ timercmn.d \ tokenzr.d \ + treebase.d \ txtstrm.d \ unzip.d \ url.d \ diff --git a/src/generic/tipwin.cpp b/src/generic/tipwin.cpp new file mode 100644 index 0000000000..6dc9d80ac6 --- /dev/null +++ b/src/generic/tipwin.cpp @@ -0,0 +1,184 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: src/generic/tipwin.cpp +// Purpose: implementation of wxTipWindow +// Author: Vadim Zeitlin +// Modified by: +// Created: 10.09.00 +// RCS-ID: $Id$ +// Copyright: (c) 2000 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "tipwin.h" +#endif + +// For compilers that support precompilatixon, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/dcclient.h" +#endif // WX_PRECOMP + +#include "wx/tipwin.h" + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +static const wxCoord TEXT_MARGIN_X = 3; +static const wxCoord TEXT_MARGIN_Y = 3; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// event tables +// ---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(wxTipWindow, wxFrame) + EVT_PAINT(wxTipWindow::OnPaint) + + EVT_LEFT_DOWN(wxTipWindow::OnMouseClick) + EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick) + EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick) +END_EVENT_TABLE() + +// ---------------------------------------------------------------------------- +// wxTipWindow +// ---------------------------------------------------------------------------- + +wxTipWindow::wxTipWindow(wxWindow *parent, + const wxString& text, + wxCoord maxLength) + : wxFrame(parent, -1, _T(""), + wxDefaultPosition, wxDefaultSize, + wxNO_BORDER | wxFRAME_FLOAT_ON_PARENT) +{ + // set colours + SetForegroundColour(*wxBLACK); + SetBackgroundColour(wxColour(0xc3ffff)); + + // set position and size + int x, y; + wxGetMousePosition(&x, &y); + Move(x, y + 20); + + Adjust(text, maxLength); + + // capture mouse as we want to dismiss the window when it is clicked + CaptureMouse(); + + Show(TRUE); +} + +void wxTipWindow::Adjust(const wxString& text, wxCoord maxLength) +{ + wxClientDC dc(this); + dc.SetFont(GetFont()); + + // calculate the length: we want each line be no longer than maxLength + // pixels and we only break lines at words boundary + wxString current; + wxCoord height, width, + widthMax = 0; + m_heightLine = 0; + + bool breakLine = FALSE; + for ( const wxChar *p = text.c_str(); ; p++ ) + { + if ( *p == _T('\n') || *p == _T('\0') ) + { + dc.GetTextExtent(current, &width, &height); + if ( width > widthMax ) + widthMax = width; + + if ( height > m_heightLine ) + m_heightLine = height; + + m_textLines.Add(current); + + if ( !*p ) + { + // end of text + break; + } + + current.clear(); + breakLine = FALSE; + } + else if ( breakLine && (*p == _T(' ') || *p == _T('\t')) ) + { + // word boundary - break the line here + m_textLines.Add(current); + current.clear(); + breakLine = FALSE; + } + else // line goes on + { + current += *p; + dc.GetTextExtent(current, &width, &height); + if ( width > maxLength ) + breakLine = TRUE; + + if ( width > widthMax ) + widthMax = width; + + if ( height > m_heightLine ) + m_heightLine = height; + } + } + + // take into account the border size and the margins + SetClientSize(2*(TEXT_MARGIN_X + 1) + widthMax, + 2*(TEXT_MARGIN_Y + 1) + m_textLines.GetCount()*m_heightLine); +} + +void wxTipWindow::OnPaint(wxPaintEvent& event) +{ + wxPaintDC dc(this); + + wxRect rect; + wxSize size = GetClientSize(); + rect.width = size.x; + rect.height = size.y; + + // first filll the background + dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID)); + dc.SetPen(*wxBLACK_PEN); + dc.DrawRectangle(rect); + + // and then draw the text line by line + dc.SetFont(GetFont()); + + wxPoint pt; + pt.x = TEXT_MARGIN_X; + pt.y = TEXT_MARGIN_Y; + size_t count = m_textLines.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + dc.DrawText(m_textLines[n], pt); + + pt.y += m_heightLine; + } +} + +void wxTipWindow::OnMouseClick(wxMouseEvent& event) +{ + ReleaseMouse(); + + Close(); +} diff --git a/src/gtk/files.lst b/src/gtk/files.lst index 4571d4c618..56c215bf58 100644 --- a/src/gtk/files.lst +++ b/src/gtk/files.lst @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE GTK.T! ALL_SOURCES = \ generic/busyinfo.cpp \ @@ -39,6 +39,7 @@ ALL_SOURCES = \ generic/tbarsmpl.cpp \ generic/textdlgg.cpp \ generic/tipdlg.cpp \ + generic/tipwin.cpp \ generic/treectlg.cpp \ generic/treelay.cpp \ generic/wizard.cpp \ @@ -413,6 +414,7 @@ ALL_HEADERS = \ time.h \ timer.h \ tipdlg.h \ + tipwin.h \ tokenzr.h \ toolbar.h \ tooltip.h \ @@ -807,6 +809,7 @@ GENERICOBJS = \ tbarsmpl.o \ textdlgg.o \ tipdlg.o \ + tipwin.o \ treectlg.o \ treelay.o \ wizard.o @@ -850,6 +853,7 @@ GENERICDEPS = \ tbarsmpl.d \ textdlgg.d \ tipdlg.d \ + tipwin.d \ treectlg.d \ treelay.d \ wizard.d diff --git a/src/gtk1/files.lst b/src/gtk1/files.lst index 4571d4c618..56c215bf58 100644 --- a/src/gtk1/files.lst +++ b/src/gtk1/files.lst @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE GTK.T! ALL_SOURCES = \ generic/busyinfo.cpp \ @@ -39,6 +39,7 @@ ALL_SOURCES = \ generic/tbarsmpl.cpp \ generic/textdlgg.cpp \ generic/tipdlg.cpp \ + generic/tipwin.cpp \ generic/treectlg.cpp \ generic/treelay.cpp \ generic/wizard.cpp \ @@ -413,6 +414,7 @@ ALL_HEADERS = \ time.h \ timer.h \ tipdlg.h \ + tipwin.h \ tokenzr.h \ toolbar.h \ tooltip.h \ @@ -807,6 +809,7 @@ GENERICOBJS = \ tbarsmpl.o \ textdlgg.o \ tipdlg.o \ + tipwin.o \ treectlg.o \ treelay.o \ wizard.o @@ -850,6 +853,7 @@ GENERICDEPS = \ tbarsmpl.d \ textdlgg.d \ tipdlg.d \ + tipwin.d \ treectlg.d \ treelay.d \ wizard.d diff --git a/src/msw/makefile.b32 b/src/msw/makefile.b32 index ebb69f856c..8e2465b4d0 100644 --- a/src/msw/makefile.b32 +++ b/src/msw/makefile.b32 @@ -1,6 +1,6 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T! # @@ -102,6 +102,7 @@ GENERICOBJS= $(MSWDIR)\busyinfo.obj \ $(MSWDIR)\tbarsmpl.obj \ $(MSWDIR)\textdlgg.obj \ $(MSWDIR)\tipdlg.obj \ + $(MSWDIR)\tipwin.obj \ $(MSWDIR)\treectlg.obj \ $(MSWDIR)\treelay.obj \ $(MSWDIR)\wizard.obj @@ -862,6 +863,8 @@ $(MSWDIR)\textdlgg.obj: $(GENDIR)\textdlgg.$(SRCSUFF) $(MSWDIR)\tipdlg.obj: $(GENDIR)\tipdlg.$(SRCSUFF) +$(MSWDIR)\tipwin.obj: $(GENDIR)\tipwin.$(SRCSUFF) + $(MSWDIR)\treectlg.obj: $(GENDIR)\treectlg.$(SRCSUFF) $(MSWDIR)\treelay.obj: $(GENDIR)\treelay.$(SRCSUFF) diff --git a/src/msw/makefile.bcc b/src/msw/makefile.bcc index b1e381a800..a364ab42a5 100644 --- a/src/msw/makefile.bcc +++ b/src/msw/makefile.bcc @@ -1,6 +1,6 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T! # @@ -103,6 +103,7 @@ GENERICOBJS= $(MSWDIR)\busyinfo.obj \ $(MSWDIR)\tbarsmpl.obj \ $(MSWDIR)\textdlgg.obj \ $(MSWDIR)\tipdlg.obj \ + $(MSWDIR)\tipwin.obj \ $(MSWDIR)\treectlg.obj \ $(MSWDIR)\treelay.obj \ $(MSWDIR)\wizard.obj @@ -721,6 +722,8 @@ $(MSWDIR)\textdlgg.obj: $(GENDIR)\textdlgg.$(SRCSUFF) $(MSWDIR)\tipdlg.obj: $(GENDIR)\tipdlg.$(SRCSUFF) +$(MSWDIR)\tipwin.obj: $(GENDIR)\tipwin.$(SRCSUFF) + $(MSWDIR)\treectlg.obj: $(GENDIR)\treectlg.$(SRCSUFF) $(MSWDIR)\treelay.obj: $(GENDIR)\treelay.$(SRCSUFF) diff --git a/src/msw/makefile.dos b/src/msw/makefile.dos index dd40f35126..916ace01b2 100644 --- a/src/msw/makefile.dos +++ b/src/msw/makefile.dos @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T! # @@ -87,6 +87,7 @@ GENERICOBJS= $(GENDIR)\busyinfo.obj \ $(GENDIR)\tbarsmpl.obj \ $(GENDIR)\textdlgg.obj \ $(GENDIR)\tipdlg.obj \ + $(GENDIR)\tipwin.obj \ $(GENDIR)\treectlg.obj \ $(GENDIR)\treelay.obj \ $(GENDIR)\wizard.obj @@ -1339,6 +1340,11 @@ $(GENDIR)/tipdlg.obj: $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) << +$(GENDIR)/tipwin.obj: $*.$(SRCSUFF) + cl @<< +$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) +<< + $(GENDIR)/treectlg.obj: $*.$(SRCSUFF) cl @<< $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) diff --git a/src/msw/makefile.g95 b/src/msw/makefile.g95 index 49fd14dcaf..0240840c68 100644 --- a/src/msw/makefile.g95 +++ b/src/msw/makefile.g95 @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T! # @@ -93,6 +93,7 @@ GENERICOBJS = \ $(GENDIR)/tbarsmpl.$(OBJSUFF) \ $(GENDIR)/textdlgg.$(OBJSUFF) \ $(GENDIR)/tipdlg.$(OBJSUFF) \ + $(GENDIR)/tipwin.$(OBJSUFF) \ $(GENDIR)/treectlg.$(OBJSUFF) \ $(GENDIR)/treelay.$(OBJSUFF) \ $(GENDIR)/wizard.$(OBJSUFF) diff --git a/src/msw/makefile.sc b/src/msw/makefile.sc index eb3568847c..25562cbae3 100644 --- a/src/msw/makefile.sc +++ b/src/msw/makefile.sc @@ -1,6 +1,6 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T! # Symantec C++ makefile for the msw objects @@ -50,6 +50,7 @@ GENERICOBJS= $(GENDIR)\busyinfo.obj \ $(GENDIR)\tbarsmpl.obj \ $(GENDIR)\textdlgg.obj \ $(GENDIR)\tipdlg.obj \ + $(GENDIR)\tipwin.obj \ $(GENDIR)\treectlg.obj \ $(GENDIR)\treelay.obj \ $(GENDIR)\wizard.obj diff --git a/src/msw/makefile.vc b/src/msw/makefile.vc index 79be1c8059..f719d708d0 100644 --- a/src/msw/makefile.vc +++ b/src/msw/makefile.vc @@ -1,4 +1,4 @@ -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T! # File: makefile.vc @@ -107,6 +107,7 @@ GENERICOBJS= ..\generic\$D\busyinfo.obj \ ..\generic\$D\tbarsmpl.obj \ ..\generic\$D\textdlgg.obj \ ..\generic\$D\tipdlg.obj \ + ..\generic\$D\tipwin.obj \ ..\generic\$D\treectlg.obj \ ..\generic\$D\treelay.obj \ ..\generic\$D\wizard.obj diff --git a/src/msw/makefile.wat b/src/msw/makefile.wat index 4adabe4f0b..a6f93a7178 100644 --- a/src/msw/makefile.wat +++ b/src/msw/makefile.wat @@ -1,6 +1,6 @@ #!/binb/wmake.exe -# This file was automatically generated by tmake at 11:57, 2000/09/08 +# This file was automatically generated by tmake at 19:28, 2000/09/10 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T! # @@ -65,6 +65,7 @@ GENERICOBJS= busyinfo.obj & tbarsmpl.obj & textdlgg.obj & tipdlg.obj & + tipwin.obj & treectlg.obj & treelay.obj & wizard.obj @@ -1045,6 +1046,9 @@ textdlgg.obj: $(GENDIR)\textdlgg.cpp tipdlg.obj: $(GENDIR)\tipdlg.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $< +tipwin.obj: $(GENDIR)\tipwin.cpp + *$(CCC) $(CPPFLAGS) $(IFLAGS) $< + treectlg.obj: $(GENDIR)\treectlg.cpp *$(CCC) $(CPPFLAGS) $(IFLAGS) $<