home *** CD-ROM | disk | FTP | other *** search
- package icontrols.DataList;
-
- import com.ms.ado.DataSource;
- import com.ms.dll.DllLib;
- import com.ms.wd.app.SystemInformation;
- import com.ms.wd.core.Event;
- import com.ms.wd.core.EventHandler;
- import com.ms.wd.ui.Bitmap;
- import com.ms.wd.ui.Brush;
- import com.ms.wd.ui.Color;
- import com.ms.wd.ui.Control;
- import com.ms.wd.ui.Font;
- import com.ms.wd.ui.Graphics;
- import com.ms.wd.ui.MouseEvent;
- import com.ms.wd.ui.MouseEventHandler;
- import com.ms.wd.ui.PaintEvent;
- import com.ms.wd.ui.Pen;
- import com.ms.wd.ui.Point;
- import com.ms.wd.ui.Rectangle;
- import com.ms.wd.ui.Screen;
- import com.ms.wd.util.Root;
- import com.ms.wd.win32.MOUSEHOOKSTRUCT;
- import com.ms.wd.win32.TEXTMETRIC;
- import com.ms.wd.win32.Windows;
- import icontrols.BorderDisplayer;
- import icontrols.StringDisplayer;
- import icontrols.Data.RecordsetProvider;
-
- public class DataCombo extends Control {
- private RecordsetProvider recordsetProvider = new RecordsetProvider();
- private ComboButton dropdownButton = new ComboButton();
- private ComboList comboList = new ComboList();
- private ComboEdit comboEdit = new ComboEdit();
- private ComboDropDown dropDown = new ComboDropDown();
- private StringDisplayer stringDisplayer = new StringDisplayer();
- private BorderDisplayer borderDisplayer = new BorderDisplayer();
- private int comboStyle = -1;
- private boolean comboEditDisplayed = false;
- private boolean comboListDisplayed = false;
- private boolean dropdownButtonDisplayed = false;
- private Rectangle clientRect = null;
- private boolean dropDownVisible = false;
- private String displayString = "";
- private boolean autoComplete = true;
- private Object currentSelection = null;
- private int mouseHookRoot = 0;
- private int mouseHookHandle = 0;
- // $FF: synthetic field
- private static Class class$com$ms$wd$win32$MOUSEHOOKSTRUCT;
-
- public void setListColumn(String column) {
- this.comboList.setListColumn(column);
- }
-
- public DataSource getRowSource() {
- return this.recordsetProvider.getDataSource();
- }
-
- private void setDisplayFromList() {
- String data = this.comboList.getDisplayData(this.comboList.getValue());
- this.displayString = data;
- if (this.comboStyle != 1) {
- this.comboEdit.setText(data);
- } else {
- ((Control)this).invalidate();
- }
-
- this.currentSelection = null;
- }
-
- public void setRowSource(DataSource dataSource) {
- this.comboList.setRowSource(dataSource);
- this.recordsetProvider.setDataSource(dataSource);
- }
-
- private void setupDropDownList() {
- this.dropDown.setComponent(this.comboList);
- }
-
- private void doDropdownListLayout() {
- Rectangle client = this.getCachedClientRect();
- int borderHeight = this.borderDisplayer.getBorderHeight();
- int borderWidth = this.borderDisplayer.getBorderWidth();
- ComboButton var10000 = this.dropdownButton;
- int var10001 = client.x + client.width - borderWidth - this.dropdownButton.getBounds().width;
- int var10002 = client.y + borderHeight;
- int var10004 = client.height - borderHeight * 2;
- ((Control)var10000).setBounds(var10001, var10002, this.dropdownButton.getBounds().width, var10004);
- }
-
- public int getStyle() {
- return this.comboStyle;
- }
-
- private void internalSetStyle(int style) {
- if (this.comboStyle != style) {
- boolean editDisplayed = false;
- boolean listDisplayed = false;
- boolean buttonDisplayed = false;
- switch (style) {
- case 0:
- editDisplayed = true;
- listDisplayed = false;
- buttonDisplayed = true;
- break;
- case 1:
- editDisplayed = false;
- listDisplayed = false;
- buttonDisplayed = true;
- break;
- case 2:
- editDisplayed = true;
- listDisplayed = true;
- buttonDisplayed = false;
- }
-
- if (this.comboEditDisplayed && !editDisplayed) {
- ((Control)this).remove(this.comboEdit);
- } else if (!this.comboEditDisplayed && editDisplayed) {
- ((Control)this).add(this.comboEdit);
- }
-
- if (this.comboListDisplayed && !listDisplayed) {
- this.comboList.setBorderStyle(0);
- this.setupDropDownList();
- ((Control)this).remove(this.comboList);
- } else if (!this.comboListDisplayed && listDisplayed) {
- this.comboList.setBorderStyle(2);
- this.clearDropDownList();
- ((Control)this).add(this.comboList);
- }
-
- if (this.dropdownButtonDisplayed && !buttonDisplayed) {
- this.dropdownButton.setVisible(false);
- ((Control)this).remove(this.dropdownButton);
- } else if (!this.dropdownButtonDisplayed && buttonDisplayed) {
- ((Control)this).add(this.dropdownButton);
- this.dropdownButton.setVisible(true);
- }
-
- this.comboStyle = style;
- this.dropdownButtonDisplayed = buttonDisplayed;
- this.comboListDisplayed = listDisplayed;
- this.comboEditDisplayed = editDisplayed;
- this.onResize(Event.EMPTY);
- }
- }
-
- public void setStyle(int style) {
- if (this.comboStyle != style) {
- this.internalSetStyle(style);
- }
-
- }
-
- private synchronized void hookMouseMessages() {
- this.mouseHookRoot = Root.alloc(new MouseHookProc(this));
- int[] i = new int[1];
- this.mouseHookHandle = Windows.SetWindowsHookEx(7, DllLib.addrOf(this.mouseHookRoot), Windows.GetModuleHandle((String)null), Windows.GetWindowThreadProcessId(((Control)this).getHandle(), i));
- }
-
- private void clearDropDownList() {
- this.hideDropdown();
- this.dropDown.setComponent((Control)null);
- }
-
- public void onParentChange(Object sender, Event event) {
- this.hideDropdown();
- }
-
- private void doSimpleComboLayout() {
- Rectangle client = this.getCachedClientRect();
- int borderHeight = this.borderDisplayer.getBorderHeight();
- int borderWidth = this.borderDisplayer.getBorderWidth();
- int height = this.computeEditHeight();
- int listHeight = -1;
- if (height > client.height - borderHeight * 2) {
- height = client.height - borderHeight * 2;
- } else {
- listHeight = client.height - height - 2;
- if (listHeight < 4) {
- height = client.height - borderHeight * 2;
- listHeight = -1;
- }
- }
-
- this.comboEdit.setBounds(client.x + borderWidth, client.y + borderHeight, client.width - borderWidth * 2, height - borderWidth * 2);
- if (listHeight >= 0) {
- this.comboList.setBounds(client.x, client.y + height + 2, client.width, listHeight);
- }
-
- }
-
- private int computeEditHeight() {
- Graphics g = ((Control)this).createGraphics();
- g.setFont(((Control)this).getFont());
- TEXTMETRIC tm = new TEXTMETRIC();
- Windows.GetTextMetrics(g.getHandle(), tm);
- int height = tm.tmHeight + 4 + 4;
- g.dispose();
- return height;
- }
-
- public String getBoundColumn() {
- return this.comboList.getBoundColumn();
- }
-
- protected void onResize(Event event) {
- this.hideDropdown();
- this.clientRect = null;
- this.doLayout();
- if (this.comboStyle != 2) {
- ((Control)this).invalidate();
- } else {
- int height = this.computeEditHeight();
- int borderHeight = this.borderDisplayer.getBorderHeight();
- if (height > this.getCachedClientRect().height - borderHeight * 2) {
- height = this.getCachedClientRect().height - borderHeight * 2;
- } else {
- height += 2;
- }
-
- ((Control)this).invalidateRect(new Rectangle(this.getCachedClientRect().x, this.getCachedClientRect().y, this.getCachedClientRect().width, height));
- }
-
- this.dropdownButton.invalidate();
- }
-
- public void setBoundColumn(String column) {
- this.comboList.setBoundColumn(column);
- }
-
- public void onButtonClick(Object sender, Event event) {
- if (this.dropDownVisible) {
- this.hideDropdown();
- } else {
- this.showDropdown();
- }
-
- }
-
- private void doLayout() {
- switch (this.comboStyle) {
- case 0:
- this.doDropdownComboLayout();
- break;
- case 1:
- this.doDropdownListLayout();
- break;
- case 2:
- this.doSimpleComboLayout();
- }
-
- }
-
- private void hideDropdown() {
- if (this.dropDown != null && this.comboStyle != 2 && this.dropDownVisible) {
- Windows.SetWindowPos(this.dropDown.getHandle(), 0, 0, 0, 0, 0, 407);
- this.dropDownVisible = false;
- ((Control)this).getParent().removeOnMove(new EventHandler(this, "onParentChange"));
- ((Control)this).getParent().removeOnResize(new EventHandler(this, "onParentChange"));
- this.comboList.setTrackSelection(false);
- if (this.comboStyle == 0) {
- this.comboEdit.removeOnLostFocus(new EventHandler(this, "onEditLostFocus"));
- }
-
- this.comboList.removeOnMouseUp(new MouseEventHandler(this, "onListMouseUp"));
- if (this.currentSelection != null) {
- this.recordsetProvider.getRecordset().move(0, this.currentSelection);
- }
-
- this.unhookMouseMessages();
- }
-
- }
-
- int mouseHookProc(int nCode, int wParam, int lParam) {
- if (nCode == 0) {
- int swap = Windows.GetSystemMetrics(23);
- int mouseWatch = 1;
- if (swap != 0) {
- mouseWatch = 2;
- }
-
- if ((Windows.GetAsyncKeyState(mouseWatch) & 'ΦÇÇ') != 0) {
- MOUSEHOOKSTRUCT mhs = (MOUSEHOOKSTRUCT)DllLib.ptrToStruct(class$com$ms$wd$win32$MOUSEHOOKSTRUCT != null ? class$com$ms$wd$win32$MOUSEHOOKSTRUCT : (class$com$ms$wd$win32$MOUSEHOOKSTRUCT = class$("com.ms.wd.win32.MOUSEHOOKSTRUCT")), lParam);
- if (mhs.hwnd != ((Control)this).getHandle() && mhs.hwnd != this.comboEdit.getHandle() && mhs.hwnd != this.dropdownButton.getHandle() && !this.comboList.isHandleOwnedByList(mhs.hwnd)) {
- this.hideDropdown();
- }
- }
- }
-
- return Windows.CallNextHookEx(this.mouseHookHandle, nCode, wParam, lParam);
- }
-
- public void onEditLostFocus(Object sender, Event event) {
- this.hideDropdown();
- }
-
- protected void onLostFocus(Event event) {
- this.hideDropdown();
- }
-
- private synchronized void unhookMouseMessages() {
- Windows.UnhookWindowsHookEx(this.mouseHookHandle);
- Root.free(this.mouseHookRoot);
- }
-
- public String getValue() {
- return this.comboList.getValue();
- }
-
- public void setValue(String value) {
- this.comboList.setValue(value);
- }
-
- public DataCombo() {
- ((Control)this).setBackColor(Color.WINDOW);
- this.borderDisplayer.setBorderStyle(18);
- this.stringDisplayer.setFont((Font)null);
- this.stringDisplayer.setForeColor((Color)null);
- this.stringDisplayer.setBackColor((Color)null);
- this.stringDisplayer.setAlignment(5);
- this.comboList.setBorderStyle(0);
- this.comboList.addValueChangedHandler(new EventHandler(this, "onListValueChanged"));
- this.comboEdit.setBorder(false);
- this.dropdownButton.addOnClick(new EventHandler(this, "onButtonClick"));
- this.dropdownButton.setBackColor(Color.CONTROL);
- this.buildDropDownArrow();
- this.setupDropDownList();
- this.internalSetStyle(0);
- ((Control)this).setBounds(0, 0, 121, 21);
- }
-
- public boolean getAutoComplete() {
- return this.autoComplete;
- }
-
- public void setAutoComplete(boolean autoComplete) {
- }
-
- public void onListMouseUp(Object sender, MouseEvent event) {
- this.hideDropdown();
- this.setDisplayFromList();
- }
-
- public String getRowMember() {
- return this.recordsetProvider.getDataMember();
- }
-
- protected void processEditChar(int key) {
- String pressed = new String(new char[]{(char)key});
- String newSearchString = null;
- int originalSelStart = this.comboEdit.getSelectionStart();
- String text = this.comboEdit.getText();
- if (text.length() > 0) {
- String selText = text.substring(this.comboEdit.getSelectionStart(), this.comboEdit.getSelectionEnd());
- String unselectedText = text.substring(0, originalSelStart);
- if (selText.length() > 1 && pressed.equalsIgnoreCase(selText.substring(0, 0))) {
- this.comboEdit.setSelectionStart(this.comboEdit.getSelectionStart() + 1);
- return;
- }
-
- newSearchString = unselectedText + pressed;
- } else {
- newSearchString = pressed;
- }
-
- String selected = this.comboList.selectByMatch(newSearchString);
- if (this.getAutoComplete() && selected != null) {
- this.comboEdit.setText(selected);
- this.comboEdit.setSelectionEnd(selected.length());
- if (originalSelStart < 1) {
- this.comboEdit.setSelectionStart(1);
- } else {
- this.comboEdit.setSelectionStart(newSearchString.length());
- }
- } else {
- this.comboEdit.setText(newSearchString);
- this.comboEdit.setSelectionEnd(newSearchString.length());
- this.comboEdit.setSelectionStart(newSearchString.length());
- }
-
- }
-
- public void setRowMember(String dataMember) {
- this.comboList.setRowMember(dataMember);
- this.recordsetProvider.setDataMember(dataMember);
- }
-
- private void buildDropDownArrow() {
- Bitmap bmp = new Bitmap(8, 8);
- Graphics g = bmp.getGraphics();
- g.setBrush(new Brush(Color.CONTROL));
- g.setPen((Pen)null);
- g.drawRect(new Rectangle(0, 0, 8, 8));
- g.setPen(new Pen(Color.CONTROLTEXT));
- int x = 3;
- int y = 5;
- g.setPixel(x, y);
-
- for(int i = 1; i < 4; ++i) {
- g.drawLine(x - i, y - i, x + i + 1, y - i);
- }
-
- g.dispose();
- this.dropdownButton.setStretch(false);
- this.dropdownButton.setImage(bmp);
- this.dropdownButton.setBounds(new Rectangle(0, 0, SystemInformation.getVertScrollBarWidth(), 1));
- }
-
- private void doDropdownComboLayout() {
- Rectangle client = this.getCachedClientRect();
- int borderHeight = this.borderDisplayer.getBorderHeight();
- int borderWidth = this.borderDisplayer.getBorderWidth();
- this.comboEdit.setBounds(client.x + borderWidth, client.y + borderHeight, client.width - borderWidth * 2 - this.dropdownButton.getBounds().width, client.height - borderHeight * 2);
- ComboButton var10000 = this.dropdownButton;
- int var10001 = client.x + client.width - borderWidth - this.dropdownButton.getBounds().width;
- int var10002 = client.y + borderHeight;
- int var10004 = client.height - borderHeight * 2;
- ((Control)var10000).setBounds(var10001, var10002, this.dropdownButton.getBounds().width, var10004);
- }
-
- public void onListValueChanged(Object sender, Event event) {
- this.setDisplayFromList();
- this.hideDropdown();
- }
-
- // $FF: synthetic method
- private static Class class$(String s) {
- try {
- return Class.forName(s);
- } catch (ClassNotFoundException e) {
- throw new NoClassDefFoundError(((Throwable)e).getMessage());
- }
- }
-
- private Rectangle getCachedClientRect() {
- if (this.clientRect == null) {
- this.clientRect = ((Control)this).getClientRect();
- }
-
- return this.clientRect;
- }
-
- protected void onMouseDown(MouseEvent event) {
- if (this.comboStyle == 1) {
- this.onButtonClick(this, event);
- }
-
- }
-
- private void showDropdown() {
- if (this.dropDown != null && this.comboStyle != 2) {
- Rectangle client = new Rectangle(this.getCachedClientRect());
- Rectangle screen = Screen.fromControl(this).workingArea;
- int comboHeight = client.height;
- Point loc = ((Control)this).pointToScreen(new Point(0, 0));
- client.y += loc.y;
- client.x += loc.x;
- client.y += comboHeight;
- client.height *= 4;
- if (client.y + client.height > screen.y + screen.height) {
- client.y -= client.height + comboHeight;
- }
-
- this.dropDown.setFont(((Control)this).getFont());
- this.dropDown.setBackColor(((Control)this).getBackColor());
- this.dropDown.setForeColor(((Control)this).getForeColor());
- Windows.SetWindowPos(this.dropDown.getHandle(), -1, client.x, client.y, client.width, client.height, 336);
- this.dropDown.setVisible(true);
- this.comboList.setTrackSelection(true);
- ((Control)this).getParent().addOnMove(new EventHandler(this, "onParentChange"));
- ((Control)this).getParent().addOnResize(new EventHandler(this, "onParentChange"));
- if (this.comboStyle == 0) {
- this.comboEdit.focus();
- this.comboEdit.addOnLostFocus(new EventHandler(this, "onEditLostFocus"));
- }
-
- this.comboList.addOnMouseUp(new MouseEventHandler(this, "onListMouseUp"));
- if (this.recordsetProvider.getRecordset() != null) {
- this.currentSelection = this.recordsetProvider.getRecordset().getBookmark();
- }
-
- this.hookMouseMessages();
- this.dropDownVisible = true;
- }
-
- }
-
- protected void onPaint(PaintEvent pe) {
- int borderHeight = this.borderDisplayer.getBorderHeight();
- int borderWidth = this.borderDisplayer.getBorderWidth();
- if (this.comboStyle != 2) {
- this.borderDisplayer.paintIn(pe.graphics, this.getCachedClientRect(), pe.clipRect);
- } else {
- Rectangle top = new Rectangle(this.getCachedClientRect());
- int height = this.computeEditHeight();
- if (height > this.getCachedClientRect().height - borderHeight * 2) {
- height = this.getCachedClientRect().height - borderHeight * 2;
- } else {
- top.y += height;
- top.height = 2;
- pe.graphics.setBrush(new Brush(Color.CONTROL));
- pe.graphics.setPen((Pen)null);
- pe.graphics.drawRect(top);
- top.y -= height;
- }
-
- top.height = height;
- this.borderDisplayer.paintIn(pe.graphics, top, pe.clipRect);
- }
-
- if (this.comboStyle == 1) {
- Rectangle bounds = new Rectangle(this.getCachedClientRect());
- bounds.inflateRect(-1 * (borderWidth + 1), -1 * borderHeight);
- this.stringDisplayer.paintIn(pe.graphics, bounds, pe.clipRect, this.displayString);
- }
-
- }
-
- public String getListColumn() {
- return this.comboList.getListColumn();
- }
- }
-