void DispatchMessage(BMessage *msg, BHandler *target) { switch(msg->what) { case M_TEMPLATE_SAVE: { EditView *ev; entry_ref dir; const char *filespec; int32 DocID; if ((msg->FindInt32("DocID", &DocID) == B_OK) && (msg->FindRef("directory", &dir) == B_OK) && (msg->FindString("name", &filespec) == B_OK) && (ev = FindEVByDocID(DocID))) { BEntry entry(&dir, true); BPath path; entry.GetPath(&path); path.Append(filespec); const char *filename = path.Path(); if (ev->Save(filename)) { (new BAlert("", "The save operation failed: the file could not be written to the destination.", "Damned!"))->Go(); } } else { (new BAlert("", "The save operation failed.", "Damned!"))->Go(); } if (TemplatePanel) { delete TemplatePanel; TemplatePanel = NULL; } Quit(); } break; case M_TEMPLATE_LOAD: { int i; uint32 type; int32 count; entry_ref ref; EditView *ev = NULL, *firstev = NULL; LockWindow(); msg->GetInfo("refs", &type, &count); for(i=0;i<count;i++) { if (msg->FindRef("refs", i, &ref) == B_OK) { BEntry entry(&ref, true); BPath path; entry.GetPath(&path); // open the template if (ev = CreateEditView((char *)path.Path())) { // take away the template filename: make the file untitled ev->MakeUntitled(); if (!firstev) firstev = ev; } } } // switch to the first template opened if (firstev) TabBar->SetActiveTab(firstev); TabBar->redraw(); UnlockWindow(); if (TemplatePanel) { delete TemplatePanel; TemplatePanel = NULL; } Quit(); } break; case M_TEMPLATE_SELECT: { entry_ref ref; if (msg->FindRef("refs", &ref) == B_OK) { BEntry entry(&ref, true); BPath path; entry.GetPath(&path); BMessenger target; BMessage msg_to_deliver; msg->FindMessage("message", &msg_to_deliver); msg->FindMessenger("target", &target); msg_to_deliver.AddString("template_name", path.Path()); stat("delivering message"); target.SendMessage(&msg_to_deliver); } } break; default: BLooper::DispatchMessage(msg, target); break; } }
void TestBtn(void) { PWindow pWinSon0 = NULL; PButton pBtnSon0 = NULL; PEditView pEditSon0 = NULL; PCheckBox pBkBoxSon0 = NULL; PWindow pWinParent = NULL; int iRnd; int i; int iParent; CRect rect; CFont font; CBrush brush; INT iID; iID = 1; InitHeapPool(INIT_HEAP_DEFAULT); InitGUI(); Log("start...\n"); pWinParent = CreateWindowE(0, pWinRoot, iID++); rect.m_iLeft = 10; rect.m_iTop = 10; rect.m_iHeigh = 200; rect.m_iWidth = 300; pWinParent->m_pfSelWinRect(P2H(pWinParent), &rect, NULL); SetWinBKColor(pWinParent, 0xFF000000); pBtnSon0 = CreateButton(pWinParent, iID++, "btn1", 0, WIN_MSG_BUTTON, WinOnUsrProc); rect.m_iLeft = 80; rect.m_iTop = 10; rect.m_iHeigh = 50; rect.m_iWidth = 50; pBtnSon0->m_pfSelWinRect(P2H(pBtnSon0), &rect, NULL); SetWinBKColor(&pBtnSon0->m_baseWin, 0xFF00FF00); font.m_color = 0xFF000000; pBtnSon0->m_pfSelWinFont(P2H(pBtnSon0), &font, NULL); pWinSon0 = CreateWindowE(0, pWinParent, iID++); rect.m_iLeft = 50; rect.m_iTop = 10; rect.m_iHeigh = 50; rect.m_iWidth = 50; pWinSon0->m_pfSelWinRect(P2H(pWinSon0), &rect, NULL); SetWinBKColor(pWinSon0, 0xFFFF0000); pEditSon0 = CreateEditView(pWinParent, iID++, "you are pig stupid, fool is your nick name kill youyou are pig stupid, fool is your nick name kill you", 0/*EDIT_VIEW_MULTI_LINE*/); rect.m_iLeft = 30; rect.m_iTop = 90; rect.m_iHeigh = 50; rect.m_iWidth = 100; pEditSon0->m_pfSelWinRect(P2H(pEditSon0), &rect, NULL); pEditSon0->m_pfSelWinFont(P2H(pEditSon0), &font, NULL); brush.m_color = 0xFFFFFFFF; pEditSon0->m_pfSelWinBrush(P2H(pEditSon0), &brush, NULL); pEditSon0->m_iCurEdit = 10; pBkBoxSon0 = CreateCheckBox(pWinParent, iID++, "CheckMe", TRUE, 0); rect.m_iLeft = 146; rect.m_iTop = 80; rect.m_iHeigh = 24; rect.m_iWidth = 100; pBkBoxSon0->m_pfSelWinRect(P2H(pBkBoxSon0), &rect, NULL); pBkBoxSon0->m_pfSelWinFont(P2H(pBkBoxSon0), &font, NULL); brush.m_color = 0xFFFF00FF; pBkBoxSon0->m_pfSelWinBrush(P2H(pBkBoxSon0), &brush, NULL); Log("window flow...\n"); FlowWindow0(pWinRoot, WindowFlow); //pWinTmp = FindWindowByID(25); //Log("find..."); //WindowFlow(pWinTmp); PrintScreen(); #if 0 pWinTmp = FindWindowByID(2); if(pWinTmp == NULL) { Log("NULL pointer\r\n"); } Log("OK\r\n"); ReorderWindow(pWinTmp); FlowWindow0(pWinRoot, WindowFlow); #endif while(TRUE) { int x; int y; int iRet; PPoint pPoint; scanf("%d %d", &x, &y); pPoint = (PPoint)Malloc(sizeof(CPoint)); pPoint->m_iX = x; pPoint->m_iY = y; iRet = pWinRoot->m_pfPostMessage(P2H(pWinRoot), WIN_MSG_ID_CLICK_SCREEN_DOWN, 0, pPoint); Log("iRet[%d]\r\n", iRet); WinFlowMain(); FlowWindow0(pWinRoot, WindowFlow); PrintScreen(); } DeleteEditView(pEditSon0); DeleteButton(pBtnSon0); }