tagging release
[dasher.git] / Src / Common / IOstreamDasherEdit.cc
blob54bb192883a66dd938aebb498f757ee9578f6769
1 // IOstreamDasherEdit.cc
2 // (c) 2003 Yann Dirson
3 // Derived from GtkDasherEdit.cc
4 // (c) 2002 Philip Cowans
6 #include "Common.h"
8 #include "IOstreamDasherEdit.h"
10 #include <string>
11 #include <iostream>
13 #include <iconv.h>
15 IOstreamDasherEdit::IOstreamDasherEdit(CDasherInterface *_interface, std::ostream *os)
16 :Dasher::CDashEditbox(), flush_count(0), interface(_interface), outstream(os) {
17 enc = 1;
18 snprintf(encstr, 255, "ISO-8859-%d", enc);
20 *outstream << "Dasher starting\n";
23 IOstreamDasherEdit::~IOstreamDasherEdit() {
26 void IOstreamDasherEdit::write_to_file() {
29 void IOstreamDasherEdit::kill_flush() {
30 flush_count = 0;
33 void IOstreamDasherEdit::get_new_context(std::string &str, int max) {
34 str = std::string();
37 void IOstreamDasherEdit::unflush() {
38 if(flush_count == 0)
39 return;
41 for(; flush_count > 0; flush_count--)
42 *outstream << "\b";
45 void IOstreamDasherEdit::output(symbol Symbol) {
46 // FIXME - again, label is utf-8 encoded, and insert is probably not
47 // expecting this to be the case
49 std::string label;
50 label = interface->GetEditText(Symbol);
52 label = interface->GetEditText(Symbol);
54 iconv_t cdesc = iconv_open(encstr, "UTF-8");
56 char *convbuffer = new char[256];
57 char *inbuffer = new char[256];
59 char *cb(convbuffer);
60 char *ib(inbuffer);
62 strncpy(inbuffer, label.c_str(), 255);
64 size_t inb = label.length();
66 size_t outb = 256;
67 iconv(cdesc, (ICONV_CONST char **)&inbuffer, &inb, &convbuffer, &outb);
69 std::string csymbol(cb, 256 - outb);
71 delete cb;
72 delete ib;
74 *outstream << csymbol;
77 void IOstreamDasherEdit::flush(symbol Symbol) {
78 // We seem to be passed Symbol 0 (root node) sometimes, so ignore
79 // this
81 if(Symbol != 0) {
82 ++flush_count;
84 std::string label;
86 label = interface->GetEditText(Symbol);
88 iconv_t cdesc = iconv_open(encstr, "UTF-8");
90 char *convbuffer = new char[256];
91 char *inbuffer = new char[256];
93 char *cb(convbuffer);
94 char *ib(inbuffer);
96 strncpy(inbuffer, label.c_str(), 255);
98 size_t inb = label.length();
100 size_t outb = 256;
101 iconv(cdesc, (ICONV_CONST char **)&inbuffer, &inb, &convbuffer, &outb);
103 std::string csymbol(cb, 256 - outb);
105 delete cb;
106 delete ib;
108 *outstream << csymbol;
109 outstream->flush();
113 void IOstreamDasherEdit::Clear() {
116 void IOstreamDasherEdit::TimeStampNewFiles(bool Value) {
119 void IOstreamDasherEdit::deletetext() {
122 void IOstreamDasherEdit::SetEncoding(Opts::FileEncodingFormats Encoding) {
125 void IOstreamDasherEdit::SetFont(std::string Name, long Size) {
128 void IOstreamDasherEdit::set_display_encoding(int _enc) {
129 if(_enc != enc) {
130 enc = _enc;
132 snprintf(encstr, 255, "ISO-8859-%d", enc);
136 bool IOstreamDasherEdit::SaveAs(std::string filename, bool a) {
137 return (true);
140 bool IOstreamDasherEdit::Save(bool a) {
141 return (true);
144 bool IOstreamDasherEdit::Open(std::string filename) {
145 return (true);