]> git.saurik.com Git - wxWidgets.git/commitdiff
1) minor modifications in fileconf.cpp
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Sep 1998 21:13:46 +0000 (21:13 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Sep 1998 21:13:46 +0000 (21:13 +0000)
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
src/common/fileconf.cpp
src/common/gdicmn.cpp
src/common/log.cpp
src/msw/button.cpp
src/msw/choice.cpp
src/msw/combobox.cpp
src/msw/notebook.cpp
src/msw/statbox.cpp
src/msw/textctrl.cpp
src/msw/utils.cpp

index c764c5641fb981b29cd6d53115b7a5f784a30522..3f7506841bae727e0b102fad9e15e50964b110c6 100644 (file)
@@ -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
index 6a9568e3b5b8624159b22a41aef34d973466fc80..a925bbae8ea4e34af9644531fa7bd503eeec57c9 100644 (file)
 // ----------------------------------------------------------------------------
 #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;
 }
index 69cc0cac80b0f57abe5508fcc94ba7c5ed5d9752..d97f067d226425b4efc09eb88d2e9205173a2b98 100644 (file)
@@ -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))
index 6a1848932c0e2dbe112e6de3f64919f4fcaa4810..66cc2c1d0cded282fcb0060d07684c18afcdbae9 100644 (file)
@@ -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;
index 2d2d82f1abf886d7f46416df93b8eacae1f5856b..849eef8dbd92429553446406c131b46d65b32dce 100644 (file)
@@ -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);
index 61119e6b67b43a9e8f3388d82ec3045e7418be12..0a802bdab08dea50d395bf5eb9a918b8e4c95121 100644 (file)
@@ -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,
index 1b795f43e63d339419ba78a62264a0b0b2a326aa..8cc929e3bcbfa148cbf8cf5e58040d34d7f320cf 100644 (file)
@@ -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();
index 6bded92b0f71bfd69dbd80199fb6757d3849e527..c6df82a1765027179e445361fde911d96f6251a9 100644 (file)
@@ -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);
 
index 15bbd1c5f787d36a8a180d3c0a1873c0d85420b6..3287dbf2049dcdbf43272da07849b69adb58ae9c 100644 (file)
@@ -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, &current_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), &current_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,
index 3def23203d57672f8715cd4dc3ab2e5303d82180..b764620b40bf794b2b0373d4237af0812ea324d7 100644 (file)
@@ -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);
index 9cb654cd38098a1983759d698959ebc5cebe2b68..d495c7f4804826c9254266c3e97ec17ce4f8bf5e 100644 (file)
@@ -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