comparison win/dw.c @ 612:c5e5671dec8f

Modify Calendar widget Amke Mac port actually compile and run Add Clipboard support for GTK and Win Add *from_data() contructors allowing icons, bitmaps to be created from embedded data.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 23 Mar 2008 04:54:30 +0000
parents bc800fc67343
children 0ab21b3b1d52
comparison
equal deleted inserted replaced
611:bc800fc67343 612:c5e5671dec8f
61 #define THREAD_LIMIT 128 61 #define THREAD_LIMIT 128
62 COLORREF _foreground[THREAD_LIMIT]; 62 COLORREF _foreground[THREAD_LIMIT];
63 COLORREF _background[THREAD_LIMIT]; 63 COLORREF _background[THREAD_LIMIT];
64 HPEN _hPen[THREAD_LIMIT]; 64 HPEN _hPen[THREAD_LIMIT];
65 HBRUSH _hBrush[THREAD_LIMIT]; 65 HBRUSH _hBrush[THREAD_LIMIT];
66 char *_clipboard_contents[THREAD_LIMIT];
66 67
67 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, 68 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77,
68 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; 69 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 };
69 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, 70 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77,
70 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 }; 71 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 };
3333 { 3334 {
3334 _foreground[z] = RGB(128,128,128); 3335 _foreground[z] = RGB(128,128,128);
3335 _background[z] = DW_RGB_TRANSPARENT; 3336 _background[z] = DW_RGB_TRANSPARENT;
3336 _hPen[z] = CreatePen(PS_SOLID, 1, _foreground[z]); 3337 _hPen[z] = CreatePen(PS_SOLID, 1, _foreground[z]);
3337 _hBrush[z] = CreateSolidBrush(_foreground[z]); 3338 _hBrush[z] = CreateSolidBrush(_foreground[z]);
3339 _clipboard_contents[z] = NULL;
3338 } 3340 }
3339 3341
3340 if(!IS_WINNTOR95) 3342 if(!IS_WINNTOR95)
3341 { 3343 {
3342 /* Get function pointers for the Win2k/98 menu functions */ 3344 /* Get function pointers for the Win2k/98 menu functions */
4664 * Parameters: 4666 * Parameters:
4665 * text: Bubble help text to be displayed. 4667 * text: Bubble help text to be displayed.
4666 * id: An ID to be used with dw_window_from_id() or 0L. 4668 * id: An ID to be used with dw_window_from_id() or 0L.
4667 * filename: Name of the file, omit extention to have 4669 * filename: Name of the file, omit extention to have
4668 * DW pick the appropriate file extension. 4670 * DW pick the appropriate file extension.
4669 * (BMP on OS/2 or Windows, XPM on Unix) 4671 * (BMP or ICO on OS/2 or Windows, XPM on Unix)
4670 */ 4672 */
4671 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename) 4673 HWND API dw_bitmapbutton_new_from_file(char *text, unsigned long id, char *filename)
4672 { 4674 {
4673 HWND tmp; 4675 HWND tmp;
4674 BubbleButton *bubble; 4676 BubbleButton *bubble;
4675 HBITMAP hbitmap = 0; 4677 HBITMAP hbitmap = 0;
4676 HANDLE icon = 0; 4678 HANDLE icon = 0;
4677 int windowtype = 0, len; 4679 int windowtype = 0, len;
4678 4680
4679 if(!(bubble = calloc(1, sizeof(BubbleButton)))) 4681 if(!(bubble = calloc(1, sizeof(BubbleButton))))
4680 return 0; 4682 return 0;
4681 4683
4682 windowtype = _dw_get_image_handle(filename, &icon, &hbitmap); 4684 windowtype = _dw_get_image_handle(filename, &icon, &hbitmap);
4683 4685
4684 tmp = CreateWindow(BUTTONCLASSNAME, 4686 tmp = CreateWindow(BUTTONCLASSNAME,
4685 "", 4687 "",
4686 WS_CHILD | BS_PUSHBUTTON | 4688 WS_CHILD | BS_PUSHBUTTON |
4687 windowtype | WS_CLIPCHILDREN | 4689 windowtype | WS_CLIPCHILDREN |
4688 WS_VISIBLE, 4690 WS_VISIBLE,
4689 0,0,2000,1000, 4691 0,0,2000,1000,
4690 DW_HWND_OBJECT, 4692 DW_HWND_OBJECT,
4691 (HMENU)id, 4693 (HMENU)id,
4692 DWInstance, 4694 DWInstance,
4693 NULL); 4695 NULL);
4694 4696
4695 bubble->id = id; 4697 bubble->id = id;
4696 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1); 4698 strncpy(bubble->bubbletext, text, BUBBLE_HELP_MAX - 1);
4697 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0'; 4699 bubble->bubbletext[BUBBLE_HELP_MAX - 1] = '\0';
4698 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc); 4700 bubble->pOldProc = (WNDPROC)SubclassWindow(tmp, _BtProc);
4699 4701
4700 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble); 4702 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)bubble);
4701 4703
4702 if(icon) 4704 if(icon)
4703 { 4705 {
4704 SendMessage(tmp, BM_SETIMAGE, 4706 SendMessage(tmp, BM_SETIMAGE,
4705 (WPARAM) IMAGE_ICON, 4707 (WPARAM) IMAGE_ICON,
4706 (LPARAM) icon); 4708 (LPARAM) icon);
4707 } 4709 }
4708 else if(hbitmap) 4710 else if(hbitmap)
4709 { 4711 {
4710 SendMessage(tmp, BM_SETIMAGE, 4712 SendMessage(tmp, BM_SETIMAGE,
4711 (WPARAM) IMAGE_BITMAP, 4713 (WPARAM) IMAGE_BITMAP,
4712 (LPARAM) hbitmap); 4714 (LPARAM) hbitmap);
4713 } 4715 }
4714 return tmp; 4716 return tmp;
4715 } 4717 }
4716 4718
4717 /* 4719 /*
4718 * Create a new spinbutton window (widget) to be packed. 4720 * Create a new spinbutton window (widget) to be packed.
4719 * Parameters: 4721 * Parameters:
8346 * handle: The handle to the calendar returned by dw_calendar_new(). 8348 * handle: The handle to the calendar returned by dw_calendar_new().
8347 * year: The year to set the date to 8349 * year: The year to set the date to
8348 * month: The month to set the date to 8350 * month: The month to set the date to
8349 * day: The day to set the date to 8351 * day: The day to set the date to
8350 */ 8352 */
8351 void API dw_calendar_set_date(HWND handle, int year, int month, int day) 8353 void API dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day)
8352 { 8354 {
8353 MONTHDAYSTATE mds[3]; 8355 MONTHDAYSTATE mds[3];
8354 SYSTEMTIME date; 8356 SYSTEMTIME date;
8355 date.wYear = year; 8357 date.wYear = year;
8356 date.wMonth = month; 8358 date.wMonth = month;
8371 * handle: The handle to the calendar returned by dw_calendar_new(). 8373 * handle: The handle to the calendar returned by dw_calendar_new().
8372 * year: Pointer to the year to get the date to 8374 * year: Pointer to the year to get the date to
8373 * month: Pointer to the month to get the date to 8375 * month: Pointer to the month to get the date to
8374 * day: Pointer to the day to get the date to 8376 * day: Pointer to the day to get the date to
8375 */ 8377 */
8376 void API dw_calendar_get_date(HWND handle, int *year, int *month, int *day) 8378 void API dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day)
8377 { 8379 {
8378 SYSTEMTIME date; 8380 SYSTEMTIME date;
8379 if ( MonthCal_GetCurSel( handle, &date ) ) 8381 if ( MonthCal_GetCurSel( handle, &date ) )
8380 { 8382 {
8381 *year = date.wYear; 8383 *year = date.wYear;
8514 { 8516 {
8515 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA); 8517 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(window, GWLP_USERDATA);
8516 8518
8517 if(cinfo) 8519 if(cinfo)
8518 cinfo->clickdefault = next; 8520 cinfo->clickdefault = next;
8521 }
8522
8523 /*
8524 * Gets the contents of the default clipboard as text.
8525 * Parameters:
8526 * None.
8527 * Returns:
8528 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
8529 * be converted to text.
8530 */
8531 char *dw_clipboard_get_text()
8532 {
8533 HANDLE handle;
8534 int threadid = dw_thread_id();
8535 long len;
8536
8537 if ( !OpenClipboard( NULL ) )
8538 return NULL;
8539
8540 if ( ( handle = GetClipboardData( CF_TEXT) ) == NULL )
8541 {
8542 CloseClipboard();
8543 return NULL;
8544 }
8545
8546 len = strlen( (char *)handle );
8547
8548 if ( threadid < 0 || threadid >= THREAD_LIMIT )
8549 threadid = 0;
8550
8551 if ( _clipboard_contents[threadid] != NULL )
8552 {
8553 GlobalFree( _clipboard_contents[threadid] );
8554 }
8555 _clipboard_contents[threadid] = (char *)GlobalAlloc(GMEM_FIXED, len + 1);
8556 if ( !_clipboard_contents[threadid] )
8557 {
8558 CloseClipboard();
8559 return NULL;
8560 }
8561
8562 strcpy( (char *)_clipboard_contents[threadid], (char *)handle );
8563 CloseClipboard();
8564
8565 return _clipboard_contents[threadid];
8566 }
8567
8568 /*
8569 * Sets the contents of the default clipboard to the supplied text.
8570 * Parameters:
8571 * Text.
8572 */
8573 void dw_clipboard_set_text( char *str, int len )
8574 {
8575 HGLOBAL ptr1;
8576 LPTSTR ptr2;
8577
8578 if ( !OpenClipboard( NULL ) )
8579 return;
8580
8581 ptr1 = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (len + 1) * sizeof(TCHAR) );
8582
8583 if ( !ptr1 )
8584 return;
8585
8586 ptr2 = GlobalLock( ptr1 );
8587
8588 memcpy( (char *)ptr2, str, len + 1);
8589 GlobalUnlock( ptr1 );
8590 EmptyClipboard();
8591
8592 if ( !SetClipboardData( CF_TEXT, ptr1 ) )
8593 {
8594 GlobalFree( ptr1 );
8595 return;
8596 }
8597
8598 CloseClipboard();
8599 GlobalFree( ptr1 );
8600
8601 return;
8519 } 8602 }
8520 8603
8521 /* 8604 /*
8522 * Returns some information about the current operating environment. 8605 * Returns some information about the current operating environment.
8523 * Parameters: 8606 * Parameters: