comparison os2/dw.c @ 995:65ccdda2d743

Fixes to MLE handling to make it work like the other platforms. Carriage returns are now stripped and the MLE is in no translate mode so the insertion point is the same as the returned buffer.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 07 May 2011 19:49:24 +0000
parents 3d898b78c2ad
children 69cf9f26e899
comparison
equal deleted inserted replaced
994:f1c7b03f944d 995:65ccdda2d743
4879 0,0,2000,1000, 4879 0,0,2000,1000,
4880 NULLHANDLE, 4880 NULLHANDLE,
4881 HWND_TOP, 4881 HWND_TOP,
4882 id, 4882 id,
4883 NULL, 4883 NULL,
4884 NULL); 4884 NULL);
4885 WinSendMsg(tmp, MLM_FORMAT, MLFIE_NOTRANS, 0);
4885 blah->oldproc = WinSubclassWindow(tmp, _mleproc); 4886 blah->oldproc = WinSubclassWindow(tmp, _mleproc);
4886 WinSetWindowPtr(tmp, QWP_USER, blah); 4887 WinSetWindowPtr(tmp, QWP_USER, blah);
4887 dw_window_set_font(tmp, DefaultFont); 4888 dw_window_set_font(tmp, DefaultFont);
4888 return tmp; 4889 return tmp;
4889 } 4890 }
6346 void API dw_listbox_delete(HWND handle, int index) 6347 void API dw_listbox_delete(HWND handle, int index)
6347 { 6348 {
6348 WinSendMsg(handle, LM_DELETEITEM, MPFROMSHORT(index), 0); 6349 WinSendMsg(handle, LM_DELETEITEM, MPFROMSHORT(index), 0);
6349 } 6350 }
6350 6351
6352 void _strip_cr(char *dest, char *src)
6353 {
6354 int z, x = 0;
6355
6356 for(z=0;z<strlen(src);z++)
6357 {
6358 if(src[z] != '\r')
6359 {
6360 dest[x] = src[z];
6361 x++;
6362 }
6363 }
6364 dest[x] = 0;
6365 }
6366
6351 /* 6367 /*
6352 * Adds text to an MLE box and returns the current point. 6368 * Adds text to an MLE box and returns the current point.
6353 * Parameters: 6369 * Parameters:
6354 * handle: Handle to the MLE to be queried. 6370 * handle: Handle to the MLE to be queried.
6355 * buffer: Text buffer to be imported. 6371 * buffer: Text buffer to be imported.
6365 { 6381 {
6366 int amount, len = strlen(buffer), written = 0; 6382 int amount, len = strlen(buffer), written = 0;
6367 6383
6368 while(written < len) 6384 while(written < len)
6369 { 6385 {
6386 int z, x = 0;
6387 char buf[1024];
6388
6370 if((len - written) > 65535) 6389 if((len - written) > 65535)
6371 amount = 65535; 6390 amount = 65535;
6372 else 6391 else
6373 amount = len - written; 6392 amount = len - written;
6374 6393
6375 memcpy(mlebuf, &buffer[written], amount); 6394 /* Remove Carriage Returns \r */
6376 mlebuf[amount] = '\0'; 6395 for(z=0;z<amount;z++)
6377 6396 {
6378 WinSendMsg(handle, MLM_SETIMPORTEXPORT, MPFROMP(mlebuf), MPFROMLONG(amount + 1)); 6397 if(buffer[z] != '\r')
6379 WinSendMsg(handle, MLM_IMPORT, MPFROMP(&point), MPFROMLONG(amount + 1)); 6398 {
6380 dw_mle_delete(handle, point, 1); 6399 mlebuf[x] = buffer[z];
6400 x++;
6401 }
6402 }
6403
6404 if(point < 0)
6405 point = 0;
6406 WinSendMsg(handle, MLM_SETIMPORTEXPORT, MPFROMP(mlebuf), MPFROMLONG(x));
6407 WinSendMsg(handle, MLM_IMPORT, MPFROMP(&point), MPFROMLONG(x));
6381 6408
6382 written += amount; 6409 written += amount;
6383 } 6410 }
6384 DosFreeMem(mlebuf); 6411 DosFreeMem(mlebuf);
6385 } 6412 }
6386 return point - 1; 6413 return point;
6387 } 6414 }
6388 6415
6389 /* 6416 /*
6390 * Grabs text from an MLE box. 6417 * Grabs text from an MLE box.
6391 * Parameters: 6418 * Parameters:
6394 * startpoint: Point to start grabbing text. 6421 * startpoint: Point to start grabbing text.
6395 * length: Amount of text to be grabbed. 6422 * length: Amount of text to be grabbed.
6396 */ 6423 */
6397 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) 6424 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
6398 { 6425 {
6399 PBYTE mlebuf; 6426 PBYTE mlebuf;
6400 6427
6401 /* Work around 64K limit */ 6428 /* Work around 64K limit */
6402 if(!DosAllocMem((PPVOID) &mlebuf, 65535, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE)) 6429 if(!DosAllocMem((PPVOID) &mlebuf, 65535, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE))
6403 { 6430 {
6404 int amount, copied, written = 0; 6431 int amount, copied, written = 0;
6448 * startpoint: Point to start deleting text. 6475 * startpoint: Point to start deleting text.
6449 * length: Amount of text to be deleted. 6476 * length: Amount of text to be deleted.
6450 */ 6477 */
6451 void API dw_mle_delete(HWND handle, int startpoint, int length) 6478 void API dw_mle_delete(HWND handle, int startpoint, int length)
6452 { 6479 {
6453 char *buf = malloc(length+1); 6480 WinSendMsg(handle, MLM_DELETE, MPFROMLONG(startpoint), MPFROMLONG(length));
6454 int z, dellen = length;
6455
6456 dw_mle_export(handle, buf, startpoint, length);
6457
6458 for(z=0;z<length-1;z++)
6459 {
6460 if(strncmp(&buf[z], "\r\n", 2) == 0)
6461 dellen--;
6462 }
6463 WinSendMsg(handle, MLM_DELETE, MPFROMLONG(startpoint), MPFROMLONG(dellen));
6464 free(buf);
6465 } 6481 }
6466 6482
6467 /* 6483 /*
6468 * Clears all text from an MLE box. 6484 * Clears all text from an MLE box.
6469 * Parameters: 6485 * Parameters:
6518 * handle: Handle to the MLE to be positioned. 6534 * handle: Handle to the MLE to be positioned.
6519 * point: Point to position cursor. 6535 * point: Point to position cursor.
6520 */ 6536 */
6521 void API dw_mle_set_cursor(HWND handle, int point) 6537 void API dw_mle_set_cursor(HWND handle, int point)
6522 { 6538 {
6539 point--;
6523 WinSendMsg(handle, MLM_SETSEL, MPFROMLONG(point), MPFROMLONG(point)); 6540 WinSendMsg(handle, MLM_SETSEL, MPFROMLONG(point), MPFROMLONG(point));
6524 } 6541 }
6525 6542
6526 /* 6543 /*
6527 * Finds text in an MLE box. 6544 * Finds text in an MLE box.