wxSize wxRadioBox::DoGetBestSize() const
{
    int charWidth, charHeight;
    int maxWidth, maxHeight;
    int eachWidth, eachHeight;
    int totWidth, totHeight;

    wxFont font = GetFont(); // GetParent()->GetFont()
    GetTextExtent(
        wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
        &charWidth, &charHeight, NULL, NULL, &font );

    charWidth /= 52;

    maxWidth = -1;
    maxHeight = -1;

    wxSize bestSizeRadio ;
    if ( m_radioButtonCycle )
        bestSizeRadio = m_radioButtonCycle->GetBestSize();

#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for (unsigned int i = 0 ; i < m_noItems; i++)
    {
        GetTextExtent(GetString(i), &eachWidth, &eachHeight, NULL, NULL, &font );
        eachWidth  = (eachWidth + RADIO_SIZE);
        eachHeight = wxMax(eachHeight, bestSizeRadio.y );
        if (maxWidth < eachWidth)
            maxWidth = eachWidth;
        if (maxHeight < eachHeight)
            maxHeight = eachHeight;
    }

    // according to HIG (official space - 3 Pixels Diff between Frame and Layout size)
    int space = 3;
    if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
        space = 2;

    totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space;
    totWidth  = GetColumnCount() * (maxWidth + charWidth);

    wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) );
    totWidth = sz.x;
    totHeight = sz.y;

    // optimum size is an additional 5 pt border to all sides
    totWidth += 10;
    totHeight += 10;

    // handle radio box title as well
    GetTextExtent( GetLabel(), &eachWidth, NULL );
    eachWidth  = (int)(eachWidth + RADIO_SIZE) +  3 * charWidth;
    if (totWidth < eachWidth)
        totWidth = eachWidth;

    return wxSize( totWidth, totHeight );
}
示例#2
0
void WorldSession::HandleOfferPetitionOpcode(WorldPacket& recvData)
{
    sLog->outDebug(LOG_FILTER_NETWORKIO, "Received opcode CMSG_OFFER_PETITION");

    ObjectGuid petitionGuid, playerGuid;
    uint32 type, junk;
    Player* player;

    ObjectGuid guid1;
    ObjectGuid guid2;
    recvData >> junk;                                      // this is not petition type!

    guid1[3] = recvData.ReadBit();
    guid1[2] = recvData.ReadBit();
    guid1[5] = recvData.ReadBit();
    guid2[4] = recvData.ReadBit();
    guid1[7] = recvData.ReadBit();
    guid1[6] = recvData.ReadBit();
    guid2[3] = recvData.ReadBit();
    guid2[7] = recvData.ReadBit();
    guid2[0] = recvData.ReadBit();
    guid1[4] = recvData.ReadBit();
    guid2[1] = recvData.ReadBit();
    guid2[6] = recvData.ReadBit();
    guid2[2] = recvData.ReadBit();
    guid1[1] = recvData.ReadBit();
    guid2[5] = recvData.ReadBit();
    guid1[0] = recvData.ReadBit();

    recvData.FlushBits();

    recvData.ReadByteSeq(guid2[2]);
    recvData.ReadByteSeq(guid2[3]);
    recvData.ReadByteSeq(guid2[1]);
    recvData.ReadByteSeq(guid2[5]);
    recvData.ReadByteSeq(guid2[4]);
    recvData.ReadByteSeq(guid1[7]);
    recvData.ReadByteSeq(guid2[0]);
    recvData.ReadByteSeq(guid1[2]);
    recvData.ReadByteSeq(guid1[0]);
    recvData.ReadByteSeq(guid1[6]);
    recvData.ReadByteSeq(guid2[7]);
    recvData.ReadByteSeq(guid1[1]);
    recvData.ReadByteSeq(guid1[4]);
    recvData.ReadByteSeq(guid1[3]);
    recvData.ReadByteSeq(guid1[5]);
    recvData.ReadByteSeq(guid2[6]);

    petitionGuid = guid1;
    playerGuid = guid2;

    player = ObjectAccessor::FindPlayer(playerGuid);
    if (!player)
        return;

    type = GUILD_CHARTER_TYPE;

    uint32 petitionGuidLow = GUID_LOPART(petitionGuid);

    sLog->outDebug(LOG_FILTER_NETWORKIO, "OFFER PETITION: type %u, GUID1 %u, to player id: %u", type, petitionGuidLow, GUID_LOPART(playerGuid));

    if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeam() != player->GetTeam())
    {
        if (type == GUILD_CHARTER_TYPE)
            Guild::SendCommandResult(this, GUILD_COMMAND_CREATE, ERR_GUILD_NOT_ALLIED);
        return;
    }

    if (type == GUILD_CHARTER_TYPE)
    {
        if (player->GetGuildIdInvited())
        {
            SendPetitionSignResult(_player->GetGUID(), MAKE_NEW_GUID(petitionGuidLow, 0, HIGHGUID_ITEM), PETITION_SIGN_ALREADY_SIGNED_OTHER);
            return;
        }

        if (player->GetGuildId())
        {
            SendPetitionSignResult(_player->GetGUID(), MAKE_NEW_GUID(petitionGuidLow, 0, HIGHGUID_ITEM), PETITION_SIGN_ALREADY_IN_GUILD);
            return;
        }
    }

    auto stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PETITION_SIGNATURE);
    stmt->setUInt32(0, petitionGuidLow);
    auto result = CharacterDatabase.Query(stmt);

    typedef std::vector<uint32> storage;
    storage loParts;

    // result == NULL also correct charter without signs
    if (result)
    {
        loParts.reserve(uint32(result->GetRowCount()));

        do
        {
            auto fields = result->Fetch();
            auto loPart = fields[0].GetUInt32();
            if (GUID_LOPART(playerGuid) == loPart)
            {
                player->GetSession()->SendAlreadySigned(playerGuid);
                return;
            }

            loParts.push_back(loPart);
        }
        while (result->NextRow());
    }

    WorldPacket data(SMSG_PETITION_SHOW_SIGNATURES);
    ByteBuffer signsBuffer;

    guid2 = _player->GetGUID();
    //ObjectGuid guid1 = petitionGuid;

    data.WriteBit(guid2[4]);
    data.WriteBit(guid1[4]);
    data.WriteBit(guid2[5]);
    data.WriteBit(guid2[0]);
    data.WriteBit(guid2[6]);
    data.WriteBit(guid1[7]);
    data.WriteBit(guid2[7]);
    data.WriteBit(guid1[0]);
    data.WriteBit(guid2[2]);
    data.WriteBit(guid2[3]);

    data.WriteBits(loParts.size(), 21);

    for (auto lowGuid : loParts)
    {
        ObjectGuid signerGuid = MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER);

        uint8 bitsSendOrder[8] = { 6, 2, 4, 5, 3, 0, 7, 1 };
        data.WriteBitInOrder(signerGuid, bitsSendOrder);

        signsBuffer.WriteByteSeq(signerGuid[4]);
        signsBuffer.WriteByteSeq(signerGuid[7]);
        signsBuffer.WriteByteSeq(signerGuid[5]);
        signsBuffer.WriteByteSeq(signerGuid[3]);
        signsBuffer.WriteByteSeq(signerGuid[2]);

        signsBuffer << uint32(0);

        signsBuffer.WriteByteSeq(signerGuid[6]);
        signsBuffer.WriteByteSeq(signerGuid[1]);
        signsBuffer.WriteByteSeq(signerGuid[0]);
    }

    data.WriteBit(guid1[5]);
    data.WriteBit(guid1[6]);
    data.WriteBit(guid1[1]);
    data.WriteBit(guid1[3]);
    data.WriteBit(guid2[1]);
    data.WriteBit(guid1[2]);

    data.FlushBits();

    data << uint32(petitionGuidLow);

    if (signsBuffer.size())
        data.append(signsBuffer);

    data.WriteByteSeq(guid1[2]);
    data.WriteByteSeq(guid2[1]);
    data.WriteByteSeq(guid2[6]);
    data.WriteByteSeq(guid1[3]);
    data.WriteByteSeq(guid2[7]);
    data.WriteByteSeq(guid1[0]);
    data.WriteByteSeq(guid2[0]);
    data.WriteByteSeq(guid2[2]);
    data.WriteByteSeq(guid1[4]);
    data.WriteByteSeq(guid1[7]);
    data.WriteByteSeq(guid1[6]);
    data.WriteByteSeq(guid2[4]);
    data.WriteByteSeq(guid2[3]);
    data.WriteByteSeq(guid2[5]);
    data.WriteByteSeq(guid1[5]);
    data.WriteByteSeq(guid1[1]);

    player->GetSession()->SendPacket(&data);
}
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
    int i;
    wxRadioButton *current;

    // define the position

    int x_current, y_current;
    int x_offset, y_offset;
    int widthOld, heightOld;

    GetSize( &widthOld, &heightOld );
    GetPosition( &x_current, &y_current );

    x_offset = x;
    y_offset = y;
    if (!(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
    {
        if (x == wxDefaultCoord)
            x_offset = x_current;
        if (y == wxDefaultCoord)
            y_offset = y_current;
    }

    // define size
    int charWidth, charHeight;
    int maxWidth, maxHeight;
    int eachWidth[128], eachHeight[128];
    int totWidth, totHeight;

    GetTextExtent(
        wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
        &charWidth, &charHeight );

    charWidth /= 52;

    maxWidth = -1;
    maxHeight = -1;
    wxSize bestSizeRadio ;
    if ( m_radioButtonCycle )
        bestSizeRadio = m_radioButtonCycle->GetBestSize();

#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for (unsigned int i = 0 ; i < m_noItems; i++)
    {
        GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] );
        eachWidth[i] = eachWidth[i] + RADIO_SIZE;
        eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y );

        if (maxWidth < eachWidth[i])
            maxWidth = eachWidth[i];
        if (maxHeight < eachHeight[i])
            maxHeight = eachHeight[i];
    }

    // according to HIG (official space - 3 Pixels Diff between Frame and Layout size)
    int space = 3;
    if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
        space = 2;

    totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space;
    totWidth  = GetColumnCount() * (maxWidth + charWidth);

    // Determine the full size in case we need to use it as fallback.
    wxSize sz;
    if ( (width == wxDefaultCoord && (sizeFlags & wxSIZE_AUTO_WIDTH)) ||
            (height == wxDefaultCoord && (sizeFlags & wxSIZE_AUTO_HEIGHT)) )
    {
        sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;
    }

    // change the width / height only when specified
    if ( width == wxDefaultCoord )
    {
        if ( sizeFlags & wxSIZE_AUTO_WIDTH )
            width = sz.x;
        else
            width = widthOld;
    }

    if ( height == wxDefaultCoord )
    {
        if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
            height = sz.y;
        else
            height = heightOld;
    }

    wxControl::DoSetSize( x_offset, y_offset, width, height, wxSIZE_AUTO );

    // But now recompute the full size again because it could have changed.
    // This notably happens if the previous full size was too small to fully
    // fit the box margins.
    sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;

    // arrange radio buttons
    int x_start, y_start;

    x_start = ( width - sz.x ) / 2;
    y_start = ( height - sz.y ) / 2;

    x_offset = x_start;
    y_offset = y_start;

    current = m_radioButtonCycle;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for (i = 0 ; i < (int)m_noItems; i++)
    {
        // not to do for the zero button!
        if ((i > 0) && ((i % GetMajorDim()) == 0))
        {
            if (m_windowStyle & wxRA_SPECIFY_ROWS)
            {
                x_offset += maxWidth + charWidth;
                y_offset = y_start;
            }
            else
            {
                x_offset = x_start;
                y_offset += maxHeight + space;
            }
        }

        current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i] );
        current = current->NextInCycle();

        if (m_windowStyle & wxRA_SPECIFY_ROWS)
            y_offset += maxHeight + space;
        else
            x_offset += maxWidth + charWidth;
    }
}
示例#4
0
//------------------------------------------------------------
void CBMRegEditView::OnInitialUpdate()
{ m_nPrevRowCount=GetRowCount(); m_nPrevSelectedRow=GetActReg(); UpdateScrollSizes(); }
示例#5
0
void CLobbyServerPlayer::ProcessGetCharacters(const PacketData& packetData)
{
	CLog::GetInstance().LogMessage(LOG_NAME, "GetCharacters");

	if(m_dbConnection.IsEmpty())
	{
		CLog::GetInstance().LogMessage(LOG_NAME, "No database connection available. Bailing.");
		m_disconnect = true;
		return;
	}

	PacketData outgoingPacket(std::begin(g_characterListPacket), std::end(g_characterListPacket));

	CCharacter character;

	try
	{
		auto query = string_format("SELECT * FROM ffxiv_characters WHERE userId = %d", m_userId);
		auto result = m_dbConnection.Query(query.c_str());
		if(result.GetRowCount() != 0)
		{
			character = CCharacter(result);
		}
	}
	catch(const std::exception& exception)
	{
		CLog::GetInstance().LogError(LOG_NAME, "Failed to fetch characters for user (id = %d): %s", m_userId, exception.what());
		m_disconnect = true;
		return;
	}

	PacketData characterData(std::begin(g_characterData), std::end(g_characterData));
	
	characterData[0x21] = CCharacter::GetModelFromTribe(character.tribe);
	characterData[0x9F] = character.tribe;
	characterData[0xC7] = character.guardian;
	characterData[0xC8] = character.birthMonth;
	characterData[0xC9] = character.birthDay;
	characterData[0xE8] = character.allegiance;

	*reinterpret_cast<uint32*>(&characterData[0x25]) = character.size;				//size

	*reinterpret_cast<uint32*>(&characterData[0x29]) = character.GetColorInfo();	//hairColor + skinColor
	*reinterpret_cast<uint32*>(&characterData[0x2D]) = character.GetFaceInfo();		//face Stuff?
	*reinterpret_cast<uint32*>(&characterData[0x31]) = character.hairStyle << 10;	//hair model
	*reinterpret_cast<uint32*>(&characterData[0x35]) = character.voice;				//voice
	*reinterpret_cast<uint32*>(&characterData[0x39]) = character.weapon1;			//weapon1
	*reinterpret_cast<uint32*>(&characterData[0x3D]) = character.weapon2;			//weapon2
	*reinterpret_cast<uint32*>(&characterData[0x55]) = character.headGear;			//headGear
	*reinterpret_cast<uint32*>(&characterData[0x59]) = character.bodyGear;			//bodyGear
	*reinterpret_cast<uint32*>(&characterData[0x5D]) = character.legsGear;			//legsGear
	*reinterpret_cast<uint32*>(&characterData[0x61]) = character.handsGear;			//handsGear
	*reinterpret_cast<uint32*>(&characterData[0x65]) = character.feetGear;			//feetGear
	*reinterpret_cast<uint32*>(&characterData[0x69]) = character.waistGear;			//waistGear
//	*reinterpret_cast<uint32*>(&characterData[0x6D]) = 0;							//???
	*reinterpret_cast<uint32*>(&characterData[0x71]) = character.rightEarGear;		//rightEarGear
	*reinterpret_cast<uint32*>(&characterData[0x75]) = character.leftEarGear;		//leftEarGear
//	*reinterpret_cast<uint32*>(&characterData[0x79]) = 0;							//???
//	*reinterpret_cast<uint32*>(&characterData[0x7D]) = 0;							//???
	*reinterpret_cast<uint32*>(&characterData[0x81]) = character.rightFingerGear;	//rightFingerGear
	*reinterpret_cast<uint32*>(&characterData[0x85]) = character.leftFingerGear;	//leftFingerGear

	auto encodedCharacterData = Framework::ToBase64(characterData.data(), characterData.size());
	std::replace(std::begin(encodedCharacterData), std::end(encodedCharacterData), '+', '-');
	std::replace(std::begin(encodedCharacterData), std::end(encodedCharacterData), '/', '_');

	static const uint32 characterInfoBase = 0x860;

	if(character.active)
	{
		for(unsigned int i = 0; i < encodedCharacterData.size(); i++)
		{
			outgoingPacket[characterInfoBase + 0x40 + i] = encodedCharacterData[i];
		}

		*reinterpret_cast<uint32*>(&outgoingPacket[characterInfoBase + 0x00]) = 0x0158E7FC;
		*reinterpret_cast<uint32*>(&outgoingPacket[characterInfoBase + 0x04]) = character.id;
		*reinterpret_cast<uint32*>(&outgoingPacket[characterInfoBase + 0x0C]) = 0x000000F4;

		//Insert character name
		for(unsigned int i = 0; i < character.name.size(); i++)
		{
			outgoingPacket[characterInfoBase + 0x10 + i] = character.name[i];
		}
		outgoingPacket[characterInfoBase + 0x10 + character.name.size()] = 0;
	}

	CPacketUtils::EncryptPacket(outgoingPacket);
	QueuePacket(outgoingPacket);
}
示例#6
0
void wxMySQLRecordset::Seek(unsigned int rowindex)
{
	unsigned int topindex(GetRowCount()-1);		
	printf("MYSQL_STMT_DATA_SEEK\r\n");
	mysql_stmt_data_seek(m_Stmt, std::max((int)0, (int)std::min(topindex, rowindex)));
}
示例#7
0
int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
{
    int count = GetCount(),
        numCols = GetColumnCount(),
        numRows = GetRowCount();

    bool horz = (style & wxRA_SPECIFY_COLS) != 0;

    switch ( dir )
    {
        case wxUP:
            if ( horz )
            {
                item -= numCols;
            }
            else // vertical layout
            {
                if ( !item-- )
                    item = count - 1;
            }
            break;

        case wxLEFT:
            if ( horz )
            {
                if ( !item-- )
                    item = count - 1;
            }
            else // vertical layout
            {
                item -= numRows;
            }
            break;

        case wxDOWN:
            if ( horz )
            {
                item += numCols;
            }
            else // vertical layout
            {
                if ( ++item == count )
                    item = 0;
            }
            break;

        case wxRIGHT:
            if ( horz )
            {
                if ( ++item == count )
                    item = 0;
            }
            else // vertical layout
            {
                item += numRows;
            }
            break;

        default:
            wxFAIL_MSG( _T("unexpected wxDirection value") );
            return wxNOT_FOUND;
    }

    // ensure that the item is in range [0..count)
    if ( item < 0 )
    {
        // first map the item to the one in the same column but in the last row
        item += count;

        // now there are 2 cases: either it is the first item of the last row
        // in which case we need to wrap again and get to the last item or we
        // can just go to the previous item
        if ( item % (horz ? numCols : numRows) )
            item--;
        else
            item = count - 1;
    }
    else if ( item >= count )
    {
        // same logic as above
        item -= count;

        // ... except that we need to check if this is not the last item, not
        // the first one
        if ( (item + 1) % (horz ? numCols : numRows) )
            item++;
        else
            item = 0;
    }

    wxASSERT_MSG( item < count && item >= 0,
                  _T("logic error in wxRadioBox::GetNextItem()") );

    return item;
}
示例#8
0
文件: radiobox.cpp 项目: EdgarTx/wx
bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
                         const wxPoint &pos, const wxSize &size,
                         int n, const wxString choices[], int majorDim,
                         long style, const wxValidator& validator,
                         const wxString &name )
{
    if (!PreCreation( parent, pos, size ) ||
        !CreateBase( parent, id, pos, size, style, validator, name ))
    {
        wxFAIL_MSG( wxT("wxRadioBox creation failed") );
        return false;
    }

    m_widget = gtk_frame_new(NULL);
    SetLabel(title);
    if ( HasFlag(wxNO_BORDER) )
    {
        // If we don't do this here, the wxNO_BORDER style is ignored in Show()
        gtk_frame_set_shadow_type(GTK_FRAME(m_widget), GTK_SHADOW_NONE);
    }

    // majorDim may be 0 if all trailing parameters were omitted, so don't
    // assert here but just use the correct value for it
    SetMajorDim(majorDim == 0 ? n : majorDim, style);


    unsigned int num_of_cols = GetColumnCount();
    unsigned int num_of_rows = GetRowCount();

    GtkRadioButton *m_radio = (GtkRadioButton*) NULL;

    GtkWidget *table = gtk_table_new( num_of_rows, num_of_cols, FALSE );
    gtk_table_set_col_spacings( GTK_TABLE(table), 1 );
    gtk_table_set_row_spacings( GTK_TABLE(table), 1 );
    gtk_widget_show( table );
    gtk_container_add( GTK_CONTAINER(m_widget), table );

    wxString label;
    GSList *radio_button_group = (GSList *) NULL;
    for (int i = 0; i < n; i++)
    {
        if ( i != 0 )
            radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) );

        label.Empty();
        for ( const wxChar *pc = choices[i]; *pc; pc++ )
        {
            if ( *pc != wxT('&') )
                label += *pc;
        }

        m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, wxGTK_CONV( label ) ) );
        gtk_widget_show( GTK_WIDGET(m_radio) );

        gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
           GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );

        m_boxes.Append( (wxObject*) m_radio );

        if (HasFlag(wxRA_SPECIFY_COLS))
        {
            int left = i%num_of_cols;
            int right = (i%num_of_cols) + 1;
            int top = i/num_of_cols;
            int bottom = (i/num_of_cols)+1;
            gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom,
                  GTK_FILL, GTK_FILL, 1, 1 );
        }
        else
        {
            int left = i/num_of_rows;
            int right = (i/num_of_rows) + 1;
            int top = i%num_of_rows;
            int bottom = (i%num_of_rows)+1;
            gtk_table_attach( GTK_TABLE(table), GTK_WIDGET(m_radio), left, right, top, bottom,
                  GTK_FILL, GTK_FILL, 1, 1 );
        }

        ConnectWidget( GTK_WIDGET(m_radio) );

        if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );

        gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
            GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );

        gtk_signal_connect( GTK_OBJECT(m_radio), "focus_in_event",
            GTK_SIGNAL_FUNC(gtk_radiobutton_focus_in), (gpointer)this );

        gtk_signal_connect( GTK_OBJECT(m_radio), "focus_out_event",
            GTK_SIGNAL_FUNC(gtk_radiobutton_focus_out), (gpointer)this );
    }

    m_parent->DoAddChild( this );

    PostCreation(size);

    return true;
}
示例#9
0
void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
    int i;
    wxRadioButton *current;

    // define the position

    int x_current, y_current;
    int x_offset, y_offset;
    int widthOld, heightOld;

    GetSize( &widthOld, &heightOld );
    GetPosition( &x_current, &y_current );

    x_offset = x;
    y_offset = y;
    if (!(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
    {
        if (x == wxDefaultCoord)
            x_offset = x_current;
        if (y == wxDefaultCoord)
            y_offset = y_current;
    }

    // define size
    int charWidth, charHeight;
    int maxWidth, maxHeight;
    int eachWidth[128], eachHeight[128];
    int totWidth, totHeight;

    GetTextExtent(
        wxT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
        &charWidth, &charHeight );

    charWidth /= 52;

    maxWidth = -1;
    maxHeight = -1;
    wxSize bestSizeRadio ;
    if ( m_radioButtonCycle )
        bestSizeRadio = m_radioButtonCycle->GetBestSize();

    for (unsigned int i = 0 ; i < m_noItems; i++)
    {
        GetTextExtent(GetString(i), &eachWidth[i], &eachHeight[i] );
        eachWidth[i] = eachWidth[i] + RADIO_SIZE;
        eachHeight[i] = wxMax( eachHeight[i], bestSizeRadio.y );

        if (maxWidth < eachWidth[i])
            maxWidth = eachWidth[i];
        if (maxHeight < eachHeight[i])
            maxHeight = eachHeight[i];
    }

    // according to HIG (official space - 3 Pixels Diff between Frame and Layout size)
    int space = 3;
    if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
        space = 2;

    totHeight = GetRowCount() * maxHeight + (GetRowCount() - 1) * space;
    totWidth  = GetColumnCount() * (maxWidth + charWidth);

    wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;

    // change the width / height only when specified
    if ( width == wxDefaultCoord )
    {
        if ( sizeFlags & wxSIZE_AUTO_WIDTH )
            width = sz.x;
        else
            width = widthOld;
    }

    if ( height == wxDefaultCoord )
    {
        if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
            height = sz.y;
        else
            height = heightOld;
    }

    wxControl::DoSetSize( x_offset, y_offset, width, height, wxSIZE_AUTO );

    // arrange radio buttons
    int x_start, y_start;

    x_start = ( width - sz.x ) / 2;
    y_start = ( height - sz.y ) / 2;

    x_offset = x_start;
    y_offset = y_start;

    current = m_radioButtonCycle;
    for (i = 0 ; i < (int)m_noItems; i++)
    {
        // not to do for the zero button!
        if ((i > 0) && ((i % GetMajorDim()) == 0))
        {
            if (m_windowStyle & wxRA_SPECIFY_ROWS)
            {
                x_offset += maxWidth + charWidth;
                y_offset = y_start;
            }
            else
            {
                x_offset = x_start;
                y_offset += maxHeight + space;
            }
        }

        current->SetSize( x_offset, y_offset, eachWidth[i], eachHeight[i] );
        current = current->NextInCycle();

        if (m_windowStyle & wxRA_SPECIFY_ROWS)
            y_offset += maxHeight + space;
        else
            x_offset += maxWidth + charWidth;
    }
}
示例#10
0
文件: kearat.cpp 项目: garnertb/gdal
GDALDefaultRasterAttributeTable *KEARasterAttributeTable::Clone() const
{
    if( ( GetRowCount() * GetColumnCount() ) > RAT_MAX_ELEM_FOR_CLONE )
        return NULL;

    GDALDefaultRasterAttributeTable *poRAT = new GDALDefaultRasterAttributeTable();

    for( int iCol = 0; iCol < (int)m_aoFields.size(); iCol++)
    {
        CPLString sName = m_aoFields[iCol].name;
        CPLString sUsage = m_aoFields[iCol].usage;
        GDALRATFieldUsage eGDALUsage;
        if( sUsage == "PixelCount" )
            eGDALUsage = GFU_PixelCount;
        else if( sUsage == "Name" )
            eGDALUsage = GFU_Name;
        else if( sUsage == "Red" )
            eGDALUsage = GFU_Red;
        else if( sUsage == "Green" )
            eGDALUsage = GFU_Green;
        else if( sUsage == "Blue" )
            eGDALUsage = GFU_Blue;
        else if( sUsage == "Alpha" )
            eGDALUsage = GFU_Alpha;
        else
        {
            // don't recognise any other special names - generic column
            eGDALUsage = GFU_Generic;
        }

        GDALRATFieldType eGDALType;
        switch( m_aoFields[iCol].dataType )
        {
            case kealib::kea_att_bool:
            case kealib::kea_att_int:
                eGDALType = GFT_Integer;
                break;
            case kealib::kea_att_float:
                eGDALType = GFT_Real;
                break;
            case kealib::kea_att_string:
                eGDALType = GFT_String;
                break;
            default:
                eGDALType = GFT_Integer;
                break;
        }
        poRAT->CreateColumn(sName, eGDALType, eGDALUsage);
        poRAT->SetRowCount(m_poKEATable->getSize());
        
        if( m_poKEATable->getSize() == 0 )
            continue;

        if( eGDALType == GFT_Integer )
        {
            int *panColData = (int*)VSIMalloc2(sizeof(int), m_poKEATable->getSize());
            if( panColData == NULL )
            {
                CPLError( CE_Failure, CPLE_OutOfMemory,
                    "Memory Allocation failed in KEARasterAttributeTable::Clone");
                delete poRAT;
                return NULL;
            }

            if( (const_cast<KEARasterAttributeTable*>(this))->
                        ValuesIO(GF_Read, iCol, 0, m_poKEATable->getSize(), panColData ) != CE_None )
            {
                CPLFree(panColData);
                delete poRAT;
                return NULL;
            }           

            for( int iRow = 0; iRow < (int)m_poKEATable->getSize(); iRow++ )
            {
                poRAT->SetValue(iRow, iCol, panColData[iRow]);            
            }
            CPLFree(panColData);
        }
        if( eGDALType == GFT_Real )
        {
            double *padfColData = (double*)VSIMalloc2(sizeof(double), m_poKEATable->getSize());
            if( padfColData == NULL )
            {
                CPLError( CE_Failure, CPLE_OutOfMemory,
                    "Memory Allocation failed in KEARasterAttributeTable::Clone");
                delete poRAT;
                return NULL;
            }
            if( (const_cast<KEARasterAttributeTable*>(this))->
                        ValuesIO(GF_Read, iCol, 0, m_poKEATable->getSize(), padfColData ) != CE_None )
            {
                CPLFree(padfColData);
                delete poRAT;
                return NULL;
            }           

            for( int iRow = 0; iRow < (int)m_poKEATable->getSize(); iRow++ )
            {
                poRAT->SetValue(iRow, iCol, padfColData[iRow]);            
            }
            CPLFree(padfColData);
        }
        if( eGDALType == GFT_String )
        {
            char **papszColData = (char**)VSIMalloc2(sizeof(char*), m_poKEATable->getSize());
            if( papszColData == NULL )
            {
                CPLError( CE_Failure, CPLE_OutOfMemory,
                    "Memory Allocation failed in KEARasterAttributeTable::Clone");
                delete poRAT;
                return NULL;
            }

            if( (const_cast<KEARasterAttributeTable*>(this))->
                    ValuesIO(GF_Read, iCol, 0, m_poKEATable->getSize(), papszColData ) != CE_None )
            {
                CPLFree(papszColData);
                delete poRAT;
                return NULL;
            }           

            for( int iRow = 0; iRow < (int)m_poKEATable->getSize(); iRow++ )
            {
                poRAT->SetValue(iRow, iCol, papszColData[iRow]);
                CPLFree(papszColData[iRow]);
            }
            CPLFree(papszColData);
        }
    }
    return poRAT;
}
示例#11
0
int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
{
    const int itemStart = item;

    int count = GetCount(),
        numCols = GetColumnCount(),
        numRows = GetRowCount();

    bool horz = (style & wxRA_SPECIFY_COLS) != 0;

    do
    {
        switch ( dir )
        {
            case wxUP:
                if ( horz )
                {
                    item -= numCols;
                }
                else // vertical layout
                {
                    if ( !item-- )
                        item = count - 1;
                }
                break;

            case wxLEFT:
                if ( horz )
                {
                    if ( !item-- )
                        item = count - 1;
                }
                else // vertical layout
                {
                    item -= numRows;
                }
                break;

            case wxDOWN:
                if ( horz )
                {
                    item += numCols;
                }
                else // vertical layout
                {
                    if ( ++item == count )
                        item = 0;
                }
                break;

            case wxRIGHT:
                if ( horz )
                {
                    if ( ++item == count )
                        item = 0;
                }
                else // vertical layout
                {
                    item += numRows;
                }
                break;

            default:
                wxFAIL_MSG( _T("unexpected wxDirection value") );
                return wxNOT_FOUND;
        }

        // ensure that the item is in range [0..count)
        if ( item < 0 )
        {
            // first map the item to the one in the same column but in the last
            // row
            item += count;

            // now there are 2 cases: either it is the first item of the last
            // row in which case we need to wrap again and get to the last item
            // or we can just go to the previous item
            if ( item % (horz ? numCols : numRows) )
                item--;
            else
                item = count - 1;
        }
        else if ( item >= count )
        {
            // same logic as above
            item -= count;

            // ... except that we need to check if this is not the last item,
            // not the first one
            if ( (item + 1) % (horz ? numCols : numRows) )
                item++;
            else
                item = 0;
        }

        wxASSERT_MSG( item < count && item >= 0,
                      _T("logic error in wxRadioBox::GetNextItem()") );
    }
    // we shouldn't select the non-active items, continue looking for a
    // visible and shown one unless we came back to the item we started from in
    // which case bail out to avoid infinite loop
    while ( !(IsItemShown(item) && IsItemEnabled(item)) && item != itemStart );

    return item;
}
示例#12
0
	BinaryVector *BinaryVector::CropVector(int start, int count = -1) {
		int endIndex = count == -1 ? GetRowCount() - 1 : (start + count - 1);
		BinaryMatrix *croped = Crop(0, 0, start, endIndex);
	};
示例#13
0
const char *XMLProcedureCall::Execute( XMLObject *pDestinatonObject /*= 0*/, 
							    bool bDestinationObjectTagPresent /* = 1*/)
{
	if (!m_DataSource)
	{
		throw GException("XMLProcedureCall", 8);
	}

	if (!m_strSchema.IsEmpty())
		AddAttribute( "Schema", (const char *)m_strSchema );

	m_DataSource->AddAttributes(this);
	if ( m_lstProcedures.Size() > 1  ||		// Multiple DB operations or joins(within the same transaction) 
		 m_bForceTransaction 		 ||		// Force Transactional
		 strstr((const char *)m_strProcedureName,"::") )	// executing CustomDLL.procedure

	{
		AddAttribute( "Transaction", "yes" );
	}

	if ( GetRowCount() != (long)-1 )
	{
		AddAttribute( "maxObjects", GetRowCount() );
	}

	if (m_pzReportTemplateName)
	{
		AddAttribute( "MergeXML", "yes" );
		AddAttribute( "Template", m_pzReportTemplateName );
	}
	
	ToXML(&m_strRequest);

	if (m_lpfnSend)
	{
		m_lpfnSend((const char *)m_strRequest);
	}

	const char *pDebugFile = GetProfile().GetString("Debug", "DebugTraceXML", false);
	if (pDebugFile && pDebugFile[0])
	{
		// trace out the xml being sent to the server
		GString strTrace;
		strTrace.Format("\n\n\n\nSent To [%s]-----------\n%s",m_DataSource->GetServerAddress(),(const char *)m_strRequest);
		strTrace.ToFileAppend(pDebugFile);
	}
	
	int nRetryCount = 0;
RESEND:
	try
	{
		
		m_strXml = m_DataSource->send(	(const char *)m_strProcedureName,
										(const char *)m_strRequest,
										(int)m_strRequest.Length(),/* Length w/o Null terminator */
										0, 
										&m_pUserData,"TransactXML=");

		if (m_lpfnRecv)
			m_lpfnRecv(m_strXml);

	}
	catch(GException &e)
	{
		// "General error parsing XML stream" means the data was corrupted in transit.
		if (e.GetError() == 7)
		{
			// Resend the request.
			if (nRetryCount++ < 3)
			{
				TRACE_WARNING("Attempting resend" );
				goto RESEND;
			}
		}
		
		// "the handle is invalid".  We need to 'reboot' the datasource. (WININET)
		if ((e.GetError()  == 6) && 
			(e.GetSystem() == 0)) 
		{
			// Resend the request.
			if (nRetryCount++ < 3)
			{
				TRACE_WARNING("Attempting resend" );
				m_DataSource->IPAddressChange();
				goto RESEND;
			}
		}

		// This helps distinguish Client errors from Server errors
		// unless the error was a client side connect error.
		throw GException("XMLProcedureCall", 4, m_DataSource->GetServerAddress(), e.GetDescription());
	}

	if (pDebugFile && pDebugFile[0])
	{
		// trace out the xml returned from the server
		GString strTrace("\n\n\n\nReceived:\n----------\n");
		const char *pXML = GetXML();
		if (pXML)
			strTrace += pXML;
		strTrace.ToFileAppend(pDebugFile);
	}

	// map to tags that we expect to recieve in the query results
	LoadMemberMappings();

	if ( m_bRunObjectFactory && m_strXml && m_strXml[0] )
	{
		const char *pFactoryXML = m_strXml;
		if (m_pzReportTemplateName)
		{
			pFactoryXML = GetXML();
		}
		
		try
		{
			if (pDestinatonObject)
			{
		
				// The tag "XMLQueryResults" can be anything.  The outer most
				// tag is never verified, this object will contain the Root
				// starting point for factorization (the pDestinatonObject object)
				if (bDestinationObjectTagPresent)
				{
					XMLRelationshipWrapper objectContainer("XMLQueryResults");

					objectContainer.ModifyObjectBehavior(PREVENT_AUTO_DESTRUCTION);


					const char *tag = pDestinatonObject->GetObjectTag();
					objectContainer.AddReference(	tag, pDestinatonObject );


					// When we are paring into an object and the object tag is
					// specified in the XML.  For example, when placing:
					// <Results>
					//		<Customer>
					//			<Widgit>
					//				...
					//			</Widgit>
					//		</Customer>
					// </Results>

					// This will allow us to put Widgit's in a 'Customer' or any 
					// type of object that the pDestinatonObject describes.
					objectContainer.FromXML(pFactoryXML,this);
				}
				else
				{
					// When we are paring into an object but that object is not
					// specified in the XML.  For example, when placing:
					// <Results>
					//		<Widgit>
					//			...
					//		</Widgit>
					// </Results>

					// This will allow us to put Widgit's in a 'Customer' or any 
					// type of object that the pDestinatonObject describes.
					pDestinatonObject->FromXML(pFactoryXML,this);
				}
			}
			else
			{
				XMLObjectFactory factory ( pFactoryXML,m_DataSource->GetServerAddress() );
				// Only Queries have result descriptors
				if ( getResultObjectTag() )
				{
					factory.setResultDescriptor( GetEntry( getResultObjectTag() ) );
				}
				factory.extractObjects(this);
			}
		}
		catch (GException &)
		{
			throw;
		}

// in a debug build, this code is better off compiled out so that the debugger will break closer to the problem.
// in a release build, this may help to 'crash softer'.
#ifndef _DEBUG
		// if we should catch an unhandled exception here
		catch ( ... )
		{
			TRACE_ERROR("Fatal Error while factory creating objects" );
			TRACE_ERROR("1. Check your String/List Handlers" );
			TRACE_ERROR("2. Did you delete a cached object and not remove it from the cache?");
	
			throw GException("XMLProcedureCall", 6);
		}
#endif

	}
	else
	{
		if (m_bRunObjectFactory)
		{
			// we should never get nothing, it may indicate 
			// communication failure depending on the type of DataSource
			TRACE_WARNING("Nothing received from DataBroker" );
			throw GException("XMLProcedureCall", 7);
		}
	}
	return m_strXml;
}
示例#14
0
void wxVListBox::OnKeyDown(wxKeyEvent& event)
{
    // flags for DoHandleItemClick()
    int flags = ItemClick_Kbd;

    int current;
    switch ( event.GetKeyCode() )
    {
        case WXK_HOME:
            current = 0;
            break;

        case WXK_END:
            current = GetRowCount() - 1;
            break;

        case WXK_DOWN:
            if ( m_current == (int)GetRowCount() - 1 )
                return;

            current = m_current + 1;
            break;

        case WXK_UP:
            if ( m_current == wxNOT_FOUND )
                current = GetRowCount() - 1;
            else if ( m_current != 0 )
                current = m_current - 1;
            else // m_current == 0
                return;
            break;

        case WXK_PAGEDOWN:
            PageDown();
            current = GetVisibleBegin();
            break;

        case WXK_PAGEUP:
            if ( m_current == (int)GetVisibleBegin() )
            {
                PageUp();
            }

            current = GetVisibleBegin();
            break;

        case WXK_SPACE:
            // hack: pressing space should work like a mouse click rather than
            // like a keyboard arrow press, so trick DoHandleItemClick() in
            // thinking we were clicked
            flags &= ~ItemClick_Kbd;
            current = m_current;
            break;

#ifdef __WXMSW__
        case WXK_TAB:
            // Since we are using wxWANTS_CHARS we need to send navigation
            // events for the tabs on MSW
            HandleAsNavigationKey(event);
            // fall through to default
#endif
        default:
            event.Skip();
            current = 0; // just to silent the stupid compiler warnings
            wxUnusedVar(current);
            return;
    }

    if ( event.ShiftDown() )
       flags |= ItemClick_Shift;
    if ( event.ControlDown() )
        flags |= ItemClick_Ctrl;

    DoHandleItemClick(current, flags);
}