diff options
Diffstat (limited to 'nGenEx/ComboBox.cpp')
-rw-r--r-- | nGenEx/ComboBox.cpp | 468 |
1 files changed, 234 insertions, 234 deletions
diff --git a/nGenEx/ComboBox.cpp b/nGenEx/ComboBox.cpp index 29cc87f..3c3934f 100644 --- a/nGenEx/ComboBox.cpp +++ b/nGenEx/ComboBox.cpp @@ -1,15 +1,15 @@ /* Project nGenEx
- Destroyer Studios LLC
- Copyright © 1997-2004. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
- SUBSYSTEM: nGenEx.lib
- FILE: ComboBox.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: nGenEx.lib
+ FILE: ComboBox.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Drop-down list of Buttons class
+ OVERVIEW
+ ========
+ Drop-down list of Buttons class
*/
#include "MemDebug.h"
@@ -30,77 +30,77 @@ DEF_MAP_CLIENT(ComboBox, OnListExit); // +--------------------------------------------------------------------+
ComboBox::ComboBox(ActiveWindow* p, int ax, int ay, int aw, int ah, DWORD aid)
- : ActiveWindow(p->GetScreen(), ax, ay, aw, ah, aid, 0, p)
+: ActiveWindow(p->GetScreen(), ax, ay, aw, ah, aid, 0, p)
{
- button_state = 0;
- captured = 0;
- pre_state = 0;
- seln = 0;
- list = 0;
- list_showing = false;
- border = true;
- animated = true;
- bevel_width = 5;
+ button_state = 0;
+ captured = 0;
+ pre_state = 0;
+ seln = 0;
+ list = 0;
+ list_showing = false;
+ border = true;
+ animated = true;
+ bevel_width = 5;
- char buf[32];
- sprintf_s(buf, "ComboBox %d", id);
- desc = buf;
+ char buf[32];
+ sprintf_s(buf, "ComboBox %d", id);
+ desc = buf;
}
ComboBox::ComboBox(Screen* s, int ax, int ay, int aw, int ah, DWORD aid)
- : ActiveWindow(s, ax, ay, aw, ah, aid)
+: ActiveWindow(s, ax, ay, aw, ah, aid)
{
- button_state = 0;
- captured = 0;
- pre_state = 0;
- seln = 0;
- list = 0;
- list_showing = false;
- border = true;
- animated = true;
- bevel_width = 5;
+ button_state = 0;
+ captured = 0;
+ pre_state = 0;
+ seln = 0;
+ list = 0;
+ list_showing = false;
+ border = true;
+ animated = true;
+ bevel_width = 5;
- char buf[32];
- sprintf_s(buf, "ComboBox %d", id);
- desc = buf;
+ char buf[32];
+ sprintf_s(buf, "ComboBox %d", id);
+ desc = buf;
}
// +--------------------------------------------------------------------+
ComboBox::~ComboBox()
{
- items.destroy();
-
- if (list && !list_showing)
- delete list;
+ items.destroy();
+
+ if (list && !list_showing)
+ delete list;
}
// +--------------------------------------------------------------------+
void ComboBox::SetBevelWidth(short nNewValue)
{
- if (nNewValue < 0) nNewValue = 0;
- bevel_width = nNewValue;
+ if (nNewValue < 0) nNewValue = 0;
+ bevel_width = nNewValue;
}
void ComboBox::SetBorder(bool bNewValue)
{
- border = bNewValue;
+ border = bNewValue;
}
void ComboBox::SetBorderColor(Color newValue)
{
- border_color = newValue;
+ border_color = newValue;
}
void ComboBox::SetActiveColor(Color newValue)
{
- active_color = newValue;
+ active_color = newValue;
}
void ComboBox::SetAnimated(bool bNewValue)
{
- animated = bNewValue;
+ animated = bNewValue;
}
// +--------------------------------------------------------------------+
@@ -108,81 +108,81 @@ void ComboBox::SetAnimated(bool bNewValue) void
ComboBox::Draw()
{
- int x = 0;
- int y = 0;
- int w = rect.w;
- int h = rect.h;
+ int x = 0;
+ int y = 0;
+ int w = rect.w;
+ int h = rect.h;
+
+ if (w < 1 || h < 1 || !shown)
+ return;
- if (w < 1 || h < 1 || !shown)
- return;
+ Rect btn_rect(x,y,w,h);
- Rect btn_rect(x,y,w,h);
+ // draw the bevel:
+ DrawRectSimple(btn_rect, button_state);
- // draw the bevel:
- DrawRectSimple(btn_rect, button_state);
-
- // draw the border:
- if (border)
- DrawRect(0,0,w-1,h-1,border_color);
-
- // draw the arrow:
- POINT arrow[3];
- double h3 = (double)h/3.0;
+ // draw the border:
+ if (border)
+ DrawRect(0,0,w-1,h-1,border_color);
- arrow[0].x = (int) (w-2*h3);
- arrow[0].y = (int) (h3);
- arrow[1].x = (int) (w-h3);
- arrow[1].y = (int) (h3);
- arrow[2].x = (int) ((arrow[1].x + arrow[0].x)/2);
- arrow[2].y = (int) (2*h3);
+ // draw the arrow:
+ POINT arrow[3];
+ double h3 = (double)h/3.0;
- FillPoly(3, arrow, border_color);
+ arrow[0].x = (int) (w-2*h3);
+ arrow[0].y = (int) (h3);
+ arrow[1].x = (int) (w-h3);
+ arrow[1].y = (int) (h3);
+ arrow[2].x = (int) ((arrow[1].x + arrow[0].x)/2);
+ arrow[2].y = (int) (2*h3);
- // draw text here:
- Text caption = text;
- if (GetSelectedIndex() >= 0)
- caption = GetSelectedItem();
+ FillPoly(3, arrow, border_color);
- if (font && caption.length()) {
- int border_size = 4;
+ // draw text here:
+ Text caption = text;
+ if (GetSelectedIndex() >= 0)
+ caption = GetSelectedItem();
- if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME)
- border_size = 8;
+ if (font && caption.length()) {
+ int border_size = 4;
- Rect label_rect = CalcLabelRect();
- int vert_space = label_rect.h;
- int horz_space = label_rect.w;
+ if (style & WIN_RAISED_FRAME && style & WIN_SUNK_FRAME)
+ border_size = 8;
- DrawText(caption.data(), 0, label_rect, DT_CALCRECT | DT_WORDBREAK | text_align);
- vert_space = (vert_space - label_rect.h)/2;
-
- label_rect.w = horz_space;
+ Rect label_rect = CalcLabelRect();
+ int vert_space = label_rect.h;
+ int horz_space = label_rect.w;
- if (vert_space > 0)
- label_rect.y += vert_space;
+ DrawText(caption.data(), 0, label_rect, DT_CALCRECT | DT_WORDBREAK | text_align);
+ vert_space = (vert_space - label_rect.h)/2;
+
+ label_rect.w = horz_space;
- if (animated && button_state > 0) {
- label_rect.x += button_state;
- label_rect.y += button_state;
- }
+ if (vert_space > 0)
+ label_rect.y += vert_space;
- font->SetColor(fore_color);
- DrawText(caption.data(), 0, label_rect, DT_WORDBREAK | text_align);
- }
+ if (animated && button_state > 0) {
+ label_rect.x += button_state;
+ label_rect.y += button_state;
+ }
+
+ font->SetColor(fore_color);
+ DrawText(caption.data(), 0, label_rect, DT_WORDBREAK | text_align);
+ }
}
Rect ComboBox::CalcLabelRect()
{
- // fit the text in the bevel:
- Rect label_rect;
- label_rect.x = 0;
- label_rect.y = 0;
- label_rect.w = rect.w;
- label_rect.h = rect.h;
+ // fit the text in the bevel:
+ Rect label_rect;
+ label_rect.x = 0;
+ label_rect.y = 0;
+ label_rect.w = rect.w;
+ label_rect.h = rect.h;
- label_rect.Deflate(bevel_width, bevel_width);
+ label_rect.Deflate(bevel_width, bevel_width);
- return label_rect;
+ return label_rect;
}
// +--------------------------------------------------------------------+
@@ -190,245 +190,245 @@ Rect ComboBox::CalcLabelRect() void
ComboBox::DrawRectSimple(Rect& rect, int state)
{
- if (state && active_color != Color::Black)
- FillRect(rect, active_color);
- else
- FillRect(rect, back_color);
+ if (state && active_color != Color::Black)
+ FillRect(rect, active_color);
+ else
+ FillRect(rect, back_color);
}
// +--------------------------------------------------------------------+
int ComboBox::OnMouseMove(int x, int y)
{
- bool dirty = false;
-
- if (captured)
- {
- ActiveWindow* test = GetCapture();
-
- if (test != this)
- {
- captured = false;
- button_state = 0;
- dirty = true;
- }
-
- else
- {
- if (button_state == 1)
- {
- if (!rect.Contains(x,y))
- {
- button_state = 0;
- dirty = true;
- }
- }
- else
- {
- if (rect.Contains(x,y))
- {
- button_state = 1;
- dirty = true;
- }
- }
- }
- }
-
- return ActiveWindow::OnMouseMove(x,y);
+ bool dirty = false;
+
+ if (captured)
+ {
+ ActiveWindow* test = GetCapture();
+
+ if (test != this)
+ {
+ captured = false;
+ button_state = 0;
+ dirty = true;
+ }
+
+ else
+ {
+ if (button_state == 1)
+ {
+ if (!rect.Contains(x,y))
+ {
+ button_state = 0;
+ dirty = true;
+ }
+ }
+ else
+ {
+ if (rect.Contains(x,y))
+ {
+ button_state = 1;
+ dirty = true;
+ }
+ }
+ }
+ }
+
+ return ActiveWindow::OnMouseMove(x,y);
}
int ComboBox::OnLButtonDown(int x, int y)
{
- if (!captured)
- captured = SetCapture();
+ if (!captured)
+ captured = SetCapture();
- button_state = 1;
+ button_state = 1;
- return ActiveWindow::OnLButtonDown(x,y);
+ return ActiveWindow::OnLButtonDown(x,y);
}
int ComboBox::OnLButtonUp(int x, int y)
{
- if (captured) {
- ReleaseCapture();
- captured = 0;
- }
+ if (captured) {
+ ReleaseCapture();
+ captured = 0;
+ }
- button_state = -1;
- ShowList();
- Button::PlaySound(Button::SND_COMBO_OPEN);
- return ActiveWindow::OnLButtonUp(x,y);
+ button_state = -1;
+ ShowList();
+ Button::PlaySound(Button::SND_COMBO_OPEN);
+ return ActiveWindow::OnLButtonUp(x,y);
}
int ComboBox::OnClick()
{
- return ActiveWindow::OnClick();
+ return ActiveWindow::OnClick();
}
int ComboBox::OnMouseEnter(int mx, int my)
{
- if (button_state == 0)
- button_state = -1;
+ if (button_state == 0)
+ button_state = -1;
- return ActiveWindow::OnMouseEnter(mx, my);
+ return ActiveWindow::OnMouseEnter(mx, my);
}
int ComboBox::OnMouseExit(int mx, int my)
{
- if (button_state == -1)
- button_state = 0;
+ if (button_state == -1)
+ button_state = 0;
- return ActiveWindow::OnMouseExit(mx, my);
+ return ActiveWindow::OnMouseExit(mx, my);
}
// +--------------------------------------------------------------------+
void ComboBox::MoveTo(const Rect& r)
{
- ActiveWindow::MoveTo(r);
+ ActiveWindow::MoveTo(r);
- if (list) {
- delete list;
- list = 0;
- }
+ if (list) {
+ delete list;
+ list = 0;
+ }
}
void ComboBox::ShowList()
{
- if (!list) {
- list = new(__FILE__,__LINE__) ComboList(this, screen,
- rect.x, rect.y,
- rect.w, rect.h,
- items.size());
+ if (!list) {
+ list = new(__FILE__,__LINE__) ComboList(this, screen,
+ rect.x, rect.y,
+ rect.w, rect.h,
+ items.size());
- }
+ }
- if (list) {
- list->SetTextAlign(text_align);
- list->SetFont(font);
- list->SetText(text);
- list->SetSelection(seln);
- list->SetItems(items);
+ if (list) {
+ list->SetTextAlign(text_align);
+ list->SetFont(font);
+ list->SetText(text);
+ list->SetSelection(seln);
+ list->SetItems(items);
- list->Show();
- list_showing = true;
+ list->Show();
+ list_showing = true;
- EventDispatch* dispatch = EventDispatch::GetInstance();
- if (dispatch) {
- dispatch->MouseEnter(list);
- dispatch->SetFocus(list);
- }
+ EventDispatch* dispatch = EventDispatch::GetInstance();
+ if (dispatch) {
+ dispatch->MouseEnter(list);
+ dispatch->SetFocus(list);
+ }
- REGISTER_CLIENT(EID_CLICK, list, ComboBox, OnListSelect);
- REGISTER_CLIENT(EID_MOUSE_EXIT, list, ComboBox, OnListExit);
- }
+ REGISTER_CLIENT(EID_CLICK, list, ComboBox, OnListSelect);
+ REGISTER_CLIENT(EID_MOUSE_EXIT, list, ComboBox, OnListExit);
+ }
}
void ComboBox::HideList()
{
- if (list) {
- // These will be handled by the list window itself (i hope)
- UNREGISTER_CLIENT(EID_CLICK, list, ComboBox);
- UNREGISTER_CLIENT(EID_MOUSE_EXIT, list, ComboBox);
+ if (list) {
+ // These will be handled by the list window itself (i hope)
+ UNREGISTER_CLIENT(EID_CLICK, list, ComboBox);
+ UNREGISTER_CLIENT(EID_MOUSE_EXIT, list, ComboBox);
- list->Hide();
- list_showing = false;
- }
+ list->Hide();
+ list_showing = false;
+ }
}
// +--------------------------------------------------------------------+
void ComboBox::OnListSelect(AWEvent* event)
{
- if (list) {
- int new_seln = list->GetSelectedIndex();
-
- if (new_seln >= 0 && new_seln < items.size())
- seln = new_seln;
+ if (list) {
+ int new_seln = list->GetSelectedIndex();
+
+ if (new_seln >= 0 && new_seln < items.size())
+ seln = new_seln;
- HideList();
- OnSelect();
- Button::PlaySound(Button::SND_COMBO_SELECT);
- }
+ HideList();
+ OnSelect();
+ Button::PlaySound(Button::SND_COMBO_SELECT);
+ }
}
void ComboBox::OnListExit(AWEvent* event)
{
- //HideList();
- //Button::PlaySound(Button::SND_COMBO_CLOSE);
+ //HideList();
+ //Button::PlaySound(Button::SND_COMBO_CLOSE);
}
// +--------------------------------------------------------------------+
int ComboBox::NumItems()
{
- return items.size();
+ return items.size();
}
void ComboBox::ClearItems()
{
- items.destroy();
- seln = 0;
+ items.destroy();
+ seln = 0;
}
void ComboBox::AddItem(const char* item)
{
- Text* t = new(__FILE__,__LINE__) Text(item);
+ Text* t = new(__FILE__,__LINE__) Text(item);
- if (t) items.append(t);
+ if (t) items.append(t);
}
const char* ComboBox::GetItem(int index)
{
- if (index >= 0 && index < items.size())
- return items[index]->data();
- else
- return 0;
+ if (index >= 0 && index < items.size())
+ return items[index]->data();
+ else
+ return 0;
}
void ComboBox::SetItem(int index, const char* item)
{
- if (index >= 0 && index < items.size()) {
- *items[index] = item;
- }
-
- else {
- Text* t = new(__FILE__,__LINE__) Text(item);
- if (t)
- items.append(t);
- }
+ if (index >= 0 && index < items.size()) {
+ *items[index] = item;
+ }
+
+ else {
+ Text* t = new(__FILE__,__LINE__) Text(item);
+ if (t)
+ items.append(t);
+ }
}
void ComboBox::SetLabel(const char* label)
{
- SetText(label);
+ SetText(label);
}
int ComboBox::GetCount()
{
- return items.size();
+ return items.size();
}
const char* ComboBox::GetSelectedItem()
{
- if (seln >= 0 && seln < items.size())
- return items[seln]->data();
- else
- return 0;
+ if (seln >= 0 && seln < items.size())
+ return items[seln]->data();
+ else
+ return 0;
}
int ComboBox::GetSelectedIndex()
{
- if (seln >= 0 && seln < items.size())
- return seln;
- else
- return -1;
+ if (seln >= 0 && seln < items.size())
+ return seln;
+ else
+ return -1;
}
void ComboBox::SetSelection(int index)
{
- if (seln != index && index >= 0 && index < items.size()) {
- seln = index;
- }
+ if (seln != index && index >= 0 && index < items.size()) {
+ seln = index;
+ }
}
|