void send_to_channel(
        const CHANNELS::ChannelDef& channel, uint8_t const * data, size_t length, size_t chunk_size, int flags
    ) override {
        BOOST_REQUIRE(!strcmp(channel.name, channel_names::cliprdr));

        InStream stream(data, length);
        RDPECLIP::RecvFactory recv_factory(stream);

        switch (recv_factory.msgType) {
            case RDPECLIP::CB_MONITOR_READY:
                this->send_to_server(RDPECLIP::FormatListPDU());
            break;
            //case RDPECLIP::CB_FORMAT_LIST:
            //    break;
            //case RDPECLIP::CB_FORMAT_LIST_RESPONSE:
            //    break;
            case RDPECLIP::CB_FORMAT_DATA_REQUEST:
            {
                RDPECLIP::FormatDataRequestPDU().recv(stream, recv_factory);
                constexpr std::size_t buf_sz = 65535;
                uint8_t buf[buf_sz];
                size_t unicode_data_length = ::UTF8toUTF16(byte_ptr_cast(this->str.c_str()),
                    buf, buf_sz);
                buf[unicode_data_length    ] = 0;
                buf[unicode_data_length + 1] = 0;
                unicode_data_length += 2;
                this->send_to_server(RDPECLIP::FormatDataResponsePDU(true), buf, unicode_data_length);
            }
            break;
            default:
            break;
        }
    }
Пример #2
0
void CopyPaste::LimitString::utf16_push_back(const uint8_t * s, size_t n)
{
    this->size_ += UTF16toUTF8(
        s, n,
        byte_ptr_cast(this->buf_ + this->size_),
        this->max_size() - this->size_
    );
    this->buf_[this->size_] = 0;
    this->widget_edit_buf_is_computed = false;
}
Пример #3
0
void WidgetEdit::insert_text(const char * text/*, int position = 0*/)
{
    if (text && *text) {
        const size_t n = strlen(text);
        const size_t tmp_buffer_size = this->buffer_size;

        const size_t remain_n = WidgetLabel::buffer_size - 1 - this->buffer_size;
        const size_t max_n = ((remain_n >= n) ? n : ::UTF8StringAdjustedNbBytes(::byte_ptr_cast(text), remain_n));
        const size_t total_n = max_n + this->buffer_size;

        if (this->edit_pos == this->buffer_size || total_n == WidgetLabel::buffer_size - 1) {
            memcpy(this->label.buffer + this->buffer_size, text, max_n);
        }
        else {
            memmove(this->label.buffer + this->edit_buffer_pos + n, this->label.buffer + this->edit_buffer_pos,
                    std::min(WidgetLabel::buffer_size - 1 - (this->edit_buffer_pos + n),
                                this->buffer_size - this->edit_buffer_pos));
            memcpy(this->label.buffer + this->edit_buffer_pos, text, max_n);
        }
        this->buffer_size = total_n;
        this->label.buffer[this->buffer_size] = 0;
        gdi::TextMetrics tm(this->font, this->label.buffer);
        this->w_text = tm.width;
        this->h_text = tm.height;
        const size_t tmp_num_chars = this->num_chars;
        this->num_chars = UTF8Len(byte_ptr_cast(this->label.buffer));
        Rect rect = this->get_cursor_rect();
        rect.cx = this->w_text - this->cursor_px_pos;
        if (this->edit_pos == tmp_buffer_size || total_n == WidgetLabel::buffer_size - 1) {
            this->cursor_px_pos = this->w_text;
            this->edit_buffer_pos = this->buffer_size;
        }
        else {
            const size_t pos = this->edit_buffer_pos + max_n;
            const char c = this->label.buffer[pos];
            this->label.buffer[pos] = 0;
            // TODO: tm.height unused ?
            gdi::TextMetrics tm(this->font, this->label.buffer + this->edit_buffer_pos);
            this->label.buffer[pos] = c;
            this->cursor_px_pos += tm.width;
            this->edit_buffer_pos += max_n;
        }
        this->edit_pos += this->num_chars - tmp_num_chars;
        this->update_draw_cursor(rect);
    }
}
Пример #4
0
WidgetEdit::WidgetEdit(
    gdi::GraphicApi & drawable,
    Widget & parent, NotifyApi* notifier, const char * text,
    int group_id, BGRColor fgcolor, BGRColor bgcolor, BGRColor focus_color,
    Font const & font, std::size_t edit_position, int xtext, int ytext)
: Widget(drawable, parent, notifier, group_id)
, label(drawable, *this, nullptr, text, 0, fgcolor, bgcolor, font, xtext, ytext)
, w_text(0)
, h_text(0)
, cursor_color(0x888888)
, focus_color(focus_color)
, drawall(false)
, draw_border_focus(true)
, font(font)
{
    if (text) {
        this->buffer_size = strlen(text);
        this->num_chars = UTF8Len(byte_ptr_cast(this->label.buffer));
        this->edit_pos = std::min(this->num_chars, edit_position);
        this->edit_buffer_pos = UTF8GetPos(reinterpret_cast<uint8_t *>(this->label.buffer), this->edit_pos);
        this->cursor_px_pos = 0;
        char c = this->label.buffer[this->edit_buffer_pos];
        this->label.buffer[this->edit_buffer_pos] = 0;
        gdi::TextMetrics tm1(this->font, this->label.buffer);
        this->w_text = tm1.width;
        this->cursor_px_pos = this->w_text;
        this->label.buffer[this->edit_buffer_pos] = c;
        // TODO: tm.height unused ?
        gdi::TextMetrics tm2(this->font, &this->label.buffer[this->edit_buffer_pos]);
        this->w_text += tm2.width;
    } else {
        this->buffer_size = 0;
        this->num_chars = 0;
        this->edit_buffer_pos = 0;
        this->edit_pos = 0;
        this->cursor_px_pos = 0;
    }

    // TODO: tm.width unused ?
    gdi::TextMetrics tm(this->font, "Édp");
    this->h_text = tm.height;
    this->h_text -= 1;

    this->pointer_flag = Pointer::POINTER_EDIT;
}
Пример #5
0
void WidgetEdit::set_text(const char * text/*, int position = 0*/)
{
    this->label.buffer[0] = 0;
    this->buffer_size = 0;
    this->num_chars = 0;
    this->w_text = 0;
    if (text && *text) {
        const size_t n = strlen(text);
        const size_t remain_n = WidgetLabel::buffer_size - 1;

        this->buffer_size = ((remain_n >= n) ? n : ::UTF8StringAdjustedNbBytes(::byte_ptr_cast(text), remain_n));

        memcpy(this->label.buffer, text, this->buffer_size);
        this->label.buffer[this->buffer_size] = 0;
        gdi::TextMetrics tm(this->font, this->label.buffer);
        this->w_text = tm.width;
        this->h_text = tm.height;
        this->num_chars = UTF8Len(byte_ptr_cast(this->label.buffer));
    }
    this->edit_pos = this->num_chars;
    this->edit_buffer_pos = this->buffer_size;
    this->cursor_px_pos = this->w_text;
}