Mercurial > dwindows
comparison win/dw.c @ 593:d3871f747160
Add calendar widget.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 25 Sep 2006 22:13:53 +0000 |
parents | bb439280ece2 |
children | e49524bc2f07 |
comparison
equal
deleted
inserted
replaced
592:840b43f3976b | 593:d3871f747160 |
---|---|
3237 WNDCLASS wc; | 3237 WNDCLASS wc; |
3238 int z; | 3238 int z; |
3239 INITCOMMONCONTROLSEX icc; | 3239 INITCOMMONCONTROLSEX icc; |
3240 | 3240 |
3241 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); | 3241 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); |
3242 icc.dwICC = ICC_WIN95_CLASSES; | 3242 icc.dwICC = ICC_WIN95_CLASSES|ICC_DATE_CLASSES; |
3243 | 3243 |
3244 InitCommonControlsEx(&icc); | 3244 InitCommonControlsEx(&icc); |
3245 | 3245 |
3246 memset(lookup, 0, sizeof(HICON) * ICON_INDEX_LIMIT); | 3246 memset(lookup, 0, sizeof(HICON) * ICON_INDEX_LIMIT); |
3247 | 3247 |
4151 } | 4151 } |
4152 | 4152 |
4153 /* | 4153 /* |
4154 * Adds a menuitem or submenu to an existing menu. | 4154 * Adds a menuitem or submenu to an existing menu. |
4155 * Parameters: | 4155 * Parameters: |
4156 * menu: The handle the the existing menu. | 4156 * menu: The handle to the existing menu. |
4157 * title: The title text on the menu item to be added. | 4157 * title: The title text on the menu item to be added. |
4158 * id: An ID to be used for message passing. | 4158 * id: An ID to be used for message passing. |
4159 * end: If TRUE memu is positioned at the end of the menu. | 4159 * end: If TRUE memu is positioned at the end of the menu. |
4160 * check: If TRUE menu is "check"able. | 4160 * check: If TRUE menu is "check"able. |
4161 * flags: Extended attributes to set on the menu. | 4161 * flags: Extended attributes to set on the menu. |
4225 } | 4225 } |
4226 | 4226 |
4227 /* | 4227 /* |
4228 * Sets the state of a menu item check. | 4228 * Sets the state of a menu item check. |
4229 * Parameters: | 4229 * Parameters: |
4230 * menu: The handle the the existing menu. | 4230 * menu: The handle to the existing menu. |
4231 * id: Menuitem id. | 4231 * id: Menuitem id. |
4232 * check: TRUE for checked FALSE for not checked. | 4232 * check: TRUE for checked FALSE for not checked. |
4233 */ | 4233 */ |
4234 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) | 4234 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) |
4235 { | 4235 { |
4245 mii.fState = MFS_CHECKED; | 4245 mii.fState = MFS_CHECKED; |
4246 else | 4246 else |
4247 mii.fState = MFS_UNCHECKED; | 4247 mii.fState = MFS_UNCHECKED; |
4248 SetMenuItemInfo(mymenu, id, FALSE, &mii); | 4248 SetMenuItemInfo(mymenu, id, FALSE, &mii); |
4249 } | 4249 } |
4250 | |
4251 #if 0 | |
4252 /* | |
4253 * TBD | |
4254 * Deletes the menu item specified | |
4255 * Parameters: | |
4256 * menu: The handle to the menu in which the item was appended. | |
4257 * id: Menuitem id. | |
4258 */ | |
4259 void API dw_menu_delete_item(HMENUI menux, unsigned long id) | |
4260 { | |
4261 HMENU mymenu = (HMENU)menux; | |
4262 | |
4263 if(IsWindow(menux) && !IsMenu(mymenu)) | |
4264 mymenu = (HMENU)dw_window_get_data(menux, "_dw_menu"); | |
4265 | |
4266 DeleteMenu(mymenu, id, MF_BYCOMMAND); | |
4267 DrawMenuBar(menux); | |
4268 } | |
4269 #endif | |
4250 | 4270 |
4251 /* | 4271 /* |
4252 * Pops up a context menu at given x and y coordinates. | 4272 * Pops up a context menu at given x and y coordinates. |
4253 * Parameters: | 4273 * Parameters: |
4254 * menu: The handle the the existing menu. | 4274 * menu: The handle the the existing menu. |
5103 if(hsize && !width) | 5123 if(hsize && !width) |
5104 width = 1; | 5124 width = 1; |
5105 | 5125 |
5106 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) | 5126 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) |
5107 tmpitem[thisbox->count].type = TYPEBOX; | 5127 tmpitem[thisbox->count].type = TYPEBOX; |
5128 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) | |
5129 { | |
5130 RECT rc; | |
5131 MonthCal_GetMinReqRect(item, &rc); | |
5132 width = 1 + rc.right - rc.left; | |
5133 height = 1 + rc.bottom - rc.top; | |
5134 tmpitem[thisbox->count].type = TYPEITEM; | |
5135 } | |
5108 else | 5136 else |
5109 { | 5137 { |
5110 if ( width == 0 && hsize == FALSE ) | 5138 if ( width == 0 && hsize == FALSE ) |
5111 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 5139 dw_messagebox("dw_box_pack_start()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
5112 if ( height == 0 && vsize == FALSE ) | 5140 if ( height == 0 && vsize == FALSE ) |
8271 return *percent; | 8299 return *percent; |
8272 return 0.0; | 8300 return 0.0; |
8273 } | 8301 } |
8274 | 8302 |
8275 /* | 8303 /* |
8304 * Creates a calendar window (widget) with given parameters. | |
8305 * Parameters: | |
8306 * type: Value can be DW_VERT or DW_HORZ. | |
8307 * topleft: Handle to the window to be top or left. | |
8308 * bottomright: Handle to the window to be bottom or right. | |
8309 * Classname: SysMonthCal32 | |
8310 * Returns: | |
8311 * A handle to a calendar window or NULL on failure. | |
8312 */ | |
8313 HWND API dw_calendar_new(unsigned long id) | |
8314 { | |
8315 RECT rc; | |
8316 MONTHDAYSTATE mds[3]; | |
8317 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, | |
8318 MONTHCAL_CLASS, | |
8319 "", | |
8320 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | MCS_DAYSTATE, | |
8321 0,0,2000,1000, // resize it later | |
8322 DW_HWND_OBJECT, | |
8323 (HMENU)id, | |
8324 DWInstance, | |
8325 NULL); | |
8326 if ( tmp ) | |
8327 { | |
8328 // Get the size required to show an entire month. | |
8329 MonthCal_GetMinReqRect(tmp, &rc); | |
8330 // Resize the control now that the size values have been obtained. | |
8331 SetWindowPos(tmp, NULL, 0, 0, | |
8332 rc.right, rc.bottom, | |
8333 SWP_NOZORDER | SWP_NOMOVE); | |
8334 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; | |
8335 MonthCal_SetDayState(tmp,3,mds); | |
8336 return tmp; | |
8337 } | |
8338 else | |
8339 return NULL; | |
8340 } | |
8341 | |
8342 /* | |
8343 * Sets the current date of a calendar | |
8344 * Parameters: | |
8345 * handle: The handle to the calendar returned by dw_calendar_new(). | |
8346 * year: The year to set the date to | |
8347 * month: The month to set the date to | |
8348 * day: The day to set the date to | |
8349 */ | |
8350 void API dw_calendar_set_date(HWND handle, int year, int month, int day) | |
8351 { | |
8352 MONTHDAYSTATE mds[3]; | |
8353 SYSTEMTIME date; | |
8354 date.wYear = year; | |
8355 date.wMonth = month; | |
8356 date.wDay = day; | |
8357 if ( MonthCal_SetCurSel( handle, &date ) ) | |
8358 { | |
8359 } | |
8360 else | |
8361 { | |
8362 } | |
8363 mds[0] = mds[1] = mds[2] = (MONTHDAYSTATE)0; | |
8364 MonthCal_SetDayState(handle,3,mds); | |
8365 } | |
8366 | |
8367 /* | |
8368 * Gets the date from the calendar | |
8369 * Parameters: | |
8370 * handle: The handle to the calendar returned by dw_calendar_new(). | |
8371 * year: Pointer to the year to get the date to | |
8372 * month: Pointer to the month to get the date to | |
8373 * day: Pointer to the day to get the date to | |
8374 */ | |
8375 void API dw_calendar_get_date(HWND handle, int *year, int *month, int *day) | |
8376 { | |
8377 SYSTEMTIME date; | |
8378 if ( MonthCal_GetCurSel( handle, &date ) ) | |
8379 { | |
8380 *year = date.wYear; | |
8381 *month = date.wMonth; | |
8382 *day = date.wDay; | |
8383 } | |
8384 else | |
8385 { | |
8386 *year = *month = *day = 0; | |
8387 } | |
8388 } | |
8389 | |
8390 /* | |
8276 * Pack windows (widgets) into a box from the end (or bottom). | 8391 * Pack windows (widgets) into a box from the end (or bottom). |
8277 * Parameters: | 8392 * Parameters: |
8278 * box: Window handle of the box to be packed into. | 8393 * box: Window handle of the box to be packed into. |
8279 * item: Window handle of the item to be back. | 8394 * item: Window handle of the item to be back. |
8280 * width: Width in pixels of the item or -1 to be self determined. | 8395 * width: Width in pixels of the item or -1 to be self determined. |
8318 if(hsize && !width) | 8433 if(hsize && !width) |
8319 width = 1; | 8434 width = 1; |
8320 | 8435 |
8321 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) | 8436 if(strnicmp(tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1)==0) |
8322 tmpitem[0].type = TYPEBOX; | 8437 tmpitem[0].type = TYPEBOX; |
8438 else if(strnicmp(tmpbuf, "SysMonthCal32", 13)==0) | |
8439 { | |
8440 RECT rc; | |
8441 MonthCal_GetMinReqRect(item, &rc); | |
8442 width = 1 + rc.right - rc.left; | |
8443 height = 1 + rc.bottom - rc.top; | |
8444 tmpitem[thisbox->count].type = TYPEITEM; | |
8445 } | |
8323 else | 8446 else |
8324 { | 8447 { |
8325 if ( width == 0 && hsize == FALSE ) | 8448 if ( width == 0 && hsize == FALSE ) |
8326 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); | 8449 dw_messagebox("dw_box_pack_end()", DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); |
8327 if ( height == 0 && vsize == FALSE ) | 8450 if ( height == 0 && vsize == FALSE ) |