Ejemplo n.º 1
0
/**
 * ポップアップ用ウィンドウのコンストラクタ
 *
 * @param wxWindow* parent     親ウィンドウのインスタンス
 * @param wxPoint&  point      ウィンドウの出現位置
 * @param wxSize    size       ウィンドウのサイズ
 * @raram wxString& htmlSource 表示させるHTMLソース
 */
AnchoredResponsePopup::AnchoredResponsePopup( wxWindow *parent, wxPoint& point, wxSize size, wxString& htmlSource )
:wxPopupTransientWindow( parent ) {

     // スキンを使わないならデフォルトフォントを設定する
     SkinInfo* skinInfo = new SkinInfo;
     // HTMLのソース
     wxString html = wxEmptyString;
     bool  useSkin = CheckSkinFiles(skinInfo);

     wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
     // wxHtmlWindowにHTMLソースを設定する
     htmlWin = new wxHtmlWindow(this, wxID_ANY, wxPoint(0, 0), size, wxHW_SCROLLBAR_AUTO);
     
     if (!useSkin) {
	  const int p = 12;
	  static int f_size[] = {p - 2, p - 1, p, p + 1, p + 2, p + 3, p + 4 };

#ifdef __WXMSW__
	  wxString fontName = wxT("MS Pゴシック");
	  htmlWin->SetFonts(fontName, wxEmptyString, f_size);
#elif  __WXGTK__
	  wxFont f;
	  if (f.SetFaceName(wxT("Mona"))) {
	       htmlWin->SetFonts(wxT("Mona"), wxEmptyString, f_size);
	  } else if (f.SetFaceName(wxT("Mona-VLGothic"))) {
	       htmlWin->SetFonts(wxT("Mona-VLGothic"), wxEmptyString, f_size);
	  } else if (f.SetFaceName(wxT("Mona-sazanami"))) {
	       htmlWin->SetFonts(wxT("Mona-sazanami"), wxEmptyString, f_size);
	  }
#elif  __WXMAC__
	  wxString fontName = wxT("Mona");
	  htmlWin->SetFonts(fontName, wxEmptyString, f_size);
#endif
	  html += HTML_HEADER;
	  html += htmlSource;
	  html += HTML_FOOTER;
     } else {
	  // スキンを使用する
	  html += skinInfo->header;
	  html += htmlSource;
	  html += skinInfo->footer;
     }

     // 後片付け
     delete skinInfo;

     htmlWin->SetBorders(0);
     htmlWin->SetPage(html);
     // wxHtmlWindow内部での実質サイズを取得する
     int hx = htmlWin->GetInternalRepresentation()->GetWidth();
     int hy = htmlWin->GetInternalRepresentation()->GetHeight();
     htmlWin->SetSize(hx, hy);
     // このウィンドウ(popup)にサイザーをセットして最小の大きさに設定する
     topsizer->Add(htmlWin, 1, wxALL, 10);
     this->SetSize(hx, hy);
}
/**
 * 通常のコンストラクタ
 */
ThreadContentWindow::ThreadContentWindow(wxWindow* parent, const wxString& threadContentPath):
wxHtmlWindow(parent, ID_ThreadContentWindow, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO) {

#ifdef __WXMSW__
     // ウィンドウ内に入った際のイベント通知
     this->Connect(ID_ThreadContentWindow,
		   wxEVT_ENTER_WINDOW,
		   wxMouseEventHandler(JaneClone::OnEnterWindow),
		   NULL, this);
#endif

     // 指定されたパスからHTMLファイルを読み出す
     wxString htmlSource = GetConvertedDatFile(threadContentPath);
     // 設定ファイルの準備をする
     // ユーザーのホームディレクトリを取得
     wxDir workDir(::wxGetHomeDir());
     wxDir jcDir(::wxGetHomeDir() + wxFILE_SEP_PATH + JANECLONE_DIR);

     // ユーザーのホームディレクトリに隠しフォルダがあるかどうか確認
     if (!workDir.HasSubDirs(JANECLONE_DIR)) {
	  ::wxMkdir(jcDir.GetName());
     }
     if (!jcDir.HasSubDirs(wxT("prop"))) {
	  ::wxMkdir(jcDir.GetName() + wxFILE_SEP_PATH + wxT("prop"));
     }

     // スキンを使わないならデフォルトフォントを設定する
     SkinInfo* skinInfo = new SkinInfo;
     bool       useSkin = CheckSkinFiles(skinInfo);
     delete skinInfo;
     
     if (!useSkin) {

	  // フォントのポイント数
	  const int p = 12;
	  static int f_size[] = {p - 2, p - 1, p, p + 1, p + 2, p + 3, p + 4 };

#ifdef __WXMSW__
	  wxString fontName = wxT("MS Pゴシック");
	  this->SetFonts(fontName, wxEmptyString, f_size);
#elif  __WXGTK__
	  wxFont f;
	  if (f.SetFaceName(wxT("Mona"))) {
	       this->SetFonts(wxT("Mona"), wxEmptyString, f_size);
	  } else if (f.SetFaceName(wxT("Mona-VLGothic"))) {
	       this->SetFonts(wxT("Mona-VLGothic"), wxEmptyString, f_size);
	  } else if (f.SetFaceName(wxT("Mona-sazanami"))) {
	       this->SetFonts(wxT("Mona-sazanami"), wxEmptyString, f_size);
	  }

#elif  __WXMAC__
	  wxString fontName = wxT("Mona");
	  this->SetFonts(fontName, wxEmptyString, f_size);
#endif
     }

     // メモリに読み込んだHTMLを表示する
     this->SetPage(htmlSource);
     // 外部から参照可能なHTML
     this->m_htmlSource = htmlSource;
     // スクロールのフラグ
     fNeedScroll = false;
}
/**
 * 指定されたパスからHTMLファイルを読み出し、2ch形式に加工する
 */
const wxString ThreadContentWindow::GetConvertedDatFile(const wxString& threadContentPath) {

     // wxStringにバッファするサイズを計測する
     size_t fileSize = JaneCloneUtil::GetFileSize(threadContentPath);

     if (fileSize == 0)
	  // 読み込みに失敗した場合
	  return FAIL_TO_READ_PAGE;

     // スキンがあれば使う
     SkinInfo* skinInfo = new SkinInfo;
     bool       useSkin = CheckSkinFiles(skinInfo);

     // 取得サイズ分だけwxStringを確保する
     wxString htmlSource;
     htmlSource.Alloc(fileSize);

     if (useSkin && skinInfo->header != wxEmptyString) {
	  htmlSource += skinInfo->header;
     } else {
	  htmlSource += HTML_HEADER;
     }     

     // テキストファイルの読み込み
     wxTextFile datfile;
     datfile.Open(threadContentPath, wxConvUTF8);
     wxString str;
     int number = 1;

     // ファイルがオープンされているならば
     if (datfile.IsOpened()) {
	  for (str = datfile.GetFirstLine(); 
	       !datfile.Eof();
	       str = datfile.GetNextLine()) {

	       if (str.IsNull())
		    continue;

	       if (number == 1) {
		    // 最初の1行目の処理
		    htmlSource += JaneCloneUtil::ProcessFirstResponse(str);
	       } else {
		    // それ以降の処理
		    htmlSource += JaneCloneUtil::ProcessRestResponse(str, number);
	       }

	       number++;
	       this->m_response_number = number;
	  }
     }

     if (useSkin && skinInfo->footer != wxEmptyString) {
	  htmlSource += skinInfo->footer;
     } else {
	  htmlSource += HTML_FOOTER;
     }

     // スキン用構造体を片付ける
     delete skinInfo;
     datfile.Close();

     // ID:xxxxxxxxxx を置換する
     htmlSource = JaneCloneUtil::AddID(htmlSource);
     // >>xx のようなアンカーを受けているレスを赤くする
     htmlSource = JaneCloneUtil::AddColorAnchoredID(htmlSource);

     return htmlSource;
}