/* These functions must be implemented by any appliation that wishes
to use this module */
void onshutdown(void);
-void onfocus(bool focused);
void onupdate(void);
-void onlayout(void);
-void onscroll(double percent);
void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col);
void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col);
void onmouseright(WinRegion id, bool pressed, size_t row, size_t col);
int clreditnor = (Regions[EDIT].clrnor.bg << 8 | Regions[EDIT].clrnor.fg);
int clreditsel = (Regions[EDIT].clrsel.bg << 8 | Regions[EDIT].clrsel.fg);
view_update(win_view(EDIT), clreditnor, clreditsel, &(Regions[EDIT].csrx), &(Regions[EDIT].csry));
- onlayout(); // Let the user program update the scroll bar
+
+ /* calculate and update scroll region */
+ View* view = win_view(EDIT);
+ size_t bend = buf_end(win_buf(EDIT));
+ if (bend == 0) bend = 1;
+ if (!view->rows) return;
+ size_t vbeg = view->rows[0]->off;
+ size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
+ double scroll_vis = (double)(vend - vbeg) / (double)bend;
+ double scroll_off = ((double)vbeg / (double)bend);
+ win_setscroll(scroll_off, scroll_vis);
int clr_hbor = Colors[ClrBorders].bg;
int clr_vbor = Colors[ClrBorders].bg;
CPair clr_scroll = Colors[ClrScrollNor];
-
for (int i = 0; i < SCROLL; i++) {
View* view = win_view(i);
x11_draw_rect(Regions[i].clrnor.bg, 0, Regions[i].y - 3, width, Regions[i].height + 8);
}
-static void scroll_actions(int btn, bool pressed, int x, int y) {
- size_t row = (y-Regions[SCROLL].y) / x11_font_height(CurrFont);
- switch (btn) {
- case MouseLeft:
- if (pressed)
- view_scroll(win_view(EDIT), -row);
- break;
- case MouseMiddle:
- if (pressed)
- onscroll((double)(y - Regions[SCROLL].y) /
- (double)(Regions[SCROLL].height - Regions[SCROLL].y));
- break;
- case MouseRight:
- if (pressed)
- view_scroll(win_view(EDIT), +row);
- break;
- case MouseWheelUp:
- view_scroll(win_view(EDIT), -ScrollBy);
- break;
- case MouseWheelDn:
- view_scroll(win_view(EDIT), +ScrollBy);
- break;
- }
-}
-
static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols) {
XGlyphSpec specs[rlen];
size_t i = 0;
static void xfocus(XEvent* e) {
if (X.xic)
(e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic);
- onfocus(e->type == FocusIn);
+ Buf* buf = win_buf(EDIT);
+ if (buf->path && buf->modtime != modtime(buf->path))
+ buf->errfn("File modified externally: {SaveAs } Overwrite Reload");
}
static void xkeypress(XEvent* e) {
before = now;
}
-static bool changed_externally(Buf* buf) {
- if (!buf->path) return false;
- bool modified = (buf->modtime != modtime(buf->path));
- if (modified)
- ondiagmsg("File modified externally: {SaveAs } Overwrite Reload");
- return modified;
-}
-
static void put(char* arg) {
trim_whitespace(arg);
win_save(arg);
{ 0, 0, 0 }
};
-void onscroll(double percent) {
- size_t bend = buf_end(win_buf(EDIT));
- size_t off = (size_t)((double)bend * percent);
- view_scrollto(win_view(EDIT), (off >= bend ? bend : off));
-}
-
-void onfocus(bool focused) {
- /* notify the user if the file has changed externally */
- if (focused)
- (void)changed_externally(win_buf(EDIT));
-}
-
-void onlayout(void) {
- /* calculate and update scroll region */
- View* view = win_view(EDIT);
- size_t bend = buf_end(win_buf(EDIT));
- if (bend == 0) bend = 1;
- if (!view->rows) return;
- size_t vbeg = view->rows[0]->off;
- size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
- double scroll_vis = (double)(vend - vbeg) / (double)bend;
- double scroll_off = ((double)vbeg / (double)bend);
- win_setscroll(scroll_off, scroll_vis);
-}
-
void onshutdown(void) {
quit(0);
}