void UnregisterEventHandler(EventHandler* h) { bool removed = allEventHandlers.Remove(h); CrashIf(!removed); if (0 == allEventHandlers.Count()) PostQuitMessage(0); }
PageElement *EbookEngine::GetElementAtPos(int pageNo, PointD pt) { Vec<PageElement *> *els = GetElements(pageNo); if (!els) return NULL; PageElement *el = NULL; for (size_t i = 0; i < els->Count() && !el; i++) if (els->At(i)->GetRect().Contains(pt)) el = els->At(i); if (el) els->Remove(el); DeleteVecMembers(*els); delete els; return el; }
LRESULT CALLBACK WndProcProperties(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PropertiesLayout *pl; switch (message) { case WM_CREATE: break; case WM_ERASEBKGND: // do nothing, helps to avoid flicker return TRUE; case WM_PAINT: OnPaintProperties(hwnd); break; case WM_CHAR: if (VK_ESCAPE == wParam) DestroyWindow(hwnd); break; case WM_DESTROY: pl = FindPropertyWindowByHwnd(hwnd); CrashIf(!pl); gPropertiesWindows.Remove(pl); delete pl; break; case WM_COMMAND: PropertiesOnCommand(hwnd, wParam); break; /* TODO: handle mouse move/down/up so that links work (?) */ default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
PageElement *DjVuEngineImpl::GetElementAtPos(int pageNo, PointD pt) { Vec<PageElement *> *els = GetElements(pageNo); if (!els) return NULL; // elements are extracted bottom-to-top but are accessed // in top-to-bottom order, so reverse the list first els->Reverse(); PageElement *el = NULL; for (size_t i = 0; i < els->Count() && !el; i++) if (els->At(i)->GetRect().Contains(pt)) el = els->At(i); if (el) els->Remove(el); DeleteVecMembers(*els); delete els; return el; }
static void VecTest() { Vec<int> ints; assert(ints.Count() == 0); ints.Append(1); ints.Push(2); ints.InsertAt(0, -1); assert(ints.Count() == 3); assert(ints.At(0) == -1 && ints.At(1) == 1 && ints.At(2) == 2); assert(ints.At(0) == -1 && ints.Last() == 2); int last = ints.Pop(); assert(last == 2); assert(ints.Count() == 2); ints.Push(3); ints.RemoveAt(0); assert(ints.Count() == 2); assert(ints.At(0) == 1 && ints.At(1) == 3); ints.Reset(); assert(ints.Count() == 0); for (int i = 0; i < 1000; i++) { ints.Push(i); } assert(ints.Count() == 1000 && ints.At(500) == 500); ints.Remove(500); assert(ints.Count() == 999 && ints.At(500) == 501); last = ints.Pop(); assert(last == 999); ints.Append(last); assert(ints.AtPtr(501) == &ints.At(501)); { Vec<int> ints2(ints); assert(ints2.Count() == 999); assert(ints.LendData() != ints2.LendData()); ints.Remove(600); assert(ints.Count() < ints2.Count()); ints2 = ints; assert(ints2.Count() == 998); } { char buf[2] = {'a', '\0'}; str::Str<char> v(0); for (int i = 0; i < 7; i++) { v.Append(buf, 1); buf[0] = buf[0] + 1; } char *s = v.LendData(); assert(str::Eq("abcdefg", s)); assert(7 == v.Count()); v.Set("helo"); assert(4 == v.Count()); assert(str::Eq("helo", v.LendData())); } { str::Str<char> v(128); v.Append("boo", 3); assert(str::Eq("boo", v.LendData())); assert(v.Count() == 3); v.Append("fop"); assert(str::Eq("boofop", v.LendData())); assert(v.Count() == 6); v.RemoveAt(2, 3); assert(v.Count() == 3); assert(str::Eq("bop", v.LendData())); v.Append('a'); assert(v.Count() == 4); assert(str::Eq("bopa", v.LendData())); char *s = v.StealData(); assert(str::Eq("bopa", s)); free(s); assert(v.Count() == 0); } { str::Str<char> v(0); for (int i = 0; i < 32; i++) { assert(v.Count() == i * 6); v.Append("lambd", 5); if (i % 2 == 0) v.Append('a'); else v.Push('a'); } for (int i=1; i<=16; i++) { v.RemoveAt((16 - i) * 6, 6); assert(v.Count() == (32 - i) * 6); } v.RemoveAt(0, 6 * 15); assert(v.Count() == 6); char *s = v.LendData(); assert(str::Eq(s, "lambda")); s = v.StealData(); assert(str::Eq(s, "lambda")); free(s); assert(v.Count() == 0); v.Append("lambda"); assert(str::Eq(v.LendData(), "lambda")); char c = v.Pop(); assert(c == 'a'); assert(str::Eq(v.LendData(), "lambd")); } VecTestAppendFmt(); { Vec<PointI *> v; srand((unsigned int)time(NULL)); for (int i = 0; i < 128; i++) { v.Append(new PointI(i, i)); size_t pos = rand() % v.Count(); v.InsertAt(pos, new PointI(i, i)); } assert(v.Count() == 128 * 2); size_t idx = 0; for (PointI **p = v.IterStart(); p; p = v.IterNext()) { assert(idx == v.IterIdx()); ++idx; } while (v.Count() > 64) { size_t pos = rand() % v.Count(); PointI *f = v.At(pos); v.Remove(f); delete f; } DeleteVecMembers(v); } { Vec<int> v; v.Append(2); for (int i = 0; i < 500; i++) v.Append(4); v.At(250) = 5; v.Reverse(); assert(v.Count() == 501 && v.At(0) == 4 && v.At(249) == v.At(251) && v.At(250) == 5 && v.At(500) == 2); v.Remove(4); v.Reverse(); assert(v.Count() == 500 && v.At(0) == 2 && v.At(249) == v.At(251) && v.At(250) == 5 && v.At(499) == 4); } }