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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// Constructor Definition
ChatWindow::ChatWindow(int x, int y, int w, int h, const char *title) : Fl_Double_Window(x, y, w, h, title)
{
buddyFlag = false;
buddyName = new char [31];
buddyListName = new char[44];
buddyLogMode = new char[12];
for(int i = 1; i <= buddyListWindow->buddyList->size(); i++)
{
if(buddyListWindow->buddyList->selected(i))
{
int cnt = 0;
buddyFlag = true;
strcpy(buddyListName, (char *)buddyListWindow->buddyList->text(i));
while(buddyListName[cnt] != '-')
{
buddyName[cnt] = buddyListName[cnt];
cnt++;
}
buddyName[cnt] = '\0';
cnt++;
for(int i = 0; i < strlen(buddyLogMode); i++)
{
if(buddyListName[cnt] == '\0')
{
buddyLogMode[i] = buddyListName[cnt];
break;
}
else
{
buddyLogMode[i] = buddyListName[cnt];
cnt++;
}
}
break;
}
}
make_current();
color(fl_rgb_color(200, 200, 255));
size_range(this->w(), this->h());
begin();
chatMenuBar = new Fl_Menu_Bar(0, 0, 640, 20);
chatMenuBar->copy(chatMenu, this);
chatMenuBar->color(FL_BLACK);
chatMenuBar->textcolor(FL_WHITE);
chatMenuBar->textsize(12);
chatDisplay = new Fl_Text_Display(0, chatMenuBar->y() + chatMenuBar->h(), 640, 270);
chatDisplay->wrap_mode(1, 0);
txtDisplayBuffy = new Fl_Text_Buffer();
chatDisplay->buffer(txtDisplayBuffy);
chatContainer = new Fl_Box(10, chatDisplay->y() + chatDisplay->h() + 50, 610, 50);
chatContainer->box(FL_DOWN_BOX);
chatContainer->color(FL_WHITE);
chatEditor = new Fl_Text_Editor(10, chatDisplay->y() + chatDisplay->h() + 50, 525, 50);
chatEditor->wrap_mode(1, 0);
txtEditorBuffy = new Fl_Text_Buffer();
chatEditor->buffer(txtEditorBuffy);
chatEditor->take_focus();
btnSend = new Fl_Return_Button(2 + chatEditor->x() + chatEditor->w(), chatDisplay->y() + chatDisplay->h() + 55,
75, 40, "Send");
btnSend->color(FL_BLACK);
btnSend->color2(FL_BLACK);
btnSend->labelcolor(FL_WHITE);
btnSend->callback(send_cb, this);
end();
callback(quit_cb, this);
show();
ChatWindow::chatFlag = true;
}
void ChatWindow::quit_cb_i()
{
buddyListWindow->btnConnect->value(0);
ChatWindow::chatFlag = false;
if(buddyName != NULL)
{
delete [] buddyName;
buddyName = NULL;
}
if(buddyListName != NULL)
{
delete [] buddyListName;
buddyListName = NULL;
}
if(buddyLogMode != NULL)
{
delete [] buddyLogMode;
buddyLogMode = NULL;
}
hide();
}
void ChatWindow::send_cb_i()
{
int action = 0;
if(buddyFlag)
{
sendData.friendname.clear();
sendData.friendname.append(buddyName);
}
if(!strcmp(buddyLogMode, "Offline"))
{
OfflineWindow *offlineWindow = new OfflineWindow(buddyName, 220, 240, 400, 200, "User is offline");
}
sendData.sendMessage.clear();
sendData.sendMessage.append((char *)txtEditorBuffy->text());
txtDisplayBuffy->append(sendData.username.c_str());
txtDisplayBuffy->append(": ");
txtDisplayBuffy->append(sendData.sendMessage.c_str());
chatWindow->chatDisplay->textcolor(FL_RED);
chatWindow->chatDisplay->textfont(FL_HELVETICA | FL_BOLD);
txtEditorBuffy->clear_rectangular(0, chatWindow->chatEditor->w(), 0, chatWindow->chatEditor->h() *100);
chatWindow->chatEditor->take_focus();
if (Fl::event_key() != FL_Enter)
txtDisplayBuffy->append("\n");
if(strcmp(sendData.username.c_str(), "offline") && strcmp(sendData.password.c_str(), "offline"))
{
buddyListWindow->parseSend();
action = send(logonSocket, buffyTheMessageSender, strlen(buffyTheMessageSender), 0);
if(action == SOCKET_ERROR)
{
cout << "\nERROR: Unable to send data on thread. Code " << WSAGetLastError() << endl;
fl_alert("Could not send Data.");
}
}
}
| |