1. wxMDIParentFrame::~wxMDIParentFrame() bug fixed

2. tooltips work with wxRadioBox
3. duplicated OnCtlColor()s moved to wxControl


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4693 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-11-25 23:28:41 +00:00
parent 1e7215e676
commit f048e32fcd
29 changed files with 435 additions and 503 deletions

View File

@ -1,5 +1,5 @@
#
# This file was automatically generated by tmake at 20:10, 1999/11/21
# This file was automatically generated by tmake at 13:22, 1999/11/24
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T!
#
@ -514,6 +514,7 @@ MSW_HEADERS = \
msw/gauge.h \
msw/gauge95.h \
msw/gaugemsw.h \
msw/gdiimage.h \
msw/gdiobj.h \
msw/helpwin.h \
msw/icon.h \
@ -1657,6 +1658,7 @@ MSW_GUIOBJS = \
fontutil.o \
frame.o \
gauge95.o \
gdiimage.o \
gdiobj.o \
gsocket.o \
helpwin.o \
@ -1746,6 +1748,7 @@ MSW_GUIDEPS = \
fontutil.d \
frame.d \
gauge95.d \
gdiimage.d \
gdiobj.d \
gsocket.d \
helpwin.d \

View File

@ -16,6 +16,8 @@ all:
wxMSW:
- tooltips work with wxRadioBox
- arbitrary controls (and not only buttons) can be put into a toolbar
wxGTK:

View File

@ -55,12 +55,6 @@ public:
virtual void Command(wxCommandEvent& event);
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual WXHBRUSH OnCtlColor(WXHDC pDC,
WXHWND pWnd,
WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam);
protected:
// send a notification event, return TRUE if processed

View File

@ -49,8 +49,6 @@ public:
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual void SetLabel(const wxString& label);
virtual void Command(wxCommandEvent& event);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
protected:
virtual wxSize DoGetBestSize() const;

View File

@ -43,10 +43,13 @@ public:
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *WXUNUSED(item)) { return FALSE; };
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *WXUNUSED(item)) { return FALSE; };
wxList& GetSubcontrols() { return m_subControls; }
wxArrayLong GetSubcontrols() { return m_subControls; }
void OnEraseBackground(wxEraseEvent& event);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
#if WXWIN_COMPATIBILITY
virtual void SetButtonColour(const wxColour& WXUNUSED(col)) { }
wxColour* GetButtonColour() const { return NULL; }
@ -66,8 +69,9 @@ protected:
#endif // WXWIN_COMPATIBILITY
protected:
// For controls like radiobuttons which are really composite
wxList m_subControls;
// for controls like radiobuttons which are really composite this array
// holds the ids (not HWNDs!) of the sub controls
wxArrayLong m_subControls;
virtual wxSize DoGetBestSize() const;

View File

@ -108,10 +108,6 @@ public:
virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
// Windows callbacks
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam, WXLPARAM lParam);
bool MSWCommand(WXUINT param, WXWORD id);
virtual void SetupColours();

View File

@ -47,8 +47,6 @@ public:
const wxValidator& val = wxDefaultValidator, const wxString& name = wxRadioBoxNameStr);
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
int FindString(const wxString& s) const;
void SetSelection(int N);

View File

@ -49,8 +49,6 @@ class WXDLLEXPORT wxRadioButton: public wxControl
bool MSWCommand(WXUINT param, WXWORD id);
void Command(wxCommandEvent& event);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
};
// Not implemented

View File

@ -50,9 +50,6 @@ public:
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
// overriden base class virtuals
virtual bool AcceptsFocus() const { return FALSE; }

View File

@ -51,8 +51,6 @@ public:
virtual bool AcceptsFocus() const { return FALSE; }
// callbacks
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
protected:

View File

@ -128,10 +128,6 @@ public:
void SetRichEdit(bool isRich) { m_isRich = isRich; }
#endif // wxUSE_RICHEDIT
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam,
WXLPARAM lParam);
virtual void AdoptAttributesFromHWND();
virtual void SetupColours();

View File

@ -35,14 +35,17 @@ public:
void RelayEvent(WXMSG *msg);
private:
static WXHWND hwndTT;
// create the tooltip ctrl for our parent frame if it doesn't exist yet
// and return its window handle
static WXHWND ms_hwndTT;
// create the tooltip ctrl if it doesn't exist yet and return its HWND
WXHWND GetToolTipCtrl();
// remove this tooltip from the tooltip control
void Remove();
// add a window to the tooltip control
void Add(WXHWND hwnd);
wxString m_text; // tooltip text
wxWindow *m_window; // window we're associated with
};

View File

@ -62,6 +62,8 @@ public:
private:
void OnButtonMove(bool up);
void AdjustColour(size_t index);
wxCheckListBox *m_pListBox;
DECLARE_EVENT_TABLE()
@ -157,13 +159,10 @@ CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame,
delete [] astrChoices;
// not implemented in other ports yet
#ifdef __WXMSW__
// set grey background for every second entry
for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) {
m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200));
AdjustColour(ui);
}
#endif // wxGTK
m_pListBox->Check(2);
@ -252,7 +251,7 @@ void CheckListBoxFrame::OnButtonMove(bool up)
wxString label = m_pListBox->GetString(selection);
int positionNew = up ? selection - 1 : selection + 2;
if ( positionNew < 0 || positionNew > m_pListBox->Number() )
if ( positionNew < 0 || positionNew > m_pListBox->GetCount() )
{
wxLogStatus(this, _T("Can't move this item %s"), up ? _T("up") : _T("down"));
}
@ -272,6 +271,9 @@ void CheckListBoxFrame::OnButtonMove(bool up)
m_pListBox->Check(selectionNew, wasChecked);
m_pListBox->SetSelection(selectionNew);
AdjustColour(selection);
AdjustColour(selectionNew);
wxLogStatus(this, _T("Item moved %s"), up ? _T("up") : _T("down"));
}
}
@ -280,3 +282,13 @@ void CheckListBoxFrame::OnButtonMove(bool up)
wxLogStatus(this, _T("Please select an item"));
}
}
void CheckListBoxFrame::AdjustColour(size_t index)
{
// not implemented in other ports yet
#ifdef __WXMSW__
// even items have grey backround, odd ones - white
unsigned char c = index % 2 ? 255 : 200;
m_pListBox->GetItem(index)->SetBackgroundColour(wxColor(c, c, c));
#endif // wxMSW
}

View File

@ -61,11 +61,6 @@
#include "wx/progdlg.h"
// VZ: this is a temp. hack, will remove soon
#ifndef wxUSE_SPINCTRL
#define wxUSE_SPINCTRL 1
#endif
#if wxUSE_SPINCTRL
#include "wx/spinctrl.h"
#endif // wxUSE_SPINCTRL
@ -167,6 +162,8 @@ public:
void OnSize( wxSizeEvent& event );
void OnMove( wxMoveEvent& event );
MyPanel *GetPanel() const { return m_panel; }
private:
void UpdateStatusBar(const wxPoint& pos, const wxSize& size)
{
@ -176,7 +173,7 @@ private:
SetStatusText(msg, 1);
}
wxPanel *m_panel;
MyPanel *m_panel;
DECLARE_EVENT_TABLE()
};
@ -259,6 +256,8 @@ bool MyApp::OnInit()
frame->Show(TRUE);
frame->SetCursor(wxCursor(wxCURSOR_HAND));
frame->GetPanel()->m_notebook->SetSelection(3);
SetTopWindow(frame);
return TRUE;
@ -504,7 +503,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_notebook->AddPage(panel, "wxChoice", FALSE, Image_Choice);
panel = new wxPanel(m_notebook);
m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(10,10), wxSize(120,-1), 5, choices, wxCB_READONLY );
(void)new wxStaticBox( panel, -1, "Box around combobox",
wxPoint(5, 5), wxSize(150, 100));
m_combo = new wxComboBox( panel, ID_COMBO, "This", wxPoint(20,20), wxSize(120,-1), 5, choices, wxCB_READONLY );
(void)new wxButton( panel, ID_COMBO_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_COMBO_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
(void)new wxButton( panel, ID_COMBO_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) );
@ -525,6 +526,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
panel = new wxPanel(m_notebook);
(void)new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
#if wxUSE_TOOLTIPS
m_radio->SetToolTip("Ever seen a radiobox?");
#endif // wxUSE_TOOLTIPS
(void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
(void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) );
m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(140,30) );
@ -584,7 +590,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
#ifndef __WXMOTIF__ // wxStaticBitmap not working under Motif yet. MB
wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon, wxPoint(10, 10));
wxStaticBitmap *bmpStatic = new wxStaticBitmap(panel, -1, icon,
wxPoint(10, 10));
bmpStatic = new wxStaticBitmap(panel, -1, wxNullIcon, wxPoint(50, 10));
bmpStatic->SetIcon(wxTheApp->GetStdIcon(wxICON_QUESTION));
@ -594,11 +601,25 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
wxMemoryDC dc;
dc.SelectObject( bitmap );
dc.SetPen(*wxGREEN_PEN);
dc.Clear();
dc.DrawEllipse(5, 5, 90, 90);
dc.DrawText("Bitmap", 20, 20);
dc.DrawText("Bitmap", 30, 40);
dc.SelectObject( wxNullBitmap );
(void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
wxBitmapButton *bmpBtn = new wxBitmapButton
(
panel, -1,
bmp1,
wxPoint(30, 50)
);
bmpBtn->SetBitmapSelected(bmp2);
bmpBtn->SetBitmapFocus(bmp3);
(void)new wxButton(panel, ID_BUTTON_LABEL, "Toggle label", wxPoint(250, 20));
m_label = new wxStaticText(panel, -1, "Label with some long text",
wxPoint(250, 60), wxDefaultSize,

View File

@ -121,15 +121,15 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
wxLogWarning("Can't find image files in either '.' or '..'!");
wxImage image( bitmap );
if ( !image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ) )
wxLogError("Can't save file");
if ( !image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG ) )
wxLogError("Can't load PNG image");
else
my_horse_png = new wxBitmap( image.ConvertToBitmap() );
if ( !image.LoadFile( dir + wxString("horse.jpg") ) )
wxLogError("Can't load JPG image");
else
@ -160,10 +160,10 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
else
my_horse_pnm = new wxBitmap( image.ConvertToBitmap() );
#endif
image.LoadFile( dir + wxString("test.png") );
my_square = new wxBitmap( image.ConvertToBitmap() );
CreateAntiAliasedBitmap();
}
@ -186,20 +186,20 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.DrawText( "Loaded image", 30, 10 );
if (my_square && my_square->Ok()) dc.DrawBitmap( *my_square, 30, 30 );
dc.DrawText( "Drawn directly", 150, 10 );
dc.SetBrush( wxBrush( "orange", wxSOLID ) );
dc.SetPen( *wxWHITE_PEN );
dc.DrawRectangle( 150, 30, 100, 100 );
if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 250, 140 );
dc.DrawText( "PNG handler", 30, 135 );
if (my_horse_png && my_horse_png->Ok()) dc.DrawBitmap( *my_horse_png, 30, 150 );
dc.DrawText( "JPEG handler", 30, 365 );
if (my_horse_jpeg && my_horse_jpeg->Ok()) dc.DrawBitmap( *my_horse_jpeg, 30, 380 );
dc.DrawText( "GIF handler", 30, 595 );
if (my_horse_gif && my_horse_gif->Ok()) dc.DrawBitmap( *my_horse_gif, 30, 610 );
@ -222,41 +222,41 @@ void MyCanvas::CreateAntiAliasedBitmap()
dc.SelectObject( bitmap );
dc.Clear();
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
dc.SetTextForeground( "RED" );
dc.DrawText( "This is anti-aliased Text.", 20, 20 );
dc.DrawText( "And a Rectangle.", 20, 60 );
dc.SetBrush( *wxRED_BRUSH );
dc.SetPen( *wxTRANSPARENT_PEN );
dc.DrawRoundedRectangle( 20, 100, 200, 180, 20 );
wxImage original( bitmap );
wxImage anti( 150, 150 );
/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */
for (int y = 1; y < 149; y++)
for (int x = 1; x < 149; x++)
{
int red = original.GetRed( x*2, y*2 ) +
original.GetRed( x*2-1, y*2 ) +
original.GetRed( x*2, y*2+1 ) +
original.GetRed( x*2-1, y*2 ) +
original.GetRed( x*2, y*2+1 ) +
original.GetRed( x*2+1, y*2+1 );
red = red/4;
red = red/4;
int green = original.GetGreen( x*2, y*2 ) +
original.GetGreen( x*2-1, y*2 ) +
original.GetGreen( x*2, y*2+1 ) +
original.GetGreen( x*2-1, y*2 ) +
original.GetGreen( x*2, y*2+1 ) +
original.GetGreen( x*2+1, y*2+1 );
green = green/4;
green = green/4;
int blue = original.GetBlue( x*2, y*2 ) +
original.GetBlue( x*2-1, y*2 ) +
original.GetBlue( x*2, y*2+1 ) +
original.GetBlue( x*2-1, y*2 ) +
original.GetBlue( x*2, y*2+1 ) +
original.GetBlue( x*2+1, y*2+1 );
blue = blue/4;
blue = blue/4;
anti.SetRGB( x, y, red, green, blue );
}
my_anti = new wxBitmap( anti.ConvertToBitmap() );

View File

@ -242,29 +242,6 @@ bool wxButton::MSWCommand(WXUINT param, WXWORD id)
return processed;
}
WXHBRUSH wxButton::OnCtlColor(WXHDC pDC,
WXHWND pWnd,
WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{
const HDC& hdc = (HDC)pDC;
const wxColour& colBack = GetBackgroundColour();
::SetBkColor(hdc, RGB(colBack.Red(), colBack.Green(), colBack.Blue()));
const wxColour& colFor = GetForegroundColour();
::SetTextColor(hdc, RGB(colFor.Red(), colFor.Green(), colFor.Blue()));
::SetBkMode(hdc, OPAQUE);
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(colBack,
wxSOLID);
backgroundBrush->RealizeResource();
return (WXHBRUSH)backgroundBrush->GetResourceHandle();
}
long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
// make sure that we won't have BS_DEFPUSHBUTTON style any more if the

View File

@ -179,34 +179,6 @@ bool wxCheckBox::GetValue() const
#endif
}
WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
// has a zero usage count.
// backgroundBrush->RealizeResource();
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
void wxCheckBox::Command (wxCommandEvent & event)
{
SetValue ((event.GetInt() != 0));

View File

@ -208,6 +208,34 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
::SetMapMode(hdc, mode);
}
WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif // wxUSE_CTL3D
HDC hdc = (HDC)pDC;
if (GetParent()->GetTransparentBackground())
SetBkMode(hdc, TRANSPARENT);
else
SetBkMode(hdc, OPAQUE);
const wxColour& colBack = GetBackgroundColour();
::SetBkColor(hdc, wxColourToRGB(colBack));
::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
return (WXHBRUSH)brush->GetResourceHandle();
}
WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const
{
WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D);

View File

@ -696,33 +696,6 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
return FALSE;
}
WXHBRUSH wxListBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
// has a zero usage count.
backgroundBrush->RealizeResource();
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
// ----------------------------------------------------------------------------
// wxCheckListBox support
// ----------------------------------------------------------------------------

View File

@ -213,6 +213,9 @@ wxMDIParentFrame::~wxMDIParentFrame()
{
DestroyChildren();
// already delete by DestroyChildren()
m_frameToolBar = NULL;
::DestroyMenu((HMENU)m_windowMenu);
m_windowMenu = 0;

View File

@ -29,8 +29,6 @@
#endif
#ifndef WX_PRECOMP
#include <stdio.h>
#include "wx/setup.h"
#include "wx/bitmap.h"
#include "wx/brush.h"
#include "wx/radiobox.h"
@ -38,10 +36,25 @@
#include "wx/msw/private.h"
#if wxUSE_TOOLTIPS
#include <commctrl.h>
#include "wx/tooltip.h"
#endif // wxUSE_TOOLTIPS
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
#endif
// VZ: the new behaviour is to create the radio buttons as children of the
// radiobox instead of creating them as children of the radiobox' parent.
//
// This seems more logical, more consistent with what other frameworks do
// and allows tooltips to work with radioboxes, so there should be no
// reason to revert to the backward compatible behaviour - but I still
// leave this possibility just in case.
#define RADIOBTN_PARENT_IS_RADIOBOX 1
// ---------------------------------------------------------------------------
// private functions
// ---------------------------------------------------------------------------
@ -154,116 +167,101 @@ wxRadioBox::wxRadioBox()
m_radioHeight = NULL;
}
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size,
int n, const wxString choices[],
int majorDim, long style,
const wxValidator& val, const wxString& name)
bool wxRadioBox::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
int n,
const wxString choices[],
int majorDim,
long style,
const wxValidator& val,
const wxString& name)
{
// initialize members
m_selectedButton = -1;
m_noItems = n;
SetName(name);
SetValidator(val);
parent->AddChild(this);
m_backgroundColour = parent->GetBackgroundColour();
m_foregroundColour = parent->GetForegroundColour();
m_windowStyle = (long&)style;
int x = pos.x;
int y = pos.y;
int width = size.x;
int height = size.y;
if (id == -1)
m_windowId = NewControlId();
else
m_windowId = id;
if ( majorDim == 0 )
m_majorDim = n;
else
m_majorDim = majorDim;
m_majorDim = majorDim == 0 ? n : majorDim;
m_noRowsOrCols = majorDim;
long msStyle = GROUP_FLAGS;
// common initialization
if ( !CreateControl(parent, id, pos, size, style, val, name) )
return FALSE;
bool want3D;
WXDWORD exStyle = Determine3DEffects(0, &want3D);
// create the static box
if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX, pos, size, title, 0) )
return FALSE;
HWND hwndParent = (HWND)parent->GetHWND();
m_hWnd = (WXHWND)::CreateWindowEx
(
(DWORD)exStyle,
GROUP_CLASS,
title,
msStyle,
0, 0, 0, 0,
hwndParent,
(HMENU)m_windowId,
wxGetInstance(),
NULL
);
#if wxUSE_CTL3D
if (want3D)
{
Ctl3dSubclassCtl((HWND)m_hWnd);
m_useCtl3D = TRUE;
}
#endif // wxUSE_CTL3D
SetFont(parent->GetFont());
SubclassWin(m_hWnd);
// and now create the buttons
#if RADIOBTN_PARENT_IS_RADIOBOX
HWND hwndParent = GetHwnd();
#else
HWND hwndParent = GetHwndOf(parent);
#endif
// Some radio boxes test consecutive id.
(void)NewControlId();
m_radioButtons = new WXHWND[n];
m_radioWidth = new int[n];
m_radioHeight = new int[n];
int i;
for (i = 0; i < n; i++)
{
m_radioWidth[i] = m_radioHeight[i] = -1;
long groupStyle = 0;
if ( i == 0 && style == 0 )
groupStyle = WS_GROUP;
long newId = NewControlId();
long msStyle = groupStyle | RADIO_FLAGS;
HWND hwndBtn = CreateWindowEx(exStyle, RADIO_CLASS,
choices[i], msStyle,
0,0,0,0,
WXHFONT hfont = 0;
wxFont& font = GetFont();
if ( font.Ok() )
{
hfont = font.GetResourceHandle();
}
for ( int i = 0; i < n; i++ )
{
m_radioWidth[i] =
m_radioHeight[i] = -1;
long styleBtn = BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE;
if ( i == 0 && style == 0 )
styleBtn |= WS_GROUP;
long newId = NewControlId();
HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
choices[i],
styleBtn,
0, 0, 0, 0, // will be set in SetSize()
hwndParent,
(HMENU)newId, wxGetInstance(),
(HMENU)newId,
wxGetInstance(),
NULL);
if ( !hwndBtn )
{
wxLogLastError("CreateWindow(radio btn)");
return FALSE;
}
m_radioButtons[i] = (WXHWND)hwndBtn;
SubclassRadioButton((WXHWND)hwndBtn);
wxFont& font = GetFont();
if ( font.Ok() )
if ( hfont )
{
SendMessage(hwndBtn, WM_SETFONT,
(WPARAM)font.GetResourceHandle(), 0L);
::SendMessage(hwndBtn, WM_SETFONT, (WPARAM)hfont, 0L);
}
m_subControls.Append((wxObject *)(WXDWORD)(WXWORD)newId);
m_subControls.Add(newId);
}
// Create a dummy radio control to end the group.
(void)CreateWindowEx(0, RADIO_CLASS, wxT(""), WS_GROUP | RADIO_FLAGS,
(void)::CreateWindow(_T("BUTTON"),
_T(""),
WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
0, 0, 0, 0, hwndParent,
(HMENU)NewControlId(), wxGetInstance(), NULL);
SetSelection(0);
SetSize(x, y, width, height);
SetSize(pos.x, pos.y, size.x, size.y);
return TRUE;
}
@ -364,10 +362,14 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
yy = currentY;
wxString buf;
#if RADIOBTN_PARENT_IS_RADIOBOX
int y_offset = 0;
int x_offset = 0;
#else
int y_offset = yy;
int x_offset = xx;
#endif
int current_width, cyf;
int cx1,cy1;
@ -386,8 +388,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (m_radioWidth[i]<0)
{
// It's a labelled toggle
buf = wxGetWindowText(m_radioButtons[i]);
GetTextExtent(buf, &current_width, &cyf);
GetTextExtent(wxGetWindowText(m_radioButtons[i]),
&current_width, &cyf);
eachWidth = (int)(current_width + RADIO_SIZE);
eachHeight = (int)((3*cyf)/2);
}
@ -409,7 +411,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
int totHeight;
int nbHor = GetNumHor(),
nbVer = GetNumVer();
nbVer = GetNumVer();
// this formula works, but I don't know why.
// Please, be sure what you do if you modify it!!
@ -444,7 +446,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
height = heightOld;
}
MoveWindow(GetHwnd(), x_offset, y_offset, width, height, TRUE);
::MoveWindow(GetHwnd(), xx, yy, width, height, TRUE);
x_offset += cx1;
y_offset += cy1;
@ -480,8 +482,8 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
if (m_radioWidth[i]<0)
{
// It's a labeled item
buf = wxGetWindowText(m_radioButtons[i]);
GetTextExtent(buf, &current_width, &cyf);
GetTextExtent(wxGetWindowText(m_radioButtons[i]),
&current_width, &cyf);
// How do we find out radio button bitmap size!!
// By adjusting them carefully, manually :-)
@ -494,9 +496,13 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
eachHeight = m_radioHeight[i];
}
MoveWindow((HWND)m_radioButtons[i], x_offset, y_offset,
eachWidth, eachHeight,
TRUE);
// VZ: make all buttons of the same, maximal size - like this they
// cover the radiobox entirely and the radiobox tooltips are always
// shown (otherwise they are not when the mouse pointer is in the
// radiobox part not belonging to any radiobutton)
::MoveWindow((HWND)m_radioButtons[i],
x_offset, y_offset, maxWidth, maxHeight,
TRUE);
if (m_windowStyle & wxRA_SPECIFY_ROWS)
{
@ -528,8 +534,7 @@ void wxRadioBox::GetSize(int *width, int *height) const
void wxRadioBox::GetPosition(int *x, int *y) const
{
wxWindow *parent = GetParent();
RECT rect;
rect.left = -1; rect.right = -1; rect.top = -1; rect.bottom = -1;
RECT rect = { -1, -1, -1, -1 };
int i;
for (i = 0; i < m_noItems; i++)
@ -538,8 +543,8 @@ void wxRadioBox::GetPosition(int *x, int *y) const
if (m_hWnd)
wxFindMaxSize(m_hWnd, &rect);
// Since we now have the absolute screen coords,
// if there's a parent we must subtract its top left corner
// Since we now have the absolute screen coords, if there's a parent we
// must subtract its top left corner
POINT point;
point.x = rect.left;
point.y = rect.top;
@ -547,9 +552,9 @@ void wxRadioBox::GetPosition(int *x, int *y) const
{
::ScreenToClient((HWND) parent->GetHWND(), &point);
}
// We may be faking the client origin.
// So a window that's really at (0, 30) may appear
// (to wxWin apps) to be at (0, 0).
// We may be faking the client origin. So a window that's really at (0, 30)
// may appear (to wxWin apps) to be at (0, 0).
if (GetParent())
{
wxPoint pt(GetParent()->GetClientAreaOrigin());
@ -617,30 +622,6 @@ void wxRadioBox::Show(int item, bool show)
::ShowWindow((HWND)m_radioButtons[item], show ? SW_SHOW : SW_HIDE);
}
WXHBRUSH wxRadioBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
// For single selection items only
wxString wxRadioBox::GetStringSelection() const
{
@ -716,68 +697,91 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
WPARAM wParam,
LPARAM lParam)
{
bool processed = TRUE;
if ( msg != WM_KEYDOWN )
processed = FALSE;
if ( processed )
bool processed = FALSE;
if ( msg == WM_KEYDOWN
#if wxUSE_TOOLTIPS
|| msg == WM_NOTIFY
#endif // wxUSE_TOOLTIPS
)
{
wxRadioBox *radiobox = (wxRadioBox *)::GetWindowLong(hwnd, GWL_USERDATA);
wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
int sel = radiobox->GetSelection();
switch ( wParam )
#if wxUSE_TOOLTIPS
if ( msg == WM_NOTIFY )
{
case VK_UP:
sel--;
break;
case VK_LEFT:
sel -= radiobox->GetNumVer();
break;
case VK_DOWN:
sel++;
break;
case VK_RIGHT:
sel += radiobox->GetNumVer();
break;
case VK_TAB:
{
wxNavigationKeyEvent event;
event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100));
event.SetWindowChange(FALSE);
event.SetEventObject(radiobox);
if ( radiobox->GetEventHandler()->ProcessEvent(event) )
return 0;
}
// fall through
default:
processed = FALSE;
}
if ( processed )
{
if ( sel >= 0 && sel < radiobox->Number() )
NMHDR* hdr = (NMHDR *)lParam;
if ( (int)hdr->code == TTN_NEEDTEXT )
{
radiobox->SetSelection(sel);
wxToolTip *tt = radiobox->GetToolTip();
if ( tt )
{
TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
ttt->lpszText = (wxChar *)tt->GetTip().c_str();
// emulate the button click
radiobox->SendNotificationEvent();
processed = TRUE;
}
}
}
else // msg == WM_KEYDOWN
#endif // wxUSE_TOOLTIPS
{
processed = TRUE;
int sel = radiobox->GetSelection();
switch ( wParam )
{
case VK_UP:
sel--;
break;
case VK_LEFT:
sel -= radiobox->GetNumVer();
break;
case VK_DOWN:
sel++;
break;
case VK_RIGHT:
sel += radiobox->GetNumVer();
break;
case VK_TAB:
{
wxNavigationKeyEvent event;
event.SetDirection(!(::GetKeyState(VK_SHIFT) & 0x100));
event.SetWindowChange(FALSE);
event.SetEventObject(radiobox);
if ( radiobox->GetEventHandler()->ProcessEvent(event) )
return 0;
}
// fall through
default:
processed = FALSE;
}
if ( processed )
{
if ( sel >= 0 && sel < radiobox->Number() )
{
radiobox->SetSelection(sel);
// emulate the button click
radiobox->SendNotificationEvent();
}
}
}
}
if ( !processed )
return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam);
else
if ( processed )
return 0;
return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam);
}
#endif // __WIN32__

View File

@ -157,33 +157,6 @@ bool wxRadioButton::GetValue(void) const
return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0L) != 0);
}
WXHBRUSH wxRadioButton::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
// has a zero usage count.
// backgroundBrush->RealizeResource();
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
void wxRadioButton::Command (wxCommandEvent & event)
{
SetValue ( (event.m_commandInt != 0) );

View File

@ -531,16 +531,7 @@ WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
return 0;
// Otherwise, it's a static
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
}
// For trackbars only

View File

@ -481,17 +481,7 @@ WXHBRUSH wxSliderMSW::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
return 0;
// Otherwise, it's a static
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
return wxControl::OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
}
// For trackbars only

View File

@ -61,7 +61,7 @@ bool wxStaticBox::Create(wxWindow *parent,
long style,
const wxString& name)
{
if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
if ( !CreateControl(parent, id, pos, size, style, name) )
return FALSE;
if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX, pos, size, label, 0) )
@ -84,34 +84,6 @@ wxSize wxStaticBox::DoGetBestSize() const
return wxSize(wBox, hBox);
}
WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message,
WXWPARAM wParam,
WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif // wxUSE_CTL3D
HDC hdc = (HDC)pDC;
if (GetParent()->GetTransparentBackground())
SetBkMode(hdc, TRANSPARENT);
else
SetBkMode(hdc, OPAQUE);
const wxColour& colBack = GetBackgroundColour();
::SetBkColor(hdc, wxColourToRGB(colBack));
::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
return (WXHBRUSH)brush->GetResourceHandle();
}
long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
switch ( nMsg )

View File

@ -150,39 +150,6 @@ void wxStaticText::SetLabel(const wxString& label)
}
}
WXHBRUSH wxStaticText::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
/*
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
if (hbrush != (HBRUSH) 0)
return hbrush;
else
return (HBRUSH)MSWDefWindowProc(message, wParam, lParam);
}
#endif
*/
if (GetParent()->GetTransparentBackground())
SetBkMode((HDC) pDC, TRANSPARENT);
else
SetBkMode((HDC) pDC, OPAQUE);
::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
// Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
// has a zero usage count.
// backgroundBrush->RealizeResource();
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
long wxStaticText::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
// Ensure that static items get messages. Some controls don't like this

View File

@ -764,30 +764,6 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
}
}
WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
WXUINT message, WXWPARAM wParam,
WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
{
HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
return (WXHBRUSH) hbrush;
}
#endif
HDC hdc = (HDC)pDC;
SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
: OPAQUE);
::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
void wxTextCtrl::OnChar(wxKeyEvent& event)
{
switch ( event.KeyCode() )

View File

@ -32,16 +32,32 @@
#include "wx/tooltip.h"
#include "wx/msw/private.h"
#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
#include <commctrl.h>
#if defined(__WIN95__) && !defined(__GNUWIN32_OLD__)
#include <commctrl.h>
#endif
// VZ: normally, the trick with subclassing the tooltip control and processing
// TTM_WINDOWFROMPOINT should work but, somehow, it doesn't. I leave the
// code here for now (but it's not compiled) in case we need it later.
//
// For now, instead of this, we just add all radiobox buttons to the
// tooltip control as well (see SetWindow) - this is probably less
// efficient, but it works.
#define wxUSE_TTM_WINDOWFROMPOINT 0
// ----------------------------------------------------------------------------
// global variables
// ----------------------------------------------------------------------------
// the tooltip parent window
WXHWND wxToolTip::hwndTT = (WXHWND)NULL;
WXHWND wxToolTip::ms_hwndTT = (WXHWND)NULL;
#if wxUSE_TTM_WINDOWFROMPOINT
// the tooltip window proc
static WNDPROC gs_wndprocToolTip = (WNDPROC)NULL;
#endif // wxUSE_TTM_WINDOWFROMPOINT
// ----------------------------------------------------------------------------
// private classes
@ -54,14 +70,14 @@ WXHWND wxToolTip::hwndTT = (WXHWND)NULL;
class wxToolInfo : public TOOLINFO
{
public:
wxToolInfo(wxWindow *win)
wxToolInfo(HWND hwnd)
{
// initialize all members
::ZeroMemory(this, sizeof(TOOLINFO));
cbSize = sizeof(TOOLINFO);
uFlags = TTF_IDISHWND;
uId = (UINT)win->GetHWND();
uId = (UINT)hwnd;
}
};
#ifdef __VISUALC__
@ -88,28 +104,68 @@ static void SendTooltipMessageToAll(WXHWND hwnd,
WPARAM wParam,
LPARAM lParam)
{
if ( hwnd )
(void)SendTooltipMessage((WXHWND)hwnd, msg, wParam, (void *)lParam);
(void)SendTooltipMessage((WXHWND)hwnd, msg, wParam, (void *)lParam);
}
// ============================================================================
// implementation
// ============================================================================
#if wxUSE_TTM_WINDOWFROMPOINT
// ----------------------------------------------------------------------------
// window proc for our tooltip control
// ----------------------------------------------------------------------------
LRESULT APIENTRY wxToolTipWndProc(HWND hwndTT,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
if ( msg == TTM_WINDOWFROMPOINT )
{
LPPOINT ppt = (LPPOINT)lParam;
// is the window under control a wxWindow?
HWND hwnd = ::WindowFromPoint(*ppt);
// return a HWND correspondign to wxWindow because only wxWindows are
// associated with tooltips using TTM_ADDTOOL
while ( hwnd && !wxFindWinFromHandle((WXHWND)hwnd) )
{
hwnd = ::GetParent(hwnd);
}
if ( hwnd )
{
// modify the point too!
RECT rect;
GetWindowRect(hwnd, &rect);
ppt->x = rect.left;
ppt->y = rect.top;
return (LRESULT)hwnd;
}
}
return ::CallWindowProc(gs_wndprocToolTip, hwndTT, msg, wParam, lParam);
}
#endif // wxUSE_TTM_WINDOWFROMPOINT
// ----------------------------------------------------------------------------
// static functions
// ----------------------------------------------------------------------------
void wxToolTip::Enable(bool flag)
{
SendTooltipMessageToAll((WXHWND)hwndTT,TTM_ACTIVATE, flag, 0);
SendTooltipMessageToAll(ms_hwndTT, TTM_ACTIVATE, flag, 0);
}
void wxToolTip::SetDelay(long milliseconds)
{
SendTooltipMessageToAll((WXHWND)hwndTT,TTM_SETDELAYTIME, TTDT_INITIAL, milliseconds);
SendTooltipMessageToAll(ms_hwndTT, TTM_SETDELAYTIME,
TTDT_INITIAL, milliseconds);
}
// ---------------------------------------------------------------------------
@ -119,25 +175,31 @@ void wxToolTip::SetDelay(long milliseconds)
// create the tooltip ctrl for our parent frame if it doesn't exist yet
WXHWND wxToolTip::GetToolTipCtrl()
{
if ( !hwndTT )
if ( !ms_hwndTT )
{
hwndTT = (WXHWND)::CreateWindow(TOOLTIPS_CLASS,
(LPSTR)NULL,
TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU)NULL,
wxGetInstance(),
NULL);
if ( hwndTT )
ms_hwndTT = (WXHWND)::CreateWindow(TOOLTIPS_CLASS,
(LPSTR)NULL,
TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU)NULL,
wxGetInstance(),
NULL);
if ( ms_hwndTT )
{
SetWindowPos((HWND)hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
HWND hwnd = (HWND)ms_hwndTT;
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
#if wxUSE_TTM_WINDOWFROMPOINT
// subclass the newly created control
gs_wndprocToolTip = (WNDPROC)::GetWindowLong(hwnd, GWL_WNDPROC);
::SetWindowLong(hwnd, GWL_WNDPROC, (long)wxToolTipWndProc);
#endif // wxUSE_TTM_WINDOWFROMPOINT
}
}
return (WXHWND)hwndTT;
return ms_hwndTT;
}
void wxToolTip::RelayEvent(WXMSG *msg)
@ -170,32 +232,57 @@ void wxToolTip::Remove()
// remove this tool from the tooltip control
if ( m_window )
{
wxToolInfo ti(m_window);
wxToolInfo ti(GetHwndOf(m_window));
(void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL, 0, &ti);
}
}
void wxToolTip::Add(WXHWND hWnd)
{
HWND hwnd = (HWND)hWnd;
wxToolInfo ti(hwnd);
// as we store our text anyhow, it seems useless to waste system memory
// by asking the tooltip ctrl to remember it too - instead it will send
// us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
ti.hwnd = hwnd;
ti.lpszText = LPSTR_TEXTCALLBACK;
// instead of: ti.lpszText = (char *)m_text.c_str();
if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, 0, &ti) )
{
wxLogSysError(_("Failed to create the tooltip '%s'"),
m_text.c_str());
}
}
void wxToolTip::SetWindow(wxWindow *win)
{
Remove();
m_window = win;
// add the window itself
if ( m_window )
{
wxToolInfo ti(m_window);
Add(m_window->GetHWND());
}
// as we store our text anyhow, it seems useless to waste system memory
// by asking the tooltip ctrl to remember it too - instead it will send
// us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown
ti.hwnd = (HWND)m_window->GetHWND();
ti.lpszText = LPSTR_TEXTCALLBACK;
// instead of: ti.lpszText = (char *)m_text.c_str();
if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, 0, &ti) )
// and all of its subcontrols (e.g. radiobuttons in a radiobox) as well
wxControl *control = wxDynamicCast(m_window, wxControl);
if ( control )
{
size_t count = control->GetSubcontrols().GetCount();
for ( size_t n = 0; n < count; n++ )
{
wxLogSysError(_("Failed to create the tooltip '%s'"),
m_text.c_str());
wxWindowID id = control->GetSubcontrols()[n];
HWND hwnd = GetDlgItem(GetHwndOf(m_window), id);
if ( hwnd )
{
Add((WXHWND)hwnd);
}
}
}
}
@ -207,7 +294,7 @@ void wxToolTip::SetTip(const wxString& tip)
if ( m_window )
{
// update it immediately
wxToolInfo ti(m_window);
wxToolInfo ti(GetHwndOf(m_window));
ti.lpszText = (wxChar *)m_text.c_str();
(void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);

View File

@ -163,6 +163,17 @@ END_EVENT_TABLE()
// Find an item given the MS Windows id
wxWindow *wxWindow::FindItem(long id) const
{
wxControl *item = wxDynamicCast(this, wxControl);
if ( item )
{
// i it we or one of our "internal" children?
if ( item->GetId() == id ||
(item->GetSubcontrols().Index(id) != wxNOT_FOUND) )
{
return item;
}
}
wxWindowList::Node *current = GetChildren().GetFirst();
while (current)
{
@ -172,19 +183,6 @@ wxWindow *wxWindow::FindItem(long id) const
if ( wnd )
return wnd;
if ( childWin->IsKindOf(CLASSINFO(wxControl)) )
{
wxControl *item = (wxControl *)childWin;
if ( item->GetId() == id )
return item;
else
{
// In case it's a 'virtual' control (e.g. radiobox)
if ( item->GetSubcontrols().Member((wxObject *)id) )
return item;
}
}
current = current->GetNext();
}
@ -2946,7 +2944,8 @@ bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
return popupMenu->MSWCommand(cmd, id);
}
wxWindow *win = FindItem(id);
// must cast to a signed type before comparing with other ids!
wxWindow *win = FindItem((signed short)id);
if ( !win )
{
win = wxFindWinFromHandle(control);