2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Point pt;
|
|
|
|
int height, count, pos, cap;
|
|
|
|
|
|
|
|
top += 10;
|
|
|
|
bottom -= 9;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
height = (bottom - top);
|
|
|
|
|
|
|
|
pos = sb->pos;
|
|
|
|
count = sb->count;
|
|
|
|
cap = sb->cap;
|
|
|
|
|
2005-07-08 22:25:24 +00:00
|
|
|
if (count != 0) top += height * pos / count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (cap > count) cap = count;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (count != 0) bottom -= (count - pos - cap) * height / count;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
pt.x = top;
|
|
|
|
pt.y = bottom - 1;
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* Special handling for the scrollbar widget type.
|
|
|
|
* Handles the special scrolling buttons and other
|
|
|
|
* scrolling.
|
|
|
|
* Parameters:
|
|
|
|
* w - Window.
|
|
|
|
* wi - Pointer to the scrollbar widget.
|
|
|
|
* x - The X coordinate of the mouse click.
|
|
|
|
* y - The Y coordinate of the mouse click.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
|
|
|
|
{
|
|
|
|
int mi, ma, pos;
|
|
|
|
Scrollbar *sb;
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
switch (wi->type) {
|
|
|
|
case WWT_SCROLLBAR: {
|
|
|
|
// vertical scroller
|
|
|
|
w->flags4 &= ~WF_HSCROLL;
|
|
|
|
w->flags4 &= ~WF_SCROLL2;
|
|
|
|
mi = wi->top;
|
|
|
|
ma = wi->bottom;
|
|
|
|
pos = y;
|
|
|
|
sb = &w->vscroll;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_SCROLL2BAR: {
|
|
|
|
// 2nd vertical scroller
|
|
|
|
w->flags4 &= ~WF_HSCROLL;
|
|
|
|
w->flags4 |= WF_SCROLL2;
|
|
|
|
mi = wi->top;
|
|
|
|
ma = wi->bottom;
|
|
|
|
pos = y;
|
|
|
|
sb = &w->vscroll2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_HSCROLLBAR: {
|
|
|
|
// horizontal scroller
|
2005-01-03 19:45:18 +00:00
|
|
|
w->flags4 &= ~WF_SCROLL2;
|
2005-01-02 17:23:04 +00:00
|
|
|
w->flags4 |= WF_HSCROLL;
|
|
|
|
mi = wi->left;
|
|
|
|
ma = wi->right;
|
|
|
|
pos = x;
|
|
|
|
sb = &w->hscroll;
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-02 22:28:56 +00:00
|
|
|
default: return; //this should never happen
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (pos <= mi+9) {
|
|
|
|
// Pressing the upper button?
|
2005-11-04 14:57:53 +00:00
|
|
|
w->flags4 |= WF_SCROLL_UP;
|
|
|
|
if (_scroller_click_timeout == 0) {
|
|
|
|
_scroller_click_timeout = 6;
|
|
|
|
if (sb->pos != 0) sb->pos--;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-04 14:57:53 +00:00
|
|
|
_left_button_clicked = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (pos >= ma-10) {
|
|
|
|
// Pressing the lower button?
|
2005-11-04 14:57:53 +00:00
|
|
|
w->flags4 |= WF_SCROLL_DOWN;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-04 14:57:53 +00:00
|
|
|
if (_scroller_click_timeout == 0) {
|
|
|
|
_scroller_click_timeout = 6;
|
|
|
|
if ((byte)(sb->pos + sb->cap) < sb->count)
|
|
|
|
sb->pos++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-04 14:57:53 +00:00
|
|
|
_left_button_clicked = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2004-09-10 19:02:27 +00:00
|
|
|
//
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt = HandleScrollbarHittest(sb, mi, ma);
|
|
|
|
|
|
|
|
if (pos < pt.x) {
|
|
|
|
sb->pos = max(sb->pos - sb->cap, 0);
|
|
|
|
} else if (pos > pt.y) {
|
|
|
|
sb->pos = min(
|
2004-09-10 19:02:27 +00:00
|
|
|
sb->pos + sb->cap,
|
2004-08-09 17:04:08 +00:00
|
|
|
max(sb->count - sb->cap, 0)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
_scrollbar_start_pos = pt.x - mi - 9;
|
|
|
|
_scrollbar_size = ma - mi - 23;
|
|
|
|
w->flags4 |= WF_SCROLL_MIDDLE;
|
|
|
|
_scrolling_scrollbar = true;
|
|
|
|
_cursorpos_drag_start = _cursor.pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
/** Returns the index for the widget located at the given position
|
|
|
|
* relative to the window. It includes all widget-corner pixels as well.
|
|
|
|
* @param *w Window to look inside
|
|
|
|
* @param x,y Window client coordinates
|
|
|
|
* @return A widget index, or -1 if no widget was found.
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-09-18 20:56:44 +00:00
|
|
|
int GetWidgetFromPos(const Window *w, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const Widget *wi;
|
|
|
|
int index, found_index = -1;
|
|
|
|
|
|
|
|
// Go through the widgets and check if we find the widget that the coordinate is
|
|
|
|
// inside.
|
2005-07-08 00:14:19 +00:00
|
|
|
for (index = 0,wi = w->widget; wi->type != WWT_LAST; index++, wi++) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom &&
|
2006-10-06 01:33:27 +00:00
|
|
|
!IsWidgetHidden(wi)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
found_index = index;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-29 06:07:57 +00:00
|
|
|
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags)
|
|
|
|
{
|
2006-08-29 19:26:13 +00:00
|
|
|
uint dark = _colour_gradient[ctab][3];
|
|
|
|
uint medium_dark = _colour_gradient[ctab][5];
|
|
|
|
uint medium_light = _colour_gradient[ctab][6];
|
|
|
|
uint light = _colour_gradient[ctab][7];
|
2006-08-29 06:07:57 +00:00
|
|
|
|
2006-08-29 06:39:00 +00:00
|
|
|
if (flags & FR_TRANSPARENT) {
|
|
|
|
GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE);
|
2006-08-29 06:07:57 +00:00
|
|
|
} else {
|
|
|
|
uint interior;
|
|
|
|
|
|
|
|
if (flags & FR_LOWERED) {
|
|
|
|
GfxFillRect(left, top, left, bottom, dark);
|
|
|
|
GfxFillRect(left + 1, top, right, top, dark);
|
|
|
|
GfxFillRect(right, top + 1, right, bottom - 1, light);
|
|
|
|
GfxFillRect(left + 1, bottom, right, bottom, light);
|
|
|
|
interior = (flags & FR_DARKENED ? medium_dark : medium_light);
|
|
|
|
} else {
|
|
|
|
GfxFillRect(left, top, left, bottom - 1, light);
|
|
|
|
GfxFillRect(left + 1, top, right - 1, top, light);
|
|
|
|
GfxFillRect(right, top, right, bottom - 1, dark);
|
|
|
|
GfxFillRect(left, bottom, right, bottom, dark);
|
|
|
|
interior = medium_dark;
|
|
|
|
}
|
|
|
|
if (!(flags & FR_BORDERONLY)) {
|
|
|
|
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawWindowWidgets(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const Widget *wi;
|
2005-10-22 06:39:32 +00:00
|
|
|
const DrawPixelInfo* dpi = _cur_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
Rect r;
|
2006-10-03 20:16:20 +00:00
|
|
|
int i = 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
wi = w->widget;
|
|
|
|
|
|
|
|
do {
|
2006-10-03 20:16:20 +00:00
|
|
|
bool clicked = IsWindowWidgetLowered((Window*)w, i);
|
2005-04-07 00:59:54 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (dpi->left > (r.right=/*w->left + */wi->right) ||
|
2005-11-14 19:48:04 +00:00
|
|
|
dpi->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
|
2004-08-09 17:04:08 +00:00
|
|
|
dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
|
|
|
|
dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
|
2006-10-06 01:33:27 +00:00
|
|
|
IsWidgetHidden(wi)) {
|
2005-11-14 19:48:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
switch (wi->type & WWT_MASK) {
|
2006-10-24 14:15:17 +00:00
|
|
|
case WWT_IMGBTN:
|
|
|
|
case WWT_IMGBTN_2: {
|
2006-09-04 15:44:28 +00:00
|
|
|
int img = wi->data;
|
2006-10-24 14:15:17 +00:00
|
|
|
assert(img != 0);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
|
2006-10-24 14:15:17 +00:00
|
|
|
/* show different image when clicked for WWT_IMGBTN_2 */
|
|
|
|
if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
|
|
|
|
DrawSprite(img, r.left + 1 + clicked, r.top + 1 + clicked);
|
|
|
|
goto draw_default;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-24 14:15:17 +00:00
|
|
|
case WWT_PANEL: {
|
|
|
|
assert(wi->data == 0);
|
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
goto draw_default;
|
|
|
|
}
|
|
|
|
|
2006-10-24 16:27:18 +00:00
|
|
|
case WWT_TEXTBTN:
|
|
|
|
case WWT_TEXTBTN_2: {
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
2006-08-22 15:23:25 +00:00
|
|
|
case WWT_LABEL: {
|
2006-09-04 15:44:28 +00:00
|
|
|
StringID str = wi->data;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-24 16:27:18 +00:00
|
|
|
if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, 0);
|
2005-07-15 15:09:52 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-10-24 16:27:18 +00:00
|
|
|
case WWT_INSET: {
|
2006-09-04 15:44:28 +00:00
|
|
|
StringID str = wi->data;
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-04 15:44:28 +00:00
|
|
|
if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, 0, r.right - r.left - 10);
|
2004-08-09 17:04:08 +00:00
|
|
|
goto draw_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_MATRIX: {
|
2004-09-10 19:02:27 +00:00
|
|
|
int c, d, ctr;
|
2004-08-09 17:04:08 +00:00
|
|
|
int x, amt1, amt2;
|
|
|
|
int color;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-09-04 15:44:28 +00:00
|
|
|
c = GB(wi->data, 0, 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
amt1 = (wi->right - wi->left + 1) / c;
|
|
|
|
|
2006-09-04 15:44:28 +00:00
|
|
|
d = GB(wi->data, 8, 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
amt2 = (wi->bottom - wi->top + 1) / d;
|
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
color = _colour_gradient[wi->color & 0xF][6];
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
x = r.left;
|
2005-12-28 08:39:43 +00:00
|
|
|
for (ctr = c; ctr > 1; ctr--) {
|
2004-08-09 17:04:08 +00:00
|
|
|
x += amt1;
|
2005-11-14 19:48:04 +00:00
|
|
|
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x = r.top;
|
2005-12-28 08:39:43 +00:00
|
|
|
for (ctr = d; ctr > 1; ctr--) {
|
2004-08-09 17:04:08 +00:00
|
|
|
x += amt2;
|
2005-11-14 19:48:04 +00:00
|
|
|
GfxFillRect(r.left + 1, x, r.right - 1, x, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
color = _colour_gradient[wi->color&0xF][4];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
x = r.left - 1;
|
2005-12-28 08:39:43 +00:00
|
|
|
for (ctr = c; ctr > 1; ctr--) {
|
2004-08-09 17:04:08 +00:00
|
|
|
x += amt1;
|
2005-11-14 19:48:04 +00:00
|
|
|
GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
x = r.top - 1;
|
2005-12-28 08:39:43 +00:00
|
|
|
for (ctr = d; ctr > 1; ctr--) {
|
2004-08-09 17:04:08 +00:00
|
|
|
x += amt2;
|
|
|
|
GfxFillRect(r.left+1, x, r.right-1, x, color);
|
|
|
|
}
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vertical scrollbar
|
|
|
|
case WWT_SCROLLBAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// draw up/down buttons
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
c1 = _colour_gradient[wi->color&0xF][3];
|
|
|
|
c2 = _colour_gradient[wi->color&0xF][7];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
|
|
|
|
GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : 0);
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_SCROLL2BAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
// draw up/down buttons
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
c1 = _colour_gradient[wi->color&0xF][3];
|
|
|
|
c2 = _colour_gradient[wi->color&0xF][7];
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
|
|
|
|
GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
|
|
|
|
|
|
|
|
pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// horizontal scrollbar
|
|
|
|
case WWT_HSCROLLBAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:45:38 +00:00
|
|
|
assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-01-04 21:28:09 +00:00
|
|
|
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_ARROW_LEFT, r.left + 1 + clicked, r.top + 1 + clicked);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-24 16:28:34 +00:00
|
|
|
clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_ARROW_RIGHT, r.right - 8 + clicked, r.top + 1 + clicked);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
c1 = _colour_gradient[wi->color&0xF][3];
|
|
|
|
c2 = _colour_gradient[wi->color&0xF][7];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+10, r.top+2, r.right-10, r.top+2, c1);
|
|
|
|
GfxFillRect(r.left+10, r.top+3, r.right-10, r.top+3, c2);
|
|
|
|
GfxFillRect(r.left+10, r.top+7, r.right-10, r.top+7, c1);
|
|
|
|
GfxFillRect(r.left+10, r.top+8, r.right-10, r.top+8, c2);
|
|
|
|
|
|
|
|
// draw actual scrollbar
|
|
|
|
pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_FRAME: {
|
|
|
|
int c1,c2;
|
2005-01-03 17:55:25 +00:00
|
|
|
int x2 = r.left; // by default the left side is the left side of the widget
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-04 15:44:28 +00:00
|
|
|
if (wi->data != 0) x2 = DrawString(r.left + 6, r.top, wi->data, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-29 19:26:13 +00:00
|
|
|
c1 = _colour_gradient[wi->color][3];
|
|
|
|
c2 = _colour_gradient[wi->color][7];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
//Line from upper left corner to start of text
|
|
|
|
GfxFillRect(r.left, r.top+4, r.left+4,r.top+4, c1);
|
|
|
|
GfxFillRect(r.left+1, r.top+5, r.left+4,r.top+5, c2);
|
|
|
|
|
|
|
|
// Line from end of text to upper right corner
|
|
|
|
GfxFillRect(x2, r.top+4, r.right-1,r.top+4,c1);
|
|
|
|
GfxFillRect(x2, r.top+5, r.right-2,r.top+5,c2);
|
|
|
|
|
|
|
|
// Line from upper left corner to bottom left corner
|
|
|
|
GfxFillRect(r.left, r.top+5, r.left, r.bottom-1, c1);
|
|
|
|
GfxFillRect(r.left+1, r.top+6, r.left+1, r.bottom-2, c2);
|
|
|
|
|
|
|
|
//Line from upper right corner to bottom right corner
|
|
|
|
GfxFillRect(r.right-1, r.top+5, r.right-1, r.bottom-2, c1);
|
|
|
|
GfxFillRect(r.right, r.top+4, r.right, r.bottom-1, c2);
|
|
|
|
|
|
|
|
GfxFillRect(r.left+1, r.bottom-1, r.right-1, r.bottom-1, c1);
|
|
|
|
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
|
|
|
|
|
2005-07-15 15:09:52 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 23:33:04 +00:00
|
|
|
case WWT_STICKYBOX: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-11-29 22:04:02 +00:00
|
|
|
|
|
|
|
clicked = !!(w->flags4 & WF_STICKY);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, r.left + 2 + clicked, r.top + 3 + clicked);
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_RESIZEBOX: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!(w->flags4 & WF_SIZING);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_WINDOW_RESIZE, r.left + 3 + clicked, r.top + 3 + clicked);
|
2004-12-15 23:33:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-12-14 08:05:36 +00:00
|
|
|
case WWT_CLOSEBOX: {
|
|
|
|
assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
|
|
|
|
|
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, 0);
|
|
|
|
DrawString(r.left + 2, r.top + 2, STR_00C5, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WWT_CAPTION: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
|
|
|
|
DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->caption_color != 0xFF) {
|
2006-08-29 19:26:13 +00:00
|
|
|
GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _colour_gradient[_player_colors[w->caption_color]][4]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 23:29:24 +00:00
|
|
|
DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top+2, wi->data, 0x84);
|
2004-08-09 17:04:08 +00:00
|
|
|
draw_default:;
|
2006-10-06 01:33:27 +00:00
|
|
|
if (IsWidgetDisabled(wi)) {
|
2006-08-29 19:26:13 +00:00
|
|
|
GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-10-06 01:33:27 +00:00
|
|
|
} while (i++, (++wi)->type != WWT_LAST);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
|
|
|
//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, FR_BORDERONLY);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-04 13:45:58 +00:00
|
|
|
static const Widget _dropdown_menu_widgets[] = {
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
2006-11-06 22:06:29 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-09-06 18:15:13 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static int GetDropdownItem(const Window *w)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2005-09-23 07:44:03 +00:00
|
|
|
byte item, counter;
|
2004-09-06 18:15:13 +00:00
|
|
|
int y;
|
|
|
|
|
|
|
|
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
|
|
|
|
return -1;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-11-06 22:06:29 +00:00
|
|
|
y = _cursor.pos.y - w->top - 2 + w->vscroll.pos;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
return - 1;
|
|
|
|
|
|
|
|
item = y / 10;
|
2005-11-22 14:02:45 +00:00
|
|
|
if (item >= WP(w,dropdown_d).num_items || (HASBIT(WP(w,dropdown_d).disabled_state, item) && !HASBIT(WP(w,dropdown_d).hidden_state, item)) || WP(w,dropdown_d).items[item] == 0)
|
2004-09-06 18:15:13 +00:00
|
|
|
return - 1;
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
// Skip hidden items -- +1 for each hidden item before the clicked item.
|
|
|
|
for (counter = 0; item >= counter; ++counter)
|
2005-11-22 14:02:45 +00:00
|
|
|
if (HASBIT(WP(w,dropdown_d).hidden_state, counter)) item++;
|
2005-09-23 07:44:03 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void DropdownMenuWndProc(Window *w, WindowEvent *e)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
int item;
|
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (e->event) {
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int x,y,i,sel;
|
2006-11-06 22:06:29 +00:00
|
|
|
int width;
|
|
|
|
bool scroll = w->vscroll.count > 0;
|
|
|
|
DrawPixelInfo tmp_dpi, *old_dpi = NULL;
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
x = 1;
|
2006-11-06 22:06:29 +00:00
|
|
|
y = 2 - w->vscroll.pos;
|
|
|
|
|
|
|
|
if (scroll) {
|
|
|
|
/* Set up the bounding box for drawing the list content */
|
|
|
|
if (!FillDrawPixelInfo(&tmp_dpi, w->widget[0].left + 1, w->widget[0].top + 1, w->widget[0].right - 1, w->widget[0].bottom - 1)) return;
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
|
_cur_dpi = &tmp_dpi;
|
|
|
|
|
|
|
|
/* Adjust x and y for the 1 pixel offset of the bounding box */
|
|
|
|
x--;
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
sel = WP(w,dropdown_d).selected_index;
|
|
|
|
width = w->widget[0].right - 3;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-11-14 08:42:45 +00:00
|
|
|
for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++) {
|
2005-11-22 14:02:45 +00:00
|
|
|
if (HASBIT(WP(w,dropdown_d).hidden_state, i)) {
|
2005-01-02 17:23:04 +00:00
|
|
|
sel--;
|
2005-01-26 11:23:54 +00:00
|
|
|
continue;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2006-09-08 03:59:38 +00:00
|
|
|
if (WP(w,dropdown_d).items[i] != STR_NULL) {
|
2006-11-06 22:06:29 +00:00
|
|
|
if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
|
|
|
|
DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
|
2005-01-26 11:23:54 +00:00
|
|
|
|
2005-11-22 14:02:45 +00:00
|
|
|
if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
|
2006-11-06 22:06:29 +00:00
|
|
|
GfxFillRect(x, y, x + width, y + 9,
|
2006-08-29 19:26:13 +00:00
|
|
|
PALETTE_MODIFIER_GREYOUT | _colour_gradient[_dropdown_menu_widgets[0].color][5]
|
2005-11-14 19:48:04 +00:00
|
|
|
);
|
2005-01-26 11:23:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-08-29 19:26:13 +00:00
|
|
|
int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
|
|
|
|
int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
|
|
|
|
GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
|
2005-01-26 11:23:54 +00:00
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
sel--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2006-11-06 22:06:29 +00:00
|
|
|
|
|
|
|
/* Reset the bounding box if we had set it up */
|
|
|
|
if (scroll) _cur_dpi = old_dpi;
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_CLICK: {
|
2006-11-06 22:06:29 +00:00
|
|
|
if (e->we.click.widget != 0) break;
|
2005-01-02 17:23:04 +00:00
|
|
|
item = GetDropdownItem(w);
|
|
|
|
if (item >= 0) {
|
2005-11-14 08:42:45 +00:00
|
|
|
WP(w,dropdown_d).click_delay = 4;
|
|
|
|
WP(w,dropdown_d).selected_index = item;
|
2005-01-02 17:23:04 +00:00
|
|
|
SetWindowDirty(w);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_MOUSELOOP: {
|
2005-11-14 08:42:45 +00:00
|
|
|
Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
|
2005-01-02 17:23:04 +00:00
|
|
|
if (w2 == NULL) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-11-14 08:42:45 +00:00
|
|
|
if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
|
2005-01-02 17:23:04 +00:00
|
|
|
WindowEvent e;
|
|
|
|
e.event = WE_DROPDOWN_SELECT;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.dropdown.button = WP(w,dropdown_d).parent_button;
|
|
|
|
e.we.dropdown.index = WP(w,dropdown_d).selected_index;
|
2005-01-02 17:23:04 +00:00
|
|
|
w2->wndproc(w2, &e);
|
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-11-14 08:42:45 +00:00
|
|
|
if (WP(w,dropdown_d).drag_mode) {
|
2005-01-02 17:23:04 +00:00
|
|
|
item = GetDropdownItem(w);
|
|
|
|
|
|
|
|
if (!_left_button_clicked) {
|
2005-11-14 08:42:45 +00:00
|
|
|
WP(w,dropdown_d).drag_mode = false;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (item < 0) return;
|
2005-11-14 08:42:45 +00:00
|
|
|
WP(w,dropdown_d).click_delay = 2;
|
2005-01-02 17:23:04 +00:00
|
|
|
} else {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (item < 0) return;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-11-14 08:42:45 +00:00
|
|
|
WP(w,dropdown_d).selected_index = item;
|
2005-01-02 17:23:04 +00:00
|
|
|
SetWindowDirty(w);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_DESTROY: {
|
2005-11-14 08:42:45 +00:00
|
|
|
Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
|
2005-01-02 17:23:04 +00:00
|
|
|
if (w2 != NULL) {
|
2006-10-03 20:16:20 +00:00
|
|
|
RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
|
2005-11-14 08:42:45 +00:00
|
|
|
InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
WindowNumber num;
|
|
|
|
WindowClass cls;
|
2005-01-03 19:45:18 +00:00
|
|
|
int i;
|
2004-09-06 18:15:13 +00:00
|
|
|
const Widget *wi;
|
|
|
|
Window *w2;
|
2006-11-06 22:06:29 +00:00
|
|
|
const Window *w3;
|
2006-10-03 20:16:20 +00:00
|
|
|
bool is_dropdown_menu_shown = IsWindowWidgetLowered(w, button);
|
2006-11-06 22:06:29 +00:00
|
|
|
int top, height;
|
|
|
|
int screen_top, screen_bottom;
|
|
|
|
bool scroll = false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
cls = w->window_class;
|
|
|
|
num = w->window_number;
|
|
|
|
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
|
|
w = FindWindowById(cls, num);
|
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
if (is_dropdown_menu_shown) return;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, button);
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
InvalidateWidget(w, button);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; strings[i] != INVALID_STRING_ID; i++) {}
|
|
|
|
if (i == 0) return;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
wi = &w->widget[button];
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
if (hidden_mask != 0) {
|
2005-11-14 19:48:04 +00:00
|
|
|
uint j;
|
|
|
|
|
2005-11-14 08:42:45 +00:00
|
|
|
for (j = 0; strings[j] != INVALID_STRING_ID; j++) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (HASBIT(hidden_mask, j)) i--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-06 22:06:29 +00:00
|
|
|
/* The preferred position is just below the dropdown calling widget */
|
|
|
|
top = w->top + wi->bottom + 2;
|
|
|
|
height = i * 10 + 4;
|
|
|
|
|
|
|
|
w3 = FindWindowById(WC_STATUS_BAR, 0);
|
|
|
|
screen_bottom = w3 == NULL ? _screen.height : w3->top;
|
|
|
|
|
|
|
|
/* Check if the dropdown will fully fit below the widget */
|
|
|
|
if (top + height >= screen_bottom) {
|
|
|
|
w3 = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
|
|
|
screen_top = w3 == NULL ? 0 : w3->top + w3->height;
|
|
|
|
|
|
|
|
/* If not, check if it will fit above the widget */
|
|
|
|
if (w->top + wi->top - height - 1 > screen_top) {
|
|
|
|
top = w->top + wi->top - height - 1;
|
|
|
|
} else {
|
|
|
|
/* ... and lastly if it won't, enable the scroll bar and fit the
|
|
|
|
* list in below the widget */
|
|
|
|
height = screen_bottom - top;
|
|
|
|
scroll = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
w2 = AllocateWindow(
|
|
|
|
w->left + wi[-1].left + 1,
|
2006-11-06 22:06:29 +00:00
|
|
|
top,
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->right - wi[-1].left + 1,
|
2006-11-06 22:06:29 +00:00
|
|
|
height,
|
2004-09-06 18:15:13 +00:00
|
|
|
DropdownMenuWndProc,
|
2006-09-08 03:59:38 +00:00
|
|
|
WC_DROPDOWN_MENU,
|
2004-09-06 18:15:13 +00:00
|
|
|
_dropdown_menu_widgets);
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
w2->widget[0].color = wi->color;
|
|
|
|
w2->widget[0].right = wi->right - wi[-1].left;
|
2006-11-06 22:06:29 +00:00
|
|
|
w2->widget[0].bottom = height - 1;
|
|
|
|
|
|
|
|
SetWindowWidgetHiddenState(w2, 1, !scroll);
|
|
|
|
|
|
|
|
if (scroll) {
|
|
|
|
/* We're scrolling, so enable the scroll bar and shrink the list by
|
|
|
|
* the scrollbar's width */
|
|
|
|
w2->widget[1].color = wi->color;
|
|
|
|
w2->widget[1].right = w2->widget[0].right;
|
|
|
|
w2->widget[1].left = w2->widget[1].right - 11;
|
|
|
|
w2->widget[1].bottom = height - 1;
|
|
|
|
w2->widget[0].right -= 12;
|
|
|
|
|
|
|
|
w2->vscroll.cap = height - 1;
|
|
|
|
w2->vscroll.count = i * 10 + 3;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-11-06 22:06:29 +00:00
|
|
|
w2->desc_flags = WDF_DEF_WIDGET;
|
2004-09-06 18:15:13 +00:00
|
|
|
w2->flags4 &= ~WF_WHITE_BORDER_MASK;
|
2005-11-12 11:10:12 +00:00
|
|
|
|
2005-11-22 14:02:45 +00:00
|
|
|
WP(w2,dropdown_d).disabled_state = disabled_mask;
|
|
|
|
WP(w2,dropdown_d).hidden_state = hidden_mask;
|
2005-11-14 08:42:45 +00:00
|
|
|
|
|
|
|
WP(w2,dropdown_d).parent_wnd_class = w->window_class;
|
|
|
|
WP(w2,dropdown_d).parent_wnd_num = w->window_number;
|
|
|
|
WP(w2,dropdown_d).parent_button = button;
|
|
|
|
|
|
|
|
WP(w2,dropdown_d).num_items = i;
|
|
|
|
WP(w2,dropdown_d).selected_index = selected;
|
|
|
|
WP(w2,dropdown_d).items = strings;
|
|
|
|
|
|
|
|
WP(w2,dropdown_d).click_delay = 0;
|
|
|
|
WP(w2,dropdown_d).drag_mode = true;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|