};
DWORD CALLBACK
-wxRichEditStreamOut(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb)
+wxRichEditStreamOut(DWORD_PTR dwCookie, BYTE *buf, LONG cb, LONG *pcb)
{
*pcb = 0;
#endif // Win32/16
}
+// ----------------------------------------------------------------------------
+// Working with files
+// ----------------------------------------------------------------------------
+
+bool wxTextCtrl::LoadFile(const wxString& file)
+{
+ if ( wxTextCtrlBase::LoadFile(file) )
+ {
+ // update the size limit if needed
+ AdjustSpaceLimit();
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
// ----------------------------------------------------------------------------
// Editing
// ----------------------------------------------------------------------------
Replace(from, to, wxEmptyString);
}
-bool wxTextCtrl::LoadFile(const wxString& file)
-{
- if ( wxTextCtrlBase::LoadFile(file) )
- {
- // update the size limit if needed
- AdjustSpaceLimit();
-
- return TRUE;
- }
-
- return FALSE;
-}
-
bool wxTextCtrl::IsModified() const
{
return SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0;
return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
}
+// ----------------------------------------------------------------------------
+// Positions <-> coords
+// ----------------------------------------------------------------------------
+
long wxTextCtrl::XYToPosition(long x, long y) const
{
// This gets the char index for the _beginning_ of this line
return TRUE;
}
+wxTextCtrlHitTestResult
+wxTextCtrl::HitTest(const wxPoint& pt, wxTextCoord *col, wxTextCoord *row) const
+{
+ // first get the position from Windows
+ LPARAM lParam;
+
+#if wxUSE_RICHEDIT
+ POINTL ptl;
+ if ( IsRich() )
+ {
+ // for rich edit controls the position is passed iva the struct fields
+ ptl.x = pt.x;
+ ptl.y = pt.y;
+ lParam = (LPARAM)&ptl;
+ }
+ else
+#endif // wxUSE_RICHEDIT
+ {
+ // for the plain ones, we are limited to 16 bit positions which are
+ // combined in a single 32 bit value
+ lParam = MAKELPARAM(pt.x, pt.y);
+ }
+
+ LRESULT pos = SendMessage(GetHwnd(), EM_CHARFROMPOS, 0, lParam);
+
+ if ( pos == -1 )
+ {
+ // this seems to indicate an error...
+ return wxTE_HT_UNKNOWN;
+ }
+
+#if wxUSE_RICHEDIT
+ if ( !IsRich() )
+#endif // wxUSE_RICHEDIT
+ {
+ // for plain EDIT controls the higher word contains something else
+ pos = LOWORD(pos);
+ }
+
+
+ // next determine where it is relatively to our point: EM_CHARFROMPOS
+ // always returns the closest character but we need to be more precise, so
+ // double check that we really are where it pretends
+ POINTL ptReal;
+
+#if wxUSE_RICHEDIT
+ // FIXME: we need to distinguish between richedit 2 and 3 here somehow but
+ // we don't know how to do it
+ if ( IsRich() )
+ {
+ SendMessage(GetHwnd(), EM_POSFROMCHAR, (WPARAM)&ptReal, pos);
+ }
+ else
+#endif // wxUSE_RICHEDIT
+ {
+ LRESULT lRc = SendMessage(GetHwnd(), EM_POSFROMCHAR, pos, 0);
+
+ if ( lRc == -1 )
+ {
+ // this is apparently returned when pos corresponds to the last
+ // position
+ ptReal.x =
+ ptReal.y = 0;
+ }
+ else
+ {
+ ptReal.x = LOWORD(lRc);
+ ptReal.y = HIWORD(lRc);
+ }
+ }
+
+ wxTextCtrlHitTestResult rc;
+
+ if ( pt.y > ptReal.y + GetCharHeight() )
+ rc = wxTE_HT_BELOW;
+ else if ( pt.x > ptReal.x + GetCharWidth() )
+ rc = wxTE_HT_BEYOND;
+ else
+ rc = wxTE_HT_ON_TEXT;
+
+ // finally translate to column/row
+ if ( !PositionToXY(pos, col, row) )
+ {
+ wxFAIL_MSG( _T("PositionToXY() not expected to fail in HitTest()") );
+ }
+
+ return rc;
+}
+
+// ----------------------------------------------------------------------------
+//
+// ----------------------------------------------------------------------------
+
void wxTextCtrl::ShowPosition(long pos)
{
HWND hWnd = GetHwnd();
switch ( event.GetKeyCode() )
{
case WXK_RETURN:
- if ( !(m_windowStyle & wxTE_MULTILINE) )
+ if ( !HasFlag(wxTE_MULTILINE) )
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
InitCommandEvent(event);
break;
case WXK_TAB:
- // always produce navigation event - even if we process TAB
+ // always produce navigation event -- even if we process TAB
// ourselves the fact that we got here means that the user code
- // decided to skip processing of this TAB - probably to let it
+ // decided to skip processing of this TAB -- probably to let it
// do its default job.
+
+ // ok, so this is getting absolutely ridiculous but I don't see
+ // any other way to fix this bug: when a multiline text control is
+ // inside a wxFrame, we need to generate the navigation event as
+ // otherwise nothing happens at all, but when the same control is
+ // created inside a dialog, IsDialogMessage() *does* switch focus
+ // all by itself and so if we do it here as well, it is advanced
+ // twice and goes to the next control... to prevent this from
+ // happening we're doing this ugly check, the logic being that if
+ // we don't have focus then it had been already changed to the next
+ // control
+ //
+ // the right thing to do would, of course, be to understand what
+ // the hell is IsDialogMessage() doing but this is beyond my feeble
+ // forces at the moment unfortunately
+ if ( FindFocus() == this )
{
wxNavigationKeyEvent eventNav;
eventNav.SetDirection(!event.ShiftDown());
int wText = DEFAULT_ITEM_WIDTH;
- int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
+ int hText = cy;
if ( m_windowStyle & wxTE_MULTILINE )
{
hText *= wxMax(GetNumberOfLines(), 5);
}
//else: for single line control everything is ok
+ // we have to add the adjustments for the control height only once, not
+ // once per line, so do it after multiplication above
+ hText += EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) - cy;
+
return wxSize(wText, hText);
}