1) minor modifications in fileconf.cpp

2) new MSW function (private.h): wxGetWindowText() which works with wxString
   instead of (horror) fixed size buffers. All calls to ::GetWindowText()
   should be replaced with this!
3) remains of casts to float in different wxControl classes removed,
   (EDIT|BUTTON)_HEIGHT_FROM_CHAR_HEIGHT macros introduced (could be
   made inline functions as well...)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@765 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-09-20 21:13:46 +00:00
parent 803bf1c581
commit 1c4a764c98
11 changed files with 111 additions and 90 deletions

View File

@@ -126,8 +126,9 @@ VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ;
#define MEANING_CHARACTER '0' #define MEANING_CHARACTER '0'
#define DEFAULT_ITEM_WIDTH 200 #define DEFAULT_ITEM_WIDTH 200
#define DEFAULT_ITEM_HEIGHT 80 #define DEFAULT_ITEM_HEIGHT 80
#define EDIT_CONTROL_FACTOR (15.0/10.0)
// Scale font to get edit control height // Scale font to get edit control height
#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
// Generic subclass proc, for panel item moving/sizing and intercept // Generic subclass proc, for panel item moving/sizing and intercept
// EDIT control VK_RETURN messages // EDIT control VK_RETURN messages
@@ -147,6 +148,9 @@ WXDLLEXPORT_DATA(extern HINSTANCE) wxhInstance;
wxWindow* WXDLLEXPORT wxFindControlFromHandle(WXHWND hWnd); wxWindow* WXDLLEXPORT wxFindControlFromHandle(WXHWND hWnd);
void WXDLLEXPORT wxAddControlHandle(WXHWND hWnd, wxWindow *item); void WXDLLEXPORT wxAddControlHandle(WXHWND hWnd, wxWindow *item);
// Safely get the window text (i.e. without using fixed size buffer)
extern wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd);
#if !defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE) #if !defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE)
#define WS_EX_CLIENTEDGE 0 #define WS_EX_CLIENTEDGE 0
#endif #endif

View File

@@ -54,6 +54,13 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#define CONST_CAST ((wxFileConfig *)this)-> #define CONST_CAST ((wxFileConfig *)this)->
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
#ifndef MAX_PATH
#define MAX_PATH 512
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// global functions declarations // global functions declarations
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -87,15 +94,10 @@ wxString wxFileConfig::GetGlobalDir()
#ifdef __UNIX__ #ifdef __UNIX__
strDir = "/etc/"; strDir = "/etc/";
#elif defined(__WXSTUBS__) #elif defined(__WXSTUBS__)
// TODO wxASSERT_MSG( FALSE, "TODO" ) ;
wxASSERT( TRUE ) ;
#else // Windows #else // Windows
#ifndef _MAX_PATH char szWinDir[MAX_PATH];
#define _MAX_PATH 512 ::GetWindowsDirectory(szWinDir, MAX_PATH);
#endif
char szWinDir[_MAX_PATH];
::GetWindowsDirectory(szWinDir, _MAX_PATH);
strDir = szWinDir; strDir = szWinDir;
strDir << '\\'; strDir << '\\';
@@ -108,29 +110,7 @@ wxString wxFileConfig::GetLocalDir()
{ {
wxString strDir; wxString strDir;
#ifdef __UNIX__ wxGetHomeDir(&strDir);
const char *szHome = getenv("HOME");
if ( szHome == NULL ) {
// we're homeless...
wxLogWarning(_("can't find user's HOME, using current directory."));
strDir = ".";
}
else
strDir = szHome;
strDir << '/'; // a double slash is no problem, a missin one yes
#else // Windows
#ifdef __WIN32__
const char *szHome = getenv("HOMEDRIVE");
if ( szHome != NULL )
strDir << szHome;
szHome = getenv("HOMEPATH");
if ( szHome != NULL )
strDir << szHome;
#else // Win16
// Win16 has no idea about home, so use the current directory instead
strDir = ".\\";
#endif // WIN16/32
#endif // UNIX/Win
return strDir; return strDir;
} }

View File

@@ -256,7 +256,11 @@ void wxColourDatabase::Initialize ()
wxColour *wxColourDatabase::FindColour(const wxString& colour) wxColour *wxColourDatabase::FindColour(const wxString& colour)
{ {
wxNode *node = Find((char *) (const char *)colour); // VZ: make the comparaison case insensitive
wxString str = colour;
str.MakeUpper();
wxNode *node = Find(str);
if (node) if (node)
return (wxColour *)node->Data(); return (wxColour *)node->Data();
@@ -290,6 +294,11 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour)
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ; Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
#endif #endif
#ifdef __XVIEW__
Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0);
Xv_opaque root_window = xv_get(screen, XV_ROOT);
Display *display = (Display *)xv_get(root_window, XV_DISPLAY);
#endif
/* MATTHEW: [4] Use wxGetMainColormap */ /* MATTHEW: [4] Use wxGetMainColormap */
if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour)) if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour))

View File

@@ -268,8 +268,9 @@ wxLog *wxLog::GetActiveTarget()
wxLog *wxLog::SetActiveTarget(wxLog *pLogger, bool bNoFlashOld) wxLog *wxLog::SetActiveTarget(wxLog *pLogger, bool bNoFlashOld)
{ {
// flush the old messages before changing // flush the old messages before changing
if ( (ms_pLogger != NULL) && !bNoFlashOld ) if ( (ms_pLogger != NULL) && !bNoFlashOld ) {
ms_pLogger->Flush(); ms_pLogger->Flush();
}
wxLog *pOldLogger = ms_pLogger; wxLog *pOldLogger = ms_pLogger;
ms_pLogger = pLogger; ms_pLogger = pLogger;
@@ -737,14 +738,30 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
((wxLogWindow *)m_pOldLog)->DoLog(level, szString); ((wxLogWindow *)m_pOldLog)->DoLog(level, szString);
} }
if ( m_pLogFrame ) {
switch ( level ) {
case wxLOG_Status:
// by default, these messages are ignored by wxLog, so process
// them ourselves
{
wxString str = TimeStamp();
str << _("Status: ") << szString;
DoLogString(str);
}
break;
// don't put trace messages in the text window for 2 reasons: // don't put trace messages in the text window for 2 reasons:
// 1) there are too many of them // 1) there are too many of them
// 2) they may provoke other trace messages thus sending a program into an // 2) they may provoke other trace messages thus sending a program
// infinite loop // into an infinite loop
if ( m_pLogFrame && level != wxLOG_Trace ) { case wxLOG_Trace:
break;
default:
// and this will format it nicely and call our DoLogString() // and this will format it nicely and call our DoLogString()
wxLog::DoLog(level, szString); wxLog::DoLog(level, szString);
} }
}
m_bHasMessages = TRUE; m_bHasMessages = TRUE;
} }

View File

@@ -30,7 +30,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
#endif #endif
#define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1) #define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
// Buttons // Buttons
@@ -135,7 +135,7 @@ void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags)
actualHeight = hh; actualHeight = hh;
else if (height == -1) else if (height == -1)
{ {
actualHeight = (int)(cyf*BUTTON_HEIGHT_FACTOR) ; actualHeight = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cyf);
} }
MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE); MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);

View File

@@ -204,7 +204,7 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
int cy; int cy;
wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
float control_width, control_height; int control_width, control_height;
// Ignore height parameter because height doesn't // Ignore height parameter because height doesn't
// mean 'initially displayed' height, it refers to the // mean 'initially displayed' height, it refers to the
@@ -219,20 +219,23 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
{ {
// Find the longest string // Find the longest string
if (m_noStrings == 0) if (m_noStrings == 0)
control_width = (float)100.0; {
control_width = 100;
}
else else
{ {
int len, ht; int len, ht;
float longest = (float)0.0; int longest = 0;
int i; int i;
for (i = 0; i < m_noStrings; i++) for (i = 0; i < m_noStrings; i++)
{ {
wxString str(GetString(i)); wxString str(GetString(i));
GetTextExtent(str, &len, &ht, NULL, NULL,GetFont()); GetTextExtent(str, &len, &ht, NULL, NULL,GetFont());
if ( len > longest) longest = len; if ( len > longest)
longest = len;
} }
control_width = (float)(int)(longest + cx*5); control_width = longest + cx*5;
} }
} }
@@ -240,25 +243,26 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
if (h1 <= 0) if (h1 <= 0)
{ {
if (m_noStrings == 0) if (m_noStrings == 0)
h1 = (int)(EDIT_CONTROL_FACTOR*cy*10.0); h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10;
else h1 = (int)(EDIT_CONTROL_FACTOR*cy*(wxMin(10, m_noStrings) + 1)); else
h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1);
} }
// If non-default width... // If non-default width...
if (w1 >= 0) if (w1 >= 0)
control_width = (float)w1; control_width = w1;
control_height = (float)h1; control_height = h1;
// Calculations may have made text size too small // Calculations may have made text size too small
if (control_height <= 0) if (control_height <= 0)
control_height = (float)(int)(cy*EDIT_CONTROL_FACTOR) ; control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if (control_width <= 0) if (control_width <= 0)
control_width = (float)100.0; control_width = 100;
MoveWindow((HWND) GetHWND(), x1, y1, MoveWindow((HWND)GetHWND(), x1, y1,
(int)control_width, (int)control_height, TRUE); control_width, control_height, TRUE);
} }
WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,

View File

@@ -139,10 +139,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
return TRUE; return TRUE;
} }
wxString wxComboBox::GetValue(void) const wxString wxComboBox::GetValue() const
{ {
GetWindowText((HWND) GetHWND(), wxBuffer, 500); return wxGetWindowText(GetHWND());
return wxString(wxBuffer);
} }
void wxComboBox::SetValue(const wxString& value) void wxComboBox::SetValue(const wxString& value)
@@ -179,19 +178,19 @@ void wxComboBox::SetValue(const wxString& value)
} }
// Clipboard operations // Clipboard operations
void wxComboBox::Copy(void) void wxComboBox::Copy()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = (HWND) GetHWND();
SendMessage(hWnd, WM_COPY, 0, 0L); SendMessage(hWnd, WM_COPY, 0, 0L);
} }
void wxComboBox::Cut(void) void wxComboBox::Cut()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = (HWND) GetHWND();
SendMessage(hWnd, WM_CUT, 0, 0L); SendMessage(hWnd, WM_CUT, 0, 0L);
} }
void wxComboBox::Paste(void) void wxComboBox::Paste()
{ {
HWND hWnd = (HWND) GetHWND(); HWND hWnd = (HWND) GetHWND();
SendMessage(hWnd, WM_PASTE, 0, 0L); SendMessage(hWnd, WM_PASTE, 0, 0L);
@@ -219,7 +218,7 @@ void wxComboBox::SetInsertionPoint(long pos)
*/ */
} }
void wxComboBox::SetInsertionPointEnd(void) void wxComboBox::SetInsertionPointEnd()
{ {
/* /*
long pos = GetLastPosition(); long pos = GetLastPosition();
@@ -227,7 +226,7 @@ void wxComboBox::SetInsertionPointEnd(void)
*/ */
} }
long wxComboBox::GetInsertionPoint(void) const long wxComboBox::GetInsertionPoint() const
{ {
/* /*
DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L); DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L);
@@ -236,7 +235,7 @@ long wxComboBox::GetInsertionPoint(void) const
return 0; return 0;
} }
long wxComboBox::GetLastPosition(void) const long wxComboBox::GetLastPosition() const
{ {
/* /*
HWND hWnd = (HWND) GetHWND(); HWND hWnd = (HWND) GetHWND();

View File

@@ -198,7 +198,7 @@ int wxNotebook::GetRowCount() const
int wxNotebook::SetSelection(int nPage) int wxNotebook::SetSelection(int nPage)
{ {
wxASSERT( IS_VALID_PAGE(nPage) ); wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, "notebook page out of range" );
ChangePage(m_nSelection, nPage); ChangePage(m_nSelection, nPage);
@@ -217,7 +217,7 @@ void wxNotebook::AdvanceSelection(bool bForward)
bool wxNotebook::SetPageText(int nPage, const wxString& strText) bool wxNotebook::SetPageText(int nPage, const wxString& strText)
{ {
wxASSERT( IS_VALID_PAGE(nPage) ); wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
TC_ITEM tcItem; TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT; tcItem.mask = TCIF_TEXT;
@@ -228,7 +228,7 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText)
wxString wxNotebook::GetPageText(int nPage) const wxString wxNotebook::GetPageText(int nPage) const
{ {
wxASSERT( IS_VALID_PAGE(nPage) ); wxCHECK_MSG( IS_VALID_PAGE(nPage), "", "notebook page out of range" );
char buf[256]; char buf[256];
TC_ITEM tcItem; TC_ITEM tcItem;
@@ -245,7 +245,7 @@ wxString wxNotebook::GetPageText(int nPage) const
int wxNotebook::GetPageImage(int nPage) const int wxNotebook::GetPageImage(int nPage) const
{ {
wxASSERT( IS_VALID_PAGE(nPage) ); wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, "notebook page out of range" );
TC_ITEM tcItem; TC_ITEM tcItem;
tcItem.mask = TCIF_IMAGE; tcItem.mask = TCIF_IMAGE;
@@ -255,7 +255,7 @@ int wxNotebook::GetPageImage(int nPage) const
bool wxNotebook::SetPageImage(int nPage, int nImage) bool wxNotebook::SetPageImage(int nPage, int nImage)
{ {
wxASSERT( IS_VALID_PAGE(nPage) ); wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
TC_ITEM tcItem; TC_ITEM tcItem;
tcItem.mask = TCIF_IMAGE; tcItem.mask = TCIF_IMAGE;
@@ -277,7 +277,7 @@ void wxNotebook::SetImageList(wxImageList* imageList)
// remove one page from the notebook // remove one page from the notebook
bool wxNotebook::DeletePage(int nPage) bool wxNotebook::DeletePage(int nPage)
{ {
wxCHECK( IS_VALID_PAGE(nPage), FALSE ); wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, "notebook page out of range" );
TabCtrl_DeleteItem(m_hwnd, nPage); TabCtrl_DeleteItem(m_hwnd, nPage);

View File

@@ -125,24 +125,22 @@ void wxStaticBox::SetSize(int x, int y, int width, int height, int sizeFlags)
GetSize(&w1, &h1); GetSize(&w1, &h1);
} }
char buf[300];
int current_width; int current_width;
int cx; int cx;
int cy; int cy;
int cyf; int cyf;
HWND button = (HWND)m_hWnd;
wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); wxGetCharSize(GetHWND(), &cx, &cy,GetFont());
GetWindowText(button, buf, 300); GetTextExtent(wxGetWindowText(m_hWnd), &current_width, &cyf,
GetTextExtent(buf, &current_width, &cyf,NULL,NULL,GetFont()); NULL,NULL,GetFont());
if (w1 < 0) if ( w1 < 0 )
w1 = (int)(current_width + 3*cx) ; w1 = current_width + 3*cx;
if (h1<0) if ( h1 < 0 )
h1 = (int)(cyf*EDIT_CONTROL_FACTOR) ; h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf);
MoveWindow(button, x1, y1, w1, h1, TRUE);
MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE);
} }
WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,

View File

@@ -321,7 +321,7 @@ void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags)
wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); wxGetCharSize(GetHWND(), &cx, &cy,GetFont());
float control_width, control_height, control_x, control_y; int control_width, control_height, control_x, control_y;
// If we're prepared to use the existing size, then... // If we're prepared to use the existing size, then...
if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
@@ -333,17 +333,17 @@ void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags)
if (w1<=0) if (w1<=0)
w1 = DEFAULT_ITEM_WIDTH; w1 = DEFAULT_ITEM_WIDTH;
control_x = (float)x1; control_x = x1;
control_y = (float)y1; control_y = y1;
control_width = (float)w1; control_width = w1;
control_height = (float)h1; control_height = h1;
// Calculations may have made text size too small // Calculations may have made text size too small
if (control_height <= 0) if (control_height <= 0)
control_height = (float)(int)(cy*EDIT_CONTROL_FACTOR) ; control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
if (control_width <= 0) if (control_width <= 0)
control_width = (float)DEFAULT_ITEM_WIDTH; control_width = DEFAULT_ITEM_WIDTH;
MoveWindow((HWND) GetHWND(), (int)control_x, (int)control_y, MoveWindow((HWND) GetHWND(), (int)control_x, (int)control_y,
(int)control_width, (int)control_height, TRUE); (int)control_width, (int)control_height, TRUE);

View File

@@ -731,6 +731,16 @@ bool wxDirExists(const wxString& dir)
#endif #endif
} }
wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
{
wxString str;
int len = GetWindowTextLength((HWND)hWnd) + 1;
GetWindowText((HWND)hWnd, str.GetWriteBuf(len), len);
str.UngetWriteBuf();
return str;
}
#if 0 #if 0
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// wild character routines // wild character routines