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
This commit is contained in:
Vadim Zeitlin
2000-09-10 16:30:16 +00:00
parent 4204da658a
commit 01fa3fe74d
15 changed files with 278 additions and 17 deletions

View File

@@ -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

48
include/wx/tipwin.h Normal file
View File

@@ -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 <zeitlin@dptmaths.ens-cachan.fr>
// 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_

View File

@@ -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 );

View File

@@ -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;
}

View File

@@ -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 \

184
src/generic/tipwin.cpp Normal file
View File

@@ -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 <zeitlin@dptmaths.ens-cachan.fr>
// 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();
}

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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) $<