comparison win/dw.c @ 1411:22ba64e357de

Initial versions of code to figure out control sizes for Windows and OS/2... and some fixes for the Mac version.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 02 Dec 2011 08:22:11 +0000
parents 93eb987c05cf
children ddf9cfb4a074
comparison
equal deleted inserted replaced
1410:c607fd86e5c2 1411:22ba64e357de
4291 { 4291 {
4292 DeleteObject(oldfont); 4292 DeleteObject(oldfont);
4293 } 4293 }
4294 } 4294 }
4295 4295
4296 /* Internal function to return a pointer to an item struct
4297 * with information about the packing information regarding object.
4298 */
4299 Item *_box_item(HWND handle)
4300 {
4301 HWND parent = GetParent(handle);
4302 Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
4303
4304 /* If it is a desktop window let WM_DESTROY handle it */
4305 if(parent != HWND_DESKTOP)
4306 {
4307 if(thisbox && thisbox->count)
4308 {
4309 int z;
4310 Item *thisitem = thisbox->items;
4311
4312 for(z=0;z<thisbox->count;z++)
4313 {
4314 if(thisitem[z].hwnd == handle)
4315 return &thisitem[z];
4316 }
4317 }
4318 }
4319 return NULL;
4320 }
4321
4322 /* Internal function to calculate the widget's required size..
4323 * These are the general rules for widget sizes:
4324 *
4325 * Scrolled(Container,Tree,MLE)/Render/Unspecified: 1x1
4326 * Entryfield/Combobox/Spinbutton: 150x(maxfontheight)
4327 * Spinbutton: 50x(maxfontheight)
4328 * Text/Status: (textwidth)x(textheight)
4329 */
4330 void _control_size(HWND handle, int *width, int *height)
4331 {
4332 int thiswidth = 1, thisheight = 1, extrawidth = 0, extraheight = 0;
4333 char tmpbuf[100], *buf = dw_window_get_text(handle);
4334 static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
4335
4336 GetClassName(handle, tmpbuf, 99);
4337
4338 /* If we have a string...
4339 * calculate the size with the current font.
4340 */
4341 if(buf)
4342 {
4343 if(*buf)
4344 dw_font_text_extents_get(handle, NULL, buf, &thiswidth, &thisheight);
4345 dw_free(buf);
4346 }
4347
4348 /* Combobox */
4349 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1) == 0)
4350 {
4351 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4352 thiswidth = 150;
4353 extraheight = 4;
4354 if(thisheight < 18)
4355 thisheight = 18;
4356 }
4357 else if(strnicmp(tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0)
4358 {
4359 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4360 thiswidth = 50;
4361 }
4362 else if(strnicmp(tmpbuf, EDITCLASSNAME, strlen(EDITCLASSNAME)+1) == 0 &&
4363 !(GetWindowLong(handle, GWL_STYLE) & ES_MULTILINE))
4364 {
4365 dw_font_text_extents_get(handle, NULL, testtext, NULL, &thisheight);
4366 thiswidth = 150;
4367 extraheight = 6;
4368 }
4369 else if(strnicmp(tmpbuf, BUTTONCLASSNAME, strlen(BUTTONCLASSNAME)+1) == 0)
4370 {
4371 ULONG style = GetWindowLong(handle, GWL_STYLE);
4372
4373 if(style & BS_AUTOCHECKBOX || style & BS_AUTORADIOBUTTON)
4374 {
4375 extrawidth = 24;
4376 extraheight = 4;
4377 }
4378 else
4379 {
4380 extrawidth = 8;
4381 extraheight = 4;
4382 }
4383 }
4384
4385 /* Set the requested sizes */
4386 if(width)
4387 *width = thiswidth + extrawidth;
4388 if(height)
4389 *height = thisheight + extraheight;
4390 }
4391
4296 /* 4392 /*
4297 * Sets the font used by a specified window (widget) handle. 4393 * Sets the font used by a specified window (widget) handle.
4298 * Parameters: 4394 * Parameters:
4299 * handle: The window (widget) handle. 4395 * handle: The window (widget) handle.
4300 * fontname: Name and size of the font in the form "size.fontname" 4396 * fontname: Name and size of the font in the form "size.fontname"
4320 4416
4321 /* This needs to be after we get the correct handle */ 4417 /* This needs to be after we get the correct handle */
4322 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); 4418 oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
4323 hfont = _acquire_font(handle, fontname); 4419 hfont = _acquire_font(handle, fontname);
4324 4420
4325 if (fontname) 4421 if(hfont && fontname)
4326 { 4422 {
4327 if(cinfo) 4423 if(cinfo)
4328 { 4424 {
4329 strcpy(cinfo->fontname, fontname); 4425 strcpy(cinfo->fontname, fontname);
4330 if(!oldfont) 4426 if(!oldfont)
4340 4436
4341 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc); 4437 cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
4342 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo); 4438 SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
4343 } 4439 }
4344 } 4440 }
4345 SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE); 4441 /* If we changed the font... */
4346 if(oldfont) 4442 if(hfont)
4347 DeleteObject(oldfont); 4443 {
4348 return 0; 4444 Item *item = _box_item(handle);
4445
4446 SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE);
4447 if(oldfont)
4448 DeleteObject(oldfont);
4449
4450 /* Check to see if any of the sizes need to be recalculated */
4451 if(item && (item->origwidth == -1 || item->origheight == -1))
4452 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
4453 return DW_ERROR_NONE;
4454 }
4455 return DW_ERROR_UNKNOWN;
4349 } 4456 }
4350 4457
4351 /* Allows the user to choose a font using the system's font chooser dialog. 4458 /* Allows the user to choose a font using the system's font chooser dialog.
4352 * Parameters: 4459 * Parameters:
4353 * currfont: current font 4460 * currfont: current font
6203 /* groupbox */ 6310 /* groupbox */
6204 thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA ); 6311 thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA );
6205 if ( thisbox && thisbox->grouphwnd != (HWND)NULL ) 6312 if ( thisbox && thisbox->grouphwnd != (HWND)NULL )
6206 SetWindowText( thisbox->grouphwnd, text ); 6313 SetWindowText( thisbox->grouphwnd, text );
6207 } 6314 }
6315 /* If we changed the text... */
6316 {
6317 Item *item = _box_item(handle);
6318
6319 /* Check to see if any of the sizes need to be recalculated */
6320 if(item && (item->origwidth == -1 || item->origheight == -1))
6321 _control_size(handle, item->origwidth == -1 ? &item->width : NULL, item->origheight == -1 ? &item->height : NULL);
6322 }
6208 } 6323 }
6209 6324
6210 /* 6325 /*
6211 * Sets the text used for a given window's floating bubble help. 6326 * Sets the text used for a given window's floating bubble help.
6212 * Parameters: 6327 * Parameters:
6405 6520
6406 tmpitem[index].hwnd = item; 6521 tmpitem[index].hwnd = item;
6407 tmpitem[index].origwidth = tmpitem[index].width = width; 6522 tmpitem[index].origwidth = tmpitem[index].width = width;
6408 tmpitem[index].origheight = tmpitem[index].height = height; 6523 tmpitem[index].origheight = tmpitem[index].height = height;
6409 tmpitem[index].pad = pad; 6524 tmpitem[index].pad = pad;
6410 if(hsize) 6525 tmpitem[index].hsize = hsize ? SIZEEXPAND : SIZESTATIC;
6411 tmpitem[index].hsize = SIZEEXPAND; 6526 tmpitem[index].vsize = vsize ? SIZEEXPAND : SIZESTATIC;
6412 else 6527
6413 tmpitem[index].hsize = SIZESTATIC; 6528 /* If either of the parameters are -1 ... calculate the size */
6414 6529 if(width == -1 || height == -1)
6415 if(vsize) 6530 _control_size(item, width == -1 ? &tmpitem[index].width : NULL, height == -1 ? &tmpitem[index].height : NULL);
6416 tmpitem[index].vsize = SIZEEXPAND;
6417 else
6418 tmpitem[index].vsize = SIZESTATIC;
6419 6531
6420 thisbox->items = tmpitem; 6532 thisbox->items = tmpitem;
6421 6533
6422 if(thisbox->count) 6534 if(thisbox->count)
6423 free(thisitem); 6535 free(thisitem);