src/widget.cpp
branchcpp_gui
changeset 6235 5077e6ed3788
parent 6075 33cdb35f9af5
child 6237 bce32e54c993
equal deleted inserted replaced
6234:42bf2d268a86 6235:5077e6ed3788
   119 			_scrolling_scrollbar = true;
   119 			_scrolling_scrollbar = true;
   120 			_cursorpos_drag_start = _cursor.pos;
   120 			_cursorpos_drag_start = _cursor.pos;
   121 		}
   121 		}
   122 	}
   122 	}
   123 
   123 
   124 	SetWindowDirty(w);
   124 	w->SetDirty();
   125 }
   125 }
   126 
   126 
   127 /** Returns the index for the widget located at the given position
   127 /** Returns the index for the widget located at the given position
   128  * relative to the window. It includes all widget-corner pixels as well.
   128  * relative to the window. It includes all widget-corner pixels as well.
   129  * @param *w Window to look inside
   129  * @param *w Window to look inside
   548 			if (e->we.click.widget != 0) break;
   548 			if (e->we.click.widget != 0) break;
   549 			item = GetDropdownItem(w);
   549 			item = GetDropdownItem(w);
   550 			if (item >= 0) {
   550 			if (item >= 0) {
   551 				WP(w,dropdown_d).click_delay = 4;
   551 				WP(w,dropdown_d).click_delay = 4;
   552 				WP(w,dropdown_d).selected_index = item;
   552 				WP(w,dropdown_d).selected_index = item;
   553 				SetWindowDirty(w);
   553 				w->SetDirty();
   554 			}
   554 			}
   555 		} break;
   555 		} break;
   556 
   556 
   557 		case WE_MOUSELOOP: {
   557 		case WE_MOUSELOOP: {
   558 			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
   558 			Window *w2 = Window::FindById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
   559 			if (w2 == NULL) {
   559 			if (w2 == NULL) {
   560 				DeleteWindow(w);
   560 				w->Close();
   561 				return;
   561 				return;
   562 			}
   562 			}
   563 
   563 
   564 			if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
   564 			if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
   565 				WindowEvent e;
   565 				WindowEvent e;
   566 				e.event = WE_DROPDOWN_SELECT;
   566 				e.event = WE_DROPDOWN_SELECT;
   567 				e.we.dropdown.button = WP(w,dropdown_d).parent_button;
   567 				e.we.dropdown.button = WP(w,dropdown_d).parent_button;
   568 				e.we.dropdown.index  = WP(w,dropdown_d).selected_index;
   568 				e.we.dropdown.index  = WP(w,dropdown_d).selected_index;
   569 				w2->wndproc(w2, &e);
   569 				w2->wndproc(w2, &e);
   570 				DeleteWindow(w);
   570 				w->Close();
   571 				return;
   571 				return;
   572 			}
   572 			}
   573 
   573 
   574 			if (WP(w,dropdown_d).drag_mode) {
   574 			if (WP(w,dropdown_d).drag_mode) {
   575 				item = GetDropdownItem(w);
   575 				item = GetDropdownItem(w);
   581 				} else {
   581 				} else {
   582 					if (item < 0) return;
   582 					if (item < 0) return;
   583 				}
   583 				}
   584 
   584 
   585 				WP(w,dropdown_d).selected_index = item;
   585 				WP(w,dropdown_d).selected_index = item;
   586 				SetWindowDirty(w);
   586 				w->SetDirty();
   587 			}
   587 			}
   588 		} break;
   588 		} break;
   589 
   589 
   590 		case WE_DESTROY: {
   590 		case WE_DESTROY: {
   591 			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
   591 			Window *w2 = Window::FindById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
   592 			if (w2 != NULL) {
   592 			if (w2 != NULL) {
   593 				RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
   593 				RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
   594 				InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
   594 				InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
   595 			}
   595 			}
   596 		} break;
   596 		} break;
   631 
   631 
   632 	/* The preferred position is just below the dropdown calling widget */
   632 	/* The preferred position is just below the dropdown calling widget */
   633 	top = w->top + wi->bottom + 2;
   633 	top = w->top + wi->bottom + 2;
   634 	height = i * 10 + 4;
   634 	height = i * 10 + 4;
   635 
   635 
   636 	w3 = FindWindowById(WC_STATUS_BAR, 0);
   636 	w3 = Window::FindById(WC_STATUS_BAR, 0);
   637 	screen_bottom = w3 == NULL ? _screen.height : w3->top;
   637 	screen_bottom = w3 == NULL ? _screen.height : w3->top;
   638 
   638 
   639 	/* Check if the dropdown will fully fit below the widget */
   639 	/* Check if the dropdown will fully fit below the widget */
   640 	if (top + height >= screen_bottom) {
   640 	if (top + height >= screen_bottom) {
   641 		w3 = FindWindowById(WC_MAIN_TOOLBAR, 0);
   641 		w3 = Window::FindById(WC_MAIN_TOOLBAR, 0);
   642 		screen_top = w3 == NULL ? 0 : w3->top + w3->height;
   642 		screen_top = w3 == NULL ? 0 : w3->top + w3->height;
   643 
   643 
   644 		/* If not, check if it will fit above the widget */
   644 		/* If not, check if it will fit above the widget */
   645 		if (w->top + wi->top - height - 1 > screen_top) {
   645 		if (w->top + wi->top - height - 1 > screen_top) {
   646 			top = w->top + wi->top - height - 1;
   646 			top = w->top + wi->top - height - 1;
   651 			height = rows * 10 + 4;
   651 			height = rows * 10 + 4;
   652 			scroll = true;
   652 			scroll = true;
   653 		}
   653 		}
   654 	}
   654 	}
   655 
   655 
   656 	w2 = AllocateWindow(
   656 	w2 = Window::Allocate(
   657 		w->left + wi[-1].left + 1,
   657 		w->left + wi[-1].left + 1,
   658 		top,
   658 		top,
   659 		wi->right - wi[-1].left + 1,
   659 		wi->right - wi[-1].left + 1,
   660 		height,
   660 		height,
   661 		DropdownMenuWndProc,
   661 		DropdownMenuWndProc,