Ignore:
Timestamp:
Mar 16, 2008, 2:17:43 AM (11 years ago)
Author:
Sam Hocevar
Message:
  • Simplified the window creation arguments. Got rid of a lot of macros and hid stuff in private namespaces.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Well, in the process of adding changes necessary to

handle recovery from alt-tabbing away from Abuse
(which is why I was updating jwindow::redraw()),
the entire windowing system is getting an overhaul.
It's gonna be sweet when I'm done, though.

  • jwindow::redraw() has been changed to a virtual

function requiring no parameters. This'll make
it much easier to implement special specific-
purpose windows.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/jwindow.cpp

    r109 r111  
    1818#include "jwindow.hpp"
    1919
    20 int jw_left=5,jw_right=5,jw_top=15,jw_bottom=5;
     20static int jw_left = 3, jw_right = 3, jw_top = 2, jw_bottom = 3;
    2121
    2222int frame_top() { return jw_top; }
     
    2525int frame_right() { return jw_right; }
    2626
     27//
     28//  Sets the size of the border around each window
     29//
    2730void set_frame_size(int x)
    2831
    29   if (x<1) x=1;
    30   jw_left=x;
    31   jw_right=x;
    32   jw_top=10+x;
    33   jw_bottom=x;
     32    if(x < 1)
     33        x = 1;
     34    jw_left = x;
     35    jw_right = x;
     36    jw_top = 2;
     37    jw_bottom = x;
    3438}
    3539
     
    5256void window_manager::close_window(jwindow *j)
    5357{
    54   jwindow *k;
    55   if (grab==j) grab=NULL;
    56   if (state==dragging && j==drag_window)  // close the window we were dragging
    57     state=inputing;
    58 
    59   if (j==first)
    60     first=first->next;
    61   else
    62   {
    63     for (k=first;k->next!=j;k=k->next)
    64       k->screen->add_dirty(j->x-k->x,j->y-k->y,
    65                    j->x+j->l-1-k->x,j->y+j->h-1-k->y);
    66     k->screen->add_dirty(j->x-k->x,j->y-k->y,
    67                    j->x+j->l-1-k->x,j->y+j->h-1-k->y);
    68     k->next=j->next;
    69   }
    70   screen->add_dirty(j->x,j->y,j->x+j->l-1,j->y+j->h-1);
    71   delete j;
     58    delete j;
    7259}
    7360
     
    243230  j->resize(l,h);
    244231  if (!frame_suppress)
    245   j->redraw(hi,med,low,frame_font());
     232  j->redraw();
    246233}
    247234
     
    260247                               int Med, int Low, JCFont *Font)
    261248{
    262   screen=Screen; hi=Hi; low=Low; med=Med; first=NULL; pal=Pal; grab=NULL;
    263   bk=pal->find_closest(0,0,0);
    264   state=inputing; fnt=Font;  wframe_fnt=Font;
    265   memset(key_state,0,sizeof(key_state));
    266   eh=new event_handler(screen,pal);
    267   frame_suppress=0;
    268 }
    269 
    270 jwindow *window_manager::new_window(int x, int y, int l, int h, ifield *fields, char const *Name)
    271 {
    272   if (x>screen->width()-4) x=screen->width()-25;
    273   if (y>screen->height()-4) y=screen->height()-10;
    274  
    275   jwindow *j=new jwindow(x,y,l,h,fields,Name),*k;
    276   j->show();
    277   if (!first)
    278     first=j;
    279   else
    280   {
    281     k=first;
    282     while (k->next) k=k->next;
    283     k->next=j;
    284     j->next=NULL;
    285   }
    286   if (!frame_suppress)
    287     j->redraw(hi,med,low,frame_font());
    288   return j;
     249    wm = this;
     250    screen = Screen;
     251    hi = Hi; low = Low; med = Med; first = NULL; pal = Pal; grab = NULL;
     252    bk = pal->find_closest(0, 0, 0);
     253    state = inputing; fnt = Font;  wframe_fnt = Font;
     254    memset(key_state, 0, sizeof(key_state));
     255    eh = new event_handler(screen, pal);
     256    frame_suppress = 0;
     257}
     258
     259window_manager::~window_manager()
     260{
     261    delete eh;
     262    while(first)
     263        close_window(first);
     264    wm = NULL;
     265}
     266
     267void window_manager::add_window(jwindow *win)
     268{
     269    if(!first)
     270        first = win;
     271    else
     272    {
     273        jwindow *tmp = first;
     274        while(tmp->next)
     275            tmp = tmp->next;
     276        tmp->next = win;
     277        win->next = NULL;
     278    }
     279}
     280
     281void window_manager::remove_window(jwindow *win)
     282{
     283    if(grab == win)
     284        grab = NULL;
     285
     286    // close the window we were dragging
     287    if(state == dragging && win == drag_window)
     288        state = inputing;
     289
     290    if(first == win)
     291        first = first->next;
     292    else
     293    {
     294        jwindow * search;
     295        for(search = first; search->next != win; search = search->next)
     296            search->screen->add_dirty(win->x - search->x,
     297                                      win->y - search->y,
     298                                      win->x + win->l - 1 - search->x,
     299                                      win->y + win->h - 1 - search->y);
     300        search->screen->add_dirty(win->x - search->x, win->y - search->y,
     301                                  win->x + win->l - 1 - search->x,
     302                                  win->y + win->h - 1 - search->y);
     303        search->next = win->next;
     304    }
     305
     306    screen->add_dirty(win->x, win->y, win->x + win->l - 1,
     307                      win->y + win->h - 1);
     308}
     309
     310jwindow * window_manager::new_window(int x, int y, int l, int h,
     311                                     ifield * fields, char const *name)
     312{
     313    if(x > screen->width () - 4)
     314        x = screen->width () - 25;
     315    if(y > screen->height () - 4)
     316        y = screen->height () - 10;
     317 
     318    jwindow * j = new jwindow (x, y, l, h, fields, name);
     319    j->show();
     320
     321    return j;
    289322}
    290323
     
    344377}
    345378
    346 jwindow::jwindow(int X, int Y, int L, int H, ifield *fields, char const *Name)
    347 {
     379jwindow::jwindow()
     380{
     381    _x1 = _y1 = _x2 = _y2 = 0;
     382    _hidden = true;
     383    _moveable = true;
     384    // property.flags = JWINDOW_NOAUTOHIDE_FLAG;
     385    inm = new input_manager (this, NULL);
     386    screen = NULL;
     387    _name = NULL;
     388    wm->add_window(this);
     389}
     390
     391jwindow::jwindow(int X, int Y, int L, int H, ifield *f, char const *name)
     392{
     393    l = 0;
     394    h = 0;
     395    _hidden = false;
     396    _moveable = true;
     397
     398    _x1 = left_border();
     399    _y1 = name ? top_border() : jw_top + 5;
     400
     401    screen = NULL;
     402    inm = new input_manager(screen, f);
     403    reconfigure(); /* FIXME: TODO */
     404
     405    l = L >= 0 ? L + left_border() : l - L;
     406    h = H >= 0 ? H + top_border() : h - H;
     407    //if (!f) { l+=WINDOW_FRAME_LEFT; h+=WINDOW_FRAME_TOP; }
     408    y = Y >= 0 ? Y : yres - h + Y - top_border() - bottom_border() - 1;
     409    x = X >= 0 ? X : xres - l + X - left_border() - right_border() - 1;
     410
     411    backg = wm->medium_color();
     412
     413    _x2 = l - 1;
     414    _y2 = h - 1;
     415    l += right_border();
     416    h += bottom_border();
     417
     418    if(L == -1)
     419        if(l < 15 + left_border() + right_border())
     420            l = 15 + left_border() + right_border();
     421    if(H == -1)
     422        if(h < top_border() + bottom_border())
     423            h = top_border() + bottom_border();
     424    screen = new image(l, h, NULL, 2);
     425    screen->clear(backg);
     426    // Keep this from getting destroyed when image list is cleared
     427    image_list.unlink(screen);
     428
     429    inm->screen = screen;
     430    next = NULL;
     431
     432    _name = NULL;
     433    if(name)
     434        _name = strcpy((char *)jmalloc(strlen(name) + 1,
     435                                       "jwindow::window name"), name);
     436
     437    wm->add_window(this);
     438    if(!wm->frame_suppress)
     439        redraw();
     440}
     441
     442jwindow::~jwindow()
     443{
     444    wm->remove_window(this);
     445    local_close();
     446    delete screen;
     447    delete inm;
     448    if(_name)
     449        jfree(_name);
     450}
     451
     452void jwindow::reconfigure()
     453{
     454    int x1, y1, x2, y2;
    348455    ifield *i;
    349     int x1, y1, x2, y2;
    350 
    351     l = 0; h = 0;
    352     hidden = false;
    353     moveable = true;
    354     if(fields)
    355         for(i = fields; i; i = i->next)
     456    l = 2;
     457    h = 2;
     458    for(i = inm->first; i; i = i->next)
     459    {
     460        i->set_owner(this);
     461        i->area(x1, y1, x2, y2);
     462        if ((int)y2 > (int)h)
     463            h = y2;
     464        if ((int)x2 > (int)l)
     465            l = x2;
     466    }
     467}
     468
     469void jwindow::local_close()
     470{
     471    ;
     472}
     473
     474void jwindow::redraw()
     475{
     476    int hi = wm->bright_color ();
     477    int med = wm->medium_color ();
     478    int low = wm->dark_color ();
     479    JCFont * fnt = wm->frame_font ();
     480
     481    if(_name)
     482    {
     483        if (right_border() >= 1)
    356484        {
    357             i->area(x1, y1, x2, y2);
    358             if ((int)y2 > (int)h)
    359                 h = y2 + 1;
    360             if ((int)x2 > (int)l)
    361                 l = x2 + 1;
     485            screen->wiget_bar (0, 0, l - 1, h - 1, hi, med, low);
     486            if (right_border() >= 3)
     487                screen->wiget_bar (right_border() - 1, top_border() - 1,
     488                                l - left_border(), h - bottom_border(), low,
     489                                med, hi);
     490         
     491          else
     492            screen->line (left_border() - 1, top_border() - 1,
     493                           right_border() - 1, top_border() - 1, low);
    362494        }
    363     else
    364     {
    365         l = 2;
    366         h = 2;
    367     }
    368 
    369     l = L > 0 ? L + jw_left : l - L;
    370     l += WINDOW_FRAME_RIGHT;
    371     if(l < 18)
    372         l = 18;
    373     h = H > 0 ? H + jw_top : h - h;
    374     h += WINDOW_FRAME_BOTTOM;
    375     if(h < 12)
    376         h = 12;
    377     //if (!fields) { l+=WINDOW_FRAME_LEFT; h+=WINDOW_FRAME_TOP; }
    378     y = Y >= 0 ? Y : yres - h + Y - WINDOW_FRAME_TOP - WINDOW_FRAME_BOTTOM - 1;
    379     x = X >= 0 ? X : xres - l + X - WINDOW_FRAME_LEFT - WINDOW_FRAME_RIGHT - 1;
    380 
    381     backg = wm->medium_color();
    382 
    383     screen=new image(l,h,NULL,2);
    384     l = screen->width();
    385     h = screen->height();
    386     screen->clear(backg);
    387     next = NULL;
    388     inm = new input_manager(screen, fields);
    389     if(Name == NULL)
    390         name = strcpy((char *)jmalloc(strlen(" ") + 1, "jwindow::window name"), " "); 
    391     else
    392         name = strcpy((char *)jmalloc(strlen(Name) + 1, "jwindow::window name"), Name);
    393 }
    394 
    395 void jwindow::local_close()
    396 {
    397     ;
    398 }
    399 
    400 void jwindow::redraw(int hi, int med, int low, JCFont *fnt)
    401 {
    402   if (jw_right>=3)
    403     screen->rectangle(0,0,l-3,h-3,low);
    404   if (jw_right>=2)
    405     screen->rectangle(1,1,l-2,h-2,med);
    406   if (jw_right>=1)
    407     screen->rectangle(2,2,l-1,h-1,hi);
    408 
    409 
     495      screen->rectangle (2, 2, top_border() - 2, top_border() - 3,
     496                           wm->black ());
     497      screen->wiget_bar (3, 3, top_border() - 3, top_border() - 4, hi, med, low);     // draws the 'close' button
     498    }
    410499 
    411   screen->wiget_bar(0,0,l-1,8,hi,med,low);
    412   screen->line(1,1,l-2,1,low);
    413   screen->line(1,3,l-2,3,low);
    414   screen->line(1,5,l-2,5,low);
    415   screen->line(1,7,l-2,7,low);
    416 
    417   screen->wiget_bar(4,3,10,5,hi,med,low);
    418   screen->rectangle(3,2,11,6,0); 
    419 
    420   screen->line(0,8,l-1,8,0);
    421   if (jw_right>=1)
    422     screen->wiget_bar(0,9,l-1,h-1,hi,med,low); 
    423     screen->wiget_bar(0,9,l-1,h-1,hi,med,low);
    424   if (jw_right>=2)
    425     screen->wiget_bar(4,13,l-jw_right,h-jw_right,low,med,hi);
    426 
    427 
    428   if (name && name[0] && (name[0]!=' ' || name[1]))
    429   {
    430     short cx1,cy1,cx2,cy2;
    431     screen->get_clip(cx1,cy1,cx2,cy2);
    432     screen->set_clip(14,1,l-2,WINDOW_FRAME_TOP-4);
    433     screen->bar(14,1,14+fnt->width()*strlen(name),15-8,med);
    434     fnt->put_string(screen,14,1,name,low); 
    435     screen->set_clip(cx1,cy1,cx2,cy2);
    436   }
    437  
    438   screen->bar(x1(),y1(),x2(),y2(),backg);
    439   inm->redraw();
     500  else
     501    {
     502      if (right_border() >= 1)
     503        {
     504          screen->wiget_bar (0, 0, l - 1, h - 1, hi, med, low);
     505          if (right_border() >= 3)
     506            screen->wiget_bar (right_border() - 1, jw_top + 4,
     507                                l - left_border(), h - bottom_border(), low,
     508                                med, hi);
     509         
     510          else
     511            screen->line (left_border() - 1, jw_top + 4, right_border() - 1,
     512                           jw_top + 4, low);
     513        }
     514      screen->rectangle (1, 1, 4, 4, wm->black ());
     515      screen->wiget_bar (2, 2, 3, 3, hi, med, low);   // draws the 'close' button
     516    }
     517  if (_name && _name[0])
     518    {
     519      screen->bar (top_border(), 1,
     520                    top_border() + fnt->width () * strlen (_name) + 1,
     521                    top_border() - 2, med);
     522      fnt->put_string (screen, top_border() + 1, 1, _name, low);
     523    }
     524  screen->bar (x1 (), y1 (), x2 (), y2 (), backg);  // clear 'client' region
     525  inm->redraw ();
     526}
     527
     528int jwindow::left_border()
     529{
     530    return frame_left();
     531}
     532
     533int jwindow::right_border()
     534{
     535    return frame_right();
     536}
     537
     538int jwindow::top_border()
     539{
     540    return wm->font()->height() + frame_top();
     541}
     542
     543int jwindow::bottom_border()
     544{
     545    return frame_bottom();
    440546}
    441547
Note: See TracChangeset for help on using the changeset viewer.