initiaql check-in, moved repository -- no-longer a fork of

haikuarchives/yab
This commit is contained in:
Jim
2015-04-13 13:40:27 -07:00
parent 9e266ef95f
commit 3e33065a02
234 changed files with 77847 additions and 1 deletions

252
src/CalendarControl.cpp Normal file
View File

@@ -0,0 +1,252 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Updated for Haiku and removed all stuff that is not needed and refactored by jan__64 2009
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#define __LANG_ENGLISH // to compile english version
#include "CalendarControl.h"
#define myButtonMessage 'DCBP'
#include "DateTextView.cpp"
#include "MonthWindow.cpp"
#include <AppFileInfo.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <Point.h>
#include <ControlLook.h>
CalendarControl::CalendarControl(BPoint p, const char* name, int day, int month, int year, uint32 flags, uint32 look)
:BControl(BRect(100,100,200,200),name, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW)
{
uint32 divider=look & CC_ALL_DIVIDERS;
myDateTextView = new DateTextView(day,month,year,flags,divider);
myButton = new CalendarButton(BRect(70,0,85,15), "CalendarButton", "", new BMessage(myButtonMessage), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
myOrigin = p;
AddChild(myDateTextView);
myDateTextView->MoveTo(3,3);
ResizeTo(myDateTextView->Bounds().Width()+6,myDateTextView->Bounds().Height()+7);
AddChild(myButton);
myButton->ResizeTo(Bounds().Height()*0.7,Bounds().Height()-1);
myButton->MoveTo(Bounds().right+1, Bounds().top);
ResizeBy(myButton->Bounds().Width()+1, 0);
}
CalendarControl::~CalendarControl()
{
RemoveChild(myDateTextView);
delete myDateTextView;
RemoveChild(myButton);
delete myButton;
}
void CalendarControl::AttachedToWindow(void)
{
BControl::AttachedToWindow();
myButton->SetTarget(this);
if(Parent()!=NULL)
view_color=Parent()->ViewColor();
else
view_color.red=view_color.green=view_color.blue=view_color.alpha=255;
SetViewColor(view_color); // function of CalendarControl class
// MakeButton(); // for BeOS interface is called only from here,
MoveTo(myOrigin);
}
void CalendarControl::Draw(BRect r)
{
BRect bounds(Bounds());
bounds.bottom--;
bounds.right = myButton->Frame().left - 1;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
bool active = myDateTextView->IsFocus() && Window()->IsActive();
uint32 flags = 0;
if (!IsEnabled())
flags |= BControlLook::B_DISABLED;
if (active)
flags |= BControlLook::B_FOCUSED;
be_control_look->DrawTextControlBorder((BView*)this, bounds, r, base, flags, 15);
}
void CalendarControl::KeyDown(const char *bytes, int32 numBytes)
{
BControl::KeyDown(bytes, numBytes);
if(bytes[0]==B_TAB) Draw(Bounds());
}
void CalendarControl::MakeFocus(bool focused)
{
myDateTextView->MakeFocus(focused);
}
void CalendarControl::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
case myButtonMessage:
{
if(IsEnabled())
{
MakeFocus(true);
int day, month, year;
int first_year, last_year;
GetDate(&day, &month, &year);
GetYearRange(&first_year, &last_year);
new MonthWindow(ConvertToScreen(BPoint(Bounds().left+1,Bounds().bottom+1)),
new BMessenger(this), day, month, year, first_year, last_year);
}
break;
}
case 'MVME': // message has come from window with calendar
{
int32 day, month, year;
msg->FindInt32("day",&day);
msg->FindInt32("month",&month);
msg->FindInt32("year",&year);
SetDate((int)day, (int)month, (int)year);
break;
}
default:
BControl::MessageReceived(msg);
}
}
void CalendarControl::SetEnabled(bool enabled)
{
if(enabled==IsEnabled()) return;
BControl::SetEnabled(enabled);
myButton->SetEnabled(enabled);
myDateTextView->SetEnabled(enabled);
Invalidate();
}
void CalendarControl::SetViewColor(rgb_color color)
{
view_color=color;
BControl::SetViewColor(view_color);
Draw(Bounds());
Invalidate();
}
void CalendarControl::SetViewColor(uchar red, uchar green,
uchar blue, uchar alpha)
{
rgb_color color={red, green, blue, alpha};
SetViewColor(color);
}
void CalendarControl::WindowActivated(bool active)
{
myWindowActive = active; // true if window where control is placed is active
Draw(Bounds());
}
const char* CalendarControl::Text() const
{
return myDateTextView->Text();
}
void CalendarControl::GetDate(int *day, int *month, int *year)
{
myDateTextView->GetDate(day,month,year);
}
void CalendarControl::SetDate(int day, int month, int year)
{
myDateTextView->SetDate(day,month,year);
}
void CalendarControl::SetDate(const char *tdate)
{
myDateTextView->SetDate(tdate);
}
void CalendarControl::GetYearRange(int *first_year, int *last_year)
{
myDateTextView->GetYearRange(first_year, last_year);
}
uint32 CalendarControl::GetLook()
{
return (myDateTextView->GetDivider());
}
void CalendarControl::SetLook(uint32 look)
{
myDateTextView->SetDivider(look & CC_ALL_DIVIDERS);
}
uint32 CalendarControl::GetFlags()
{
return myDateTextView->GetDateFlags();
}
void CalendarControl::SetFlags(uint32 flags)
{
myDateTextView->SetDateFlags(flags);
}
BTextView *CalendarControl::TextView(void) const
{
return (BTextView *)myDateTextView;
}
void CalendarButton::Draw(BRect update)
{
BButton::Draw(update);
BRect rect = Bounds();
rect.InsetBy(2.0,4.0);
uint32 flags = 0;
rgb_color base = ui_color(B_PANEL_TEXT_COLOR);
float tint = B_NO_TINT;
if(!IsEnabled())
{
tint = B_LIGHTEN_MAX_TINT;
flags |= BControlLook::B_DISABLED;
}
be_control_look->DrawArrowShape(this, rect, update, base, 3, flags, tint);
}

97
src/CalendarControl.h Normal file
View File

@@ -0,0 +1,97 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <Control.h>
#include <PictureButton.h>
#include <Button.h>
#include <TextView.h>
class DateTextView;
class CalendarButton : public BButton
{
public:
CalendarButton(BRect frame, const char* name, const char* label,
BMessage* message, uint32 resizingMode, uint32 flags)
: BButton(frame, name, label, message, resizingMode, flags)
{};
~CalendarButton() {};
void Draw(BRect update);
};
// Formats of date
enum date_format {
CC_DD_MM_YYYY_FORMAT = 0,
CC_MM_DD_YYYY_FORMAT
};
enum full_short_year {
CC_FULL_YEAR = 0, // DD.MM.YYYY
CC_SHORT_YEAR = 8 // DD.MM.YY
};
enum century_begin {
CC_FULL_CENTURY = 0, // first year is first year of century (01-00)
CC_HALF_CENTURY = 16 // first year is 51th year of century (51-50)
};
enum divider_format {
CC_DOT_DIVIDER = 0, // .
CC_SLASH_DIVIDER, // /
CC_MINUS_DIVIDER, // -
CC_ALL_DIVIDERS // 2 bits, and some one bit is reserved
};
class CalendarControl: public BControl
{
public:
CalendarControl(BPoint p,
const char* name,
int day=0,
int month=0,
int year=0,
uint32 flags=CC_DD_MM_YYYY_FORMAT | CC_FULL_YEAR,
uint32 look=CC_DOT_DIVIDER);
~CalendarControl();
virtual void AttachedToWindow(void);
virtual void Draw(BRect r);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MakeFocus(bool focused=true);
virtual void MessageReceived(BMessage *msg);
virtual void SetEnabled(bool enabled);
virtual void SetViewColor(rgb_color color);
void SetViewColor(uchar red, uchar green, uchar blue, uchar alpha=255);
virtual void WindowActivated(bool active);
void GetDate(int *day, int *month, int *year);
void SetDate(int day=0, int month=0, int year=0);
void SetDate(const char *tdate);
void GetYearRange(int *first_year, int *last_year);
uint32 GetLook();
void SetLook(uint32 look);
uint32 GetFlags();
void SetFlags(uint32 flags);
const char* Text() const;
BTextView *TextView(void) const;
const char* Version();
private:
void MakeButton();
DateTextView *myDateTextView;
CalendarButton *myButton;
bool myWindowActive;
BPoint myOrigin;
rgb_color view_color;
};

2293
src/ControlLook.cpp Normal file

File diff suppressed because it is too large Load Diff

620
src/DateTextView.cpp Normal file
View File

@@ -0,0 +1,620 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <Clipboard.h>
#include <InterfaceDefs.h>
#include <Rect.h>
#include <String.h>
#include <TextView.h>
#include <stdlib.h>
#include <time.h>
#define LAST_FORMAT 1 // quantity of formats - 1
#define LAST_DIVIDER 2 // quantity of dividers - 1
class DateTextView: public BTextView
{
public:
DateTextView(int day, int month, int year, uint32 flags, uint32 look);
virtual void Cut(BClipboard *clip);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MakeFocus(bool focused);
virtual void Paste(BClipboard *clip);
virtual void SetEnabled(bool enabled);
void GetDate(int *day, int *month, int *year);
void SetDate(int day, int month, int year);
void SetDate(const char *tdate);
void GetYearRange(int *first_year, int *last_year);
uint32 GetDivider();
void SetDivider(uint32 dvder);
uint32 GetDateFlags();
void SetDateFlags(uint32 flags);
protected:
virtual void DeleteText(int32 start, int32 finish);
private:
virtual bool AcceptsDrop(const BMessage *message);
virtual bool AcceptsPaste(BClipboard *clip);
void DrawDate(int day, int month, int year);
bool VerifyDate(int *day, int *month, int *year);
bool is_ins; // is it necessar to insert symbol
uint32 flags;
char *div[LAST_DIVIDER+1]; // сstrings of dividers
uint32 divider;
bool enabled;
int first_year;
int last_year; // first and last year which control accepts
int textlen; // length of text string (10 or 8 symbols)
uint32 interface; // the same as control variable
};
//////////////////////////////////////////////////////////////////////////
DateTextView::DateTextView(int day, int month, int year,
uint32 flags, uint32 look)
:BTextView(BRect(0,0,110,15),"DateTextViewAViX",
BRect(0,0,110,15),B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE)
{
enabled=true;
is_ins=false;
interface=look;
div[0]=(char*)".";
div[1]=(char*)"/";
div[2]=(char*)"-";
divider=look & CC_ALL_DIVIDERS;
if(divider>LAST_DIVIDER || divider<0) divider=0; // index of divider
this->flags=(flags & (LAST_FORMAT | CC_SHORT_YEAR | CC_HALF_CENTURY));
if((this->flags & (CC_SHORT_YEAR | CC_HALF_CENTURY))==CC_HALF_CENTURY)
this->flags=this->flags^CC_HALF_CENTURY; // XOR; CC_FULL_YEAR and CC_HALF_CENTURY
// at the same time may not be used
first_year=1;
last_year=9999;
if((this->flags & CC_SHORT_YEAR)==CC_SHORT_YEAR)
{
textlen=8;
// Changing first and last acceptable years
// Working in range of century defined by year variable
if(year<first_year || year>last_year)
{
// Range is set relative to today's year
struct tm *dat;
time_t tmp;
time(&tmp);
dat=localtime(&tmp);
year=dat->tm_year+1900; // today's year
}
first_year=(year/100)*100+1; // dividing with loosing rest
last_year=first_year+99;
if(last_year==10000) last_year--; // full century
if((this->flags & CC_HALF_CENTURY)==CC_HALF_CENTURY)
{
if(year<51 || year>9950)
this->flags=this->flags^CC_HALF_CENTURY; // HALF_CENTURY may nor be set
else
{
if((year%100)>50)
{
first_year+=50;
last_year+=50;
}
else
{
first_year-=50;
last_year-=50;
}
}
}
}
else textlen=10; // length of text string
SetDate(day,month,year);
float width=0;
BString s("");
for(char i='0'; i<='9'; i++)
{
s<<i;
if(StringWidth(s.String())>width) width=StringWidth(s.String());
s.SetTo("");
}
ResizeTo(width*(textlen-2)+StringWidth("/")*2.5, LineHeight()-1);
SetWordWrap(false);
SetMaxBytes(textlen);
SetTextRect(Bounds());
SetDoesUndo(false);
for(int32 i=0;i<256;i++) DisallowChar(i);
for(int32 i='0';i<='9';i++) AllowChar(i);
}
///////////////////////////////////////////////////////
bool DateTextView::AcceptsDrop(const BMessage *message)
{
return false;
}
/////////////////////////////////////////////////
bool DateTextView::AcceptsPaste(BClipboard *clip)
{
return false;
}
////////////////////////////////////////
void DateTextView::Cut(BClipboard *clip)
{
Copy(clip);
}
////////////////////////////////////////////////////////
void DateTextView::DeleteText(int32 start, int32 finish)
{
BTextView::DeleteText(start,finish);
if(is_ins)
{
if(start==2 || start==5) InsertText(div[divider],1,start,NULL);
else InsertText("0",1,start,NULL);
}
}
/////////////////////////////////////////////////////////////
void DateTextView::KeyDown(const char *bytes, int32 numBytes)
{
if(!enabled) if(bytes[0]!=B_TAB) return;
int32 i1,i2;
GetSelection(&i1,&i2);
if(bytes[0]>='0' && bytes[0]<='9')
{
if(i1>(textlen-1)) return; // not to insert after end of string
Select(i1,i1);
if(i1==2 || i1==5)
{
i1++;
Select(i1,i1);
}
DeleteText(i1,i1+1);
BTextView::KeyDown(bytes, numBytes);
}
else if(bytes[0]==B_DELETE)
{
if(i1>(textlen-1)) return; // not to insert after end of string
Select(i1,i1);
is_ins=true; // symbol "0" or divider will be inserted
BTextView::KeyDown(bytes, numBytes);
is_ins=false;
}
else if(bytes[0]==B_BACKSPACE)
{
Select(i1,i1);
is_ins=true;
BTextView::KeyDown(bytes, numBytes);
is_ins=false;
}
else if(bytes[0]==B_TAB)
{
Parent()->KeyDown(bytes, numBytes);
}
else if(bytes[0]==B_DOWN_ARROW)
{
// Is Ctrl+DownArrow pressed?
if(modifiers() & B_CONTROL_KEY)
{
// yes
BMessage msg(myButtonMessage);
Parent()->MessageReceived(&msg);
}
else
BTextView::KeyDown(bytes, numBytes);
}
else
BTextView::KeyDown(bytes, numBytes);
}
///////////////////////////////////////////////
void DateTextView::MakeFocus(bool focused=true)
{
BTextView::MakeFocus(focused);
int day, month, year;
GetDate(&day, &month, &year);
Parent()->Draw(Parent()->Bounds());
}
//////////////////////////////////////////
void DateTextView::Paste(BClipboard *clip)
{
return;
}
///////////////////////////////////////////
void DateTextView::SetEnabled(bool enabled)
{
this->enabled=enabled;
SetFlags(Flags()^B_NAVIGABLE);
MakeEditable(enabled);
BFont font;
rgb_color color;
GetFontAndColor((int32) 0, &font, &color);
color.alpha=0;
if(enabled)
{
SetViewColor(255,255,255,255);
color.red=color.green=color.blue=0;
}
else
{
SetViewColor(239,239,239,255);
color.red=color.green=color.blue=128;
}
SetFontAndColor(&font,B_FONT_ALL,&color);
Invalidate();
}
/////////////////////////////////////////////////////////
void DateTextView::DrawDate(int day, int month, int year)
{
// It is assumed that date is correct
BString s;
s.SetTo("");
if(!((flags & CC_MM_DD_YYYY_FORMAT)==CC_MM_DD_YYYY_FORMAT))
{
if(day<10) s.Append("0");
s<<day;
s.Append(div[divider]);
if(month<10) s.Append("0");
s<<month;
}
else // CC_MM_DD_YYYY_FORMAT
{
if(month<10) s.Append("0");
s<<month;
s.Append(div[divider]);
if(day<10) s.Append("0");
s<<day;
}
s.Append(div[divider]);
if((flags & CC_SHORT_YEAR)==CC_SHORT_YEAR)
{
int year1=year%100;
if(year1<10) s.Append("0");
s<<year1;
}
else // FULL_YEAR
{
if(year<10) s.Append("000");
else if(year<100) s.Append("00");
else if(year<1000) s.Append("0");
s<<year;
}
SetText(s.String());
}
///////////////////////////////////////////////////////////
void DateTextView::GetDate(int *day, int *month, int *year)
{
int mday=*day;
int mmonth=*month;
int myear=*year;
BString s(Text());
char n1[11];
char n2[11];
char n3[11];
s.CopyInto(n1,0,2);
n1[2]='\0';
s.CopyInto(n2,3,2);
n2[2]='\0';
if((flags & CC_SHORT_YEAR)==CC_SHORT_YEAR)
{
s.CopyInto(n3,6,2);
n3[2]='\0';
}
else // FULL_YEAR
{
s.CopyInto(n3,6,4);
n3[4]='\0';
}
if(!((flags & CC_MM_DD_YYYY_FORMAT)==CC_MM_DD_YYYY_FORMAT))
{
mday=atoi(n1);
mmonth=atoi(n2);
}
else
{
mday=atoi(n2);
mmonth=atoi(n1);
}
myear=atoi(n3);
if((flags & CC_SHORT_YEAR)==CC_SHORT_YEAR)
{
if((flags & CC_HALF_CENTURY)==CC_HALF_CENTURY)
{
if(myear<51) myear+=50; else myear-=50;
}
else if(myear==0) myear=100;
myear+=(first_year-1);
}
if(!VerifyDate(&mday,&mmonth,&myear)) SetDate(mday,mmonth,myear);
*day=mday;
*month=mmonth;
*year=myear;
return;
}
////////////////////////////////////////////////////////
void DateTextView::SetDate(int day, int month, int year)
{
int mday=day;
int mmonth=month;
int myear=year;
VerifyDate(&mday, &mmonth, &myear);
DrawDate(mday, mmonth, myear);
}
/////////////////////////////////////////////
void DateTextView::SetDate(const char *tdate)
{
// Almost the same as GetDate. May be to combine them.
// Changes text using current settings of control.
int day;
int month;
int year;
int k;
bool short_year=false;
if((flags & CC_SHORT_YEAR)==CC_SHORT_YEAR) short_year=true;
char n1[3]="00";
char n2[3]="00";
char n3[5]="0000";
if(short_year) n3[2]='\0';
bool zero=false; // was the end of tdate string?
int c=0;
while (!(c==2 || zero))
{
if(tdate[c]=='\0') zero=true;
else n1[c]=tdate[c];
c++;
}
if(zero) goto L1;
if(tdate[2]=='\0') goto L1;
c=0;
while (!(c==2 || zero))
{
if(tdate[c+3]=='\0') zero=true;
else n2[c]=tdate[c+3];
c++;
}
if(zero) goto L1;
if(tdate[5]=='\0') goto L1;
k=short_year ? 2 : 4;
c=0;
while (!(c==k || zero))
{
if(tdate[c+6]=='\0') zero=true;
else n3[c]=tdate[c+6];
c++;
}
L1:
if(!((flags & CC_MM_DD_YYYY_FORMAT)==CC_MM_DD_YYYY_FORMAT))
{
day=atoi(n1);
month=atoi(n2);
}
else
{
day=atoi(n2);
month=atoi(n1);
}
year=atoi(n3);
if(short_year)
{
if((flags & CC_HALF_CENTURY)==CC_HALF_CENTURY)
{
if(year<51) year+=50; else year-=50;
}
else if(year==0) year=100;
year+=(first_year-1);
}
SetDate(day,month,year);
}
//////////////////////////////////////////////////////////////
bool DateTextView::VerifyDate(int *day, int *month, int *year)
{
// Function verifies date to be correct and changes it if it's needed
// Returns true if date was correct (and wasn't changed)
struct tm *dat;
time_t tmp;
time(&tmp);
dat=localtime(&tmp);
bool flag=true; // date is correct
if((flags & CC_SHORT_YEAR)==CC_SHORT_YEAR)
{
if(*year<first_year || *year>last_year)
{
int year1=*year%100;
if((flags & CC_HALF_CENTURY)==CC_HALF_CENTURY)
{
if(year1<51) year1+=50; else year1-=50;
}
else if(year1==0) year1=100;
*year=year1+first_year-1;
flag=false;
}
}
else // FULL_YEAR
{
if(*year<1 || *year>9999)
{
*year=dat->tm_year+1900;
flag=false;
}
}
if(*month<1 || *month>12)
{
*month=dat->tm_mon+1;
flag=false;
}
if(*day<1 || *day>31)
{
*day=dat->tm_mday;
flag=false;
}
if((*month==4 || *month==6 || *month==9 || *month==11) && *day>30)
{
if((*day=dat->tm_mday)>30) *day=30;
flag=false;
}
else if (*month==2)
{
int tmpday;
if((*year)%4==0) // leap year?
{
if((*year)%100==0 && (*year)%400!=0) tmpday=28; // no
else tmpday=29; // yes
}
else tmpday=28;
if(*day>tmpday)
{
if((*day=dat->tm_mday)>tmpday) *day=tmpday;
flag=false;
}
}
return flag;
}
////////////////////////////////////////////////////////////////
void DateTextView::GetYearRange(int *first_year, int *last_year)
{
*first_year=this->first_year;
*last_year=this->last_year;
}
/////////////////////////////////
uint32 DateTextView::GetDivider()
{
return divider;
}
///////////////////////////////////////////
void DateTextView::SetDivider(uint32 dvder)
{
if(dvder<0 || dvder>LAST_DIVIDER) dvder=0;
BString s(Text());
SetText((s.ReplaceAll(div[divider],div[dvder])).String());
this->divider=dvder;
}
///////////////////////////////////
uint32 DateTextView::GetDateFlags()
{
return flags;
}
///////////////////////////////////////////
void DateTextView::SetDateFlags(uint32 fmt)
{
int mday, mmonth, myear;
GetDate(&mday, &mmonth, &myear);
// Blocking changing of parameters of year
// (full/short year, full/half century)
fmt=fmt & 0xFFE7;
if(fmt<0 || fmt>LAST_FORMAT) fmt=0;
flags=fmt | (flags & 0xFFFE); // LAST_FORMAT==1, 1 bit
SetDate(mday, mmonth, myear);
}

129
src/Makefile Normal file
View File

@@ -0,0 +1,129 @@
##
## yab Haiku Makefile
##
## (c) Jan Bungeroth 2009 - 2012
## Artistic License.
##
## Use
## make
## to compile yab for Haiku.
##
## Needs a valid installation of at least: gcc, flex, bison, perl, ncurses
##
##
## Haiku stuff
##
HAIKUTAB = YabTabView.o
HAIKUOPT = -DHAIKU -DLIBRARY_PATH=\"`finddir B_USER_SETTINGS_DIRECTORY`/yab\"
##
## Use our own column list view
##
COLUMN = column/ColumnListView.o
##
## enable debug
##
# DBG = -g
#
##
## enable optimization
##
OPT = -O
#
##
## GCC Options
##
GCC = gcc
GCC_OPT = $(DBG) $(OPT) -I. -I/boot/home/config/include/ -I/boot/home/config/include/ncurses/ -DHAVE_CONFIG -DUNIX $(HAIKUOPT)
GPP = g++
GPP_OPT = $(DBG) $(OPT) -I. -DHAVE_CONFIG -DUNIX $(HAIKUOPT)
##
## Libraries
##
##LIBPATH = -L/boot/home/config/lib
LIBPATHS = $(shell findpaths B_FIND_PATH_LIB_DIRECTORY)
LIBPATH=$(addprefix -L,$(LIBPATHS))
##LIBPATH = -L`finddir B_SYSTEM_LIB_DIRECTORY` ##/boot/system/lib
LIB = -lbe -lroot -ltranslation -ltracker -lmedia
## flags for flex (-d for debugging)
FLEXFLAGS = -i -I -L -s
## flags for bison (-t -v for debugging)
BISONFLAGS = -d -l -t -v
##
## Compile and link
##
yab: YabMain.o YabInterface.o YabWindow.o YabView.o YabBitmapView.o YabFilePanel.o YabFilePanelLooper.o YabList.o \
YabText.o flex.o bison.o symbol.o function.o graphic.o io.o main.o $(COLUMN) column/YabColumnType.o column/ColorTools.o YabStackView.o SplitPane.o URLView.o YabControlLook.o \
$(HAIKUTAB) Spinner.o column/ColumnListView.o CalendarControl.o
$(GPP) $(GPP_OPT) -o yab YabMain.o YabInterface.o YabWindow.o YabView.o YabBitmapView.o YabText.o YabFilePanel.o \
YabFilePanelLooper.o YabList.o main.o function.o io.o graphic.o symbol.o bison.o flex.o $(COLUMN) column/YabColumnType.o column/ColorTools.o \
YabStackView.o SplitPane.o URLView.o YabControlLook.o $(HAIKUTAB) Spinner.o $(TABLIB) CalendarControl.o \
$(LIBPATH) $(LIB)
YabMain.o: YabMain.cpp
$(GPP) $(GPP_OPT) -c YabMain.cpp -o YabMain.o
YabInterface.o: YabInterface.cpp YabInterface.h YabMenu.h
$(GPP) $(GPP_OPT) -c YabInterface.cpp -o YabInterface.o
YabWindow.o: YabWindow.cpp YabWindow.h
$(GPP) $(GPP_OPT) -c YabWindow.cpp -o YabWindow.o
YabView.o: YabView.cpp YabView.h
$(GPP) $(GPP_OPT) -c YabView.cpp -o YabView.o
YabBitmapView.o: YabBitmapView.cpp YabBitmapView.h
$(GPP) $(GPP_OPT) -c YabBitmapView.cpp -o YabBitmapView.o
YabFilePanel.o: YabFilePanel.cpp YabFilePanel.h
$(GPP) $(GPP_OPT) -c YabFilePanel.cpp -o YabFilePanel.o
YabFilePanelLooper.o: YabFilePanelLooper.cpp YabFilePanelLooper.h
$(GPP) $(GPP_OPT) -c YabFilePanelLooper.cpp -o YabFilePanelLooper.o
YabList.o: YabList.cpp YabList.h
$(GPP) $(GPP_OPT) -c YabList.cpp -o YabList.o
YabText.o: YabText.cpp YabText.h
$(GPP) $(GPP_OPT) -c YabText.cpp -o YabText.o
bison.o: bison.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c bison.c -o bison.o
flex.o: flex.c bison.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c flex.c -o flex.o
function.o: function.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c function.c -o function.o
io.o: io.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c io.c -o io.o
graphic.o: graphic.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c graphic.c -o graphic.o
symbol.o: symbol.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c symbol.c -o symbol.o
main.o: main.c yabasic.h config.h
$(GCC) $(GCC_OPT) -c main.c -o main.o
flex.c: yabasic.flex
flex $(FLEXFLAGS) -t yabasic.flex >flex.c
bison.c: yabasic.bison
bison $(BISONFLAGS) --output-file bison.c yabasic.bison
YabStackView.o: YabStackView.cpp YabStackView.h
$(GPP) $(GPP_OPT) -c YabStackView.cpp -o YabStackView.o
SplitPane.o: SplitPane.cpp SplitPane.h
$(GPP) $(GPP_OPT) -c SplitPane.cpp -o SplitPane.o
URLView.o: URLView.cpp URLView.h
$(GPP) $(GPP_OPT) -c URLView.cpp -o URLView.o
Spinner.o: Spinner.cpp Spinner.h
$(GPP) $(GPP_OPT) -c Spinner.cpp -o Spinner.o
column/ColumnListView.o: column/ColumnListView.cpp column/ColumnListView.h column/ObjectList.h
$(GPP) $(GPP_OPT) -c column/ColumnListView.cpp -o column/ColumnListView.o
column/ColorTools.o: column/ColorTools.cpp column/ColorTools.h
$(GPP) $(GPP_OPT) -c column/ColorTools.cpp -o column/ColorTools.o
column/YabColumnType.o: column/YabColumnType.cpp column/YabColumnType.h
$(GPP) $(GPP_OPT) -c column/YabColumnType.cpp -o column/YabColumnType.o
$(HAIKUTAB): YabTabView.cpp YabTabView.h
$(GPP) $(GPP_OPT) -c YabTabView.cpp -o YabTabView.o
CalendarControl.o: CalendarControl.cpp CalendarControl.h DateTextView.cpp MonthWindow.cpp MonthView.cpp MouseSenseStringView.cpp
$(GPP) $(GPP_OPT) -c CalendarControl.cpp -o CalendarControl.o
YabControlLook.o: YabControlLook.h YabControlLook.cpp
$(GPP) $(GPP_OPT) -c YabControlLook.cpp -o YabControlLook.o
clean:
rm -f core *.o column/*.o flex.* bison.* yab yabasic.output

960
src/MonthView.cpp Normal file
View File

@@ -0,0 +1,960 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <Bitmap.h>
#include <View.h>
#include <time.h>
#include <ControlLook.h>
#include "MouseSenseStringView.cpp"
class MonthView : public BView
{
public:
MonthView(int day, int month, int year, int first_year, int last_year);
~MonthView();
virtual void AttachedToWindow(void);
virtual void Draw(BRect r);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MessageReceived(BMessage *msg);
virtual void MouseDown(BPoint p);
virtual void MouseUp(BPoint p);
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
private:
void DrawMonth();
BMessenger *msng;
MouseSenseStringView *yearMStringView[2];
MouseSenseStringView *monthMStringView[2];
MouseSenseStringView *todayStringView;
BStringView *monthStringView;
BStringView *yearStringView;
char *weekdayNames[7];
char *monthNames[12];
int monthDays[12];
BBitmap *Bmp;
BView *BmpView;
int cday, cmonth, cyear; // current date in window
int cwday1; // day of week of 1st of month in window
int cwday; // day of week of current day of month in window
int first_year, last_year;
int tday, tmonth, tyear; // today
int twday; // is needed to calculate days of week
float h_cell, w_cell; // height and width of cell for one number of day of nonth
BRect cursor; // rectangle arounding chosen date
BRect cursorPressed; // rectangle arounding date where mouse was pressed
bool MousePressed; // is mouse pressed on date
int dayPressed; // date where mouse is pressed
bool NewMonth; // if true field must be cleared
int which_focused; // 0 - if month, 1 - if year,
// 2 - if days of month, 3 - if today
};
MonthView::MonthView(int day, int month, int year, int first_year, int last_year)
:BView(BRect(0,0,100,100), "MonthViewAViX", B_FOLLOW_LEFT, B_WILL_DRAW)
{
this->cday=day;
this->cmonth=month;
this->cyear=year;
this->first_year=first_year;
this->last_year=last_year;
struct tm *dat;
time_t tmp;
time(&tmp);
dat=localtime(&tmp);
tday=dat->tm_mday;
tmonth=dat->tm_mon+1;
tyear=dat->tm_year+1900; // new day coming when window is opened is not handled
// because it is very rear case
twday=dat->tm_wday;
weekdayNames[0]=(char*)"Mo";
weekdayNames[1]=(char*)"Tu";
weekdayNames[2]=(char*)"We";
weekdayNames[3]=(char*)"Th";
weekdayNames[4]=(char*)"Fr";
weekdayNames[5]=(char*)"Sa";
weekdayNames[6]=(char*)"Su";
monthNames[0]=(char*)"January";
monthNames[1]=(char*)"February";
monthNames[2]=(char*)"March";
monthNames[3]=(char*)"April";
monthNames[4]=(char*)"May";
monthNames[5]=(char*)"June";
monthNames[6]=(char*)"July";
monthNames[7]=(char*)"August";
monthNames[8]=(char*)"September";
monthNames[9]=(char*)"October";
monthNames[10]=(char*)"November";
monthNames[11]=(char*)"December";
monthDays[0]=31;
monthDays[1]=28;
monthDays[2]=31;
monthDays[3]=30;
monthDays[4]=31;
monthDays[5]=30;
monthDays[6]=31;
monthDays[7]=31;
monthDays[8]=30;
monthDays[9]=31;
monthDays[10]=30;
monthDays[11]=31;
NewMonth=false; // first field is cleared and clearing is not needed
MousePressed=false;
}
MonthView::~MonthView()
{
delete todayStringView;
delete monthStringView;
delete monthMStringView[0];
delete monthMStringView[1];
delete yearStringView;
delete yearMStringView[0];
delete yearMStringView[1];
delete msng;
Bmp->RemoveChild(BmpView);
delete BmpView;
delete Bmp;
}
void MonthView::AttachedToWindow(void)
{
SetFont(be_plain_font);
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// Calculate size of cell needed for number of day of month
font_height h;
be_plain_font->GetHeight(&h);
h_cell = (int)(h.ascent+h.descent+h.leading+6);
w_cell = StringWidth("4")*4;
// add today's date
BString s("");
s << tday << " " << monthNames[tmonth-1] << " " << tyear;
msng=new BMessenger(this);
todayStringView=new MouseSenseStringView(new BMessage('TODA'), msng,
BRect(10,10,100,100),"todayMStringViewAViX", s.String());
todayStringView->ResizeToPreferred();
todayStringView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(todayStringView);
// add month selection
monthStringView=new BStringView(BRect(10,10,100,100),"monthStringViewAViX", monthNames[8]);
monthStringView->SetAlignment(B_ALIGN_CENTER);
monthStringView->ResizeToPreferred();
monthStringView->SetText(monthNames[cmonth-1]);
monthStringView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(monthStringView);
// add year selection
s.SetTo("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s << cyear;
yearStringView=new BStringView(BRect(10,10,100,100),"yearStringViewAViX",
"0000");
yearStringView->ResizeToPreferred();
yearStringView->SetText(s.String());
yearStringView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(yearStringView);
ResizeTo(w_cell*7+1,h_cell*7+3+16+yearStringView->Bounds().bottom+todayStringView->Bounds().bottom);
Window()->ResizeTo(Bounds().right, Bounds().bottom);
// year to the left button
yearMStringView[0]=new MouseSenseStringView(new BMessage('YEA0'),msng,
BRect(10,10,100,100),
"yearMStringViewAViX0",
"<<");
AddChild(yearMStringView[0]);
yearMStringView[0]->ResizeToPreferred();
yearMStringView[0]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// year to the right button
yearMStringView[1]=new MouseSenseStringView(new BMessage('YEA1'),msng,
BRect(10,10,100,100),
"yearMStringViewAViX1",
">>");
AddChild(yearMStringView[1]);
yearMStringView[1]->ResizeToPreferred();
yearMStringView[1]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// month to the left button
monthMStringView[0]=new MouseSenseStringView(new BMessage('MON0'),msng,
BRect(10,10,100,100),
"monthMStringViewAViX0",
"<<");
AddChild(monthMStringView[0]);
monthMStringView[0]->ResizeToPreferred();
monthMStringView[0]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// month to the right button
monthMStringView[1]=new MouseSenseStringView(new BMessage('MON1'),msng,
BRect(10,10,100,100),
"monthMStringViewAViX1",
">>");
AddChild(monthMStringView[1]);
monthMStringView[1]->ResizeToPreferred();
monthMStringView[1]->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// move all in correct position
todayStringView->MoveTo((Bounds().right-todayStringView->Bounds().right)/2,
Bounds().bottom-todayStringView->Bounds().bottom-2);
if(tyear<first_year || tyear>last_year) todayStringView->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
yearMStringView[1]->MoveTo(Bounds().right-yearMStringView[1]->Bounds().right,5);
yearStringView->MoveTo(yearMStringView[1]->Frame().left-yearStringView->Bounds().right,5);
yearMStringView[0]->MoveTo(yearStringView->Frame().left-yearMStringView[0]->Bounds().right,5);
monthStringView->MoveTo((yearMStringView[0]->Frame().left-monthStringView->Bounds().right)/2,5);
monthMStringView[0]->MoveTo(monthStringView->Frame().left-monthMStringView[0]->Bounds().right,5);
monthMStringView[1]->MoveTo(monthStringView->Frame().right,5);
which_focused=2; // days of month
// Bitmap for the dates
Bmp=new BBitmap(Bounds(),B_RGB32,true);
BmpView=new BView(Bmp->Bounds(),"BV",0,B_WILL_DRAW);
Bmp->AddChild(BmpView);
Bmp->Lock();
BmpView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BmpView->FillRect(BmpView->Frame());
BmpView->SetHighColor(255,255,255);
BRect bmpRect(Bounds());
bmpRect.top = yearStringView->Frame().bottom + 2;
bmpRect.bottom = todayStringView->Frame().top - 5;
BmpView->FillRect(bmpRect);
BmpView->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT));
BmpView->StrokeLine(BPoint(0,bmpRect.top), BPoint(BmpView->Bounds().right,bmpRect.top));
BmpView->StrokeLine(BPoint(0,bmpRect.bottom), BPoint(BmpView->Bounds().right,bmpRect.bottom));
BmpView->SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
float y=yearStringView->Frame().bottom+h_cell;
float x=0;
for(int i=0;i<7;i++)
{
BmpView->DrawString(weekdayNames[i],BPoint(x+(w_cell-StringWidth(weekdayNames[i]))/2,y));
x+=w_cell;
}
BmpView->Sync();
Bmp->Unlock();
DrawMonth();
}
void MonthView::Draw(BRect r)
{
Window()->Lock();
DrawBitmap(Bmp, BPoint(0,0));
Window()->Unlock();
}
void MonthView::DrawMonth()
{
Bmp->Lock();
float y=yearStringView->Frame().bottom+h_cell;
float x=0;
if(NewMonth)
{
BmpView->SetHighColor(255,255,255);
BmpView->FillRect(BRect(0,y+1, BmpView->Bounds().right,todayStringView->Frame().top - 6));
BmpView->SetHighColor(ui_color(B_PANEL_TEXT_COLOR));
BmpView->SetLowColor(255,255,255);
NewMonth=false;
}
int byear=cyear; // base year
if(tyear<byear) byear=tyear;
int day1=0, m=0, k=byear;
while(k<cyear)
{
day1++;
if(k%4==0) // leap year?
if((k%100!=0) || (k%400==0)) day1++; // yes
k++;
}
while(++m<cmonth)
{
day1+=(monthDays[m-1]-28);
if(m==2) if((cyear%4)==0) if((cyear%100!=0) || (cyear%400==0)) day1++;
}
day1++; // day1 is number of 1st day of chosen month in chosen year
day1=day1%7;
int day2=0;
m=0;
k=byear;
while(k<tyear)
{
day2++;
if((k%4)==0) if((k%100!=0) || (k%400==0)) day2++;
k++;
}
while(++m<tmonth)
{
day2+=(monthDays[m-1]-28);
if(m==2) if((tyear%4)==0) if((tyear%100!=0) || (tyear%400==0)) day2++;
}
day2+=tday; // day2 - number of today's day in today's year
day2=day2%7;
k=(twday==0) ? 6 : twday-1;
k=k-day2+day1;
while(k<0) k+=7;
k=k%7;
cwday1=k;
x=w_cell*k+1;
y+=h_cell;
int qu_days=monthDays[cmonth-1]; // quantity of days in month
if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
BString s;
int t=0;
while(t<qu_days)
{
t++;
s<<t;
if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(236,0,0,0);
BmpView->DrawString(s.String(),BPoint(x+(w_cell-StringWidth(s.String()))/2,y));
if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(0,0,0,0);
if(t==cday)
{
cwday=k;
if(which_focused==2) BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
else
// BmpView->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
BmpView->SetHighColor(255,255,255);
cursor.Set(x,y-h_cell+5,x+w_cell-1,y+4);
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0,0);
}
x+=w_cell;
k++;
s.SetTo("");
if(k==7)
{
k=0;
y+=h_cell;
x=1;
}
}
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
}
////////////////////////////////////////////////////////////////
void MonthView::KeyDown(const char *bytes, int32 numBytes)
{
switch(bytes[0])
{
case B_TAB:
{
Bmp->Lock();
switch(which_focused)
{
case 0: // months
{
BmpView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
monthMStringView[0]->Frame().bottom+1),
BPoint(monthMStringView[1]->Frame().right,
monthMStringView[1]->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
case 1: // years
{
BmpView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
yearMStringView[0]->Frame().bottom+1),
BPoint(yearMStringView[1]->Frame().right,
yearMStringView[1]->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
case 2: // days of month
{
BmpView->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_3_TINT));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
break;
}
case 3: // today
{
BmpView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
todayStringView->Frame().bottom+1),
BPoint(todayStringView->Frame().right,
todayStringView->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
}
// changing which_focused
if(modifiers() & B_SHIFT_KEY)
{
if(which_focused==0)
which_focused=3;
else which_focused--;
}
else // simply Tab
{
if(which_focused==3)
which_focused=0;
else which_focused++;
}
// drawing with new which_focused
switch(which_focused)
{
case 0: // months
{
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
monthMStringView[0]->Frame().bottom+1),
BPoint(monthMStringView[1]->Frame().right,
monthMStringView[1]->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
case 1: // years
{
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
yearMStringView[0]->Frame().bottom+1),
BPoint(yearMStringView[1]->Frame().right,
yearMStringView[1]->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
case 2: // days of month
{
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
break;
}
case 3: // today
{
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
todayStringView->Frame().bottom+1),
BPoint(todayStringView->Frame().right,
todayStringView->Frame().bottom+1));
BmpView->SetHighColor(0,0,0);
break;
}
}
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
break;
} // B_TAB
case B_DOWN_ARROW:
{
if(which_focused==0) // month
{
BMessage msg('MON0');
MessageReceived(&msg);
}
else if(which_focused==1) // year
{
BMessage msg('YEA0');
MessageReceived(&msg);
}
else if(which_focused==2) // days of month
{
int qu_days=monthDays[cmonth-1];
if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
if((cday+7)<=qu_days)
{
Bmp->Lock();
BmpView->SetHighColor(255,255,255);
BmpView->StrokeRect(cursor);
cursor.OffsetBySelf(0, h_cell);
cday+=7;
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
}
}
break;
}
case B_UP_ARROW:
{
// Test whether Ctrl+UpArrow is pressed
if(modifiers() & B_CONTROL_KEY)
Window()->PostMessage(B_QUIT_REQUESTED);
else
{
if(which_focused==0) // month
{
BMessage msg('MON1');
MessageReceived(&msg);
}
else if(which_focused==1) // year
{
BMessage msg('YEA1');
MessageReceived(&msg);
}
else if(which_focused==2) // days of month
{
if((cday-7)>=1)
{
Bmp->Lock();
BmpView->SetHighColor(255,255,255);
BmpView->StrokeRect(cursor);
cursor.OffsetBySelf(0, -h_cell);
cday-=7;
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
}
}
}
break;
}
case B_LEFT_ARROW:
{
if(which_focused==0) // month
{
BMessage msg('MON0');
MessageReceived(&msg);
}
else if(which_focused==1) // year
{
BMessage msg('YEA0');
MessageReceived(&msg);
}
else if(which_focused==2) // days of month
{
if(cday>1)
{
Bmp->Lock();
BmpView->SetHighColor(255,255,255);
BmpView->StrokeRect(cursor);
if(cwday>0) // by dates no matter of day of week
{
cursor.OffsetBySelf(-w_cell,0);
cwday--;
}
else // cwday==0
{
cursor.OffsetBySelf(w_cell*6,-h_cell);
cwday=6;
}
cday--;
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
}
else // 1st of month, go month before
{
if(cyear>first_year || cmonth>1) // one can go
{
int cm=(cmonth==1) ? 12 : cmonth-1;
int qu_days=monthDays[cm-1];
if(cm==2) if(cyear%4==0)
if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
// it is correct not to pay attention to year changing
// because if we moved to february then year was not changed
// but if month is other then february
// then it has the same number of days every year.
cday=qu_days;
BMessage msg('MON0');
MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
}
}
}
break;
}
case B_RIGHT_ARROW:
{
if(which_focused==0) // month
{
BMessage msg('MON1');
MessageReceived(&msg);
}
else if(which_focused==1) // year
{
BMessage msg('YEA1');
MessageReceived(&msg);
}
else if(which_focused==2) // days of month
{
int qu_days=monthDays[cmonth-1];
if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
if(cday<qu_days)
{
Bmp->Lock();
BmpView->SetHighColor(255,255,255);
BmpView->StrokeRect(cursor);
if(cwday<6) // by dates no matter of day of week
{
cursor.OffsetBySelf(w_cell,0);
cwday++;
}
else // cwday==6
{
cursor.OffsetBySelf(-w_cell*6,h_cell);
cwday=0;
}
cday++;
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(0,0,0);
BmpView->Sync();
Bmp->Unlock();
Draw(Bounds());
}
else // last of month, go next month
{
if(cyear<last_year || cmonth<12) // one can go
{
cday=1;
BMessage msg('MON1');
MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
}
}
}
break;
}
case B_ESCAPE:
{
Window()->PostMessage(B_QUIT_REQUESTED);
break;
}
case B_ENTER:
case B_SPACE:
{
if(which_focused==2)
{
// here it is needed to send dayPressed (==cwday), cyear, cmonth
// to window and leave
BMessage *msg=new BMessage('MVME');
msg->AddInt32("day",cday);
msg->AddInt32("month",cmonth);
msg->AddInt32("year",cyear);
Window()->PostMessage(msg);
}
else if(which_focused==3)
{
BMessage msg('TODA');
MessageReceived(&msg);
}
break;
}
default:
BView::KeyDown(bytes, numBytes);
}
}
////////////////////////////////////////////////////
void MonthView::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
case 'YEA0': // year before
{
if(cyear<=first_year) break;
cyear--;
NewMonth=true;
BString s("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s<<cyear;
yearStringView->SetText(s.String());
if(cmonth==2) if(cday==29) // one can do simplier: if cday==29, then make
// cday=28, because two leap years one after other can't be
{
if(cyear%4!=0) cday=28;
else if(cyear%100==0 && cyear%400!=0) cday=28;
}
DrawMonth();
break;
}
case 'YEA1': // year after
{
if(cyear>=last_year) break;
cyear++;
NewMonth=true;
BString s("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s<<cyear;
yearStringView->SetText(s.String());
if(cmonth==2) if(cday==29)
{
if(cyear%4!=0) cday=28;
else if(cyear%100==0 && cyear%400!=0) cday=28;
}
DrawMonth();
break;
}
case 'MON0': // month before
{
if(cmonth>1) cmonth--;
else if(cyear>first_year)
{
cmonth=12;
cyear--;
BString s("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s<<cyear;
yearStringView->SetText(s.String());
}
else break; // nothing is changed
NewMonth=true;
monthStringView->SetText(monthNames[cmonth-1]);
if(cmonth==2)
{
int tmpday=28;
if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) tmpday=29;
if(cday>tmpday) cday=tmpday;
}
else if(cday>monthDays[cmonth-1]) cday=monthDays[cmonth-1];
DrawMonth();
break;
}
case 'MON1': // month after
{
if(cmonth<12) cmonth++;
else if(cyear<last_year)
{
cmonth=1;
cyear++;
BString s("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s<<cyear;
yearStringView->SetText(s.String());
}
else break; // nothing is changed
NewMonth=true;
monthStringView->SetText(monthNames[cmonth-1]);
if(cmonth==2)
{
int tmpday=28;
if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) tmpday=29;
if(cday>tmpday) cday=tmpday;
}
else if(cday>monthDays[cmonth-1]) cday=monthDays[cmonth-1];
DrawMonth();
break;
}
case 'TODA': // to place to today's date
{
if(tyear<first_year || tyear>last_year) break;
NewMonth=true;
cyear=tyear;
cmonth=tmonth;
cday=tday;
BString s("");
if(cyear<10) s.Append("000");
else if(cyear<100) s.Append("00");
else if(cyear<1000) s.Append("0");
s<<cyear;
yearStringView->SetText(s.String());
monthStringView->SetText(monthNames[cmonth-1]);
DrawMonth();
break;
}
default:
BView::MessageReceived(msg);
}
}
/////////////////////////////////////////
void MonthView::MouseDown(BPoint p)
{
// It's necessary to define whether mouse cursor is on one of dates
BRect r;
int k=cwday1;
float x=w_cell*k+1;
float y=yearStringView->Frame().bottom+h_cell+h_cell;
int qu_days=monthDays[cmonth-1]; // quantity of days in month
if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
bool flag=false; // whether mouse is pressed just on date
int t=0;
while(t<qu_days)
{
t++;
r.Set(x,y-h_cell+5,x+w_cell-1,y+4);
if(r.Contains(p))
{
flag=true;
dayPressed=t;
cursorPressed.Set(r.left,r.top,r.right,r.bottom);
MousePressed=true;
Bmp->Lock();
BmpView->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BmpView->StrokeRect(cursor);
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursorPressed);
Bmp->Unlock();
Invalidate();
break; // exit while
}
x+=w_cell;
k++;
if(k==7)
{
k=0;
y+=h_cell;
x=1;
}
}
}
void MonthView::MouseUp(BPoint p)
{
if(!MousePressed) return;
if(cursorPressed.Contains(p))
{
// here it is needed to send dayPressed, cyear, cmonth
// to window and leave
BMessage *msg=new BMessage('MVME');
msg->AddInt32("day",dayPressed);
msg->AddInt32("month",cmonth);
msg->AddInt32("year",cyear);
Window()->PostMessage(msg);
}
else
{
Bmp->Lock();
BmpView->SetHighColor(255,255,255);
BmpView->StrokeRect(cursorPressed);
BmpView->SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR));
BmpView->StrokeRect(cursor);
Bmp->Unlock();
Invalidate();
MousePressed=false;
}
}
void MonthView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
{
BPoint point;
uint32 buttons;
GetMouse(&point,&buttons);
if(transit==B_ENTERED_VIEW)
{
if( (buttons & B_PRIMARY_MOUSE_BUTTON)==0 &&
(buttons & B_SECONDARY_MOUSE_BUTTON)==0 &&
(buttons & B_PRIMARY_MOUSE_BUTTON)==0 )
MousePressed = false;
else
MousePressed = true;
}
if(transit==B_EXITED_VIEW || transit==B_OUTSIDE_VIEW)
MouseUp(Bounds().LeftTop());
}

112
src/MonthWindow.cpp Normal file
View File

@@ -0,0 +1,112 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <Point.h>
#include <Screen.h>
#include <String.h>
#include <StringView.h>
#include <Window.h>
#include "MonthView.cpp"
class MonthWindow: public BWindow
{
public:
MonthWindow(BPoint LT, BMessenger *msng, int day, int month, int year,
int first_year, int last_year);
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested(void);
virtual void WindowActivated(bool active);
private:
MonthView *myMonthView;
BMessenger *messenger;
int first_year;
int last_year;
};
MonthWindow::MonthWindow(BPoint LT, BMessenger *msng, int day, int month, int year, int first_year, int last_year)
:BWindow(BRect(LT,BPoint(LT.x+200,LT.y+200)),"MonthWindowAViX",
B_BORDERED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_MOVABLE|B_AVOID_FOCUS)
{
this->first_year=first_year;
this->last_year=last_year;
myMonthView = new MonthView(day, month, year, first_year, last_year);
AddChild(myMonthView);
myMonthView->MakeFocus(true);
messenger = msng;
BRect screenFrame = BScreen(this).Frame();
if(LT.x < 0)
LT.x = 0;
if(LT.x > screenFrame.right - Bounds().Width())
LT.x = screenFrame.right - Bounds().Width();
if(LT.y > screenFrame.bottom - Bounds().Height())
LT.y = screenFrame.bottom - Bounds().Height();
MoveTo(LT);
Show();
}
void MonthWindow::MessageReceived(BMessage *msg)
{
if(msg->what=='MVME')
{
// Is date correct?
int32 day, month, year;
if(msg->FindInt32("day",&day)!=B_OK) return;
if(msg->FindInt32("month",&month)!=B_OK) return;
if(msg->FindInt32("year",&year)!=B_OK) return;
if(year<first_year || year>last_year) return;
if(month<1 || month>12) return;
int32 tmp;
tmp=31;
if(month==4 || month==6 || month==9 || month==11)
tmp=30;
else if(month==2)
{
if(year%4==0)
{
if(year%100==0 && year%400!=0)
tmp=28;
else
tmp=29;
}
else
tmp=28;
}
if(day<1 || day>tmp) return;
messenger->SendMessage(msg);
Quit();
}
else
BWindow::MessageReceived(msg);
}
bool MonthWindow::QuitRequested(void)
{
return true;
}
void MonthWindow::WindowActivated(bool active)
{
// exit if unfocused
if(!active) Quit();
}

View File

@@ -0,0 +1,95 @@
// Calendar Control version 2.5
// by Al.V. Sarikov.
// Kherson, Ukraine, 2006.
// E-mail: avix@ukrpost.net.
// Home page: http://avix.pp.ru.
// Control which allows to work with dates:
// enter date to text field and choose it from calendar.
// Distributed under BSD license (see LICENSE file).
#include <ControlLook.h>
#include <Message.h>
#include <Messenger.h>
#include <Point.h>
#include <Rect.h>
#include <StringView.h>
class MouseSenseStringView:public BStringView
{
public:
MouseSenseStringView(BMessage *msg,
BMessenger *msng,
BRect frame,
const char *name,
const char *text,
uint32 resizingMode=B_FOLLOW_LEFT|B_FOLLOW_TOP,
uint32 flags=B_WILL_DRAW);
virtual void MouseDown(BPoint p);
virtual void MouseUp(BPoint p);
void Draw(BRect(update));
private:
BMessage *msg;
BMessenger *msng;
bool isMouseDown;
};
MouseSenseStringView::MouseSenseStringView(BMessage *msg,
BMessenger *msng,
BRect frame,
const char *name,
const char *text,
uint32 resizingMode,
uint32 flags)
:BStringView(frame,name,text,resizingMode,flags)
{
this->msg=msg;
this->msng=msng;
isMouseDown = false;
}
void MouseSenseStringView::MouseDown(BPoint p)
{
isMouseDown = true;
// if(msg!=NULL) if(msng!=NULL)
// msng->SendMessage(msg);
}
void MouseSenseStringView::MouseUp(BPoint p)
{
BPoint mouse;
uint32 buttons;
GetMouse(&mouse, &buttons);
if(Bounds().Contains(mouse))
if(msg!=NULL) if(msng!=NULL)
msng->SendMessage(msg);
isMouseDown = false;
}
void MouseSenseStringView::Draw(BRect update)
{
BString t(Text());
BRect r1(Bounds());
r1.right = r1.right/2;
BRect r2(Bounds());
r2.left= r2.right/4;
r2.right= r2.right*3/4;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
if(t == "<<")
{
be_control_look->DrawArrowShape(this, r1, update, base, 0);
be_control_look->DrawArrowShape(this, r2, update, base, 0);
}
else if(t == ">>")
{
be_control_look->DrawArrowShape(this, r1, update, base, 1);
be_control_look->DrawArrowShape(this, r2, update, base, 1);
}
else
BStringView::Draw(update);
}

34
src/RdefApply Executable file
View File

@@ -0,0 +1,34 @@
#!yab
doc RdefApply
doc adds icon, application signature and version info attributes from an rdef file.
doc
doc Copyright © 2015 Jim Saxton, Fat Elk Software
if (peek("argument") >= 2) then
filename$=peek$("argument")
Outfilename$=peek$("argument")
make$=peek$("argument")
make=0
if (make$="M") make=1
readicon()
else
print"RdefApply"
print "Adds icon, application signature and version info attributes from an rdef file.
"
print "usage:"
print "RdefApply <RdefFilename> <OutputFilename> <M>"
print "if M is used, OutoutFilename is created if it does not exist
or the creation date is set if it does exist."
endif
sub readicon()
if (not open(1,filename$)) print "Could not open file'"+filename$+"' for reading":exit
if (make=1) system("touch "+Outfilename$)
close #1
system("rc -o "+filename$+".rsrc "+filename$)
system("resattr -O -o "+Outfilename$+" "+filename$+".rsrc")
end sub

624
src/Spinner.cpp Normal file
View File

@@ -0,0 +1,624 @@
/*
Spinner.cpp: A number spinner control.
Written by DarkWyrm <bpmagic@columbus.rr.com>, Copyright 2004
Released under the MIT license.
Original BScrollBarButton class courtesy Haiku project
*/
#include "Spinner.h"
#include <String.h>
#include <ScrollBar.h>
#include <Window.h>
#include <stdio.h>
#include <Font.h>
#include <Box.h>
#include <MessageFilter.h>
#include <ControlLook.h>
#include "global.h"
enum
{
M_UP='mmup',
M_DOWN,
M_TEXT_CHANGED='mtch'
};
typedef enum
{
ARROW_LEFT=0,
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
ARROW_NONE
} arrow_direction;
class SpinnerMsgFilter : public BMessageFilter
{
public:
SpinnerMsgFilter(void);
~SpinnerMsgFilter(void);
virtual filter_result Filter(BMessage *msg, BHandler **target);
};
class SpinnerArrowButton : public BView
{
public:
SpinnerArrowButton(BPoint location, const char *name,
arrow_direction dir);
~SpinnerArrowButton(void);
void AttachedToWindow(void);
void DetachedToWindow(void);
void MouseDown(BPoint pt);
void MouseUp(BPoint pt);
void MouseMoved(BPoint pt, uint32 code, const BMessage *msg);
void Draw(BRect update);
void SetEnabled(bool value);
bool IsEnabled(void) const { return enabled; }
void SetViewColor(rgb_color color);
private:
arrow_direction fDirection;
BPoint tri1,tri2,tri3;
Spinner *parent;
bool mousedown;
bool enabled;
rgb_color myColor;
};
class SpinnerPrivateData
{
public:
SpinnerPrivateData(void)
{
thumbframe.Set(0,0,0,0);
enabled=true;
tracking=false;
mousept.Set(0,0);
thumbinc=1.0;
repeaterid=-1;
exit_repeater=false;
arrowdown=ARROW_NONE;
#ifdef TEST_MODE
sbinfo.proportional=true;
sbinfo.double_arrows=false;
sbinfo.knob=0;
sbinfo.min_knob_size=14;
#else
get_scroll_bar_info(&sbinfo);
#endif
}
~SpinnerPrivateData(void)
{
if(repeaterid!=-1)
{
exit_repeater=false;
kill_thread(repeaterid);
}
}
thread_id repeaterid;
scroll_bar_info sbinfo;
BRect thumbframe;
bool enabled;
bool tracking;
BPoint mousept;
float thumbinc;
bool exit_repeater;
arrow_direction arrowdown;
};
Spinner::Spinner(BRect frame, const char *name, const char *label, int32 min, int32 max, int32 step, BMessage *msg,
uint32 resize,uint32 flags)
: BControl(frame, name,NULL,msg,resize,flags)
{
BRect r(Bounds());
if(r.Height()<14*2)
r.bottom=r.top+14*2;
ResizeTo(r.Width(),r.Height());
r.right-=14;
font_height fh;
BFont font;
font.GetHeight(&fh);
float textheight=fh.ascent+fh.descent+fh.leading;
BString t("");
t << max;
BFont f(be_plain_font);
float width1 = f.StringWidth(t.String())+2;
float width2 = f.StringWidth(label);
ResizeTo(width1+width2+18+14, 14*2-2);
r = Bounds();
r.right-=14+3;
r.bottom=r.top+textheight+8;
r.OffsetTo(0, ( (Bounds().Height()-r.Height())/2) );
fTextControl=new BTextControl(r,"textcontrol",label,"0",new BMessage(M_TEXT_CHANGED),
B_FOLLOW_ALL,B_WILL_DRAW|B_NAVIGABLE);
AddChild(fTextControl);
BTextView *tview=fTextControl->TextView();
tview->SetAlignment(B_ALIGN_LEFT);
tview->SetWordWrap(false);
fTextControl->SetDivider(width2+5);
BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| "
"asdfghjkl:\"zxcvbnm<>?!@#$%^&*()-_=+`~\r");
for(int32 i=0; i<string.CountChars(); i++)
{
char c=string.ByteAt(i);
tview->DisallowChar(c);
}
r=Bounds();
r.left=r.right-15;
r.bottom/=2;
fUpButton=new SpinnerArrowButton(BPoint(r.left, r.top),"up",ARROW_UP);
AddChild(fUpButton);
r=Bounds();
r.left=r.right-15;
r.top=r.bottom/2+1;
fDownButton=new SpinnerArrowButton(BPoint(r.left, r.top-1),"down",ARROW_DOWN);
AddChild(fDownButton);
fStep=step;
fMin=min;
fMax=max;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
privatedata=new SpinnerPrivateData;
fFilter=new SpinnerMsgFilter;
SetValue(min);
}
Spinner::~Spinner(void)
{
delete privatedata;
delete fFilter;
}
void Spinner::AttachedToWindow(void)
{
Window()->AddCommonFilter(fFilter);
fTextControl->SetTarget(this);
}
void Spinner::DetachedFromWindow(void)
{
Window()->RemoveCommonFilter(fFilter);
}
void Spinner::SetValue(int32 value)
{
if(value>GetMax() || value<GetMin())
return;
BControl::SetValue(value);
char string[50];
sprintf(string,"%ld",value);
fTextControl->SetText(string);
}
void Spinner::SetViewColor(rgb_color color)
{
BControl::SetViewColor(color);
fTextControl->SetViewColor(color);
fTextControl->SetLowColor(color);
fUpButton->SetViewColor(color);
fDownButton->SetViewColor(color);
}
void Spinner::SetLabel(const char *text)
{
fTextControl->SetLabel(text);
}
void Spinner::ValueChanged(int32 value)
{
}
void Spinner::MessageReceived(BMessage *msg)
{
if(msg->what==M_TEXT_CHANGED)
{
BString string(fTextControl->Text());
int32 newvalue=0;
sscanf(string.String(),"%ld",&newvalue);
if(newvalue>=GetMin() && newvalue<=GetMax())
{
// new value is in range, so set it and go
SetValue(newvalue);
Invoke();
Draw(Bounds());
ValueChanged(Value());
}
else
{
// new value is out of bounds. Clip to range if current value is not
// at the end of its range
if(newvalue<GetMin() && Value()!=GetMin())
{
SetValue(GetMin());
Invoke();
Draw(Bounds());
ValueChanged(Value());
}
else
if(newvalue>GetMax() && Value()!=GetMax())
{
SetValue(GetMax());
Invoke();
Draw(Bounds());
ValueChanged(Value());
}
else
{
char string[100];
sprintf(string,"%ld",Value());
fTextControl->SetText(string);
}
}
}
else
BControl::MessageReceived(msg);
}
void Spinner::SetSteps(int32 stepsize)
{
fStep=stepsize;
}
void Spinner::SetRange(int32 min, int32 max)
{
SetMin(min);
SetMax(max);
}
void Spinner::GetRange(int32 *min, int32 *max)
{
*min=fMin;
*max=fMax;
}
void Spinner::SetMax(int32 max)
{
fMax=max;
if(Value()>fMax)
SetValue(fMax);
}
void Spinner::SetMin(int32 min)
{
fMin=min;
if(Value()<fMin)
SetValue(fMin);
}
void Spinner::SetEnabled(bool value)
{
if(IsEnabled()==value)
return;
BControl::SetEnabled(value);
fTextControl->SetEnabled(value);
fTextControl->TextView()->MakeSelectable(value);
fUpButton->SetEnabled(value);
fDownButton->SetEnabled(value);
}
void Spinner::MakeFocus(bool value)
{
fTextControl->MakeFocus(value);
}
SpinnerArrowButton::SpinnerArrowButton(BPoint location,
const char *name, arrow_direction dir)
:BView(BRect(0,0,16,12).OffsetToCopy(location),
name, B_FOLLOW_ALL, B_WILL_DRAW)
{
fDirection=dir;
enabled=true;
myColor = ui_color(B_PANEL_BACKGROUND_COLOR);
mousedown=false;
}
SpinnerArrowButton::~SpinnerArrowButton(void)
{
}
void SpinnerArrowButton::MouseDown(BPoint pt)
{
if(enabled==false)
return;
if (!IsEnabled())
return;
mousedown=true;
int redcost = 1000;
Draw(Bounds());
BRect bounds = Bounds();
uint32 buttons;
BPoint point;
int32 step=parent->GetSteps();
int32 newvalue=parent->Value();
int32 waitvalue=150000;
do
{
if(fDirection==ARROW_UP)
{
parent->privatedata->arrowdown=ARROW_UP;
newvalue+=step;
}
else
{
parent->privatedata->arrowdown=ARROW_DOWN;
newvalue-=step;
}
if( newvalue>=parent->GetMin() && newvalue<=parent->GetMax())
{
// new value is in range, so set it and go
parent->SetValue(newvalue);
parent->Invoke();
// parent->Draw(parent->Bounds());
parent->ValueChanged(parent->Value());
}
else
{
// new value is out of bounds. Clip to range if current value is not
// at the end of its range
if(newvalue<parent->GetMin() && parent->Value()!=parent->GetMin())
{
parent->SetValue(parent->GetMin());
parent->Invoke();
// parent->Draw(parent->Bounds());
parent->ValueChanged(parent->Value());
}
else
if(newvalue>parent->GetMax() && parent->Value()!=parent->GetMax())
{
parent->SetValue(parent->GetMax());
parent->Invoke();
// parent->Draw(parent->Bounds());
parent->ValueChanged(parent->Value());
}
else
{
// cases which go here are if new value is <minimum and value already at
// minimum or if > maximum and value already at maximum
return;
}
}
Window()->UpdateIfNeeded();
snooze(waitvalue);
GetMouse(&point, &buttons, false);
bool inside = bounds.Contains(point);
// if ((parent->Value() == B_CONTROL_ON) != inside)
// parent->SetValue(inside ? B_CONTROL_ON : B_CONTROL_OFF);
if(waitvalue<=50000)
waitvalue=50000;
else
{
waitvalue -= redcost;
redcost = redcost*10;
}
} while (buttons != 0);
}
void SpinnerArrowButton::MouseUp(BPoint pt)
{
if(enabled)
{
mousedown=false;
if(parent)
{
parent->privatedata->arrowdown=ARROW_NONE;
parent->privatedata->exit_repeater=true;
}
Draw(Bounds());
}
}
void SpinnerArrowButton::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
{
if(enabled==false)
return;
if(transit==B_ENTERED_VIEW)
{
BPoint point;
uint32 buttons;
GetMouse(&point,&buttons);
if( (buttons & B_PRIMARY_MOUSE_BUTTON)==0 &&
(buttons & B_SECONDARY_MOUSE_BUTTON)==0 &&
(buttons & B_PRIMARY_MOUSE_BUTTON)==0 )
mousedown=false;
else
mousedown=true;
Draw(Bounds());
}
if(transit==B_EXITED_VIEW || transit==B_OUTSIDE_VIEW)
MouseUp(Bounds().LeftTop());
}
void SpinnerArrowButton::Draw(BRect update)
{
BRect rect(Bounds());
rgb_color background = B_TRANSPARENT_COLOR;
if (Parent())
background = Parent()->ViewColor();
if (background == B_TRANSPARENT_COLOR)
background = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
if(!parent->IsEnabled())
flags |= BControlLook::B_DISABLED;
if(mousedown)
flags = 1 << 2;
BRect r(Bounds());
if(fDirection == ARROW_UP)
r.bottom = r.bottom*2;
else
r.top = - r.bottom;
be_control_look->DrawButtonFrame(this, r, update, base, background, flags);
be_control_look->DrawButtonBackground(this, r, update, base, flags);
rect.InsetBy(2.0,2.0);
base = ui_color(B_PANEL_TEXT_COLOR);
float tint = B_NO_TINT;
if(!parent->IsEnabled())
tint = B_LIGHTEN_MAX_TINT;
be_control_look->DrawArrowShape(this, rect, update, base, fDirection, flags, tint);
}
void SpinnerArrowButton::AttachedToWindow(void)
{
parent=(Spinner*)Parent();
}
void SpinnerArrowButton::DetachedToWindow(void)
{
parent=NULL;
}
void SpinnerArrowButton::SetEnabled(bool value)
{
enabled=value;
Invalidate();
}
void SpinnerArrowButton::SetViewColor(rgb_color color)
{
myColor = color;
Invalidate();
}
SpinnerMsgFilter::SpinnerMsgFilter(void)
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,B_KEY_DOWN)
{
}
SpinnerMsgFilter::~SpinnerMsgFilter(void)
{
}
filter_result SpinnerMsgFilter::Filter(BMessage *msg, BHandler **target)
{
int32 c;
msg->FindInt32("raw_char",&c);
switch(c)
{
case B_ENTER:
{
BTextView *text=dynamic_cast<BTextView*>(*target);
if(text && text->IsFocus())
{
BView *view=text->Parent();
while(view)
{
Spinner *spin=dynamic_cast<Spinner*>(view);
if(spin)
{
BString string(text->Text());
int32 newvalue=0;
sscanf(string.String(),"%ld",&newvalue);
if(newvalue!=spin->Value())
{
spin->SetValue(newvalue);
spin->Invoke();
}
return B_SKIP_MESSAGE;
}
view=view->Parent();
}
}
return B_DISPATCH_MESSAGE;
}/*
case B_TAB:
{
// Cause Tab characters to perform keybaord navigation
BHandler *h=*target;
BView *v=NULL;
h=h->NextHandler();
while(h)
{
v=dynamic_cast<BView*>(h);
if(v)
{
*target=v->Window();
return B_DISPATCH_MESSAGE;
}
h=h->NextHandler();
}
return B_SKIP_MESSAGE;
// return B_DISPATCH_MESSAGE;
}*/
case B_UP_ARROW:
case B_DOWN_ARROW:
{
BTextView *text=dynamic_cast<BTextView*>(*target);
if(text && text->IsFocus())
{
// We have a text view. See if it currently has the focus and belongs
// to a Spinner control. If so, change the value of the spinner
// TextViews are complicated beasts which are actually multiple views.
// Travel up the hierarchy to see if any of the target's ancestors are
// a Spinner.
BView *view=text->Parent();
while(view)
{
Spinner *spin=dynamic_cast<Spinner*>(view);
if(spin)
{
int32 step=spin->GetSteps();
if(c==B_DOWN_ARROW)
step=0-step;
spin->SetValue(spin->Value()+step);
spin->Invoke();
return B_SKIP_MESSAGE;
}
view=view->Parent();
}
}
return B_DISPATCH_MESSAGE;
}
default:
return B_DISPATCH_MESSAGE;
}
// shut the stupid compiler up
return B_SKIP_MESSAGE;
}

59
src/Spinner.h Normal file
View File

@@ -0,0 +1,59 @@
#ifndef SPINNER_H_
#define SPINNER_H_
#include <Control.h>
#include <TextView.h>
#include <Button.h>
#include <StringView.h>
#include <TextControl.h>
class SpinnerPrivateData;
class SpinnerArrowButton;
class SpinnerMsgFilter;
class Spinner : public BControl
{
public:
Spinner(BRect frame, const char *name, const char *label, int32 min, int32 max, int32 step, BMessage *msg,
uint32 resize=B_FOLLOW_LEFT|B_FOLLOW_TOP,uint32 flags=B_WILL_DRAW|B_NAVIGABLE);
virtual ~Spinner(void);
virtual void AttachedToWindow(void);
virtual void DetachedFromWindow(void);
virtual void ValueChanged(int32 value);
virtual void MessageReceived(BMessage *msg);
virtual void SetViewColor(rgb_color color);
virtual void SetSteps(int32 stepsize);
int32 GetSteps(void) const { return fStep; }
virtual void SetRange(int32 min, int32 max);
void GetRange(int32 *min, int32 *max);
virtual void SetMax(int32 max);
int32 GetMax(void) const { return fMax; }
virtual void SetMin(int32 min);
int32 GetMin(void) const { return fMin; }
virtual void MakeFocus(bool value=true);
virtual void SetValue(int32 value);
// int32 Value();
virtual void SetLabel(const char *text);
BTextControl *TextControl(void) const { return fTextControl; }
virtual void SetEnabled(bool value);
private:
friend class SpinnerArrowButton;
friend class SpinnerPrivateData;
BTextControl *fTextControl;
SpinnerArrowButton *fUpButton, *fDownButton;
SpinnerPrivateData *privatedata;
int32 fStep;
int32 fMin, fMax;
SpinnerMsgFilter *fFilter;
};
#endif

726
src/SplitPane.cpp Normal file
View File

@@ -0,0 +1,726 @@
/*******************************************************
* SplitPane©
*
* SplitPane is a usefull UI component. It alows the
* use to ajust two view Horizontaly or Vertacly so
* that they are a desired size. This type of Pane
* shows up most comonly in Mail/News Readers.
*
* @author YNOP (ynop@acm.org)
* @version beta
* @date Dec. 10 1999
*******************************************************/
#include <AppKit.h>
#include <InterfaceKit.h>
#include <StorageKit.h>
#include <String.h>
#include <Path.h>
#include <TranslationKit.h>
#include <TranslationUtils.h>
//#include <stdio.h>
#include "SplitPane.h"
//#include "SplitPaneConfig.h"
/*******************************************************
* Setup the main view. Add in all the niffty components
* we have made and get things rolling
*******************************************************/
SplitPane::SplitPane(BRect frame, const char* name, BView *one, BView *two,uint32 Mode):BView(frame, name, Mode,B_WILL_DRAW|B_FRAME_EVENTS){
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // This is default get from parent if exist
//SetViewColor(B_TRANSPARENT_32_BIT); // go tran so we have control over drawing
BRect b;
b = Bounds();
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
PaneOne = one;
PaneTwo = two;
align = B_VERTICAL; // Most people use it this way
pos = (int)b.Width()/2; // Center is a good start place
thickness = 10;
jump = 1; // 1 makes a smother slide
VOneDetachable = false;
VTwoDetachable = false;
pad = 1;
MinSizeOne = 0; // full left
MinSizeTwo = 0; // full right
poslocked = false; // free movement
alignlocked = false; // free alignment
Draggin = false;
attached = false;
WinOne = NULL;
WinTwo = NULL;
ConfigWindow = NULL;
AddChild(one);
AddChild(two);
}
/*******************************************************
* When ready grap the parents color and refreash.
*******************************************************/
void SplitPane::AttachedToWindow(){
//SetViewColor(Parent()->ViewColor());
attached = true;
Update();
}
/*******************************************************
* If we are being resized. Fix the stuff we need to fix
*******************************************************/
void SplitPane::FrameResized(float,float){
// if bar is on the left side follow left
// else if it is on the right side follow the right
// Need to implements smart follow still
Update();
Invalidate();
}
/*******************************************************
* The main draw stuff here. basicly just the slider
*******************************************************/
void SplitPane::Draw(BRect f){
SetHighColor(160,160,160);
if(align == B_VERTICAL){
SetHighColor(185,185,185);
// SetHighColor(145,145,145);
//FillRect(BRect(pos,Bounds().top+pad+1,pos,Bounds().bottom-pad-1)); // 145
FillRect(BRect(pos,Bounds().top+pad+1,pos,Bounds().bottom-pad-1)); // 145
SetHighColor(255,255,255);
FillRect(BRect(pos+1,Bounds().top+pad+1,pos+2,Bounds().bottom-pad-1)); // 255
//SetHighColor(216,216,216);
SetHighColor(Parent()->ViewColor());
FillRect(BRect(pos+2,Bounds().top+pad+1,pos+thickness-2,Bounds().bottom-pad-1));// 216
if(thickness>9)
{
float y = (Bounds().bottom - Bounds().top)/2;
float x = pos + (thickness/2);
SetPenSize(2);
SetHighColor(255,255,255);
StrokeLine(BPoint(x-3,y-11),BPoint(x+3,y-5));
StrokeLine(BPoint(x-3,y-7),BPoint(x+3,y-1));
StrokeLine(BPoint(x-3,y-3),BPoint(x+3,y+3));
StrokeLine(BPoint(x-3,y+1),BPoint(x+3,y+7));
StrokeLine(BPoint(x-3,y+5),BPoint(x+3,y+11));
SetPenSize(1);
SetHighColor(145,145,145);
StrokeLine(BPoint(x-3,y-10),BPoint(x+3,y-4));
StrokeLine(BPoint(x-3,y-6),BPoint(x+3,y+0));
StrokeLine(BPoint(x-3,y-2),BPoint(x+3,y+4));
StrokeLine(BPoint(x-3,y+2),BPoint(x+3,y+8));
StrokeLine(BPoint(x-3,y+6),BPoint(x+3,y+12));
}
SetHighColor(185,185,185);
// SetHighColor(145,145,145);
FillRect(BRect(pos+thickness-2,Bounds().top+pad+1,pos+thickness-2,Bounds().bottom-pad-1)) ;// 145
SetHighColor(145,145,145);
FillRect(BRect(pos+thickness-1,Bounds().top+pad+1,pos+thickness-1,Bounds().bottom-pad-1)); // 96
//FillRect(BRect(pos+thickness,Bounds().top+pad+1,pos+thickness,Bounds().bottom-pad-1));
}else{
SetHighColor(185,185,185);
// SetHighColor(145,145,145);
//FillRect(BRect(Bounds().left+pad+1,pos,Bounds().right-pad-1,pos)); // 145
FillRect(BRect(Bounds().left+pad+1,pos,Bounds().right-pad-1,pos)); // 145
SetHighColor(255,255,255);
FillRect(BRect(Bounds().left+pad+1,pos+1,Bounds().right-pad-1,pos+2)); // 255
//SetHighColor(216,216,216);
SetHighColor(Parent()->ViewColor());
FillRect(BRect(Bounds().left+pad+1,pos+2,Bounds().right-pad-1,pos+thickness-2));// 216
if(thickness>9)
{
SetHighColor(255,255,255);
float x = (Bounds().right - Bounds().left)/2;
float y = pos + (thickness/2);
SetPenSize(2);
StrokeLine(BPoint(x-11,y-3),BPoint(x-5,y+3));
StrokeLine(BPoint(x-7,y-3),BPoint(x-1,y+3));
StrokeLine(BPoint(x-3,y-3),BPoint(x+3,y+3));
StrokeLine(BPoint(x+1,y-3),BPoint(x+7,y+3));
StrokeLine(BPoint(x+5,y-3),BPoint(x+11,y+3));
SetPenSize(1);
SetHighColor(145,145,145);
StrokeLine(BPoint(x-10,y-3),BPoint(x-4,y+3));
StrokeLine(BPoint(x-6,y-3),BPoint(x+0,y+3));
StrokeLine(BPoint(x-2,y-3),BPoint(x+4,y+3));
StrokeLine(BPoint(x+2,y-3),BPoint(x+8,y+3));
StrokeLine(BPoint(x+6,y-3),BPoint(x+12,y+3));
}
SetHighColor(185,185,185);
// SetHighColor(145,145,145);
FillRect(BRect(Bounds().left+pad+1,pos+thickness-2,Bounds().right-pad-1,pos+thickness-2)) ;// 145
SetHighColor(145,145,145);
// SetHighColor(96,96,96);
FillRect(BRect(Bounds().left+pad+1,pos+thickness-1,Bounds().right-pad-1,pos+thickness-1)); // 96
//FillRect(BRect(Bounds().left+pad+1,pos+thickness,Bounds().right-pad-1,pos+thickness));
}
}
/*******************************************************
* Keeps Modes for both panles uptodate and acctually
* is the func that sets the location of the slider
*******************************************************/
void SplitPane::Update(){
Window()->Lock();
if(align == B_VERTICAL){
PaneOne->SetResizingMode(B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM);
PaneTwo->SetResizingMode(B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM);
if(pos > (Bounds().Width()-thickness-MinSizeTwo)){
if(!poslocked){
pos = (int)Bounds().Width()-thickness-MinSizeTwo;
}
}
if(pos < MinSizeOne){
if(!poslocked){
pos = MinSizeOne;
}
}
}else{
PaneOne->SetResizingMode(B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP);
PaneTwo->SetResizingMode(B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM);
if(pos > (Bounds().Height()-thickness-MinSizeTwo)){
if(!poslocked){
pos = (int)Bounds().Height()-thickness-MinSizeTwo;
}
}
if(pos < MinSizeOne){
if(!poslocked){
pos = MinSizeOne;
}
}
}
// this block should go in FrameResized .. think about it
if(align == B_VERTICAL){
if(pos >= (Bounds().IntegerWidth()/2)){
//pos should follow the right side
// staying the same distans from it that
// it is right now
}
}else{
if(pos >= (Bounds().IntegerHeight()/2)){
//should follow bottom and stay the
// same distance that we are way from
// it now
}
}
if(PaneOne){
if(!WinOne){
if(align == B_VERTICAL){
PaneOne->MoveTo(pad,Bounds().top+pad);
PaneOne->ResizeTo(pos-pad, Bounds().Height()-pad-pad); // widht x height
}else{
PaneOne->MoveTo(pad,Bounds().top+pad);
PaneOne->ResizeTo(Bounds().Width()-pad-pad, pos-pad-pad); // widht x height
}
}
}
if(PaneTwo){
if(!WinTwo){
if(align == B_VERTICAL){
PaneTwo->MoveTo(pos+thickness,Bounds().top+pad);
PaneTwo->ResizeTo(Bounds().Width()-(pos+thickness)-pad, Bounds().Height()-pad-pad);
}else{
PaneTwo->MoveTo(Bounds().left+pad,pos+thickness);
PaneTwo->ResizeTo(Bounds().Width()-pad-pad, Bounds().Height()-pos-pad-thickness);
}
}
}
Window()->Unlock();
}
/*******************************************************
* Hook for when we click. This takes care of all the
* little stuff - Like where is the mouse and what is
* going on.
*******************************************************/
void SplitPane::MouseDown(BPoint where){
Window()->Lock();
BMessage *currentMsg = Window()->CurrentMessage();
if (currentMsg->what == B_MOUSE_DOWN) {
uint32 buttons = 0;
currentMsg->FindInt32("buttons", (int32 *)&buttons);
uint32 modifiers = 0;
currentMsg->FindInt32("modifiers", (int32 *)&modifiers);
uint32 clicks = 0;
currentMsg->FindInt32("clicks",(int32*)&clicks);
if (buttons & B_SECONDARY_MOUSE_BUTTON){
if(!alignlocked){
switch(align){
case B_VERTICAL:
align = B_HORIZONTAL;
break;
case B_HORIZONTAL:
align = B_VERTICAL;
break;
}
Update();
Invalidate();
}
/*if(VOneDetachable){
WinOne = new BWindow(ConvertToScreen(PaneOne->Bounds()),"PanelOne",B_TITLED_WINDOW,B_ASYNCHRONOUS_CONTROLS);
RemoveChild(PaneOne);
WinOne->AddChild(PaneOne);
PaneOne->SetResizingMode(B_FOLLOW_ALL_SIDES);
// PaneOne->SetTarget(this);
WinOne->Show();
}*/
}
// if((buttons & B_PRIMARY_MOUSE_BUTTON) && (clicks >= 2)){
//Config window for split pane
// (new BAlert(NULL,"This is - or will be - a configuration panel for SplitPane.","Ok"))->Go();
//ConfigWindow = new SplitPaneConfig(this);
//ConfigWindow->Show();
//}else
if((buttons & B_PRIMARY_MOUSE_BUTTON) && !Draggin){
if(!poslocked){
Draggin= true; // this is so we can drag
here = where;
}
SetMouseEventMask(B_POINTER_EVENTS,B_LOCK_WINDOW_FOCUS);
}
}
Window()->Unlock();
}
/*******************************************************
* If we unclick then stop dragging or whatever it is
* we are doing
*******************************************************/
void SplitPane::MouseUp(BPoint where){
Draggin = false; // stop following mouse
}
/*******************************************************
* If the mouse moves while we dragg. Then follow it
* Also Invalidate so we update the views
*******************************************************/
void SplitPane::MouseMoved(BPoint where,uint32 info,const BMessage *m){
if(Draggin){
switch(align){
case B_HORIZONTAL:
pos = (int)(where.y)-(thickness/2);//- here.x
break;
case B_VERTICAL:
pos = (int)(where.x)-(thickness/2);
break;
}
/*
// This code figures out which jump we are closest
// to and if needed we "snap" to that.
int c = Bounds().IntegerWidth() / pos
Jump * c ... hmmm this is not right at all
*/
if(pos < MinSizeOne){
pos = MinSizeOne;
}
if(align == B_VERTICAL){
if(pos > (Bounds().Width() - thickness - MinSizeTwo)){
pos = (int)(Bounds().Width() - thickness - MinSizeTwo + 1);
}
}else{
if(pos > (Bounds().Height() - thickness - MinSizeTwo)){
pos = (int)(Bounds().Height() - thickness - MinSizeTwo + 1);
}
}
Update();
Invalidate();
}
}
/*******************************************************
* If you already have a view One, but want to change
* if for some odd reason. This should work.
*******************************************************/
void SplitPane::AddChildOne(BView *v){
RemoveChild(PaneOne);
PaneOne = v;
AddChild(PaneOne);
}
/*void SplitPane::MakePaneTwoFocus()
{
if(PaneTwo)
PaneTwo->MakeFocus();
}
*/
/*******************************************************
* If you already have a view Two, and want to put
* another view there, this is what to use.
*******************************************************/
void SplitPane::AddChildTwo(BView* v,bool IsAdded,bool ShowAfterHide)
{
if(!v->IsHidden())
v->Hide();
PaneTwo = v;
//WinTwo = NULL;
PaneTwo = v;
if(IsAdded)
{
Update();
if(ShowAfterHide)
{
if(v->IsHidden())
v->Show();
}
}
if(!IsAdded)
{
AddChild(PaneTwo);
}
PaneTwo = v;
}
/*******************************************************
* Sets is we are horizontal or Vertical. We use the
* standard B_HORIZONTAL and B_VERTICAL flags for this
*******************************************************/
void SplitPane::SetAlignment(uint a){
align = a;
if(attached){
Update();
}
Invalidate();
}
/*******************************************************
* Returns wheather the slider is horizontal or vertical
*******************************************************/
uint SplitPane::GetAlignment(){
return align;
}
/*******************************************************
* Sets the location of the bar. (we do no bounds
* checking for you so if its off the window thats
* your problem)
*******************************************************/
void SplitPane::SetBarPosition(int i){
pos = i;
if(attached){
Update();
}
Invalidate();
}
/*******************************************************
* Returns about where the bar is ...
*******************************************************/
int SplitPane::GetBarPosition(){
return pos;
}
/*******************************************************
* Sets how thick the bar should be.
*******************************************************/
void SplitPane::SetBarThickness(int i){
thickness = i;
if(attached){
Update();
}
Invalidate();
}
/*******************************************************
* Retuns to us the thickness of the slider bar
*******************************************************/
int SplitPane::GetBarThickness(){
return thickness;
}
/*******************************************************
* Sets the amount of jump the bar has when it is
* moved. This can also be though of as snap. The bar
* will start at 0 and jump(snap) to everry J pixels.
*******************************************************/
void SplitPane::SetJump(int i){
jump = i;
if(attached){
Update();
}
}
/*******************************************************
* Lets you know what the jump is .. see SetJump
*******************************************************/
int SplitPane::GetJump(){
return jump;
}
/*******************************************************
* Do we have a View One or is it NULL
*******************************************************/
bool SplitPane::HasViewOne(){
if(PaneOne) return true;
return false;
}
/*******************************************************
* Do we have a View Two .. or is it NULL too
*******************************************************/
bool SplitPane::HasViewTwo(){
if(PaneTwo) return true;
return false;
}
/*******************************************************
* Sets wheather View one is detachable from the
* slider view and from the app. This will creat a
* window that is detached (floating) from the app.
*******************************************************/
void SplitPane::SetViewOneDetachable(bool b){
VOneDetachable = b;
}
/*******************************************************
* Sets view tow detachable or not
*******************************************************/
void SplitPane::SetViewTwoDetachable(bool b){
VTwoDetachable = b;
}
/*******************************************************
* Returns whether the view is detachable
*******************************************************/
bool SplitPane::IsViewOneDetachable(){
return VOneDetachable;
}
/*******************************************************
* Returns if this view is detachable
*******************************************************/
bool SplitPane::IsViewTwoDetachable(){
return VTwoDetachable;
}
/*******************************************************
* Tells the view if the user is alowed to open the
* configuration window for the slider.
*******************************************************/
void SplitPane::SetEditable(bool b){
//ADD CODE HERE YNOP
}
/*******************************************************
* Tells use if the split pane is user editable
*******************************************************/
bool SplitPane::IsEditable(){
return true; //ADD SOME MORE CODE HERE
}
/*******************************************************
* Sets the inset that the view has.
*******************************************************/
void SplitPane::SetViewInsetBy(int i){
pad = i;
if(attached){
Update();
} Invalidate();
}
/*******************************************************
* Returns to use the padding around the views
*******************************************************/
int SplitPane::GetViewInsetBy(){
return pad;
}
/*******************************************************
* This sets the minimum size that View one can be.
* if the user trys to go past this .. we just stop
* By default the minimum size is set to 0 (zero) so
* the user can put the slider anywhere.
*******************************************************/
void SplitPane::SetMinSizeOne(int i){
MinSizeOne = i;
}
/*******************************************************
* Gives us the minimum size that one can be.
*******************************************************/
int SplitPane::GetMinSizeOne(){
return MinSizeOne;
}
/*******************************************************
* This sets the Minimum size that the second view
* can be.
*******************************************************/
void SplitPane::SetMinSizeTwo(int i){
MinSizeTwo = i;
}
/*******************************************************
* Lets us know what that minimum size is.
*******************************************************/
int SplitPane::GetMinSizeTwo(){
return MinSizeTwo;
}
/*******************************************************
* Locks the bar from being moved by the User. The
* system can still move the bar (via SetBarPosition)
*******************************************************/
void SplitPane::SetBarLocked(bool b){
poslocked = b;
}
/*******************************************************
* Returns to use if the bar is in a locked state or
* not.
*******************************************************/
bool SplitPane::IsBarLocked(){
return poslocked;
}
/*******************************************************
* Locks the alignment of the bar. The user can no
* longer toggle between Horizontal and Vertical
* Slider bar. Again you can still progomaticly set
* the position how ever you want.
*******************************************************/
void SplitPane::SetBarAlignmentLocked(bool b){
alignlocked = b;
}
/*******************************************************
* Lets us know about the lock state of the bar
*******************************************************/
bool SplitPane::IsBarAlignmentLocked(){
return alignlocked;
}
/*******************************************************
* Gets the Total state of the bar, alignment, size,
* position and many other things that are required
* to fully capture the state of the SplitPane.
* We pack all of this into a cute little BMessage
* so that it is esally expandable and can be saved
* off easyaly too. The SplitPane System does not
* however save the state for you. Your program must
* grab the state and save it in its config file.
*******************************************************/
BMessage* SplitPane::GetState(){
BMessage *state;
state = new BMessage(SPLITPANE_STATE);
state->AddBool("onedetachable",VOneDetachable);
state->AddBool("twodetachable",VTwoDetachable);
state->AddInt32("align",align);
state->AddInt32("pos",pos);
state->AddInt32("thick",thickness);
state->AddInt32("jump",jump);
state->AddInt32("pad",pad);
state->AddInt32("minsizeone",MinSizeOne);
state->AddInt32("minsizetwo",MinSizeTwo);
state->AddBool("poslock",poslocked);
state->AddBool("alignlock",alignlocked);
return state;
// delete state;
}
/*******************************************************
* Sets the state of the SplitPane from a BMessage
* like the one recived from GetState().
* This is one of three ways the user can rebuild the
* state of the SplitPane. The second is to simply
* send the SplitPane the state message, it is the
* same as calling SetState but it ashyncronouse.
* The third way is to use all the Get/Set methouds
* for each element of the SplitPane, this way is
* long and boarding. I suggest you just send the
* View a message :)
*******************************************************/
void SplitPane::SetState(BMessage *state){
int32 Npos,Nthickness,Njump,Npad,NMSO,NMST;
int32 Nalign;//uint
if(state->FindBool("onedetachable",&VOneDetachable) != B_OK){
VOneDetachable = false;
}
if(state->FindBool("towdetachable",&VTwoDetachable) != B_OK){
VTwoDetachable = false;
}
if(state->FindInt32("align",&Nalign) == B_OK){
align = Nalign;
}
if(state->FindInt32("pos",&Npos) == B_OK){
pos = Npos;
}
if(state->FindInt32("thick",&Nthickness) == B_OK){
thickness = Nthickness;
}
if(state->FindInt32("jump",&Njump) == B_OK){
jump = Njump;
}
if(state->FindInt32("pad",&Npad) == B_OK){
pad = Npad;
}
if(state->FindInt32("minsizeonw",&NMSO) == B_OK){
MinSizeOne = NMSO;
}
if(state->FindInt32("minsizetwo",&NMST) == B_OK){
MinSizeTwo = NMST;
}
if(state->FindBool("poslock",&poslocked) != B_OK){
poslocked = false;
}
if(state->FindBool("alignlock",&alignlocked) != B_OK){
alignlocked = false;
}
Update();
Invalidate();
}
/*******************************************************
* Ok, hmm what does this do. NOT MUCH. if we get a
* STATE message then lets set the state. This is here
* to provide a asyncronuse way of seting the state and
* also to make life easyer.
*******************************************************/
void SplitPane::MessageReceived(BMessage *msg){
switch(msg->what){
case SPLITPANE_STATE:
SetState(msg);
break;
default:
BView::MessageReceived(msg);
break;
}
}

93
src/SplitPane.h Normal file
View File

@@ -0,0 +1,93 @@
/*******************************************************
* SplitPane©
*
* SplitPane is a usefull UI component. It alows the
* use to ajust two view Horizontaly or Vertacly so
* that they are a desired size. This type of Pane
* shows up most comonly in Mail/News Readers.
*
* @author YNOP (ynop@acm.org)
* @version beta
* @date Dec. 10 1999
*******************************************************/
#ifndef _SPLIT_PANE_VIEW_H
#define _SPLIT_PANE_VIEW_H
#include <Application.h>
#include <AppKit.h>
// #include <InterfaceKit.h>
#include <iostream>
#include <ScrollView.h>
#define SPLITPANE_STATE 'spst'
class SplitPane : public BView {
public:
SplitPane(BRect,const char*,BView*,BView*,uint32);
void AddChildOne(BView*);
void AddChildTwo(BView* v,bool IsAdded,bool ShowAfterHide);
void SetAlignment(uint);
uint GetAlignment();
void SetBarPosition(int);
int GetBarPosition();
void SetBarThickness(int);
int GetBarThickness();
void SetJump(int);
int GetJump();
bool HasViewOne();
bool HasViewTwo();
void SetViewOneDetachable(bool);
void SetViewTwoDetachable(bool);
bool IsViewOneDetachable();
bool IsViewTwoDetachable();
void SetEditable(bool);
bool IsEditable();
void SetViewInsetBy(int);
int GetViewInsetBy();
void SetMinSizeOne(int);
int GetMinSizeOne();
void SetMinSizeTwo(int);
int GetMinSizeTwo();
BMessage* GetState();
void SetBarLocked(bool);
bool IsBarLocked();
void SetBarAlignmentLocked(bool);
bool IsBarAlignmentLocked();
void SetState(BMessage*);
virtual void Draw(BRect);
virtual void AttachedToWindow();
virtual void FrameResized(float,float);
virtual void MouseDown(BPoint);
virtual void MouseUp(BPoint);
virtual void MouseMoved(BPoint,uint32,const BMessage*);
virtual void MessageReceived(BMessage*);
//void MakePaneTwoFocus();
private:
void Update();
BView *PaneOne;
BView *PaneTwo;
//State info
bool VOneDetachable;
bool VTwoDetachable;
uint align;
int pos;
int thickness;
int jump;
int pad;
int MinSizeOne;
int MinSizeTwo;
bool poslocked;
bool alignlocked;
//end State info
bool Draggin;
BPoint here;
bool attached;
BWindow *WinOne;
BWindow *WinTwo;
BWindow *ConfigWindow;
};
#endif

1126
src/URLView.cpp Normal file

File diff suppressed because it is too large Load Diff

141
src/URLView.h Normal file
View File

@@ -0,0 +1,141 @@
/* URLView 2.11
written by William Kakes of Tall Hill Software.
This class provides an underlined and clickable BStringView
that will launch the web browser, e-mail program, or FTP client
when clicked on. Other features include hover-highlighting,
right-click menus, and drag-and-drop support.
You are free to use URLView in your own programs (both open-source
and closed-source) free of charge, but a mention in your read me
file or your program's about box would be appreciated. See
http://www.tallhill.com for current contact information.
URLView is provided as-is, with no warranties of any kind. If
you use it, you are on your own.
*/
#ifndef TH_URL_VIEW_H
#define TH_URL_VIEW_H
#include <Cursor.h>
#include <List.h>
#include <Mime.h>
#include <PopUpMenu.h>
#include <String.h>
#include <StringView.h>
// This is the link's mouse cursor (a replica of NetPositive's link cursor).
const uint8 url_cursor[] = { 16, 1, 1, 2,
// This is the cursor data.
0x00, 0x00, 0x38, 0x00, 0x24, 0x00, 0x24, 0x00,
0x13, 0xe0, 0x12, 0x5c, 0x09, 0x2a, 0x08, 0x01,
0x3c, 0x21, 0x4c, 0x71, 0x42, 0x71, 0x30, 0xf9,
0x0c, 0xf9, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
// This is the cursor mask.
0x00, 0x00, 0x38, 0x00, 0x3c, 0x00, 0x3c, 0x00,
0x1f, 0xe0, 0x1f, 0xfc, 0x0f, 0xfe, 0x0f, 0xff,
0x3f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x3f, 0xff,
0x0f, 0xff, 0x03, 0xfe, 0x01, 0xf8, 0x00, 0x00,
};
// The default link color, blue.
const rgb_color blue = { 0, 0, 255 };
// The default clicked-link color, red.
const rgb_color red = { 255, 0, 0 };
// The default link hover color, dark blue.
const rgb_color dark_blue = { 0, 0, 120 };
// The default disabled color, gray.
const rgb_color gray = { 100, 100, 100 };
class URLView : public BStringView {
public:
URLView( BRect frame, const char *name, const char *label, const char *url,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW );
~URLView();
virtual void AttachedToWindow();
virtual void Draw( BRect updateRect );
virtual void MessageReceived( BMessage *message );
virtual void MouseDown( BPoint point );
virtual void MouseMoved( BPoint point, uint32 transit, const BMessage *message );
virtual void MouseUp( BPoint point );
virtual void WindowActivated( bool active );
virtual void AddAttribute( const char *name, const char *value );
virtual bool IsEnabled();
virtual void SetColor( rgb_color color );
virtual void SetColor( uchar red, uchar green, uchar blue, uchar alpha = 255 );
virtual void SetClickColor( rgb_color color );
virtual void SetClickColor( uchar red, uchar green, uchar blue, uchar alpha = 255 );
virtual void SetDisabledColor( rgb_color color );
virtual void SetDisabledColor( uchar red, uchar green, uchar blue, uchar alpha = 255 );
virtual void SetDraggable( bool draggable );
virtual void SetEnabled( bool enabled );
virtual void SetHoverColor( rgb_color color );
virtual void SetHoverColor( uchar red, uchar green, uchar blue, uchar alpha = 255 );
virtual void SetHoverEnabled( bool hover );
virtual void SetIconSize( icon_size iconSize );
virtual void SetUnderlineThickness( int thickness );
virtual void SetURL( const char *url );
private:
void CopyToClipboard();
void CreateBookmark( const BString *fullName, const BString *title );
void CreatePerson( const BString *fullName, const BString *title );
BPopUpMenu *CreatePopupMenu();
void DoBookmarkDrag();
void DoPersonDrag();
BString GetImportantURL();
BRect GetTextRect();
BRect GetURLRect();
bool IsEmailLink();
bool IsFTPLink();
bool IsHTMLLink();
void LaunchURL();
void Redraw();
void WriteAttributes( int fd );
BString *url;
rgb_color color;
rgb_color clickColor;
rgb_color hoverColor;
rgb_color disabledColor;
bool enabled;
bool hoverEnabled;
bool draggable;
int underlineThickness;
int iconSize;
bool selected;
bool hovering;
bool draggedOut;
bool inPopup;
const BCursor *linkCursor;
BPoint dragOffset;
BList *attributes;
typedef struct kp {
BString *key;
BString *value;
} KeyPair;
};
#endif // TH_URL_VIEW

38
src/YAB.rdef Normal file
View File

@@ -0,0 +1,38 @@
resource vector_icon {
$"6E6369660E0500020006023C43C6B9E5E23A85A83CEE414268F44A445900C6D7"
$"F5FF6B94DD03EC66660200060238C5F1BB105D3DFDC23B9CD045487847B50700"
$"FFFFFFFFC1CCFF020006023B3049396B0ABA90833C646E4A101543299500FFFF"
$"FFFFEBEFFF020006023C71E33A0C78BA15E43C7D2149055549455700E3EDFFFF"
$"9EC2FF03FFACAC0200060239D53438FFCBBBC1973C666F4ADC3246DC6C00C1CC"
$"FFFFFFFFFF03003CB0020006023C0AE63B3927BC611E3D03FF4C25624A1A9600"
$"A3043CFFFF90AF03C93B3B030D296402000602BD498B3E1159BF219BBE7D2F4C"
$"1B8F4A331300BD0F0FFFE98484040174100A08325E385E40564E5E545E605058"
$"4C3E510A062E2C2E3E3E454A3C4A2A3A250A042E2C2E3E3E453E320A042E2C3E"
$"324A2A3A250A043E323E454A3C4A2A0A0338423C4D3C440A0622422254325C3E"
$"513E402E3A0A0422422254325C32490A04224232493E402E3A0A043249325C3E"
$"513E400A063E423E544E5C5A505A3F4A390A04C222C20F4E495A3F523C0A043E"
$"42C222C20F523C4A390A054151C08BC8834E5C4E49C22AC2130A053E423E54C0"
$"8BC8834151C22AC2130A044E494E5C5A505A3F110A0D0100000A0001061815FF"
$"01178400040A00010618001501178600040A010107000A080109000A0B010520"
$"20210A050108000A00010A1001178400040A02010D000A0A010E000A0902040F"
$"000A06010B000A0C010C000A0001011001178400040A030102000A040103000A"
$"07010400"
};
resource app_signature "application/x-vnd.yab-app";
resource app_version {
major = 1,
middle = 7,
minor = 4,
variety = B_APPV_FINAL,
internal = 1,
short_info = "Yab BASIC programming language",
long_info = "Yab allows fast prototyping with simple and clean code. yab contains a large number of BeAPI specific commands for GUI creation and much, much more."
};
resource app_flags 1;

BIN
src/YAB.rdef.rsrc Normal file

Binary file not shown.

117
src/YabBitmapView.cpp Normal file
View File

@@ -0,0 +1,117 @@
#include <Bitmap.h>
#include <Path.h>
#include <Picture.h>
#include <Region.h>
#include <View.h>
#include "YabWindow.h"
#include "YabBitmapView.h"
YabBitmapView::YabBitmapView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags)
{
bmp = new BBitmap(BRect(0,0, frame.Width(), frame.Height()), B_RGBA32, true);
BView *myView = new BView(BRect(0,0, frame.Width(), frame.Height()), "canvas", B_FOLLOW_NONE, 0);
bmp->AddChild(myView);
SetDrawingMode(B_OP_COPY);
SetViewColor(0,0,0,255);
mouseMovedInfo = 1;
mouseStateInfo = -1;
prevMouseStateInfo = 0;
mouseX = 0;
mouseY = 0;
mouseLButton = 0;
mouseMButton = 0;
mouseRButton = 0;
}
YabBitmapView::~YabBitmapView()
{
delete bmp;
}
BBitmap* YabBitmapView::GetBitmap()
{
return bmp;
}
BView* YabBitmapView::GetBitmapView()
{
return bmp->FindView("canvas");
}
void YabBitmapView::Draw(BRect updateRect)
{
DrawBitmap(bmp, updateRect, updateRect);
}
void YabBitmapView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, true);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
switch(transit)
{
case B_INSIDE_VIEW:
if(prevMouseStateInfo==1)
mouseStateInfo = 0;
else
{
mouseStateInfo = 1;
prevMouseStateInfo = 1;
}
mouseMovedInfo = 0;
break;
case B_ENTERED_VIEW:
mouseStateInfo = 1;
mouseMovedInfo = 0;
break;
case B_OUTSIDE_VIEW:
mouseStateInfo = 2;
mouseMovedInfo = 1;
break;
case B_EXITED_VIEW:
mouseStateInfo = 3;
mouseMovedInfo = 1;
prevMouseStateInfo = 0;
break;
}
BView::MouseMoved(point, transit, message);
}
void YabBitmapView::MouseDown(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 4;
BView::MouseDown(point);
}
void YabBitmapView::MouseUp(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 5;
BView::MouseUp(point);
}

31
src/YabBitmapView.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef YABBITMAPVIEW_H
#define YABBITMAPVIEW_H
#include <View.h>
class YabBitmapView : public BView
{
public:
YabBitmapView(BRect frame, const char *name, uint32 resizingMode, uint32 flags);
~YabBitmapView();
virtual void Draw(BRect updateRect);
BBitmap* GetBitmap();
BView* GetBitmapView();
BBitmap *bmp;
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
virtual void MouseUp(BPoint point);
virtual void MouseDown(BPoint point);
int mouseStateInfo;
int mouseMovedInfo;
int mouseX;
int mouseY;
uint mouseLButton;
uint mouseMButton;
uint mouseRButton;
private:
int prevMouseStateInfo;
};
#endif

257
src/YabControlLook.cpp Normal file
View File

@@ -0,0 +1,257 @@
#include <GradientLinear.h>
#include <Region.h>
#include "YabControlLook.h"
YabControlLook::YabControlLook()
{ }
YabControlLook::~YabControlLook()
{ }
void YabControlLook::DrawActiveTabBottom(BView* view, BRect& rect, const BRect& updateRect, const rgb_color& base, uint32 flags, uint32 borders)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
rgb_color edgeShadowColor;
rgb_color edgeLightColor;
rgb_color frameShadowColor;
rgb_color frameLightColor;
rgb_color bevelShadowColor;
rgb_color bevelLightColor;
BGradientLinear fillGradient;
fillGradient.SetStart(rect.LeftBottom() + BPoint(3, -3));
fillGradient.SetEnd(rect.LeftTop() + BPoint(3, 3));
if (flags & B_DISABLED) {
edgeShadowColor = base;
edgeLightColor = base;
frameShadowColor = tint_color(base, 1.30);
frameLightColor = tint_color(base, 1.25);
bevelShadowColor = tint_color(base, 1.07);
bevelLightColor = tint_color(base, 0.8);
fillGradient.AddColor(tint_color(base, 0.85), 0);
fillGradient.AddColor(base, 255);
} else {
edgeShadowColor = tint_color(base, 1.03);
edgeLightColor = tint_color(base, 0.80);
frameShadowColor = tint_color(base, 1.30);
frameLightColor = tint_color(base, 1.30);
bevelShadowColor = tint_color(base, 1.07);
bevelLightColor = tint_color(base, 0.6);
fillGradient.AddColor(tint_color(base, 0.75), 0);
fillGradient.AddColor(tint_color(base, 1.03), 255);
}
static const float kRoundCornerRadius = 4;
// left/top corner
BRect cornerRect(rect);
cornerRect.right = cornerRect.left + kRoundCornerRadius;
cornerRect.top = cornerRect.bottom - kRoundCornerRadius;
BRegion clipping(rect);
clipping.Exclude(cornerRect);
_DrawRoundCornerLeftBottom(view, cornerRect, updateRect, base, edgeShadowColor,
frameLightColor, bevelLightColor, fillGradient);
// left/top corner
cornerRect.right = rect.right;
cornerRect.left = cornerRect.right - kRoundCornerRadius;
clipping.Exclude(cornerRect);
_DrawRoundCornerRightBottom(view, cornerRect, updateRect, base, edgeShadowColor,
edgeLightColor, frameLightColor, frameShadowColor, bevelLightColor,
bevelShadowColor, fillGradient);
// rest of frame and fill
view->ConstrainClippingRegion(&clipping);
_DrawFrame(view, rect, edgeShadowColor, edgeLightColor, edgeLightColor,
edgeShadowColor,
borders & (B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER));
if ((borders & B_LEFT_BORDER) == 0)
rect.left++;
if ((borders & B_RIGHT_BORDER) == 0)
rect.right--;
_DrawFrame(view, rect, frameLightColor, frameShadowColor, frameShadowColor,
frameLightColor, B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER);
_DrawFrame(view, rect, bevelLightColor, bevelShadowColor, bevelShadowColor,
bevelLightColor);
view->FillRect(rect, fillGradient);
view->SetHighColor(216,216,216);
view->StrokeLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.top));
view->ConstrainClippingRegion(NULL);
}
void YabControlLook::DrawInactiveTabBottom(BView* view, BRect& rect,const BRect& updateRect, const rgb_color& base, uint32 flags, uint32 borders)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
rgb_color edgeShadowColor;
rgb_color edgeLightColor;
rgb_color frameShadowColor;
rgb_color frameLightColor;
rgb_color bevelShadowColor;
rgb_color bevelLightColor;
BGradientLinear fillGradient;
fillGradient.SetStart(rect.LeftBottom() + BPoint(3, -3));
fillGradient.SetEnd(rect.LeftTop() + BPoint(3, 3));
if (flags & B_DISABLED) {
edgeShadowColor = base;
edgeLightColor = base;
frameShadowColor = tint_color(base, 1.30);
frameLightColor = tint_color(base, 1.25);
bevelShadowColor = tint_color(base, 1.07);
bevelLightColor = tint_color(base, 0.8);
fillGradient.AddColor(tint_color(base, 0.85), 0);
fillGradient.AddColor(base, 255);
} else {
edgeShadowColor = tint_color(base, 1.03);
edgeLightColor = tint_color(base, 0.80);
frameShadowColor = tint_color(base, 1.30);
frameLightColor = tint_color(base, 1.30);
bevelShadowColor = tint_color(base, 1.17);
bevelLightColor = tint_color(base, 1.10);
fillGradient.AddColor(tint_color(base, 1.12), 0);
fillGradient.AddColor(tint_color(base, 1.08), 255);
}
// active tabs stand out at the top, but this is an inactive tab
view->SetHighColor(base);
view->FillRect(BRect(rect.left, rect.bottom - 4, rect.right, rect.bottom));
rect.bottom -= 4;
// frame and fill
_DrawFrame(view, rect, edgeShadowColor, edgeShadowColor, edgeLightColor,
edgeLightColor,
borders & (B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER));
_DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor,
frameShadowColor,
borders & (B_LEFT_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER));
if (rect.IsValid()) {
_DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
bevelLightColor, bevelLightColor, B_LEFT_BORDER & ~borders);
} else {
if ((B_LEFT_BORDER & ~borders) != 0)
rect.left++;
}
view->FillRect(rect, fillGradient);
}
void
YabControlLook::_DrawRoundCornerLeftBottom(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base, const rgb_color& edgeColor,
const rgb_color& frameColor, const rgb_color& bevelColor,
const BGradientLinear& fillGradient)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
BRegion clipping(rect);
view->ConstrainClippingRegion(&clipping);
// background
view->SetHighColor(base);
view->FillRect(rect);
// outer edge
BRect ellipseRect(rect);
ellipseRect.right = ellipseRect.left + ellipseRect.Width() * 2;
ellipseRect.top = ellipseRect.bottom - ellipseRect.Height() * 2;
view->SetHighColor(edgeColor);
view->FillEllipse(ellipseRect);
// frame
ellipseRect.InsetBy(1, 1);
view->SetHighColor(frameColor);
view->FillEllipse(ellipseRect);
// bevel
ellipseRect.InsetBy(1, 1);
view->SetHighColor(bevelColor);
view->FillEllipse(ellipseRect);
// fill
ellipseRect.InsetBy(1, 1);
view->FillEllipse(ellipseRect, fillGradient);
view->ConstrainClippingRegion(NULL);
}
void
YabControlLook::_DrawRoundCornerRightBottom(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base,
const rgb_color& edgeTopColor, const rgb_color& edgeRightColor,
const rgb_color& frameTopColor, const rgb_color& frameRightColor,
const rgb_color& bevelTopColor, const rgb_color& bevelRightColor,
const BGradientLinear& fillGradient)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
BRegion clipping(rect);
view->ConstrainClippingRegion(&clipping);
// background
view->SetHighColor(base);
view->FillRect(rect);
// outer edge
BRect ellipseRect(rect);
ellipseRect.left = ellipseRect.right - ellipseRect.Width() * 2;
ellipseRect.top = ellipseRect.bottom - ellipseRect.Height() * 2;
BGradientLinear gradient;
gradient.AddColor(edgeTopColor, 0);
gradient.AddColor(edgeRightColor, 255);
gradient.SetStart(rect.LeftTop());
gradient.SetEnd(rect.RightBottom());
view->FillEllipse(ellipseRect, gradient);
// frame
ellipseRect.InsetBy(1, 1);
rect.right--;
rect.top++;
if (frameTopColor == frameRightColor) {
view->SetHighColor(frameTopColor);
view->FillEllipse(ellipseRect);
} else {
gradient.SetColor(0, frameTopColor);
gradient.SetColor(1, frameRightColor);
gradient.SetStart(rect.LeftTop());
gradient.SetEnd(rect.RightBottom());
view->FillEllipse(ellipseRect, gradient);
}
// bevel
ellipseRect.InsetBy(1, 1);
rect.right--;
rect.top++;
gradient.SetColor(0, bevelTopColor);
gradient.SetColor(1, bevelRightColor);
gradient.SetStart(rect.LeftTop());
gradient.SetEnd(rect.RightBottom());
view->FillEllipse(ellipseRect, gradient);
// fill
ellipseRect.InsetBy(1, 1);
view->FillEllipse(ellipseRect, fillGradient);
view->ConstrainClippingRegion(NULL);
}

33
src/YabControlLook.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef YABCONTROLLOOK
#define YABCONTROLLOOK
#include <ControlLook.h>
class YabControlLook : public BControlLook
{
public:
YabControlLook();
~YabControlLook();
virtual void DrawActiveTabBottom(BView* view, BRect& rect, const BRect& updateRect, const rgb_color& base, uint32 flags = 0, uint32 borders = BControlLook::B_ALL_BORDERS);
virtual void DrawInactiveTabBottom(BView* view, BRect& rect, const BRect& updateRect, const rgb_color& base, uint32 flags = 0, uint32 borders = BControlLook::B_ALL_BORDERS);
void _DrawRoundCornerLeftBottom(BView* view,
BRect& rect, const BRect& updateRect,
const rgb_color& base,
const rgb_color& edgeColor,
const rgb_color& frameColor,
const rgb_color& bevelColor,
const BGradientLinear& fillGradient);
void _DrawRoundCornerRightBottom(BView* view,
BRect& rect, const BRect& updateRect,
const rgb_color& base,
const rgb_color& edgeTopColor,
const rgb_color& edgeRightColor,
const rgb_color& frameTopColor,
const rgb_color& frameRightColor,
const rgb_color& bevelTopColor,
const rgb_color& bevelRightColor,
const BGradientLinear& fillGradient);
};
#endif

79
src/YabFilePanel.cpp Normal file
View File

@@ -0,0 +1,79 @@
#include <Directory.h>
#include <Entry.h>
#include <FilePanel.h>
#include <Messenger.h>
#include <Window.h>
#include "YabFilePanel.h"
#include "YabFilePanelLooper.h"
BEntry *YabFilePanel::MyFilePanel(const char *name, const char *directory, const char* filename, int mode)
{
BEntry *myEntry = NULL;
entry_ref ref;
sem_id semaphore = create_sem(0, "yabfilepanel");
YabFilePanelLooper *myLooper = new YabFilePanelLooper(semaphore);
myLooper->Run();
if(directory)
{
myEntry=new BEntry(directory);
if(myEntry->GetRef(&ref)!=B_OK)
{
myEntry->Unset();
myEntry->SetTo("/boot/home/");
myEntry->GetRef(&ref);
}
myEntry->Unset();
delete myEntry;
}
BFilePanel *myFilePanel = NULL;
switch(mode)
{
case 0:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true);
break;
case 1:
myFilePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE, false, NULL, NULL, true, true);
if (filename) myFilePanel->SetSaveText(filename);
break;
case 2:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_DIRECTORY_NODE, false, NULL, NULL, true, true);
break;
case 3:
myFilePanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(myLooper, myLooper), &ref, B_FILE_NODE|B_DIRECTORY_NODE, false, NULL, NULL, true, true);
break;
}
if(name) myFilePanel->Window()->SetTitle(name);
myFilePanel->Show();
bool inloop = true;
while(inloop)
{
while(acquire_sem_etc(semaphore, 1, B_RELATIVE_TIMEOUT, 10000)==B_TIMED_OUT) ;
myEntry = myLooper->GetChosenFile();
inloop = false;
/*
if(mode!=2)
inloop = false;
else
{
if(myEntry->IsDirectory())
inloop = false;
else
{
myFilePanel->Show();
}
}
*/
}
myLooper->Lock();
myLooper->Quit();
delete_sem(semaphore);
delete myFilePanel;
return myEntry;
}

10
src/YabFilePanel.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef YABFILEPANEL_H
#define YABFILEPANEL_H
class YabFilePanel
{
public:
BEntry *MyFilePanel(const char *name, const char *directory, const char* filename, int panelType);
};
#endif

View File

@@ -0,0 +1,57 @@
#include <Entry.h>
#include <Directory.h>
#include "YabFilePanelLooper.h"
YabFilePanelLooper::YabFilePanelLooper(sem_id semaphore) : BLooper("YabFilePanelLooper")
{
myEntry=new BEntry();
mySemaphore = semaphore;
}
BEntry *YabFilePanelLooper::GetChosenFile()
{
return myEntry;
}
void YabFilePanelLooper::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
case B_REFS_RECEIVED:
{
entry_ref ref;
if (msg->FindRef("refs", 0, &ref)==B_OK)
myEntry->SetTo(&ref);
else
myEntry->Unset();
}
break;
case B_SAVE_REQUESTED:
{
const char *selected;
entry_ref ref;
if (msg->FindString("name", &selected)!=B_OK)
myEntry->Unset();
else
{
if (msg->FindRef("directory", 0, &ref)==B_OK)
{
BDirectory *myDirectory = new BDirectory(&ref);
myEntry->SetTo(myDirectory, selected);
myDirectory->Unset();
delete myDirectory;
}
else
myEntry->Unset();
}
}
break;
case B_CANCEL:
release_sem(mySemaphore);
break;
}
}

19
src/YabFilePanelLooper.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef YABFPLOOPER_H
#define YABFPLOOPER_H
#include <Looper.h>
#include <Message.h>
#include <Entry.h>
class YabFilePanelLooper : public BLooper
{
public:
YabFilePanelLooper(sem_id semaphore);
void MessageReceived(BMessage *msg);
BEntry *GetChosenFile();
private:
BEntry *myEntry;
sem_id mySemaphore;
};
#endif

10698
src/YabInterface.cpp Normal file

File diff suppressed because it is too large Load Diff

523
src/YabInterface.h Normal file
View File

@@ -0,0 +1,523 @@
#ifndef YABINTERFACE_H
#define YABINTERFACE_H
#ifdef __cplusplus
#include <Application.h>
#include <FilePanel.h>
#include <GraphicsDefs.h>
#include <ListItem.h>
#include <Menu.h>
#include <PropertyInfo.h>
#include <String.h>
#include <TranslatorRoster.h>
#include "YabList.h"
#include "global.h"
#include "config.h"
class YabInterface : public BApplication
{
public:
YabInterface(int argc, char** argv, const char* signature);
~YabInterface();
status_t GetSupportedSuites(BMessage *msg);
BHandler *ResolveSpecifier(BMessage *msg, int32 index, BMessage *spec, int32 form, const char *prop);
const char* GetApplicationDirectory();
void OpenWindow(const BRect frame, const char* id, const char* title);
int CloseWindow(const char* view);
void MessageReceived(BMessage *message);
bool QuitRequested();
bool ExitRequested();
void CreateButton(BRect frame, const char* id, const char* title, const char* window);
int CreateImage(BPoint coordinates, const char* imagefile, const char* window);
int CreateImage(BRect frame, const char* imagefile, const char* window);
int CreateSVG(BRect frame, const char* imagefile, const char* window);
void DrawText(BPoint coordinates, const char* text, const char* window);
void DrawRect(BRect frame, const char* window);
void DrawClear(const char* window, bool isExit);
void CreateAlert(const char* text, const char* button1, const char* option);
void CreateMenu(const char* menuhead, const char* menuitem, const char *shortcut, const char* window);
void CreateTextControl(BRect frame, const char *id, const char* label, const char* text, const char* window);
void CreateCheckBox(double x, double y, const char *id, const char* label, int isActivated, const char* window);
void CreateRadioButton(double x, double y, const char* groupID, const char* label, int isActivated, const char* window);
void CreateListBox(BRect frame, const char* title, int scrollbar, const char* window);
void CreateDropBox(BRect frame, const char* title, const char* label, const char* window);
void CreateItem(const char* id, const char* item);
void RemoveItem(const char* title, const char* item);
void ClearItems(const char* title);
void CreateText(double x, double y, const char *id, const char* text, const char* window);
void Text2(BRect frame, const char *id, const char* text, const char* window);
void TextAlign(const char* txt, const char *option);
const char* LoadFilePanel(const char* mode, const char* title, const char* directory);
const char* SaveFilePanel(const char* mode, const char* title, const char* directory, const char*filename);
void SetLayout(const char* layout, const char* window);
void WindowSet(const char* option, const char* value, const char* window);
void WindowSet(const char* option, int r, int g, int b, const char* window);
void WindowSet(const char* option, double x, double y, const char* window);
void WindowSet(const char* option, const char* window);
void WindowClear(const char* window);
void TextEdit(BRect frame, const char* title, int scrollbar, const char* window);
void TextAdd(const char* title, const char* text);
void TextSet(const char* title, const char* option);
void TextSet(const char* title, const char* option, int value);
void TextSet(const char* title, const char* option, const char* value);
void TextColor(const char* title, const char* option, const char* command);
void TextColor(const char* title, const char* option, int r, int g, int b);
void TextClear(const char* title);
const char* TextGet(const char* title);
const char* TextGet(const char* title, int linenum);
const char* TextGet6(const char* title, const char* option);
int TextGet(const char* title, const char* option);
double TextGet(const char* title, const char* option, int line);
int TextGet(const char* title, const char* option, const char* option2);
void DrawSet1(const char* option, const char* window);
void DrawSet2(int fillorstroke, const char* mypattern);
void View(BRect frame, const char* id, const char* view);
void BoxView(BRect frame, const char* id, const char* text, int lineType, const char* view);
void BoxViewSet(const char* id, const char* option, const char* value);
void Tab(BRect frame, const char* id, const char* names, const char* view);
void TabSet(const char* id, int num);
void TabAdd(const char* id, const char* name);
void TabDel(const char* id, int num);
int TabViewGet(const char* id);
void DrawDot(double x, double y, const char* window);
void DrawLine(double x1, double y1, double x2, double y2, const char* window);
void DrawCircle(double x, double y, double r, const char* window);
void DrawEllipse(double x, double y, double r1, double r2, const char* window);
void DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char* window);
void Slider(BRect frame, const char* id, const char* title, int min, int max, const char* view);
void Slider(BRect frame, const char* id, const char* title, int min, int max, const char* option, const char* view);
void SetSlider(const char* id, const char* label1, const char* label2);
void SetSlider(const char* id, const char* bottomtop, int count);
void SetSlider(const char* id, const char* part, int r, int g, int b);
void SetSlider(const char* id, int value);
void SetOption(const char* id, const char* option, const char* value);
void SetOption(const char* id, const char* option, int r, int g, int b);
void SetOption(const char* id, const char* option, double x, double y);
void SetOption(const char* id, const char* option);
void SetOption(const char* id, const char* option, int value);
void DropZone(const char* view);
void ColorControl(double x, double y, const char* id, const char* view);
void ColorControl(const char* id, int r, int g, int b);
void TextControl(const char* id, const char* text);
void TextControl(const char* id, int mode);
void TextControl(const char* id, const char* option, const char* value);
void TextControl(const char* id);
void TreeBox1(BRect frame, const char* id, int scrollbarType, const char* view);
void TreeBox2(const char* id, const char* item);
void TreeBox3(const char* id, const char* head, const char* item, int isExpanded);
void TreeBox4(const char* id);
void TreeBox5(const char* id, const char* item);
void TreeBox7(const char* id, int pos);
void TreeBox8(const char* id, int pos);
void TreeBox9(const char* id, const char* head, const char* item);
void TreeBox10(const char* id, const char* head);
void TreeBox11(const char* id, const char* head);
void TreeBox12(const char* id, const char* item, int pos);
void Launch(const char* strg);
const char* TreeboxGet(const char* treebox, int pos);
int TreeboxCount(const char* treebox);
void ButtonImage(double x, double y,const char* id,const char* enabledon, const char* enabledoff, const char* disabled, const char* view);
void CheckboxImage(double x, double y,const char* id,const char* enabledon, const char* enabledoff, const char *disabledon, const char *disabledoff, int isActivated, const char* view);
void CheckboxSet(const char* id, int isActivated);
void RadioSet(const char* id, int isActivated);
void ToolTips(const char* view, const char* text);
void ToolTipsColor(const char* color, int r, int g, int b);
void TreeSort(const char* view);
void ListSort(const char* view);
void FileBox(BRect frame, const char* id, bool scrollbartype, const char* option, const char* view);
void FileBoxAdd(const char* id, const char* name, int32 pos, double maxWidth, double minWidth, double width, const char* option);
void FileBoxClear(const char* view);
void ColumnBoxAdd(const char* id, int column, int position, int height, const char* item);
void ColumnBoxSelect(const char *columnbox, int position);
void ColumnBoxRemove(const char *columnbox, int position);
void ColumnBoxColor(const char *columnbox, const char* option, int r, int g, int b);
int Printer(const char* docname, const char *view, const char* config);
void PrinterConfig(const char* config);
void Calendar(double x, double y, const char* id, const char* format, const char* date, const char* view);
const char* Calendar(const char* id);
void Calendar(const char* id, const char* date);
void MouseSet(const char* opt);
void Scrollbar(const char* id, int format, const char* view);
void ScrollbarSet(const char* scrollview, const char* option, double position);
void ScrollbarSet(const char* scrollview, const char* option, double opt1, double opt2);
void ScrollbarSet(const char* scrollview, const char* option);
double ScrollbarGet(const char* scrollview, const char* option);
const char* ListboxGet(const char* listbox, int pos);
int ListboxCount(const char* listbox);
void ListboxAdd(const char* listbox, const char* item);
void ListboxAdd(const char* listbox, int pos, const char* item);
void ListboxSelect(const char* listbox, int pos);
void ListboxRemove(const char* listbox, int pos);
void SplitView(BRect frame, const char* id, int isVertical, int style, const char* view);
void SplitView(const char* splitView, const char* option, double position);
void SplitView(const char* splitView, const char* option, double left, double right);
double SplitViewGet(const char* splitView, const char* option);
void StackViews(BRect frame, const char* id, int number, const char* view);
void StackViews(const char* stackView, int num);
int StackViewGet(const char* stackView);
void DrawSet3(const char* option, int transparency);
void TextURL(double x, double y, const char* id, const char* text, const char* url, const char* view);
void TextURL(const char* id, const char* option, int r, int g, int b);
void Menu(const char* menuHead, int isRadio, const char* view);
void SubMenu(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* modifiers, const char* view);
void SubMenu(const char* menuHead, const char* menuItem, int isRadio, const char* view);
void SpinControl(double x, double y, const char* id, const char* label, int min, int max, int step, const char* view);
void SpinControl(const char* spinControl, int value);
int SpinControlGet(const char *spinControl);
const char* PopUpMenu(double x, double y, const char* menuItems, const char* view);
void DropBoxSelect(const char* dropbox, int position);
void DropBoxClear(const char* dropbox);
void DropBoxRemove(const char* dropbox, int position);
int DropBoxCount(const char* dropbox);
const char* DropBoxGet(const char* dropbox, int position);
int ColorControlGet(const char* colorcontrol, const char* option);
int SliderGet(const char* slider);
void SubMenu3(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* option, const char* view);
void Menu3(const char* menuHead, const char* menuItem, const char* option,const char* view);
double ScrollbarWidth();
double MenuHeight();
double TabHeight();
const char* ColumnBoxGet(const char *columnbox, int column, int position);
int ColumnBoxCount(const char *columnbox);
const char* TextControlGet(const char* id);
int WindowGet(const char* view, const char* option);
int ViewGet(const char* view, const char* option); //vasper
double DrawGet(const char* option, const char* txt, const char* view);
int DrawGet(BPoint coord, const char* option, const char* view);
const char* DrawGet(const char* option);
void ClipboardCopy(const char* text);
const char* ClipboardPaste();
int DeskbarParam(const char* option);
int DesktopParam(bool isWidth);
int NewAlert(const char* text, const char* button1, const char* button2, const char* button3, const char* option);
int ThreadKill(const char* option, int id);
int ThreadGet(const char* option, const char* appname);
const int IsMouseIn(const char* view);
const char* GetMouseIn();
const char* GetMouseMessages(const char* view);
const char* KeyboardMessages(const char* view);
const char* GetMessageString();
int MessageSend(const char* app, const char* msg);
void SetLocalize(const char* path);
void Bitmap(double w, double h, const char* id);
int BitmapColor(double x, double y, const char* id, const char* option);
void BitmapDraw(double x, double y, const char* bitmap, const char* mode, const char* view);
void BitmapDraw(BRect frame, const char* bitmap, const char* mode, const char* view);
void BitmapGet(BRect frame, const char* id, const char* bitmap);
void BitmapGet(double w, const char* id, const char* path);
int BitmapGet(const char* id, const char* option);
int BitmapLoad(const char* id, const char* option);
void BitmapGetIcon(const char* id, const char* option, const char* path);
void BitmapDrag(const char* bitmap);
void BitmapRemove(const char* bitmap);
void Screenshot(BRect frame, const char* bitmap);
int BitmapSave(const char* id, const char* filename, const char* type);
void Canvas(BRect frame, const char* id, const char* view);
int Sound(const char* filename);
void SoundStop(int32 id);
void SoundWait(int32 id);
int IsComputerOn();
void ShortCut(const char* view, const char* key, const char* msg);
void DrawSet(const char* option, const char* color,const char* view);
void Treebox13(const char* id,const char* option, int pos);
int TreeboxGetOpt(const char* id, const char* option, int pos);
int ListboxGetNum(const char* id);
int DropboxGetNum(const char* id);
int TreeboxGetNum(const char* id);
int ColumnboxGetNum(const char* id);
void Attribute1(const char* type, const char* name, const char* value, const char* filename);
void AttributeClear(const char* name, const char* filename);
const char* AttributeGet1(const char* name, const char* filename);
double AttributeGet2(const char* name, const char* filename);
const int GetErrorCode();
void Error(const char* id, const char* type);
void ErrorGen(const char* msg);
void SetCurrentLineNumber(int line, const char* libname);
void SetMainFileName(const char* name);
void KillThread(int code);
void StatusBar(BRect frame, const char* id, const char* label1, const char* label2, const char* view);
void StatusBarSet(const char* id, const char* label1, const char* label2, double state);
void StatusBarSet(BRect frame, const char* id, const char* view);
void StatusBarSet(const char* id, int r, int g, int b);
void RefsReceived(BMessage *message);
private:
void RemoveView(BView* myView);
void GetMMsgInfo(BString &t, int mouseStateInfo, int mouseLButton, int mouseMButton, int mouseRButton, int x, int y, const char* name);
BBitmap* loadImage(const char* name);
static int compare(BListItem **firstArg, BListItem **secondArg);
BTranslatorRoster *Roster;
char ApplicationDirectory[1024];
char loadPanel[1280];
char columntext[4096];
char mousemessagebuffer[64];
char keyboardbuffer[27];
char messagebuffer[32567];
char attrbuffer[32567];
char mouseoverbuffer[256];
BFilePanel *fopen, *fsave;
thread_id myThread;
int errorCode;
bool drawStroking;
int yabAlpha;
pattern yabPattern;
YabList *viewList;
int currentLineNumber;
const char* mainFileName;
bool exiting;
BPropertyInfo *myProps;
BString localMessage;
BString currentLib;
BList *yabbitmaps;
BList *yabcanvas;
BString lastMouseMsg;
};
#else
typedef
struct YabInterface
YabInterface;
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int mmain(int argc, char** argv, YabInterface* yab); /* ANSI C prototypes */
extern const char* yi_GetApplicationDirectory(YabInterface *yab);
extern void yi_OpenWindow(double x1,double y1,double x2,double y2, const char* id, const char* title, YabInterface* yab);
extern int yi_CloseWindow(const char* view, YabInterface* yab);
extern void yi_CreateButton(double x1,double y1,double x2,double y2, const char* id, const char* title, const char* window, YabInterface* yab);
extern int yi_CreateImage(double x,double y,const char* imagefile, const char* window, YabInterface* yab);
extern int yi_CreateImage2(double x1,double y1,double x2, double y2,const char* imagefile, const char* window, YabInterface* yab);
extern int yi_CreateSVG(double x1,double y1,double x2, double y2,const char* imagefile, const char* window, YabInterface* yab);
extern void yi_CreateMenu(const char* menuhead, const char* menuitem, const char *shortcut, const char* window, YabInterface* yab);
extern void yi_CreateTextControl(double x1, double y1, double x2, double y2, const char *id, const char* label, const char* text, const char* window, YabInterface *yab);
extern void yi_CreateCheckBox(double x, double y, const char *id, const char* label, int isActivated, const char* window, YabInterface *yab);
extern void yi_CreateRadioButton(double x, double y, const char* groupID, const char* label, int isActivated, const char* window, YabInterface *yab);
extern void yi_CreateListBox(double x1,double y1,double x2,double y2, const char* title, int scrollbar, const char* window, YabInterface *yab);
extern void yi_CreateDropBox(double x1, double y1,double x2,double y2, const char* title,const char* label, const char* window, YabInterface *yab);
extern void yi_CreateItem(const char* id,const char* item, YabInterface *yab);
extern void yi_RemoveItem(const char* title,const char* item, YabInterface *yab);
extern void yi_ClearItems(const char* title, YabInterface *yab);
extern void yi_DrawText(double x, double y, const char* text, const char* window, YabInterface* yab);
extern void yi_DrawRect(double x1, double y1, double x2, double y2, const char* window, YabInterface* yab);
extern void yi_DrawClear(const char* window, YabInterface* yab);
extern void yi_CreateAlert(const char* text, const char* button1, const char* type, YabInterface* yab);
extern void yi_CreateText(double x, double y, const char *id, const char* text, const char* window, YabInterface *yab);
extern void yi_Text2(double x1, double y1, double x2, double y2, const char *id, const char* text, const char* window, YabInterface *yab);
extern void yi_TextAlign(const char* txt, const char *option, YabInterface *yab);
extern void yi_Translate(char* text, char result[]);
extern void yi_MenuTranslate(char* text, char result[]);
extern void yi_SetLocalize();
extern void yi_StopLocalize();
extern const char* yi_LoadFilePanel(const char* mode, const char* title, const char* directory, YabInterface* yab);
extern const char* yi_SaveFilePanel(const char* mode, const char* title, const char* directory, const char*filename, YabInterface* yab);
extern void yi_SetLayout(const char* layout, const char* window, YabInterface *yab);
extern void yi_WindowSet1(const char* option, const char* value, const char* window, YabInterface *yab);
extern void yi_WindowSet2(const char* option, int r, int g, int b, const char* window, YabInterface *yab);
extern void yi_WindowSet3(const char* option, double x, double y, const char* window, YabInterface *yab);
extern void yi_WindowSet4(const char* option, const char* window, YabInterface *yab);
extern void yi_WindowClear(const char* window, YabInterface *yab);
extern void yi_TextEdit(double x1, double y1, double x2, double y2, const char* title, int scrollbar, const char* window, YabInterface *yab);
extern void yi_TextAdd(const char* title, const char* text, YabInterface *yab);
extern void yi_TextSet(const char* title, const char* option, YabInterface *yab);
extern void yi_TextClear(const char* title, YabInterface *yab);
extern const char* yi_TextGet(const char* title, YabInterface *yab);
extern const char* yi_TextGet3(const char* title, int linenum, YabInterface *yab);
extern const char* yi_TextGet6(const char* title, const char* option, YabInterface *yab);
extern double yi_TextGet4(const char* title, const char* option, int line, YabInterface *yab);
extern int yi_TextGet5(const char* title, const char* option, const char* option2, YabInterface *yab);
extern void yi_TextSet2(const char* title, const char* option, int value, YabInterface *yab);
extern void yi_TextSet3(const char* title, const char* option, const char* value, YabInterface *yab);
extern void yi_TextColor1(const char* title, const char* option, const char* command, YabInterface *yab);
extern void yi_TextColor2(const char* title, const char* option, int r, int g, int b, YabInterface *yab);
extern int yi_TextGet2(const char* title, const char* option, YabInterface *yab);
extern void yi_DrawSet1(const char* option, const char* window, YabInterface *yab);
extern void yi_DrawSet2(int fillorstroke, const char* mypattern, YabInterface *yab);
extern void yi_View(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface *yab);
extern void yi_BoxView(double x1, double y1, double x2, double y2, const char* id, const char* text, int lineType, const char* view, YabInterface *yab);
extern void yi_BoxViewSet(const char* id, const char* option, const char* value, YabInterface *yab);
extern void yi_Tab(double x1, double y1, double x2, double y2, const char* id, const char* names, const char* view, YabInterface *yab);
extern void yi_TabSet(const char* id, int num, YabInterface *yab);
extern void yi_TabAdd(const char* id, const char* name, YabInterface *yab);
extern void yi_TabDel(const char* id, int num, YabInterface *yab);
extern int yi_TabViewGet(const char* id, YabInterface *yab);
extern void yi_DrawDot(double x, double y, const char* window, YabInterface *yab);
extern void yi_DrawLine(double x1, double y1, double x2, double y2, const char* window, YabInterface *yab);
extern void yi_DrawCircle(double x, double y, double r, const char* window, YabInterface *yab);
extern void yi_DrawEllipse(double x, double y, double r1, double r2, const char* window, YabInterface *yab);
extern void yi_DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char* window, YabInterface *yab);
extern void yi_Slider1(double x1, double y1, double x2, double y2, const char* id, const char* title, int min, int max, const char* view, YabInterface *yab);
extern void yi_Slider2(double x1, double y1, double x2, double y2, const char* id, const char* title, int min, int max, const char* option, const char* view, YabInterface *yab);
extern void yi_SetSlider1(const char* id, const char* label1, const char* label2, YabInterface *yab);
extern void yi_SetSlider2(const char* id, const char* bottomtop, int count, YabInterface *yab);
extern void yi_SetSlider3(const char* id, const char* part, int r, int g, int b, YabInterface *yab);
extern void yi_SetSlider4(const char* id, int value, YabInterface *yab);
extern void yi_SetOption1(const char* id, const char* option, const char* value, YabInterface *yab);
extern void yi_SetOption2(const char* id, const char* option, int r, int g, int b, YabInterface *yab);
extern void yi_SetOption3(const char* id, const char* option, double x, double y, YabInterface *yab);
extern void yi_SetOption4(const char* id, const char* option, YabInterface *yab);
extern void yi_SetOption5(const char* id, const char* option, int value, YabInterface *yab);
extern void yi_DropZone(const char* view, YabInterface *yab);
extern void yi_ColorControl1(double x, double y, const char* id, const char* view, YabInterface* yab);
extern void yi_ColorControl2(const char* id, int r, int g, int b, YabInterface* yab);
extern void yi_TextControl2(const char* id, const char* text, YabInterface* yab);
extern void yi_TextControl3(const char* id, int mode, YabInterface* yab);
extern void yi_TextControl5(const char* id, YabInterface* yab);
extern void yi_TextControl4(const char* id, const char* option, const char* value, YabInterface* yab);
extern void yi_TreeBox1(double x1, double y1, double x2, double y2, const char* id, int scrollbarType, const char* view, YabInterface* yab);
extern void yi_TreeBox2(const char* id, const char* item, YabInterface* yab);
extern void yi_TreeBox3(const char* id, const char* head, const char* item, int isExpanded, YabInterface* yab);
extern void yi_TreeBox4(const char* id, YabInterface* yab);
extern void yi_TreeBox5(const char* id, const char* item, YabInterface* yab);
extern void yi_TreeBox7(const char* id, int pos, YabInterface* yab);
extern void yi_TreeBox8(const char* id, int pos, YabInterface* yab);
extern void yi_TreeBox9(const char* id, const char* head, const char* item, YabInterface* yab);
extern void yi_TreeBox10(const char* id, const char* head, YabInterface* yab);
extern void yi_TreeBox11(const char* id, const char* head, YabInterface* yab);
extern void yi_TreeBox12(const char* id, const char* item, int pos, YabInterface* yab);
extern const char* yi_TreeboxGet(const char* treebox, int pos, YabInterface* yab);
extern int yi_TreeboxCount(const char* treebox, YabInterface* yab);
extern void yi_ButtonImage(double x,double y,const char* id,const char* enabledon, const char* enabledoff, const char* disabled, const char* view, YabInterface *yab);
extern void yi_CheckboxImage(double x,double y,const char* id,const char* enabledon, const char* enabledoff, const char *disabledon, const char *disabledoff, int isActivated, const char* view, YabInterface *yab);
extern void yi_CheckboxSet(const char* id, int isActivated, YabInterface* yab);
extern void yi_RadioSet(const char* id, int isActivated, YabInterface* yab);
extern const char* yi_TextControlGet(const char* id, YabInterface* yab);
extern void yi_ToolTip(const char* view, const char* text, YabInterface *yab);
extern void yi_ToolTipColor(const char* color, int r, int g, int b, YabInterface *yab);
extern void yi_TreeSort(const char* view, YabInterface *yab);
extern void yi_ListSort(const char* view, YabInterface *yab);
extern void yi_FileBox(double x1, double y1, double x2, double y2, const char* id, int scrollbartype, const char* option, const char* view, YabInterface *yab);
extern void yi_FileBoxAdd2(const char* id, const char* name, int pos, double maxWidth, double minWidth, double width, const char* option, YabInterface *yab);
extern void yi_FileBoxClear(const char* view, YabInterface *yab);
extern void yi_ColumnBoxAdd(const char* id, int column, int position, int height, const char* item, YabInterface *yab);
extern void yi_ColumnBoxSelect(const char *columnbox, int position, YabInterface *yab);
extern void yi_ColumnBoxRemove(const char *columnbox, int position, YabInterface *yab);
extern void yi_ColumnBoxColor(const char *columnbox, const char* option, int r, int g, int b, YabInterface *yab);
extern int yi_Printer(const char* docname, const char *view, const char* config, YabInterface *yab);
extern void yi_PrinterConfig(const char* config, YabInterface *yab);
extern const char* yi_ColumnBoxGet(const char *columnbox, int column, int position, YabInterface *yab);
extern int yi_ColumnBoxCount(const char *columnbox, YabInterface *yab);
extern int yi_DeskbarPosition(YabInterface *yab);
extern int yi_DeskbarExpanded(YabInterface *yab);
extern int yi_DeskbarWidth(YabInterface *yab);
extern int yi_DeskbarHeight(YabInterface *yab);
extern int yi_DeskbarX(YabInterface *yab);
extern int yi_DeskbarY(YabInterface *yab);
extern int yi_DesktopWidth(YabInterface *yab);
extern int yi_DesktopHeight(YabInterface *yab);
extern int yi_WindowGet(const char* view, const char* option, YabInterface *yab);
extern int yi_ViewGet(const char* view, const char* option, YabInterface *yab); //vasper
extern void yi_ClipboardCopy(const char* text, YabInterface *yab);
extern const char* yi_ClipboardPaste(YabInterface *yab);
extern int yi_NewAlert(const char* text, const char* button1, const char* button2, const char* button3, const char* option, YabInterface *yab);
extern void yi_Calendar1(double x, double y, const char* id, const char* format, const char* date, const char* view, YabInterface *yab);
extern const char* yi_Calendar2(const char* id, YabInterface *yab);
extern void yi_Calendar3(const char* id, const char* date, YabInterface *yab);
extern void yi_MouseSet(const char* opt, YabInterface *yab);
extern void yi_Scrollbar(const char* id, int format, const char* view, YabInterface *yab);
extern void yi_ScrollbarSet1(const char* scrollview, const char* option, double position, YabInterface *yab);
extern void yi_ScrollbarSet2(const char* scrollview, const char* option, double opt1, double opt2, YabInterface *yab);
extern void yi_ScrollbarSet3(const char* scrollview, const char* option, YabInterface *yab);
extern double yi_ScrollbarGet(const char* scrollview, const char* option, YabInterface *yab);
extern const char* yi_ListboxGet(const char* listbox, int pos, YabInterface *yab);
extern int yi_ListboxCount(const char* listbox, YabInterface *yab);
extern void yi_ListboxAdd1(const char* listbox, const char* item, YabInterface *yab);
extern void yi_ListboxAdd2(const char* listbox, int pos, const char* item, YabInterface *yab);
extern void yi_ListboxSelect(const char* listbox, int pos, YabInterface *yab);
extern void yi_ListboxRemove(const char* listbox, int pos, YabInterface *yab);
extern void yi_SplitView1(double x1,double y1,double x2,double y2, const char* id, int isVertical, int style, const char* view, YabInterface *yab);
extern void yi_SplitView2(const char* splitView, const char* option, double position, YabInterface *yab);
extern void yi_SplitView3(const char* splitView, const char* option, double left, double right, YabInterface *yab);
extern double yi_SplitViewGet(const char* splitView, const char* option, YabInterface *yab);
extern void yi_StackView1(double x1,double y1,double x2,double y2, const char* id, int number, const char* view, YabInterface *yab);
extern void yi_StackView2(const char* stackView, int num, YabInterface *yab);
extern int yi_StackViewGet(const char* stackView, YabInterface *yab);
extern void yi_DrawSet3(const char* option, int transparency, YabInterface *yab);
extern void yi_TextURL1(double x, double y, const char* id, const char* text, const char* url, const char* view, YabInterface *yab);
extern void yi_TextURL2(const char* id, const char* option, int r, int g, int b, YabInterface *yab);
extern void yi_Menu2(const char* menuHead, int isRadio, const char* view, YabInterface *yab);
extern void yi_SubMenu1(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* modifiers, const char* view, YabInterface *yab);
extern void yi_SubMenu2(const char* menuHead, const char* menuItem, int isRadio, const char* view, YabInterface *yab);
extern void yi_SpinControl1(double x, double y, const char* id, const char* label, int min, int max, int step, const char* view, YabInterface *yab);
extern void yi_SpinControl2(const char* spinControl, int value, YabInterface *yab);
extern int yi_SpinControlGet(const char *spinControl, YabInterface *yab);
extern const char* yi_PopUpMenu(double x, double y, const char* menuItems, const char* view, YabInterface *yab);
extern void yi_DropBoxSelect(const char* dropbox, int position, YabInterface *yab);
extern void yi_DropBoxClear(const char* dropbox, YabInterface *yab);
extern void yi_DropBoxRemove(const char* dropbox, int position, YabInterface *yab);
extern int yi_DropBoxCount(const char* dropbox, YabInterface *yab);
extern const char* yi_DropBoxGet(const char* dropbox, int position, YabInterface *yab);
extern int yi_ColorControlGet(const char* colorcontrol, const char* option, YabInterface *yab);
extern int yi_SliderGet(const char* slider, YabInterface *yab);
extern void yi_SubMenu3(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* option, const char* view, YabInterface *yab);
extern void yi_Menu3(const char* menuHead, const char* menuItem, const char* option,const char* view, YabInterface *yab);
extern double yi_MenuHeight(YabInterface *yab);
extern double yi_TabHeight(YabInterface *yab);
extern double yi_ScrollbarWidth(YabInterface *yab);
extern double yi_DrawGet1(const char* option, const char* txt, const char* view, YabInterface* yab);
extern double yi_DrawGet2(const char* option, const char* view, YabInterface* yab);
extern const char* yi_DrawGet3(const char* option, YabInterface* yab);
extern int yi_DrawGet4(double x, double y, const char* option, const char* view, YabInterface* yab);
extern void yi_exit(int code, YabInterface *yab);
extern void yi_Launch(const char* strg, YabInterface *yab);
extern const int yi_IsMouseIn(const char* view, YabInterface* yab);
extern const char* yi_GetMouseIn(YabInterface* yab);
extern const char* yi_GetMouseMessages(const char* view, YabInterface* yab);
extern const char* yi_KeyboardMessages(const char* view, YabInterface* yab);
extern const char* yi_CheckMessages(YabInterface* yab);
extern int yi_MessageSend(const char* app, const char* msg,YabInterface* yab);
extern int yi_ThreadKill(const char* option, int id,YabInterface* yab);
extern int yi_ThreadGet(const char* option, const char* appname,YabInterface* yab);
extern void yi_Bitmap(double w, double h, const char* id,YabInterface* yab);
extern int yi_BitmapColor(double x, double y, const char* id, const char* option, YabInterface *yab);
extern void yi_BitmapDraw(double x, double y, const char* bitmap, const char* mode, const char* view,YabInterface* yab);
extern void yi_BitmapDraw2(double x1, double y1, double x2, double y2, const char* bitmap, const char* mode, const char* view,YabInterface* yab);
extern void yi_BitmapGet(double x1, double y1, double x2, double y2, const char* id, const char* bitmap,YabInterface* yab);
extern void yi_BitmapGet2(double w, const char* id, const char* path, YabInterface* yab);
extern void yi_BitmapGetIcon(const char* id, const char* option, const char* path, YabInterface* yab);
extern int yi_BitmapGetNum(const char* id, const char* option, YabInterface* yab);
extern int yi_BitmapLoad(const char* filename, const char* bitmap, YabInterface* yab);
extern void yi_BitmapDrag(const char* bitmap,YabInterface* yab);
extern void yi_BitmapRemove(const char* bitmap,YabInterface* yab);
extern void yi_Screenshot(double x1, double y1, double x2, double y2, const char* bitmap, YabInterface* yab);
extern int yi_BitmapSave(const char* id, const char* filename, const char* type, YabInterface* yab);
extern void yi_Canvas(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface *yab);
extern int yi_Sound(const char* filename, YabInterface* yab);
extern void yi_SoundStop(int id, YabInterface* yab);
extern void yi_SoundWait(int id, YabInterface* yab);
extern int yi_IsComputerOn(YabInterface* yab);
extern void yi_ShortCut(const char* view, const char* key, const char* msg, YabInterface* yab);
extern void yi_DrawSet4(const char* option, const char* color,const char* view, YabInterface* yab);
extern void yi_Treebox13(const char* id,const char* option, int pos, YabInterface* yab);
extern int yi_TreeboxGetOpt(const char* id, const char* option, int pos, YabInterface* yab);
extern int yi_ListboxGetNum(const char* id, YabInterface* yab);
extern int yi_DropboxGetNum(const char* id, YabInterface* yab);
extern int yi_TreeboxGetNum(const char* id, YabInterface* yab);
extern int yi_ColumnboxGetNum(const char* id, YabInterface* yab);
extern void yi_SetLocalize2(const char* path, YabInterface* yab);
extern void yi_SetCurrentLineNumber(int line, const char* libname, YabInterface* yab);
extern void yi_SetMainFileName(const char* name, YabInterface* yab);
extern void yi_beep();
extern void yi_StatusBar(double x1, double y1, double x2, double y2, const char* id, const char* label1, const char* label2, const char* view, YabInterface* yab);
extern void yi_StatusBarSet(const char* id, const char* label1, const char* label2, double state, YabInterface* yab);
extern void yi_StatusBarSet2(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface* yab);
extern void yi_StatusBarSet3(const char* id, int r, int g, int b, YabInterface* yab);
extern void yi_Attribute1(const char* type, const char* name, const char* value, const char* filename, YabInterface* yab);
extern void yi_AttributeClear(const char* name, const char* filename, YabInterface* yab);
extern const char* yi_AttributeGet1(const char* name, const char* filename, YabInterface* yab);
extern double yi_AttributeGet2(const char* name, const char* filename, YabInterface* yab);
extern char* refsRec; //refs received
#ifdef LOCALIZE
const char* _L(const char* text);
#endif
#ifdef __cplusplus
}
#endif
#endif /*YABINTERFACE_H*/

92
src/YabList.cpp Normal file
View File

@@ -0,0 +1,92 @@
#include <List.h>
#include <String.h>
#include <View.h>
#include "YabList.h"
#include <stdio.h>
YabList::YabList()
{
idList = new BList(1);
viewList = new BList(1);
typeList = new BList(1);
}
YabList::~YabList()
{
DelAll();
delete idList;
delete viewList;
delete typeList;
}
int YabList::ViewNum(const char* id)
{
int tmp=-1;
if(id)
{
for(int i=0; i<idList->CountItems(); i++)
if(!strcmp(id, ((BString*)(idList->ItemAt(i)))->String() ))
{
tmp = i;
break;
}
}
return tmp;
}
void YabList::AddView(const char* id, const BView* view, int type)
{
idList->AddItem((void*)new BString(id));
viewList->AddItem((void*)view);
typeList->AddItem((void*)type);
}
void YabList::DelView(const char* id)
{
int i = ViewNum(id);
if(i!=-1)
{
idList->RemoveItem(i);
viewList->RemoveItem(i);
typeList->RemoveItem(i);
}
}
void YabList::DelAll()
{
idList->MakeEmpty();
viewList->MakeEmpty();
typeList->MakeEmpty();
}
const void* YabList::GetView(const char* id)
{
int t = ViewNum(id);
if(t>=0)
return viewList->ItemAt(t);
else
return NULL;
}
const int YabList::GetType(const char* id)
{
return (int)typeList->ItemAt(ViewNum(id));
}
const int YabList::CountItems()
{
return typeList->CountItems();
}
const void* YabList::ItemAt(int i)
{
return viewList->ItemAt(i);
}
void YabList::PrintOut()
{
printf("\n");
for(int i=0; i<idList->CountItems(); i++)
printf("\t%s\n", ((BString*)(idList->ItemAt(i)))->String() );
printf("\n");
}

27
src/YabList.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef YABLIST_H
#define YABLIST_H
#include <String.h>
#include <View.h>
class YabList
{
public:
YabList();
~YabList();
void AddView(const char* id, const BView* view, int type);
void DelView(const char* id);
void DelAll();
const void* GetView(const char* id);
const int GetType(const char* id);
const int CountItems();
const void* ItemAt(int i);
void PrintOut();
private:
int ViewNum(const char* id);
BList* idList;
BList* viewList;
BList* typeList;
};
#endif

54
src/YabMain.cpp Normal file
View File

@@ -0,0 +1,54 @@
#include <File.h>
#include <String.h>
#include <stdio.h>
#include "YabInterface.h"
char t[1024];
const char* readSignature(int argc, char** argv)
{
BString tmp("application/x-vnd.yab-app");
/* Do not make changes above this comment without changing yab-IDE
to compensate for these changes.*/
for(int i=1; i<argc; i++)
{
if(argv[i][0]!='-')
{
BFile file(argv[i], B_READ_ONLY);
if(file.InitCheck()==B_OK)
{
char readData[1024];
int pos;
file.Read(readData,1024);
BString tmpString(readData);
pos = tmpString.IFindFirst("MIMETYPE");
if(pos!=B_ERROR)
{
int quote1, quote2;
quote1 = tmpString.FindFirst("\"",pos);
if(quote1!=B_ERROR)
{
quote2 = tmpString.FindFirst("\"",quote1+1);
if(quote2!=B_ERROR)
{
tmp.SetTo("");
tmpString.CopyInto(tmp,quote1+1,quote2-quote1-1);
}
}
}
}
break;
}
}
strcpy(t,tmp.String());
return (const char*)t;
}
int main(int argc, char** argv)
{
int ret;
YabInterface *yabInterface = new YabInterface(argc, argv, readSignature(argc, argv));
yabInterface->Run();
ret = yabInterface->GetErrorCode();
delete yabInterface;
return ret;
}

17
src/YabMenu.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef YABMENU_H
#define YABMENU_H
class YabMenu : public BMenu
{
public:
YabMenu(const char* name) : BMenu(name)
{
}
void MyHide()
{
Hide();
}
};
#endif

50
src/YabStackView.cpp Normal file
View File

@@ -0,0 +1,50 @@
// #include <string.h>
#include "YabStackView.h"
YabStackView::YabStackView(BRect frame, const char *name, int32 number_of_views, uint32 resizingMode, uint32 flags, const BFont *labelFont) : BView(frame, name, resizingMode, flags)
{
myViews = new BView*[number_of_views];
// init
for(int i=0; i < number_of_views; i++)
{
myViews[i] = NULL;
}
myCurrent = 0;
myBounds = Bounds();
myNumOfViews = number_of_views;
}
YabStackView::~YabStackView()
{
delete[] myViews;
}
void YabStackView::AddViews(BView** stackedViews)
{
for(int32 i = 0; i < myNumOfViews; i++)
{
myViews[i] = stackedViews[i];
if(i != myCurrent) myViews[i]->Hide();
AddChild(myViews[i]);
}
}
void YabStackView::SelectView(int32 index)
{
if(index != myCurrent && index >= 0 && index < myNumOfViews)
{
Invalidate(myBounds);
myViews[myCurrent]->Hide();
myCurrent = index;
Invalidate(myBounds);
myViews[myCurrent]->Show();
}
}
int32 YabStackView::CurrentView()
{
return myCurrent;
}

23
src/YabStackView.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef YAB_STACKVIEW_H_
#define YAB_STACKVIEW_H_
#include <View.h>
class YabStackView : public BView
{
public:
YabStackView(BRect frame, const char *name, int32 number_of_views, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS, const BFont *labelFont = be_plain_font);
~YabStackView();
void AddViews(BView** stackedViews);
int32 CurrentView();
virtual void SelectView(int32 index);
private:
BView** myViews;
int32 myCurrent;
BRect myBounds;
int32 myNumOfViews;
};
#endif

543
src/YabTabView.cpp Normal file
View File

@@ -0,0 +1,543 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: YabTabView.cpp
// Author: Marc Flerackers (mflerackers@androme.be)
// Modified by Jan Bungeroth (jan@be-logos.org)
// Description: YabTabView provides the framework for containing and
// managing groups of BView objects. Modified for *sane*
// view handling (they stay connected to the window).
//------------------------------------------------------------------------------
#include <List.h>
#include <Rect.h>
#include <String.h>
#include <View.h>
#include <stdio.h>
#include <ControlLook.h>
#include "YabControlLook.h"
#include "YabTabView.h"
#define X_OFFSET 0.0f
YabTabView::YabTabView(BRect frame, const char* name, button_width width, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags)
{
fTabList = new BList;
fTabNames = new BList;
fTabWidthSetting = width;
fSelection = 0;
fFocus = -1;
fTabOffset = 0.0f;
rgb_color color = ui_color(B_PANEL_BACKGROUND_COLOR);
SetViewColor(color);
SetLowColor(color);
font_height fh;
GetFontHeight(&fh);
fTabHeight = fh.ascent + fh.descent + fh.leading + 8.0f;
/*
if (layouted) {
BGroupLayout* layout = new(std::nothrow) BGroupLayout(B_HORIZONTAL);
if (layout) {
layout->SetInsets(3.0, 3.0 + TabHeight() - 1, 3.0, 3.0);
SetLayout(layout);
}
fContainerView = new BView("view container", B_WILL_DRAW);
fContainerView->SetLayout(new(std::nothrow) BCardLayout());
} else {
*/
BRect bounds = Bounds();
bounds.top += TabHeight();
bounds.InsetBy(3.0f, 3.0f);
fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL,
B_WILL_DRAW);
// }
fContainerView->SetViewColor(color);
fContainerView->SetLowColor(color);
AddChild(fContainerView);
FocusChanged = 1;
OldTabView = 1;
fTabOrientation = B_TAB_TOP;
}
YabTabView::~YabTabView()
{
for(int i=0; i<CountTabs(); i++)
{
delete TabAt(i);
delete (BString*)fTabNames->RemoveItem(i);
}
delete fTabList;
delete fTabNames;
}
void YabTabView::AddTab(BView *tabView, const char* label)
{
if(tabView)
{
tabView->Hide();
fContainerView->AddChild(tabView);
Invalidate();
if(CountTabs() == 0) tabView->Show();
fTabList->AddItem(tabView);
fTabNames->AddItem(new BString(label));
}
}
BView* YabTabView::RemoveTab(int32 index)
{
if(index < 0 || index >= CountTabs())
return NULL;
BView *tab = (BView*)fTabList->RemoveItem(index);
delete (BString*)fTabNames->RemoveItem(index);
if (index <= fSelection && fSelection != 0)
fSelection--;
Select(fSelection);
if (fFocus == CountTabs() - 1)
SetFocusTab(fFocus, false);
else
SetFocusTab(fFocus, true);
return tab;
}
int32 YabTabView::CountTabs() const
{
return fTabList->CountItems();
}
int32 YabTabView::Selection() const
{
return fSelection;
}
void YabTabView::Select(int32 index)
{
if (index < 0 || index >= CountTabs())
index = Selection();
BView *tab = TabAt(Selection());
if (tab)
{
Invalidate();
tab->Hide();
}
tab = TabAt(index);
if (tab)
{
if (index != 0 && !Bounds().Contains(TabFrame(index))){
if (!Bounds().Contains(TabFrame(index).LeftTop()))
fTabOffset += TabFrame(index).left - Bounds().left - 20.0f;
else
fTabOffset += TabFrame(index).right - Bounds().right + 20.0f;
}
Invalidate();
tab->Show();
fSelection = index;
FocusChanged = index+1;
}
}
void YabTabView::MakeFocus(bool focused)
{
BView::MakeFocus(focused);
SetFocusTab(Selection(), focused);
}
int32 YabTabView::FocusTab() const
{
return fFocus;
}
void YabTabView::SetFocusTab(int32 tab, bool focused)
{
if (tab >= CountTabs())
tab = 0;
if (tab < 0)
tab = CountTabs() - 1;
if (focused) {
if (tab == fFocus)
return;
if (fFocus != -1){
if (TabAt (fFocus) != NULL)
TabAt(fFocus)->MakeFocus(false);
Invalidate(TabFrame(fFocus));
}
if (TabAt(tab) != NULL){
TabAt(tab)->MakeFocus(true);
Invalidate(TabFrame(tab));
fFocus = tab;
}
} else if (fFocus != -1) {
TabAt(fFocus)->MakeFocus(false);
Invalidate(TabFrame(fFocus));
fFocus = -1;
}
}
BView* YabTabView::TabAt(int32 index)
{
if(index < 0 || index >= CountTabs())
return NULL;
return (BView*)fTabList->ItemAt(index);
}
const char* YabTabView::GetTabName(int32 index) const
{
if(index < 0 || index >= CountTabs())
return NULL;
return ((BString*)fTabNames->ItemAt(index))->String();
}
void YabTabView::KeyDown(const char *bytes, int32 numBytes)
{
if (IsHidden())
return;
switch (bytes[0]) {
case B_DOWN_ARROW:
case B_LEFT_ARROW: {
int32 focus = fFocus - 1;
if (focus < 0)
focus = CountTabs() - 1;
SetFocusTab(focus, true);
FocusChanged = 1;
break;
}
case B_UP_ARROW:
case B_RIGHT_ARROW: {
int32 focus = fFocus + 1;
if (focus >= CountTabs())
focus = 0;
SetFocusTab(focus, true);
FocusChanged = 1;
break;
}
case B_RETURN:
case B_SPACE:
Select(FocusTab());
break;
default:
BView::KeyDown(bytes, numBytes);
}
}
void YabTabView::MouseDown(BPoint point)
{
if (fTabOrientation == B_TAB_TOP && point.y > fTabHeight)
return;
if (fTabOrientation == B_TAB_BOTTOM && point.y < Bounds().bottom-fTabHeight)
return;
for (int32 i = 0; i < CountTabs(); i++) {
if (TabFrame(i).Contains(point) && i != Selection()) {
Select(i);
fFocus = -1;
return;
}
}
BView::MouseDown(point);
}
BRect YabTabView::TabFrame(int32 tab_index) const
{
float width = 100.0;
float height = fTabHeight;;
BRect tabFrame(Bounds());
switch (fTabWidthSetting) {
case B_WIDTH_FROM_LABEL:
{
float x = 0.0;
for (int32 i = 0; i < tab_index; i++){
x += StringWidth(GetTabName(i)) + 20.0;
}
if(fTabOrientation == B_TAB_TOP)
tabFrame.Set(x, 0.0, x + StringWidth(GetTabName(tab_index)) + 20.0, height);
else
tabFrame.Set(x, tabFrame.bottom - height, x + StringWidth(GetTabName(tab_index)) + 20.0, tabFrame.bottom);
return tabFrame;
}
case B_WIDTH_FROM_WIDEST:
width = 0.0;
for (int32 i = 0; i < CountTabs(); i++) {
float tabWidth = StringWidth(GetTabName(i)) + 20.0;
if (tabWidth > width)
width = tabWidth;
}
// fall through
case B_WIDTH_AS_USUAL:
default:
if(fTabOrientation == B_TAB_TOP)
tabFrame.Set(tab_index * width, 0.0, tab_index * width + width, height);
else
tabFrame.Set(tab_index * width, tabFrame.bottom - height, tab_index * width + width, tabFrame.bottom);
return tabFrame;
}
}
void YabTabView::SetTabWidth(button_width width)
{
fTabWidthSetting = width;
Invalidate();
}
button_width YabTabView::TabWidth() const
{
return fTabWidthSetting;
}
void YabTabView::SetTabHeight(float height)
{
if (fTabHeight == height)
return;
fContainerView->MoveBy(0.0f, height - fTabHeight);
fContainerView->ResizeBy(0.0f, height - fTabHeight);
fTabHeight = height;
Invalidate();
}
float YabTabView::TabHeight()
{
return fTabHeight;
}
BView *YabTabView::ContainerView()
{
return fContainerView;
}
void YabTabView::Draw(BRect updateRect)
{
// DrawBox(DrawTabs());
// SetHighColor(223,223,223);
// StrokeLine(BPoint(Bounds().left, Bounds().bottom-TabHeight()-2), BPoint(Bounds().right, Bounds().bottom-TabHeight()-2));
DrawBox(TabFrame(fSelection));
DrawTabs();
if (IsFocus() && fFocus != -1)
{
DrawFocusMark(TabFrame(fFocus), fFocus);
// Invalidate(TabFrame(fFocus));
}
}
BRect YabTabView::DrawTabs()
{
float left = 0;
for (int32 i = 0; i < CountTabs(); i++) {
BRect tabFrame = TabFrame(i);
DrawTab(tabFrame, i, i == fSelection ? B_TAB_FRONT : (i == 0) ? B_TAB_FIRST : B_TAB_ANY, i + 1 != fSelection);
left = tabFrame.right;
}
BRect frame(Bounds());
if (left < frame.right) {
frame.left = left;
if(fTabOrientation == B_TAB_TOP)
frame.bottom = fTabHeight;
else
frame.top = frame.bottom - fTabHeight;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER;
if (left == 0)
borders |= BControlLook::B_LEFT_BORDER;
if(fTabOrientation == B_TAB_TOP)
be_control_look->DrawInactiveTab(this, frame, frame, base, 0, borders);
else
fYabControlLook.DrawInactiveTabBottom(this, frame, frame, base, 0, borders);
}
if (fSelection < CountTabs())
return TabFrame(fSelection);
return BRect();
}
void YabTabView::DrawLabel(int32 current, BRect frame)
{
BString label = GetTabName(current);
if (label == NULL)
return;
float frameWidth = frame.Width();
float width = StringWidth(label.String());
font_height fh;
if (width > frameWidth) {
BFont font;
GetFont(&font);
font.TruncateString(&label, B_TRUNCATE_END, frameWidth);
width = frameWidth;
font.GetHeight(&fh);
} else {
GetFontHeight(&fh);
}
SetDrawingMode(B_OP_OVER);
SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
DrawString(label.String(),
BPoint((frame.left + frame.right - width) / 2.0,
(frame.top + frame.bottom - fh.ascent - fh.descent) / 2.0
+ fh.ascent));
}
void YabTabView::DrawTab(BRect frame, int32 current, tab_position position, bool full)
{
BView *owner = this;
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR);
// uint32 borders = BControlLook::B_RIGHT_BORDER
// | BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER;
// if (frame.left == owner->Bounds().left)
// borders |= BControlLook::B_LEFT_BORDER;
// be_control_look->DrawButtonFrame(owner, frame, frame,
// no_tint, 0, borders);
// if (position == B_TAB_FRONT)
// no_tint = tint_color(no_tint, B_DARKEN_2_TINT);
// be_control_look->DrawButtonBackground(owner, frame, frame, no_tint);
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER;
if (frame.left == owner->Bounds().left)
borders |= BControlLook::B_LEFT_BORDER;
if (frame.right == owner->Bounds().right)
borders |= BControlLook::B_RIGHT_BORDER;
if (position == B_TAB_FRONT) {
if(fTabOrientation == B_TAB_TOP)
{
frame.bottom += 1;
be_control_look->DrawActiveTab(owner, frame, frame, no_tint, 0, borders);
}
else
{
frame.top -= 1;
fYabControlLook.DrawActiveTabBottom(owner, frame, frame, no_tint, 0, borders);
}
} else {
if(fTabOrientation == B_TAB_TOP)
be_control_look->DrawInactiveTab(owner, frame, frame, no_tint, 0, borders);
else
fYabControlLook.DrawInactiveTabBottom(owner, frame, frame, no_tint, 0, borders);
}
DrawLabel(current, frame);
return;
}
void YabTabView::DrawFocusMark(BRect frame, int32 current)
{
float width = StringWidth(GetTabName(current));
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
float offset = (fSelection == current) ? 3 : 2;
StrokeLine(BPoint((frame.left + frame.right - width) / 2.0,
frame.bottom - offset),
BPoint((frame.left + frame.right + width) / 2.0,
frame.bottom - offset));
}
void YabTabView::DrawBox(BRect selTabRect)
{
BRect rect(Bounds());
if(fTabOrientation == B_TAB_TOP)
rect.top = selTabRect.bottom;
else
rect.bottom -= selTabRect.Height();
// BRegion clipping(Bounds());
// selTabRect.left += 2;
// selTabRect.right -= 2;
// clipping.Exclude(selTabRect);
// ConstrainClippingRegion(&clipping);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
be_control_look->DrawGroupFrame(this, rect, rect, base);
// ConstrainClippingRegion(NULL);
}
void YabTabView::SetOrientation(tab_orientation side)
{
if(fTabOrientation != side)
if(side == B_TAB_BOTTOM)
fContainerView->MoveTo(3.0, 3.0);
else
fContainerView->MoveTo(3.0, TabHeight());
fTabOrientation = side;
}
tab_orientation YabTabView::Orientation()
{
return fTabOrientation;
}

115
src/YabTabView.h Normal file
View File

@@ -0,0 +1,115 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: YabTabView.h
// Author: Marc Flerackers (mflerackers@androme.be)
// Jan Bungeroth (jan@be-logos.org)
// Description: YabTabView provides the framework for containing and
// managing groups of BView objects.
//------------------------------------------------------------------------------
#ifndef YABTAB_VIEW_H
#define YABTAB_VIEW_H
// Standard Includes -----------------------------------------------------------
#include <View.h>
#include "YabControlLook.h"
// Local Defines ---------------------------------------------------------------
enum tab_position {
B_TAB_FIRST = 999,
B_TAB_FRONT,
B_TAB_ANY
};
enum tab_orientation {
B_TAB_TOP = 0,
B_TAB_BOTTOM
};
// YabTabView class ------------------------------------------------------------------
class YabTabView : public BView
{
public:
YabTabView(BRect frame, const char *name,
button_width width = B_WIDTH_AS_USUAL,
uint32 resizingMode = B_FOLLOW_ALL,
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
B_WILL_DRAW | B_NAVIGABLE_JUMP |
B_FRAME_EVENTS | B_NAVIGABLE);
~YabTabView();
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void MouseDown(BPoint point);
virtual void Select(int32 tab);
int32 Selection() const;
virtual void MakeFocus(bool focused = true);
virtual void SetFocusTab(int32 tab, bool focused);
int32 FocusTab() const;
virtual void Draw(BRect updateRect);
virtual BRect DrawTabs();
virtual void DrawBox(BRect selTabRect);
virtual BRect TabFrame(int32 tab_index) const;
virtual void DrawFocusMark(BRect frame, int32 current);
virtual void DrawLabel(int32 current, BRect frame);
virtual void DrawTab(BRect frame, int32 current, tab_position position, bool full);
virtual const char* GetTabName(int32 index) const;
virtual void AddTab(BView *target, const char* tabname);
virtual BView *RemoveTab(int32 tabIndex);
virtual BView *TabAt ( int32 tab_index );
virtual void SetTabWidth(button_width width);
button_width TabWidth() const;
void SetOrientation(tab_orientation side);
tab_orientation Orientation();
virtual void SetTabHeight(float height);
float TabHeight();
BView *ContainerView();
int32 CountTabs() const;
int32 FocusChanged;
int32 OldTabView;
private:
BList *fTabList;
BList *fTabNames;
BView *fContainerView;
button_width fTabWidthSetting;
float fTabWidth;
float fTabHeight;
int32 fSelection;
int32 fInitialSelection;
int32 fFocus;
float fTabOffset;
tab_orientation fTabOrientation;
YabControlLook fYabControlLook;
};
//------------------------------------------------------------------------------
#endif

920
src/YabText.cpp Normal file
View File

@@ -0,0 +1,920 @@
#include <Input.h>
#include "YabText.h"
const uint32 YABTEXT_ANALYSE = 'YTan';
const uint32 YABTEXT_FILECHANGED = 'YTfc';
const uint32 YABTEXT_PARSE_LINE = 'YTpl';
const uint32 YABTEXT_UNDO_HIGHLIGHTING = 'YTuh';
const rgb_color Blue = {0,0,255,255};
const rgb_color Red = {255,0,0,255};
const rgb_color Grey = {185,185,185,255};
const rgb_color Green = {0,200,000,255};
const rgb_color Magenta = {200,0,255,255};
YabText::YabText(BRect frame, const char* name, BRect textRect, uint32 resizeMode, uint32 flags)
: BTextView(frame, name, textRect, resizeMode, flags)
{
isCaseSensitive = false;
hasChanged = false;
// Standard definitions
bgcolor.blue = bgcolor.red = bgcolor.green = bgcolor.alpha = 255; // background
textcolor.blue = textcolor.red = textcolor.green = 0; textcolor.alpha = 255;
generic_cmd_color = Blue;
format_cmd_color = Red;
special_cmd_color = Green;
comment_color = Grey;
punc_symbol_color = Magenta;
SetStylable(true);
// BFont myFont(be_fixed_font);
// myFontSize = 12;
// f = myFont;
// f.SetSize(myFontSize);
// SetFontAndColor(0,1,&f,B_FONT_ALL,&textcolor);
SearchOffset = 0;
SetDoesUndo(true);
hasAutoCompletion = true;
words = new BList(0);
number_of_letters = 3;
isJapanese = false;
}
YabText::~YabText()
{
BString *anItem;
for ( int32 i = 0; (anItem = (BString*)words->ItemAt(i)); i++ )
delete anItem;
delete words;
}
void YabText::AddWord(BString *word)
{
words->AddItem((void*)word);
}
void YabText::HasAutoCompletion(bool flag)
{
hasAutoCompletion = flag;
}
void YabText::SetAutoCompleteStart(int num)
{
number_of_letters = num;
}
void YabText::AddCommand(const char* command, int colorGroup)
{
switch(colorGroup)
{
case 0: generic_matches.push_back(command);
break;
case 1: green_matches.push_back(command);
break;
case 2: purple_matches.push_back(command);
break;
case 3: comment_matches.push_back(command);
break;
case 4: punctuation.push_back(command[0]);
break;
default:
break;
}
}
void YabText::SetColors(int id, int r, int g, int b)
{
switch(id)
{
case 0: generic_cmd_color.red = r;
generic_cmd_color.green = g;
generic_cmd_color.blue = b;
ParseAll(0,TextLength()-1,true);
break;
case 1: format_cmd_color.red = r;
format_cmd_color.green = g;
format_cmd_color.blue = b;
ParseAll(0,TextLength()-1,true);
break;
case 2: special_cmd_color.red = r;
special_cmd_color.green = g;
special_cmd_color.blue = b;
ParseAll(0,TextLength()-1,true);
break;
case 3: comment_color.red = r;
comment_color.green = g;
comment_color.blue = b;
ParseAll(0,TextLength()-1,true);
break;
case 4: punc_symbol_color.red = r;
punc_symbol_color.green = g;
punc_symbol_color.blue = b;
ParseAll(0,TextLength()-1,true);
break;
case 5: SetViewColor(r,g,b);
Invalidate();
break;
case 6: {
textcolor.red = r;
textcolor.green = g;
textcolor.blue = b;
BFont default_font;
GetFontAndColor(0, &default_font);
// BFont default_font(be_fixed_font);
// default_font.SetSize(myFontSize);
SetFontAndColor(0,TextLength()-1,&default_font,B_FONT_ALL,&textcolor);
ParseAll(0,TextLength()-1,true);
}
break;
default:
break;
}
}
void YabText::AttachedToWindow()
{
SetViewColor(bgcolor);
SetColorSpace(B_RGB32);
BTextView::AttachedToWindow();
}
void YabText::Select(int32 start,int32 finish)
{
BTextView::Select(start,finish);
}
int32 YabText::CountPhysicalLines()
{
return BTextView::CountLines();
}
void YabText::KeyDown(const char* bytes, int32 numBytes)
{
isAutoComplete = false;
bool shouldBeChanged = true;
bool passon = true;
switch(bytes[0])
{
case B_ENTER:
{
//update previous line on enter
BMessage msg(YABTEXT_PARSE_LINE);
int32 start,finish;
GetSelection(&start,&finish);
if(msg.AddInt32("start",start) == B_OK && msg.AddInt32("finish",finish) == B_OK)
{
BMessenger msgr(this);
msgr.SendMessage(&msg);
}
}
break;
case B_LEFT_ARROW:
{
shouldBeChanged = false;
if(modifiers() & B_CONTROL_KEY)
{
passon = false;
int32 startoffset, endoffset;
GetSelection(&startoffset, &endoffset);
bool inloop = true;
while(inloop)
{
startoffset--;
if(startoffset < 0)
{
if(modifiers() & B_SHIFT_KEY)
Select(0,endoffset);
else
Select(0,0);
ScrollToSelection();
inloop = false;
}
else
{
char tmp = ByteAt(startoffset);
if(tmp == ' ' || tmp == ':' || tmp == '/' || tmp == '\n' || tmp == '.' || tmp == '(' || tmp == ')' || tmp == '"' || tmp == '\t' || tmp == '-' || tmp == '+' || tmp == '*' || tmp == '^' || tmp == ',' || tmp == ';' || tmp == '=' || tmp == '\r')
{
if(modifiers() & B_SHIFT_KEY)
Select(startoffset,endoffset);
else
Select(startoffset,startoffset);
ScrollToSelection();
inloop = false;
}
}
}
}
}
break;
case B_RIGHT_ARROW:
{
shouldBeChanged = false;
int cur = CurrentLine();
if(modifiers() & B_CONTROL_KEY)
{
// passon = false;
int32 startoffset, endoffset;
GetSelection(&startoffset, &endoffset);
bool inloop = true;
while(inloop)
{
endoffset++;
if(endoffset > TextLength() )
{
if(modifiers() & B_SHIFT_KEY)
Select(startoffset,endoffset);
else
Select(endoffset, endoffset);
ScrollToSelection();
inloop = false;
}
else
{
char tmp = ByteAt(endoffset);
int a = LineAt(endoffset);
if(tmp == ' ' || tmp == ':' || tmp == '/' || tmp == '\n' || tmp == '.' || tmp == '(' || tmp == ')' || tmp == '"' || tmp == '\t' || tmp == '-' || tmp == '+' || tmp == '*' || tmp == '^' || tmp == ',' || tmp == ';' || tmp == '=' || tmp == '\r' || a!=cur)
{
if(a!=cur) endoffset --;
if(modifiers() & B_SHIFT_KEY)
Select(startoffset,endoffset);
else
Select(endoffset,endoffset);
ScrollToSelection();
inloop = false;
}
}
}
}
}
break;
case B_UP_ARROW:
case B_DOWN_ARROW:
case B_PAGE_UP:
case B_PAGE_DOWN:
case B_HOME:
case B_END:
case B_INSERT:
case B_FUNCTION_KEY:
case B_ESCAPE:
shouldBeChanged = false;
break;
case B_BACKSPACE:
{
int32 a,b;
GetSelection(&a, &b);
if(a == b && a == 0) shouldBeChanged = false;
}
break;
case B_DELETE:
{
int32 a,b;
GetSelection(&a, &b);
if(a == b && a == TextLength()) shouldBeChanged = false;
}
break;
}
if(shouldBeChanged && !hasChanged) hasChanged = true;
if(passon) BTextView::KeyDown(bytes,numBytes);
if(isAutoComplete)
{
Select(autoOffset, autoEnd);
}
}
int YabText::FindFirstOnLine(char c,int offset,int eol)
{
for(int i=offset;i<eol;i++)
{
if(ByteAt(i) == c)
return i;
}
return -1;
}
int32 YabText::OffsetAtIndex(int32 index) //const
{
//int text_length = TextLength();
int i;
//if(index <= 0)
// return 0;
int count = 0;
int last=0;
for(i=0;count < index;i++)
{
if(ByteAt(i) == '\n')
{
count++;
last = i+1;
}
}
return last;
}
int32 YabText::LineAt(int32 offset) //const
{
std::vector<int> sols;
std::vector<int> eols;
FillSolEol(sols,eols,0,TextLength()-1);
for(int i=0;i<sols.size();i++)
{
if(offset >= sols[i] && offset <= eols[i])
return i;
}
return -1;
}
void YabText::FillSolEol(std::vector<int>& s,std::vector<int>& e,int start,int finish)
{
int i=start;
int text_length = TextLength();
for(i=start;i>=0;i--)
{
if(ByteAt(i) == '\n')
{
break;
}
}
start=i+1;
i = finish;
for(i=finish;i<text_length;i++)
{
if(ByteAt(i) == '\n')
{
break;
}
}
finish=i;
for(i=start;i<=finish;i++)
{
if(ByteAt(i) == '\n')
{
e.push_back(i);
}
}
e.push_back(i);
s.push_back(start);
for(i=0;i<e.size()-1;i++)
{
s.push_back(e[i]+1);
}
//s.push_back(e[i]);
}
/*
void YabText::GoToLine(int32 index)
{
if(TextLength()<=0)
return;
if(index<=0) index = 0;
if(index > CountLines()) index = CountLines();
// if(index < 0 || index > CountLines() || TextLength() <= 0)
// return;
std::vector<int> eols;
std::vector<int> sols;
FillSolEol(sols,eols,0,TextLength()-1);
Select(sols[index],eols[index]);
}*/
int32 YabText::CountLines()
{
std::vector<int> eols;
std::vector<int> sols;
FillSolEol(sols,eols,0,TextLength()-1);
return eols.size();
}
void YabText::ParseAll(int start,int finish,bool IsInteractive)
{
// BFont font(be_fixed_font);
// font.SetSize(myFontSize);
BFont default_font;
GetFontAndColor(0, &default_font);
int text_length = TextLength();
if(text_length > 0)
{
std::vector<int> eols;
std::vector<int> sols;
FillSolEol(sols,eols,start,finish);
int i;
int size;
/*
if(!IsInteractive)
{
size = text_length;
std::vector<rgb_color> colorVec(size,textcolor);
for(i=0;i<sols.size();i++)
{
ParseLine(sols[i],eols[i],colorVec);
}
int offset_size=1;
std::vector<int> offsets;
offsets.push_back(0);
for(i=1;i<size;i++)
{
if(colorVec[i-1].blue != colorVec[i].blue ||
colorVec[i-1].green != colorVec[i].green ||
colorVec[i-1].red != colorVec[i].red)
{
offsets.push_back(i);
offset_size++;
}
}
text_run_array* tra = (text_run_array*)malloc(sizeof(text_run_array)*(size));
tra->count = offset_size;
for(i=0;i<offset_size;i++)
{
tra->runs[i].color=colorVec[offsets[i]];
tra->runs[i].font=font;
tra->runs[i].offset=offsets[i];
}
SetRunArray(0,text_length-1,tra);
}
else
{*/
for(i=0;i<sols.size();i++)
{
IParseLine(sols[i],eols[i]);
}
}
}
void YabText::IParseLine(int sol,int eol)
{
int size = eol-sol+1;
std::vector<rgb_color> colorVec(size,textcolor);
for(int k=0;k<size;k++)
colorVec[k] = textcolor;
int i,j;
int pos;
int text_length = TextLength();
// punctuation first
for(i=sol;i<eol;i++)
{
for(int j=0; j<punctuation.size(); j++)
if(ByteAt(i) == punctuation[j])
colorVec[i-sol] = punc_symbol_color;
}
// words second
ICheckWordLists(sol,eol,colorVec);
/*
for(i=sol;i<eol;i++)
{
BString word("");
for(j=i; j<eol; j++)
word << (char)ByteAt(j);
if(isIgnoring)
{
for(int k=i;k<j;k++)
colorVec[k-sol] = comment_color;
}
else
{
printf("%s\n", word.String());
if(Contains(comment_matches,word))
{
printf("\t%s\n", word.String());
isIgnoring = true;
for(int k=i;k<j;k++)
colorVec[k-sol] = comment_color;
}
}
}
*/
/*
if(FindFirstOnLine('#',sol,eol) == 0)
for(i=0;i<eol;i++)
colorVec[i-sol] = comment_color;
*/
//START COLOURING***********************************
// BFont default_font(be_fixed_font);
// default_font.SetSize(myFontSize);
BFont default_font;
GetFontAndColor(0, &default_font);
// INS HERE
int plLength=0;
int plStart=0;
for(i=sol;i<eol;i++)
{
if(i == sol)
{
plLength = 1;
plStart = i;
}
else if(colorVec[i-sol-1].blue != colorVec[i-sol].blue ||
colorVec[i-sol-1].green != colorVec[i-sol].green ||
colorVec[i-sol-1].red != colorVec[i-sol].red)
{
if(!isJapanese) SetFontAndColor(plStart,plStart+plLength,&default_font,B_FONT_ALL,&colorVec[i-sol-1]);
plLength = 1;
plStart = i;
}
else
{
plLength++;
}
}
if(plLength > 0)
if(!isJapanese) SetFontAndColor(plStart,plStart+plLength,&default_font,B_FONT_ALL,&colorVec[i-sol-1]);
}
void YabText::ParseLine(int sol,int eol,std::vector<rgb_color>& colorVec)//,std::vector<rgb_color>& colorVec)
{
int i;
int offset = sol;
int pos;
int text_length = TextLength();
//assert(sol >=0 && eol >=0 && sol < text_length && eol < text_length);
//Setup some defaults....
/*
TwoColorPlateau('\'',sol,eol,comment_color,colorVec);//,displaced);//-displaced
TwoColorPlateau('`',sol,eol,comment_color,colorVec);//,displaced);
TwoColorPlateau('\\',sol,eol,comment_color,colorVec);//,displaced);*/
for(i=sol;i<eol;i++)
{
if(ByteAt(i) == '[' || ByteAt(i) == ']')
{
if(i-1 >= 0 && ByteAt(i-1) == '\\')
{
colorVec[i-1] = punc_symbol_color;
}
colorVec[i] = punc_symbol_color;
}
else if(ByteAt(i) == '&' || ByteAt(i) == '{' || ByteAt(i) == '}')//
{
if(i-1 >= 0 && ByteAt(i-1) == '\\')
{
colorVec[i-1] = punc_symbol_color;
}
colorVec[i] = punc_symbol_color;
}
else if(ByteAt(i) == '$')
{
if(i-1 >= 0 && ByteAt(i-1) == '\\')
{
colorVec[i-1] = textcolor;
colorVec[i] = textcolor;
}
}
else if(ByteAt(i) == '\\' && i+1 < eol)
{
if(ByteAt(i+1) == '#')
{
colorVec[i] = punc_symbol_color;
colorVec[i+1] = punc_symbol_color;
}else if(ByteAt(i+1) == '\'' || ByteAt(i+1) == '`')
{
colorVec[i] = textcolor;
colorVec[i+1] = textcolor;
}
}
/*if(toupper((char)ByteAt(i)) == 'B')
{
if(i+3 < eol && toupper((char)ByteAt(i+1)) == 'E' &&
toupper((char)ByteAt(i+2)) == 'O' && toupper((char)ByteAt(i+3)) == 'S')
{
colorVec[i] = Blue;
colorVec[i+1] = Red;
}
else if(i+4 < eol && toupper((char)ByteAt(i+1)) == 'E' &&
toupper((char)ByteAt(i+2)) == 'T' && toupper((char)ByteAt(i+3)) == 'E'
&& toupper((char)ByteAt(i+3)) == 'X')
{
colorVec[i] = Blue;
colorVec[i+1] = Red;
}
}*/
}
offset = sol;
while((pos = FindFirstOnLine('%',offset,eol))>= 0 && offset < eol)
{
if(pos - 1 >= 0 && ByteAt(pos-1) == '\\')
{
colorVec[pos-1] = punc_symbol_color;
colorVec[pos] = punc_symbol_color;
}
else
{
for(i=pos;i<eol;i++)
colorVec[i] = comment_color;
break;
}
offset= pos+1;
}
}
void YabText::ICheckWordLists(int sol,int eol,std::vector<rgb_color>& colorVec)
{
int i;
for(i=sol;i<eol;i++)
{
BString match="";
int j=i;
for(j=i;j < eol;j++)
{
if(isalpha(ByteAt(j)) || (char)ByteAt(j) == ':' || (char)ByteAt(j) == '$' || ((char)ByteAt(j)>='0' && (char)ByteAt(j)<='9'))
// if(ByteAt(j)>32)
{
match << (char)ByteAt(j);
}
else
break;
}
if((match.Length() > 0) && (i==sol || !isalpha(ByteAt(i-1))))
{
if(Contains(green_matches,match))
{
for(int k=i;k<j;k++)
colorVec[k-sol] = format_cmd_color;
}
else if(Contains(purple_matches,match))
{
for(int k=i;k<j;k++)
colorVec[k-sol] = special_cmd_color;
}
else if(Contains(generic_matches,match))
{
for(int k=i;k<j;k++)
colorVec[k-sol] = generic_cmd_color;
}
else if(Contains(comment_matches,match))
{
for(int k=i;k<j;k++)
colorVec[k-sol] = comment_color;
}
}
}
}
void YabText::InsertText(const char* text,int32 length,int32 offset,const text_run_array* runner)
{
hasChanged = true;
BString replace = text;
if(length == 1 && hasAutoCompletion)
{
BString itext(""); //Text();
// BString lastWord = "";
int32 myOffset = offset - 1;
while(myOffset>=0)
{
if(ByteAt(myOffset) == ' ' || ByteAt(myOffset) == '\n' || ByteAt(myOffset) == '\t')
break;
myOffset --;
}
if(offset-myOffset>number_of_letters)
{
for(int i=myOffset+1; i<offset; i++)
itext << (char)ByteAt(i);
itext << text;
BString *anItem;
for ( int32 i = 0; (anItem = (BString*)words->ItemAt(i)); i++ )
{
if(anItem->Compare(itext, offset-myOffset+length-1) == 0)
{
autoOffset = offset + 1;
isAutoComplete = true;
BString sleepy(anItem->String());
sleepy.CopyInto(replace, offset-myOffset-1, anItem->Length());
length = replace.Length();
autoEnd = anItem->Length()+myOffset+1;
break;
}
}
}
}
BTextView::InsertText(replace.String(),length,offset,NULL);
if(text[0] != B_ENTER)
{
BMessage msg(YABTEXT_ANALYSE);
if(msg.AddInt32("offset",offset)==B_OK && msg.AddInt32("length",length)==B_OK)
//&& msg.AddString("text",text) == B_OK)
{
BMessenger msgr(this);
msgr.SendMessage(&msg);
}
}
}
void YabText::DeleteText(int32 start, int32 finish)
{
BMessage msg(YABTEXT_ANALYSE);
if(msg.AddInt32("start",start)==B_OK && msg.AddInt32("finish",finish)==B_OK)
{
BMessenger msgr(this);
msgr.SendMessage(&msg);
}
BTextView::DeleteText(start,finish);
}
void YabText::SetText(const char* text,int32 length,const text_run_array* runs )
{
hasChanged = true;
BTextView::SetText(text,length,runs);
// ParseAll(0,length-1,false);
}
void YabText::UpdateColors()
{
SetFontAndColor(0,TextLength(),&f,B_FONT_ALL,&textcolor);
ParseAll(0,TextLength()-1,true);
//const char* text = Text();
//Delete(0,TextLength()-1);
//SetText(text,strlen(text));//,TextLength()-1);
}
void YabText::UpdateFontSize()
{
f.SetSize(myFontSize);
SetFontAndColor(0,TextLength(),&f,B_FONT_ALL,&textcolor);
ParseAll(0,TextLength()-1,true);
}
void YabText::SetText(BFile* file,int32 offset,int32 length,const text_run_array* runs )
{
hasChanged = true;
BTextView::SetText(file,offset,length,runs);
// ParseAll(offset,length-1,false);
}
bool YabText::Contains(std::vector<BString>& v,BString s)
{
for(int i=0;i<v.size();i++)
{
if(isCaseSensitive)
{
if(v[i].Compare(s) == 0)
return true;
}
else
{
if(v[i].ICompare(s) == 0)
return true;
}
}
return false;
}
/*
bool YabText::CanEndLine(int32 offset)
{
if(ByteAt(offset) == B_ENTER || )
return true;
else
return false;
}*/
void YabText::MessageReceived(BMessage* msg)
{
switch(msg->what)
{
case B_INPUT_METHOD_EVENT:
{
int32 be_op;
if(msg->FindInt32("be:opcode", &be_op) == B_OK)
{
if(be_op == B_INPUT_METHOD_STARTED) isJapanese = true;
if(be_op == B_INPUT_METHOD_STOPPED) isJapanese = false;
}
BTextView::MessageReceived(msg);
}
break;
case YABTEXT_UNDO_HIGHLIGHTING:
{
int32 start,finish;
if(msg->FindInt32("start",&start)==B_OK && msg->FindInt32("finish",&finish)==B_OK)
{
Select(start,finish);
}
}break;
case YABTEXT_PARSE_LINE:
{
int32 start,finish;
if(msg->FindInt32("start",&start)==B_OK && msg->FindInt32("finish",&finish)==B_OK)
{
int32 sel_start,sel_finish;
GetSelection(&sel_start,&sel_finish);
ParseAll(min(sel_start,start),max(sel_finish,finish),true);
}
}break;
case YABTEXT_ANALYSE:
{
int32 start,finish;
if(msg->FindInt32("start",&start)==B_OK && msg->FindInt32("finish",&finish)==B_OK)
{
ParseAll(start,finish,true);
}
int32 offset,length;
if(msg->FindInt32("offset",&offset)==B_OK
&& msg->FindInt32("length",&length)==B_OK)
{
GetSelection(&start,&finish);
ParseAll(offset,finish,true);
}
}break;
/*
case B_CUT:
case B_COPY:
case B_PASTE:
{
BMessage msg(UPDATE_CLIPBOARD_MENU_STATUS);
BMessenger msgr(Window());
msgr.SendMessage(&msg);
}*/
default:
BTextView::MessageReceived(msg);
}
}
/*
void YabText::LoadFile (entry_ref *ref)
{
if (ref == NULL) {
return;
}
BFile file(ref, B_READ_ONLY);
if (file.InitCheck() != B_OK) {
return;
}
off_t length;
file.GetSize(&length);
if (length == 0) {
return;
}
SetText (&file, 0, length);
}*/
bool YabText::HasChanged()
{
return hasChanged;
}
void YabText::SetChanged(bool changed)
{
hasChanged = changed;
}
bool YabText::IsCaseSensitive()
{
return isCaseSensitive;
}
void YabText::SetCaseSensitive(bool caseSensitive)
{
isCaseSensitive = caseSensitive;
}

90
src/YabText.h Normal file
View File

@@ -0,0 +1,90 @@
#ifndef YABTEXT_H
#define YABTEXT_H
#include <TextView.h>
#include <Font.h>
#include <String.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <Window.h>
#include <Message.h>
#include <Messenger.h>
class YabText : public BTextView
{
public:
YabText(BRect frame, const char* name, BRect textRect, uint32 resizeMode, uint32 flags);
~YabText();
void AddCommand(const char* command, int colorGroup);
virtual void AttachedToWindow();
virtual void Select(int32 start,int32 finish);
void SetColors(int, int, int, int);
int32 CountPhysicalLines(); //?
virtual void KeyDown(const char* bytes, int32 numBytes);
int FindFirstOnLine(char c,int offset,int eol);
int32 OffsetAtIndex(int32 index);// const;
int32 LineAt(int32 offset);// const;
void FillSolEol(std::vector<int>& s,std::vector<int>& e,int start,int finish);
// void GoToLine(int32 index);
int32 CountLines();
void ParseAll(int start,int finish,bool IsInteractive);
void IParseLine(int sol,int eol); // TODO!
void ParseLine(int sol,int eol,std::vector<rgb_color>& colorVec); // TODO!
void ICheckWordLists(int sol,int eol,std::vector<rgb_color>& colorVec);
void SetText(const char* text,int32 length,const text_run_array* runs = NULL);
void UpdateColors();
void UpdateFontSize();
void SetText(BFile* file,int32 offset,int32 length,const text_run_array* runs = NULL);
bool Contains(std::vector<BString>& v,BString s);
// virtual bool CanEndLine(int32 offset);
// void LoadFile(entry_ref *ref);
virtual void MessageReceived(BMessage* msg);
bool HasChanged();
void SetChanged(bool changed);
bool IsCaseSensitive();
void SetCaseSensitive(bool caseSensitive);
void SetNormalFocus();
void SetAttachedFocus();
void AddWord(BString *word);
void SetAutoCompleteStart(int num);
void HasAutoCompletion(bool flag);
int SearchOffset;
private:
bool isCaseSensitive, hasChanged, isJapanese;
int myFontSize;
rgb_color bgcolor;
rgb_color textcolor, punc_symbol_color, comment_color, ignore_color;
rgb_color format_cmd_color, special_cmd_color, generic_cmd_color;
BFont f;
std::vector <BString> green_matches;
std::vector <BString> purple_matches;
std::vector <BString> generic_matches;
std::vector <BString> comment_matches;
std::vector <char> punctuation;
BList *words;
bool hasAutoCompletion, isAutoComplete;
int32 autoOffset, autoEnd;
int number_of_letters;
bool min(int32 a, int32 b)
{
return (a<=b?a:b);
};
bool max(int32 a, int32 b)
{
return (a>=b?a:b);
};
protected:
virtual void InsertText(const char* text,int32 length,int32 offset,const text_run_array* runner);
virtual void DeleteText(int32 start, int32 finish);
};
#endif

138
src/YabToolTip.cpp Normal file
View File

@@ -0,0 +1,138 @@
/*
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
// #include <MessageRunner.h>
#include <StringView.h>
#include <Window.h>
#include "ToolTip.h"
class MouseToolTip : public BToolTip {
public:
MouseToolTip()
{
fView = new MouseView();
SetSticky(true);
}
virtual ~MouseToolTip()
{
delete fView;
}
virtual BView* View() const
{
return fView;
}
private:
BStringView* fView;
};
class ImmediateView : public BStringView {
public:
ImmediateView(const char* name, const char* label)
:
BStringView(name, label)
{
SetToolTip("Easy but immediate!");
ToolTip()->SetSticky(true);
}
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
if (transit == B_ENTERED_VIEW)
ShowToolTip(ToolTip());
}
};
class Window : public BWindow {
public:
Window();
virtual bool QuitRequested();
};
class Application : public BApplication {
public:
Application();
virtual void ReadyToRun();
};
// #pragma mark -
Window::Window()
:
BWindow(BRect(100, 100, 520, 430), "ToolTip-Test",
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{
BView* simple = new BStringView("1", "Simple Tool Tip");
simple->SetToolTip("This is a really\nsimple tool tip!");
BView* custom = new BStringView("2", "Custom Tool Tip");
custom->SetToolTip(new CustomToolTip());
BView* changing = new BStringView("3", "Changing Tool Tip");
changing->SetToolTip(new ChangingToolTip());
BView* mouse = new BStringView("3", "Mouse Tool Tip (sticky)");
mouse->SetToolTip(new MouseToolTip());
BView* immediate = new ImmediateView("3", "Immediate Tool Tip (sticky)");
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(simple)
.Add(custom)
.Add(changing)
.Add(mouse)
.Add(immediate);
}
bool
Window::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
// #pragma mark -
Application::Application()
: BApplication("application/x-vnd.haiku-tooltiptest")
{
}
void
Application::ReadyToRun()
{
BWindow *window = new Window();
window->Show();
}
// #pragma mark -
int
main(int argc, char **argv)
{
Application app;
app.Run();
return 0;
}

335
src/YabView.cpp Normal file
View File

@@ -0,0 +1,335 @@
#include <Bitmap.h>
#include <Path.h>
#include <Picture.h>
#include <Region.h>
#include <View.h>
#include "YabWindow.h"
#include "YabView.h"
YabView::YabView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags)
{
/*
SetViewColor(216,216,216,255);
SetLowColor(216,216,216,255);
SetHighColor(0,0,0,255);
*/
rgb_color b1 = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color b2 = {0,0,0,255};
SetViewColor(b1);
SetLowColor(b1);
SetHighColor(b2);
drawList = new BList(1);
YabDrawing *t = new YabDrawing();
t->command = 6;
t->r = 0; t->g = 0;
t->b = 0; t->alpha = 255;
drawList->AddItem(t);
YabDrawing *t2 = new YabDrawing();
t2->command = 7;
t2->r = b1.red; t2->g = b1.green;
t2->b = b1.blue; t2->alpha = 255;
drawList->AddItem(t2);
mouseMovedInfo = 1;
mouseStateInfo = -1;
prevMouseStateInfo = 0;
mouseX = 0;
mouseY = 0;
mouseLButton = 0;
mouseMButton = 0;
mouseRButton = 0;
dropZone = false;
pressedKeys.SetTo("");
SetDrawingMode(B_OP_COPY);
}
YabView::~YabView()
{
while(drawList->CountItems()>0)
{
YabDrawing *t = (YabDrawing*)drawList->LastItem();
drawList->RemoveItem(t);
if(t->command == 0) delete [] t->chardata;
delete t;
}
delete drawList;
}
void YabView::MessageReceived(BMessage *msg)
{
entry_ref ref;
switch (msg->what)
{
case B_SIMPLE_DATA:
{
if(dropZone)
{
BString tmp("");
int32 count;
uint32 type;
const char* name;
int i =0;
while(msg->FindRef("refs", i, &ref) == B_OK)
{
BEntry dropEntry(&ref);
BPath tmpDirectory;
dropEntry.GetPath(&tmpDirectory);
tmp << Name();
tmp << ":_Dropped";
tmp << ":" << tmpDirectory.Path();
tmp << "|";
i++;
}
YabWindow *yabWin = (YabWindow*)Window();
yabWin->dropMsg.SetTo(tmp);
}
else
BView::MessageReceived(msg);
}
break;
default:
BView::MessageReceived(msg);
break;
}
}
void YabView::Draw(BRect updateRect)
{
SetFont(be_plain_font);
updateRect = Bounds();
for(int i=0; i<drawList->CountItems(); i++)
{
YabDrawing *e = (YabDrawing*)drawList->ItemAt(i);
switch(e->command)
{
case 0: DrawString(e->chardata, BPoint(e->x1, e->y1));
break;
case 1: StrokeLine(BPoint(e->x1,e->y1),BPoint(e->x2,e->y2), e->p);
break;
case 2: StrokeEllipse(BPoint(e->x1,e->y1), e->x2, e->y2, e->p);
break;
case 3: FillEllipse(BPoint(e->x1,e->y1), e->x2, e->y2, e->p);
break;
case 4: StrokeRect(BRect(e->x1,e->y1,e->x2,e->y2), e->p);
break;
case 5: FillRect(BRect(e->x1,e->y1,e->x2,e->y2), e->p);
break;
case 6: {
if(e->alpha == 255)
SetDrawingMode(B_OP_COPY);
else
SetDrawingMode(B_OP_ALPHA);
SetHighColor(e->r,e->g,e->b,e->alpha);
}
break;
case 7: {
if(e->alpha == 255)
SetDrawingMode(B_OP_COPY);
else
SetDrawingMode(B_OP_ALPHA);
SetLowColor(e->r,e->g,e->b,e->alpha);
}
break;
case 8: {
BPoint p[4];
p[0].Set(e->x1,e->y1);
p[1].Set(e->x2,e->y2);
p[2].Set(e->x3,e->y3);
p[3].Set(e->x4,e->y4);
SetPenSize(1.01);
StrokeBezier(p, e->p);
SetPenSize(1.0);
}
break;
case 9: {
BPoint p[4];
p[0].Set(e->x1,e->y1);
p[1].Set(e->x2,e->y2);
p[2].Set(e->x3,e->y3);
p[3].Set(e->x4,e->y4);
SetPenSize(2.0);
FillBezier(p, e->p);
SetPenSize(1.0);
}
break;
case 10: {
drawing_mode mode = DrawingMode();
if(IsPrinting())
SetDrawingMode(B_OP_COPY);
else
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(e->bitmap, BPoint(e->x1, e->y1));
SetDrawingMode(mode);
}
break;
case 11: {
drawing_mode mode = DrawingMode();
if(IsPrinting())
SetDrawingMode(B_OP_COPY);
else
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(e->bitmap, BRect(e->x1, e->y1, e->x2, e->y2));
SetDrawingMode(mode);
}
break;
case 12: {
// SetFont(&e->font, B_FONT_FAMILY_AND_STYLE);
// SetFont(&e->font, B_FONT_SIZE);
SetFont(&e->font, B_FONT_ALL);
}
break;
}
}
}
void YabView::MouseDown(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 4;
BView::MouseDown(point);
}
void YabView::MouseUp(BPoint point)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, false);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
mouseStateInfo = 5;
BView::MouseUp(point);
}
void YabView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
BPoint ptCursor;
uint32 uButtons = 0;
GetMouse(&ptCursor, &uButtons, true);
mouseX = (int)ptCursor.x;
mouseY = (int)ptCursor.y;
if(uButtons & B_PRIMARY_MOUSE_BUTTON) mouseLButton = 1; else mouseLButton = 0;
if(uButtons & B_SECONDARY_MOUSE_BUTTON) mouseRButton = 1; else mouseRButton = 0;
if(uButtons & B_TERTIARY_MOUSE_BUTTON) mouseMButton = 1; else mouseMButton = 0;
switch(transit)
{
case B_INSIDE_VIEW:
if(prevMouseStateInfo==1)
mouseStateInfo = 0;
else
{
mouseStateInfo = 1;
prevMouseStateInfo = 1;
}
mouseMovedInfo = 0;
break;
case B_ENTERED_VIEW:
mouseStateInfo = 1;
mouseMovedInfo = 0;
break;
case B_OUTSIDE_VIEW:
mouseStateInfo = 2;
mouseMovedInfo = 1;
break;
case B_EXITED_VIEW:
mouseStateInfo = 3;
mouseMovedInfo = 1;
prevMouseStateInfo = 0;
break;
}
BView::MouseMoved(point, transit, message);
}
void YabView::KeyDown(const char *bytes, int32 numBytes)
{
BMessage *msg = Window()->CurrentMessage();
if(msg)
{
pressedKeys.SetTo("");
int32 key, modifiers;
msg->FindInt32("key", &key);
msg->FindInt32("modifiers", &modifiers);
if(modifiers&B_CONTROL_KEY) pressedKeys << "ctrl-";
if(modifiers&B_COMMAND_KEY) pressedKeys << "command-";
if(modifiers&B_OPTION_KEY) pressedKeys << "option-";
if(modifiers&B_SHIFT_KEY) pressedKeys << "shift-";
switch(bytes[0])
{
case B_BACKSPACE: pressedKeys << "backspace"; break;
case B_ENTER: pressedKeys << "enter"; break;
case B_TAB: pressedKeys << "tab"; break;
case B_ESCAPE: pressedKeys << "esc"; break;
case B_LEFT_ARROW: pressedKeys << "left"; break;
case B_RIGHT_ARROW: pressedKeys << "right"; break;
case B_UP_ARROW: pressedKeys << "up"; break;
case B_DOWN_ARROW: pressedKeys << "down"; break;
case B_INSERT: pressedKeys << "insert"; break;
case B_DELETE: pressedKeys << "del"; break;
case B_HOME: pressedKeys << "home"; break;
case B_END: pressedKeys << "end"; break;
case B_PAGE_UP: pressedKeys << "pageup"; break;
case B_PAGE_DOWN: pressedKeys << "pagedown"; break;
case B_FUNCTION_KEY:
{
switch(key)
{
case B_F1_KEY: pressedKeys << "f1"; break;
case B_F2_KEY: pressedKeys << "f2"; break;
case B_F3_KEY: pressedKeys << "f3"; break;
case B_F4_KEY: pressedKeys << "f4"; break;
case B_F5_KEY: pressedKeys << "f5"; break;
case B_F6_KEY: pressedKeys << "f6"; break;
case B_F7_KEY: pressedKeys << "f7"; break;
case B_F8_KEY: pressedKeys << "f8"; break;
case B_F9_KEY: pressedKeys << "f9"; break;
case B_F10_KEY: pressedKeys << "f10"; break;
case B_F11_KEY: pressedKeys << "f11"; break;
case B_F12_KEY: pressedKeys << "f12"; break;
case B_PRINT_KEY: pressedKeys << "print"; break;
case B_SCROLL_KEY: pressedKeys << "scroll"; break;
case B_PAUSE_KEY: pressedKeys << "pause"; break;
default:
pressedKeys.SetTo(bytes);
break;
}
}
break;
default:
pressedKeys.SetTo(bytes);
break;
}
}
else
pressedKeys.SetTo(bytes);
if(bytes[0]!=B_TAB) BView::KeyDown(bytes,numBytes);
}
void YabView::KeyUp(const char *bytes, int32 numBytes)
{
pressedKeys.SetTo("");
BView::KeyUp(bytes,numBytes);
}

44
src/YabView.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef YABVIEW_H
#define YABVIEW_H
#include <String.h>
#include <View.h>
struct YabDrawing
{
int command;
double x1,y1,x2,y2,x3,y3,x4,y4;
int r,g,b,alpha;
const char* chardata;
pattern p;
BBitmap *bitmap;
BFont font;
};
class YabView : public BView
{
public:
YabView(BRect frame, const char *name, uint32 resizingMode, uint32 flags);
~YabView();
virtual void MessageReceived(BMessage *msg);
virtual void Draw(BRect updateRect);
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
virtual void MouseUp(BPoint point);
virtual void MouseDown(BPoint point);
virtual void KeyUp(const char *bytes, int32 numBytes);
virtual void KeyDown(const char *bytes, int32 numBytes);
BList *drawList;
int mouseMovedInfo;
int mouseStateInfo;
int mouseX;
int mouseY;
uint mouseLButton;
uint mouseMButton;
uint mouseRButton;
bool dropZone;
BString pressedKeys;
private:
int prevMouseStateInfo;
};
#endif

361
src/YabWindow.cpp Normal file
View File

@@ -0,0 +1,361 @@
#include "global.h"
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
#include <CheckBox.h>
#include <ColorControl.h>
#include <ListView.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <OutlineListView.h>
#include <RadioButton.h>
#include <Slider.h>
#include <String.h>
#include <TextControl.h>
#include <Window.h>
#include <stdio.h>
#include "YabWindow.h"
#include "column/ColumnListView.h"
const uint32 YABBUTTON = 'YBbu';
const uint32 YABMENU = 'YBme';
const uint32 YABSUBMENU = 'YBsu';
const uint32 YABTEXTCONTROL = 'YBtc';
const uint32 YABCHECKBOX = 'YBcb';
const uint32 YABRADIOBUTTON = 'YBrb';
const uint32 YABLISTBOXSELECT = 'YBls';
const uint32 YABLISTBOXINVOKE = 'YBli';
const uint32 YABDROPBOX = 'YBdb';
const uint32 YABSLIDER = 'YBsl';
const uint32 YABCOLORCONTROL = 'YBco';
const uint32 YABTREEBOXSELECT = 'YBts';
const uint32 YABTREEBOXINVOKE = 'YBti';
const uint32 YABFILEBOXSELECT = 'YBfs';
const uint32 YABFILEBOXINVOKE = 'YBfi';
const uint32 YABSPINCONTROL = 'YBsp';
const uint32 YABSHORTCUT = 'YBsh';
YabWindow::YabWindow(BRect frame, const char* title, const char* id, window_look winlook, window_feel winfeel, uint32 flags)
: BWindow (frame, title, winlook, winfeel, flags)
{
messageString.SetTo("");
idString.SetTo(id);
showing = 1;
dropMsg.SetTo("");
WActivated=-1;
WFrameMoved=-1;
WFrameResized=-1;
}
YabWindow::~YabWindow()
{
}
void YabWindow::WindowActivated(bool state)
{
if (state)
WActivated=1;
else
WActivated=0;
}
void YabWindow::FrameMoved(BPoint new_position)
{
WFrameMoved=1;
Wpx=(int)new_position.x;
Wpy=(int)new_position.y;
}
void YabWindow::FrameResized(float new_width, float new_height)
{
WFrameResized=1;
Wph=(int)new_height;
Wpw=(int)new_width;
}
void YabWindow::MessageReceived(BMessage *message)
{
// if(message) message->PrintToStream();
switch(message->what)
{
case YABBUTTON:
{
BString tmpMessage("");
BButton *myButtonPressed;
message->FindPointer("source",(void **) &myButtonPressed);
tmpMessage += myButtonPressed->Name();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABMENU:
{
BString tmpMessage("");
BMenuItem *mySelectedMenu;
message->FindPointer("source",(void **) &mySelectedMenu);
BMenu *myMenu = mySelectedMenu->Menu();
tmpMessage += ((BMenuBar*)myMenu->Supermenu())->Parent()->Name();
tmpMessage += ":";
tmpMessage += myMenu->Name();
tmpMessage += ":";
tmpMessage += mySelectedMenu->Label();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABSUBMENU:
{
BString tmpMessage("");
BMenuItem *mySelectedMenu;
message->FindPointer("source",(void **) &mySelectedMenu);
BMenu *myMenu = mySelectedMenu->Menu();
tmpMessage += ((BMenuBar*)myMenu->Supermenu()->Supermenu())->Parent()->Name();
tmpMessage += ":";
tmpMessage += myMenu->Supermenu()->Name();
tmpMessage += ":";
tmpMessage += myMenu->Name();
tmpMessage += ":";
tmpMessage += mySelectedMenu->Label();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABTEXTCONTROL:
{
BString tmpMessage("");
BTextControl *myTextControl;
message->FindPointer("source",(void **) &myTextControl);
tmpMessage += myTextControl->Name();
tmpMessage += ":";
tmpMessage += myTextControl->Text();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABCHECKBOX:
{
BString tmpMessage("");
BCheckBox *myCheckBox;
message->FindPointer("source",(void **) &myCheckBox);
tmpMessage += myCheckBox->Name();
tmpMessage += ":";
if(myCheckBox->Value()==B_CONTROL_ON)
tmpMessage += "ON|";
else
tmpMessage += "OFF|";
messageString += tmpMessage;
}
break;
case YABRADIOBUTTON:
{
BString tmpMessage("");
BRadioButton *myRadioButton;
message->FindPointer("source",(void **) &myRadioButton);
tmpMessage += myRadioButton->Name();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABLISTBOXINVOKE:
{
BListView *myList;
message->FindPointer("source",(void **) &myList);
int i = myList->CurrentSelection();
if(i>=0)
{
BString tmpMessage("");
tmpMessage += myList->Name();
tmpMessage += ":_Invoke:";
// tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text();
tmpMessage << i+1;
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABLISTBOXSELECT:
{
BListView *myList;
message->FindPointer("source",(void **) &myList);
int i = myList->CurrentSelection();
if(i>=0)
{
BString tmpMessage("");
tmpMessage += myList->Name();
tmpMessage += ":_Select:";
// tmpMessage += ((BStringItem*)(myList->ItemAt(i)))->Text();
tmpMessage << i+1;
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABDROPBOX:
{
BString tmpMessage("");
BMenuItem *myMenuItem;
message->FindPointer("source",(void **) &myMenuItem);
tmpMessage += (myMenuItem->Menu())->Supermenu()->Parent()->Name();
tmpMessage += ":";
tmpMessage += myMenuItem->Label();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABSLIDER:
{
BString tmpMessage("");
BSlider *mySlider;
message->FindPointer("source",(void **) &mySlider);
tmpMessage += mySlider->Name();
tmpMessage += ":";
tmpMessage << mySlider->Value();
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABCOLORCONTROL:
{
rgb_color col;
BString tmpMessage("");
BColorControl *myCControl;
message->FindPointer("source",(void **) &myCControl);
tmpMessage += myCControl->Name();
tmpMessage += ":";
col = myCControl->ValueAsColor();
tmpMessage << col.red << ":" << col.green << ":" << col.blue;
tmpMessage += "|";
messageString += tmpMessage;
}
break;
case YABTREEBOXINVOKE:
{
BOutlineListView *myList;
message->FindPointer("source",(void **) &myList);
int i = myList->FullListCurrentSelection();
if(i>=0)
{
BString tmpMessage("");
const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text();
tmpMessage += myList->Name();
tmpMessage += ":_Invoke:";
tmpMessage << i+1;
/*
int n = tmpMessage.Length();
BListItem *superitem = myList->Superitem(myList->FullListItemAt(i));
while(superitem)
{
BString t("");
t << ((BStringItem*)superitem)->Text() << ":";
tmpMessage.Insert(t,n);
superitem = myList->Superitem(superitem);
}
tmpMessage += txt;*/
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABTREEBOXSELECT:
{
BOutlineListView *myList;
message->FindPointer("source",(void **) &myList);
int i = myList->FullListCurrentSelection();
if(i>=0)
{
BString tmpMessage("");
const char* txt = ((BStringItem*)(myList->FullListItemAt(i)))->Text();
tmpMessage += myList->Name();
tmpMessage += ":_Select:";
tmpMessage << i+1;
/*
int n = tmpMessage.Length();
BListItem *superitem = myList->Superitem(myList->FullListItemAt(i));
while(superitem)
{
BString t("");
t << ((BStringItem*)superitem)->Text() << ":";
tmpMessage.Insert(t,n);
superitem = myList->Superitem(superitem);
}
tmpMessage += txt;*/
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABFILEBOXSELECT:
{
BColumnListView *myList;
message->FindPointer("source",(void **) &myList);
BRow *myRow = NULL;
if(myList) myRow = myList->CurrentSelection();
if(myRow)
{
// if(!myList->IsFocus()) myList->MakeFocus();
BString tmpMessage("");
tmpMessage += myList->Name();
tmpMessage += ":_Select:";
tmpMessage << myList->IndexOf(myRow)+1;
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABFILEBOXINVOKE:
{
BColumnListView *myList;
message->FindPointer("source",(void **) &myList);
BRow *myRow = NULL;
if(myList) myRow = myList->CurrentSelection();
if(myRow)
{
// if(!myList->IsFocus()) myList->MakeFocus();
BString tmpMessage("");
tmpMessage += myList->Name();
tmpMessage += ":_Invoke:";
tmpMessage << myList->IndexOf(myRow)+1;
tmpMessage += "|";
messageString += tmpMessage;
}
}
break;
case YABSHORTCUT:
{
const char* myMsg;
if(message->FindString("shortcut", &myMsg) == B_OK)
{
messageString += myMsg;
messageString += "|";
}
}
break;
default:
BWindow::MessageReceived(message);
break;
}
}
const BString YabWindow::getMessages()
{
BString tmp(messageString);
tmp += dropMsg;
messageString.SetTo("");
dropMsg.SetTo("");
return (const BString)tmp;
}
bool YabWindow::QuitRequested()
{
messageString += idString;
messageString += ":_QuitRequested|";
return false;
}
bool YabWindow::IsPaper(uint8* a)
{
if(a[32] != 0) return true;
return false;
}

38
src/YabWindow.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef YABWINDOW_H
#define YABWINDOW_H
#include <FilePanel.h>
#include <List.h>
#include <Menu.h>
#include <PopUpMenu.h>
#include <String.h>
#include <Window.h>
class YabWindow : public BWindow
{
public:
YabWindow(BRect frame, const char* title, const char* id, window_look winlook, window_feel winfeel, uint32 flags);
~YabWindow();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
const BString getMessages();
virtual void WindowActivated(bool state);
virtual void FrameMoved(BPoint new_position);
virtual void FrameResized(float new_width, float new_height);
int layout;
int showing;
int WActivated;
int WFrameResized;
int Wpx;
int Wpy;
int Wph;
int Wpw;
int WFrameMoved;
BString dropMsg;
BString idString;
private:
bool IsPaper(uint8* a);
BString messageString;
};
#endif

110
src/column/ColorTools.cpp Normal file
View File

@@ -0,0 +1,110 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColorTools.cpp
/
/ Description: Additional experimental color manipulation functions.
/
/ Copyright 2000, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#include "ColorTools.h"
#if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI
namespace BExperimental {
#if DEBUG
#define DB_INLINE
#else
#define DB_INLINE inline
#endif
static DB_INLINE void mix_color_func(rgb_color* target, const rgb_color other, uint8 amount)
{
target->red = (uint8)( ((int16(other.red)-int16(target->red))*amount)/255
+ target->red );
target->green = (uint8)( ((int16(other.green)-int16(target->green))*amount)/255
+ target->green );
target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*amount)/255
+ target->blue );
target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
+ target->alpha );
}
static DB_INLINE void blend_color_func(rgb_color* target, const rgb_color other, uint8 amount)
{
const uint8 alphaMix = (uint8)( ((int16(other.alpha)-int16(255-target->alpha))*amount)/255
+ (255-target->alpha) );
target->red = (uint8)( ((int16(other.red)-int16(target->red))*alphaMix)/255
+ target->red );
target->green = (uint8)( ((int16(other.green)-int16(target->green))*alphaMix)/255
+ target->green );
target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*alphaMix)/255
+ target->blue );
target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
+ target->alpha );
}
static DB_INLINE void disable_color_func(rgb_color* target, const rgb_color background)
{
blend_color_func(target, background, 255-70);
}
// --------------------------------------------------------------------------
rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount)
{
mix_color_func(&color1, color2, amount);
return color1;
}
rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount)
{
blend_color_func(&color1, color2, amount);
return color1;
}
rgb_color disable_color(rgb_color color, rgb_color background)
{
disable_color_func(&color, background);
return color;
}
}
#endif

107
src/column/ColorTools.h Normal file
View File

@@ -0,0 +1,107 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColorTools.h
/
/ Description: Additional experimental color manipulation functions.
/
/ Copyright 2000, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLOR_TOOLS_H
#define _COLOR_TOOLS_H
#include <GraphicsDefs.h>
#if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI
namespace BExperimental {
// Comparison operators.
inline bool operator==(const rgb_color c1, const rgb_color c2)
{
return (*((uint32*)&c1)) == (*((uint32*)&c2));
}
inline bool operator!=(const rgb_color c1, const rgb_color c2)
{
return (*((uint32*)&c1)) != (*((uint32*)&c2));
}
// Color creation.
#ifndef HAIKU
inline rgb_color make_color(uint8 red, uint8 green, uint8 blue, uint8 alpha=255)
{
rgb_color c;
c.red = red;
c.green = green;
c.blue = blue;
c.alpha = alpha;
return c;
}
#endif
// Mix two colors together, ignoring their relative alpha channels.
// If amount is 0, the result is color1; if 255, the result is color2;
// if another value, it is somewhere in-between. The resulting alpha
// channel is mixed exactly like the other color channels.
rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount);
// Blend two colors together, weighting by their relative alpha channels.
// The resulting color is the same as mix_color(), except that the amount
// used from color1 and color2's color channels is dependent on that color's
// alpha channel. For example, if color1.alpha is 0 and color2.alpha is
// 255, the resulting red, green, and blue values will be the same as those
// in color2, regardless of 'amount'.
rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount);
// Return a color that is the disabled representation of 'color' when drawn
// on a solid color 'background'.
rgb_color disable_color(rgb_color color, rgb_color background);
} // namespace BExperimental
using namespace BExperimental;
#endif
#endif

File diff suppressed because it is too large Load Diff

409
src/column/ColumnListView.h Normal file
View File

@@ -0,0 +1,409 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnListView.h
/
/ Description: Experimental multi-column list view.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLUMN_LIST_VIEW_H
#define _COLUMN_LIST_VIEW_H
#include <BeBuild.h>
#include <View.h>
#include <List.h>
#include <Invoker.h>
#include <ListView.h>
class BScrollBar;
namespace BPrivate {
class OutlineView;
class TitleView;
class BRowContainer;
class RecursiveOutlineIterator;
} // ns BPrivate
class BField;
class BRow;
class BColumn;
class BColumnListView;
enum LatchType {
B_NO_LATCH = 0,
B_OPEN_LATCH = 1,
B_PRESSED_LATCH = 2,
B_CLOSED_LATCH = 3
};
typedef enum {
B_ALLOW_COLUMN_NONE = 0,
B_ALLOW_COLUMN_MOVE = 1,
B_ALLOW_COLUMN_RESIZE = 2,
B_ALLOW_COLUMN_POPUP = 4,
B_ALLOW_COLUMN_REMOVE = 8
} column_flags;
enum ColumnListViewColor {
B_COLOR_BACKGROUND = 0,
B_COLOR_TEXT = 1,
B_COLOR_ROW_DIVIDER = 2,
B_COLOR_SELECTION = 3,
B_COLOR_SELECTION_TEXT = 4,
B_COLOR_NON_FOCUS_SELECTION = 5,
B_COLOR_EDIT_BACKGROUND = 6,
B_COLOR_EDIT_TEXT = 7,
B_COLOR_HEADER_BACKGROUND = 8,
B_COLOR_HEADER_TEXT = 9,
B_COLOR_SEPARATOR_LINE = 10,
B_COLOR_SEPARATOR_BORDER = 11,
B_COLOR_TOTAL = 12
};
enum ColumnListViewFont {
B_FONT_ROW = 0,
B_FONT_HEADER = 1,
B_FONT_TOTAL = 2
};
// A single row/column intersection in the list.
class BField {
public:
BField();
virtual ~BField();
};
// A single line in the list. Each line contains a BField object
// for each column in the list, associated by their "logical field"
// index. Hierarchies are formed by adding other BRow objects as
// a parent of a row, using the AddRow() function in BColumnListView().
class BRow {
public:
BRow(float height = 16.0);
virtual ~BRow();
virtual bool HasLatch() const;
int32 CountFields() const;
BField* GetField(int32 logicalFieldIndex);
const BField* GetField(int32 logicalFieldIndex) const;
void SetField(BField* field,
int32 logicalFieldIndex);
float Height() const;
bool IsExpanded() const;
private:
// Blows up into the debugger if the validation fails.
void ValidateFields() const;
void ValidateField(const BField* field,
int32 logicalFieldIndex) const;
private:
BList fFields;
BPrivate::
BRowContainer* fChildList;
bool fIsExpanded;
float fHeight;
BRow* fNextSelected;
BRow* fPrevSelected;
BRow* fParent;
BColumnListView* fList;
friend class BColumnListView;
friend class BPrivate::RecursiveOutlineIterator;
friend class BPrivate::OutlineView;
};
// Information about a single column in the list. A column knows
// how to display the BField objects that occur at its location in
// each of the list's rows. See ColumnTypes.h for particular
// subclasses of BField and BColumn that handle common data types.
class BColumn {
public:
BColumn(float width, float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual ~BColumn();
float Width() const;
void SetWidth(float width);
float MinWidth() const;
float MaxWidth() const;
virtual void DrawTitle(BRect rect, BView* targetView);
virtual void DrawField(BField* field, BRect rect,
BView* targetView);
virtual int CompareFields(BField* field1, BField* field2);
virtual void MouseMoved(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect,
BPoint point, uint32 buttons, int32 code);
virtual void MouseDown(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect,
BPoint point, uint32 buttons);
virtual void MouseUp(BColumnListView* parent, BRow* row,
BField* field);
virtual void GetColumnName(BString* into) const;
virtual float GetPreferredWidth(BField* field,
BView* parent) const;
bool IsVisible() const;
void SetVisible(bool);
bool WantsEvents() const;
void SetWantsEvents(bool);
bool ShowHeading() const;
void SetShowHeading(bool);
alignment Alignment() const;
void SetAlignment(alignment);
int32 LogicalFieldNum() const;
/*!
\param field The BField derivative to validate.
Implement this function on your BColumn derivatives to validate
BField derivatives that your BColumn will be drawing/manipulating.
This function will be called when BFields are added to the Column,
use dynamic_cast<> to determine if it is of a kind that your
BColumn know how ot handle. return false if it is not.
\note The debugger will be called if you return false from here
with information about what type of BField and BColumn and the
logical field index where it occured.
\note Do not call the inherited version of this, it just returns
true;
*/
virtual bool AcceptsField(const BField* field) const;
private:
float fWidth;
float fMinWidth;
float fMaxWidth;
bool fVisible;
int32 fFieldID;
BColumnListView* fList;
bool fSortAscending;
bool fWantsEvents;
bool fShowHeading;
alignment fAlignment;
friend class BPrivate::OutlineView;
friend class BColumnListView;
friend class BPrivate::TitleView;
};
// The column list view class.
class BColumnListView : public BView, public BInvoker {
public:
BColumnListView(BRect rect,
const char* name, uint32 resizingMode,
uint32 flags, border_style = B_NO_BORDER,
bool showHorizontalScrollbar = true);
BColumnListView(const char* name,
uint32 flags, border_style = B_NO_BORDER,
bool showHorizontalScrollbar = true);
virtual ~BColumnListView();
// Interaction
virtual bool InitiateDrag(BPoint, bool wasSelected);
virtual void MessageDropped(BMessage*, BPoint point);
virtual void ExpandOrCollapse(BRow* row, bool expand);
virtual status_t Invoke(BMessage* message = NULL);
virtual void ItemInvoked();
virtual void SetInvocationMessage(BMessage* message);
BMessage* InvocationMessage() const;
uint32 InvocationCommand() const;
BRow* FocusRow() const;
void SetFocusRow(int32 index, bool select = false);
void SetFocusRow(BRow* row, bool select = false);
void SetMouseTrackingEnabled(bool);
// Selection
list_view_type SelectionMode() const;
void Deselect(BRow* row);
void AddToSelection(BRow* row);
void DeselectAll();
BRow* CurrentSelection(BRow* lastSelected = 0) const;
virtual void SelectionChanged();
virtual void SetSelectionMessage(BMessage* message);
BMessage* SelectionMessage();
uint32 SelectionCommand() const;
void SetSelectionMode(list_view_type type);
// list_view_type is defined in ListView.h.
// Sorting
void SetSortingEnabled(bool);
bool SortingEnabled() const;
void SetSortColumn(BColumn* column, bool add,
bool ascending);
void ClearSortColumns();
// The status view is a little area in the lower left hand corner.
void AddStatusView(BView* view);
BView* RemoveStatusView();
// Column Manipulation
void AddColumn(BColumn* column,
int32 logicalFieldIndex);
void MoveColumn(BColumn* column, int32 index);
void RemoveColumn(BColumn* column);
int32 CountColumns() const;
BColumn* ColumnAt(int32 index) const;
BColumn* ColumnAt(BPoint point) const;
void SetColumnVisible(BColumn* column,
bool isVisible);
void SetColumnVisible(int32, bool);
bool IsColumnVisible(int32) const;
void SetColumnFlags(column_flags flags);
void ResizeColumnToPreferred(int32 index);
void ResizeAllColumnsToPreferred();
// Row manipulation
const BRow* RowAt(int32 index, BRow *parent = 0) const;
BRow* RowAt(int32 index, BRow *parent = 0);
const BRow* RowAt(BPoint) const;
BRow* RowAt(BPoint);
bool GetRowRect(const BRow* row, BRect* _rect) const;
bool FindParent(BRow* row, BRow** _parent,
bool *_isVisible) const;
int32 IndexOf(BRow* row);
int32 CountRows(BRow* parent = 0) const;
void AddRow(BRow* row, BRow* parent = NULL);
void AddRow(BRow* row, int32 index,
BRow* parent = NULL);
void ScrollTo(const BRow* Row);
void ScrollTo(BPoint point);
// Does not delete row or children at this time.
// todo: Make delete row and children
void RemoveRow(BRow* row);
void UpdateRow(BRow* row);
void Clear();
// Appearance (DEPRECATED)
void GetFont(BFont* font) const
{ BView::GetFont(font); }
virtual void SetFont(const BFont* font,
uint32 mask = B_FONT_ALL);
virtual void SetHighColor(rgb_color);
void SetSelectionColor(rgb_color);
void SetBackgroundColor(rgb_color);
void SetEditColor(rgb_color);
const rgb_color SelectionColor() const;
const rgb_color BackgroundColor() const;
const rgb_color EditColor() const;
// Appearance (NEW STYLE)
void SetColor(ColumnListViewColor colorIndex,
rgb_color color);
void SetFont(ColumnListViewFont fontIndex,
const BFont* font,
uint32 mask = B_FONT_ALL);
rgb_color Color(ColumnListViewColor colorIndex) const;
void GetFont(ColumnListViewFont fontIndex,
BFont* font) const;
BPoint SuggestTextPosition(const BRow* row,
const BColumn* column = NULL) const;
void SetLatchWidth(float width);
float LatchWidth() const;
virtual void DrawLatch(BView* view, BRect frame,
LatchType type, BRow* row);
virtual void MakeFocus(bool isfocus = true);
void SaveState(BMessage* archive);
void LoadState(BMessage* archive);
BView* ScrollView() const
{ return (BView*)fOutlineView; }
void SetEditMode(bool state);
void Refresh();
virtual BSize MinSize();
virtual BSize PreferredSize();
virtual BSize MaxSize();
virtual void InvalidateLayout(bool descendants = false);
protected:
virtual void MessageReceived(BMessage* message);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void AttachedToWindow();
virtual void WindowActivated(bool active);
virtual void Draw(BRect updateRect);
virtual void DoLayout();
private:
void _Init(bool showHorizontalScrollbar);
void _GetChildViewRects(const BRect& bounds,
bool showHorizontalScrollBar,
BRect& titleRect, BRect& outlineRect,
BRect& vScrollBarRect,
BRect& hScrollBarRect);
rgb_color fColorList[B_COLOR_TOTAL];
BPrivate::TitleView* fTitleView;
BPrivate::OutlineView* fOutlineView;
BList fColumns;
BScrollBar* fHorizontalScrollBar;
BScrollBar* fVerticalScrollBar;
BList fSortColumns;
BView* fStatusView;
BMessage* fSelectionMessage;
bool fSortingEnabled;
float fLatchWidth;
border_style fBorderStyle;
};
#endif // _COLUMN_LIST_VIEW_H

704
src/column/ColumnTypes.cpp Normal file
View File

@@ -0,0 +1,704 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnTypes.h
/
/ Description: Experimental classes that implement particular column/field
/ data types for use in BColumnListView.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#include "ColumnTypes.h"
#include <stdio.h>
#include <View.h>
#include <parsedate.h>
#define kTEXT_MARGIN 8
//=====================================================================
BTitledColumn::BTitledColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BColumn(width, minWidth, maxWidth, align),
fTitle(title)
{
font_height fh;
be_plain_font->GetHeight(&fh);
fFontHeight = fh.descent + fh.leading;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawTitle(BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString out_string(fTitle);
parent->TruncateString(&out_string, B_TRUNCATE_END, width + 2);
DrawString(out_string.String(), parent, rect);
}
//--------------------------------------------------------------------
void BTitledColumn::GetColumnName(BString* into) const
{
*into = fTitle;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawString(const char* string, BView* parent, BRect rect)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
float y;
BFont font;
font_height finfo;
parent->GetFont(&font);
font.GetHeight(&finfo);
y = rect.top + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
(finfo.ascent + finfo.descent) - 2;
switch (Alignment())
{
case B_ALIGN_LEFT:
parent->MovePenTo(rect.left + kTEXT_MARGIN, y);
break;
case B_ALIGN_CENTER:
parent->MovePenTo(rect.left + kTEXT_MARGIN + ((width - font.StringWidth(string)) / 2), y);
break;
case B_ALIGN_RIGHT:
parent->MovePenTo(rect.right - kTEXT_MARGIN - font.StringWidth(string), y);
break;
}
parent->DrawString(string);
}
//--------------------------------------------------------------------
void BTitledColumn::SetTitle(const char* title)
{
fTitle.SetTo(title);
}
//--------------------------------------------------------------------
void BTitledColumn::Title(BString* forTitle) const
{
if (forTitle)
forTitle->SetTo(fTitle.String());
}
//--------------------------------------------------------------------
float BTitledColumn::FontHeight() const
{
return fFontHeight;
}
// #pragma mark -
//=====================================================================
BStringField::BStringField(const char* string)
:fWidth(0),
fString(string),
fClippedString(string)
{
}
//--------------------------------------------------------------------
void BStringField::SetString(const char* val)
{
fString = val;
fClippedString = "";
fWidth = 0;
}
//--------------------------------------------------------------------
const char* BStringField::String() const
{
return fString.String();
}
//--------------------------------------------------------------------
void BStringField::SetWidth(float width)
{
fWidth = width;
}
//--------------------------------------------------------------------
float BStringField::Width()
{
return fWidth;
}
//--------------------------------------------------------------------
void BStringField::SetClippedString(const char* val)
{
fClippedString = val;
}
//--------------------------------------------------------------------
const char* BStringField::ClippedString()
{
return fClippedString.String();
}
// #pragma mark -
//=====================================================================
BStringColumn::BStringColumn(const char* title, float width, float minWidth,
float maxWidth, uint32 truncate, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTruncate(truncate)
{
}
//--------------------------------------------------------------------
void BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BStringField* field = static_cast<BStringField*>(_field);
if (width != field->Width())
{
BString out_string(field->String());
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
//--------------------------------------------------------------------
int BStringColumn::CompareFields(BField* field1, BField* field2)
{
return(ICompare(((BStringField*)field1)->String(),
(((BStringField*)field2)->String())));
}
//--------------------------------------------------------------------
bool BStringColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BStringField*>(field));
}
// #pragma mark -
//=====================================================================
BDateField::BDateField(time_t *t)
:fTime(*localtime(t)),
fUnixTime(*t),
fSeconds(0),
fClippedString(""),
fWidth(0)
{
fSeconds = mktime(&fTime);
}
//--------------------------------------------------------------------
void BDateField::SetWidth(float width)
{
fWidth = width;
}
//--------------------------------------------------------------------
float BDateField::Width()
{
return fWidth;
}
//--------------------------------------------------------------------
void BDateField::SetClippedString(const char* val)
{
fClippedString = val;
}
//--------------------------------------------------------------------
const char* BDateField::ClippedString()
{
return fClippedString.String();
}
//--------------------------------------------------------------------
time_t BDateField::Seconds()
{
return fSeconds;
}
//--------------------------------------------------------------------
time_t BDateField::UnixTime()
{
return fUnixTime;
}
// #pragma mark -
//=====================================================================
BDateColumn::BDateColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTitle(title)
{
}
//--------------------------------------------------------------------
const char *kTIME_FORMATS[] = {
"%A, %B %d %Y, %I:%M:%S %p", // Monday, July 09 1997, 05:08:15 PM
"%a, %b %d %Y, %I:%M:%S %p", // Mon, Jul 09 1997, 05:08:15 PM
"%a, %b %d %Y, %I:%M %p", // Mon, Jul 09 1997, 05:08 PM
"%b %d %Y, %I:%M %p", // Jul 09 1997, 05:08 PM
"%m/%d/%y, %I:%M %p", // 07/09/97, 05:08 PM
"%m/%d/%y", // 07/09/97
NULL
};
void BDateColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BDateField* field = (BDateField*)_field;
if (field->Width() != rect.Width())
{
char dateString[256];
time_t curtime = field->UnixTime();
tm time_data;
BFont font;
parent->GetFont(&font);
localtime_r(&curtime, &time_data);
for (int32 index = 0; ; index++)
{
if (!kTIME_FORMATS[index])
break;
strftime(dateString, 256, kTIME_FORMATS[index], &time_data);
if (font.StringWidth(dateString) <= width)
break;
}
if (font.StringWidth(dateString) > width)
{
BString out_string(dateString);
parent->TruncateString(&out_string, B_TRUNCATE_MIDDLE, width + 2);
strcpy(dateString, out_string.String());
}
field->SetClippedString(dateString);
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
//--------------------------------------------------------------------
int BDateColumn::CompareFields(BField* field1, BField* field2)
{
return((BDateField*)field1)->Seconds() - ((BDateField*)field2)->Seconds();
}
// #pragma mark -
//=====================================================================
BSizeField::BSizeField(off_t size)
:fSize(size)
{
}
//--------------------------------------------------------------------
void BSizeField::SetSize(off_t size)
{
fSize = size;
}
//--------------------------------------------------------------------
off_t BSizeField::Size()
{
return fSize;
}
// #pragma mark -
//=====================================================================
BSizeColumn::BSizeColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
const int64 kKB_SIZE = 1024;
const int64 kMB_SIZE = 1048576;
const int64 kGB_SIZE = 1073741824;
const int64 kTB_SIZE = kGB_SIZE * kKB_SIZE;
const char *kSIZE_FORMATS[] = {
"%.2f %s",
"%.1f %s",
"%.f %s",
"%.f%s",
0
};
void BSizeColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
char str[256];
float width = rect.Width() - (2 * kTEXT_MARGIN);
BFont font;
BString string;
off_t size = ((BSizeField*)_field)->Size();
parent->GetFont(&font);
if (size < kKB_SIZE)
{
sprintf(str, "%Ld bytes", size);
if (font.StringWidth(str) > width)
sprintf(str, "%Ld B", size);
}
else
{
const char* suffix;
float float_value;
if (size >= kTB_SIZE)
{
suffix = "TB";
float_value = (float)size / kTB_SIZE;
}
else if (size >= kGB_SIZE)
{
suffix = "GB";
float_value = (float)size / kGB_SIZE;
}
else if (size >= kMB_SIZE)
{
suffix = "MB";
float_value = (float)size / kMB_SIZE;
}
else
{
suffix = "KB";
float_value = (float)size / kKB_SIZE;
}
for (int32 index = 0; ; index++)
{
if (!kSIZE_FORMATS[index])
break;
sprintf(str, kSIZE_FORMATS[index], float_value, suffix);
// strip off an insignificant zero so we don't get readings
// such as 1.00
char *period = 0;
char *tmp (NULL);
for (tmp = str; *tmp; tmp++)
{
if (*tmp == '.')
period = tmp;
}
if (period && period[1] && period[2] == '0')
// move the rest of the string over the insignificant zero
for (tmp = &period[2]; *tmp; tmp++)
*tmp = tmp[1];
if (font.StringWidth(str) <= width)
break;
}
}
string = str;
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
DrawString(string.String(), parent, rect);
}
//--------------------------------------------------------------------
int BSizeColumn::CompareFields(BField* field1, BField* field2)
{
return ((BSizeField*)field1)->Size() - ((BSizeField*)field2)->Size();
}
// #pragma mark -
//=====================================================================
BIntegerField::BIntegerField(int32 number)
:fInteger(number)
{
}
//--------------------------------------------------------------------
void BIntegerField::SetValue(int32 value)
{
fInteger = value;
}
//--------------------------------------------------------------------
int32 BIntegerField::Value()
{
return fInteger;
}
// #pragma mark -
//=====================================================================
BIntegerColumn::BIntegerColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void BIntegerColumn::DrawField(BField *field, BRect rect, BView* parent)
{
char formatted[256];
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString string;
sprintf(formatted, "%d", (int)((BIntegerField*)field)->Value());
string = formatted;
parent->TruncateString(&string, B_TRUNCATE_MIDDLE, width + 2);
DrawString(string.String(), parent, rect);
}
//--------------------------------------------------------------------
int BIntegerColumn::CompareFields(BField *field1, BField *field2)
{
return (((BIntegerField*)field1)->Value() - ((BIntegerField*)field2)->Value());
}
// #pragma mark -
//=====================================================================
GraphColumn::GraphColumn(const char* name, float width, float minWidth,
float maxWidth, alignment align)
:BIntegerColumn(name, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void GraphColumn::DrawField(BField* field, BRect rect, BView* parent)
{
int number = ((BIntegerField*)field)->Value();
if (number > 100)
number = 100;
else if (number < 0)
number = 0;
BRect graphRect(rect);
graphRect.InsetBy(5, 3);
parent->StrokeRect(graphRect);
if (number > 0) {
graphRect.InsetBy(1, 1);
float val = graphRect.Width() * (float) number / 100;
graphRect.right = graphRect.left + val;
parent->SetHighColor(0, 0, 190);
parent->FillRect(graphRect);
}
parent->SetDrawingMode(B_OP_INVERT);
parent->SetHighColor(128, 128, 128);
char numstr[256];
sprintf(numstr, "%d%%", number);
float width = be_plain_font->StringWidth(numstr);
parent->MovePenTo(rect.left + rect.Width() / 2 - width / 2, rect.bottom - FontHeight());
parent->DrawString(numstr);
}
// #pragma mark -
//=====================================================================
BBitmapField::BBitmapField(BBitmap *bitmap)
:fBitmap(bitmap)
{
}
//--------------------------------------------------------------------
const BBitmap* BBitmapField::Bitmap()
{
return fBitmap;
}
//--------------------------------------------------------------------
void BBitmapField::SetBitmap(BBitmap* bitmap)
{
fBitmap = bitmap;
}
// #pragma mark -
//=====================================================================
BBitmapColumn::BBitmapColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align)
{
}
//--------------------------------------------------------------------
void BBitmapColumn::DrawField(BField* field, BRect rect, BView* parent)
{
BBitmapField *bitmapField = static_cast<BBitmapField *>(field);
const BBitmap *bitmap = bitmapField->Bitmap();
if (bitmap != NULL)
{
float x = 0.0;
float y;
BRect r = bitmap->Bounds();
y = rect.top + ((rect.Height() - r.Height()) / 2);
switch (Alignment())
{
case B_ALIGN_LEFT:
x = rect.left + kTEXT_MARGIN;
break;
case B_ALIGN_CENTER:
x = rect.left + ((rect.Width() - r.Width()) / 2);
break;
case B_ALIGN_RIGHT:
x = rect.right - kTEXT_MARGIN - r.Width();
break;
}
parent->SetDrawingMode(B_OP_ALPHA);
parent->DrawBitmap(bitmap, BPoint(x, y));
parent->SetDrawingMode(B_OP_OVER);
}
}
//--------------------------------------------------------------------
int BBitmapColumn::CompareFields(BField* /*field1*/, BField* /*field2*/)
{
// Comparing bitmaps doesn't really make sense...
return 0;
}
//--------------------------------------------------------------------
bool
BBitmapColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BBitmapField*>(field));
}

289
src/column/ColumnTypes.h Normal file
View File

@@ -0,0 +1,289 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/*******************************************************************************
/
/ File: ColumnTypes.h
/
/ Description: Experimental classes that implement particular column/field
/ data types for use in BColumnListView.
/
/ Copyright 2000+, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _COLUMN_TYPES_H
#define _COLUMN_TYPES_H
#include "ColumnListView.h"
#include <String.h>
#include <Font.h>
#include <Bitmap.h>
//=====================================================================
// Common base-class: a column that draws a standard title at its top.
class BTitledColumn : public BColumn
{
public:
BTitledColumn (const char *title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawTitle (BRect rect,
BView* parent);
virtual void GetColumnName (BString* into) const;
void DrawString (const char*,
BView*,
BRect);
void SetTitle (const char* title);
void Title (BString* forTitle) const; // sets the BString arg to be the title
float FontHeight () const;
private:
float fFontHeight;
BString fTitle;
};
//=====================================================================
// Field and column classes for strings.
class BStringField : public BField
{
public:
BStringField (const char* string);
void SetString (const char* string);
const char* String () const;
void SetClippedString (const char* string);
const char* ClippedString ();
void SetWidth (float);
float Width ();
private:
float fWidth;
BString fString;
BString fClippedString;
};
//--------------------------------------------------------------------
class BStringColumn : public BTitledColumn
{
public:
BStringColumn (const char *title,
float width,
float maxWidth,
float minWidth,
uint32 truncate,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
virtual bool AcceptsField (const BField* field) const;
private:
uint32 fTruncate;
};
//=====================================================================
// Field and column classes for dates.
class BDateField : public BField
{
public:
BDateField (time_t* t);
void SetWidth (float);
float Width ();
void SetClippedString (const char*);
const char* ClippedString ();
time_t Seconds ();
time_t UnixTime ();
private:
struct tm fTime;
time_t fUnixTime;
time_t fSeconds;
BString fClippedString;
float fWidth;
};
//--------------------------------------------------------------------
class BDateColumn : public BTitledColumn
{
public:
BDateColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
private:
BString fTitle;
};
//=====================================================================
// Field and column classes for numeric sizes.
class BSizeField : public BField
{
public:
BSizeField (off_t size);
void SetSize (off_t);
off_t Size ();
private:
off_t fSize;
};
//--------------------------------------------------------------------
class BSizeColumn : public BTitledColumn
{
public:
BSizeColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
};
//=====================================================================
// Field and column classes for integers.
class BIntegerField : public BField
{
public:
BIntegerField (int32 number);
void SetValue (int32);
int32 Value ();
private:
int32 fInteger;
};
//--------------------------------------------------------------------
class BIntegerColumn : public BTitledColumn
{
public:
BIntegerColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField* field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1,
BField* field2);
};
//=====================================================================
// Field and column classes for bitmaps
class BBitmapField : public BField
{
public:
BBitmapField (BBitmap* bitmap);
const BBitmap* Bitmap ();
void SetBitmap (BBitmap* bitmap);
private:
BBitmap* fBitmap;
};
//--------------------------------------------------------------------
class BBitmapColumn : public BTitledColumn
{
public:
BBitmapColumn (const char* title,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField*field,
BRect rect,
BView* parent);
virtual int CompareFields (BField* field1, BField* field2);
virtual bool AcceptsField (const BField* field) const;
};
//=====================================================================
// Column to display BIntegerField objects as a graph.
class GraphColumn : public BIntegerColumn
{
public:
GraphColumn (const char* name,
float width,
float minWidth,
float maxWidth,
alignment align = B_ALIGN_LEFT);
virtual void DrawField (BField*field,
BRect rect,
BView* parent);
};
#endif

800
src/column/ObjectList.h Normal file
View File

@@ -0,0 +1,800 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/****************************************************************************
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
** **
** DANGER, WILL ROBINSON! **
** **
** The interfaces contained here are part of BeOS's **
** **
** >> PRIVATE NOT FOR PUBLIC USE << **
** **
** implementation. **
** **
** These interfaces WILL CHANGE in future releases. **
** If you use them, your app WILL BREAK at some future time. **
** **
** (And yes, this does mean that binaries built from OpenTracker will not **
** be compatible with some future releases of the OS. When that happens, **
** we will provide an updated version of this file to keep compatibility.) **
** **
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
****************************************************************************/
//
// ObjectList is a wrapper around BList that adds type safety,
// optional object ownership, search, insert operations, etc.
//
#ifndef __OBJECT_LIST__
#define __OBJECT_LIST__
#ifndef _BE_H
#include <List.h>
#endif
#include <Debug.h>
template<class T> class BObjectList;
template<class T>
struct UnaryPredicate {
virtual int operator()(const T *) const
// virtual could be avoided here if FindBinaryInsertionIndex,
// etc. were member template functions
{ return 0; }
private:
static int _unary_predicate_glue(const void *item, void *context);
friend class BObjectList<T>;
};
template<class T>
int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
{
return ((UnaryPredicate<T> *)context)->operator()((const T *)item);
}
class _PointerList_ : public BList {
public:
_PointerList_(const _PointerList_ &list);
_PointerList_(int32 itemsPerBlock = 20, bool owning = false);
~_PointerList_();
typedef void *(* GenericEachFunction)(void *, void *);
typedef int (* GenericCompareFunction)(const void *, const void *);
typedef int (* GenericCompareFunctionWithState)(const void *, const void *,
void *);
typedef int (* UnaryPredicateGlue)(const void *, void *);
void *EachElement(GenericEachFunction, void *);
void SortItems(GenericCompareFunction);
void SortItems(GenericCompareFunctionWithState, void *state);
void HSortItems(GenericCompareFunction);
void HSortItems(GenericCompareFunctionWithState, void *state);
void *BinarySearch(const void *, GenericCompareFunction) const;
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
bool Owning() const;
bool ReplaceItem(int32, void *);
protected:
bool owning;
};
template<class T>
class BObjectList : private _PointerList_ {
public:
// iteration and sorting
typedef T *(* EachFunction)(T *, void *);
typedef const T *(* ConstEachFunction)(const T *, void *);
typedef int (* CompareFunction)(const T *, const T *);
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state);
BObjectList(int32 itemsPerBlock = 20, bool owning = false);
BObjectList(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
virtual ~BObjectList();
BObjectList &operator=(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
// adding and removing
// ToDo:
// change Add calls to return const item
bool AddItem(T *);
bool AddItem(T *, int32);
bool AddList(BObjectList *);
bool AddList(BObjectList *, int32);
bool RemoveItem(T *, bool deleteIfOwning = true);
// if owning, deletes the removed item
T *RemoveItemAt(int32);
// returns the removed item
void MakeEmpty();
// item access
T *ItemAt(int32) const;
bool ReplaceItem(int32 index, T *);
// if list is owning, deletes the item at <index> first
T *SwapWithItem(int32 index, T *newItem);
// same as ReplaceItem, except does not delete old item at <index>,
// returns it instead
T *FirstItem() const;
T *LastItem() const;
// misc. getters
int32 IndexOf(const T *) const;
bool HasItem(const T *) const;
bool IsEmpty() const;
int32 CountItems() const;
T *EachElement(EachFunction, void *);
const T *EachElement(ConstEachFunction, void *) const;
void SortItems(CompareFunction);
void SortItems(CompareFunctionWithState, void *state);
void HSortItems(CompareFunction);
void HSortItems(CompareFunctionWithState, void *state);
// linear search, returns first item that matches predicate
const T *FindIf(const UnaryPredicate<T> &) const;
T *FindIf(const UnaryPredicate<T> &);
// list must be sorted with CompareFunction for these to work
const T *BinarySearch(const T &, CompareFunction) const;
const T *BinarySearch(const T &, CompareFunctionWithState, void *state) const;
// Binary insertion - list must be sorted with CompareFunction for
// these to work
// simple insert
void BinaryInsert(T *, CompareFunction);
void BinaryInsert(T *, CompareFunctionWithState, void *state);
void BinaryInsert(T *, const UnaryPredicate<T> &);
// unique insert, returns false if item already in list
bool BinaryInsertUnique(T *, CompareFunction);
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
// insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, CompareFunctionWithState, void *state);
// insert a copy of the item if not in list already
// returns new inserted item or existing item in case of a conflict
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
// returns either the index into which a new item should be inserted
// or index of an existing item that matches the predicate
// deprecated API, will go away
BList *AsBList()
{ return this; }
const BList *AsBList() const
{ return this; }
private:
void SetItem(int32, T *);
};
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
break;
return result;
}
template<class Item, class Result>
void
EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)();
}
template<class Item, class Param1>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)(p1, p2);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2);
}
template<class Item, class Param1, class Param2, class Param3>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3), Param1 p1, Param2 p2, Param3 p3)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3);
}
template<class Item, class Param1, class Param2, class Param3, class Param4>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3, p4);
}
// inline code
inline bool
_PointerList_::Owning() const
{
return owning;
}
template<class T>
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool isOwning)
: _PointerList_(itemsPerBlock, isOwning)
{
}
template<class T>
BObjectList<T>::BObjectList(const BObjectList<T> &list)
: _PointerList_(list)
{
owning = list.owning;
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
}
template<class T>
BObjectList<T>::~BObjectList()
{
if (Owning())
// have to nuke elements first
MakeEmpty();
}
template<class T>
BObjectList<T> &
BObjectList<T>::operator=(const BObjectList<T> &list)
{
owning = list.owning;
BObjectList<T> &result = (BObjectList<T> &)_PointerList_::operator=(list);
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
return result;
}
template<class T>
bool
BObjectList<T>::AddItem(T *item)
{
// need to cast to void * to make T work for const pointers
return _PointerList_::AddItem((void *)item);
}
template<class T>
bool
BObjectList<T>::AddItem(T *item, int32 atIndex)
{
return _PointerList_::AddItem((void *)item, atIndex);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems)
{
return _PointerList_::AddList(newItems);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
{
return _PointerList_::AddList(newItems, atIndex);
}
template<class T>
bool
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
{
bool result = _PointerList_::RemoveItem((void *)item);
if (result && Owning() && deleteIfOwning)
delete item;
return result;
}
template<class T>
T *
BObjectList<T>::RemoveItemAt(int32 index)
{
return (T *)_PointerList_::RemoveItem(index);
}
template<class T>
inline T *
BObjectList<T>::ItemAt(int32 index) const
{
return (T *)_PointerList_::ItemAt(index);
}
template<class T>
bool
BObjectList<T>::ReplaceItem(int32 index, T *item)
{
if (owning)
delete ItemAt(index);
return _PointerList_::ReplaceItem(index, (void *)item);
}
template<class T>
T *
BObjectList<T>::SwapWithItem(int32 index, T *newItem)
{
T *result = ItemAt(index);
_PointerList_::ReplaceItem(index, (void *)newItem);
return result;
}
template<class T>
void
BObjectList<T>::SetItem(int32 index, T *newItem)
{
_PointerList_::ReplaceItem(index, (void *)newItem);
}
template<class T>
int32
BObjectList<T>::IndexOf(const T *item) const
{
return _PointerList_::IndexOf((void *)const_cast<T *>(item));
}
template<class T>
T *
BObjectList<T>::FirstItem() const
{
return (T *)_PointerList_::FirstItem();
}
template<class T>
T *
BObjectList<T>::LastItem() const
{
return (T *)_PointerList_::LastItem();
}
template<class T>
bool
BObjectList<T>::HasItem(const T *item) const
{
return _PointerList_::HasItem((void *)item);
}
template<class T>
bool
BObjectList<T>::IsEmpty() const
{
return _PointerList_::IsEmpty();
}
template<class T>
int32
BObjectList<T>::CountItems() const
{
return _PointerList_::CountItems();
}
template<class T>
void
BObjectList<T>::MakeEmpty()
{
if (owning) {
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
delete ItemAt(index);
}
_PointerList_::MakeEmpty();
}
template<class T>
T *
BObjectList<T>::EachElement(EachFunction func, void *params)
{
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const
{
return (const T *)
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
(GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate) const
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate)
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunction function)
{
_PointerList_::SortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunction function)
{
_PointerList_::HSortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)func, state);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func,
void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
const
{
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
if (alreadyInList)
*alreadyInList = index >= 0;
if (index < 0)
index = -index - 1;
return index;
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
{
int32 index = FindBinaryInsertionIndex(pred);
AddItem(item, index);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
{
bool alreadyInList;
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);
if (alreadyInList)
return false;
AddItem(item, index);
return true;
}
#endif

View File

@@ -0,0 +1,413 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#include "YabColumnType.h"
#include <stdio.h>
#include <Application.h>
#include <BitmapStream.h>
#include <File.h>
#include <Path.h>
#include <Roster.h>
#include <TranslatorRoster.h>
#include <Translator.h>
#include <View.h>
#include <NodeInfo.h>
#ifdef ZETA
#include <sys_apps/Tracker/Icons.h>
#endif
#define kTEXT_MARGIN 8
#define kIMG_MARGIN 2
//=====================================================================
BTitledColumn::BTitledColumn(const char* title, float width, float minWidth,
float maxWidth, alignment align)
:BColumn(width, minWidth, maxWidth, align),
fTitle(title)
{
font_height fh;
be_plain_font->GetHeight(&fh);
fFontHeight = fh.descent + fh.leading;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawTitle(BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BString out_string(fTitle);
parent->TruncateString(&out_string, B_TRUNCATE_END, width + 2);
DrawString(out_string.String(), parent, rect);
}
//--------------------------------------------------------------------
void BTitledColumn::GetColumnName(BString* into) const
{
*into = fTitle;
}
//--------------------------------------------------------------------
void BTitledColumn::DrawString(const char* string, BView* parent, BRect rect)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
float y;
BFont font;
font_height finfo;
parent->GetFont(&font);
font.GetHeight(&finfo);
y = rect.top + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
(finfo.ascent + finfo.descent) - 2;
switch (Alignment())
{
case B_ALIGN_LEFT:
parent->MovePenTo(rect.left + kTEXT_MARGIN, y);
break;
case B_ALIGN_CENTER:
parent->MovePenTo(rect.left + kTEXT_MARGIN + ((width - font.StringWidth(string)) / 2), y);
break;
case B_ALIGN_RIGHT:
parent->MovePenTo(rect.right - kTEXT_MARGIN - font.StringWidth(string), y);
break;
}
parent->DrawString(string);
}
//--------------------------------------------------------------------
void BTitledColumn::SetTitle(const char* title)
{
fTitle.SetTo(title);
}
//--------------------------------------------------------------------
void BTitledColumn::Title(BString* forTitle) const
{
if (forTitle)
forTitle->SetTo(fTitle.String());
}
//--------------------------------------------------------------------
float BTitledColumn::FontHeight() const
{
return fFontHeight;
}
//=====================================================================
BYabField::BYabField(const char* string)
:fWidth(0), fString(string), fClippedString(string)
{
int n = fString.FindFirst("__Icon__=");
fBitmap = NULL;
if(n==0)
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
BPath AppDirectory;
// app directory
BString ApplicationDirectory("");
app_info appinfo;
if(be_roster->GetRunningAppInfo(be_app->Team(), &appinfo) == B_OK)
{
BEntry ApplicationEntry( &appinfo.ref);
BEntry ApplicationDirectoryEntry;
if( ApplicationEntry.GetParent( &ApplicationDirectoryEntry) == B_OK)
{
if( AppDirectory.SetTo( &ApplicationDirectoryEntry) == B_OK)
{
// strcpy(ApplicationDirectory, AppDirectory.Path());
ApplicationDirectory.SetTo(AppDirectory.Path());
}
}
}
BFile ImageFile;
BPath ImagePath;
if(myPath[0] == '/')
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
else
// App directory.
if(ApplicationDirectory != "")
{
if( ImagePath.SetTo(ApplicationDirectory.String(), myPath.String()) == B_OK)
ImageFile.SetTo( ImagePath.Path(), B_READ_ONLY);
}
if( ImageFile.InitCheck() != B_OK)
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
if( ImageFile.InitCheck() == B_OK)
{
BTranslatorRoster *Roster = BTranslatorRoster::Default();
if( Roster)
{
BBitmapStream Stream;
if( Roster->Translate( &ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) == B_OK)
Stream.DetachBitmap( &fBitmap);
delete Roster;
}
}
}
}
void BYabField::SetString(const char* val, int height)
{
fString = val;
fClippedString = "";
fWidth = 0;
fBitmap = NULL;
if( ! fString.FindFirst("__Icon__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
BPath AppDirectory;
// app directory
BString ApplicationDirectory("");
app_info appinfo;
if(be_roster->GetRunningAppInfo(be_app->Team(), &appinfo) == B_OK)
{
BEntry ApplicationEntry( &appinfo.ref);
BEntry ApplicationDirectoryEntry;
if( ApplicationEntry.GetParent( &ApplicationDirectoryEntry) == B_OK)
{
if( AppDirectory.SetTo( &ApplicationDirectoryEntry) == B_OK)
{
// strcpy(ApplicationDirectory, AppDirectory.Path());
ApplicationDirectory.SetTo(AppDirectory.Path());
}
}
}
BFile ImageFile;
BPath ImagePath;
if(myPath[0] == '/')
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
else
// App directory.
if(ApplicationDirectory != "")
{
if( ImagePath.SetTo(ApplicationDirectory.String(), myPath.String()) == B_OK)
ImageFile.SetTo( ImagePath.Path(), B_READ_ONLY);
}
if( ImageFile.InitCheck() != B_OK)
ImageFile.SetTo( myPath.String(), B_READ_ONLY);
if( ImageFile.InitCheck() == B_OK)
{
BTranslatorRoster *Roster = BTranslatorRoster::Default();
if( Roster)
{
BBitmapStream Stream;
if( Roster->Translate( &ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) == B_OK)
Stream.DetachBitmap( &fBitmap);
delete Roster;
}
}
}
else if( ! fString.FindFirst("__Mime__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
fBitmap = new BBitmap(BRect(0, 0, 15,15), B_CMAP8);
BMimeType mime(myPath.String());
mime.GetIcon(fBitmap, B_MINI_ICON);
}
else if( ! fString.FindFirst("__Path__=") )
{
BString myPath;
fString.CopyInto(myPath, 9, fString.Length()-9);
#ifdef ZETA
fBitmap = new BBitmap(BRect(0, 0, 15, 15), B_RGBA32);
BEntry fEntry = BEntry( myPath.String() );
BBitmap icon = &GetTrackerIcon(fEntry, 16);
*fBitmap = icon;
#else
fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
BNode *fNode = new BNode(myPath.String());
BNodeInfo fInfo(fNode);
fInfo.GetTrackerIcon(fBitmap, B_LARGE_ICON);
delete fNode;
#endif
}
}
const char* BYabField::String() const
{
return fString.String();
}
void BYabField::SetWidth(float width)
{
fWidth = width;
}
float BYabField::Width()
{
return fWidth;
}
void BYabField::SetClippedString(const char* val)
{
fClippedString = val;
}
const char* BYabField::ClippedString()
{
return fClippedString.String();
}
const BBitmap* BYabField::Bitmap()
{
return fBitmap;
}
void BYabField::SetBitmap(BBitmap* bitmap)
{
fBitmap = bitmap;
}
bool BYabField::HasBitmap()
{
if(fBitmap) return true;
return false;
}
//=====================================================================
BYabColumn::BYabColumn(const char* title, float width, float minWidth,
float maxWidth, uint32 truncate, alignment align)
:BTitledColumn(title, width, minWidth, maxWidth, align),
fTruncate(truncate)
{
}
void BYabColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
if(!((BYabField*)_field)->HasBitmap())
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
BYabField* field = static_cast<BYabField*>(_field);
if (width != field->Width())
{
BString out_string(field->String());
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
field->SetWidth(width);
}
DrawString(field->ClippedString(), parent, rect);
}
else
{
BYabField *bitmapField = static_cast<BYabField *>(_field);
const BBitmap *bitmap = bitmapField->Bitmap();
if (bitmap != NULL)
{
float x = 0.0;
float y;
BRect r = bitmap->Bounds();
y = rect.top + ((rect.Height() - r.Height()) / 2);
switch (Alignment())
{
case B_ALIGN_LEFT:
x = rect.left + kIMG_MARGIN;
break;
case B_ALIGN_CENTER:
x = rect.left + ((rect.Width() - r.Width()) / 2);
break;
case B_ALIGN_RIGHT:
x = rect.right - kIMG_MARGIN - r.Width();
break;
}
parent->SetDrawingMode(B_OP_ALPHA);
parent->DrawBitmap(bitmap, BPoint(x, y));
parent->SetDrawingMode(B_OP_OVER);
}
}
}
int BYabColumn::CompareFields(BField* field1, BField* field2)
{
return(ICompare(((BYabField*)field1)->String(),
(((BYabField*)field2)->String())));
}
bool
BYabColumn::AcceptsField(const BField *field) const
{
return static_cast<bool>(dynamic_cast<const BYabField*>(field));
}

107
src/column/YabColumnType.h Normal file
View File

@@ -0,0 +1,107 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
#ifndef YAB_COLUMN_TYPES_H
#define YAB_COLUMN_TYPES_H
#include "../global.h"
#include <String.h>
#include <Font.h>
#include <Bitmap.h>
#include "ColumnListView.h"
//=====================================================================
// Common base-class: a column that draws a standard title at its top.
class BTitledColumn : public BColumn
{
public:
BTitledColumn (const char *title, float width, float minWidth, float maxWidth, alignment align = B_ALIGN_LEFT);
virtual void DrawTitle(BRect rect, BView* parent);
virtual void GetColumnName(BString* into) const;
void DrawString(const char*, BView*, BRect);
void SetTitle(const char* title);
void Title(BString* forTitle) const; // sets the BString arg to be the title
float FontHeight() const;
private:
float fFontHeight;
BString fTitle;
};
//=====================================================================
// Field and column classes for strings.
class BYabField : public BField
{
public:
BYabField (const char* string);
BYabField (BBitmap* bitmap);
void SetString(const char* string, int height);
const char* String() const;
void SetClippedString(const char* string);
const char*ClippedString();
void SetWidth(float);
float Width();
const BBitmap* Bitmap();
void SetBitmap(BBitmap* bitmap);
bool HasBitmap();
private:
BBitmap* fBitmap;
float fWidth;
BString fString;
BString fClippedString;
};
//--------------------------------------------------------------------
class BYabColumn: public BTitledColumn
{
public:
BYabColumn(const char *title, float width, float maxWidth, float minWidth, uint32 truncate, alignment align = B_ALIGN_LEFT);
virtual void DrawField(BField* field, BRect rect, BView* parent);
virtual int CompareFields(BField* field1, BField* field2);
virtual bool AcceptsField(const BField* field) const;
private:
uint32 fTruncate;
};
#endif

216
src/config.h Normal file
View File

@@ -0,0 +1,216 @@
#ifndef CONFIG_H
#define CONFIG_H
#define BEOS
// #define LIBBSVG
#define BUILD_TIME __DATE__
/* Version number of package */
#define VERSION "1.7.4.3"
/* architecture of build machine */
#define UNIX_ARCHITECTURE "BePC-Haiku"
/* config.h. Generated by configure. */
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have `alloca', as a function or macro. */
#define HAVE_ALLOCA 1
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
*/
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
/* defined, if ncurses.h is present */
#define HAVE_CURSES_HEADER 1
/* Define to 1 if you have the `difftime' function. */
#define HAVE_DIFFTIME 1
/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
/* Define to 1 if you have the <float.h> header file. */
#define HAVE_FLOAT_H 1
/* Define to 1 if you have the `floor' function. */
#define HAVE_FLOOR 1
/* Define to 1 if you have the `fork' function. */
#define HAVE_FORK 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `ncurses' library (-lncurses). */
#define HAVE_LIBNCURSES 0
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <math.h> header file. */
#define HAVE_MATH_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* defined, if ncurses.h is present */
#define HAVE_NCURSES_HEADER 0
/* Define to 1 if you have the `pow' function. */
#define HAVE_POW 1
/* Define to 1 if you have the `select' function. */
#define HAVE_SELECT 1
/* Define to 1 if you have the <signal.h> header file. */
#define HAVE_SIGNAL_H 1
/* Define to 1 if you have the `sqrt' function. */
#define HAVE_SQRT 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
/* #undef HAVE_STDINT_H */
/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strchr' function. */
#define HAVE_STRCHR 1
/* Define to 1 if you have the `strerror' function. */
#define HAVE_STRERROR 1
/* Define to 1 if you have the `strftime' function. */
#define HAVE_STRFTIME 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* defined, if strings.h is present */
#define HAVE_STRINGS_HEADER 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* defined, if string.h is present */
#define HAVE_STRING_HEADER 1
/* Define to 1 if you have the `strpbrk' function. */
#define HAVE_STRPBRK 1
/* Define to 1 if you have the `strrchr' function. */
#define HAVE_STRRCHR 1
/* Define to 1 if you have the `strstr' function. */
#define HAVE_STRSTR 1
/* Define to 1 if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
#define HAVE_SYS_WAIT_H 1
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define to 1 if you have the `tmpnam' function. */
#define HAVE_TMPNAM 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the `vfork' function. */
/* #undef HAVE_VFORK */
/* Define to 1 if you have the <vfork.h> header file. */
/* #undef HAVE_VFORK_H */
/* Define to 1 if `fork' works. */
#define HAVE_WORKING_FORK 1
/* Define to 1 if `vfork' works. */
/* #undef HAVE_WORKING_VFORK */
/* Name of package */
#define PACKAGE "yabasic"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME ""
/* Define to the full name and version of this package. */
#define PACKAGE_STRING ""
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME ""
/* Define to the version of this package. */
#define PACKAGE_VERSION ""
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to the type of arg 1 for `select'. */
#define SELECT_TYPE_ARG1 int
/* Define to the type of args 2, 3 and 4 for `select'. */
#define SELECT_TYPE_ARG234 (fd_set *)
/* Define to the type of arg 5 for `select'. */
#define SELECT_TYPE_ARG5 (struct timeval *)
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
automatically deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Define to 1 if the X Window System is missing or not being used. */
#define X_DISPLAY_MISSING 1
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef pid_t */
/* Define to `unsigned' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define as `fork' if `vfork' does not work. */
#define vfork fork
#endif

3
src/fixattributes.sh Executable file
View File

@@ -0,0 +1,3 @@
#!sh
yab RdefApply YAB.rdef yab
addattr -t mime BEOS:TYPE application/x-vnd.be-elfexecutable yab

2053
src/function.c Normal file

File diff suppressed because it is too large Load Diff

3
src/global.h Normal file
View File

@@ -0,0 +1,3 @@
//define BUILD_NCURSES
#define BUILD_YABTEXT
#define BUILD_GAMESOUND

2560
src/graphic.c Normal file

File diff suppressed because it is too large Load Diff

1586
src/io.c Normal file

File diff suppressed because it is too large Load Diff

2250
src/main.c Normal file

File diff suppressed because it is too large Load Diff

BIN
src/resattr Executable file

Binary file not shown.

1775
src/symbol.c Normal file

File diff suppressed because it is too large Load Diff

3918
src/yab-IDE.yab Executable file

File diff suppressed because it is too large Load Diff

940
src/yabasic.bison Normal file
View File

@@ -0,0 +1,940 @@
%{
/*
YABASIC --- a simple Basic Interpreter
written by Marc-Oliver Ihm 1995-2004
homepage: www.yabasic.de
BISON part
This file is part of yabasic and may be copied only
under the terms of either the Artistic License or
the GNU General Public License (GPL), both of which
can be found at www.yabasic.de
*/
#ifndef YABASIC_INCLUDED
#include "yabasic.h" /* definitions of yabasic */
#endif
#include <malloc.h>
#if HAVE_ALLOCA_H
#ifndef WINDOWS
#include <alloca.h>
#endif
#endif
void __yy_bcopy(char *,char *,int); /* prototype missing */
int tileol; /* true, read should go to eon of line */
int mylineno=1; /* line number; counts fresh in every new file */
int main_lineno=1; /* line number of main */
int function_type=ftNONE; /* contains function type while parsing function */
char *current_function=NULL; /* name of currently parsed function */
int exported=FALSE; /* true, if function is exported */
int yylex(void);
extern struct libfile_name *current_libfile; /* defined in main.c: name of currently parsed file */
int missing_endif=0;
int missing_endif_line=0;
int missing_endsub=0;
int missing_endsub_line=0;
int missing_next=0;
int missing_next_line=0;
int missing_wend=0;
int missing_wend_line=0;
int missing_until=0;
int missing_until_line=0;
int missing_loop=0;
int missing_loop_line=0;
int in_loop=0;
void report_missing(int severity,char *text) {
if (missing_loop || missing_endif || missing_next || missing_until || missing_wend) {
error(severity,text);
string[0]='\0';
if (missing_endif)
sprintf(string,"if statement starting at line %d has seen no 'endif' yet",missing_endif_line);
else if (missing_next)
sprintf(string,"for-loop starting at line %d has seen no 'next' yet",missing_next_line);
else if (missing_wend)
sprintf(string,"while-loop starting at line %d has seen no 'wend' yet",missing_wend_line);
else if (missing_until)
sprintf(string,"repeat-loop starting at line %d has seen no 'until' yet",missing_until_line);
else if (missing_loop)
sprintf(string,"do-loop starting at line %d has seen no 'loop' yet",missing_wend_line);
if (string[0]) error(severity,string);
}
}
%}
%union {
double fnum; /* double number */
int inum; /* integer number */
int token; /* token of command */
int sep; /* number of newlines */
char *string; /* quoted string */
char *symbol; /* general symbol */
char *digits; /* string of digits */
char *docu; /* embedded documentation */
}
%type <fnum> const
%type <fnum> number
%type <symbol> symbol_or_lineno
%type <symbol> function_name
%type <symbol> function_or_array
%type <symbol> stringfunction_or_array
%type <sep> tSEP sep_list
%token <fnum> tFNUM
%token <symbol> tSYMBOL
%token <symbol> tSTRSYM
%token <symbol> tDOCU
%token <digits> tDIGITS
%token <string> tSTRING
%token tFOR tTO tSTEP tNEXT tWHILE tWEND tREPEAT tUNTIL tIMPORT
%token tGOTO tGOSUB tLABEL tON tSUB tENDSUB tLOCAL tSTATIC tEXPORT tERROR
%token tEXECUTE tEXECUTE2 tCOMPILE tRUNTIME_CREATED_SUB
%token tINTERRUPT tBREAK tCONTINUE tSWITCH tSEND tCASE tDEFAULT tLOOP tDO tSEP tEOPROG
%token tIF tTHEN tELSE tELSIF tENDIF tUSING
%token tPRINT tINPUT tLINE tRETURN tDIM tEND tEXIT tAT tSCREEN tSCREENSHOT
%token tREVERSE tCOLOUR
%token tAND tOR tNOT tEOR
%token tNEQ tLEQ tGEQ tLTN tGTN tEQU tPOW
%token tREAD tDATA tRESTORE
%token tOPEN tCLOSE tSEEK tTELL tAS tREADING tWRITING
%token tWAIT tBELL tLET tARDIM tARSIZE tBIND
%token tWINDOW tDOT tCIRCLE tCLEAR tFILL tPRINTER tSETUP
%token tBUTTON tALERT tMENU tCHECKBOX tRADIOBUTTON tTEXTCONTROL
%token tLISTBOX tDROPBOX tADD tREMOVE tLOCALIZE tFILEPANEL tSLIDER tSTATUSBAR
%token tLAYOUT tSET tTEXTEDIT tCOUNT tVIEW tBOXVIEW tTABVIEW tTEXTURL tBITMAP tCANVAS
%token tOPTION tDROPZONE tCOLORCONTROL tTREEBOX tCOLUMNBOX tCOLUMN tSORT tTOOLTIP tCALENDAR
%token tCLIPBOARD tCOPY tSUBMENU tSELECT tSCROLLBAR tEXPAND tCOLLAPSE tSPLITVIEW tSTACKVIEW
%token tPOPUPMENU tSPINCONTROL tMSEND tNUMMESSAGE tTHREAD tSOUND tPLAY tSTOP tSHORTCUT tISCOMPUTERON
%token tDRAW tTEXT tFLUSH tELLIPSE tSAVE
%token tRECT tGETCHAR tPUTCHAR tNEW tCURVE tLAUNCH tATTRIBUTE
%token tSIN tASIN tCOS tACOS tTAN tATAN tEXP tLOG
%token tSQRT tSQR tMYEOF tABS tSIG
%token tINT tFRAC tMOD tRAN tLEN tVAL tLEFT tRIGHT tMID tMIN tMAX
%token tSTR tINKEY tCHR tASC tHEX tDEC tBIN tUPPER tLOWER
%token tTRIM tLTRIM tRTRIM tINSTR tRINSTR
%token tSYSTEM tSYSTEM2 tPEEK tPEEK2 tPOKE
%token tDATE tTIME tTOKEN tTOKENALT tSPLIT tSPLITALT tGLOB
%token tMESSAGE tIMAGE tSVG tTRANSLATE tGET tMOUSE tISMOUSEIN
%token tKEYBOARD tPASTE tGETNUM
%left tOR
%left tAND
%left tNOT
%left tNEQ
%left tGEQ
%left tLEQ
%left tLTN
%left tGTN
%left tEQU
%left '-' '+'
%left '*' '/'
%left tPOW
%nonassoc UMINUS
%%
program: statement_list tEOPROG {YYACCEPT;}
;
statement_list: statement
| statement_list {if (errorlevel<=ERROR) {YYABORT;}}
tSEP {if ($3>=0) mylineno+=$3; else switchlib();} statement
;
statement: /* empty */
| string_assignment
| tLET string_assignment
| assignment
| tLET assignment
| tIMPORT {report_missing(ERROR,"do not import a library in a loop or an if-statement");switchlib();}
| tERROR string_expression {add_command(cERROR,NULL);}
| for_loop
| switch_number_or_string
| repeat_loop
| while_loop
| do_loop
| tBREAK {add_command(cBREAK,NULL);if (!in_loop) error(ERROR,"break outside loop");}
| tCONTINUE {add_command(cCONTINUE,NULL);if (!in_loop) error(ERROR,"continue outside loop");}
| function_definition
| function_or_array {create_call($1);add_command(cPOP,NULL);}
| stringfunction_or_array {create_call($1);add_command(cPOP,NULL);}
| tLOCAL {if (function_type==ftNONE) error(ERROR,"no use for 'local' outside functions");} local_list
| tSTATIC {if (function_type==ftNONE) error(ERROR,"no use for 'static' outside functions");} static_list
| if_clause
| short_if
| tGOTO symbol_or_lineno {create_goto((function_type!=ftNONE)?dotify($2,TRUE):$2);}
| tGOSUB symbol_or_lineno {create_gosub((function_type!=ftNONE)?dotify($2,TRUE):$2);}
| tON tINTERRUPT tBREAK {create_exception(TRUE);}
| tON tINTERRUPT tCONTINUE {create_exception(FALSE);}
| tON expression tGOTO {add_command(cSKIPPER,NULL);}
goto_list {add_command(cNOP,NULL);}
| tON expression tGOSUB {add_command(cSKIPPER,NULL);}
gosub_list {add_command(cNOP,NULL);}
| tLABEL symbol_or_lineno {create_label((function_type!=ftNONE)?dotify($2,TRUE):$2,cLABEL);}
| open_clause {add_command(cCHECKOPEN,NULL);}
| tCLOSE hashed_number {add_command(cCLOSE,NULL);}
| seek_clause {add_command(cCHECKSEEK,NULL);}
| tCOMPILE string_expression {add_command(cCOMPILE,NULL);}
| tEXECUTE '(' call_list ')' {create_execute(0);add_command(cPOP,NULL);add_command(cPOP,NULL);}
| tEXECUTE2 '(' call_list ')' {create_execute(1);add_command(cPOP,NULL);add_command(cPOP,NULL);}
| tPRINT printintro printlist {create_colour(0);create_print('n');create_pps(cPOPSTREAM,0);}
| tPRINT printintro printlist ';' {create_colour(0);create_pps(cPOPSTREAM,0);}
| tPRINT printintro printlist ',' {create_colour(0);create_print('t');create_pps(cPOPSTREAM,0);}
| tINPUT {tileol=FALSE;} inputbody
| tLINE tINPUT {tileol=TRUE;} inputbody
| tREAD readlist
| tDATA datalist
| tRESTORE {create_restore("");}
| tRESTORE symbol_or_lineno {create_restore((function_type!=ftNONE)?dotify($2,TRUE):$2);}
| tRESTORE string_expression {add_command(cRESTORE2, NULL);}
| tRETURN {if (get_switch_id()) create_clean_switch_mark(0,TRUE);
if (function_type!=ftNONE) {
add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;
add_command(cPOPSYMLIST,NULL);
create_retval(ftNONE,function_type);
add_command(cRET_FROM_FUN,NULL);
} else {
add_command(cRETURN,NULL);
}}
| tRETURN expression {if (get_switch_id()) create_clean_switch_mark(1,TRUE); if (function_type==ftNONE) {error(ERROR,"can not return value"); YYABORT;} add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;add_command(cPOPSYMLIST,NULL);create_retval(ftNUMBER,function_type);add_command(cRET_FROM_FUN,NULL);}
| tRETURN string_expression {if (get_switch_id()) create_clean_switch_mark(1,TRUE); if (function_type==ftNONE) {error(ERROR,"can not return value"); YYABORT;} add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;add_command(cPOPSYMLIST,NULL);create_retval(ftSTRING,function_type);add_command(cRET_FROM_FUN,NULL);}
| tDIM dimlist
/* | tOPEN tWINDOW expression ',' expression {create_openwin(FALSE);} */
| tWINDOW tOPEN coordinates to coordinates ',' string_expression ',' string_expression {create_openwin(TRUE);}
| tBUTTON coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cBUTTON,NULL);}
| tMENU string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cMENU,NULL);}
| tCHECKBOX coordinates ',' string_expression ',' string_expression ',' expression ',' string_expression {add_command(cCHECKBOX,NULL);}
| tRADIOBUTTON coordinates ',' string_expression ',' string_expression ',' expression ',' string_expression {add_command(cRADIOBUTTON,NULL);}
| tTEXTCONTROL coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression{add_command(cTEXTCONTROL,NULL);}
| tLISTBOX coordinates to coordinates ',' string_expression ',' expression ',' string_expression {add_command(cLISTBOX,NULL);}
| tLISTBOX tCLEAR string_expression {add_command(cITEMCLEAR, NULL);}
| tLISTBOX tADD string_expression ',' string_expression {add_command(cLISTBOXADD1, NULL);}
| tLISTBOX tADD string_expression ',' expression ',' string_expression {add_command(cLISTBOXADD2, NULL);}
| tDROPBOX coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cDROPBOX,NULL);}
| tDROPBOX tADD string_expression ',' string_expression {add_command(cITEMADD,NULL);}
| tDROPBOX tCLEAR string_expression {add_command(cDROPBOXCLEAR,NULL);}
| tDROPBOX tREMOVE string_expression ',' expression {add_command(cDROPBOXREMOVE,NULL);}
| tLISTBOX tREMOVE string_expression ',' string_expression {add_command(cITEMDEL,NULL);}
| tLISTBOX tREMOVE string_expression ',' expression {add_command(cLISTBOXDEL2,NULL);}
| tLISTBOX tSELECT string_expression ',' expression {add_command(cLISTBOXSELECT,NULL);}
| tALERT string_expression ',' string_expression ',' string_expression {add_command(cALERT,NULL);}
| tTEXT coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cTEXT,NULL);}
| tTEXT coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cTEXT2, NULL);}
| tTEXT tSET string_expression ',' string_expression {add_command(cTEXTALIGN,NULL);}
| tLOCALIZE {add_command(cLOCALIZE,NULL);}
| tLOCALIZE string_expression {add_command(cLOCALIZE2,NULL);}
| tLOCALIZE tSTOP {add_command(cLOCALIZESTOP, NULL);}
| tDRAW tTEXT coordinates ',' string_expression ',' string_expression {add_command(cDRAWTEXT,NULL);}
| tDRAW tRECT coordinates to coordinates ',' string_expression {add_command(cDRAWRECT,NULL);}
| tDRAW tFLUSH string_expression {add_command(cDRAWCLEAR,NULL);}
| tWINDOW tCLOSE string_expression {add_command(cCLOSEWIN,NULL);}
| tLAYOUT string_expression ',' string_expression {add_command(cLAYOUT,NULL);}
| tWINDOW tSET string_expression ',' string_expression {add_command(cWINSET4,NULL);}
| tWINDOW tSET string_expression ',' string_expression ',' string_expression {add_command(cWINSET1,NULL);}
| tWINDOW tSET string_expression ',' string_expression ',' expression ',' expression {add_command(cWINSET3,NULL);}
/*
| tWINDOW tSET string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cWINSET2,NULL);}
this tWINDOW tSET was replaced by tDRAW tSET ... cWINSET2
tWINDOW tCLEAR string_expression {add_command(cWINCLEAR,NULL);}*/
| tSHORTCUT string_expression ',' string_expression ',' string_expression {add_command(cSHORTCUT,NULL);}
| tTEXTEDIT coordinates to coordinates ',' string_expression ',' expression ',' string_expression {add_command(cTEXTEDIT,NULL);}
| tTEXTEDIT tADD string_expression ',' string_expression {add_command(cTEXTADD,NULL);}
| tTEXTEDIT tSET string_expression ',' string_expression {add_command(cTEXTSET,NULL);}
| tTEXTEDIT tSET string_expression ',' string_expression ',' expression {add_command(cTEXTSET2,NULL);}
| tTEXTEDIT tSET string_expression ',' string_expression ',' string_expression {add_command(cTEXTSET3,NULL);}
| tTEXTEDIT tCOLOUR string_expression ',' string_expression ',' string_expression {add_command(cTEXTCOLOR1,NULL);}
| tTEXTEDIT tCOLOUR string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cTEXTCOLOR2,NULL);}
| tTEXTEDIT tCLEAR string_expression {add_command(cTEXTCLEAR,NULL);}
| tDRAW tSET string_expression ',' string_expression {add_command(cDRAWSET1,NULL);}
| tDRAW tSET expression ',' string_expression {add_command(cDRAWSET2,NULL);}
| tDRAW tSET string_expression ',' expression ',' expression ',' expression ',' string_expression {add_command(cWINSET2,NULL);}
| tDRAW tSET string_expression ',' expression {add_command(cDRAWSET3,NULL);}
| tDRAW tSET string_expression ',' string_expression ',' string_expression {add_command(cDRAWSET4,NULL);}
| tVIEW coordinates to coordinates ',' string_expression ',' string_expression {add_command(cVIEW,NULL);}
| tVIEW tREMOVE string_expression {add_command(cWINCLEAR,NULL);}
| tBOXVIEW coordinates to coordinates ',' string_expression ',' string_expression ',' expression ',' string_expression {add_command(cBOXVIEW,NULL);}
| tBOXVIEW tSET string_expression ',' string_expression ',' string_expression {add_command(cBOXVIEWSET,NULL);}
| tTABVIEW coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cTAB,NULL);}
| tTABVIEW tSET string_expression ',' expression {add_command(cTABSET,NULL);}
| tTABVIEW tADD string_expression ',' string_expression {add_command(cTABADD, NULL);}
| tTABVIEW tREMOVE string_expression ',' expression {add_command(cTABDEL, NULL);}
| tDRAW tDOT coordinates ',' string_expression {add_command(cDOT,NULL);}
| tDRAW tLINE coordinates to coordinates ',' string_expression {add_command(cLINE,NULL);}
| tDRAW tCIRCLE coordinates ',' expression ',' string_expression {add_command(cCIRCLE,NULL);}
| tDRAW tELLIPSE coordinates ',' expression ',' expression ',' string_expression {add_command(cELLIPSE,NULL);}
| tDRAW tCURVE coordinates ',' coordinates ',' coordinates ',' coordinates ',' string_expression {add_command(cCURVE,NULL);}
| tSLIDER coordinates to coordinates ',' string_expression ',' string_expression ',' expression ',' expression ',' string_expression {add_command(cSLIDER1,NULL);}
| tSLIDER coordinates to coordinates ',' string_expression ',' string_expression ',' expression ',' expression ',' string_expression ',' string_expression {add_command(cSLIDER2,NULL);}
| tSLIDER tLABEL string_expression ',' string_expression ',' string_expression {add_command(cSLIDER3,NULL);}
| tSLIDER tSET string_expression ',' string_expression ',' expression {add_command(cSLIDER4,NULL);}
| tSLIDER tCOLOUR string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cSLIDER5,NULL);}
| tSLIDER tSET string_expression ',' expression {add_command(cSLIDER6,NULL);}
| tLAUNCH string_expression {add_command(cLAUNCH,NULL);}
| tOPTION tSET string_expression ',' string_expression ',' string_expression {add_command(cOPTION1,NULL);}
| tOPTION tCOLOUR string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cOPTION2,NULL);}
/*
| tOPTION tRESIZE string_expression ',' coordinates to coordinates {add_command(cOPTION3,NULL);}
*/
| tOPTION tSET string_expression ',' string_expression {add_command(cOPTION4,NULL);}
| tOPTION tSET string_expression ',' string_expression ',' expression {add_command(cOPTION5,NULL);}
| tOPTION tSET string_expression ',' string_expression ',' expression ',' expression {add_command(cOPTION3,NULL);}
| tBITMAP coordinates ',' string_expression {add_command(cBITMAP,NULL);}
| tBITMAP tGETNUM coordinates to coordinates ',' string_expression ',' string_expression {add_command(cBITMAPGET, NULL);}
| tBITMAP tGETNUM expression ',' string_expression ',' string_expression {add_command(cBITMAPGET2, NULL);}
| tBITMAP tGETNUM string_expression ',' string_expression ',' string_expression {add_command(cBITMAPGETICON, NULL);}
| tDRAW tBITMAP coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cBITMAPDRAW,NULL);}
| tDRAW tBITMAP coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cBITMAPDRAW2,NULL);}
/*
| tCANVAS tDRAG string_expression {add_command(cBITMAPDRAG,NULL);}
*/
| tBITMAP tREMOVE string_expression {add_command(cBITMAPREMOVE,NULL);}
| tSCREENSHOT coordinates to coordinates ',' string_expression {add_command(cSCREENSHOT,NULL);}
| tCANVAS coordinates to coordinates ',' string_expression ',' string_expression {add_command(cCANVAS,NULL);}
| tVIEW tDROPZONE string_expression {add_command(cDROPZONE,NULL);}
| tCOLORCONTROL coordinates ',' string_expression ',' string_expression {add_command(cCOLORCONTROL1,NULL);}
| tCOLORCONTROL tSET string_expression ',' expression ',' expression ',' expression {add_command(cCOLORCONTROL2,NULL);}
| tTEXTCONTROL tSET string_expression ',' string_expression {add_command(cTEXTCONTROL2,NULL);}
| tTEXTCONTROL tSET string_expression ',' expression {add_command(cTEXTCONTROL3,NULL);}
| tTEXTCONTROL tSET string_expression ',' string_expression ',' string_expression {add_command(cTEXTCONTROL4,NULL);}
| tTEXTCONTROL tCLEAR string_expression {add_command(cTEXTCONTROL5,NULL);}
| tTREEBOX coordinates to coordinates ',' string_expression ',' expression ',' string_expression {add_command(cTREEBOX1,NULL);}
| tTREEBOX tADD string_expression ',' string_expression {add_command(cTREEBOX2,NULL);}
| tTREEBOX tADD string_expression ',' string_expression ',' string_expression ',' expression {add_command(cTREEBOX3,NULL);}
| tTREEBOX tADD string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cTREEBOX13,NULL);}
| tTREEBOX tADD string_expression ',' string_expression ',' expression {add_command(cTREEBOX12,NULL);}
| tTREEBOX tCLEAR string_expression {add_command(cTREEBOX4,NULL);}
| tTREEBOX tREMOVE string_expression ',' string_expression {add_command(cTREEBOX5,NULL);}
| tTREEBOX tSELECT string_expression ',' expression {add_command(cTREEBOX7,NULL);}
| tTREEBOX tREMOVE string_expression ',' expression {add_command(cTREEBOX8,NULL);}
| tTREEBOX tREMOVE string_expression ',' string_expression ',' string_expression {add_command(cTREEBOX9,NULL);}
| tTREEBOX tEXPAND string_expression ',' string_expression {add_command(cTREEBOX10,NULL);}
| tTREEBOX tCOLLAPSE string_expression ',' string_expression {add_command(cTREEBOX11,NULL);}
| tBUTTON tIMAGE coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cBUTTONIMAGE,NULL);}
| tCHECKBOX tIMAGE coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression ',' string_expression ',' expression ',' string_expression {add_command(cCHECKBOXIMAGE,NULL);}
| tCHECKBOX tSET string_expression ',' expression {add_command(cCHECKBOXSET,NULL);}
| tRADIOBUTTON tSET string_expression ',' expression {add_command(cRADIOSET,NULL);}
| tTOOLTIP string_expression ',' string_expression {add_command(cTOOLTIP,NULL);}
| tTOOLTIP tCOLOUR string_expression ',' expression ',' expression ',' expression {add_command(cTOOLTIPCOLOR,NULL);}
| tLISTBOX tSORT string_expression {add_command(cLISTSORT,NULL);}
| tTREEBOX tSORT string_expression {add_command(cTREESORT,NULL);}
| tCOLUMNBOX coordinates to coordinates ',' string_expression ',' expression ',' string_expression ',' string_expression {add_command(cFILEBOX,NULL);}
| tCOLUMNBOX tADD string_expression ',' expression ',' expression ',' expression ',' string_expression {add_command(cCOLUMNBOXADD,NULL);}
| tCOLUMNBOX tCOLUMN string_expression ',' string_expression ',' expression ',' expression ',' expression ',' expression ',' string_expression {add_command(cFILEBOXADD2,NULL);}
| tCOLUMNBOX tCLEAR string_expression {add_command(cFILEBOXCLEAR,NULL);}
| tCOLUMNBOX tREMOVE string_expression ',' expression {add_command(cCOLUMNBOXREMOVE,NULL);}
| tCOLUMNBOX tSELECT string_expression ',' expression {add_command(cCOLUMNBOXSELECT,NULL);}
| tCOLUMNBOX tCOLOUR string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cCOLUMNBOXCOLOR,NULL);}
| tCALENDAR coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cCALENDAR,NULL);}
| tCALENDAR tSET string_expression ',' string_expression {add_command(cCALENDARSET,NULL);}
| tSCROLLBAR string_expression ',' expression ',' string_expression {add_command(cSCROLLBAR,NULL);}
| tSCROLLBAR tSET string_expression ',' string_expression ',' expression {add_command(cSCROLLBARSET1,NULL);}
| tSCROLLBAR tSET string_expression ',' string_expression ',' expression ',' expression {add_command(cSCROLLBARSET2,NULL);}
| tSCROLLBAR tSET string_expression ',' string_expression {add_command(cSCROLLBARSET3,NULL);}
| tDROPBOX tSELECT string_expression ',' expression {add_command(cDROPBOXSELECT,NULL);}
| tMENU tSET string_expression ',' expression ',' string_expression {add_command(cMENU2,NULL);}
| tMENU tSET string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cMENU3,NULL);}
| tSUBMENU string_expression ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cSUBMENU1,NULL);}
| tSUBMENU tSET string_expression ',' string_expression ',' expression ',' string_expression {add_command(cSUBMENU2,NULL);}
| tSUBMENU tSET string_expression ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cSUBMENU3,NULL);}
| tSTATUSBAR coordinates to coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cSTATUSBAR,NULL);}
| tSTATUSBAR tSET string_expression ',' string_expression ',' string_expression ',' expression {add_command(cSTATUSBARSET,NULL);}
| tSTATUSBAR tSET string_expression ',' expression ',' expression ',' expression {add_command(cSTATUSBARSET3,NULL);}
| tSPINCONTROL coordinates ',' string_expression ',' string_expression ',' expression ',' expression ',' expression ',' string_expression {add_command(cSPINCONTROL1,NULL);}
| tSPINCONTROL tSET string_expression ',' expression {add_command(cSPINCONTROL2,NULL);}
| tCLIPBOARD tCOPY string_expression {add_command(cCLIPBOARDCOPY,NULL);}
| tPRINTER tSETUP string_expression {add_command(cPRINTERCONFIG,NULL);}
| tMOUSE tSET string_expression {add_command(cMOUSESET,NULL);}
| tSOUND tSTOP expression {add_command(cSOUNDSTOP,NULL);}
| tSOUND tSTOP '(' expression ')' {add_command(cSOUNDSTOP,NULL);}
| tSOUND tWAIT expression {add_command(cSOUNDWAIT,NULL);}
| tSOUND tWAIT '(' expression ')' {add_command(cSOUNDWAIT,NULL);}
| tSPLITVIEW coordinates to coordinates ',' string_expression ',' expression ',' expression ',' string_expression {add_command(cSPLITVIEW1,NULL);}
| tSPLITVIEW tSET string_expression ',' string_expression ',' expression {add_command(cSPLITVIEW2,NULL);}
| tSPLITVIEW tSET string_expression ',' string_expression ',' expression ',' expression {add_command(cSPLITVIEW3,NULL);}
| tSTACKVIEW coordinates to coordinates ',' string_expression ',' expression ',' string_expression {add_command(cSTACKVIEW1,NULL);}
| tSTACKVIEW tSET string_expression ',' expression {add_command(cSTACKVIEW2,NULL);}
| tTEXTURL coordinates ',' string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cTEXTURL1, NULL);}
| tTEXTURL tCOLOUR string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cTEXTURL2, NULL);}
| tATTRIBUTE tSET string_expression ',' string_expression ',' string_expression ',' string_expression {add_command(cATTRIBUTE1, NULL);}
| tATTRIBUTE tCLEAR string_expression ',' string_expression {add_command(cATTRIBUTECLEAR, NULL);}
| tPUTCHAR string_expression to expression ',' expression {add_command(cPUTCHAR,NULL);}
| tCLEAR tSCREEN {add_command(cCLEARSCR,NULL);}
| tWAIT expression {add_command(cWAIT,NULL);}
| tBELL {add_command(cBELL,NULL);}
| tINKEY {create_pushdbl(-1);create_function(fINKEY);add_command(cPOP,NULL);}
| tINKEY '(' ')' {create_pushdbl(-1);create_function(fINKEY);add_command(cPOP,NULL);}
| tINKEY '(' expression ')' {create_function(fINKEY);add_command(cPOP,NULL);}
| tSYSTEM2 '(' string_expression ')' {create_function(fSYSTEM2);
add_command(cPOP,NULL);}
| tPOKE string_expression ',' string_expression {create_poke('s');}
| tPOKE string_expression ',' expression {create_poke('d');}
| tPOKE hashed_number ',' string_expression {create_poke('S');}
| tPOKE hashed_number ',' expression {create_poke('D');}
| tEND {add_command(cEND,NULL);}
| tEXIT {create_pushdbl(0);add_command(cEXIT,NULL);}
| tEXIT expression {add_command(cEXIT,NULL);}
| tDOCU {create_docu($1);}
| tBIND string_expression {add_command(cBIND,NULL);}
;
/*
clear_fill_clause: * empty * {drawmode=0;}
| tCLEAR {drawmode=dmCLEAR;}
| tFILL {drawmode=dmFILL;}
| tCLEAR tFILL {drawmode=dmFILL+dmCLEAR;}
| tFILL tCLEAR {drawmode=dmFILL+dmCLEAR;}
;*/
string_assignment: tSTRSYM tEQU string_expression {add_command(cPOPSTRSYM,dotify($1,FALSE));}
| tMID '(' string_scalar_or_array ',' expression ',' expression ')' tEQU string_expression {create_changestring(fMID);}
| tMID '(' string_scalar_or_array ',' expression ')' tEQU string_expression {create_changestring(fMID2);}
| tLEFT '(' string_scalar_or_array ',' expression ')' tEQU string_expression {create_changestring(fLEFT);}
| tRIGHT '(' string_scalar_or_array ',' expression ')' tEQU string_expression {create_changestring(fRIGHT);}
| stringfunction_or_array tEQU string_expression {create_doarray(dotify($1,FALSE),ASSIGNSTRINGARRAY);}
;
to: ','
| tTO
;
open_clause: tOPEN hashed_number ',' string_expression ',' string_expression {create_myopen(OPEN_HAS_STREAM+OPEN_HAS_MODE);}
| tOPEN hashed_number ',' string_expression {create_myopen(OPEN_HAS_STREAM);}
/* | tOPEN hashed_number ',' tPRINTER {create_myopen(OPEN_HAS_STREAM+OPEN_PRINTER);} */
| tOPEN string_expression tFOR tREADING tAS hashed_number {add_command(cSWAP,NULL);create_pushstr("r");create_myopen(OPEN_HAS_STREAM+OPEN_HAS_MODE);}
| tOPEN string_expression tFOR tWRITING tAS hashed_number {add_command(cSWAP,NULL);create_pushstr("w");create_myopen(OPEN_HAS_STREAM+OPEN_HAS_MODE);}
;
seek_clause: tSEEK hashed_number ',' expression {add_command(cSEEK,NULL);}
| tSEEK hashed_number ',' expression ',' string_expression {add_command(cSEEK2,NULL);}
;
string_scalar_or_array: tSTRSYM {add_command(cPUSHSTRPTR,dotify($1,FALSE));}
| tSTRSYM '(' call_list ')' {create_doarray(dotify($1,FALSE),GETSTRINGPOINTER);}
;
string_expression: tSTRSYM {add_command(cPUSHSTRSYM,dotify($1,FALSE));}
| string_function
| stringfunction_or_array {add_command(cSTRINGFUNCTION_OR_ARRAY,$1);}
| tSTRING {if ($1==NULL) {error(ERROR,"String not terminated");create_pushstr("");} else {create_pushstr($1);}}
| string_expression '+' string_expression {add_command(cCONCAT,NULL);}
| '(' string_expression ')'
;
string_function: tLEFT '(' string_expression ',' expression ')' {create_function(fLEFT);}
| tRIGHT '(' string_expression ',' expression ')' {create_function(fRIGHT);}
| tMID '(' string_expression ',' expression ',' expression ')' {create_function(fMID);}
| tMID '(' string_expression ',' expression ')' {create_function(fMID2);}
| tSTR '(' expression ')' {create_function(fSTR);}
| tSTR '(' expression ',' string_expression ')' {create_function(fSTR2);}
| tSTR '(' expression ',' string_expression ',' string_expression ')' {create_function(fSTR3);}
| tINKEY {create_pushdbl(-1);create_function(fINKEY);}
| tINKEY '(' ')' {create_pushdbl(-1);create_function(fINKEY);}
| tINKEY '(' expression ')' {create_function(fINKEY);}
| tCHR '(' expression ')' {create_function(fCHR);}
| tUPPER '(' string_expression ')' {create_function(fUPPER);}
| tLOWER '(' string_expression ')' {create_function(fLOWER);}
| tLTRIM '(' string_expression ')' {create_function(fLTRIM);}
| tRTRIM '(' string_expression ')' {create_function(fRTRIM);}
| tTRIM '(' string_expression ')' {create_function(fTRIM);}
| tSYSTEM '(' string_expression ')' {create_function(fSYSTEM);}
| tDATE {create_function(fDATE);}
| tDATE '(' ')' {create_function(fDATE);}
| tTIME {create_function(fTIME);}
| tTIME '(' ')' {create_function(fTIME);}
| tPEEK2 '(' string_expression ')' {create_function(fPEEK2);}
| tPEEK2 '(' string_expression ',' string_expression ')' {create_function(fPEEK3);}
| tTOKENALT '(' string_scalar_or_array ',' string_expression ')' {add_command(cTOKENALT2,NULL);}
| tTOKENALT '(' string_scalar_or_array ')' {add_command(cTOKENALT,NULL);}
| tSPLITALT '(' string_scalar_or_array ',' string_expression ')' {add_command(cSPLITALT2,NULL);}
| tSPLITALT '(' string_scalar_or_array ')' {add_command(cSPLITALT,NULL);}
| tGETCHAR '(' expression ',' expression to expression ',' expression ')' {create_function(fGETCHAR);}
| tHEX '(' expression ')' {create_function(fHEX);}
| tBIN '(' expression ')' {create_function(fBIN);}
| tEXECUTE2 '(' call_list ')' {create_execute(1);add_command(cSWAP,NULL);add_command(cPOP,NULL);}
| tMESSAGE {create_function(fMESSAGE);}
| tMESSAGE '(' ')' {create_function(fMESSAGE);}
| tMOUSE tMESSAGE {create_function(fMOUSEMOVE);}
| tMOUSE tMESSAGE '(' ')' {create_function(fMOUSEMOVE);}
| tTRANSLATE '(' string_expression ')' {create_function(fTRANSLATE);}
| tMENU tTRANSLATE '(' string_expression ')' {create_function(fMENUTRANSLATE);}
| tTEXTEDIT tGET string_expression {create_function(fTEXTGET);}
| tTEXTEDIT tGET string_expression ',' expression {create_function(fTEXTGET3);}
| tTEXTEDIT tGET string_expression ',' string_expression {create_function(fTEXTGET6);}
| tTEXTCONTROL tGET string_expression {create_function(fTEXTCONTROLGET);}
| tFILEPANEL string_expression ',' string_expression ',' string_expression {create_function(fLOAD);}
| tFILEPANEL string_expression ',' string_expression ',' string_expression ',' string_expression {create_function(fSAVE);}
| tMOUSE tMESSAGE string_expression {create_function(fMOUSE);}
//| tMOUSE tMESSAGE '(' string_expression ')' {create_function(fMOUSE);}
| tKEYBOARD tMESSAGE string_expression {create_function(fKEYBOARD);}
//| tKEYBOARD tMESSAGE '(' string_expression ')' {create_function(fKEYBOARD);}
| tCLIPBOARD tPASTE {create_function(fCLIPBOARDPASTE);}
| tCOLUMNBOX tGET string_expression ',' expression ',' expression {create_function(fCOLUMNBOXGET);}
| tCALENDAR tGET string_expression {create_function(fCALENDAR);}
| tLISTBOX tGET string_expression ',' expression {create_function(fLISTBOXGET);}
| tTREEBOX tGET string_expression ',' expression {create_function(fTREEBOXGET);}
| tPOPUPMENU coordinates ',' string_expression ',' string_expression {create_function(fPOPUPMENU);}
| tDROPBOX tGET string_expression ',' expression {create_function(fDROPBOXGET);}
| tDRAW tGET string_expression {create_function(fDRAWGET3);}
| tATTRIBUTE tGET string_expression ',' string_expression {create_function(fATTRIBUTEGET1);}
;
assignment: tSYMBOL tEQU expression {add_command(cPOPDBLSYM,dotify($1,FALSE));}
| function_or_array tEQU expression {create_doarray($1,ASSIGNARRAY);}
;
expression: expression tOR {add_command(cORSHORT,NULL);pushlabel();} expression {poplabel();create_boole('|');}
| expression tAND {add_command(cANDSHORT,NULL);pushlabel();} expression {poplabel();create_boole('&');}
| tNOT expression {create_boole('!');}
| expression tEQU expression {create_dblrelop('=');}
| expression tNEQ expression {create_dblrelop('!');}
| expression tLTN expression {create_dblrelop('<');}
| expression tLEQ expression {create_dblrelop('{');}
| expression tGTN expression {create_dblrelop('>');}
| expression tGEQ expression {create_dblrelop('}');}
| tMYEOF '(' hashed_number ')' {add_command(cTESTEOF,NULL);}
| tGLOB '(' string_expression ',' string_expression ')' {add_command(cGLOB,NULL);}
| number {create_pushdbl($1);}
| tARDIM '(' arrayref ')' {add_command(cARDIM,"");}
| tARDIM '(' string_arrayref ')' {add_command(cARDIM,"");}
| tARSIZE '(' arrayref ',' expression ')' {add_command(cARSIZE,"");}
| tARSIZE '(' string_arrayref ',' expression ')' {add_command(cARSIZE,"");}
| function_or_array {add_command(cFUNCTION_OR_ARRAY,$1);}
| tSYMBOL {add_command(cPUSHDBLSYM,dotify($1,FALSE));}
| expression '+' expression {create_dblbin('+');}
| expression '-' expression {create_dblbin('-');}
| expression '*' expression {create_dblbin('*');}
| expression '/' expression {create_dblbin('/');}
| expression tPOW expression {create_dblbin('^');}
| '-' expression %prec UMINUS {add_command(cNEGATE,NULL);}
| string_expression tEQU string_expression {create_strrelop('=');}
| string_expression tNEQ string_expression {create_strrelop('!');}
| string_expression tLTN string_expression {create_strrelop('<');}
| string_expression tLEQ string_expression {create_strrelop('{');}
| string_expression tGTN string_expression {create_strrelop('>');}
| string_expression tGEQ string_expression {create_strrelop('}');}
| function
| '(' expression ')'
;
arrayref: tSYMBOL '(' ')' {create_pusharrayref(dotify($1,FALSE),stNUMBERARRAYREF);}
;
string_arrayref: tSTRSYM '(' ')' {create_pusharrayref(dotify($1,FALSE),stSTRINGARRAYREF);}
;
coordinates: expression ',' expression
;
function: tSIN '(' expression ')' {create_function(fSIN);}
| tASIN '(' expression ')' {create_function(fASIN);}
| tCOS '(' expression ')' {create_function(fCOS);}
| tACOS '(' expression ')' {create_function(fACOS);}
| tTAN '(' expression ')' {create_function(fTAN);}
| tATAN '(' expression ')' {create_function(fATAN);}
| tATAN '(' expression ',' expression ')' {create_function(fATAN2);}
| tEXP '(' expression ')' {create_function(fEXP);}
| tLOG '(' expression ')' {create_function(fLOG);}
| tLOG '(' expression ',' expression ')' {create_function(fLOG2);}
| tSQRT '(' expression ')' {create_function(fSQRT);}
| tSQR '(' expression ')' {create_function(fSQR);}
| tINT '(' expression ')' {create_function(fINT);}
| tFRAC '(' expression ')' {create_function(fFRAC);}
| tABS '(' expression ')' {create_function(fABS);}
| tSIG '(' expression ')' {create_function(fSIG);}
| tMOD '(' expression ',' expression ')' {create_function(fMOD);}
| tRAN '(' expression ')' {create_function(fRAN);}
| tRAN '(' ')' {create_function(fRAN2);}
| tMIN '(' expression ',' expression ')' {create_function(fMIN);}
| tMAX '(' expression ',' expression ')' {create_function(fMAX);}
| tLEN '(' string_expression ')' {create_function(fLEN);}
| tVAL '(' string_expression ')' {create_function(fVAL);}
| tASC '(' string_expression ')' {create_function(fASC);}
| tDEC '(' string_expression ')' {create_function(fDEC);}
| tDEC '(' string_expression ',' expression ')' {create_function(fDEC2);}
| tINSTR '(' string_expression ',' string_expression ')' {if (check_compat) error(WARNING,"instr() has changed in version 2.712"); create_function(fINSTR);}
| tINSTR '(' string_expression ',' string_expression ',' expression ')' {create_function(fINSTR2);}
| tRINSTR '(' string_expression ',' string_expression ')' {create_function(fRINSTR);}
| tRINSTR '(' string_expression ',' string_expression ',' expression ')' {create_function(fRINSTR2);}
| tSYSTEM2 '(' string_expression ')' {create_function(fSYSTEM2);}
| tPEEK '(' hashed_number ')' {create_function(fPEEK4);}
| tPEEK '(' string_expression ')' {create_function(fPEEK);}
/*
| tMOUSEX '(' string_expression ')' {create_function(fMOUSEX);}
| tMOUSEX {create_pushstr("");create_function(fMOUSEX);}
| tMOUSEX '(' ')' {create_pushstr("");create_function(fMOUSEX);}
| tMOUSEY '(' string_expression ')' {create_function(fMOUSEY);}
| tMOUSEY {create_pushstr("");create_function(fMOUSEY);}
| tMOUSEY '(' ')' {create_pushstr("");create_function(fMOUSEY);}
| tMOUSEB '(' string_expression ')' {create_function(fMOUSEB);}
| tMOUSEB {create_pushstr("");create_function(fMOUSEB);}
| tMOUSEB '(' ')' {create_pushstr("");create_function(fMOUSEB);}
| tMOUSEMOD '(' string_expression ')' {create_function(fMOUSEMOD);}
| tMOUSEMOD {create_pushstr("");create_function(fMOUSEMOD);}
| tMOUSEMOD '(' ')' {create_pushstr("");create_function(fMOUSEMOD);}*/
| tAND '(' expression ',' expression ')' {create_function(fAND);}
| tOR '(' expression ',' expression ')' {create_function(fOR);}
| tEOR '(' expression ',' expression ')' {create_function(fEOR);}
| tTELL '(' hashed_number ')' {create_function(fTELL);}
| tTOKEN '(' string_expression ',' string_arrayref ',' string_expression ')' {add_command(cTOKEN2,NULL);}
| tTOKEN '(' string_expression ',' string_arrayref ')' {add_command(cTOKEN,NULL);}
| tSPLIT '(' string_expression ',' string_arrayref ',' string_expression ')' {add_command(cSPLIT2,NULL);}
| tSPLIT '(' string_expression ',' string_arrayref ')' {add_command(cSPLIT,NULL);}
| tEXECUTE '(' call_list ')' {create_execute(0);add_command(cSWAP,NULL);add_command(cPOP,NULL);}
| tOPEN '(' string_expression ')' {create_myopen(0);}
| tOPEN '(' string_expression ',' string_expression ')' {create_myopen(OPEN_HAS_MODE);}
| tOPEN '(' hashed_number ',' string_expression ')' {create_myopen(OPEN_HAS_STREAM);}
| tOPEN '(' hashed_number ',' string_expression ',' string_expression ')' {create_myopen(OPEN_HAS_STREAM+OPEN_HAS_MODE);}
| tDRAW tIMAGE expression ',' expression ',' string_expression ',' string_expression {create_function(fDRAWIMAGE);}
| tDRAW tIMAGE coordinates to coordinates ',' string_expression ',' string_expression {create_function(fDRAWIMAGE2);}
| tSVG coordinates to coordinates ',' string_expression ',' string_expression {create_function(fDRAWSVG);}
| tWINDOW tCOUNT {create_function(fNUMWINDOWS);}
// | tISMOUSEIN '(' string_expression ')' {create_function(fISMOUSEIN);}
| tISMOUSEIN string_expression {create_function(fISMOUSEIN);}
| tCOLUMNBOX tCOUNT string_expression {create_function(fCOLUMNBOXCOUNT);}
| tWINDOW tGETNUM string_expression ',' string_expression {create_function(fWINDOWGET);}
| tVIEW tGETNUM string_expression ',' string_expression {create_function(fVIEWGET);}
| tALERT string_expression ',' string_expression ',' string_expression ',' string_expression ',' string_expression {create_function(fALERT);}
| tLISTBOX tCOUNT string_expression {create_function(fLISTBOXCOUNT);}
| tTREEBOX tCOUNT string_expression {create_function(fTREEBOXCOUNT);}
| tSCROLLBAR tGETNUM string_expression ',' string_expression {create_function(fSCROLLBARGET);}
| tSPLITVIEW tGETNUM string_expression ',' string_expression {create_function(fSPLITVIEWGET);}
| tSTACKVIEW tGETNUM string_expression {create_function(fSTACKVIEWGET);}
| tTABVIEW tGETNUM string_expression {create_function(fTABVIEWGET);}
| tSPINCONTROL tGETNUM string_expression {create_function(fSPINCONTROLGET);}
| tDROPBOX tCOUNT string_expression {create_function(fDROPBOXCOUNT);}
| tSLIDER tGETNUM string_expression {create_function(fSLIDERGET);}
| tCOLORCONTROL tGETNUM string_expression ',' string_expression {create_function(fCOLORCONTROLGET);}
| tTEXTEDIT tGETNUM string_expression ',' string_expression {create_function(fTEXTGET2);}
| tTEXTEDIT tGETNUM string_expression ',' string_expression ',' expression {create_function(fTEXTGET4);}
| tTEXTEDIT tGETNUM string_expression ',' string_expression ',' string_expression {create_function(fTEXTGET5);}
| tDRAW tGETNUM string_expression ',' string_expression ',' string_expression {create_function(fDRAWGET1);}
| tDRAW tGETNUM string_expression ',' string_expression {create_function(fDRAWGET2);}
| tDRAW tGETNUM coordinates ',' string_expression ',' string_expression {create_function(fDRAWGET4);}
| tNUMMESSAGE tMSEND string_expression ',' string_expression {create_function(fMESSAGESEND);}
| tTHREAD tREMOVE string_expression ',' expression {create_function(fTHREADKILL);}
| tTHREAD tGETNUM string_expression ',' string_expression {create_function(fTHREADGET);}
| tPRINTER string_expression ',' string_expression ',' string_expression {create_function(fPRINTER);}
| tSOUND tPLAY string_expression {create_function(fSOUND);}
| tISCOMPUTERON {create_function(fISCOMPUTERON);}
| tLISTBOX tGETNUM string_expression {create_function(fLISTBOXGETNUM);}
| tDROPBOX tGETNUM string_expression {create_function(fDROPBOXGETNUM);}
| tTREEBOX tGETNUM string_expression {create_function(fTREEBOXGETNUM);}
| tCOLUMNBOX tGETNUM string_expression {create_function(fCOLUMNBOXGETNUM);}
| tTREEBOX tGETNUM string_expression ',' string_expression ',' expression {create_function(fTREEBOXGETOPT);}
| tBITMAP tSAVE string_expression ',' string_expression ',' string_expression {create_function(fBITMAPSAVE);}
| tBITMAP tIMAGE string_expression ',' string_expression {create_function(fBITMAPLOAD);}
| tBITMAP tGETNUM string_expression ',' string_expression {create_function(fBITMAPGET);}
| tBITMAP tCOLOUR expression ',' expression ',' string_expression ',' string_expression {create_function(fBITMAPCOLOR);}
| tATTRIBUTE tGETNUM string_expression ',' string_expression {create_function(fATTRIBUTEGET2);}
;
const: number {$$=$1;}
| '+' number {$$=$2;}
| '-' number {$$=-$2;}
;
number: tFNUM {$$=$1;}
| tDIGITS {$$=strtod($1,NULL);}
;
symbol_or_lineno: tDIGITS {$$=my_strdup(dotify($1,FALSE));}
| tSYMBOL {$$=my_strdup(dotify($1,FALSE));}
;
dimlist: tSYMBOL '(' call_list ')' {create_dim(dotify($1,FALSE),'D');}
| dimlist ',' tSYMBOL '(' call_list ')' {create_dim(dotify($3,FALSE),'D');}
| tSTRSYM '(' call_list ')' {create_dim(dotify($1,FALSE),'S');}
| dimlist ',' tSTRSYM '(' call_list ')' {create_dim(dotify($3,FALSE),'S');}
;
function_or_array: tSYMBOL '(' call_list ')' {$$=my_strdup(dotify($1,FALSE));}
;
stringfunction_or_array: tSTRSYM '(' call_list ')' {$$=my_strdup(dotify($1,FALSE));}
;
call_list: {add_command(cPUSHFREE,NULL);} calls
;
calls: /* empty */
| call_item
| calls ',' call_item
;
call_item: string_expression
| expression
;
function_definition: export tSUB {missing_endsub++;missing_endsub_line=mylineno;pushlabel();report_missing(WARNING,"do not define a function in a loop or an if-statement");if (function_type!=ftNONE) {error(ERROR,"nested functions not allowed");YYABORT;}}
function_name {if (exported) create_sublink($4); create_label($4,cUSER_FUNCTION);
add_command(cPUSHSYMLIST,NULL);add_command(cCLEARREFS,NULL);firstref=lastref=lastcmd;
create_numparam();}
'(' paramlist ')' {create_require(stFREE);add_command(cPOP,NULL);}
statement_list
endsub {add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;add_command(cPOPSYMLIST,NULL);create_retval(ftNONE,function_type);function_type=ftNONE;add_command(cRET_FROM_FUN,NULL);lastref=NULL;create_endfunction();poplabel();}
;
endsub: tEOPROG {if (missing_endsub) {sprintf(string,"%d end-sub(s) are missing (last at line %d)",missing_endsub,missing_endsub_line);error(ERROR,string);} YYABORT;}
| tENDSUB {missing_endsub--;}
;
function_name: tSYMBOL {function_type=ftNUMBER;current_function=my_strdup(dotify($1,FALSE));$$=my_strdup(dotify($1,FALSE));}
| tSTRSYM {function_type=ftSTRING;current_function=my_strdup(dotify($1,FALSE));$$=my_strdup(dotify($1,FALSE));}
;
export: /* empty */ {exported=FALSE;}
| tEXPORT {exported=TRUE;}
| tRUNTIME_CREATED_SUB {exported=FALSE;}
| tRUNTIME_CREATED_SUB tEXPORT {exported=TRUE;}
;
local_list: local_item
| local_list ',' local_item
;
local_item: tSYMBOL {create_makelocal(dotify($1,FALSE),syNUMBER);}
| tSTRSYM {create_makelocal(dotify($1,FALSE),sySTRING);}
| tSYMBOL '(' call_list ')' {create_makelocal(dotify($1,FALSE),syARRAY);create_dim(dotify($1,FALSE),'d');}
| tSTRSYM '(' call_list ')' {create_makelocal(dotify($1,FALSE),syARRAY);create_dim(dotify($1,FALSE),'s');}
;
static_list: static_item
| static_list ',' static_item
;
static_item: tSYMBOL {create_makestatic(dotify($1,TRUE),syNUMBER);}
| tSTRSYM {create_makestatic(dotify($1,TRUE),sySTRING);}
| tSYMBOL '(' call_list ')' {create_makestatic(dotify($1,TRUE),syARRAY);create_dim(dotify($1,TRUE),'D');}
| tSTRSYM '(' call_list ')' {create_makestatic(dotify($1,TRUE),syARRAY);create_dim(dotify($1,TRUE),'S');}
;
paramlist: /* empty */
| paramitem
| paramlist ',' paramitem
;
paramitem: tSYMBOL {create_require(stNUMBER);create_makelocal(dotify($1,FALSE),syNUMBER);add_command(cPOPDBLSYM,dotify($1,FALSE));}
| tSTRSYM {create_require(stSTRING);create_makelocal(dotify($1,FALSE),sySTRING);add_command(cPOPSTRSYM,dotify($1,FALSE));}
| tSYMBOL '(' ')' {create_require(stNUMBERARRAYREF);create_arraylink(dotify($1,FALSE),stNUMBERARRAYREF);}
| tSTRSYM '(' ')' {create_require(stSTRINGARRAYREF);create_arraylink(dotify($1,FALSE),stSTRINGARRAYREF);}
;
for_loop: tFOR {missing_next++;missing_next_line=mylineno;} tSYMBOL tEQU
{pushname(dotify($3,FALSE)); /* will be used by next_symbol to check equality */
add_command(cRESETSKIPONCE,NULL);
pushgoto();add_command(cCONTINUE_HERE,NULL);create_break_mark(0,1);}
expression tTO expression
step_part { /* pushes another expression */
add_command(cSKIPONCE,NULL);
pushlabel();
add_command(cSTARTFOR,NULL);
add_command(cPOPDBLSYM,dotify($3,FALSE));
poplabel();
add_command(cPUSHDBLSYM,dotify($3,FALSE));
add_command(cFORINCREMENT,NULL);
add_command(cPOPDBLSYM,dotify($3,FALSE));
add_command(cPUSHDBLSYM,dotify($3,FALSE));
add_command(cFORCHECK,NULL);
add_command(cDECIDE,NULL);
pushlabel();}
statement_list {
swap();popgoto();poplabel();}
next next_symbol {create_break_mark(0,-1);add_command(cBREAK_HERE,NULL);}
;
next: tEOPROG {if (missing_next) {sprintf(string,"%d next(s) are missing (last at line %d)",missing_next,missing_next_line);error(ERROR,string);} YYABORT;}
| tNEXT {missing_next--;}
;
step_part: {create_pushdbl(1);} /* can be omitted */
| tSTEP expression
;
next_symbol: {pop(stSTRING);}/* can be omitted */
| tSYMBOL {if (strcmp(pop(stSTRING)->pointer,dotify($1,FALSE)))
{error(ERROR,"'for' and 'next' do not match"); YYABORT;}
}
;
switch_number_or_string: tSWITCH {push_switch_id();add_command(cPUSH_SWITCH_MARK,NULL);create_break_mark(0,1);
add_command(cCONTINUE_CORRECTION,NULL);}
number_or_string sep_list case_list default tSEND {create_break_mark(-1,0);add_command(cBREAK_HERE,NULL);create_break_mark(0,-1);add_command(cBREAK_HERE,NULL);create_clean_switch_mark(0,FALSE);pop_switch_id();}
;
sep_list: tSEP {if ($1>=0) mylineno+=$1;}
| sep_list tSEP {if ($2>=0) mylineno+=$2;}
;
number_or_string: expression
| string_expression
;
case_list: /* empty */
| case_list tCASE {create_break_mark(-1,0);add_command(cBREAK_HERE,NULL);} number_or_string
{add_command(cSWITCH_COMPARE,NULL);add_command(cDECIDE,NULL);add_command(cMINOR_BREAK,NULL);create_break_mark(1,0);} statement_list {add_command(cNEXT_CASE,NULL);}
;
default: /* empty */
| tDEFAULT tSEP {if ($2>=0) mylineno+=$2; create_break_mark(-1,0);add_command(cBREAK_HERE,NULL);} statement_list
;
do_loop: tDO {add_command(cCONTINUE_HERE,NULL);create_break_mark(0,1);missing_loop++;missing_loop_line=mylineno;pushgoto();}
statement_list
loop
;
loop: tEOPROG {if (missing_loop) {sprintf(string,"%d loop(s) are missing (last at line %d)",missing_loop,missing_loop_line);error(ERROR,string);} YYABORT;}
| tLOOP {missing_loop--;popgoto();create_break_mark(0,-1);add_command(cBREAK_HERE,NULL);}
;
while_loop: tWHILE {add_command(cCONTINUE_HERE,NULL);create_break_mark(0,1);missing_wend++;missing_wend_line=mylineno;pushgoto()} '(' expression ')'
{add_command(cDECIDE,NULL);
pushlabel();}
statement_list
wend
;
wend: tEOPROG {if (missing_wend) {sprintf(string,"%d wend(s) are missing (last at line %d)",missing_wend,missing_wend_line);error(ERROR,string);} YYABORT;}
| tWEND {missing_wend--;swap();popgoto();poplabel();create_break_mark(0,-1);add_command(cBREAK_HERE,NULL);}
;
repeat_loop: tREPEAT {add_command(cCONTINUE_HERE,NULL);create_break_mark(0,1);missing_until++;missing_until_line=mylineno;pushgoto();}
statement_list
until
;
until: tEOPROG {if (missing_until) {sprintf(string,"%d until(s) are missing (last at line %d)",missing_until,missing_until_line);error(ERROR,string);} YYABORT;}
| tUNTIL '(' expression ')'
{missing_until--;add_command(cDECIDE,NULL);popgoto();create_break_mark(0,-1);add_command(cBREAK_HERE,NULL);}
;
if_clause: tIF expression {add_command(cDECIDE,NULL);storelabel();pushlabel();}
tTHEN {missing_endif++;missing_endif_line=mylineno;} statement_list {swap();matchgoto();swap();poplabel();}
elsif_part
else_part {poplabel();}
endif
;
endif: tEOPROG {if (missing_endif) {sprintf(string,"%d endif(s) are missing (last at line %d)",missing_endif,missing_endif_line);error(ERROR,string);} YYABORT;}
| tENDIF {missing_endif--;}
;
short_if: tIF expression {fi_pending++;add_command(cDECIDE,NULL);pushlabel();}
statement_list tENDIF {poplabel();}
;
else_part: /* can be omitted */
| tELSE statement_list
;
elsif_part: /* can be omitted */
| tELSIF expression maybe_then
{add_command(cDECIDE,NULL);pushlabel();}
statement_list
{swap();matchgoto();swap();poplabel();}
elsif_part
;
maybe_then: /* can be omitted */
| tTHEN
;
inputlist: input
| input ',' {add_command(cCHKPROMPT,NULL);} inputlist
;
input: tSYMBOL {create_myread('d',tileol);add_command(cPOPDBLSYM,dotify($1,FALSE));}
| tSYMBOL '(' call_list ')'
{create_myread('d',tileol);create_doarray(dotify($1,FALSE),ASSIGNARRAY);}
| tSTRSYM {create_myread('s',tileol);add_command(cPOPSTRSYM,dotify($1,FALSE));}
| tSTRSYM '(' call_list ')'
{create_myread('s',tileol);create_doarray(dotify($1,FALSE),ASSIGNSTRINGARRAY);}
;
readlist: readitem
| readlist ',' readitem
;
readitem: tSYMBOL {create_readdata('d');add_command(cPOPDBLSYM,dotify($1,FALSE));}
| tSYMBOL '(' call_list ')'
{create_readdata('d');create_doarray(dotify($1,FALSE),ASSIGNARRAY);}
| tSTRSYM {create_readdata('s');add_command(cPOPSTRSYM,dotify($1,FALSE));}
| tSTRSYM '(' call_list ')'
{create_readdata('s');create_doarray(dotify($1,FALSE),ASSIGNSTRINGARRAY);}
;
datalist: tSTRING {create_strdata($1);}
| const {create_dbldata($1);}
| datalist ',' tSTRING {create_strdata($3);}
| datalist ',' const {create_dbldata($3);}
;
printlist: /* possible empty */
| expression using
| printlist ',' expression using
| string_expression {create_print('s');}
| printlist ',' string_expression {create_print('s');}
;
using: {create_print('d');} /* possible empty */
| tUSING string_expression {create_print('u');}
| tUSING '(' string_expression ',' string_expression ')' {create_print('U');}
;
inputbody: '#' tSYMBOL {add_command(cPUSHDBLSYM,dotify($2,FALSE));create_pps(cPUSHSTREAM,1);} inputlist {create_pps(cPOPSTREAM,0);}
| '#' tDIGITS {create_pushdbl(atoi($2));create_pps(cPUSHSTREAM,1);} inputlist {create_pps(cPOPSTREAM,0);}
| '#' '(' expression ')' {create_pps(cPUSHSTREAM,1);} inputlist {create_pps(cPOPSTREAM,0);}
| tAT '(' expression ',' expression ')' {add_command(cMOVE,NULL);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,1);} prompt inputlist {create_pps(cPOPSTREAM,0);}
| {create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,1);} prompt inputlist {create_pps(cPOPSTREAM,0);}
;
prompt: /* empty */ {create_pushstr("?");create_print('s');}
| tSTRING {create_pushstr($1);create_print('s');}
;
printintro: /* may be empty */ {create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| '#' tSYMBOL {add_command(cPUSHDBLSYM,dotify($2,FALSE));create_pps(cPUSHSTREAM,0);}
| '#' tDIGITS {create_pushdbl(atoi($2));create_pps(cPUSHSTREAM,0);}
| '#' '(' expression ')' {create_pps(cPUSHSTREAM,0);}
| tREVERSE {create_colour(1);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tCOLOUR '(' string_expression ')' {create_colour(2);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tCOLOUR '(' string_expression ',' string_expression ')' {create_colour(3);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tAT '(' expression ',' expression ')' {add_command(cMOVE,NULL);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tREVERSE tAT '(' expression ',' expression ')' {add_command(cMOVE,NULL);create_colour(1);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tCOLOUR '(' string_expression ')' tAT '(' expression ',' expression ')' {add_command(cMOVE,NULL);create_colour(2);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tCOLOUR '(' string_expression ',' string_expression ')' tAT '(' expression ',' expression ')' {add_command(cMOVE,NULL);create_colour(3);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);}
| tAT '(' expression ',' expression ')' tREVERSE {create_colour(1);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);add_command(cMOVE,NULL);}
| tAT '(' expression ',' expression ')' tCOLOUR '(' string_expression ')' {create_colour(2);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);add_command(cMOVE,NULL);}
| tAT '(' expression ',' expression ')' tCOLOUR '(' string_expression ',' string_expression ')' {create_colour(3);create_pushdbl(STDIO_STREAM);create_pps(cPUSHSTREAM,0);add_command(cMOVE,NULL);}
;
hashed_number: '#' expression
| expression;
goto_list: symbol_or_lineno {create_goto((function_type!=ftNONE)?dotify($1,TRUE):$1);add_command(cFINDNOP,NULL);}
| goto_list ',' symbol_or_lineno {create_goto((function_type!=ftNONE)?dotify($3,TRUE):$3);add_command(cFINDNOP,NULL);}
;
gosub_list: symbol_or_lineno {create_gosub((function_type!=ftNONE)?dotify($1,TRUE):$1);add_command(cFINDNOP,NULL);}
| gosub_list ',' symbol_or_lineno {create_gosub((function_type!=ftNONE)?dotify($3,TRUE):$3);add_command(cFINDNOP,NULL);}
;

560
src/yabasic.flex Normal file
View File

@@ -0,0 +1,560 @@
%{
/*
YABASIC --- a simple Basic Interpreter
written by Marc-Oliver Ihm 1995-2004
homepage: www.yabasic.de
FLEX part
This file is part of yabasic and may be copied only
under the terms of either the Artistic License or
the GNU General Public License (GPL), both of which
can be found at www.yabasic.de
*/
#include <string.h>
#undef WINDOWS
#include "bison.h" /* get tokens from BISON */
#ifndef YABASIC_INCLUDED
#include "yabasic.h" /* definitions of yabasic */
#endif
extern int main_lineno; /* defined in yabasic.bison: line number of main file */
extern int mylineno; /* defined in yabasic.bison: line number of main file */
int import_lib(char *); /* import library */
#define MAX_INCLUDE_DEPTH 5
#define MAX_INCLUDE_NUMBER 100
static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; /* stack for included libraries */
int include_stack_ptr; /* current position in libfile_stack */
struct libfile_name *libfile_stack[MAX_INCLUDE_DEPTH]; /* stack for library file names */
int libfile_chain_length=0; /* length of libfile_chain */
struct libfile_name *libfile_chain[MAX_INCLUDE_NUMBER]; /* list of all library file names */
struct libfile_name *currlib; /* current libfile as relevant to bison */
int inlib; /* true, while in library */
int fi_pending=0; /* true, if within a short if */
int flex_line=0; /* line number counted in flex */
%}
WS [ \t\f\r\v]
NAME ([A-Za-z_][A-za-z0-9_]*\.[A-Za-z_][A-za-z0-9_]*)|([A-Za-z_][A-za-z0-9_]*)
%option noyywrap
%x PRELNO
%x PASTLNO
%x IMPORT
%x IMPORT_DONE
%%
<<EOF>> {
if (--include_stack_ptr<0) {
return tEOPROG;
} else {
if (!is_bound) {
yy_delete_buffer(YY_CURRENT_BUFFER);
yy_switch_to_buffer(include_stack[include_stack_ptr]);
}
flex_line+=yylval.sep=-1;
return tSEP;
}
}
{WS}+ {BEGIN(INITIAL);} /* ignore whitespace */
^{WS}*/[0-9]+ {BEGIN(PRELNO);return tLABEL;}
<PRELNO>[0-9]+ {
BEGIN(PASTLNO);
yylval.symbol=(char *)my_strdup(yytext);
return tSYMBOL;
}
<PASTLNO>.* {BEGIN(INITIAL);flex_line+=yylval.sep=0;yyless(0);return tSEP;}
<PASTLNO>\n {if (fi_pending) {fi_pending--;yyless(0);return tENDIF;}BEGIN(INITIAL);flex_line+=yylval.sep=1;return tSEP;}
\n\n {if (fi_pending) {fi_pending--;yyless(0);return tENDIF;}if (interactive && !inlib) {return tEOPROG;} else {flex_line+=yylval.sep=2;return tSEP;}}
\n {if (fi_pending) {fi_pending--;yyless(0);return tENDIF;}flex_line+=yylval.sep=1;return tSEP;}
: {if (fi_pending && check_compat) error_with_line(WARNING,"short-if has changed in version 2.71",flex_line);flex_line+=yylval.sep=0;return tSEP;}
REM{WS}+.* {flex_line+=yylval.sep=0;return tSEP;} /* comments span 'til end of line */
\/\/.* {flex_line+=yylval.sep=0;return tSEP;} /* comments span 'til end of line */
REM\n {if (fi_pending) {fi_pending--;yyless(0);return tENDIF;}flex_line+=yylval.sep=1;return tSEP;}
REM {yymore();}
IMPORT {BEGIN(IMPORT);}
<IMPORT>{WS}+{NAME} {if (!import_lib(yytext)) return 0;BEGIN(IMPORT_DONE);return tIMPORT;}
<IMPORT_DONE>(.|\n) {if (yytext[0]=='\n' && fi_pending) {fi_pending--;yyless(0);return tENDIF;}BEGIN(INITIAL);yyless(0);flex_line+=yylval.sep=0;return tSEP;}
((DOCU|DOC|DOCUMENTATION)({WS}+.*)?) {
char *where=strpbrk(yytext," \t\r\f\v");
yylval.docu=(char *)my_strdup(where ? where+1 : NULL);
return tDOCU;
}
^#.*\n {flex_line+=yylval.sep=1;return tSEP;} /* '#' as first character may introduce comments too */
^'.*\n {flex_line+=yylval.sep=1;return tSEP;} /* ' as first character may introduce comments too */
EXECUTE return tEXECUTE;
"EXECUTE$" return tEXECUTE2;
COMPILE return tCOMPILE;
RUNTIME_CREATED_SUB return tRUNTIME_CREATED_SUB;
END{WS}+SUB return tENDSUB;
END{WS}+IF return tENDIF;
END-IF return tENDIF;
END{WS}+WHILE return tWEND;
END-WHILE return tWEND;
END{WS}+SWITCH return tSEND;
END-SWITCH return tSEND;
END{WS}+"SWITCH$" return tSEND;
END-"SWITCH$" return tSEND;
EXPORT return tEXPORT;
ERROR return tERROR;
FOR return tFOR;
BREAK return tBREAK;
SWITCH return tSWITCH;
CASE return tCASE;
DEFAULT return tDEFAULT;
LOOP return tLOOP;
DO return tDO;
TO return tTO;
AS return tAS;
READING return tREADING;
WRITING return tWRITING;
STEP return tSTEP;
NEXT return tNEXT;
WHILE return tWHILE;
WEND return tWEND;
REPEAT return tREPEAT;
UNTIL return tUNTIL;
GOTO return tGOTO;
GOSUB return tGOSUB;
SUB return tSUB;
SUBROUTINE return tSUB;
LOCAL return tLOCAL;
STATIC return tSTATIC;
ON return tON;
INTERRUPT return tINTERRUPT;
CONTINUE return tCONTINUE;
LABEL return tLABEL;
IF return tIF;
THEN return tTHEN;
ELSE return tELSE;
ELSIF return tELSIF;
ELSEIF return tELSIF;
ENDIF return tENDIF;
FI return tENDIF;
OPEN return tOPEN;
CLOSE return tCLOSE;
SEEK return tSEEK;
TELL return tTELL;
PRINT return tPRINT;
USING return tUSING;
REVERSE return tREVERSE;
COLOR return tCOLOUR;
COLOUR return tCOLOUR;
\? return tPRINT;
INPUT return tINPUT;
RETURN return tRETURN;
DIM return tDIM;
REDIM return tDIM;
END return tEND;
EXIT return tEXIT;
READ return tREAD;
DATA return tDATA;
RESTORE return tRESTORE;
AND return tAND;
OR return tOR;
NOT return tNOT;
EOR return tEOR;
XOR return tEOR;
WINDOW return tWINDOW;
PRINTER return tPRINTER;
SETUP return tSETUP;
PUTSCREEN return tPUTCHAR;
"GETSCREEN$" return tGETCHAR;
NEW return tNEW;
WAIT return tWAIT;
PAUSE return tWAIT;
SLEEP return tWAIT;
BELL return tBELL;
BEEP return tBELL;
LET return tLET;
ARRAYDIM return tARDIM;
ARRAYDIMENSION return tARDIM;
ARRAYSIZE return tARSIZE;
NUMPARAM(S)?({WS}*\({WS}*\))? {yylval.symbol=(char *)my_strdup("numparams"); return tSYMBOL;}
BIND return tBIND;
SET return tSET;
LOCALIZE return tLOCALIZE;
BUTTON return tBUTTON;
ALERT return tALERT;
MENU return tMENU;
CHECKBOX return tCHECKBOX;
RADIOBUTTON return tRADIOBUTTON;
TEXTCONTROL return tTEXTCONTROL;
LISTBOX return tLISTBOX;
DROPBOX return tDROPBOX;
ADD return tADD;
REMOVE return tREMOVE;
TEXT return tTEXT;
RECT return tRECT;
DRAW return tDRAW;
FLUSH return tFLUSH;
FILEPANEL return tFILEPANEL;
LAYOUT return tLAYOUT;
TEXTEDIT return tTEXTEDIT;
COUNT return tCOUNT;
VIEW return tVIEW;
BOXVIEW return tBOXVIEW;
TABVIEW return tTABVIEW;
ELLIPSE return tELLIPSE;
DOT return tDOT;
LINE return tLINE;
CURVE return tCURVE;
CIRCLE return tCIRCLE;
CLEAR return tCLEAR;
TEXT return tTEXT;
RECT return tRECT;
SLIDER return tSLIDER;
OPTION return tOPTION;
DROPZONE return tDROPZONE;
COLORCONTROL return tCOLORCONTROL;
TREEBOX return tTREEBOX;
SORT return tSORT;
TOOLTIP return tTOOLTIP;
COLUMNBOX return tCOLUMNBOX;
COLUMN return tCOLUMN;
CLIPBOARD return tCLIPBOARD;
COPY return tCOPY;
SUBMENU return tSUBMENU;
KEYBOARD return tKEYBOARD;
SELECT return tSELECT;
CALENDAR return tCALENDAR;
SCROLLBAR return tSCROLLBAR;
COLLAPSE return tCOLLAPSE;
EXPAND return tEXPAND;
SOUND return tSOUND;
PLAY return tPLAY;
STOP return tSTOP;
SPLITVIEW return tSPLITVIEW;
STACKVIEW return tSTACKVIEW;
TEXTURL return tTEXTURL;
SPINCONTROL return tSPINCONTROL;
POPUPMENU return tPOPUPMENU;
SEND return tMSEND;
MESSAGE return tNUMMESSAGE;
THREAD return tTHREAD;
BITMAP return tBITMAP;
CANVAS return tCANVAS;
SHORTCUT return tSHORTCUT;
SAVE return tSAVE;
ISCOMPUTERON return tISCOMPUTERON;
SCREENSHOT return tSCREENSHOT;
STATUSBAR return tSTATUSBAR;
LAUNCH return tLAUNCH;
ATTRIBUTE return tATTRIBUTE;
"PASTE$" return tPASTE;
IMAGE return tIMAGE;
SVG return tSVG;
"MESSAGE$" return tMESSAGE;
"TRANSLATE$" return tTRANSLATE;
"GET$" return tGET;
MOUSE return tMOUSE;
ISMOUSEIN return tISMOUSEIN;
GET return tGETNUM;
SIN return tSIN;
ASIN return tASIN;
COS return tCOS;
ACOS return tACOS;
TAN return tTAN;
ATAN return tATAN;
EXP return tEXP;
LOG return tLOG;
SQRT return tSQRT;
SQR return tSQR;
INT return tINT;
FRAC return tFRAC;
ABS return tABS;
SIG return tSIG;
MOD return tMOD;
RAN return tRAN;
MIN return tMIN;
MAX return tMAX;
"LEFT$" return tLEFT;
"RIGHT$" return tRIGHT;
"MID$" return tMID;
"LOWER$" return tLOWER;
"UPPER$" return tUPPER;
"LTRIM$" return tLTRIM;
"RTRIM$" return tRTRIM;
"TRIM$" return tTRIM;
INSTR return tINSTR;
RINSTR return tRINSTR;
LEN return tLEN;
VAL return tVAL;
EOF return tMYEOF;
"STR$" return tSTR;
"INKEY$" return tINKEY;
"CHR$" return tCHR;
ASC return tASC;
"HEX$" return tHEX;
"BIN$" return tBIN;
DEC return tDEC;
AT return tAT;
@ return tAT;
SCREEN return tSCREEN;
"SYSTEM$" return tSYSTEM;
SYSTEM return tSYSTEM2;
"DATE$" return tDATE;
"TIME$" return tTIME;
PEEK return tPEEK;
"PEEK$" return tPEEK2;
POKE return tPOKE;
TOKEN return tTOKEN;
"TOKEN$" return tTOKENALT;
SPLIT return tSPLIT;
"SPLIT$" return tSPLITALT;
GLOB return tGLOB;
"^" return tPOW;
"**" return tPOW;
"<>" return tNEQ;
"<=" return tLEQ;
">=" return tGEQ;
"=" return tEQU;
"<" return tLTN;
">" return tGTN;
"!" return tNOT;
[-+*/:(),.;] {return yytext[0];}
[0-9]+ {
yylval.digits=(char *)my_strdup(yytext);
return tDIGITS;
}
(([0-9]+|([0-9]*\.[0-9]*))([eE][-+]?[0-9]+)?) {
{ double d;
sscanf(yytext,"%lg",&d);
yylval.fnum=d;
return tFNUM;
}
}
pi {yylval.fnum=3.1415926535897932;return tFNUM;}
euler {yylval.fnum=2.7182818284590452;return tFNUM;}
TRUE {yylval.fnum=1; return tFNUM;}
FALSE {yylval.fnum=0; return tFNUM;}
{NAME} {
yylval.symbol=(char *)my_strdup(yytext);
return tSYMBOL;
}
/* Symbols with a trailing $-sign are treated special */
{NAME}\$ {
yylval.symbol=(char *)my_strdup(yytext);
return tSTRSYM;
}
\"[^"]*(\"|\n) {
int cnt;
if (yytext[yyleng-1]=='\n' && fi_pending) {fi_pending--;yyless(0);return tENDIF;}
if (yytext[yyleng-1]=='\n') {
yylval.string=NULL;
return tSTRING;
}
for(cnt=0;yytext[yyleng-cnt-2]=='\\';cnt++) ;
if (cnt%2) {
yyless(yyleng-1);
yymore();
} else {
yylval.string=(char *)my_strdup(yytext+1);
*(yylval.string+yyleng-2)='\0';
replace(yylval.string);
return tSTRING;
}
}
. {if (isprint(yytext[0])) return yytext[0]; else return ' ';}
%%
void yyerror(char *msg)
{
int i,j;
sprintf(string,"%s at %n",msg,&j);
if (*yytext=='\n' || *yytext=='\0') {
sprintf(string+j,"end of line");
} else {
i=0;
string[j++]='\"';
while(yytext[i]) {
if (isprint(yytext[i])) string[j++]=yytext[i++];
else {
sprintf(string+j,"0x%02x",yytext[i]);
j+=4;
break;
}
}
string[j++]='\"';
string[j]='\0';
}
error(ERROR,string);
return;
}
void open_main(FILE *file,char *explicit,char *main_file_name) /* open main file */
{
include_stack_ptr=0;
if (explicit)
include_stack[include_stack_ptr]=yy_scan_string(explicit);
else
include_stack[include_stack_ptr]=yy_create_buffer(file,YY_BUF_SIZE);
libfile_stack[include_stack_ptr]=new_file(main_file_name,"main");
libfile_chain[libfile_chain_length++]=libfile_stack[include_stack_ptr];
if (!explicit) yy_switch_to_buffer(include_stack[include_stack_ptr]);
currlib=libfile_stack[0];
inlib=FALSE;
return;
}
void open_string(char *cmd) /* open string with commands */
{
yy_switch_to_buffer(yy_scan_string(cmd));
}
int import_lib(char *name) /* import library */
{
char *full;
static int end_of_import=FALSE;
if (!*name) name=pop(stSTRING)->pointer;
while(isspace(*name)) name++;
if (!strcmp(name,"__END_OF_IMPORT")) end_of_import=TRUE;
if (end_of_import) return TRUE;
/* start line numbers anew */
libfile_stack[include_stack_ptr]->lineno=mylineno;
include_stack_ptr++;
if (include_stack_ptr>=MAX_INCLUDE_DEPTH) {
sprintf(string,"Could not import '%s': nested too deep",name);
error(ERROR,string);
return FALSE;
}
if (is_bound) {
full=name;
} else {
yyin=open_library(name,&full,FALSE);
if (!yyin) return FALSE;
yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
include_stack[include_stack_ptr]=YY_CURRENT_BUFFER;
}
libfile_stack[include_stack_ptr]=new_file(full,NULL);
libfile_chain[libfile_chain_length++]=libfile_stack[include_stack_ptr];
if (libfile_chain_length>=MAX_INCLUDE_NUMBER) {
sprintf(string,"Cannot import more than %d libraries",MAX_INCLUDE_NUMBER);
error(ERROR,string);
return FALSE;
}
if (!libfile_stack[include_stack_ptr]) {
sprintf(string,"library '%s' has already been imported",full);
error(ERROR,string);
return FALSE;
}
if (infolevel>=NOTE && !is_bound) {
sprintf(string,"importing from file '%s'",full);
error(NOTE,string);
}
return TRUE;
}
FILE *open_library(char *name,char **fullreturn,int without) /* search and open a library */
{
static char full[200];
char unquoted[200];
char *p;
FILE *lib;
int i;
char *trail;
if (fullreturn) *fullreturn=full;
for(p=name;strchr(" \"'`",*p);p++) if (!*p) break;
strncpy(unquoted,p,200);
for(;!strchr(" \"'`",*p);p++) if (!*p) break;
if (*p) unquoted[p-name-2]='\0';
name=unquoted;
if (strchr(name,'.')) {
sprintf(string,"library name '%s' contains '.'",name);
error(ERROR,string);
return NULL;
}
if (!strcmp(name,"main")) {
if (is_bound) return NULL;
error(ERROR,"invalid library name 'main'");
return NULL;
}
/* search local */
trail=".yab";
for(i=0;i<2;i++) {
strcpy(full,name);
if (!strchr(full,'.')) strcat(full,trail);
lib=fopen(full,"r");
if (lib) return lib;
trail="";
if (!without) break;
}
/* search in global location */
trail=".yab";
for(i=0;i<2;i++) {
strcpy(full,library_path);
if (full[0] && !strchr("\\/",full[strlen(full)-1])) {
#ifdef UNIX
strcat(full,"/");
#else
strcat(full,"\\");
#endif
}
strcat(full,name);
if (!strchr(full,'.')) strcat(full,trail);
lib=fopen(full,"r");
if (lib) return lib;
trail="";
if (!without) break;
}
sprintf(string,"couldn't open library '%s'",full);
error(ERROR,string);
return NULL;
}
void switchlib(void) /* switch library, called by bison */
{
if (include_stack_ptr<0) return;
if (infolevel>=DEBUG) {
sprintf(string,"switching from '%s' to '%s'",currlib->s,libfile_stack[include_stack_ptr]->s);
error(DEBUG,string);
}
currlib=libfile_stack[include_stack_ptr];
mylineno=currlib->lineno;
inlib=(include_stack_ptr>0);
}

885
src/yabasic.h Normal file
View File

@@ -0,0 +1,885 @@
/*
YABASIC --- a simple Basic Interpreter
written by Marc-Oliver Ihm 1995-2004
homepage: www.yabasic.de
yabasic.h --- function prototypes and global variables
This file is part of yabasic and may be copied only
under the terms of either the Artistic License or
the GNU General Public License (GPL), both of which
can be found at www.yabasic.de
*/
#define YABLICENSE \
"\n"\
" Yab may only be copied under the terms of the Artistic \n"\
" License which can be found at yab-interpreter.sourceforge.net. \n"\
"\n"\
" The Artistic License gives you the right to use and distribute \n"\
" yab in a more-or-less customary fashion, plus the right to make \n"\
" reasonable modifications and distribute (or even sell) such a \n"\
" modified version under a different name. \n"\
" However, the original author and copyright holder still reserves \n"\
" himself some sort of artistic control over the development \n"\
" of yab itself. \n"\
#define YABASIC_INCLUDED
/* ------------- defines ---------------- */
/*
Define one and only one of the following symbols, depending on your
System:
- UNIX: uses some UNIX-features and X11
- WINDOWS: uses WIN32-features
Define UNIX and BEOS for a BeOS build
*/
#if defined(UNIX) && defined(WINDOWS)
UNIX and WINDOWS are defined at once; check your compiler settings
#endif
/* ------------- includes ---------------- */
#include "global.h"
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <errno.h>
#ifdef WINDOWS
#include <string.h>
#include <windows.h>
#include <io.h>
#define ARCHITECTURE "windows"
#ifdef __LCC__ /* fix for lccwin32 */
#include <winspool.h>
#endif
#endif
#include "YabInterface.h"
#ifdef UNIX
#define ARCHITECTURE UNIX_ARCHITECTURE
#ifdef HAS_STRING_HEADER
#include <string.h>
#elif HAS_STRINGS_HEADER
#include <strings.h>
#endif
#include <sys/time.h>
#include <sys/wait.h>
#ifndef BEOS
#include <sys/ipc.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Intrinsic.h>
#define XK_LATIN1
#define XK_MISCELLANY
#include <X11/keysymdef.h>
#endif
#include <unistd.h>
#include <fcntl.h>
#ifdef BUILD_NCURSES
#include <ncurses.h>
// #else
// #ifdef HAVE_CURSES_HEADER
// #include <curses.h>
// #endif
#endif
#ifndef KEY_MAX
#define KEY_MAX 0777
#endif
#endif
#ifndef FOPEN_MAX
#define FOPEN_MAX 24
#endif
#include <signal.h>
#include <ctype.h>
#ifdef UNIX
#ifndef LIBRARY_PATH
#define LIBRARY_PATH "/boot/home/config/settings/yab"
#endif
#endif
#define OPEN_HAS_STREAM 1
#define OPEN_HAS_MODE 2
#define OPEN_PRINTER 8
#define STDIO_STREAM 1234
/* -------- variables needed in all files and defined in ... -------- */
/* main.c */
extern struct command *current; /* currently executed command */
extern struct command *cmdroot; /* first command */
extern struct command *cmdhead; /* next command */
extern struct command *lastcmd; /* last command */
extern int infolevel; /* controls issuing of error messages */
extern int errorlevel; /* highest level of error message seen til now */
extern int interactive; /* true, if commands come from stdin */
extern char *progname; /* name of yabasic-program */
extern char *explanation[]; /* explanations of commands */
extern char **yabargv; /* arguments for yabasic */
extern int yabargc; /* number of arguments in yabargv */
extern time_t compilation_start,compilation_end,execution_end;
extern char *string; /* for trash-strings */
extern char *errorstring; /* for error-strings */
extern int errorcode; /* error-codes */
extern char library_path[]; /* full path to search libraries */
extern int program_state; /* state of program */
extern int check_compat; /* true, if compatibility should be checked */
extern int is_bound; /* true, if this executable is bound */
extern char* appdirectory; /* appdir */
/* io.c */
extern FILE *streams[]; /* file streams */
extern int read_controls; /* TRUE, if input should read control characters */
extern int stream_modes[]; /* modes for streams */
extern int curinized; /* true, if curses has been initialized */
extern int badstream(int,int); /* test for valid stream id */
void myseek(struct command *); /* reposition file pointer */
#ifdef WINDOWS
extern HANDLE wantkey; /* mutex to signal key desire */
extern HANDLE gotkey; /* mutex to signal key reception */
extern HANDLE wthandle; /* handle of win thread */
extern HANDLE kthandle; /* handle of inkey thread */
extern DWORD ktid; /* id of inkey thread */
extern int LINES; /* number of lines on screen */
extern int COLS; /* number of columns on screen */
extern HANDLE ConsoleInput; /* handle for console input */
extern HANDLE ConsoleOutput; /* handle for console output */
#else
extern int winpid; /* pid of process waiting for window keys */
extern int termpid; /* pid of process waiting for terminal keys */
#ifndef BUILD_NCURSES
extern int LINES; /* number of lines on screen */
extern int COLS; /* number of columns on screen */
#endif
#endif
/* graphic.c */
/* printing and plotting */
extern int print_to_file; /* print to file ? */
#ifdef WINDOWS
extern HFONT printerfont; /* handle of printer-font */
extern HDC printer; /* handle of printer */
#endif
extern FILE *printerfile; /* file to print on */
extern double xoff; /* offset for x-mapping */
extern double xinc; /* inclination of x-mapping */
extern double yoff; /* offset for y-mapping */
extern double yinc; /* inclination for y-mapping */
/* window coordinates */
extern int winopened; /* flag if window is open already */
extern char *winorigin; /* e.g. "lt","rc"; defines origin of grafic window */
extern int winwidth,winheight; /* size of window */
/* mouse, console and keyboard */
/* extern int mousex,mousey,mouseb,mousemod; */ /* last know mouse coordinates */
extern char *ykey[]; /* keys returned by inkey */
/* text and font */
extern char *getreg(char *); /* get defaults from Registry */
extern char *text_align; /* specifies alignement of text */
extern int fontheight; /* height of font in pixel */
#ifdef WINDOWS
extern HFONT myfont; /* handle of font for screen */
#endif
/* general window stuff */
extern char *foreground;
extern char *background;
extern char *geometry;
extern char *displayname;
extern char *font;
extern int drawmode;
#ifdef WINDOWS
extern HWND window; /* handle of my window */
extern HANDLE mainthread; /* handle to main thread */
extern HANDLE this_instance;
extern WNDCLASS myclass; /* window class for my program */
extern char *my_class;
extern BOOL Commandline; /* true if launched from command line */
#else
extern int backpid; /* pid of process waiting for redraw events */
#endif
/* function.c */
extern struct command *datapointer; /* current location for read-command */
/* symbol.c */
extern struct stackentry *stackroot; /* first element of stack */
extern struct stackentry *stackhead; /* last element of stack */
extern void query_array(struct command *cmd); /* query array */
extern struct command *lastref; /* last command in UDS referencing a symbol */
extern struct command *firstref; /* first command in UDS referencing a symbol */
extern int labelcount; /* count self-generated labels */
/* flex.c */
extern int include_stack_ptr; /* Lex buffer for any imported file */
extern struct libfile_name *libfile_stack[]; /* stack for library file names */
extern struct libfile_name *currlib; /* current libfile as relevant to bison */
extern int inlib; /* true, while in library */
extern int fi_pending; /* true, if within a short if */
extern int libfile_chain_length; /* length of libfile_chain */
extern struct libfile_name *libfile_chain[]; /* list of all library file names */
/* bison.c */
extern char *current_function; /* name of currently parsed function */
extern int yydebug;
extern int missing_endif;
extern int missing_endif_line;
extern int in_loop;
/*-------------------------- defs and undefs ------------------------*/
/* undef symbols */
#undef FATAL
#undef ERROR
#undef WARNING
#undef NOTE
#undef DEBUG
#undef DUMP
#if !defined(TRUE)
#define TRUE (1==1)
#endif
#ifndef FALSE
#define FALSE (1!=1)
#endif
/* I've been told, that some symbols are missing under SunOs ... */
#ifndef RAND_MAX
#define RAND_MAX 32767
#endif
/* length of buffers for system() and input */
#define SYSBUFFLEN 100
#define INBUFFLEN 10000
/* ---------------------- enum types ------------------------------- */
enum error { /* error levels */
FATAL,ERROR,INFO,DUMP,WARNING,NOTE,DEBUG
};
enum endreasons { /* ways to end the program */
erNONE,erERROR,erREQUEST,erEOF
};
enum streammodes { /* ways to access a stream */
smCLOSED=0,smREAD=1,smWRITE=2,smPRINT=4
};
enum functions { /* functions in yabasic (sorted by number of arguments) */
fRAN2,fDATE,fTIME,fMESSAGE,fNUMWINDOWS,fCLIPBOARDPASTE,fISCOMPUTERON,fMOUSEMOVE,
fZEROARGS,
fINKEY,/* fMOUSEX,fMOUSEY,fMOUSEB,fMOUSEMOD,*/
fSIN,fASIN,fCOS,fACOS,fTAN,
fATAN,fSYSTEM,fSYSTEM2,fPEEK,fPEEK2,fPEEK4,fTELL,fEXP,fLOG,fLEN,fSTR,
fSQRT,fSQR,fFRAC,fABS,fSIG,fRAN,fINT,fVAL,fASC,fHEX,fBIN,fDEC,fUPPER,fLOWER,
fLTRIM,fRTRIM,fTRIM,fCHR,fTRANSLATE,fMENUTRANSLATE,fMOUSE, fISMOUSEIN,fTEXTCONTROLGET,
fKEYBOARD,fCOLUMNBOXCOUNT, fCALENDAR, fLISTBOXCOUNT, fTREEBOXCOUNT, fSTACKVIEWGET,
fSPINCONTROLGET, fDROPBOXCOUNT, fSLIDERGET, fTEXTGET, fDRAWGET3, fTABVIEWGET,
fLISTBOXGETNUM, fDROPBOXGETNUM, fCOLUMNBOXGETNUM, fTREEBOXGETNUM, fSOUND,
fONEARGS,
fDEC2,fATAN2,fLEFT,fAND,fOR,fEOR,fLOG2,
fRIGHT,fINSTR,fRINSTR,fSTR2,fMOD,fMIN,fMAX,fPEEK3,fMID2,fWINDOWGET, fVIEWGET /* vasper */,
fLISTBOXGET, fTREEBOXGET, fSCROLLBARGET, fSPLITVIEWGET, fDROPBOXGET, fCOLORCONTROLGET,
fTEXTGET2,fTEXTGET6,fDRAWGET2, fTEXTGET3, fMESSAGESEND, fTHREADKILL, fTHREADGET, fBITMAPGET,
fBITMAPLOAD, fATTRIBUTEGET1, fATTRIBUTEGET2,
fTWOARGS,
fMID,fINSTR2,fRINSTR2,fSTR3,fCOLUMNBOXGET,fDRAWGET1,fTEXTGET4,fTEXTGET5,fPRINTER,
fLOAD, fTREEBOXGETOPT,fBITMAPSAVE,
fTHREEARGS,
fGETCHAR,fDRAWIMAGE,fPOPUPMENU,fSAVE,fDRAWGET4,fBITMAPCOLOR,
fFOURARGS,
fALERT,
fFIVEARGS,
fDRAWSVG,fDRAWIMAGE2,
fSIXARGS
};
enum arraymode { /* type of array access */
CALLARRAY,ASSIGNARRAY,CALLSTRINGARRAY,ASSIGNSTRINGARRAY,GETSTRINGPOINTER
};
enum drawing_modes { /* various ways to draw */
dmNORMAL=0,dmCLEAR=1,dmFILL=2
};
enum cmd_type { /* type of command */
cFIRST_COMMAND, /* no command, just marks start of list */
cLABEL,cSUBLINK,cGOTO,cQGOTO,cGOSUB,cQGOSUB,cRETURN, /* flow control */
cEND,cEXIT,cBIND,cDECIDE,cSKIPPER,cNOP,cFINDNOP,cEXCEPTION,cANDSHORT,
cORSHORT,cSKIPONCE,cRESETSKIPONCE,cCOMPILE,cEXECUTE,cEXECUTE2,
cDIM,cFUNCTION,cDOARRAY,cARRAYLINK,cPUSHARRAYREF,cCLEARREFS, /* everything with "()" */
cARDIM,cARSIZE,cTOKEN,cTOKEN2,cTOKENALT,cTOKENALT2,
cSPLIT,cSPLIT2,cSPLITALT,cSPLITALT2,
cSTARTFOR,cFORCHECK,cFORINCREMENT, /* for for-loops */
cSWITCH_COMPARE,cNEXT_CASE,cBREAK,cMINOR_BREAK, /* break-continue-switch */
cCONTINUE,cBREAK_HERE,cCONTINUE_HERE,cCONTINUE_CORRECTION,
cBREAK_MARK,cPUSH_SWITCH_MARK,cCLEAN_SWITCH_MARK,
cDBLADD,cDBLMIN,cDBLMUL,cDBLDIV,cDBLPOW, /* double operations */
cNEGATE,cPUSHDBLSYM,cPOP,cPOPDBLSYM,cPUSHDBL,
cREQUIRE,cPUSHFREE,cMAKELOCAL,cMAKESTATIC,cNUMPARAM, /* functions and procedures */
cCALL,cQCALL,cPUSHSYMLIST,cPOPSYMLIST,cRET_FROM_FUN,
cUSER_FUNCTION,cRETVAL,cEND_FUNCTION,
cFUNCTION_OR_ARRAY,cSTRINGFUNCTION_OR_ARRAY,
cPOKE,cPOKEFILE,cSWAP,cDUPLICATE,cDOCU, /* internals */
cAND,cOR,cNOT,cLT,cGT,cLE,cGE,cEQ,cNE, /* comparisons */
cSTREQ,cSTRNE,cSTRLT,cSTRLE,cSTRGT,cSTRGE,
cPUSHSTRSYM,cPOPSTRSYM,cPUSHSTR,cCONCAT, /* string operations */
cPUSHSTRPTR,cCHANGESTRING,cGLOB,
cPRINT,cREAD,cRESTORE,cQRESTORE,cONESTRING, /* i/o operations */
cREADDATA,cDATA,cOPEN,cCHECKOPEN,cCHECKSEEK,cCLOSE,cPUSHSTREAM,cPOPSTREAM,
cSEEK,cSEEK2,cTESTEOF,cWAIT,cBELL,cMOVE,
cCLEARSCR,cCOLOUR,cCHKPROMPT,cERROR,
/*
cDOT,cLINE,cCIRCLE,cCLEARWIN,
cOPENPRN,cCLOSEPRN,cMOVEORIGIN,cRECT,
cPUTBIT, */
cPUTCHAR,
cOPENWIN, cCLOSEWIN, cLAYOUT, cWINSET1, cWINSET2, cWINSET3, cWINSET4, /* Be Graphics */
cBUTTON, cALERT, cMENU, cTEXTCONTROL, cCHECKBOX, cRADIOBUTTON, cWINCLEAR,
cLISTBOX, cDROPBOX, cITEMADD, cITEMDEL, cITEMCLEAR, cLOCALIZE, cLOCALIZE2, cLOCALIZESTOP, cTEXT, cTEXT2, cTEXTALIGN,
cTEXTEDIT, cTEXTADD, cTEXTSET, cTEXTSET2, cTEXTCOLOR1, cTEXTCOLOR2, cTEXTSET3, cTEXTCLEAR,
cVIEW, cBOXVIEW, cBOXVIEWSET, cTAB, cSLIDER1, cSLIDER2, cSLIDER3, cSLIDER4, cSLIDER5, cSLIDER6,
cOPTION1, cOPTION2, cOPTION3, cDROPZONE, cTEXTCONTROL2, cTEXTCONTROL3, cTEXTCONTROL4, cTEXTCONTROL5,
cCOLORCONTROL1, cCOLORCONTROL2, cTREEBOX1, cTREEBOX2, cTREEBOX3, cTREEBOX4, cTREEBOX5,
cBUTTONIMAGE, cCHECKBOXIMAGE, cCHECKBOXSET, cRADIOSET, cTOOLTIP, cTOOLTIPCOLOR, cTREESORT,
cLISTSORT, cFILEBOX, cFILEBOXADD2, cFILEBOXCLEAR, cCOLUMNBOXREMOVE,
cCOLUMNBOXSELECT, cCOLUMNBOXADD, cDROPBOXSELECT, cMENU2, cSUBMENU1, cSUBMENU2, cCLIPBOARDCOPY,
cCOLUMNBOXCOLOR, cPRINTERCONFIG, cCALENDAR, cLISTBOXSELECT, cLISTBOXADD1, cLISTBOXADD2,
cLISTBOXDEL2, cSCROLLBAR, cSCROLLBARSET1, cSCROLLBARSET2, cSCROLLBARSET3, cTREEBOX7, cTREEBOX8,
cTREEBOX9, cTREEBOX10, cTREEBOX11, cSPLITVIEW1, cSPLITVIEW2, cSPLITVIEW3,
cSTACKVIEW1, cSTACKVIEW2, cTEXTURL1, cTEXTURL2, cDRAWSET3, cSPINCONTROL1, cTABSET, cTABDEL, cTABADD,
cSPINCONTROL2, cDROPBOXREMOVE, cDROPBOXCLEAR, cSUBMENU3, cMENU3, cCALENDARSET,
cDOT, cLINE, cCIRCLE, cDRAWTEXT, cDRAWRECT, cTREEBOX12, cOPTION4, cOPTION5,
cDRAWCLEAR, cDRAWSET1, cDRAWSET2, cELLIPSE, cCURVE, /* Drawing */
cBITMAP, cBITMAPDRAW, cBITMAPDRAW2, cBITMAPGET, cBITMAPGET2, cBITMAPGETICON, cBITMAPDRAG, cBITMAPREMOVE, cCANVAS, /* Bitmaps */
cSOUNDSTOP, cSOUNDWAIT, /* Sound */
cTREEBOX13, cDRAWSET4, cSHORTCUT, cMOUSESET,
cSCREENSHOT, cSTATUSBAR, cSTATUSBARSET, cSTATUSBARSET2, cSTATUSBARSET3, cLAUNCH, cRESTORE2, cRESTORE3,
cATTRIBUTE1, cATTRIBUTE2, cATTRIBUTECLEAR,
cLAST_COMMAND /* no command, just marks end of list */
};
enum stackentries { /* different types of stackentries */
stGOTO,stSTRING,stSTRINGARRAYREF,stNUMBER,stNUMBERARRAYREF,stLABEL,stRETADD,stRETADDCALL,stFREE,stROOT,
stANY,stSTRING_OR_NUMBER,stSTRING_OR_NUMBER_ARRAYREF, /* these will never appear on stack but are used to check with pop */
stSWITCH_MARK, /* used to clean up stack after switch-statement */
stSWITCH_STRING,stSWITCH_NUMBER /* only used in switch statement, compares true to every string or number */
};
enum symbols { /* different types of symbols */
sySTRING,syNUMBER,syFREE,syARRAY
};
enum function_type { /* different types of functions */
ftNONE,ftNUMBER,ftSTRING
};
enum addmodes { /* different modes for adding symbols */
amSEARCH,amSEARCH_PRE,amADD_LOCAL,amADD_GLOBAL,amSEARCH_VERY_LOCAL
};
enum states { /* current state of program */
HATCHED,INITIALIZED,COMPILING,RUNNING,FINISHED
};
enum yabkeys { /* recognized special keys */
kERR,kUP,kDOWN,kLEFT,kRIGHT,kDEL,kINS,kCLEAR,kHOME,kEND,
kF0,kF1,kF2,kF3,kF4,kF5,kF6,kF7,kF8,kF9,kF10,kF11,kF12,
kF13,kF14,kF15,kF16,kF17,kF18,kF19,kF20,kF21,kF22,kF23,kF24,
kBACKSPACE,kSCRNDOWN,kSCRNUP,kENTER,kESC,kTAB,kLASTKEY
};
enum searchmodes { /* modes for searching labels */
smSUB=1,smLINK=2,smLABEL=4,smGLOBAL=8
};
/* ------------- global types ---------------- */
struct stackentry { /* one element on stack */
int type; /* contents of entry */
struct stackentry *next;
struct stackentry *prev;
void *pointer; /* multiuse ptr */
double value; /* double value, only one of pointer or value is used */
};
/*
symbols are organized as a stack of lists: for every procedure call
a new list is pushed onto the stack; all local variables of this
function are chained into this list. After return from this procedure,
the whole list is discarded and one element is popped from
the stack.
*/
struct symstack { /* stack of symbol lists */
struct symbol *next_in_list;
struct symstack *next_in_stack;
struct symstack *prev_in_stack;
};
struct symbol { /* general symbol; either variable, string */
int type;
struct symbol *link; /* points to linked symbol, if any */
struct symbol *next_in_list; /* next symbol in symbollist */
char *name; /* name of symbol */
void *pointer; /* pointer to string contents (if any) */
char *args; /* used to store number of arguments for functions/array */
double value;
};
struct command { /* one interpreter command */
int type; /* type of command */
int cnt; /* count of this command */
struct command *prev; /* link to previous command */
struct command *next; /* link to next command */
void *pointer; /* pointer to data */
void *symbol; /* pointer to symbol (or data within symbol) associated with command */
struct command *jump; /* pointer to jump destination */
char *name; /* name of symbol associated with command */
struct command *nextref; /* next cmd within function referencing a symbol */
struct command *nextassoc; /* next cmd within within chain of associated commands */
int args; /* number of arguments for function/array call */
/* or stream number for open/close */
int tag; /* char/int to pass some information */
int line; /* line this command has been created for */
struct libfile_name *lib; /* associated library */
int switch_id; /* TRUE, if in switch, FALSE else; used to check gotos */
};
struct array { /* data structure for arrays */
int bounds[10]; /* index boundaries */
int dimension; /* dimension of array */
void *pointer; /* contents of array */
char type; /* decide between string- ('s') and double-Arrays ('d') */
};
struct buff_chain { /* buffer chain for system-input */
char buff[SYSBUFFLEN+1]; /* content of buffer */
int len; /* used length of buff */
struct buff_chain *next; /* next buffer in chain */
};
struct libfile_name { /* used to store library names */
char *l; /* long version, including path */
int llen; /* length of l */
char *s; /* short version */
int slen; /* length of s */
int lineno; /* linenumber within file */
struct command *datapointer; /* data pointer of this library */
struct command *firstdata; /* first data-command in library */
struct libfile_name *next; /* next in chain */
};
/* ------------- function prototypes defined in ... ---------------- */
/* main.c */
void error(int,char *); /* reports an error and possibly exits */
void error_with_line(int,char *,int); /* reports an error and possibly exits */
void *my_malloc(unsigned); /* my own version of malloc */
void my_free(void *); /* free memory */
char *my_strerror(int); /* return description of error messages */
struct command *add_command(int,char *); /* get room for new command */
void signal_handler(int); /* handle various signals */
char *my_strdup(char *); /* my own version of strdup */
char *my_strndup(char *,int); /* own version of strndup */
struct libfile_name *new_file(char *,char *); /* create a new structure for library names */
char *dotify(char *,int); /* add library name, if not already present */
char *strip(char *); /* strip off to minimal name */
void do_error(struct command *); /* issue user defined error */
void create_docu(char *); /* create command 'docu' */
extern void add_variables(char *); /* add pi and e to symbol table */
void compile(void); /* create a subroutine at runtime */
void create_execute(int); /* create command 'cEXECUTE' */
void execute(struct command *); /* execute a subroutine */
int isbound(void); /* check if this interpreter is bound to a program */
/* io.c */
void checkopen(void); /* check, if open has been sucessfull */
void create_colour(int); /* create command 'reverse' */
void colour(struct command *cmd); /* switch reverse-printing */
void create_print(char); /* create command 'print' */
void print(struct command *); /* print on screen */
void create_myread(char,int); /* create command 'read' */
void myread(struct command *); /* read from file or stdin */
void create_onestring(char *); /* write string to file */
void onestring(char *); /* write string to file */
void chkprompt(void); /* print an intermediate prompt if necessary */
void create_myopen(int); /* create command 'myopen' */
void myopen(struct command *); /* open specified file for given name */
void testeof(struct command *); /* close the specified stream */
void myclose(); /* close the specified stream */
void create_pps(int,int); /* create command pushswitch or popswitch */
void push_switch(struct command *); /* push current stream on stack and switch to new one */
void pop_switch(void); /* pop current stream from stack and switch to it */
void mymove(); /* move to specific position on screen */
void clearscreen(); /* clear entire screen */
char *inkey(double); /* gets char from keyboard, blocks and doesn´t print */
char *replace(char *); /* replace \n,\a, etc. */
/* graphic.c */
void create_openwin(int); /* create Command 'openwin' */
void openwin(struct command *, YabInterface* yab); /* open a Window */
void closewin(struct command *, YabInterface* yab); /* close the window */
int numwindows(); /* number of windows opened */
void createbutton(struct command *, YabInterface* yab); /* create a Button */
int createimage(double x, double y, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname); /* insert an image*/
int createimage2(double x1, double y1, double x2, double y2, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname); /* insert an image*/
int createsvg(double x1, double y1, double x2, double y2, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname); /* insert a svg image*/
int ismousein(const char* view, YabInterface *yab, int line, const char* libname); /* check if mouse is in view */
char* getmousein(YabInterface *yab, int line, const char* libname); /* check which view the mouse is in */ //vasper
void drawtext(struct command *, YabInterface* yab); /* draw text */
void drawrect(struct command *, YabInterface* yab); /* draw rectangle */
void drawclear(struct command *, YabInterface* yab); /* clears canvas */
void createmenu(struct command *, YabInterface* yab); /* add a menu */
void createalert(struct command *, YabInterface* yab); /* alert */
void createtext(struct command *, YabInterface* yab); /* text */
void text2(struct command *, YabInterface* yab); /* text */
void textalign(struct command *, YabInterface* yab); /* align text */
void createtextcontrol(struct command *, YabInterface* yab); /* textcontrol */
void createcheckbox(struct command *, YabInterface* yab); /* checkbox*/
void createradiobutton(struct command *, YabInterface* yab); /* radio button */
void createlistbox(struct command *, YabInterface* yab); /* list box */
void createdropbox(struct command *, YabInterface* yab); /* drop box */
void createitem(struct command *, YabInterface* yab); /* item add*/
void removeitem(struct command *, YabInterface* yab); /* item del*/
void clearitems(struct command *, YabInterface* yab); /* clears itemlist */
void localize();
void localizestop();
void localize2(struct command *, YabInterface* yab);
void setlayout(struct command *, YabInterface* yab); /* set layout */
void winset1(struct command *, YabInterface* yab);
void winset2(struct command *, YabInterface* yab);
void winset3(struct command *, YabInterface* yab);
void winset4(struct command *, YabInterface* yab);
void winclear(struct command *, YabInterface* yab);
void textedit(struct command *, YabInterface* yab);
void textadd(struct command *, YabInterface* yab);
void textset(struct command *, YabInterface* yab);
void textset2(struct command *, YabInterface* yab);
void textset3(struct command *, YabInterface* yab);
void textcolor1(struct command *, YabInterface* yab);
void textcolor2(struct command *, YabInterface* yab);
void textclear(struct command *, YabInterface* yab);
char* textget(const char*, YabInterface* yab, int line, const char* libname);
int textget2(const char*, const char*, YabInterface* yab, int line, const char* libname);
char* textget3(const char*, int, YabInterface* yab, int line, const char* libname);
double textget4(const char*, const char*, int, YabInterface* yab, int line, const char* libname);
int textget5(const char*, const char*, const char*, YabInterface* yab, int line, const char* libname);
char* textget6(const char*, const char*, YabInterface *yab, int line, const char* libname);
char* textcontrolget(const char*, YabInterface* yab, int line, const char* libname);
void drawset1(struct command *, YabInterface* yab);
void drawset2(struct command *, YabInterface* yab);
char* getmessages(YabInterface* yab, int line, const char* libname); /* get message string */
char* getmousemessages(const char* view, YabInterface* yab, int line, const char* libname); /* get mouse message string */
char* gettranslation(const char*,YabInterface* yab, int line, const char* libname); /* get translation string */
char* getmenutranslation(const char*,YabInterface* yab, int line, const char* libname); /* get translation string */
char* getloadfilepanel(const char*, const char*, const char*, YabInterface *yab, int line, const char* libname); /* open a load filepanel */
char* getsavefilepanel(const char*, const char*, const char*, const char*, YabInterface *yab, int line, const char* libname); /* open a save filepanel */
void view(struct command *, YabInterface *yab); /* add a view */
void boxview(struct command *, YabInterface *yab); /* add a boxview */
void boxviewset(struct command *, YabInterface *yab);/*boxview options*/
void tab(struct command *, YabInterface *yab); /* add a tab */
void tabset(struct command *, YabInterface *yab); /* set a tab */
void tabadd(struct command *, YabInterface *yab);
void tabdel(struct command *, YabInterface *yab);
int tabviewget(const char* tab, YabInterface *yab, int line, const char* libname); /* get a tab */
void drawdot(struct command *, YabInterface *yab); /* draw a dot */
void drawline(struct command *, YabInterface *yab); /* draw a line */
void drawcircle(struct command *, YabInterface *yab); /* draw a circle */
void drawellipse(struct command *, YabInterface *yab); /* draw a ellipse */
void drawcurve(struct command *, YabInterface *yab); /* draw a curve */
void slider1(struct command *, YabInterface *yab);
void slider2(struct command *, YabInterface *yab);
void slider3(struct command *, YabInterface *yab);
void slider4(struct command *, YabInterface *yab);
void slider5(struct command *, YabInterface *yab);
void slider6(struct command *, YabInterface *yab);
void option1(struct command *, YabInterface *yab);
void option2(struct command *, YabInterface *yab);
void option3(struct command *, YabInterface *yab);
void dropzone(struct command *, YabInterface *yab);
void colorcontrol1(struct command *, YabInterface *yab);
void colorcontrol2(struct command *, YabInterface *yab);
void textcontrol2(struct command *, YabInterface *yab);
void textcontrol3(struct command *, YabInterface *yab);
void textcontrol4(struct command *, YabInterface *yab);
void textcontrol5(struct command *, YabInterface *yab);
void treebox1(struct command *, YabInterface *yab);
void treebox2(struct command *, YabInterface *yab);
void treebox3(struct command *, YabInterface *yab);
void treebox4(struct command *, YabInterface *yab);
void treebox5(struct command *, YabInterface *yab);
void treebox7(struct command *, YabInterface *yab);
void treebox8(struct command *, YabInterface *yab);
void treebox9(struct command *, YabInterface *yab);
void treebox10(struct command *, YabInterface *yab);
void treebox11(struct command *, YabInterface *yab);
void buttonimage(struct command *, YabInterface *yab);
void checkboximage(struct command *, YabInterface *yab);
void checkboxset(struct command *, YabInterface *yab);
void radioset(struct command *, YabInterface *yab);
void tooltip(struct command *, YabInterface *yab);
void tooltipcolor(struct command *, YabInterface *yab);
void listsort(struct command *, YabInterface *yab);
void treesort(struct command *, YabInterface *yab);
void filebox(struct command *, YabInterface *yab);
void fileboxadd2(struct command *, YabInterface *yab);
void fileboxclear(struct command *, YabInterface *yab);
void columnboxadd(struct command *, YabInterface *yab);
void columnboxremove(struct command *, YabInterface *yab);
void columnboxselect(struct command *, YabInterface *yab);
void columnboxcolor(struct command *, YabInterface *yab);
void dropboxselect(struct command *, YabInterface *yab);
void menu2(struct command *, YabInterface *yab);
void submenu1(struct command *, YabInterface *yab);
void submenu2(struct command *, YabInterface *yab);
void clipboardcopy(struct command *, YabInterface *yab);
void launch(struct command *, YabInterface *yab);
int printer(const char* docname, const char *view, const char* config, YabInterface *yab, int line, const char* libname);
void printerconfig(struct command *, YabInterface *yab);
char* keyboardmessages(const char* view, YabInterface* yab, int line, const char* libname);
char* clipboardpaste(YabInterface* yab, int line, const char* libname);
char* columnboxget(const char* columnbox, int column, int position, YabInterface* yab, int line, const char* libname);
int columnboxcount(const char* columnbox, YabInterface* yab, int line, const char* libname);
int windowgetnum(const char* view, const char *option, YabInterface* yab, int line, const char* libname);
int viewgetnum(const char* view, const char *option, YabInterface* yab, int line, const char* libname); //vasper
int newalert(const char* text, const char* button1, const char* button2, const char* button3, const char* option, YabInterface* yab, int line, const char* libname);
void calendar1(struct command *, YabInterface *yab);
char* calendar2(const char* calendar, YabInterface *yab, int line, const char* libname);
void calendar3(struct command *, YabInterface *yab);
void listboxadd1(struct command *, YabInterface *yab);
void listboxadd2(struct command *, YabInterface *yab);
void listboxselect(struct command *, YabInterface *yab);
void listboxremove(struct command *, YabInterface *yab);
int listboxcount(const char* listbox, YabInterface *yab, int line, const char* libname);
char* treeboxget(const char* treebox, int position, YabInterface *yab, int line, const char* libname);
int treeboxcount(const char* treebox, YabInterface *yab, int line, const char* libname);
char* listboxget(const char* listbox, int position, YabInterface *yab, int line, const char* libname);
void scrollbar(struct command *, YabInterface *yab);
void scrollbarset1(struct command *, YabInterface *yab);
void scrollbarset2(struct command *, YabInterface *yab);
void scrollbarset3(struct command *, YabInterface *yab);
double scrollbarget(const char* scrollbar, const char* option, YabInterface *yab, int line, const char* libname);
void splitview1(struct command *, YabInterface *yab);
void splitview2(struct command *, YabInterface *yab);
void splitview3(struct command *, YabInterface *yab);
double splitviewget(const char* splitview, const char* option, YabInterface *yab, int line, const char* libname);
void stackview1(struct command *, YabInterface *yab);
void stackview2(struct command *, YabInterface *yab);
int stackviewget(const char* stackview, YabInterface *yab, int line, const char* libname);
void texturl1(struct command *, YabInterface *yab);
void texturl2(struct command *, YabInterface *yab);
void drawset3(struct command *, YabInterface *yab);
void spincontrol1(struct command *, YabInterface *yab);
void spincontrol2(struct command *, YabInterface *yab);
int spincontrol(const char* spincontrol, YabInterface *yab, int line, const char* libname);
char* popupmenu(double x, double y, const char* messages, const char* id, YabInterface *yab, int line, const char* libname);
void dropboxremove(struct command *, YabInterface *yab);
void dropboxclear(struct command *, YabInterface *yab);
int dropboxcount(const char* id, YabInterface *yab, int line, const char* libname);
char* dropboxget(const char* id, int position, YabInterface *yab, int line, const char* libname);
int sliderget(const char *slider, YabInterface *yab, int line, const char* libname);
int colorcontrolget(const char* colorcontrol, const char* option, YabInterface *yab, int line, const char* libname);
void submenu3(struct command *, YabInterface *yab);
void menu3(struct command *, YabInterface *yab);
double drawget1(const char*, const char*, const char*, YabInterface *yab, int line, const char* libname);
double drawget2(const char*, const char*, YabInterface *yab, int line, const char* libname);
char* drawget3(const char*, YabInterface *yab, int line, const char* libname);
int drawget4(double, double, const char*, const char*, YabInterface *yab, int line, const char* libname);
void option4(struct command *, YabInterface *yab);
void option5(struct command *, YabInterface *yab);
void treebox12(struct command *, YabInterface *yab);
int messagesend(const char*, const char*, YabInterface *yab, int line, const char* libname);
int threadkill(const char*, int, YabInterface *yab, int line, const char* libname);
int threadget(const char*, const char*, YabInterface *yab, int line, const char* libname);
void bitmap(struct command *, YabInterface *yab);
void bitmapdraw(struct command *, YabInterface *yab);
void bitmapdraw2(struct command *, YabInterface *yab);
void bitmapget(struct command *, YabInterface *yab);
void bitmapget2(struct command *, YabInterface *yab);
void bitmapgeticon(struct command *, YabInterface *yab);
void bitmapdrag(struct command *, YabInterface *yab);
void bitmapremove(struct command *, YabInterface *yab);
void screenshot(struct command *, YabInterface *yab);
void statusbar(struct command *, YabInterface *yab);
void statusbarset(struct command *, YabInterface *yab);
void statusbarset2(struct command *, YabInterface *yab);
void statusbarset3(struct command *, YabInterface *yab);
void canvas(struct command *, YabInterface *yab);
int bitmapsave(const char*, const char*, const char*, YabInterface *yab, int line, const char* libname);
int bitmapload(const char*, const char*, YabInterface *yab, int line, const char* libname);
int bitmapgetnum(const char*, const char*, YabInterface *yab, int line, const char* libname);
int bitmapcolor(double x, double y, const char* id, const char* option, YabInterface *yab, int line, const char* libname);
int listboxgetnum(const char*, YabInterface *yab, int line, const char* libname);
int dropboxgetnum(const char*, YabInterface *yab, int line, const char* libname);
int columnboxgetnum(const char*, YabInterface *yab, int line, const char* libname);
int treeboxgetnum(const char*, YabInterface *yab, int line, const char* libname);
int treeboxgetopt(const char*, const char*, int, YabInterface *yab, int line, const char* libname);
void treebox13(struct command *, YabInterface *yab);
void drawset4(struct command *, YabInterface *yab);
int sound(const char*, YabInterface *yab, int line, const char* libname);
void soundstop(struct command *, YabInterface *yab);
void soundwait(struct command *, YabInterface *yab);
void shortcut(struct command *, YabInterface *yab);
int iscomputeron(YabInterface *yab, int line, const char* libname);
void mouseset(struct command *, YabInterface *yab);
void gettermkey(char *); /* read a key from terminal */
void attribute1(struct command *, YabInterface *yab);
void attributeclear(struct command *, YabInterface *yab);
char* attributeget1(const char*, const char*, YabInterface *yab, int line, const char* libname);
double attributeget2(const char*, const char*, YabInterface *yab, int line, const char* libname);
/* function.c */
void create_exception(int); /* create command 'exception' */
void exception(struct command *); /* change handling of exceptions */
void create_poke(char); /* create Command 'POKE' */
void poke(); /* poke in internals */
void pokefile(struct command *); /* poke into file */
void create_dblrelop(char); /* create command dblrelop */
void dblrelop(struct command *); /* compare topmost double-values */
void concat(void); /* concetenates two strings from stack */
void create_strrelop(char); /* create command strrelop */
void strrelop(struct command *); /* compare topmost string-values */
void create_changestring(int); /* create command 'changestring' */
void changestring(struct command *); /* changes a string */
void glob(void); /* check, if pattern globs string */
void create_boole(char); /* create command boole */
void boole(struct command *); /* perform and/or/not */
void create_function(int); /* create command 'function' */
void function(struct command *, YabInterface* yab); /* performs a function */
int myformat(char *,double,char *,char *); /* format number */
void create_restore(char *); /* create command 'restore' */
void restore(struct command *); /* reset data pointer to given label */
void create_dbldata(double); /* create command dbldata */
void create_strdata(char *); /* create command strdata */
void create_readdata(char); /* create command readdata */
void readdata(struct command *); /* read data items */
void mywait(); /* wait given number of seconds */
void mybell(); /* ring ascii bell */
void getmousexybm(char *,int *,int *,int *,int *); /* get mouse coordinates */
void token(struct command *); /* extract token from variable */
void tokenalt(struct command *); /* extract token from variable with alternate semantics */
/* symbol.c */
struct array *create_array(int,int); /* create an array */
void clearrefs(struct command *); /* clear references for commands within function */
void duplicate(void); /* duplicate topmost element of stack */
void negate(void); /* negates top of stack */
void create_require(int); /* create command 'cREQUIRE' */
void require(struct command *); /* check item on stack has right type */
void create_makelocal(char *,int); /* create command 'cMAKELOCAL' */
void create_makestatic(char *,int); /* create command 'cMAKESTATIC' */
void create_arraylink(char *,int); /* create command 'cARRAYLINK' */
void create_pusharrayref(char *,int); /* create command 'cPUSHARRAYREF' */
void pusharrayref(struct command *); /* push an array reference onto stack */
void arraylink(struct command *); /* link a local symbol to a global array */
void makestatic(struct command *); /* makes symbol static */
void makelocal(struct command *); /* makes symbol local */
void create_numparam(void); /* create command 'cNUMPARAM' */
void numparam(struct command *); /* count number of function parameters */
void pushdblsym(struct command *); /* push double symbol onto stack */
void popdblsym(struct command *); /* pop double from stack */
void create_pushdbl(double); /* create command 'pushdbl' */
void pushdbl(struct command *); /* push double onto stack */
void create_dblbin(char); /* create binary expression calculation */
void dblbin(struct command *); /* compute with two numbers from stack */
void pushstrsym(struct command *); /* push string symbol onto stack */
void popstrsym(struct command *); /* pop string from stack */
void create_pushstr(char *); /* creates command pushstr */
void pushstr(struct command *); /* push string onto stack */
void pushname(char *); /* push a name on stack */
void pushstrptr(struct command *); /* push string-pointer onto stack */
void forcheck(void); /* check, if for-loop is done */
void forincrement(void); /* increment value on stack */
void startfor(void); /* compute initial value of for-variable */
void create_goto(char *); /* creates command goto */
void create_gosub(char *); /* creates command gosub */
void create_call(char *); /* creates command function call */
void create_label(char *,int); /* creates command label */
void create_sublink(char *); /* create link to subroutine */
void pushgoto(void); /* generate label and push goto on stack */
void popgoto(void); /* pops a goto and generates the matching command */
void jump(struct command *); /* jump to specific Label */
void myreturn(struct command *); /* return from gosub */
void findnop(); /* used for on_gosub, find trailing nop command */
void skipper(void); /* used for on_goto/gosub, skip commands */
void skiponce(struct command *); /* skip next command once */
void resetskiponce(struct command *); /* find and reset next skip */
void decide(void); /* skips next command, if not 0 on stack */
void logical_shortcut(struct command *type); /* shortcut and/or if possible */
void create_doarray(char *,int); /* creates array-commands */
void doarray(struct command *); /* call an array */
void create_dim(char *,char); /* create command 'dim' */
void dim(struct command *); /* get room for array */
void pushlabel(void); /* generate goto and push label on stack */
void poplabel(void); /* pops a label and generates the matching command */
void storelabel(); /* push label on stack */
void matchgoto(); /* generate goto matching label on stack */
void swap(void); /*swap topmost elements on stack */
struct stackentry *push(void); /* push element on stack and enlarge it*/
struct stackentry *pop(int); /* pops element to memory */
struct symbol *get_sym(char *,int,int); /* find and/or add a symbol */
void link_symbols(struct symbol *,struct symbol *); /* link one symbol to the other */
void pushsymlist(void); /* push a new list on symbol stack */
void popsymlist(void); /* pop list of symbols and free symbol contents */
void dump_sym(); /* dump the stack of lists of symbols */
void dump_sub(int); /* dump the stack of subroutine calls */
void create_retval(int,int); /* create command 'cRETVAL' */
void retval(struct command *); /* check return value of function */
void create_endfunction(void); /* create command cEND_FUNCTION */
void function_or_array(struct command *); /* decide whether to do perform function or array */
struct command *search_label(char *,int); /* search label */
void reshufflestack(struct stackentry *); /* reorganize stack for function call */
void push_switch_mark(void); /* push a switch mark */
void create_clean_switch_mark(int,int); /* add command clean_switch_mark */
void clean_switch_mark(struct command *); /* pop everything up to (and including) first switch_mark from stack */
void push_switch_id(void); /* generate a new switch id */
void pop_switch_id(void); /* get previous switch id */
int get_switch_depth(void); /* get current depth of switch id stack */
/* flex.c */
void yyerror(char *); /* yyerror message */
void open_main(FILE *,char *,char *); /* switch to file */
void open_string(char *); /* open string with commands */
FILE *open_library(char *,char **,int); /* search and open a library */
void switchlib(void); /* switch library, called by bison */