summaryrefslogtreecommitdiff
path: root/cpp/demo/Glacier2/winrt/chat/ChatView.xaml.cpp
blob: a9c505c2aae6d61b983d5f87b61a6fb68a08ae04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// ChatView.xaml.cpp
// Implementation of the ChatView class
//

#include "pch.h"
#include "ChatView.xaml.h"
#include "MainPage.xaml.h"
#include <string>

using namespace chat;
using namespace std;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

ChatView::ChatView()
{
    InitializeComponent();
    MainPage::instance()->_chatView = this;
}

void
ChatView::setError(String^ err)
{
    appendMessage(L"<system-message> " + err);
}

void 
ChatView::appendMessage(String^ message)
{
    messages->Text += message + L"\n";
    messages->UpdateLayout();
    Scroller->ScrollToVerticalOffset(Scroller->ScrollableHeight);
}

/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.  The Parameter
/// property is typically used to configure the page.</param>
void ChatView::OnNavigatedTo(NavigationEventArgs^ e)
{
    (void) e;	// Unused parameter
}


void chat::ChatView::inputKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    if(e->Key == Windows::System::VirtualKey::Enter && !input->Text->IsEmpty())
    {
        string msg = IceUtil::wstringToString(input->Text->Data());
        input->Text = ref new String();
        MainPage::instance()->coordinator()->say(msg);
    }
}