From 1c4a764c984ba8e482e5d808fd1c762aeb5b535a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Sep 1998 21:13:46 +0000 Subject: [PATCH] 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 --- include/wx/msw/private.h | 8 ++++++-- src/common/fileconf.cpp | 44 +++++++++++----------------------------- src/common/gdicmn.cpp | 11 +++++++++- src/common/log.cpp | 33 ++++++++++++++++++++++-------- src/msw/button.cpp | 4 ++-- src/msw/choice.cpp | 30 +++++++++++++++------------ src/msw/combobox.cpp | 17 ++++++++-------- src/msw/notebook.cpp | 12 +++++------ src/msw/statbox.cpp | 18 ++++++++-------- src/msw/textctrl.cpp | 14 ++++++------- src/msw/utils.cpp | 10 +++++++++ 11 files changed, 111 insertions(+), 90 deletions(-) diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index c764c5641f..3f7506841b 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -126,8 +126,9 @@ VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ; #define MEANING_CHARACTER '0' #define DEFAULT_ITEM_WIDTH 200 #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 // EDIT control VK_RETURN messages @@ -147,6 +148,9 @@ WXDLLEXPORT_DATA(extern HINSTANCE) wxhInstance; wxWindow* WXDLLEXPORT wxFindControlFromHandle(WXHWND hWnd); 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) #define WS_EX_CLIENTEDGE 0 #endif diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 6a9568e3b5..a925bbae8e 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -54,6 +54,13 @@ // ---------------------------------------------------------------------------- #define CONST_CAST ((wxFileConfig *)this)-> +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- +#ifndef MAX_PATH + #define MAX_PATH 512 +#endif + // ---------------------------------------------------------------------------- // global functions declarations // ---------------------------------------------------------------------------- @@ -87,15 +94,10 @@ wxString wxFileConfig::GetGlobalDir() #ifdef __UNIX__ strDir = "/etc/"; #elif defined(__WXSTUBS__) - // TODO - wxASSERT( TRUE ) ; + wxASSERT_MSG( FALSE, "TODO" ) ; #else // Windows - #ifndef _MAX_PATH - #define _MAX_PATH 512 - #endif - - char szWinDir[_MAX_PATH]; - ::GetWindowsDirectory(szWinDir, _MAX_PATH); + char szWinDir[MAX_PATH]; + ::GetWindowsDirectory(szWinDir, MAX_PATH); strDir = szWinDir; strDir << '\\'; @@ -107,30 +109,8 @@ wxString wxFileConfig::GetGlobalDir() wxString wxFileConfig::GetLocalDir() { wxString strDir; - - #ifdef __UNIX__ - 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 + + wxGetHomeDir(&strDir); return strDir; } diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index 69cc0cac80..d97f067d22 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -256,7 +256,11 @@ void wxColourDatabase::Initialize () 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) return (wxColour *)node->Data(); @@ -290,6 +294,11 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour) #ifdef __WXMOTIF__ Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ; #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 */ if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour)) diff --git a/src/common/log.cpp b/src/common/log.cpp index 6a1848932c..66cc2c1d0c 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -268,8 +268,9 @@ wxLog *wxLog::GetActiveTarget() wxLog *wxLog::SetActiveTarget(wxLog *pLogger, bool bNoFlashOld) { // flush the old messages before changing - if ( (ms_pLogger != NULL) && !bNoFlashOld ) + if ( (ms_pLogger != NULL) && !bNoFlashOld ) { ms_pLogger->Flush(); + } wxLog *pOldLogger = ms_pLogger; ms_pLogger = pLogger; @@ -737,13 +738,29 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString) ((wxLogWindow *)m_pOldLog)->DoLog(level, szString); } - // don't put trace messages in the text window for 2 reasons: - // 1) there are too many of them - // 2) they may provoke other trace messages thus sending a program into an - // infinite loop - if ( m_pLogFrame && level != wxLOG_Trace ) { - // and this will format it nicely and call our DoLogString() - wxLog::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: + // 1) there are too many of them + // 2) they may provoke other trace messages thus sending a program + // into an infinite loop + case wxLOG_Trace: + break; + + default: + // and this will format it nicely and call our DoLogString() + wxLog::DoLog(level, szString); + } } m_bHasMessages = TRUE; diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 2d2d82f1ab..849eef8dbd 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -30,7 +30,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) #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 @@ -135,7 +135,7 @@ void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags) actualHeight = hh; 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); diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 61119e6b67..0a802bdab0 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -204,7 +204,7 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) int cy; wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); - float control_width, control_height; + int control_width, control_height; // Ignore height parameter because height doesn't // 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 if (m_noStrings == 0) - control_width = (float)100.0; + { + control_width = 100; + } else { int len, ht; - float longest = (float)0.0; + int longest = 0; int i; for (i = 0; i < m_noStrings; i++) { wxString str(GetString(i)); 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 (m_noStrings == 0) - h1 = (int)(EDIT_CONTROL_FACTOR*cy*10.0); - else h1 = (int)(EDIT_CONTROL_FACTOR*cy*(wxMin(10, m_noStrings) + 1)); + h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10; + else + h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1); } // If non-default width... 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 if (control_height <= 0) - control_height = (float)(int)(cy*EDIT_CONTROL_FACTOR) ; + control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); if (control_width <= 0) - control_width = (float)100.0; + control_width = 100; - MoveWindow((HWND) GetHWND(), x1, y1, - (int)control_width, (int)control_height, TRUE); + MoveWindow((HWND)GetHWND(), x1, y1, + control_width, control_height, TRUE); } WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index 1b795f43e6..8cc929e3bc 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -139,10 +139,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, return TRUE; } -wxString wxComboBox::GetValue(void) const +wxString wxComboBox::GetValue() const { - GetWindowText((HWND) GetHWND(), wxBuffer, 500); - return wxString(wxBuffer); + return wxGetWindowText(GetHWND()); } void wxComboBox::SetValue(const wxString& value) @@ -179,19 +178,19 @@ void wxComboBox::SetValue(const wxString& value) } // Clipboard operations -void wxComboBox::Copy(void) +void wxComboBox::Copy() { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, WM_COPY, 0, 0L); } -void wxComboBox::Cut(void) +void wxComboBox::Cut() { HWND hWnd = (HWND) GetHWND(); SendMessage(hWnd, WM_CUT, 0, 0L); } -void wxComboBox::Paste(void) +void wxComboBox::Paste() { HWND hWnd = (HWND) GetHWND(); 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(); @@ -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); @@ -236,7 +235,7 @@ long wxComboBox::GetInsertionPoint(void) const return 0; } -long wxComboBox::GetLastPosition(void) const +long wxComboBox::GetLastPosition() const { /* HWND hWnd = (HWND) GetHWND(); diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 6bded92b0f..c6df82a176 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -198,7 +198,7 @@ int wxNotebook::GetRowCount() const 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); @@ -217,7 +217,7 @@ void wxNotebook::AdvanceSelection(bool bForward) 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; tcItem.mask = TCIF_TEXT; @@ -228,7 +228,7 @@ bool wxNotebook::SetPageText(int nPage, const wxString& strText) 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]; TC_ITEM tcItem; @@ -245,7 +245,7 @@ wxString wxNotebook::GetPageText(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; tcItem.mask = TCIF_IMAGE; @@ -255,7 +255,7 @@ int wxNotebook::GetPageImage(int nPage) const 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; tcItem.mask = TCIF_IMAGE; @@ -277,7 +277,7 @@ void wxNotebook::SetImageList(wxImageList* imageList) // remove one page from the notebook 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); diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 15bbd1c5f7..3287dbf204 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -125,24 +125,22 @@ void wxStaticBox::SetSize(int x, int y, int width, int height, int sizeFlags) GetSize(&w1, &h1); } - char buf[300]; - int current_width; int cx; int cy; int cyf; - HWND button = (HWND)m_hWnd; wxGetCharSize(GetHWND(), &cx, &cy,GetFont()); - GetWindowText(button, buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL,GetFont()); - if (w1 < 0) - w1 = (int)(current_width + 3*cx) ; - if (h1<0) - h1 = (int)(cyf*EDIT_CONTROL_FACTOR) ; - MoveWindow(button, x1, y1, w1, h1, TRUE); + GetTextExtent(wxGetWindowText(m_hWnd), ¤t_width, &cyf, + NULL,NULL,GetFont()); + if ( w1 < 0 ) + w1 = current_width + 3*cx; + if ( h1 < 0 ) + h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf); + + MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE); } WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 3def23203d..b764620b40 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -321,7 +321,7 @@ void wxTextCtrl::SetSize(int x, int y, int width, int height, int sizeFlags) 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 (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) w1 = DEFAULT_ITEM_WIDTH; - control_x = (float)x1; - control_y = (float)y1; - control_width = (float)w1; - control_height = (float)h1; + control_x = x1; + control_y = y1; + control_width = w1; + control_height = h1; // Calculations may have made text size too small if (control_height <= 0) - control_height = (float)(int)(cy*EDIT_CONTROL_FACTOR) ; + control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); if (control_width <= 0) - control_width = (float)DEFAULT_ITEM_WIDTH; + control_width = DEFAULT_ITEM_WIDTH; MoveWindow((HWND) GetHWND(), (int)control_x, (int)control_y, (int)control_width, (int)control_height, TRUE); diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 9cb654cd38..d495c7f480 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -731,6 +731,16 @@ bool wxDirExists(const wxString& dir) #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 //------------------------------------------------------------------------ // wild character routines -- 2.47.2