Example #1
0
void MGuiEditText::onEvent(MWinEvent * windowEvent)
{
	MGuiWindow * parent = getParentWindow();

	MMouse * mouse = MMouse::getInstance();

	switch(windowEvent->type)
	{
	case MWIN_EVENT_MOUSE_WHEEL_MOVE:
	case MWIN_EVENT_MOUSE_MOVE:
		if(parent->isHighLight() && isMouseInside())
		{
			setHighLight(true);

			if(m_pointerEvent) // send mouse move gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_MOVE;
				guiEvent.data[0] = windowEvent->data[0];
				guiEvent.data[1] = windowEvent->data[1];

				m_pointerEvent(this, &guiEvent);
			}

			// break events
			if(parent->breakEvents())
				return;
		}
		else
		{
			setHighLight(false);
		}

		if(isPressed() && mouse->isLeftButtonPushed())
		{
			m_endSelectionId = getFont()->findPointedCharacter(
				getText(),
				getPosition(),
				getTextSize(),
				getMouseLocalPosition()
			);

			autoScrolling();
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_DOWN:
		if(isHighLight())
		{
			if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
			{
				// unpress all edit text
				unsigned int i;
				unsigned int size = parent->getEditTextsNumber();
				for(i=0; i<size; i++)
					parent->getEditText(i)->setPressed(false);

				setPressed(true);

				setCharId(
					getFont()->findPointedCharacter(
						getText(),
						getPosition(),
						getTextSize(),
						getMouseLocalPosition()
					)
				);

				// start select
				setSelection(getCharId(), getCharId());
			}

			if(m_pointerEvent) // send mouse button down gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_DOWN;
				guiEvent.data[0] = windowEvent->data[0];

				m_pointerEvent(this, &guiEvent);
			}
		}
		else
		{
			if(isPressed() && windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
			{
				setPressed(false);
				sendVariable();
			}
		}
		break;
	case MWIN_EVENT_CHAR:
	case MWIN_EVENT_KEY_DOWN:
		if(isPressed())
		{
			editText(windowEvent);
			autoScrolling();
		}
		break;
	}
}
Example #2
0
EditServerDialog::EditServerDialog(ServerDialog *parent, ServerInfo server,
                                   int index) :
    Window(_("Edit Server"), true, parent),
    mServerDialog(parent),
    mServer(server),
    mIndex(index)
{
    setWindowName("EditServerDialog");

    Label *nameLabel = new Label(_("Name:"));
    Label *serverAdressLabel = new Label(_("Address:"));
    Label *portLabel = new Label(_("Port:"));
    Label *typeLabel = new Label(_("Server type:"));
    Label *descriptionLabel = new Label(_("Description:"));
    mServerAddressField = new TextField(std::string());
    mPortField = new TextField(std::string());
    mPortField->setNumeric(true);
    mPortField->setRange(1, 65535);

    mTypeListModel = new TypeListModel();
    mTypeField = new DropDown(mTypeListModel);
    mTypeField->setSelected(0); // TmwAthena by default for now.

    mNameField = new TextField(std::string());
    mDescriptionField = new TextField(std::string());

    mOkButton = new Button(_("OK"), "addServer", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);

    mServerAddressField->addActionListener(this);
    mPortField->addActionListener(this);

    place(0, 0, nameLabel);
    place(1, 0, mNameField, 4).setPadding(3);
    place(0, 1, serverAdressLabel);
    place(1, 1, mServerAddressField, 4).setPadding(3);
    place(0, 2, portLabel);
    place(1, 2, mPortField, 4).setPadding(3);
    place(0, 3, typeLabel);
    place(1, 3, mTypeField).setPadding(3);
    place(0, 4, descriptionLabel);
    place(1, 4, mDescriptionField, 4).setPadding(3);
    place(4, 5, mOkButton);
    place(3, 5, mCancelButton);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 0, height = 0;
    getLayout().reflow(width, height);
    if (width < 300)
    {
        width = 300;
        getLayout().reflow(width, height);
    }
    if (height < 120)
    {
        height = 120;
        getLayout().reflow(width, height);
    }

    setContentSize(width, height);

    setMinWidth(getWidth());
    setMinHeight(getHeight());
    setDefaultSize(getWidth(), getHeight(), ImageRect::CENTER);

    setResizable(false);
    addKeyListener(this);

    loadWindowState();

    mNameField->setText(mServer.name);
    mDescriptionField->setText(mServer.description);
    mServerAddressField->setText(mServer.hostname);
    mPortField->setText(toString(mServer.port));

    switch (mServer.type)
    {
#ifdef EATHENA_SUPPORT
        case ServerInfo::EATHENA:
            mTypeField->setSelected(2);
            break;
        case ServerInfo::MANASERV:
#ifdef MANASERV_SUPPORT
            mTypeField->setSelected(3);
            break;
#endif
#else
        case ServerInfo::MANASERV:
#ifdef MANASERV_SUPPORT
            mTypeField->setSelected(2);
            break;
#endif
#endif
        default:
        case ServerInfo::UNKNOWN:
        case ServerInfo::TMWATHENA:
            mTypeField->setSelected(0);
            break;
        case ServerInfo::EVOL:
            mTypeField->setSelected(1);
            break;
    }

    setLocationRelativeTo(getParentWindow());
    setVisible(true);

    mNameField->requestFocus();
}
Example #3
0
bool UserPropertiesHandler::handleURI(URI& uri)
{
    bool addUser = uri.action == "add_user";
    bool editUser = uri.action == "edit_user";
    if (!addUser && !editUser)
        return false;

    wxWindow* w = getParentWindow(uri);
    ServerPtr server;
    UserPtr user;
    wxString title(_("Modify User"));
    if (addUser)
    {
        server = extractMetadataItemPtrFromURI<Server>(uri);
        if (!server)
            return true;
        title = _("Create New User");
        user.reset(new User(server));
    }
    else
    {
        user = extractMetadataItemPtrFromURI<User>(uri);
        if (!user)
            return true;
#ifdef __WXGTK__
        if (user->getUsername() == "SYSDBA")
        {
            showWarningDialog(w, _("The password for the SYSDBA user should not be changed here."),
                _("The appropriate way to change the password of the SYSDBA user is to run the changeDBAPassword.sh script in Firebird's bin directory.\n\nOtherwise the scripts will not be updated."),
                AdvancedMessageDialogButtonsOk(), config(), "DIALOG_warn_sysdba_change",
                _("Do not show this information again"));
        }
#endif
        server = user->getServer();
        if (!server)
            return true;
    }

    UserDialog d(w, title, addUser);
    d.setUser(user);
    if (d.ShowModal() == wxID_OK)
    {
        ProgressDialog pd(w, _("Connecting to Server..."), 1);
        pd.doShow();
        IBPP::Service svc;
        if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password
            return true;

        try
        {
            IBPP::User u;
            user->assignTo(u);
            if (addUser)
                svc->AddUser(u);
            else
                svc->ModifyUser(u);
            server->notifyObservers();
        }
        catch(IBPP::Exception& e)
        {
            wxMessageBox(e.what(), _("Error"),
                wxOK | wxICON_WARNING);
        }
    }
    return true;
}
Example #4
0
EditServerDialog::EditServerDialog(ServerDialog *const parent,
                                   ServerInfo server,
                                   const int index) :
    // TRANSLATORS: edit server dialog name
    Window(_("Edit Server"), Modal_true, parent),
    ActionListener(),
    KeyListener(),
    mServerAddressField(new TextField(this, std::string())),
    mPortField(new TextField(this, std::string())),
    mNameField(new TextField(this, std::string())),
    mDescriptionField(new TextField(this, std::string())),
    mOnlineListUrlField(new TextField(this, std::string())),
    mPacketVersionField(new IntTextField(this, 0, 0, maxPacketVersion)),
    // TRANSLATORS: edit server dialog button
    mConnectButton(new Button(this, _("Connect"), "connect", this)),
    // TRANSLATORS: edit server dialog button
    mOkButton(new Button(this, _("OK"), "addServer", this)),
    // TRANSLATORS: edit server dialog button
    mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
    // TRANSLATORS: edit server dialog label
    mPersistentIp(new CheckBox(this, _("Use same ip"),
                  true, this, "persistentIp")),
    mTypeListModel(new TypeListModel),
    mTypeField(new DropDown(this, mTypeListModel, false, Modal_true)),
    mServerDialog(parent),
    mServer(server),
    mIndex(index)
{
    setWindowName("EditServerDialog");

    // TRANSLATORS: edit server dialog label
    Label *const nameLabel = new Label(this, _("Name:"));
    // TRANSLATORS: edit server dialog label
    Label *const serverAdressLabel = new Label(this, _("Address:"));
    // TRANSLATORS: edit server dialog label
    Label *const portLabel = new Label(this, _("Port:"));
    // TRANSLATORS: edit server dialog label
    Label *const typeLabel = new Label(this, _("Server type:"));
    // TRANSLATORS: edit server dialog label
    Label *const descriptionLabel = new Label(this, _("Description:"));
    // TRANSLATORS: edit server dialog label
    Label *const onlineListUrlLabel = new Label(this, _("Online list url:"));
    // TRANSLATORS: edit server dialog label
    Label *const packetVersionLabel = new Label(this, _("Packet version:"));
    mPortField->setNumeric(true);
    mPortField->setRange(1, 65535);

    mTypeField->setSelected(0);  // TmwAthena by default

    mServerAddressField->addActionListener(this);
    mPortField->addActionListener(this);

    place(0, 0, nameLabel);
    place(1, 0, mNameField, 4).setPadding(3);
    place(0, 1, serverAdressLabel);
    place(1, 1, mServerAddressField, 4).setPadding(3);
    place(0, 2, portLabel);
    place(1, 2, mPortField, 4).setPadding(3);
    place(0, 3, typeLabel);
    place(1, 3, mTypeField).setPadding(3);
    place(0, 4, descriptionLabel);
    place(1, 4, mDescriptionField, 4).setPadding(3);
    place(0, 5, onlineListUrlLabel);
    place(1, 5, mOnlineListUrlField, 4).setPadding(3);
    place(0, 6, packetVersionLabel);
    place(1, 6, mPacketVersionField, 4).setPadding(3);
    place(0, 7, mPersistentIp, 4).setPadding(3);
    place(0, 8, mConnectButton);
    place(4, 8, mOkButton);
    place(3, 8, mCancelButton);

    // Do this manually instead of calling reflowLayout so we can enforce a
    // minimum width.
    int width = 0;
    int height = 0;
    getLayout().reflow(width, height);
    if (width < 300)
    {
        width = 300;
        getLayout().reflow(width, height);
    }
    if (height < 120)
    {
        height = 120;
        getLayout().reflow(width, height);
    }

    setContentSize(width, height);

    setMinWidth(getWidth());
    setMinHeight(getHeight());
    setDefaultSize(getWidth(), getHeight(), ImagePosition::CENTER);

    setResizable(false);
    addKeyListener(this);

    loadWindowState();

    mNameField->setText(mServer.name);
    mDescriptionField->setText(mServer.description);
    mOnlineListUrlField->setText(mServer.onlineListUrl);
    mServerAddressField->setText(mServer.hostname);
    mPacketVersionField->setValue(mServer.packetVersion);
    mPortField->setText(toString(mServer.port));
    mPersistentIp->setSelected(mServer.persistentIp);

    switch (mServer.type)
    {
        case ServerType::EATHENA:
#ifdef TMWA_SUPPORT
            mTypeField->setSelected(1);
#else   // TMWA_SUPPORT
            mTypeField->setSelected(0);
#endif  // TMWA_SUPPORT
            break;
        default:
        case ServerType::UNKNOWN:
        case ServerType::TMWATHENA:
            mTypeField->setSelected(0);
            break;
        case ServerType::EVOL2:
#ifdef TMWA_SUPPORT
            mTypeField->setSelected(2);
#else   // TMWA_SUPPORT
            mTypeField->setSelected(1);
#endif  // TMWA_SUPPORT
            break;
    }

    setLocationRelativeTo(getParentWindow());
}
Example #5
0
void MGuiSlide::onEvent(MWinEvent * windowEvent)
{
	MGuiWindow * parent = getParentWindow();

	MMouse * mouse = MMouse::getInstance();

	switch(windowEvent->type)
	{
	case MWIN_EVENT_MOUSE_WHEEL_MOVE:
	case MWIN_EVENT_MOUSE_MOVE:
		if(parent->isHighLight() && m_button.isPointInside(getMouseLocalPosition()) && (! mouse->isLeftButtonPushed()) && (! mouse->isMiddleButtonPushed()) && (! mouse->isRightButtonPushed()))
		{
			setHighLight(true);

			if(m_pointerEvent) // send gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_MOVE;
				guiEvent.data[0] = windowEvent->data[0];
				guiEvent.data[1] = windowEvent->data[1];

				m_pointerEvent(this, &guiEvent);
			}

			// break events
			if(parent->breakEvents())
				return;
		}
		else{
			setHighLight(false);
		}

		if(isPressed())
		{
			float value = getValueFromPoint(getMouseLocalPosition());
			setValue(value);
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_DOWN:
		if(isHighLight())
		{
			if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT){
				setPressed(true);
				m_offset = getMouseLocalPosition() - m_button.getPosition();
			}

			if(m_pointerEvent) // send gui event
			{
				MGuiEvent guiEvent;

				guiEvent.type = MGUI_EVENT_MOUSE_BUTTON_DOWN;
				guiEvent.data[0] = windowEvent->data[0];

				m_pointerEvent(this, &guiEvent);
			}
		}
		break;
	case MWIN_EVENT_MOUSE_BUTTON_UP:
		if(windowEvent->data[0] == MMOUSE_BUTTON_LEFT)
		{
			setPressed(false);
		}
		break;
	}
}
Example #6
0
bool DatabaseInfoHandler::handleURI(URI& uri)
{
    bool isEditSweep, isEditForcedWrites, isEditReserve, isEditReadOnly,
        isEditPageBuffers;

    isEditSweep = (uri.action == "edit_db_sweep_interval");
    isEditForcedWrites = (uri.action == "edit_db_forced_writes");
    isEditReserve = (uri.action == "edit_db_reserve_space");
    isEditReadOnly = (uri.action == "edit_db_read_only");
    isEditPageBuffers = (uri.action == "edit_db_page_buffers");

    if (!isEditSweep && !isEditForcedWrites && !isEditReserve
        && !isEditReadOnly && !isEditPageBuffers)
    {
        return false;
    }

    DatabasePtr d = extractMetadataItemPtrFromURI<Database>(uri);
    wxWindow* w = getParentWindow(uri);

    // when either the database or the window does not exist
    // return immediately. Because this function returns whether
    // the specified uri is handled, return true.
    if (!d || !w || !d->isConnected())
         return true;

    IBPP::Database& db = d->getIBPPDatabase();
    IBPP::Service svc = IBPP::ServiceFactory(
        wx2std(d->getServer()->getConnectionString()),
        db->Username(), db->UserPassword());
    svc->Connect();

    if (isEditSweep || isEditPageBuffers)
    {
        long oldValue = 0;
        wxString title, label;
        if (isEditSweep)
        {
            oldValue = d->getInfo().getSweep();
            title = _("Enter the new Sweep Interval");
            label = _("Sweep Interval"); 
        }
        else if (isEditPageBuffers)
        {
            oldValue = d->getInfo().getBuffers();
            title = _("Enter the new value for Page Buffers");
            label = _("Page Buffers"); 
        }

        while (true)
        {
            wxString s;
            long value = oldValue;
            s = ::wxGetTextFromUser(title, label,
                wxString::Format("%d", value), w);

            // return from the iteration when the entered string is empty, in
            // case of cancelling the operation.
            if (s.IsEmpty())
                break;
            if (!s.ToLong(&value))
                continue;
            // return from the iteration when the interval has not changed
            if (value == oldValue)
                break;

            if (isEditSweep)
                svc->SetSweepInterval(wx2std(d->getPath()), value);
            else if (isEditPageBuffers)
                svc->SetPageBuffers(wx2std(d->getPath()), value);

            // Before reloading the info, re-attach to the database
            // otherwise the sweep interval won't be changed for FB Classic
            // Server.
            db->Disconnect();
            db->Connect();
            d->loadInfo();
            break;
        }
    }

    else if (isEditForcedWrites || isEditReserve || isEditReadOnly)
    {
        bool fw = !d->getInfo().getForcedWrites();
        bool reserve = !d->getInfo().getReserve();
        bool ro = !d->getInfo().getReadOnly();

        // setting these properties requires that the database is
        // disconnected.
        db->Disconnect();

        if (isEditForcedWrites)
            svc->SetSyncWrite(wx2std(d->getPath()), fw);
        if (isEditReserve)
            svc->SetReserveSpace(wx2std(d->getPath()), reserve);
        if (isEditReadOnly)
            svc->SetReadOnly(wx2std(d->getPath()), ro);

        db->Connect();

        // load the database info because the info values are changed.
        d->loadInfo();
    }

    svc->Disconnect();
    return true;
}
Example #7
0
void MenuItem::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if((whichField & EnabledFieldMask) &&
        getParentWindow() != NULL &&
        !getEnabled() && 
        getAcceleratorKey() != KeyEventDetails::KEY_NONE)
    {
        _AcceleratorTypedConnection.disconnect();
    }

    if(whichField & TextFieldMask ||
	   whichField & AcceleratorKeyFieldMask ||
       whichField & AcceleratorModifiersFieldMask)
    {
        updateAcceleratorText();
    }
    if(whichField & TextFieldMask ||
       whichField & MnemonicKeyFieldMask)
    {
        Int32 Pos(-1);
        if(getMnemonicKey() != KeyEventDetails::KEY_NONE &&
           getText() != "")
        {
            //Get the Character representation of the key
            UChar8 MnemonicCharLower(KeyEventDetails::getCharFromKey(static_cast<KeyEventDetails::Key>(getMnemonicKey()),0));
            UChar8 MnemonicCharUpper(KeyEventDetails::getCharFromKey(static_cast<KeyEventDetails::Key>(getMnemonicKey()),KeyEventDetails::KEY_MODIFIER_CAPS_LOCK));
            
            //Find the first occurance of this character in the text case-insensitive
            std::string::size_type MnemonicCharLowerPos;
            std::string::size_type MnemonicCharUpperPos;
            MnemonicCharLowerPos = getText().find_first_of(MnemonicCharLower);
            MnemonicCharUpperPos = getText().find_first_of(MnemonicCharUpper);

            if(MnemonicCharLowerPos == std::string::npos)
            {
                if(MnemonicCharUpperPos == std::string::npos)
                {
                    Pos = -1;
                }
                else
                {
                    Pos = MnemonicCharUpperPos;
                }
            }
            else
            {
                if(MnemonicCharUpperPos == std::string::npos)
                {
                    Pos = MnemonicCharLowerPos;
                }
                else
                {
                    Pos = osgMin(MnemonicCharLowerPos, MnemonicCharUpperPos);
                }
            }

			//Update Parent Menu
			if(getParentContainer() != NULL)
			{
				getParentContainer()->updateLayout();
			}
        }
        
        _MnemonicTextPosition =Pos;
    }
}
void RotatedComponent::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if(whichField & InternalComponentFieldMask)
    {
            clearChildren();
            if(getInternalComponent() != NULL)
            {
                pushToChildren(getInternalComponent());
            }
    }
        
    if((whichField & InternalComponentFieldMask) ||
       (whichField & AngleFieldMask) || 
       (whichField & ResizePolicyFieldMask))
    {
        if(getInternalComponent() != NULL)
        {
            Vec2f Size;
            switch (static_cast<ResizePolicy>(getResizePolicy()))
            {
            case RESIZE_TO_MIN:
                {
                    //Treat TopLeft as 0,0
                    //Get the Rotated Bounds of the Internal Component
                    Pnt2f p1,p2,p3,p4;

                    Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0);

                    p1 = -ComponentCenter;
                    p2.setValues(ComponentCenter.x(),-ComponentCenter.y());
                    p3 = ComponentCenter;
                    p4.setValues(-ComponentCenter.x(),ComponentCenter.y());

                    //Rotate them
                    p1 = Rotate(p1, -getAngle());
                    p2 = Rotate(p2, -getAngle());
                    p3 = Rotate(p3, -getAngle());
                    p4 = Rotate(p4, -getAngle());

                    //Get their min and max
                    Pnt2f Min(osgMin(osgMin(osgMin(p1.x(),p2.x()),p3.x()),p4.x()),
                              osgMin(osgMin(osgMin(p1.y(),p2.y()),p3.y()),p4.y()));
                    Pnt2f Max(osgMax(osgMax(osgMax(p1.x(),p2.x()),p3.x()),p4.x()),
                              osgMax(osgMax(osgMax(p1.y(),p2.y()),p3.y()),p4.y()));
                    
	                Pnt2f BorderTopLeft, BorderBottomRight;
	                getInsideInsetsBounds(BorderTopLeft, BorderBottomRight);
	                Pnt2f TopLeft, BottomRight;
	                getBounds(TopLeft, BottomRight);
                    
                        setPreferredSize(Vec2f(Max.x() - Min.x() + (BorderTopLeft.x() - TopLeft.x()) + (BottomRight.x() - BorderBottomRight.x()),
                                               Max.y() - Min.y() + (BorderTopLeft.y() - TopLeft.y()) + (BottomRight.y() - BorderBottomRight.y())));
                    break;
                }
            case RESIZE_TO_MAX:
                {
                    //Get the Internal Components Center
                    Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0);
                    //Get the distance from the Center to one of the TopLeft Corner
                    Real32 Length = 2*ComponentCenter.dist(Pnt2f(0,0));
                    
                        setPreferredSize(Vec2f(Length,Length));
                    break;
                }
            case NO_RESIZING:
            default:
                break;
            }
            getInternalComponent()->updateClipBounds();

			//Check the Mouse
			if( getParentWindow() != NULL &&
				getParentWindow()->getParentDrawingSurface() != NULL &&
				getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL)
			{
				Pnt2f MouseLoc(getParentWindow()->getParentDrawingSurface()->getEventProducer()->getMousePosition());
				MouseEventDetailsUnrecPtr e = MouseEventDetails::create(getParentWindow()->getParentDrawingSurface()->getEventProducer(),getSystemTime(),MouseEventDetails::NO_BUTTON,0,MouseLoc, NULL);
				checkMouseEnterExit(e,e->getLocation(),getInternalComponent(),getInternalComponent()->isContained(MouseLoc, true),e->getViewport());
			}
        }
    }
}
Example #9
0
void SplitPanel::dividerDragCancel(void)
{
    _DragMouseDraggedConnection.disconnect();
    _DragMouseReleasedConnection.disconnect();
    getParentWindow()->getParentDrawingSurface()->getEventProducer()->setLockCursor(false);
}
Example #10
0
ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item,
                                   int maxRange):
    Window("", true, parent),
    mItem(item),
    mMax(maxRange),
    mUsage(usage)
{
    if (!mMax)
        mMax = mItem->getQuantity();

    // Save keyboard state
    mEnabledKeyboard = keyboard.isEnabled();
    keyboard.setEnabled(false);

    // Integer field
    mItemAmountTextField = new IntTextField(1);
    mItemAmountTextField->setRange(1, mMax);
    mItemAmountTextField->setWidth(35);
    mItemAmountTextField->addKeyListener(this);

    // Slider
    mItemAmountSlide = new Slider(1.0, mMax);
    mItemAmountSlide->setHeight(10);
    mItemAmountSlide->setActionEventId("slide");
    mItemAmountSlide->addActionListener(this);

    //Item icon
    Image *image = item->getImage();
    mItemIcon = new Icon(image);

    // Buttons
    Button *minusButton = new Button(_("-"), "dec", this);
    Button *plusButton = new Button(_("+"), "inc", this);
    Button *okButton = new Button(_("OK"), "ok", this);
    Button *cancelButton = new Button(_("Cancel"), "cancel", this);
    Button *addAllButton = new Button(_("All"), "all", this);

    minusButton->adjustSize();
    minusButton->setWidth(plusButton->getWidth());

    // Set positions
    ContainerPlacer place;
    place = getPlacer(0, 0);
    place(1, 0, minusButton);
    place(2, 0, mItemAmountTextField);
    place(3, 0, plusButton);
    place(4, 0, addAllButton);

    place(0, 0, mItemIcon, 1, 3);
    place(1, 1, mItemAmountSlide, 5);

    place(4, 2, cancelButton);
    place(5, 2, okButton);

    reflowLayout(225, 0);

    resetAmount();

    switch (usage)
    {
        case TradeAdd:
            setCaption(_("Select amount of items to trade."));
            break;
        case ItemDrop:
            setCaption(_("Select amount of items to drop."));
            break;
        case StoreAdd:
            setCaption(_("Select amount of items to store."));
            break;
        case StoreRemove:
            setCaption(_("Select amount of items to retrieve."));
            break;
        case ItemSplit:
            setCaption(_("Select amount of items to split."));
            break;
    }

    setLocationRelativeTo(getParentWindow());
    setVisible(true);

    mItemPopup = new ItemPopup;
    mItemIcon->addMouseListener(this);
}
void TextDomArea::keyTyped(KeyEventDetails* const details)
{
	DocumentElementAttribute temp;
	_CurrentCaretBlinkElps=0;
	_DrawCaret = true;

    switch(details->getKey())
    {
    case KeyEventDetails::KEY_UP:
        getLayoutManager()->moveTheCaret(UP,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_DOWN:
        getLayoutManager()->moveTheCaret(DOWN,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_LEFT:
	    getLayoutManager()->moveTheCaret(LEFT,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_RIGHT:
        getLayoutManager()->moveTheCaret(RIGHT,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_PAGE_UP:
        getLayoutManager()->moveTheCaret(PAGEUP,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_PAGE_DOWN:
        getLayoutManager()->moveTheCaret(PAGEDOWN,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_BACK_SPACE:
	    if(getLayoutManager()->isSomethingSelected())
	    {
		    deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected();
	    }
	    else
	    {
		    if(getLayoutManager()->getCaretLine()!=0 || getLayoutManager()->getCaretIndex()!=0)
		    {
			    getLayoutManager()->moveTheCaret(LEFT,false,false);
			    deleteCharacterUsingCommandManager();//getDocumentModel()->deleteCharacter(getLayoutManager()->getCaretLine(),getLayoutManager()->getCaretIndex());
		    }
	    }
        break;
	case KeyEventDetails::KEY_DELETE:
	    if(getLayoutManager()->isSomethingSelected())
	    {
		    deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected();
	    }
	    else
	    {
		    deleteCharacterUsingCommandManager();//getDocumentModel()->deleteCharacter(getLayoutManager()->getCaretLine(),getLayoutManager()->getCaretIndex());
	    }
        break;
	case KeyEventDetails::KEY_ENTER:
	    if(getLayoutManager()->isSomethingSelected())
	    {
		    deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected();
	    }
	    insertCharacterUsingCommandManager('\n',-1,-1);
        break;
	case KeyEventDetails::KEY_HOME:
	    getLayoutManager()->moveTheCaret(HOME,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_END:
	    getLayoutManager()->moveTheCaret(END,(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT),(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL));
        break;
	case KeyEventDetails::KEY_TAB:
	    tabHandler(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT);
        break;
    default:
	    if(isPrintableChar(details->getKeyChar()) || details->getKey() == KeyEventDetails::KEY_SPACE)
	    {
		    if(details->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL)
		    {
                switch(details->getKey())
                {

                case KeyEventDetails::KEY_A:
				    getLayoutManager()->selectAll();
                    break;
			    case KeyEventDetails::KEY_C:
			        {
				        std::string stringToTheClipboard = getHighlightedString();
				        getParentWindow()->getParentDrawingSurface()->getEventProducer()->putClipboard(stringToTheClipboard);
                        break;
			        }
			    case KeyEventDetails::KEY_V:
			        {
				        std::string theClipboard = getParentWindow()->getParentDrawingSurface()->getEventProducer()->getClipboard();
				        handlePastingAString(theClipboard);
                        break;
			        }
			    case KeyEventDetails::KEY_Z:
				    if(_TheUndoManager->canUndo())
				    {
					    _TheUndoManager->undo();
				    }
                    break;
			    case KeyEventDetails::KEY_Y:
				    if(_TheUndoManager->canRedo())
				    {
					    _TheUndoManager->redo();
				    }
                    break;
			    }
		    }
		    else
		    {
			    if(getLayoutManager()->isSomethingSelected())
			    {
				    deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected();
			    }
			    if(getLayoutManager()->isStartingBraces(details->getKeyChar()))
			    {
				    getLayoutManager()->removeBracesHighlightIndices();
				    getLayoutManager()->setStartingBraces(details->getKeyChar(),getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine());
			    }
			    else if(getLayoutManager()->isEndingBraces(details->getKeyChar()))
			    {
				    getLayoutManager()->removeBracesHighlightIndices();
				    getLayoutManager()->setEndingBraces(details->getKeyChar(),getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine());
			    }
			    insertCharacterUsingCommandManager(details->getKeyChar(),-1,-1);

			    /*getDocumentModel()->insertCharacter(getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine(),details->getKeyChar(),temp);
			    getLayoutManager()->moveTheCaret(RIGHT,false,false);
			    getLayoutManager()->DoIfLineLongerThanPreferredSize();*/
		    }
	    }
        break;
    }
}
void Component::moveFocus(Int32 MoveAmount)
{
    //Follow a depth first search of Components that are isFocusInteractable 
    ComponentUnrecPtr ComponentToFocus = ComponentUnrecPtr(this);
    if(MoveAmount > 0)
    {
        //Focus forward the given amount
        for(Int32 i(0) ; i<MoveAmount ; ++i)
        {
            //Find the next component that is Focus Interactable
            do
            {
                ComponentToFocus = ComponentToFocus->getNextDepthFirstComponent();
            }while(ComponentToFocus != NULL &&               //None found
                   ComponentToFocus != this &&               //Looped back to this component
                   !ComponentToFocus->isFocusInteractable());

            //Has the Depth first order reached the end
            if(ComponentToFocus == NULL &&
               getParentWindow() != NULL)
            {
                ComponentToFocus = getParentWindow()->getLeftmostDecendent();
            }

            //Is the focus allowed to go here
            ComponentContainer* ParentTest(getParentContainer());
            while(ParentTest != NULL &&
                  !ParentTest->isDecendent(ComponentToFocus))
            {
                if(!ParentTest->allowFocusToLeave())
                {
                    //Change the focus to the first child of this parent
                    ComponentToFocus = ParentTest->getLeftmostDecendent();
                    break;
                }
                ParentTest = ParentTest->getParentContainer();
            }
        }
    }
    else if(MoveAmount < 0)
    {
        //Focus backward the given amount
        for(Int32 i(0) ; i>MoveAmount ; --i)
        {
            //Find the next component that is Focus Interactable
            do
            {
                ComponentToFocus = ComponentToFocus->getPrevDepthFirstComponent();
            }while(ComponentToFocus != NULL &&               //None found
                   ComponentToFocus != this &&               //Looped back to this component
                   !ComponentToFocus->isFocusInteractable());

            //Has the Depth first order reached the first
            if(ComponentToFocus == NULL &&
               getParentWindow() != NULL)
            {
                ComponentToFocus = getParentWindow()->getRightmostDecendent();
            }

            //Is the focus allowed to go here
            ComponentContainer* ParentTest(getParentContainer());
            while(ParentTest != NULL &&
                  !ParentTest->isDecendent(ComponentToFocus))
            {
                if(!ParentTest->allowFocusToLeave())
                {
                    //Change the focus to the first child of this parent
                    ComponentToFocus = ParentTest->getRightmostDecendent();
                    break;
                }
                ParentTest = ParentTest->getParentContainer();
            }
        }
    }

    //If a component was found to move to
    if(ComponentToFocus != NULL &&
       ComponentToFocus != this)
    {
        ComponentToFocus->takeFocus();
    }
}
void Component::changed(ConstFieldMaskArg whichField, 
                        UInt32            origin,
                        BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if( (whichField & MinSizeFieldMask) ||
        (whichField & MaxSizeFieldMask) ||
        (whichField & PreferredSizeFieldMask) ||
        (whichField & ConstraintsFieldMask))
    {
        //Layout needs to be recalculated for my parent ComponentContainer
        updateContainerLayout();
    }

    if( (whichField & SizeFieldMask) ||
        (whichField & PositionFieldMask) )
    {
        updateClipBounds();
    }

    if( (whichField & SizeFieldMask) )
    {
        produceComponentResized();
    }
    if( (whichField & PositionFieldMask) )
    {
        produceComponentMoved();
    }
    if( (whichField & StateFieldMask) )
    {
        if(getEnabled())
        {
            produceComponentEnabled();    
        }
        else
        {
            produceComponentDisabled();    
        }

        if(getVisible())
        {
            produceComponentVisible();    
        }
        else
        {
            produceComponentHidden();    
        }
    }

    if(whichField & ToolTipFieldMask)
    {
        _ToolTipActivateMouseEnterConnection.disconnect();
        _ToolTipActivateMouseExitConnection.disconnect();

        if(getToolTip() != NULL)
        {
            getToolTip()->setVisible(true);
            getToolTip()->setEnabled(true);
            getToolTip()->updateClipBounds();

            getToolTip()->setPosition(Pnt2f(0.0f,0.0f));

            _ToolTipActivateMouseEnterConnection = connectMouseEntered(boost::bind(&Component::handleToolTipActivateMouseEntered, this, _1));
            _ToolTipActivateMouseExitConnection = connectMouseExited(boost::bind(&Component::handleToolTipActivateMouseExited, this, _1));
        }
    }

    if((whichField & CursorFieldMask) &&
       getMouseOver() &&
       getParentWindow() != NULL &&
       getParentWindow()->getParentDrawingSurface() != NULL &&
       getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL)
    {
        getParentWindow()->getParentDrawingSurface()->getEventProducer()->setCursorType(getCursor());
    }
}
Example #14
0
ComponentContainer* MenuBar::getParentContainer(void) const
{
    return getParentWindow();
}
Example #15
0
ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item,
                                   int maxRange):
    Window("", true, parent, "amount.xml"),
    mItemPriceTextField(nullptr),
    mGPLabel(nullptr),
    mItem(item),
    mMax(maxRange),
    mUsage(usage),
    mItemPriceSlide(nullptr),
    mItemsModal(nullptr),
    mPrice(0)
{
    if (!mItem)
    {
        setVisible(false);
        return;
    }
    if (usage == ShopBuyAdd)
        mMax = 10000;
    else if (!mMax)
        mMax = mItem->getQuantity();

    // Save keyboard state
    mEnabledKeyboard = keyboard.isEnabled();
    keyboard.setEnabled(false);

    // Integer field
    mItemAmountTextField = new IntTextField(1);
    mItemAmountTextField->setRange(1, mMax);
    mItemAmountTextField->setWidth(35);
    mItemAmountTextField->addKeyListener(this);

    // Slider
    mItemAmountSlide = new Slider(1.0, mMax);
    mItemAmountSlide->setHeight(10);
    mItemAmountSlide->setActionEventId("slide");
    mItemAmountSlide->addActionListener(this);

    if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd)
    {
        // Integer field
        mItemPriceTextField = new IntTextField(1);
        mItemPriceTextField->setRange(1, 10000000);
        mItemPriceTextField->setWidth(35);
        mItemPriceTextField->addKeyListener(this);

        // Slider
        mItemPriceSlide = new Slider(1.0, 10000000);
        mItemPriceSlide->setHeight(10);
        mItemPriceSlide->setActionEventId("slidePrice");
        mItemPriceSlide->addActionListener(this);

        mGPLabel = new Label(" GP");
    }

    if (mUsage == ShopBuyAdd)
    {
        mItemsModal = new ItemsModal;
        mItemDropDown = new DropDown(mItemsModal);
        mItemDropDown->setActionEventId("itemType");
        mItemDropDown->addActionListener(this);
    }

    //Item icon
    Image *image = item->getImage();
    mItemIcon = new Icon(image);

    // Buttons
    Button *minusAmountButton = new Button(_("-"), "dec", this);
    Button *plusAmountButton = new Button(_("+"), "inc", this);
    Button *okButton = new Button(_("OK"), "ok", this);
    Button *cancelButton = new Button(_("Cancel"), "cancel", this);
    Button *addAllButton = new Button(_("All"), "all", this);

    minusAmountButton->adjustSize();
    minusAmountButton->setWidth(plusAmountButton->getWidth());

    // Set positions
    ContainerPlacer placer;
    placer = getPlacer(0, 0);
    int n = 0;
    if (mUsage == ShopBuyAdd)
    {
        placer(0, n, mItemDropDown, 8);
        n++;
    }
    placer(1, n, minusAmountButton);
    placer(2, n, mItemAmountTextField, 3);
    placer(5, n, plusAmountButton);
    placer(6, n, addAllButton);

    placer(0, n, mItemIcon, 1, 3);
    placer(1, n + 1, mItemAmountSlide, 7);

    if (mUsage == ShopBuyAdd || mUsage == ShopSellAdd)
    {
        Button *minusPriceButton = new Button(_("-"), "decPrice", this);
        Button *plusPriceButton = new Button(_("+"), "incPrice", this);
        minusPriceButton->adjustSize();
        minusPriceButton->setWidth(plusPriceButton->getWidth());

        placer(1, n + 2, minusPriceButton);
        placer(2, n + 2, mItemPriceTextField, 3);
        placer(5, n + 2, plusPriceButton);
        placer(6, n + 2, mGPLabel);

        placer(1, n + 3, mItemPriceSlide, 7);
        placer(4, n + 5, cancelButton);
        placer(5, n + 5, okButton);
    }
    else
    {
        placer(4, n + 2, cancelButton);
        placer(5, n + 2, okButton);
    }

    reflowLayout(225, 0);

    resetAmount();

    switch (usage)
    {
        case TradeAdd:
            setCaption(_("Select amount of items to trade."));
            break;
        case ItemDrop:
            setCaption(_("Select amount of items to drop."));
            break;
        case StoreAdd:
            setCaption(_("Select amount of items to store."));
            break;
        case StoreRemove:
            setCaption(_("Select amount of items to retrieve."));
            break;
        case ItemSplit:
            setCaption(_("Select amount of items to split."));
            break;
        case ShopBuyAdd:
            setCaption(_("Add to buy shop."));
            break;
        case ShopSellAdd:
            setCaption(_("Add to sell shop."));
            break;
        default:
            setCaption(_("Unknown."));
            break;
    }

    setLocationRelativeTo(getParentWindow());
    setVisible(true);

    mItemPopup = new ItemPopup;
    mItemIcon->addMouseListener(this);
}