📄 htobj.cc
字号:
} else { buf->setCursorMode(CURSOR_OFF); screen->setCursorMode(CURSOR_OFF); }}void ht_view::setdata(ObjectStream &s){}void ht_view::setgroup(ht_group *_group){ group=_group;}void ht_view::setnumber(uint number){}void ht_view::setoptions(int Options){ options = Options;}void ht_view::setpalette(const char *Pal_name){ pal_name = Pal_name; reloadpalette();}void ht_view::setpalettefull(const char *_pal_name, const char *_pal_class){ pal_class=_pal_class; setpalette(pal_name);}void ht_view::store(ObjectStream &s) const{/* s->putBool(enabled, NULL); s->putBool(focused, NULL); s->putIntDec(options, 4, NULL); s->putIntDec(browse_idx, 4, NULL); s->putString(desc, NULL); put_bounds(s, &size); put_bounds(s, &vsize); s->putString(pal_class, NULL); s->putString(pal_name, NULL); s->putIntDec(growmode, 4, NULL);*/}void ht_view::unrelocate_to(ht_view *view){ Bounds b; view->getbounds(&b); b.x=-b.x; b.y=-b.y; move(b.x, b.y);}/* * CLASS ht_group */void ht_group::init(Bounds *b, int options, const char *desc){ first=0; current=0; last=0; ht_view::init(b, options, desc); VIEW_DEBUG_NAME("ht_group"); view_count=0; shared_data=0; growmode = MK_GM(GMH_FIT, GMV_FIT);}void ht_group::done(){ ht_view *a, *b; a=first; while (a) { b=a->next; a->done(); delete a; a=b; } ht_view::done();}int ht_group::childcount() const{ return view_count;}int ht_group::countselectables(){ int c=0; ht_view *v=first; while (v) { c+=v->countselectables(); v=v->next; } return c;}int ht_group::datasize(){ uint size=0; ht_view *v=first; while (v) { size+=v->datasize(); v=v->next; } return size;}int ht_group::enum_start(){ return -1;}ht_view *ht_group::enum_next(int *handle){ int lowest = 0x7fffffff; ht_view *view = 0; ht_view *v = first; while (v) { if (v->browse_idx > *handle && v->browse_idx < lowest) { lowest = v->browse_idx; view = v; } v = v->next; } *handle = lowest; return view;}bool ht_group::focus(ht_view *view){ ht_view *v = first; while (v) { if (v->focus(view)) { releasefocus(); current = v; putontop(v); receivefocus(); return true; } v = v->next; } return ht_view::focus(view);}bool ht_group::focusnext(){ if (!current) return false; int i = current->browse_idx; bool r = (options & VO_SELBOUND); ht_view *x = NULL; while (true) { i++; if (i > view_count-1) i=0; if (i == current->browse_idx) break; ht_view *y = get_by_browse_idx(i); if (y && (y->options & VO_SELECTABLE)) { x = y; break; } } if (i < current->browse_idx && !aclone() && !r) { return false; } if (x) { x->selectfirst(); focus(x); return true; } return r;}bool ht_group::focusprev(){ if (!current) return false; int i = current->browse_idx; bool r = (options & VO_SELBOUND); if (!i && !aclone() && !r) { return false; } while (true) { i--; if (i<0) i=view_count-1; if (i==current->browse_idx) break; ht_view *v=get_by_browse_idx(i); if (v && (v->options & VO_SELECTABLE)) { v->selectlast(); focus(v); return true; } } return r;}ht_view *ht_group::get_by_browse_idx(int i){ ht_view *v=first; while (v) { if (v->browse_idx==i) return v; v=v->next; } return 0;}void ht_group::getdata(ObjectStream &s){ ht_view *v; int h = enum_start(); while ((v = enum_next(&h))) { v->getdata(s); }}ht_view *ht_group::getselected(){ if (current) return current->getselected(); else return NULL;}ht_view *ht_group::getfirstchild(){ return first;}void ht_group::getminbounds(int *width, int *height){ ht_view::getminbounds(width, height); ht_view *v = first; while (v) { if (v->options & VO_RESIZE) { int w, h; v->getminbounds(&w, &h); w += v->size.x + size.w - (v->size.x + v->size.w); h += v->size.y + size.h - (v->size.y + v->size.h); uint gmh = GET_GM_H(v->growmode); uint gmv = GET_GM_V(v->growmode); if (gmh == GMH_FIT && w > *width) *width = w; if (gmv == GMV_FIT && h > *height) *height = h; } v = v->next; }}void ht_group::handlemsg(htmsg *msg){ if (!enabled) return; if (msg->type == mt_broadcast) { ht_view::handlemsg(msg); ht_view *v=first; while (v) { v->handlemsg(msg); v = v->next; } } else if (msg->type == mt_empty) { int msgtype = msg->type; ht_view *v; msg->type=mt_preprocess; v=first; while (v) { if (v->options & VO_PREPROCESS) { v->handlemsg(msg); } v=v->next; } msg->type=mt_empty; if (current) current->handlemsg(msg); msg->type=mt_postprocess; v=first; while (v) { if (v->options & VO_POSTPROCESS) { v->handlemsg(msg); } v=v->next; } msg->type=msgtype; ht_view::handlemsg(msg); } else if (msg->type == mt_preprocess) { ht_view *v; v=first; while (v) { if (v->options & VO_PREPROCESS) { v->handlemsg(msg); } v=v->next; } } else if (msg->type == mt_postprocess) { ht_view *v; v=first; while (v) { if (v->options & VO_POSTPROCESS) { v->handlemsg(msg); } v=v->next; } } if ((msg->type==mt_empty || msg->type==mt_broadcast) && (msg->msg == msg_keypressed)) { switch (msg->data1.integer) { case K_Left: case K_Shift_Tab: { if (focusprev()) { clearmsg(msg); dirtyview(); return; } break; } case K_Right: case K_Tab: { if (focusnext()) { clearmsg(msg); dirtyview(); return; } break; } } }}void ht_group::insert(ht_view *view){ if (current) current->releasefocus(); if (view->options & VO_PREPROCESS) setoptions(options | VO_PREPROCESS); if (view->options & VO_POSTPROCESS) setoptions(options | VO_POSTPROCESS); if (view->pal_class && pal_class && strcmp(view->pal_class, pal_class)==0) view->setpalette(pal_name); view->g_hdist=size.w - (view->size.x+view->size.w); view->g_vdist=size.h - (view->size.y+view->size.h); Bounds c; getbounds(&c); view->move(c.x, c.y); if (last) last->next=view; view->prev = last; view->next = NULL; last = view; if (!first) first = view; view->setgroup(this); view->browse_idx = view_count++; if (!current || (current && (!(current->options & VO_SELECTABLE)) && (view->options & VO_SELECTABLE))) { current = view; } if (current && (current->options & VO_SELECTABLE)) { if (focused) { focus(current); } else { select(current); } }}int ht_group::isaclone(ht_view *view){ ht_view *v = first; while (v) { if (v != view && v->countselectables()) return 0; v = v->next; } return 1;}int ht_group::isviewdirty(){ ht_view *v = first; while (v) { if (v->isviewdirty()) return 1; v = v->next; } return 0;}void ht_group::load(ObjectStream &f){}void ht_group::move(int rx, int ry){ ht_view::move(rx, ry); ht_view *v = first; while (v) { v->move(rx, ry); v = v->next; }}ObjectID ht_group::getObjectID() const{ return ATOM_HT_GROUP;}void ht_group::putontop(ht_view *view){ if (view->next) { if (view->prev) view->prev->next=view->next; else first=view->next; view->next->prev=view->prev; view->prev=last; view->next=0; last->next=view; last=view; }}void ht_group::receivefocus(){ ht_view::receivefocus(); if (current) current->receivefocus();}void ht_group::releasefocus(){ ht_view::releasefocus(); if (current) current->releasefocus();}void ht_group::remove(ht_view *view){ ht_view *n = view->next ? view->next : view->prev; if (n) { focus(n); } else { releasefocus(); current = NULL; } Bounds c; getbounds(&c); view->move(-c.x, -c.y); if (view->prev) view->prev->next = view->next; if (view->next) view->next->prev = view->prev; if (first == view) first = first->next; if (last == view) last = last->prev;}void ht_group::reorder_view(ht_view *v, int rx, int ry){ int px = 0, py = 0; int sx = 0, sy = 0; int gmv = GET_GM_V(v->growmode); int gmh = GET_GM_H(v->growmode); switch (gmh) { case GMH_LEFT: /* do nothing */ break; case GMH_RIGHT: px = rx; break; case GMH_FIT: sx = rx; break; } switch (gmv) { case GMV_TOP: /* do nothing */ break; case GMV_BOTTOM: py = ry; break; case GMV_FIT: sy = ry; break; } v->move(px, py); v->resize(sx, sy);}void ht_group::resize(int sx, int sy){ int min_width, min_height; getminbounds(&min_width, &min_height); if (size.w+sx <= min_width) sx = min_width - size.w; if (size.h+sy <= min_height) sy = min_height - size.h; ht_view::resize(sx, sy); ht_view *v = first; while (v) { reorder_view(v, sx, sy); v = v->next; }}int ht_group::select(ht_view *view){ ht_view *v = first; while (v) { if (v->select(view)) { current = v; putontop(v); return 1; } v=v->next; } return ht_view::select(view);}void ht_group::selectfirst(){ for (int i=0; i<view_count; i++) { ht_view *v=first; while (v) { if ((v->browse_idx==i) && (v->options & VO_SELECTABLE)) { select(v); return; } v=v->next; } }}void ht_group::selectlast(){ for (int i=view_count-1; i>=0; i--) { ht_view *v=first; while (v) { if ((v->browse_idx==i) && (v->options & VO_SELECTABLE)) { select(v); return; } v=v->next; } }}void ht_group::setdata(ObjectStream &s){ ht_view *v; int h=enum_start(); while ((v=enum_next(&h))) { v->setdata(s); }}void ht_group::setpalette(const char *pal_name){ ht_view *v=first; while (v) { if (strcmp(pal_class, v->pal_class)==0) v->setpalette(pal_name); v=v->next; } ht_view::setpalette(pal_name);}void ht_group::store(ObjectStream &s) const{ ht_view::store(s); PUTX_INT32D(s, childcount(), "childcount"); ht_view *v=first; while (v) { PUTX_OBJECT(s, v, "obj"); v=v->next; }}/* * CLASS ht_xgroup */void ht_xgroup::init(Bounds *b, int options, const char *desc){ ht_group::init(b, options, desc); VIEW_DEBUG_NAME("ht_xgroup"); first=0; current=0; last=0;}void ht_xgroup::done(){ ht_group::done();}int ht_xgroup::countselectables(){ return current->countselectables();}void ht_xgroup::handlemsg(htmsg *msg){ if ((msg->msg!=msg_draw) && (msg->type==mt_broadcast)) { ht_group::handlemsg(msg); } else { if (msg->msg==msg_complete_init) return; if (current) current->handlemsg(msg); ht_view::handlemsg(msg); }}int ht_xgroup::isaclone(ht_view *view){ if (group) return group->isaclone(this); return 0;}void ht_xgroup::load(ObjectStream &s){ ht_group::load(s);}ObjectID ht_xgroup::getObjectID() const{ return ATOM_HT_XGROUP;}void ht_xgroup::redraw(){ ht_view::redraw();/* no broadcasts. */ if (current) current->redraw();}void ht_xgroup::selectfirst(){ current->selectfirst();}void ht_xgroup::selectlast(){ current->selectlast();}void ht_xgroup::store(ObjectStream &s) const{ ht_group::store(s);}/* * CLASS ht_scrollbar */bool scrollbar_pos(sint64 start, sint64 size, sint64 all, int *pstart, int *psize){ if (!all) return false; if (start+size >= all) { if (size >= all) return false; *psize = (int)(((double)size)*100/all); *pstart = 100 - *psize; } else { *psize = (int)(((double)size)*100/all); *pstart = (int)(((double)start)*100/all); } return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -