Integrated fixes for sizing/positioning; cleanup; removal of handle/window

association in dtor. (All according to patch #1396667).


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36745 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Neis
2006-01-06 23:43:45 +00:00
parent 179db36df4
commit a4ebf7ba61
2 changed files with 44 additions and 240 deletions

View File

@@ -126,22 +126,12 @@ public:
virtual int GetCount(void) const; virtual int GetCount(void) const;
inline int GetNumberOfRowsOrCols(void) const { return m_nNoRowsOrCols; }
void GetPosition( int* pnX
,int* pnY
) const;
inline WXHWND* GetRadioButtons(void) const { return m_ahRadioButtons; } inline WXHWND* GetRadioButtons(void) const { return m_ahRadioButtons; }
int GetSelection(void) const; int GetSelection(void) const;
void GetSize( int* pnX void GetSize( int* pnX
,int* pnY ,int* pnY
) const; ) const;
inline int GetSizeFlags(void) const { return m_nSizeFlags; } inline int GetSizeFlags(void) const { return m_nSizeFlags; }
void AdjustButtons( int nX
,int nY
,int nWidth
,int nHeight
,int nSizeFlags
);
wxString GetString(int nIndex) const; wxString GetString(int nIndex) const;
virtual wxString GetStringSelection(void) const; virtual wxString GetStringSelection(void) const;
@@ -149,7 +139,6 @@ public:
void SetFocus(void); void SetFocus(void);
virtual bool SetFont(const wxFont& rFont); virtual bool SetFont(const wxFont& rFont);
inline void SetLabelFont(const wxFont& WXUNUSED(font)) {}; inline void SetLabelFont(const wxFont& WXUNUSED(font)) {};
inline void SetNumberOfRowsOrCols(int nNum) { m_nNoRowsOrCols = nNum; }
void SetSelection(int nIndex); void SetSelection(int nIndex);
virtual void SetString( int nNum virtual void SetString( int nNum
,const wxString& rsLabel ,const wxString& rsLabel
@@ -182,7 +171,6 @@ protected:
int* m_pnRadioWidth; // for bitmaps int* m_pnRadioWidth; // for bitmaps
int* m_pnRadioHeight; int* m_pnRadioHeight;
int m_nNoItems; int m_nNoItems;
int m_nNoRowsOrCols;
int m_nSelectedButton; int m_nSelectedButton;
int m_nSizeFlags; int m_nSizeFlags;

View File

@@ -46,10 +46,11 @@ MRESULT EXPENTRY wxRadioBoxWndProc( HWND hWnd
// global vars // global vars
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// the pointer to standard radio button wnd proc
extern void wxAssociateWinWithHandle( HWND hWnd extern void wxAssociateWinWithHandle( HWND hWnd
,wxWindowOS2* pWin ,wxWindowOS2* pWin
); );
extern void wxRemoveHandleAssociation( wxWindowOS2 *pWin );
// the pointer to standard radio button & box wnd procs
static WXFARPROC fnWndProcRadioBtn = NULL; static WXFARPROC fnWndProcRadioBtn = NULL;
static WXFARPROC fnWndProcRadioBox = NULL; static WXFARPROC fnWndProcRadioBox = NULL;
@@ -66,7 +67,6 @@ wxRadioBox::wxRadioBox()
{ {
m_nSelectedButton = -1; m_nSelectedButton = -1;
m_nNoItems = 0; m_nNoItems = 0;
m_nNoRowsOrCols = 0;
m_ahRadioButtons = NULL; m_ahRadioButtons = NULL;
m_pnRadioWidth = NULL; m_pnRadioWidth = NULL;
m_pnRadioHeight = NULL; m_pnRadioHeight = NULL;
@@ -76,11 +76,17 @@ wxRadioBox::~wxRadioBox()
{ {
m_isBeingDeleted = true; m_isBeingDeleted = true;
if (m_hWnd)
wxRemoveHandleAssociation(this);
if (m_ahRadioButtons) if (m_ahRadioButtons)
{ {
int i; for (int i = 0; i < m_nNoItems; i++)
for (i = 0; i < m_nNoItems; i++) {
wxWindow* pWin = wxFindWinFromHandle((WXHWND)m_ahRadioButtons[i]);
wxRemoveHandleAssociation(pWin);
::WinDestroyWindow((HWND)m_ahRadioButtons[i]); ::WinDestroyWindow((HWND)m_ahRadioButtons[i]);
}
delete[] m_ahRadioButtons; delete[] m_ahRadioButtons;
} }
if (m_pnRadioWidth) if (m_pnRadioWidth)
@@ -89,143 +95,6 @@ wxRadioBox::~wxRadioBox()
delete[] m_pnRadioHeight; delete[] m_pnRadioHeight;
} // end of wxRadioBox::~wxRadioBox } // end of wxRadioBox::~wxRadioBox
void wxRadioBox::AdjustButtons( int nX,
int nY,
int nWidth,
int nHeight,
int WXUNUSED(nSizeFlags) )
{
wxSize vMaxSize;
int nXOffset = nX;
int nYOffset = nY + nHeight;
int nCx1;
int nCy1;
int nStartX;
int nStartY;
int nMaxWidth;
int nMaxHeight;
wxFont vFont = GetFont();
wxGetCharSize( m_hWnd
,&nCx1
,&nCy1
,&vFont
);
vMaxSize = GetMaxButtonSize();
nMaxWidth = vMaxSize.x;
nMaxHeight = vMaxSize.y;
nXOffset += nCx1;
nYOffset -= (nMaxHeight + ((3*nCy1)/2));
nStartX = nXOffset;
nStartY = nYOffset;
for (int i = 0; i < m_nNoItems; i++)
{
//
// The last button in the row may be wider than the other ones as the
// radiobox may be wider than the sum of the button widths (as it
// happens, for example, when the radiobox label is very long)
//
bool bIsLastInTheRow;
if (m_windowStyle & wxRA_SPECIFY_COLS)
{
//
// Item is the last in its row if it is a multiple of the number of
// columns or if it is just the last item
//
int n = i + 1;
bIsLastInTheRow = ((n % GetMajorDim()) == 0) || (n == m_nNoItems);
}
else // winRA_SPECIFY_ROWS
{
//
// Item is the last in the row if it is in the last columns
//
bIsLastInTheRow = i >= (m_nNoItems/GetMajorDim()) * GetMajorDim();
}
//
// Is this the start of new row/column?
//
if (i && (i % GetMajorDim() == 0))
{
if (m_windowStyle & wxRA_SPECIFY_ROWS)
{
//
// Start of new column
//
nYOffset = nStartY;
nXOffset += nMaxWidth + nCx1;
}
else // start of new row
{
nXOffset = nStartX;
nYOffset -= nMaxHeight;
if (m_pnRadioWidth[0] > 0L)
nYOffset -= nCy1/2;
}
}
int nWidthBtn;
if (bIsLastInTheRow)
{
//
// Make the button go to the end of radio box
//
nWidthBtn = nStartX + nWidth - nXOffset - (2 * nCx1);
if (nWidthBtn < nMaxWidth)
nWidthBtn = nMaxWidth;
}
else
{
//
// Normal button, always of the same size
//
nWidthBtn = nMaxWidth;
}
//
// 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)
//
::WinSetWindowPos( (HWND)m_ahRadioButtons[i]
,HWND_BOTTOM
,(LONG)nXOffset
,(LONG)nYOffset
,(LONG)nWidthBtn
,(LONG)nMaxHeight
,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
);
//
// Where do we put the next button?
//
if (m_windowStyle & wxRA_SPECIFY_ROWS)
{
//
// Below this one
//
nYOffset -= nMaxHeight;
if (m_pnRadioWidth[0] > 0)
nYOffset -= nCy1/2;
}
else
{
//
// To the right of this one
//
nXOffset += nWidthBtn + nCx1;
}
}
} // end of wxRadioBox::AdjustButtons
void wxRadioBox::Command ( void wxRadioBox::Command (
wxCommandEvent& rEvent wxCommandEvent& rEvent
) )
@@ -284,6 +153,7 @@ bool wxRadioBox::Create(
{ {
wxColour vColour; wxColour vColour;
LONG lColor; LONG lColor;
HWND hWndParent = GetHwndOf(pParent);
vColour.Set(wxString(wxT("BLACK"))); vColour.Set(wxString(wxT("BLACK")));
m_backgroundColour = pParent->GetBackgroundColour(); m_backgroundColour = pParent->GetBackgroundColour();
@@ -317,12 +187,7 @@ bool wxRadioBox::Create(
// //
m_nNoItems = nNum; m_nNoItems = nNum;
SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle); SetMajorDim(nMajorDim == 0 ? nNum : nMajorDim, lStyle);
m_nNoRowsOrCols = nMajorDim;
//
// Some radio boxes test consecutive id.
//
(void)NewControlId();
m_ahRadioButtons = new WXHWND[nNum]; m_ahRadioButtons = new WXHWND[nNum];
m_pnRadioWidth = new int[nNum]; m_pnRadioWidth = new int[nNum];
m_pnRadioHeight = new int[nNum]; m_pnRadioHeight = new int[nNum];
@@ -330,41 +195,42 @@ bool wxRadioBox::Create(
for (int i = 0; i < nNum; i++) for (int i = 0; i < nNum; i++)
{ {
m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1; m_pnRadioWidth[i] = m_pnRadioHeight[i] = -1;
long lStyleBtn = BS_AUTORADIOBUTTON | WS_VISIBLE;
long lStyleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE;
int nNewId = NewControlId(); int nNewId = NewControlId();
if (i == 0) if (i == 0)
lStyleBtn |= WS_GROUP; lStyleBtn |= WS_GROUP | WS_TABSTOP;
HWND hWndBtn = (WXHWND)::WinCreateWindow ( GetHwndOf(pParent) wxString sLabel = ::wxPMTextToLabel(asChoices[i]);
,WC_BUTTON
,::wxPMTextToLabel(asChoices[i]) HWND hWndBtn = (WXHWND)::WinCreateWindow ( hWndParent,
,lStyleBtn WC_BUTTON,
,0, 0, 0, 0 sLabel.c_str(),
,GetWinHwnd(pParent) lStyleBtn,
,HWND_BOTTOM 0, 0, 0, 0,
,(HMENU)nNewId hWndParent,
,NULL HWND_BOTTOM,
,NULL (HMENU)nNewId,
NULL,
NULL
); );
if (!hWndBtn)
{
return false;
}
lColor = (LONG)vColour.GetPixel(); lColor = (LONG)vColour.GetPixel();
::WinSetPresParam( hWndBtn ::WinSetPresParam( hWndBtn
,PP_FOREGROUNDCOLOR ,PP_FOREGROUNDCOLOR
,sizeof(LONG) ,sizeof(LONG)
,(PVOID)&lColor ,(PVOID)&lColor
); );
lColor = (LONG)m_backgroundColour.GetPixel();
lColor = (LONG)m_backgroundColour.GetPixel();
::WinSetPresParam( hWndBtn ::WinSetPresParam( hWndBtn
,PP_BACKGROUNDCOLOR ,PP_BACKGROUNDCOLOR
,sizeof(LONG) ,sizeof(LONG)
,(PVOID)&lColor ,(PVOID)&lColor
); );
if (!hWndBtn)
{
return false;
}
m_ahRadioButtons[i] = (WXHWND)hWndBtn; m_ahRadioButtons[i] = (WXHWND)hWndBtn;
SubclassRadioButton((WXHWND)hWndBtn); SubclassRadioButton((WXHWND)hWndBtn);
wxAssociateWinWithHandle(hWndBtn, this); wxAssociateWinWithHandle(hWndBtn, this);
@@ -378,18 +244,17 @@ bool wxRadioBox::Create(
// //
// Create a dummy control to end the group. // Create a dummy control to end the group.
// //
(void)::WinCreateWindow ( GetHwndOf(pParent), (void)::WinCreateWindow ( hWndParent,
WC_BUTTON, WC_BUTTON,
"", "",
WS_GROUP, WS_GROUP,
0, 0, 0, 0, 0, 0, 0, 0,
GetWinHwnd(pParent), hWndParent,
HWND_TOP, HWND_TOP,
(HMENU)NewControlId(), (HMENU)NewControlId(),
NULL, NULL,
NULL NULL
); );
SetFont(*wxSMALL_FONT);
fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd() fnWndProcRadioBox = (WXFARPROC)::WinSubclassWindow( GetHwnd()
,(PFNWP)wxRadioBoxWndProc ,(PFNWP)wxRadioBoxWndProc
); );
@@ -421,7 +286,7 @@ bool wxRadioBox::Create(
wxSize wxRadioBox::DoGetBestSize() const wxSize wxRadioBox::DoGetBestSize() const
{ {
return (GetTotalButtonSize(GetMaxButtonSize())); return (GetTotalButtonSize(GetMaxButtonSize()));
} // end of WinGuiBase_CRadioBox::DoGetBestSize } // end of wxRadioBox::DoGetBestSize
void wxRadioBox::DoSetSize( void wxRadioBox::DoSetSize(
int nX int nX
@@ -431,6 +296,9 @@ void wxRadioBox::DoSetSize(
, int nSizeFlags , int nSizeFlags
) )
{ {
//
// Input parameters assume wxWidgets coordinate system
//
int nCurrentX; int nCurrentX;
int nCurrentY; int nCurrentY;
int nWidthOld; int nWidthOld;
@@ -505,22 +373,19 @@ void wxRadioBox::DoSetSize(
nHeight = nHeightOld; nHeight = nHeightOld;
} }
//
// Now convert to OS/2 coordinate system
//
wxWindowOS2* pParent = (wxWindowOS2*)GetParent(); wxWindowOS2* pParent = (wxWindowOS2*)GetParent();
if (pParent) if (pParent)
{ nYy = GetOS2ParentHeight(pParent) - nYy - nHeight;
int nOS2Height = GetOS2ParentHeight(pParent);
nYy = nOS2Height - (nYy + nHeight);
nYOffset = nYy + nHeight;
}
else else
{ {
RECTL vRect; RECTL vRect;
::WinQueryWindowRect(HWND_DESKTOP, &vRect); ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
nYy = vRect.yTop - (nYy + nHeight); nYy = vRect.yTop - nYy - nHeight;
} }
nYOffset = nYy + nHeight;
::WinSetWindowPos( GetHwnd() ::WinSetWindowPos( GetHwnd()
,HWND_TOP ,HWND_TOP
,(LONG)nXx ,(LONG)nXx
@@ -582,7 +447,6 @@ void wxRadioBox::DoSetSize(
{ {
if (m_windowStyle & wxRA_SPECIFY_ROWS) if (m_windowStyle & wxRA_SPECIFY_ROWS)
{ {
// //
// Start of new column // Start of new column
// //
@@ -724,53 +588,6 @@ wxSize wxRadioBox::GetMaxButtonSize() const
return maxsize; return maxsize;
} // end of wxRadioBox::GetMaxButtonSize } // end of wxRadioBox::GetMaxButtonSize
void wxRadioBox::GetPosition( int* pnX,
int* WXUNUSED(pnY) ) const
{
wxWindowOS2* pParent = GetParent();
RECT vRect = { -1, -1, -1, -1 };
POINTL vPoint;
int i;
for (i = 0; i < m_nNoItems; i++)
wxFindMaxSize( m_ahRadioButtons[i]
,&vRect
);
if (m_hWnd)
wxFindMaxSize( m_hWnd
,&vRect
);
//
// Since we now have the absolute screen coords, if there's a parent we
// must subtract its top left corner
//
vPoint.x = vRect.xLeft;
vPoint.y = vRect.yTop;
if (pParent)
{
SWP vSwp;
::WinQueryWindowPos((HWND)pParent->GetHWND(), &vSwp);
vPoint.x = vSwp.x;
vPoint.y = vSwp.y;
}
//
// 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 vPt(GetParent()->GetClientAreaOrigin());
vPoint.x = vPt.x;
vPoint.y = vPt.y;
}
if (pnX)
*pnX = vPoint.y;
} // end of wxRadioBox::GetPosition
// Get single selection, for single choice list items // Get single selection, for single choice list items
int wxRadioBox::GetSelection() const int wxRadioBox::GetSelection() const
{ {
@@ -780,7 +597,6 @@ int wxRadioBox::GetSelection() const
void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const
{ {
RECT vRect; RECT vRect;
int i;
vRect.xLeft = -1; vRect.xLeft = -1;
vRect.xRight = -1; vRect.xRight = -1;
@@ -792,7 +608,7 @@ void wxRadioBox::GetSize( int* pnWidth, int* pnHeight ) const
,&vRect ,&vRect
); );
for (i = 0; i < m_nNoItems; i++) for (int i = 0; i < m_nNoItems; i++)
wxFindMaxSize( m_ahRadioButtons[i] wxFindMaxSize( m_ahRadioButtons[i]
,&vRect ,&vRect
); );
@@ -808,6 +624,7 @@ wxString wxRadioBox::GetString(
int nNum int nNum
) const ) const
{ {
wxCHECK_MSG( IsValid(nNum), wxString(""), wxT("invalid radiobox index") );
return wxGetWindowText(m_ahRadioButtons[nNum]); return wxGetWindowText(m_ahRadioButtons[nNum]);
} // end of wxRadioBox::GetString } // end of wxRadioBox::GetString
@@ -887,7 +704,6 @@ bool wxRadioBox::OS2Command( WXUINT uCmd,
if (wId == GetId()) if (wId == GetId())
return true; return true;
for (int i = 0; i < m_nNoItems; i++) for (int i = 0; i < m_nNoItems; i++)
{ {
if (wId == wxGetWindowId(m_ahRadioButtons[i])) if (wId == wxGetWindowId(m_ahRadioButtons[i]))