diff --git a/src/CalendarControl.cpp b/src/CalendarControl.cpp deleted file mode 100644 index 6c7e5a7..0000000 --- a/src/CalendarControl.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// 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 -#include -#include -#include -#include -#include - - -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); -} diff --git a/src/CalendarControl.h b/src/CalendarControl.h deleted file mode 100644 index 005b132..0000000 --- a/src/CalendarControl.h +++ /dev/null @@ -1,97 +0,0 @@ -// 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 -#include -#include -#include - -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; -}; - diff --git a/src/ControlLook.cpp b/src/ControlLook.cpp deleted file mode 100644 index 984502e..0000000 --- a/src/ControlLook.cpp +++ /dev/null @@ -1,2293 +0,0 @@ -/* - * Copyright 2009, Stephan Aßmus - * Distributed under the terms of the MIT License. - */ -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace BPrivate { - -static const float kEdgeBevelLightTint = 0.59; -static const float kEdgeBevelShadowTint = 1.0735; - - -BControlLook::BControlLook() -{ -} - - -BControlLook::~BControlLook() -{ -} - - -BAlignment -BControlLook::DefaultLabelAlignment() const -{ - return BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); -} - - -float -BControlLook::DefaultLabelSpacing() const -{ - return 4.0;//ceilf(be_plain_font->Size() / 4.0); -} - - -uint32 -BControlLook::Flags(BControl* control) const -{ - uint32 flags = 0; - - if (!control->IsEnabled()) - flags |= B_DISABLED; - - if (control->IsFocus()) - flags |= B_FOCUSED; - - if (control->Value() == B_CONTROL_ON) - flags |= B_ACTIVATED; - - return flags; -} - - -// #pragma mark - - - -void -BControlLook::DrawButtonFrame(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, const rgb_color& background, uint32 flags, - uint32 borders) -{ - _DrawButtonFrame(view, rect, updateRect, base, background, 1.0, 1.0, flags, - borders); -} - - -void -BControlLook::DrawButtonBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders, enum orientation orientation) -{ - if (!rect.IsValid() || !updateRect.Intersects(rect)) - return; - - // the surface edges - - // colors - rgb_color buttonBgColor = tint_color(base, B_LIGHTEN_1_TINT); - rgb_color maxLightColor; - - rgb_color bevelColor1; - rgb_color bevelColor2; - - if ((flags & B_DISABLED) == 0) { - maxLightColor = tint_color(base, 0.2); - bevelColor1 = tint_color(base, 1.08); - bevelColor2 = base; - } else { - maxLightColor = tint_color(base, 0.7); - bevelColor1 = base; - bevelColor2 = buttonBgColor; - buttonBgColor = maxLightColor; - } - - if (flags & B_ACTIVATED) { - view->BeginLineArray(4); - - bevelColor1 = tint_color(bevelColor1, B_DARKEN_1_TINT); - bevelColor2 = tint_color(bevelColor2, B_DARKEN_1_TINT); - - // shadow along left/top borders - if (borders & B_LEFT_BORDER) { - view->AddLine(BPoint(rect.left, rect.top), - BPoint(rect.left, rect.bottom), bevelColor1); - rect.left++; - } - if (borders & B_TOP_BORDER) { - view->AddLine(BPoint(rect.left, rect.top), - BPoint(rect.right, rect.top), bevelColor1); - rect.top++; - } - - // softer shadow along left/top borders - if (borders & B_LEFT_BORDER) { - view->AddLine(BPoint(rect.left, rect.top), - BPoint(rect.left, rect.bottom), bevelColor2); - rect.left++; - } - if (borders & B_TOP_BORDER) { - view->AddLine(BPoint(rect.left, rect.top), - BPoint(rect.right, rect.top), bevelColor2); - rect.top++; - } - - view->EndLineArray(); - } else { - _DrawFrame(view, rect, - maxLightColor, maxLightColor, - bevelColor1, bevelColor1, - buttonBgColor, buttonBgColor, borders); - } - - // the actual surface top - - float topTint = 0.49; - float middleTint1 = 0.62; - float middleTint2 = 0.76; - float bottomTint = 0.90; - - if (flags & B_ACTIVATED) { - topTint = 1.11; - bottomTint = 1.08; - } - - if (flags & B_DISABLED) { - topTint = (topTint + B_NO_TINT) / 2; - middleTint1 = (middleTint1 + B_NO_TINT) / 2; - middleTint2 = (middleTint2 + B_NO_TINT) / 2; - bottomTint = (bottomTint + B_NO_TINT) / 2; - } else if (flags & B_HOVER) { - static const float kHoverTintFactor = 0.85; - topTint *= kHoverTintFactor; - middleTint1 *= kHoverTintFactor; - middleTint2 *= kHoverTintFactor; - bottomTint *= kHoverTintFactor; - } - - if (flags & B_ACTIVATED) { - _FillGradient(view, rect, base, topTint, bottomTint, orientation); - } else { - _FillGlossyGradient(view, rect, base, topTint, middleTint1, - middleTint2, bottomTint, orientation); - } -} - - -void -BControlLook::DrawMenuBarBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - if (!rect.IsValid() || !updateRect.Intersects(rect)) - return; - - // the surface edges - - // colors - float topTint; - float bottomTint; - - if (flags & B_ACTIVATED) { - rgb_color bevelColor1 = tint_color(base, 1.40); - rgb_color bevelColor2 = tint_color(base, 1.25); - - topTint = 1.25; - bottomTint = 1.20; - - _DrawFrame(view, rect, - bevelColor1, bevelColor1, - bevelColor2, bevelColor2, - borders & B_TOP_BORDER); - } else { - rgb_color cornerColor = tint_color(base, 0.9); - rgb_color bevelColorTop = tint_color(base, 0.5); - rgb_color bevelColorLeft = tint_color(base, 0.7); - rgb_color bevelColorRightBottom = tint_color(base, 1.08); - - topTint = 0.69; - bottomTint = 1.03; - - _DrawFrame(view, rect, - bevelColorLeft, bevelColorTop, - bevelColorRightBottom, bevelColorRightBottom, - cornerColor, cornerColor, - borders); - } - - // the actual surface top - - _FillGradient(view, rect, base, topTint, bottomTint); -} - - -void -BControlLook::DrawMenuFieldFrame(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, - const rgb_color& background, uint32 flags, uint32 borders) -{ - _DrawButtonFrame(view, rect, updateRect, base, background, 0.6, 1.0, flags, - borders); -} - - -void -BControlLook::DrawMenuFieldBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, bool popupIndicator, - uint32 flags) -{ - if (popupIndicator) { - BRect leftRect(rect); - leftRect.right -= 10; - - BRect rightRect(rect); - rightRect.left = rightRect.right - 9; - - DrawMenuFieldBackground(view, leftRect, updateRect, base, flags, - B_LEFT_BORDER | B_TOP_BORDER | B_BOTTOM_BORDER); - - rgb_color indicatorBase; - rgb_color markColor; - if (flags & B_DISABLED) { - indicatorBase = tint_color(base, 1.05); - markColor = tint_color(base, 1.35); - } else { - indicatorBase = tint_color(base, 1.12); - markColor = tint_color(base, 1.65); - } - - DrawMenuFieldBackground(view, rightRect, updateRect, indicatorBase, - flags, B_RIGHT_BORDER | B_TOP_BORDER | B_BOTTOM_BORDER); - - // popup marker - BPoint center(roundf((rightRect.left + rightRect.right) / 2.0), - roundf((rightRect.top + rightRect.bottom) / 2.0)); - BPoint triangle[3]; - triangle[0] = center + BPoint(-2.5, -0.5); - triangle[1] = center + BPoint(2.5, -0.5); - triangle[2] = center + BPoint(0.0, 2.0); - - uint32 viewFlags = view->Flags(); - view->SetFlags(viewFlags | B_SUBPIXEL_PRECISE); - - view->SetHighColor(markColor); - view->FillTriangle(triangle[0], triangle[1], triangle[2]); - - view->SetFlags(viewFlags); - - rect = leftRect; - } else { - DrawMenuFieldBackground(view, rect, updateRect, base, flags); - } -} - -void -BControlLook::DrawMenuFieldBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - if (!rect.IsValid() || !updateRect.Intersects(rect)) - return; - - // the surface edges - - // colors - rgb_color cornerColor = tint_color(base, 0.85); - rgb_color bevelColor1 = tint_color(base, 0.3); - rgb_color bevelColor2 = tint_color(base, 0.5); - rgb_color bevelColor3 = tint_color(base, 1.03); - - if (flags & B_DISABLED) { - cornerColor = tint_color(base, 0.8); - bevelColor1 = tint_color(base, 0.7); - bevelColor2 = tint_color(base, 0.8); - bevelColor3 = tint_color(base, 1.01); - } else { - cornerColor = tint_color(base, 0.85); - bevelColor1 = tint_color(base, 0.3); - bevelColor2 = tint_color(base, 0.5); - bevelColor3 = tint_color(base, 1.03); - } - - _DrawFrame(view, rect, - bevelColor2, bevelColor1, - bevelColor3, bevelColor3, - cornerColor, cornerColor, - borders); - - // the actual surface top - - float topTint = 0.49; - float middleTint1 = 0.62; - float middleTint2 = 0.76; - float bottomTint = 0.90; - - if (flags & B_DISABLED) { - topTint = (topTint + B_NO_TINT) / 2; - middleTint1 = (middleTint1 + B_NO_TINT) / 2; - middleTint2 = (middleTint2 + B_NO_TINT) / 2; - bottomTint = (bottomTint + B_NO_TINT) / 2; - } else if (flags & B_HOVER) { - static const float kHoverTintFactor = 0.85; - topTint *= kHoverTintFactor; - middleTint1 *= kHoverTintFactor; - middleTint2 *= kHoverTintFactor; - bottomTint *= kHoverTintFactor; - } - - _FillGlossyGradient(view, rect, base, topTint, middleTint1, - middleTint2, bottomTint); -} - -void -BControlLook::DrawMenuBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - if (!rect.IsValid() || !updateRect.Intersects(rect)) - return; - - // the surface edges - - rgb_color bevelLightColor; - rgb_color bevelShadowColor; - rgb_color background = tint_color(base, 0.75); - - if (flags & B_DISABLED) { - bevelLightColor = tint_color(background, 0.80); - bevelShadowColor = tint_color(background, 1.07); - } else { - bevelLightColor = tint_color(background, 0.6); - bevelShadowColor = tint_color(background, 1.12); - } - - _DrawFrame(view, rect, - bevelLightColor, bevelLightColor, - bevelShadowColor, bevelShadowColor, - borders); - - // the actual surface top - - view->SetHighColor(background); - view->FillRect(rect); -} - - -void -BControlLook::DrawMenuItemBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - if (!rect.IsValid() || !updateRect.Intersects(rect)) - return; - - // the surface edges - - float topTint; - float bottomTint; - rgb_color selectedColor = base; - - if (flags & B_ACTIVATED) { - topTint = 0.9; - bottomTint = 1.05; - selectedColor = tint_color(base, 1.26); - } else if (flags & B_DISABLED) { - topTint = 0.80; - bottomTint = 1.07; - } else { - topTint = 0.6; - bottomTint = 1.12; - } - - rgb_color bevelLightColor = tint_color(selectedColor, topTint); - rgb_color bevelShadowColor = tint_color(selectedColor, bottomTint); - - _DrawFrame(view, rect, - bevelLightColor, bevelLightColor, - bevelShadowColor, bevelShadowColor, - borders); - - // the actual surface top - - view->SetLowColor(selectedColor); -// _FillGradient(view, rect, selectedColor, topTint, bottomTint); - _FillGradient(view, rect, selectedColor, bottomTint, topTint); -} - - -void -BControlLook::DrawStatusBar(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, const rgb_color& barColor, float progressPosition) -{ - if (!rect.Intersects(updateRect)) - return; - - _DrawOuterResessedFrame(view, rect, base, 0.6); - - // colors - rgb_color dark1BorderColor = tint_color(base, 1.3); - rgb_color dark2BorderColor = tint_color(base, 1.2); - rgb_color dark1FilledBorderColor = tint_color(barColor, 1.20); - rgb_color dark2FilledBorderColor = tint_color(barColor, 1.45); - - BRect filledRect(rect); - filledRect.right = progressPosition - 1; - - BRect nonfilledRect(rect); - nonfilledRect.left = progressPosition; - - bool filledSurface = filledRect.Width() > 0; - bool nonfilledSurface = nonfilledRect.Width() > 0; - - if (filledSurface) { - _DrawFrame(view, filledRect, - dark1FilledBorderColor, dark1FilledBorderColor, - dark2FilledBorderColor, dark2FilledBorderColor); - - _FillGlossyGradient(view, filledRect, barColor, 0.55, 0.68, 0.76, 0.90); - } - - if (nonfilledSurface) { - _DrawFrame(view, nonfilledRect, dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor, - B_TOP_BORDER | B_BOTTOM_BORDER | B_RIGHT_BORDER); - - if (nonfilledRect.left < nonfilledRect.right) { - // shadow from fill bar, or left border - rgb_color leftBorder = dark1BorderColor; - if (filledSurface) - leftBorder = tint_color(base, 0.50); - view->SetHighColor(leftBorder); - view->StrokeLine(nonfilledRect.LeftTop(), - nonfilledRect.LeftBottom()); - nonfilledRect.left++; - } - - _FillGradient(view, nonfilledRect, base, 0.25, 0.06); - } -} - - -void -BControlLook::DrawCheckBox(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, uint32 flags) -{ - if (!rect.Intersects(updateRect)) - return; - - rgb_color dark1BorderColor; - rgb_color dark2BorderColor; - rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - - if (flags & B_DISABLED) { - _DrawOuterResessedFrame(view, rect, base, 0.0, 1.0, flags); - - dark1BorderColor = tint_color(base, 1.15); - dark2BorderColor = tint_color(base, 1.15); - } else if (flags & B_CLICKED) { - dark1BorderColor = tint_color(base, 1.50); - dark2BorderColor = tint_color(base, 1.48); - - _DrawFrame(view, rect, - dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor); - - dark2BorderColor = dark1BorderColor; - } else { - _DrawOuterResessedFrame(view, rect, base, 0.6, 1.0, flags); - - dark1BorderColor = tint_color(base, 1.40); - dark2BorderColor = tint_color(base, 1.38); - } - - if (flags & B_FOCUSED) { - dark1BorderColor = navigationColor; - dark2BorderColor = navigationColor; - } - - _DrawFrame(view, rect, - dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor); - - if (flags & B_DISABLED) { - _FillGradient(view, rect, base, 0.4, 0.2); - } else { - _FillGradient(view, rect, base, 0.15, 0.0); - } - - rgb_color markColor; - if (_RadioButtonAndCheckBoxMarkColor(base, markColor, flags)) { - view->SetHighColor(markColor); - - rect.InsetBy(2, 2); - view->SetPenSize(max_c(1.0, ceilf(rect.Width() / 3.5))); - view->SetDrawingMode(B_OP_OVER); - - view->StrokeLine(rect.LeftTop(), rect.RightBottom()); - view->StrokeLine(rect.LeftBottom(), rect.RightTop()); - } -} - - -void -BControlLook::DrawRadioButton(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, uint32 flags) -{ - if (!rect.Intersects(updateRect)) - return; - - rgb_color borderColor; - rgb_color bevelLight; - rgb_color bevelShadow; - rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - - if (flags & B_DISABLED) { - borderColor = tint_color(base, 1.15); - bevelLight = base; - bevelShadow = base; - } else if (flags & B_CLICKED) { - borderColor = tint_color(base, 1.50); - bevelLight = borderColor; - bevelShadow = borderColor; - } else { - borderColor = tint_color(base, 1.45); - bevelLight = tint_color(base, 0.55); - bevelShadow = tint_color(base, 1.11); - } - - if (flags & B_FOCUSED) { - borderColor = navigationColor; - } - - BGradientLinear bevelGradient; - bevelGradient.AddColor(bevelShadow, 0); - bevelGradient.AddColor(bevelLight, 255); - bevelGradient.SetStart(rect.LeftTop()); - bevelGradient.SetEnd(rect.RightBottom()); - - view->FillEllipse(rect, bevelGradient); - rect.InsetBy(1, 1); - - bevelGradient.MakeEmpty(); - bevelGradient.AddColor(borderColor, 0); - bevelGradient.AddColor(tint_color(borderColor, 0.8), 255); - view->FillEllipse(rect, bevelGradient); - rect.InsetBy(1, 1); - - float topTint; - float bottomTint; - if (flags & B_DISABLED) { - topTint = 0.4; - bottomTint = 0.2; - } else { - topTint = 0.15; - bottomTint = 0.0; - } - - BGradientLinear gradient; - _MakeGradient(gradient, rect, base, topTint, bottomTint); - view->FillEllipse(rect, gradient); - - rgb_color markColor; - if (_RadioButtonAndCheckBoxMarkColor(base, markColor, flags)) { - view->SetHighColor(markColor); - rect.InsetBy(3, 3); - view->FillEllipse(rect); - } -} - - -void -BControlLook::DrawScrollBarBackground(BView* view, BRect& rect1, BRect& rect2, - const BRect& updateRect, const rgb_color& base, uint32 flags, - enum orientation orientation) -{ - DrawScrollBarBackground(view, rect1, updateRect, base, flags, orientation); - DrawScrollBarBackground(view, rect2, updateRect, base, flags, orientation); -} - -void -BControlLook::DrawScrollBarBackground(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - float gradient1Tint; - float gradient2Tint; - float darkEdge1Tint; - float darkEdge2Tint; - float shadowTint; - - if (flags & B_DISABLED) { - gradient1Tint = 0.9; - gradient2Tint = 0.8; - darkEdge1Tint = B_DARKEN_2_TINT; - darkEdge2Tint = B_DARKEN_2_TINT; - shadowTint = gradient1Tint; - } else { - gradient1Tint = 1.10; - gradient2Tint = 1.05; - darkEdge1Tint = B_DARKEN_3_TINT; - darkEdge2Tint = B_DARKEN_2_TINT; - shadowTint = gradient1Tint; - } - - rgb_color darkEdge1 = tint_color(base, darkEdge1Tint); - rgb_color darkEdge2 = tint_color(base, darkEdge2Tint); - rgb_color shadow = tint_color(base, shadowTint); - - if (orientation == B_HORIZONTAL) { - // dark vertical line on left edge - if (rect.Width() > 0) { - view->SetHighColor(darkEdge1); - view->StrokeLine(rect.LeftTop(), rect.LeftBottom()); - rect.left++; - } - // dark vertical line on right edge - if (rect.Width() >= 0) { - view->SetHighColor(darkEdge2); - view->StrokeLine(rect.RightTop(), rect.RightBottom()); - rect.right--; - } - // vertical shadow line after left edge - if (rect.Width() >= 0) { - view->SetHighColor(shadow); - view->StrokeLine(rect.LeftTop(), rect.LeftBottom()); - rect.left++; - } - // fill - if (rect.Width() >= 0) { - _FillGradient(view, rect, base, gradient1Tint, gradient2Tint, - orientation); - } - } else { - // dark vertical line on top edge - if (rect.Height() > 0) { - view->SetHighColor(darkEdge1); - view->StrokeLine(rect.LeftTop(), rect.RightTop()); - rect.top++; - } - // dark vertical line on bottom edge - if (rect.Height() >= 0) { - view->SetHighColor(darkEdge2); - view->StrokeLine(rect.LeftBottom(), rect.RightBottom()); - rect.bottom--; - } - // horizontal shadow line after top edge - if (rect.Height() >= 0) { - view->SetHighColor(shadow); - view->StrokeLine(rect.LeftTop(), rect.RightTop()); - rect.top++; - } - // fill - if (rect.Height() >= 0) { - _FillGradient(view, rect, base, gradient1Tint, gradient2Tint, - orientation); - } - } -} - - -void -BControlLook::DrawScrollViewFrame(BView* view, BRect& rect, - const BRect& updateRect, BRect verticalScrollBarFrame, - BRect horizontalScrollBarFrame, const rgb_color& base, - border_style border, uint32 flags, uint32 _borders) -{ - // calculate scroll corner rect before messing with the "rect" - BRect scrollCornerFillRect(rect.right, rect.bottom, - rect.right, rect.bottom); - if (horizontalScrollBarFrame.IsValid()) - scrollCornerFillRect.left = horizontalScrollBarFrame.right + 1; - if (verticalScrollBarFrame.IsValid()) - scrollCornerFillRect.top = verticalScrollBarFrame.bottom + 1; - - if (border == B_NO_BORDER) { - if (scrollCornerFillRect.IsValid()) { - view->SetHighColor(base); - view->FillRect(scrollCornerFillRect); - } - return; - } - - bool excludeScrollCorner = border == B_FANCY_BORDER - && horizontalScrollBarFrame.IsValid() - && verticalScrollBarFrame.IsValid(); - - uint32 borders = _borders; - if (excludeScrollCorner) { - rect.bottom = horizontalScrollBarFrame.top; - rect.right = verticalScrollBarFrame.left; - borders &= ~(B_RIGHT_BORDER | B_BOTTOM_BORDER); - } - - rgb_color scrollbarFrameColor = tint_color(base, B_DARKEN_2_TINT); - - if (border == B_FANCY_BORDER) - _DrawOuterResessedFrame(view, rect, base, 1.0, 1.0, flags, borders); - - if (flags & B_FOCUSED) { - rgb_color focusColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - _DrawFrame(view, rect, focusColor, focusColor, focusColor, focusColor, - borders); - } else { - _DrawFrame(view, rect, scrollbarFrameColor, scrollbarFrameColor, - scrollbarFrameColor, scrollbarFrameColor, borders); - } - - if (excludeScrollCorner) { - horizontalScrollBarFrame.InsetBy(-1, -1); - // do not overdraw the top edge - horizontalScrollBarFrame.top += 2; - borders = _borders; - borders &= ~B_TOP_BORDER; - _DrawOuterResessedFrame(view, horizontalScrollBarFrame, base, - 1.0, 1.0, flags, borders); - _DrawFrame(view, horizontalScrollBarFrame, scrollbarFrameColor, - scrollbarFrameColor, scrollbarFrameColor, scrollbarFrameColor, - borders); - - - verticalScrollBarFrame.InsetBy(-1, -1); - // do not overdraw the left edge - verticalScrollBarFrame.left += 2; - borders = _borders; - borders &= ~B_LEFT_BORDER; - _DrawOuterResessedFrame(view, verticalScrollBarFrame, base, - 1.0, 1.0, flags, borders); - _DrawFrame(view, verticalScrollBarFrame, scrollbarFrameColor, - scrollbarFrameColor, scrollbarFrameColor, scrollbarFrameColor, - borders); - - // exclude recessed frame - scrollCornerFillRect.top++; - scrollCornerFillRect.left++; - } - - if (scrollCornerFillRect.IsValid()) { - view->SetHighColor(base); - view->FillRect(scrollCornerFillRect); - } -} - - -void -BControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, uint32 direction, uint32 flags, float tint) -{ - BPoint tri1, tri2, tri3; - float hInset = rect.Width() / 3; - float vInset = rect.Height() / 3; - rect.InsetBy(hInset, vInset); - - switch (direction) { - case B_LEFT_ARROW: - tri1.Set(rect.right, rect.top); - tri2.Set(rect.right - rect.Width() / 1.33, - (rect.top + rect.bottom + 1) /2 ); - tri3.Set(rect.right, rect.bottom + 1); - break; - case B_RIGHT_ARROW: - tri1.Set(rect.left, rect.bottom + 1); - tri2.Set(rect.left + rect.Width() / 1.33, - (rect.top + rect.bottom + 1) / 2); - tri3.Set(rect.left, rect.top); - break; - case B_UP_ARROW: - tri1.Set(rect.left, rect.bottom); - tri2.Set((rect.left + rect.right + 1) / 2, - rect.bottom - rect.Height() / 1.33); - tri3.Set(rect.right + 1, rect.bottom); - break; - case B_DOWN_ARROW: - default: - tri1.Set(rect.left, rect.top); - tri2.Set((rect.left + rect.right + 1) / 2, - rect.top + rect.Height() / 1.33); - tri3.Set(rect.right + 1, rect.top); - break; - } - // offset triangle if down - if (flags & B_ACTIVATED) - view->MovePenTo(BPoint(1, 1)); - else - view->MovePenTo(BPoint(0, 0)); - - BShape arrowShape; - arrowShape.MoveTo(tri1); - arrowShape.LineTo(tri2); - arrowShape.LineTo(tri3); - - if (flags & B_DISABLED) - tint = (tint + B_NO_TINT + B_NO_TINT) / 3; - - view->SetHighColor(tint_color(base, tint)); - - float penSize = view->PenSize(); - drawing_mode mode = view->DrawingMode(); - - view->SetPenSize(ceilf(hInset / 2.0)); - view->SetDrawingMode(B_OP_OVER); - view->StrokeShape(&arrowShape); - - view->SetPenSize(penSize); - view->SetDrawingMode(mode); -} - - -rgb_color -BControlLook::SliderBarColor(const rgb_color& base) -{ - return tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT); -} - - -void -BControlLook::DrawSliderBar(BView* view, BRect rect, const BRect& updateRect, - const rgb_color& base, rgb_color leftFillColor, rgb_color rightFillColor, - float sliderScale, uint32 flags, enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - // separate the bar in two sides - float sliderPosition; - BRect leftBarSide = rect; - BRect rightBarSide = rect; - - if (orientation == B_HORIZONTAL) { - sliderPosition = floorf(rect.left + 2 + (rect.Width() - 2) - * sliderScale); - leftBarSide.right = sliderPosition - 1; - rightBarSide.left = sliderPosition; - } else { - sliderPosition = floorf(rect.top + 2 + (rect.Height() - 2) - * sliderScale); - leftBarSide.bottom = sliderPosition - 1; - rightBarSide.top = sliderPosition; - } - - // fill the background for the corners, exclude the middle bar for now - BRegion region(rect); - region.Exclude(rightBarSide); - view->ConstrainClippingRegion(®ion); - - view->PushState(); - - DrawSliderBar(view, rect, updateRect, base, leftFillColor, flags, - orientation); - - view->PopState(); - - region.Set(rect); - region.Exclude(leftBarSide); - view->ConstrainClippingRegion(®ion); - - view->PushState(); - - DrawSliderBar(view, rect, updateRect, base, rightFillColor, flags, - orientation); - - view->PopState(); - - view->ConstrainClippingRegion(NULL); -} - - -void -BControlLook::DrawSliderBar(BView* view, BRect rect, const BRect& updateRect, - const rgb_color& base, rgb_color fillColor, uint32 flags, - enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - // separate the rect into corners - BRect leftCorner(rect); - BRect rightCorner(rect); - BRect barRect(rect); - - if (orientation == B_HORIZONTAL) { - leftCorner.right = leftCorner.left + leftCorner.Height(); - rightCorner.left = rightCorner.right - rightCorner.Height(); - barRect.left += ceilf(barRect.Height() / 2); - barRect.right -= ceilf(barRect.Height() / 2); - } else { - leftCorner.bottom = leftCorner.top + leftCorner.Width(); - rightCorner.top = rightCorner.bottom - rightCorner.Width(); - barRect.top += ceilf(barRect.Width() / 2); - barRect.bottom -= ceilf(barRect.Width() / 2); - } - - // fill the background for the corners, exclude the middle bar for now - BRegion region(rect); - region.Exclude(barRect); - view->ConstrainClippingRegion(®ion); - - view->SetHighColor(base); - view->FillRect(rect); - - // figure out the tints to be used - float edgeLightTint; - float edgeShadowTint; - float frameLightTint; - float frameShadowTint; - float fillLightTint; - float fillShadowTint; - - if (flags & B_DISABLED) { - edgeLightTint = 1.0; - edgeShadowTint = 1.0; - frameLightTint = 1.20; - frameShadowTint = 1.25; - fillLightTint = 0.9; - fillShadowTint = 1.05; - - fillColor.red = uint8(fillColor.red * 0.4 + base.red * 0.6); - fillColor.green = uint8(fillColor.green * 0.4 + base.green * 0.6); - fillColor.blue = uint8(fillColor.blue * 0.4 + base.blue * 0.6); - } else { - edgeLightTint = 0.65; - edgeShadowTint = 1.07; - frameLightTint = 1.40; - frameShadowTint = 1.50; - fillLightTint = 0.8; - fillShadowTint = 1.1; - } - - rgb_color edgeLightColor = tint_color(base, edgeLightTint); - rgb_color edgeShadowColor = tint_color(base, edgeShadowTint); - rgb_color frameLightColor = tint_color(fillColor, frameLightTint); - rgb_color frameShadowColor = tint_color(fillColor, frameShadowTint); - rgb_color fillLightColor = tint_color(fillColor, fillLightTint); - rgb_color fillShadowColor = tint_color(fillColor, fillShadowTint); - - if (orientation == B_HORIZONTAL) { - _DrawRoundBarCorner(view, leftCorner, updateRect, edgeLightColor, - edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor, - fillShadowColor, 1.0, 1.0, 0.0, -1.0, orientation); - - _DrawRoundBarCorner(view, rightCorner, updateRect, edgeLightColor, - edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor, - fillShadowColor, 0.0, 1.0, -1.0, -1.0, orientation); - } else { - _DrawRoundBarCorner(view, leftCorner, updateRect, edgeLightColor, - edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor, - fillShadowColor, 1.0, 1.0, -1.0, 0.0, orientation); - - _DrawRoundBarCorner(view, rightCorner, updateRect, edgeLightColor, - edgeShadowColor, frameLightColor, frameShadowColor, fillLightColor, - fillShadowColor, 1.0, 0.0, -1.0, -1.0, orientation); - } - - view->ConstrainClippingRegion(NULL); - - view->BeginLineArray(4); - if (orientation == B_HORIZONTAL) { - view->AddLine(barRect.LeftTop(), barRect.RightTop(), edgeShadowColor); - view->AddLine(barRect.LeftBottom(), barRect.RightBottom(), - edgeLightColor); - barRect.InsetBy(0, 1); - view->AddLine(barRect.LeftTop(), barRect.RightTop(), frameShadowColor); - view->AddLine(barRect.LeftBottom(), barRect.RightBottom(), - frameLightColor); - barRect.InsetBy(0, 1); - } else { - view->AddLine(barRect.LeftTop(), barRect.LeftBottom(), edgeShadowColor); - view->AddLine(barRect.RightTop(), barRect.RightBottom(), - edgeLightColor); - barRect.InsetBy(1, 0); - view->AddLine(barRect.LeftTop(), barRect.LeftBottom(), frameShadowColor); - view->AddLine(barRect.RightTop(), barRect.RightBottom(), - frameLightColor); - barRect.InsetBy(1, 0); - } - view->EndLineArray(); - - _FillGradient(view, barRect, fillColor, fillShadowTint, fillLightTint, - orientation); -} - - -void -BControlLook::DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, uint32 flags, enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - // figure out frame color - rgb_color frameLightColor; - rgb_color frameShadowColor; - rgb_color shadowColor = (rgb_color){ 0, 0, 0, 60 }; - - if (flags & B_FOCUSED) { - // focused - frameLightColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - frameShadowColor = frameLightColor; - } else { - // figure out the tints to be used - float frameLightTint; - float frameShadowTint; - - if (flags & B_DISABLED) { - frameLightTint = 1.30; - frameShadowTint = 1.35; - shadowColor.alpha = 30; - } else { - frameLightTint = 1.6; - frameShadowTint = 1.65; - } - - frameLightColor = tint_color(base, frameLightTint); - frameShadowColor = tint_color(base, frameShadowTint); - } - - BRect originalRect(rect); - rect.right--; - rect.bottom--; - - _DrawFrame(view, rect, frameLightColor, frameLightColor, - frameShadowColor, frameShadowColor); - - flags &= ~B_ACTIVATED; - DrawButtonBackground(view, rect, updateRect, base, flags); - - // thumb shadow - view->SetDrawingMode(B_OP_ALPHA); - view->SetHighColor(shadowColor); - originalRect.left++; - originalRect.top++; - view->StrokeLine(originalRect.LeftBottom(), originalRect.RightBottom()); - originalRect.bottom--; - view->StrokeLine(originalRect.RightTop(), originalRect.RightBottom()); - - // thumb edge - if (orientation == B_HORIZONTAL) { - rect.InsetBy(0, floorf(rect.Height() / 4)); - rect.left = floorf((rect.left + rect.right) / 2); - rect.right = rect.left + 1; - shadowColor = tint_color(base, B_DARKEN_2_TINT); - shadowColor.alpha = 128; - view->SetHighColor(shadowColor); - view->StrokeLine(rect.LeftTop(), rect.LeftBottom()); - rgb_color lightColor = tint_color(base, B_LIGHTEN_2_TINT); - lightColor.alpha = 128; - view->SetHighColor(lightColor); - view->StrokeLine(rect.RightTop(), rect.RightBottom()); - } else { - rect.InsetBy(floorf(rect.Width() / 4), 0); - rect.top = floorf((rect.top + rect.bottom) / 2); - rect.bottom = rect.top + 1; - shadowColor = tint_color(base, B_DARKEN_2_TINT); - shadowColor.alpha = 128; - view->SetHighColor(shadowColor); - view->StrokeLine(rect.LeftTop(), rect.RightTop()); - rgb_color lightColor = tint_color(base, B_LIGHTEN_2_TINT); - lightColor.alpha = 128; - view->SetHighColor(lightColor); - view->StrokeLine(rect.LeftBottom(), rect.RightBottom()); - } - - view->SetDrawingMode(B_OP_COPY); -} - - -void -BControlLook::DrawSliderTriangle(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - enum orientation orientation) -{ - DrawSliderTriangle(view, rect, updateRect, base, base, flags, orientation); -} - - -void -BControlLook::DrawSliderTriangle(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, const rgb_color& fill, - uint32 flags, enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - // figure out frame color - rgb_color frameLightColor; - rgb_color frameShadowColor; - rgb_color shadowColor = (rgb_color){ 0, 0, 0, 60 }; - - float topTint = 0.49; - float middleTint1 = 0.62; - float middleTint2 = 0.76; - float bottomTint = 0.90; - - if (flags & B_DISABLED) { - topTint = (topTint + B_NO_TINT) / 2; - middleTint1 = (middleTint1 + B_NO_TINT) / 2; - middleTint2 = (middleTint2 + B_NO_TINT) / 2; - bottomTint = (bottomTint + B_NO_TINT) / 2; - } else if (flags & B_HOVER) { - static const float kHoverTintFactor = 0.85; - topTint *= kHoverTintFactor; - middleTint1 *= kHoverTintFactor; - middleTint2 *= kHoverTintFactor; - bottomTint *= kHoverTintFactor; - } - - if (flags & B_FOCUSED) { - // focused - frameLightColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - frameShadowColor = frameLightColor; - } else { - // figure out the tints to be used - float frameLightTint; - float frameShadowTint; - - if (flags & B_DISABLED) { - frameLightTint = 1.30; - frameShadowTint = 1.35; - shadowColor.alpha = 30; - } else { - frameLightTint = 1.6; - frameShadowTint = 1.65; - } - - frameLightColor = tint_color(base, frameLightTint); - frameShadowColor = tint_color(base, frameShadowTint); - } - - // make room for the shadow - rect.right--; - rect.bottom--; - - uint32 viewFlags = view->Flags(); - view->SetFlags(viewFlags | B_SUBPIXEL_PRECISE); - view->SetLineMode(B_ROUND_CAP, B_ROUND_JOIN); - - float center = (rect.left + rect.right) / 2; - - BShape shape; - shape.MoveTo(BPoint(rect.left + 0.5, rect.bottom + 0.5)); - shape.LineTo(BPoint(rect.right + 0.5, rect.bottom + 0.5)); - shape.LineTo(BPoint(rect.right + 0.5, rect.bottom - 1 + 0.5)); - shape.LineTo(BPoint(center + 0.5, rect.top + 0.5)); - shape.LineTo(BPoint(rect.left + 0.5, rect.bottom - 1 + 0.5)); - shape.Close(); - - view->MovePenTo(BPoint(1, 1)); - - view->SetDrawingMode(B_OP_ALPHA); - view->SetHighColor(shadowColor); - view->StrokeShape(&shape); - - view->MovePenTo(B_ORIGIN); - - view->SetDrawingMode(B_OP_COPY); - view->SetHighColor(frameLightColor); - view->StrokeShape(&shape); - - rect.InsetBy(1, 1); - shape.Clear(); - shape.MoveTo(BPoint(rect.left, rect.bottom + 1)); - shape.LineTo(BPoint(rect.right + 1, rect.bottom + 1)); - shape.LineTo(BPoint(center + 0.5, rect.top)); - shape.Close(); - - BGradientLinear gradient; - if (flags & B_DISABLED) { - _MakeGradient(gradient, rect, fill, topTint, bottomTint); - } else { - _MakeGlossyGradient(gradient, rect, fill, topTint, middleTint1, - middleTint2, bottomTint); - } - - view->FillShape(&shape, gradient); - - view->SetFlags(viewFlags); -} - - -void -BControlLook::DrawSliderHashMarks(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, int32 count, - hash_mark_location location, uint32 flags, enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - rgb_color lightColor; - rgb_color darkColor; - - if (flags & B_DISABLED) { - lightColor = tint_color(base, 0.9); - darkColor = tint_color(base, 1.07); - } else { - lightColor = tint_color(base, 0.8); - darkColor = tint_color(base, 1.14); - } - - int32 hashMarkCount = max_c(count, 2); - // draw at least two hashmarks at min/max if - // fHashMarks != B_HASH_MARKS_NONE - float factor; - float startPos; - if (orientation == B_HORIZONTAL) { - factor = (rect.Width() - 2) / (hashMarkCount - 1); - startPos = rect.left + 1; - } else { - factor = (rect.Height() - 2) / (hashMarkCount - 1); - startPos = rect.top + 1; - } - - if (location & B_HASH_MARKS_TOP) { - view->BeginLineArray(hashMarkCount * 2); - - if (orientation == B_HORIZONTAL) { - float pos = startPos; - for (int32 i = 0; i < hashMarkCount; i++) { - view->AddLine(BPoint(pos, rect.top), - BPoint(pos, rect.top + 4), darkColor); - view->AddLine(BPoint(pos + 1, rect.top), - BPoint(pos + 1, rect.top + 4), lightColor); - - pos += factor; - } - } else { - float pos = startPos; - for (int32 i = 0; i < hashMarkCount; i++) { - view->AddLine(BPoint(rect.left, pos), - BPoint(rect.left + 4, pos), darkColor); - view->AddLine(BPoint(rect.left, pos + 1), - BPoint(rect.left + 4, pos + 1), lightColor); - - pos += factor; - } - } - - view->EndLineArray(); - } - - if (location & B_HASH_MARKS_BOTTOM) { - - view->BeginLineArray(hashMarkCount * 2); - - if (orientation == B_HORIZONTAL) { - float pos = startPos; - for (int32 i = 0; i < hashMarkCount; i++) { - view->AddLine(BPoint(pos, rect.bottom - 4), - BPoint(pos, rect.bottom), darkColor); - view->AddLine(BPoint(pos + 1, rect.bottom - 4), - BPoint(pos + 1, rect.bottom), lightColor); - - pos += factor; - } - } else { - float pos = startPos; - for (int32 i = 0; i < hashMarkCount; i++) { - view->AddLine(BPoint(rect.right - 4, pos), - BPoint(rect.right, pos), darkColor); - view->AddLine(BPoint(rect.right - 4, pos + 1), - BPoint(rect.right, pos + 1), lightColor); - - pos += factor; - } - } - - view->EndLineArray(); - } -} - - -void -BControlLook::DrawActiveTab(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.LeftTop() + BPoint(3, 3)); - fillGradient.SetEnd(rect.LeftBottom() + 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.bottom = cornerRect.top + kRoundCornerRadius; - - BRegion clipping(rect); - clipping.Exclude(cornerRect); - - _DrawRoundCornerLeftTop(view, cornerRect, updateRect, base, edgeShadowColor, - frameLightColor, bevelLightColor, fillGradient); - - // left/top corner - cornerRect.right = rect.right; - cornerRect.left = cornerRect.right - kRoundCornerRadius; - - clipping.Exclude(cornerRect); - - _DrawRoundCornerRightTop(view, cornerRect, updateRect, base, edgeShadowColor, - edgeLightColor, frameLightColor, frameShadowColor, bevelLightColor, - bevelShadowColor, fillGradient); - - // rest of frame and fill - view->ConstrainClippingRegion(&clipping); - - _DrawFrame(view, rect, edgeShadowColor, edgeShadowColor, edgeLightColor, - edgeLightColor, - borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER)); - if ((borders & B_LEFT_BORDER) == 0) - rect.left++; - if ((borders & B_RIGHT_BORDER) == 0) - rect.right--; - - _DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor, - frameShadowColor, B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER); - - _DrawFrame(view, rect, bevelLightColor, bevelLightColor, bevelShadowColor, - bevelShadowColor); - - view->FillRect(rect, fillGradient); - - view->ConstrainClippingRegion(NULL); -} - - -void -BControlLook::DrawInactiveTab(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.LeftTop() + BPoint(3, 3)); - fillGradient.SetEnd(rect.LeftBottom() + 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.top, rect.right, rect.top + 4)); - rect.top += 4; - - // frame and fill - _DrawFrame(view, rect, edgeShadowColor, edgeShadowColor, edgeLightColor, - edgeLightColor, - borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER)); - - _DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor, - frameShadowColor, - borders & (B_LEFT_BORDER | B_TOP_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 -BControlLook::DrawSplitter(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, enum orientation orientation, uint32 flags, - uint32 borders) -{ - rgb_color background; - if ((flags & (B_CLICKED | B_ACTIVATED)) != 0) - background = tint_color(base, B_DARKEN_1_TINT); - else - background = base; - - rgb_color light = tint_color(background, 0.6); - rgb_color shadow = tint_color(background, 1.21); - - // frame - if (borders != 0 && rect.Width() > 3 && rect.Height() > 3) - DrawRaisedBorder(view, rect, updateRect, background, flags, borders); - - // dots and rest of background - if (orientation == B_HORIZONTAL) { - if (rect.Width() > 2) { - // background on left/right - BRegion region(rect); - rect.left = floorf((rect.left + rect.right) / 2.0 - 0.5); - rect.right = rect.left + 1; - region.Exclude(rect); - view->SetHighColor(background); - view->FillRegion(®ion); - } - - BPoint dot = rect.LeftTop(); - BPoint stop = rect.LeftBottom(); - int32 num = 1; - while (dot.y <= stop.y) { - rgb_color col1; - rgb_color col2; - switch (num) { - case 1: - col1 = background; - col2 = background; - break; - case 2: - col1 = shadow; - col2 = background; - break; - case 3: - default: - col1 = background; - col2 = light; - num = 0; - break; - } - view->SetHighColor(col1); - view->StrokeLine(dot, dot, B_SOLID_HIGH); - view->SetHighColor(col2); - dot.x++; - view->StrokeLine(dot, dot, B_SOLID_HIGH); - dot.x -= 1.0; - // next pixel - num++; - dot.y++; - } - } else { - if (rect.Height() > 2) { - // background on left/right - BRegion region(rect); - rect.top = floorf((rect.top + rect.bottom) / 2.0 - 0.5); - rect.bottom = rect.top + 1; - region.Exclude(rect); - view->SetHighColor(background); - view->FillRegion(®ion); - } - - BPoint dot = rect.LeftTop(); - BPoint stop = rect.RightTop(); - int32 num = 1; - while (dot.x <= stop.x) { - rgb_color col1; - rgb_color col2; - switch (num) { - case 1: - col1 = background; - col2 = background; - break; - case 2: - col1 = shadow; - col2 = background; - break; - case 3: - default: - col1 = background; - col2 = light; - num = 0; - break; - } - view->SetHighColor(col1); - view->StrokeLine(dot, dot, B_SOLID_HIGH); - view->SetHighColor(col2); - dot.y++; - view->StrokeLine(dot, dot, B_SOLID_HIGH); - dot.y -= 1.0; - // next pixel - num++; - dot.x++; - } - } -} - - -// #pragma mark - - - -void -BControlLook::DrawBorder(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, border_style border, uint32 flags, uint32 borders) -{ - if (border == B_NO_BORDER) - return; - - rgb_color scrollbarFrameColor = tint_color(base, B_DARKEN_2_TINT); - if (flags & B_FOCUSED) - scrollbarFrameColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - - if (border == B_FANCY_BORDER) - _DrawOuterResessedFrame(view, rect, base, 1.0, 1.0, flags, borders); - - _DrawFrame(view, rect, scrollbarFrameColor, scrollbarFrameColor, - scrollbarFrameColor, scrollbarFrameColor, borders); -} - - -void -BControlLook::DrawRaisedBorder(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - rgb_color lightColor; - rgb_color shadowColor; - - if (flags & B_DISABLED) { - lightColor = base; - shadowColor = base; - } else { - lightColor = tint_color(base, 0.85); - shadowColor = tint_color(base, 1.07); - } - - _DrawFrame(view, rect, lightColor, lightColor, shadowColor, shadowColor, - borders); -} - - -void -BControlLook::DrawTextControlBorder(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - uint32 borders) -{ - if (!rect.Intersects(updateRect)) - return; - - rgb_color dark1BorderColor; - rgb_color dark2BorderColor; - rgb_color navigationColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - - if (flags & B_DISABLED) { - _DrawOuterResessedFrame(view, rect, base, 0.0, 1.0, flags, borders); - - if (flags & B_BLEND_FRAME) - dark1BorderColor = (rgb_color){ 0, 0, 0, 40 }; - else - dark1BorderColor = tint_color(base, 1.15); - dark2BorderColor = dark1BorderColor; - } else if (flags & B_CLICKED) { - dark1BorderColor = tint_color(base, 1.50); - dark2BorderColor = tint_color(base, 1.49); - - // BCheckBox uses this to indicate the clicked state... - _DrawFrame(view, rect, - dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor); - - dark2BorderColor = dark1BorderColor; - } else { - _DrawOuterResessedFrame(view, rect, base, 0.6, 1.0, flags, borders); - - if (flags & B_BLEND_FRAME) { - dark1BorderColor = (rgb_color){ 0, 0, 0, 102 }; - dark2BorderColor = (rgb_color){ 0, 0, 0, 97 }; - } else { - dark1BorderColor = tint_color(base, 1.40); - dark2BorderColor = tint_color(base, 1.38); - } - } - - if ((flags & B_DISABLED) == 0 && (flags & B_FOCUSED)) { - dark1BorderColor = navigationColor; - dark2BorderColor = navigationColor; - } - - if (flags & B_BLEND_FRAME) { - drawing_mode oldMode = view->DrawingMode(); - view->SetDrawingMode(B_OP_ALPHA); - - _DrawFrame(view, rect, - dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor, borders); - - view->SetDrawingMode(oldMode); - } else { - _DrawFrame(view, rect, - dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor, borders); - } -} - - -void -BControlLook::DrawGroupFrame(BView* view, BRect& rect, const BRect& updateRect, - const rgb_color& base, uint32 borders) -{ - rgb_color frameColor = tint_color(base, 1.30); - rgb_color bevelLight = tint_color(base, 0.8); - rgb_color bevelShadow = tint_color(base, 1.03); - - _DrawFrame(view, rect, bevelShadow, bevelShadow, bevelLight, bevelLight, - borders); - - _DrawFrame(view, rect, frameColor, frameColor, frameColor, frameColor, - borders); - - _DrawFrame(view, rect, bevelLight, bevelLight, bevelShadow, bevelShadow, - borders); -} - - -void -BControlLook::DrawLabel(BView* view, const char* label, BRect rect, - const BRect& updateRect, const rgb_color& base, uint32 flags) -{ - DrawLabel(view, label, rect, updateRect, base, flags, - DefaultLabelAlignment()); -} - - -void -BControlLook::DrawLabel(BView* view, const char* label, BRect rect, - const BRect& updateRect, const rgb_color& base, uint32 flags, - const BAlignment& alignment) -{ - if (!rect.Intersects(updateRect)) - return; - - // setup the text color - rgb_color color; - if (base.red + base.green + base.blue > 128 * 3) - color = tint_color(base, B_DARKEN_MAX_TINT); - else - color = tint_color(base, B_LIGHTEN_MAX_TINT); - - if (flags & B_DISABLED) { - color.red = (uint8)(((int32)base.red + color.red + 1) / 2); - color.green = (uint8)(((int32)base.green + color.green + 1) / 2); - color.blue = (uint8)(((int32)base.blue + color.blue + 1) / 2); - } - - view->SetHighColor(color); - view->SetDrawingMode(B_OP_OVER); - - // truncate the label if necessary and get the width and height - BString truncatedLabel(label); - - BFont font; - view->GetFont(&font); - - float width = rect.Width(); - font.TruncateString(&truncatedLabel, B_TRUNCATE_END, width); - width = font.StringWidth(truncatedLabel.String()); - - font_height fontHeight; - font.GetHeight(&fontHeight); - float height = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent); - - // handle alignment - BPoint location; - - switch (alignment.horizontal) { - default: - case B_ALIGN_LEFT: - location.x = rect.left; - break; - case B_ALIGN_RIGHT: - location.x = rect.right - width; - break; - case B_ALIGN_CENTER: - location.x = (rect.left + rect.right - width) / 2.0f; - break; - } - - switch (alignment.vertical) { - case B_ALIGN_TOP: - location.y = rect.top + ceilf(fontHeight.ascent); - break; - default: - case B_ALIGN_MIDDLE: - location.y = floorf((rect.top + rect.bottom - height) / 2.0f + 0.5f) - + ceilf(fontHeight.ascent); - break; - case B_ALIGN_BOTTOM: - location.y = rect.bottom - ceilf(fontHeight.descent); - break; - } - - view->DrawString(truncatedLabel.String(), location); -} - - -// #pragma mark - - - -void -BControlLook::_DrawButtonFrame(BView* view, BRect& rect, - const BRect& updateRect, const rgb_color& base, const rgb_color& background, - float contrast, float brightness, uint32 flags, uint32 borders) -{ - // colors - rgb_color dark1BorderColor; - rgb_color dark2BorderColor; - - if ((flags & B_DISABLED) == 0) { - if (flags & B_BLEND_FRAME) { - dark1BorderColor = (rgb_color){ 0, 0, 0, 75 }; - dark2BorderColor = (rgb_color){ 0, 0, 0, 95 }; - } else { - dark1BorderColor = tint_color(base, 1.33); - dark2BorderColor = tint_color(base, 1.45); - } - - if (flags & B_DEFAULT_BUTTON) { - // TODO: B_BLEND_FRAME - dark2BorderColor = tint_color(dark1BorderColor, 1.5); - dark1BorderColor = tint_color(dark1BorderColor, 1.35); - } - } else { - // TODO: B_BLEND_FRAME - dark1BorderColor = tint_color(base, 1.147); - dark2BorderColor = tint_color(base, 1.24); - - if (flags & B_DEFAULT_BUTTON) { - dark1BorderColor = tint_color(dark1BorderColor, 1.14); - dark2BorderColor = tint_color(dark1BorderColor, 1.12); - } - } - - if (flags & B_ACTIVATED) { - rgb_color temp = dark2BorderColor; - dark2BorderColor = dark1BorderColor; - dark1BorderColor = temp; - } - - // indicate focus by changing main button border - if (flags & B_FOCUSED) { - dark1BorderColor = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - dark2BorderColor = dark1BorderColor; - } - - if (flags & B_DEFAULT_BUTTON) { - // TODO: B_BLEND_FRAME - float focusTint = 1.2; - if (flags & B_DISABLED) - focusTint = (B_NO_TINT + focusTint) / 2; - - rgb_color focusColor = tint_color(base, focusTint); - view->SetHighColor(base); - - view->StrokeRect(rect); - rect.InsetBy(1.0, 1.0); - - view->SetHighColor(focusColor); - view->StrokeRect(rect); - rect.InsetBy(1.0, 1.0); - view->StrokeRect(rect); - rect.InsetBy(1.0, 1.0); - - // bevel around external border - _DrawOuterResessedFrame(view, rect, focusColor, - contrast * (((flags & B_DISABLED) ? 0.3 : 0.8)), - brightness * (((flags & B_DISABLED) ? 1.0 : 0.9)), - flags, borders); - } else { - // bevel around external border - _DrawOuterResessedFrame(view, rect, background, - contrast * ((flags & B_DISABLED) ? 0.0 : 1.0), brightness * 1.0, - flags, borders); - } - - if (flags & B_BLEND_FRAME) { - drawing_mode oldDrawingMode = view->DrawingMode(); - view->SetDrawingMode(B_OP_ALPHA); - - _DrawFrame(view, rect, dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor, borders); - - view->SetDrawingMode(oldDrawingMode); - } else { - _DrawFrame(view, rect, dark1BorderColor, dark1BorderColor, - dark2BorderColor, dark2BorderColor, borders); - } -} - - -void -BControlLook::_DrawOuterResessedFrame(BView* view, BRect& rect, - const rgb_color& base, float contrast, float brightness, uint32 flags, - uint32 borders) -{ - if (flags & B_BLEND_FRAME) { - // assumes the background has already been painted - drawing_mode oldDrawingMode = view->DrawingMode(); - view->SetDrawingMode(B_OP_ALPHA); - - uint8 alpha = uint8(20 * contrast); - uint32 white = uint8(255 * brightness); - - rgb_color borderBevelShadow = (rgb_color){ 0, 0, 0, alpha }; - rgb_color borderBevelLight = (rgb_color){ white, white, white, alpha }; - - _DrawFrame(view, rect, borderBevelShadow, borderBevelShadow, - borderBevelLight, borderBevelLight, borders); - - view->SetDrawingMode(oldDrawingMode); - } else { - // colors - float tintLight = kEdgeBevelLightTint; - float tintShadow = kEdgeBevelShadowTint; - - if (contrast == 0.0) { - tintLight = B_NO_TINT; - tintShadow = B_NO_TINT; - } else if (contrast != 1.0) { - tintLight = B_NO_TINT + (tintLight - B_NO_TINT) * contrast; - tintShadow = B_NO_TINT + (tintShadow - B_NO_TINT) * contrast; - } - - rgb_color borderBevelShadow = tint_color(base, tintShadow); - rgb_color borderBevelLight = tint_color(base, tintLight); - - if (brightness < 1.0) { - borderBevelShadow.red = uint8(borderBevelShadow.red * brightness); - borderBevelShadow.green = uint8(borderBevelShadow.green * brightness); - borderBevelShadow.blue = uint8(borderBevelShadow.blue * brightness); - borderBevelLight.red = uint8(borderBevelLight.red * brightness); - borderBevelLight.green = uint8(borderBevelLight.green * brightness); - borderBevelLight.blue = uint8(borderBevelLight.blue * brightness); - } - - _DrawFrame(view, rect, borderBevelShadow, borderBevelShadow, - borderBevelLight, borderBevelLight, borders); - } -} - - -void -BControlLook::_DrawFrame(BView* view, BRect& rect, const rgb_color& left, - const rgb_color& top, const rgb_color& right, const rgb_color& bottom, - uint32 borders) -{ - view->BeginLineArray(4); - - if (borders & B_LEFT_BORDER) { - view->AddLine( - BPoint(rect.left, rect.bottom), - BPoint(rect.left, rect.top), left); - rect.left++; - } - if (borders & B_TOP_BORDER) { - view->AddLine( - BPoint(rect.left, rect.top), - BPoint(rect.right, rect.top), top); - rect.top++; - } - if (borders & B_RIGHT_BORDER) { - view->AddLine( - BPoint(rect.right, rect.top), - BPoint(rect.right, rect.bottom), right); - rect.right--; - } - if (borders & B_BOTTOM_BORDER) { - view->AddLine( - BPoint(rect.left, rect.bottom), - BPoint(rect.right, rect.bottom), bottom); - rect.bottom--; - } - - view->EndLineArray(); -} - - -void -BControlLook::_DrawFrame(BView* view, BRect& rect, const rgb_color& left, - const rgb_color& top, const rgb_color& right, const rgb_color& bottom, - const rgb_color& rightTop, const rgb_color& leftBottom, uint32 borders) -{ - view->BeginLineArray(6); - - if (borders & B_TOP_BORDER) { - if (borders & B_RIGHT_BORDER) { - view->AddLine( - BPoint(rect.left, rect.top), - BPoint(rect.right - 1, rect.top), top); - view->AddLine( - BPoint(rect.right, rect.top), - BPoint(rect.right, rect.top), rightTop); - } else { - view->AddLine( - BPoint(rect.left, rect.top), - BPoint(rect.right, rect.top), top); - } - rect.top++; - } - - if (borders & B_LEFT_BORDER) { - view->AddLine( - BPoint(rect.left, rect.top), - BPoint(rect.left, rect.bottom - 1), left); - view->AddLine( - BPoint(rect.left, rect.bottom), - BPoint(rect.left, rect.bottom), leftBottom); - rect.left++; - } - - if (borders & B_BOTTOM_BORDER) { - view->AddLine( - BPoint(rect.left, rect.bottom), - BPoint(rect.right, rect.bottom), bottom); - rect.bottom--; - } - - if (borders & B_RIGHT_BORDER) { - view->AddLine( - BPoint(rect.right, rect.bottom), - BPoint(rect.right, rect.top), right); - rect.right--; - } - - view->EndLineArray(); -} - - -//void -//BControlLook::_DrawShadowFrame(BView* view, BRect& rect, const rgb_color& base, -// uint32 borders) -//{ -// view->BeginLineArray(4); -// -// bevelColor1 = tint_color(base, 1.2); -// bevelColor2 = tint_color(base, 1.1); -// -// // shadow along left/top borders -// if (rect.Height() > 0 && borders & B_LEFT_BORDER) { -// view->AddLine(BPoint(rect.left, rect.top), -// BPoint(rect.left, rect.bottom), bevelColor1); -// rect.left++; -// } -// if (rect.Width() > 0 && borders & B_TOP_BORDER) { -// view->AddLine(BPoint(rect.left, rect.top), -// BPoint(rect.right, rect.top), bevelColor1); -// rect.top++; -// } -// -// // softer shadow along left/top borders -// if (rect.Height() > 0 && borders & B_LEFT_BORDER) { -// view->AddLine(BPoint(rect.left, rect.top), -// BPoint(rect.left, rect.bottom), bevelColor2); -// rect.left++; -// } -// if (rect.Width() > 0 && borders & B_TOP_BORDER) { -// view->AddLine(BPoint(rect.left, rect.top), -// BPoint(rect.right, rect.top), bevelColor2); -// rect.top++; -// } -// -// view->EndLineArray(); -//} - - -void -BControlLook::_FillGradient(BView* view, const BRect& rect, - const rgb_color& base, float topTint, float bottomTint, - enum orientation orientation) -{ - BGradientLinear gradient; - _MakeGradient(gradient, rect, base, topTint, bottomTint, orientation); - view->FillRect(rect, gradient); -} - - -void -BControlLook::_FillGlossyGradient(BView* view, const BRect& rect, - const rgb_color& base, float topTint, float middle1Tint, - float middle2Tint, float bottomTint, enum orientation orientation) -{ - BGradientLinear gradient; - _MakeGlossyGradient(gradient, rect, base, topTint, middle1Tint, - middle2Tint, bottomTint, orientation); - view->FillRect(rect, gradient); -} - - -void -BControlLook::_MakeGradient(BGradientLinear& gradient, const BRect& rect, - const rgb_color& base, float topTint, float bottomTint, - enum orientation orientation) const -{ - gradient.AddColor(tint_color(base, topTint), 0); - gradient.AddColor(tint_color(base, bottomTint), 255); - gradient.SetStart(rect.LeftTop()); - if (orientation == B_HORIZONTAL) - gradient.SetEnd(rect.LeftBottom()); - else - gradient.SetEnd(rect.RightTop()); -} - - -void -BControlLook::_MakeGlossyGradient(BGradientLinear& gradient, const BRect& rect, - const rgb_color& base, float topTint, float middle1Tint, - float middle2Tint, float bottomTint, - enum orientation orientation) const -{ - gradient.AddColor(tint_color(base, topTint), 0); - gradient.AddColor(tint_color(base, middle1Tint), 132); - gradient.AddColor(tint_color(base, middle2Tint), 136); - gradient.AddColor(tint_color(base, bottomTint), 255); - gradient.SetStart(rect.LeftTop()); - if (orientation == B_HORIZONTAL) - gradient.SetEnd(rect.LeftBottom()); - else - gradient.SetEnd(rect.RightTop()); -} - - -bool -BControlLook::_RadioButtonAndCheckBoxMarkColor(const rgb_color& base, - rgb_color& color, uint32 flags) const -{ - if ((flags & (B_ACTIVATED | B_CLICKED)) == 0) { - // no mark to be drawn at all - return false; - } - - // TODO: Get from UI settings - color.red = 27; - color.green = 82; - color.blue = 140; - - float mix = 1.0; - - if (flags & B_DISABLED) { - // activated, but disabled - mix = 0.4; - } else if (flags & B_CLICKED) { - if (flags & B_ACTIVATED) { - // loosing activation - mix = 0.7; - } else { - // becoming activated - mix = 0.3; - } - } else { - // simply activated - } - - color.red = uint8(color.red * mix + base.red * (1.0 - mix)); - color.green = uint8(color.green * mix + base.green * (1.0 - mix)); - color.blue = uint8(color.blue * mix + base.blue * (1.0 - mix)); - - return true; -} - - -void -BControlLook::_DrawRoundBarCorner(BView* view, BRect& rect, - const BRect& updateRect, - const rgb_color& edgeLightColor, const rgb_color& edgeShadowColor, - const rgb_color& frameLightColor, const rgb_color& frameShadowColor, - const rgb_color& fillLightColor, const rgb_color& fillShadowColor, - float leftInset, float topInset, float rightInset, float bottomInset, - enum orientation orientation) -{ - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - - BGradientLinear gradient; - gradient.AddColor(edgeShadowColor, 0); - gradient.AddColor(edgeLightColor, 255); - gradient.SetStart(rect.LeftTop()); - if (orientation == B_HORIZONTAL) - gradient.SetEnd(rect.LeftBottom()); - else - gradient.SetEnd(rect.RightTop()); - - view->FillEllipse(rect, gradient); - - rect.left += leftInset; - rect.top += topInset; - rect.right += rightInset; - rect.bottom += bottomInset; - - gradient.MakeEmpty(); - gradient.AddColor(frameShadowColor, 0); - gradient.AddColor(frameLightColor, 255); - gradient.SetStart(rect.LeftTop()); - if (orientation == B_HORIZONTAL) - gradient.SetEnd(rect.LeftBottom()); - else - gradient.SetEnd(rect.RightTop()); - - view->FillEllipse(rect, gradient); - - rect.left += leftInset; - rect.top += topInset; - rect.right += rightInset; - rect.bottom += bottomInset; - - gradient.MakeEmpty(); - gradient.AddColor(fillShadowColor, 0); - gradient.AddColor(fillLightColor, 255); - gradient.SetStart(rect.LeftTop()); - if (orientation == B_HORIZONTAL) - gradient.SetEnd(rect.LeftBottom()); - else - gradient.SetEnd(rect.RightTop()); - - view->FillEllipse(rect, gradient); -} - - -void -BControlLook::_DrawRoundCornerLeftTop(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.bottom = ellipseRect.top + 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 -BControlLook::_DrawRoundCornerRightTop(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.bottom = ellipseRect.top + 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); -} - - -// NOTE: May come from a add-on in the future. Initialized in -// InterfaceDefs.cpp -BControlLook* be_control_look = NULL; - -} // namespace BPrivate diff --git a/src/DateTextView.cpp b/src/DateTextView.cpp deleted file mode 100644 index 510aa50..0000000 --- a/src/DateTextView.cpp +++ /dev/null @@ -1,620 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include - - -#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(yearlast_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<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<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); -} diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 3df82e9..0000000 --- a/src/Makefile +++ /dev/null @@ -1,181 +0,0 @@ -## -## 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 -## -HAIKUOPT = -DHAIKU -DLIBRARY_PATH=\"`finddir B_USER_SETTINGS_DIRECTORY`/yab\" -# - -## -## Find haiku systenm archetecture from the package file name -## -SYSTEMARCH:= $(shell catattr SYS:PACKAGE_FILE /boot/system/kernel_x86*|cut --fields=4 -d-|cut -d. --fields 1) -# - -## -## Find used archetecture using the getarch command -## -USEDARCH := $(shell getarch) -ifeq ($(SYSTEMARCH),$(USEDARCH)) - ARCHADD:= -else - ARCHADD := /$(USEDARCH) -endif -# - -## -## Use our own column list view -## -COLUMN = column/ColumnListView.o - -## -## enable debug -## -# DBG = -g -# - -## -## enable optimization -## -OPT = -O -# -## -## set libtrary name -## -YABLIBRARY := libyab1.so -## -# - - - -## 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) -## -## find out if we need to change the library to libyab_x86.so and use gcc instead of ld -ifeq ($(USEDARCH), x86) - LD = gcc - YABLIBRARY:=libyab1_x86.so -else - LD = ld -endif -ifeq ($(SYSTEMARCH),x86_64) - LD=gcc -endif -# - -LD_OPT = -shared - -## -## Libraries -## -##LIBPATH = -L/boot/home/config/lib -LIBPATHS = $(shell findpaths -a `getarch` B_FIND_PATH_LIB_DIRECTORY;findpaths -a `getarch` B_FIND_PATH_DEVELOP_LIB_DIRECTORY) . -LIBPATH=$(addprefix -L,$(LIBPATHS)) -##LIBPATH = -L`finddir B_SYSTEM_LIB_DIRECTORY` ##/boot/system/lib -LIB = -lbe -lroot -ltranslation -ltracker -lmedia -llocalestub -lgame - -## flags for flex (-d for debugging) -FLEXFLAGS = -i -I -L -s - -## flags for bison (-t -v for debugging) -BISONFLAGS = -d -l -t -v - -YAB_OBJECTS = YabInterface.o YabWindow.o YabView.o YabBitmapView.o YabText.o YabFilePanel.o YabFilePanelLooper.o YabList.o \ - function.o io.o graphic.o symbol.o bison.o \ - $(COLUMN) column/YabColumnType.o column/ColorTools.o \ - YabStackView.o SplitPane.o URLView.o YabTabView.o Spinner.o $(TABLIB) CalendarControl.o - -## -## Compile and link -## -yab: $(YABLIBRARY) YabMain.o main.o bison.o flex.o RdefApply YAB.rdef - $(GPP) $(GPP_OPT) -o $@ YabMain.o main.o bison.o flex.o $(LIBPATH) $(YABLIBRARY) $(LIB) - LIBRARY_PATH=$$LIBRARY_PATH:. $@ RdefApply YAB.rdef $@ - addattr -t mime BEOS:TYPE application/x-vnd.be-elfexecutable $@ - -$(YABLIBRARY): $(YAB_OBJECTS) - $(LD) $(LD_OPT) -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 -YabTabView.o: 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 - -clean: - rm -f core *.o column/*.o flex.* bison.* yab yabasic.output $(YABLIBRARY) - -install: yab $(YABLIBRARY) - - - mkdir -p /boot/system/non-packaged/bin$(ARCHADD) - mkdir -p /boot/system/non-packaged/lib$(ARCHADD) - mkdir -p /boot/system/non-packaged/develop/lib$(ARCHADD) - cp -f yab /boot/system/non-packaged/bin$(ARCHADD)/ - cp -f $(YABLIBRARY) /boot/system/non-packaged/lib$(ARCHADD)/ - cp -f $(YABLIBRARY) /boot/system/non-packaged/develop/lib$(ARCHADD)/ - diff --git a/src/MediaPlay.h b/src/MediaPlay.h deleted file mode 100644 index 7ed0c46..0000000 --- a/src/MediaPlay.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright 2017, Dario Casalinuovo. All rights reserved. - * Distributed under the terms of the MIT License. - */ - -#ifndef _MEDIA_CLIENT_PLAY -#define _MEDIA_CLIENT_PLAY - -int media_play(const char* uri); - -#endif diff --git a/src/MonthView.cpp b/src/MonthView.cpp deleted file mode 100644 index 5d6847d..0000000 --- a/src/MonthView.cpp +++ /dev/null @@ -1,960 +0,0 @@ -// 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 -#include -#include -#include -#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(tyearlast_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(tyearSetHighColor(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(cdayLock(); - 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(cyearPostMessage(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<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<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<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(cyearSetText(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(tyearlast_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<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(tLock(); - 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()); -} diff --git a/src/MonthWindow.cpp b/src/MonthWindow.cpp deleted file mode 100644 index 9517460..0000000 --- a/src/MonthWindow.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// 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 -#include -#include -#include -#include - -#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(yearlast_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(); -} diff --git a/src/MouseSenseStringView.cpp b/src/MouseSenseStringView.cpp deleted file mode 100644 index abc9e35..0000000 --- a/src/MouseSenseStringView.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// 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 -#include -#include -#include -#include -#include - -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); -} diff --git a/src/RdefApply b/src/RdefApply deleted file mode 100755 index fe19566..0000000 --- a/src/RdefApply +++ /dev/null @@ -1,34 +0,0 @@ -#!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 " - 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 - diff --git a/src/Spinner.cpp b/src/Spinner.cpp deleted file mode 100644 index 6b6429c..0000000 --- a/src/Spinner.cpp +++ /dev/null @@ -1,654 +0,0 @@ -/* - Spinner.cpp: A number spinner control. - Written by DarkWyrm , Copyright 2004 - Released under the MIT license. - - Original BScrollBarButton class courtesy Haiku project -*/ -#include "Spinner.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "global.h" -#include -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+30, textheight+6); //14*2-2); //+18+14 length of textcontrol - - - r = Bounds(); - r.right -= 14+3; //Distance between textcontrol and spinnerbutton - - r.bottom=r.top+textheight+8; //+10; //Changed from 8 to 10, because the spinnerbutton look nicer - 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_RIGHT); //change from left to right not completed - tview->SetWordWrap(false); - - if (strcmp(label, "") == 0) //check if Label was set - { - fTextControl->SetDivider(width2); - } - else if (strcmp(label,"") != 0) - { - fTextControl->SetDivider(width2+4); - } - //fTextControl->SetDivider(width2+5); - //fTextControl->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_RIGHT); - BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| " - "asdfghjkl:\"zxcvbnm<>?!@#$%^&*()-_=+`~\r"); - - for(int32 i=0; iDisallowChar(c); - } - r=Bounds(); - r.left=r.right-15; - //r.bottom/=2+4; - //r.top - - fUpButton=new SpinnerArrowButton(BPoint(r.left, r.top-1),"up",ARROW_UP); //to make one line with the textcontrol - AddChild(fUpButton); - - r=Bounds(); - r.left=r.right-15; - r.top=r.bottom/2; //remove +1 to make one line with the textcontrol - - fDownButton=new SpinnerArrowButton(BPoint(r.left, r.top),"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() || valueSetText(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(newvalueGetMax() && 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()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(newvalueGetMin() && 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 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(*target); - if(text && text->IsFocus()) - { - BView *view=text->Parent(); - while(view) - { - Spinner *spin=dynamic_cast(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: - { - 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(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(*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(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; -} diff --git a/src/Spinner.h b/src/Spinner.h deleted file mode 100644 index 4cdffcd..0000000 --- a/src/Spinner.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SPINNER_H_ -#define SPINNER_H_ - -#include -#include -#include -#include -#include - -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 diff --git a/src/SplitPane.cpp b/src/SplitPane.cpp deleted file mode 100644 index 68e85f4..0000000 --- a/src/SplitPane.cpp +++ /dev/null @@ -1,726 +0,0 @@ -/******************************************************* -* 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 -#include -#include -#include -#include -#include -#include - -//#include - -#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; - } -} - - - - - - - diff --git a/src/SplitPane.h b/src/SplitPane.h deleted file mode 100644 index 7098041..0000000 --- a/src/SplitPane.h +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************* -* 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 -#include -// #include -#include -#include -#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 - diff --git a/src/URLView.cpp b/src/URLView.cpp deleted file mode 100644 index 73403ee..0000000 --- a/src/URLView.cpp +++ /dev/null @@ -1,1147 +0,0 @@ -/* 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. -*/ - - - -#include "URLView.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -// #include -#include "global.h" - -#ifndef ZETA - #define _T(str) str -#else - #include -#endif - -URLView::URLView( BRect frame, const char *name, const char *label, - const char *url, uint32 resizingMode, uint32 flags ) - : BStringView( frame, name, label, resizingMode, flags ) { - - // Set the default values for the other definable instance variables. - this->color = blue; - this->clickColor = dark_green; - this->hoverColor = dark_blue; - this->disabledColor = gray; - this->hoverEnabled = true; - this->draggable = true; - this->iconSize = 16; - this->underlineThickness = 1; - - // The link should be enabled by default (unless the URL is invalid, which - // is handled by the SetURL() function). - enabled = true; - - // Set the instance variables. - this->url = 0; - SetURL( url ); - - // Create the cursor to use when over the link. - this->linkCursor = new BCursor( url_cursor ); - - // The link is not currently selected. - selected = false; - - // The URL is currently not hover-colored. - hovering = false; - - // The user has not dragged out of the view. - draggedOut = false; - - // The user has not yet opened the popup menu. - inPopup = false; - - // Initialize the attributes list (there are 14 standard - // Person attributes). - attributes = new BList( 14 ); - -} - - -URLView::~URLView() { - delete url; - delete linkCursor; - - // Delete all the attributes. - KeyPair *item; - for( int i = 0; (item = (KeyPair *) attributes->ItemAt(i)); i++ ) { - delete item->key; - delete item->value; - delete item; - } - delete attributes; -} - - - - - -void URLView::AttachedToWindow() { - // When the view is first attached, we want to draw the link - // in the normal color. Also, we want to set our background color - // to meet that of our parent. - if( IsEnabled() ) - SetHighColor( color ); - else - SetHighColor( disabledColor ); - - if( Parent() != NULL ) { - SetLowColor( Parent()->ViewColor() ); - SetViewColor( Parent()->ViewColor() ); - } -} - - - -void URLView::Draw( BRect updateRect ) { - - BRect rect = Frame(); - rect.OffsetTo( B_ORIGIN ); - - // We want 'g's, etc. to go below the underline. When the BeOS can - // do underlining of any font, this code can be removed. - font_height height; - GetFontHeight( &height ); - float descent = height.descent; - - // We want to be sensitive to the SetAlignment() function. - float left, right; - if( Alignment() == B_ALIGN_RIGHT ) { - left = rect.right - StringWidth( Text() ) + 1; - right = rect.right - 1; - } - else if( Alignment() == B_ALIGN_CENTER ) { - left = rect.left + (rect.Width() / 2) - (StringWidth( Text() ) / 2); - right = left + StringWidth( Text() ) - 2; - } - else { - left = rect.left; - right = left + StringWidth( Text() ) - 2; - } - - // Draw the underline in the requested thickness. - // Note: If the link is disabled, we don't want to draw the underline. - if( IsEnabled() ) { - FillRect( BRect( (float) left, - (float) (rect.bottom - descent), - (float) right, - (float) (rect.bottom - descent + (underlineThickness - 1)) ) ); - } - MovePenTo( BPoint( left, rect.bottom - descent - 1 ) ); - - // Note: DrawString() draws the text at one pixel above the pen's - // current y coordinate. - DrawString( Text() ); - -} - - - -void URLView::MessageReceived( BMessage *message ) -{ - entry_ref ref; - switch (message->what) - { - - case 'DDCP': - { - - // Is this a message from Tracker in response to our drag-and-drop? - //if( message->what == 'DDCP' ) { - // Tracker will send back the name and path of the created file. - // We need to read this information. - entry_ref ref; - message->FindRef( "directory", &ref ); - - BEntry entry( &ref ); - BPath path( &entry ); - BString *fullName = new BString( path.Path() ); - fullName->Append( "/" ); - fullName->Append( message->FindString( "name" ) ); - BString *title = new BString( Text() ); - - // Set the new file as a bookmark or as a person as appropriate. - if( IsEmailLink() ) { - CreatePerson( fullName, title ); - } - else CreateBookmark( fullName, title ); - - delete fullName; - delete title; - - } - break; - default: - - BView::MessageReceived(message); - break; - } - -} - -void URLView::MouseDown( BPoint point ) { - // If the link isn't enabled, don't do anything. - if( !IsEnabled() ) - return; - - // See which mouse buttons were clicked. - int32 buttons = Window()->CurrentMessage()->FindInt32( "buttons" ); - - // We want to highlight the text if the user clicks on - // the URL. We want to be sure to only register a click - // if the user clicks on the link text itself and not just - // anywhere in the view. - if( GetTextRect().Contains( point ) ) { - SetHighColor( clickColor ); - - // Set the link as selected and track the mouse. - selected = true; - SetMouseEventMask( B_POINTER_EVENTS ); - - // Remember where the user clicked so we can correctly - // offset the transparent URL if the user drags. - BRect frame = Frame(); - frame.OffsetTo( B_ORIGIN ); - dragOffset = point; - if( Alignment() == B_ALIGN_RIGHT ) { - dragOffset.x -= frame.Width() - StringWidth( Text() ); - } - else if( Alignment() == B_ALIGN_CENTER ) { - dragOffset.x -= (frame.Width() / 2) - (StringWidth( Text() ) / 2); - } - - // Pop up the context menu? - if( buttons == B_SECONDARY_MOUSE_BUTTON ) inPopup = true; - } - //Redraw(); -} - - - -void URLView::MouseMoved( BPoint point, uint32 transit, - const BMessage *message ) { - - // If the link isn't enabled, don't do anything. - if( !IsEnabled() ) - return; - - // Make sure the window is the active one. - if( !Window()->IsActive() ) return; - - // See which mouse buttons were clicked. - int32 buttons = Window()->CurrentMessage()->FindInt32( "buttons" ); - // Is the user currently dragging the link? (i.e. is a mouse button - // currently down?) - bool alreadyDragging = (buttons != 0); - - switch( transit ) { - case( B_ENTERED_VIEW ): - - // Should we set the cursor to the link cursor? - if( GetTextRect().Contains( point ) && !draggedOut ) { - if( !alreadyDragging ) be_app->SetCursor( linkCursor ); - - // Did the user leave and re-enter the view while - // holding down the mouse button? If so, highlight - // the link. - if( selected ) { - SetHighColor( clickColor ); - //Redraw(); - } - // Should we hover-highlight the link? - else if( hoverEnabled && !alreadyDragging ) { - if( buttons == 0 ) { - SetHighColor( hoverColor ); - //Redraw(); - hovering = true; - } - } - } - break; - - case( B_EXITED_VIEW ): - // We want to restore the link to it normal color and the - // mouse cursor to the normal hand. However, we should only - // set the color and re-draw if it is needed. - if( selected && !draggedOut ) { - be_app->SetCursor( B_HAND_CURSOR ); - SetHighColor( color ); - //Redraw(); - - // Is the user drag-and-dropping a bookmark or person? - if( draggable ) { - // = true; - if( IsEmailLink() ) DoPersonDrag(); - else DoBookmarkDrag(); - } - } - // Is the link currently hover-highlighted? If so, restore - // the normal color now. - else if( hovering && !alreadyDragging ) { - be_app->SetCursor( B_HAND_CURSOR ); - SetHighColor( color ); - //Redraw(); - hovering = false; - } - // Change the cursor back to the hand. - else { - be_app->SetCursor( B_HAND_CURSOR ); - } - - break; - - case( B_INSIDE_VIEW ): - // The user could either be moving out of the view or - // back into it here, so we must handle both cases. - // In the first case, the cursor is now over the link. - - if( GetTextRect().Contains( point ) && !draggedOut ) { - - // We only want to change the cursor if not dragging. - if( !alreadyDragging ) be_app->SetCursor( linkCursor ); - if( selected ) { - if( draggable ) { - // If the user moves the mouse more than ten - // pixels, begin the drag. - if( (point.x - dragOffset.x) > 10 || - (dragOffset.x - point.x) > 10 || - (point.y - dragOffset.y) > 10 || - (dragOffset.y - point.y) > 10 ) { - draggedOut = true; - // Draw the appropriate drag object, etc. - if( IsEmailLink() ) DoPersonDrag(); - else DoBookmarkDrag(); - SetHighColor( color ); - //Redraw(); - } - } - else { - // Since the link is not draggable, highlight it - // as long as the user holds the button down and - // has the mouse cursor over it (like a standard - // button). - SetHighColor( clickColor ); - //Redraw(); - } - } - // The link isn't currently selected? If hover-highlighting - // is enabled, highlight the link. - else if( hoverEnabled && !alreadyDragging ) { - SetHighColor( hoverColor ); - //Redraw(); - hovering = true; - } - } - // In this case, the mouse cursor is not over the link, so we - // need to restore the original link color, etc. - else if( !draggedOut ) { - be_app->SetCursor( B_HAND_CURSOR ); - if( selected ) { - SetHighColor( color ); - - - // Is the user dragging the link? - if( draggable ) { - draggedOut = true; - if( IsEmailLink() ) DoPersonDrag(); - else DoBookmarkDrag(); - } - } - // Is the mouse cursor hovering over the link? - else if( hovering ) { - SetHighColor( color ); - //Redraw(); - hovering = false; - } - - } - break; - } -} - - - -void URLView::MouseUp( BPoint point ) { - // If the link isn't enabled, don't do anything. - if( !IsEnabled() ) - return; - - // Do we want to show the right-click menu? - if( inPopup && GetTextRect().Contains( point ) ) { - BPopUpMenu *popup = CreatePopupMenu(); - // Work around a current bug in Be's popup menus. - point.y = point.y - 6; - - // Display the popup menu. - BMenuItem *selected = popup->Go( ConvertToScreen( point ) , false, true ); - - // Did the user select an item? - if( selected ) { - BString label( selected->Label() ); - // Did the user select the first item? If so, launch the URL. - if( label.FindFirst( "Open" ) != B_ERROR || - label.FindFirst( "Send" ) != B_ERROR || - label.FindFirst( "Connect" ) != B_ERROR ) { - LaunchURL(); - } - // Did the user select the second item? - else if( label.FindFirst( "Copy" ) != B_ERROR ) { - CopyToClipboard(); - } - } - // If not, restore the normal link color. - else { - SetHighColor( color ); - - } - } - - // If the link was clicked on (and not dragged), run the program - // that should handle the URL. - if( selected && GetTextRect().Contains( point ) && - !draggedOut && !inPopup ) { - LaunchURL(); - } - selected = false; - draggedOut = false; - inPopup = false; - - // Should we restore the hovering-highlighted color or the original - // link color? - if( GetTextRect().Contains( point ) && !draggedOut && - !inPopup && hoverEnabled ) { - SetHighColor( hoverColor ); - } - else if( !hovering ) - { - SetHighColor( color ); - } - -} - - - -void URLView::WindowActivated( bool active ) { - // Be sure that if the user clicks on a link prompting the opening of - // a new window (i.e. launching NetPositive) the URL is not left drawn - // with the hover color. - if( !active ) { - if( IsEnabled() ) { - SetHighColor( color ); - //Redraw(); - } - } -} - - - - - -void URLView::AddAttribute( const char *name, const char *value ) { - // Add an attribute (name and corresponding value) to the object - // that will be dragged out (i.e. to fill in Person fields, etc.) - KeyPair *newPair = new KeyPair; - newPair->key = new BString( name ); - newPair->value = new BString( value ); - attributes->AddItem( newPair ); -} - - - -bool URLView::IsEnabled() { - // Return whether or not this link is enabled (and therefore clickable). - return enabled; -} - - - - -void URLView::SetColor( rgb_color color ) { - // Set the normal link color. - this->color = color; - if( IsEnabled() ) { - Window()->Lock(); - SetHighColor( color ); - Redraw(); - Window()->Unlock(); - } -} - - -void URLView::SetColor( uchar red, uchar green, uchar blue, uchar alpha ) { - // Set the normal link color. - rgb_color color; - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - SetColor( color ); -} - - -void URLView::SetClickColor( rgb_color color ) { - // Set the link color used when the link is clicked. - clickColor = color; -} - - -void URLView::SetClickColor( uchar red, uchar green, uchar blue, uchar alpha ) { - // Set the link color used when the link is clicked. - rgb_color color; - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - SetClickColor( color ); -} - - -void URLView::SetDisabledColor( rgb_color color ) { - // Set the color to draw in when the link is disabled. - disabledColor = color; - Window()->Lock(); - Redraw(); - Window()->Unlock(); -} - - -void URLView::SetDisabledColor( uchar red, uchar green, uchar blue, uchar alpha ) { - // Set the color to draw in when the link is disabled. - rgb_color color; - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - SetDisabledColor( color ); -} - - -void URLView::SetDraggable( bool draggable ) { - // Set whether or not this link is draggable. - this->draggable = draggable; -} - - -void URLView::SetEnabled( bool enabled ) { - // Set whether or not the link is enabled (and therefore clickable). - bool redraw = this->enabled != enabled; - this->enabled = enabled; - - if( Window() ) { - Window()->Lock(); - if( !enabled ) - SetHighColor( disabledColor ); - else - SetHighColor( color ); - if( redraw ) - Invalidate(); - Window()->Unlock(); - } -} - - -void URLView::SetHoverColor( rgb_color color ) { - // Set the link color used when the mouse cursor is over it. - hoverColor = color; -} - - -void URLView::SetHoverColor( uchar red, uchar green, uchar blue, uchar alpha ) { - // Set the color to draw in when the link is disabled. - rgb_color color; - color.red = red; - color.green = green; - color.blue = blue; - color.alpha = alpha; - SetHoverColor( color ); -} - - -void URLView::SetHoverEnabled( bool hover ) { - // Set whether or not to hover-highlight the link. - hoverEnabled = hover; -} - - -void URLView::SetIconSize( icon_size iconSize ) { - // Set the size of the icon that will be shown when the link is dragged. - if( iconSize == B_MINI_ICON ) this->iconSize = 16; - else this->iconSize = 32; -} - - -void URLView::SetUnderlineThickness( int thickness ) { - // Set the thickness of the underline in pixels. - underlineThickness = thickness; -} - - -void URLView::SetURL( const char *url ) { - // Set the URL value. - delete this->url; - this->url = new BString( url ); - - // If it's an e-mail link, we want to insert "mailto:" to the front - // if the user did not enter it. - if( IsEmailLink() ) { - if( this->url->FindFirst( "mailto:" ) != 0 ) { - this->url->Prepend( "mailto:" ); - return; - } - } - - // We want to see if the URL is valid. If not, we will disable it. - if( !IsFTPLink() && !IsHTMLLink() ) - SetEnabled( false ); -} - - - - - -void URLView::CopyToClipboard() { - // Copy the URL to the clipboard. - BClipboard clipboard( "system" ); - BMessage *clip = (BMessage *) NULL; - // Get the important URL (i.e. trim off "mailto:", etc.). - BString newclip = GetImportantURL(); - - // Be sure to lock the clipboard first. - if( clipboard.Lock() ) { - clipboard.Clear(); - if( (clip = clipboard.Data()) ) { - clip->AddData( "text/plain", B_MIME_TYPE, newclip.String(), - newclip.Length() + 1 ); - clipboard.Commit(); - } - clipboard.Unlock(); - } -} - - - -void URLView::CreateBookmark( const BString *fullName, const BString *title ) { - // Read the file defined by the path and the title. - BFile *file = new BFile( fullName->String(), B_WRITE_ONLY ); - - // Set the file's MIME type to be a bookmark. - BNodeInfo *nodeInfo = new BNodeInfo( file ); - nodeInfo->SetType( "application/x-vnd.Be-bookmark" ); - delete nodeInfo; - delete file; - - // Add all the attributes, both those inherrent to bookmarks and any - // the developer may have defined using AddAttribute(). - DIR *d; - int fd; - d = fs_open_attr_dir( fullName->String() ); - if( d ) { - fd = open( fullName->String(), O_WRONLY ); - fs_write_attr( fd, "META:title", B_STRING_TYPE, 0, title->String(), title->Length() + 1 ); - fs_write_attr( fd, "META:url", B_STRING_TYPE, 0, url->String(), url->Length() + 1 ); - WriteAttributes( fd ); - close( fd ); - fs_close_attr_dir( d ); - } -} - - -void URLView::CreatePerson( const BString *fullName, const BString *title ) { - // Read the file defined by the path and the title. - BFile *file = new BFile( fullName->String(), B_WRITE_ONLY ); - - // Set the file's MIME type to be a person. - BNodeInfo *nodeInfo = new BNodeInfo( file ); - nodeInfo->SetType( "application/x-person" ); - delete nodeInfo; - delete file; - - // Add all the attributes, both those inherrent to person files and any - // the developer may have defined using AddAttribute(). - DIR *d; - int fd; - d = fs_open_attr_dir( fullName->String() ); - if( d ) { - fd = open( fullName->String(), O_WRONLY ); - fs_write_attr( fd, "META:name", B_STRING_TYPE, 0, title->String(), title->Length() + 1 ); - BString email = GetImportantURL(); - fs_write_attr( fd, "META:email", B_STRING_TYPE, 0, email.String(), email.Length() + 1 ); - WriteAttributes( fd ); - close( fd ); - fs_close_attr_dir( d ); - } -} - - - -BPopUpMenu * URLView::CreatePopupMenu() { - // Create the right-click popup menu. - BPopUpMenu *returnMe = new BPopUpMenu( "URLView Popup", false, false ); - returnMe->SetAsyncAutoDestruct( true ); - - entry_ref app; - - // Set the text of the first item according to the link type. - if( IsEmailLink() ) { - // Find the name of the default e-mail client. - if( be_roster->FindApp( "text/x-email", &app ) == B_OK ) { - BEntry entry( &app ); - BString openLabel( _T("Send e-mail to this address using ") ); - char name[B_FILE_NAME_LENGTH]; - entry.GetName( name ); - openLabel.Append( name ); - returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) ); - } - } - else if( IsFTPLink() ) { - // Find the name of the default FTP client. - if( be_roster->FindApp( "application/x-vnd.Be.URL.ftp", &app ) == B_OK ) { - BEntry entry( &app ); - BString openLabel( _T("Connect to this server using ") ); - char name[B_FILE_NAME_LENGTH]; - entry.GetName( name ); - openLabel.Append( name ); - returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) ); - } - } - else { - // Find the name of the default HTML handler (browser). - if( be_roster->FindApp( "text/html", &app ) == B_OK ) { - BEntry entry( &app ); - BString openLabel( _T("Open this link using ") ); - char name[B_FILE_NAME_LENGTH]; - entry.GetName( name ); - openLabel.Append( name ); - returnMe->AddItem( new BMenuItem( openLabel.String(), NULL ) ); - } - } - returnMe->AddItem( new BMenuItem( _T("Copy this link to the clipboard"), NULL ) ); - - return returnMe; -} - - - -void URLView::DoBookmarkDrag() { - // Handle all of the bookmark dragging. This includes setting up - // the drag message and drawing the dragged bitmap. - - // Set up the drag message to support both BTextView dragging (using - // the URL) and file dropping (to Tracker). - BMessage *dragMessage = new BMessage( B_MIME_DATA ); - dragMessage->AddInt32( "be:actions", B_COPY_TARGET ); - dragMessage->AddString( "be:types", "application/octet-stream" ); - dragMessage->AddString( "be:filetypes", "application/x-vnd.Be-bookmark" ); - dragMessage->AddString( "be:type_descriptions", "bookmark" ); - dragMessage->AddString( "be:clip_name", Text() ); - dragMessage->AddString( "be:url", url->String() ); - - // This allows the user to drag the URL into a standard BTextView. - BString link = GetImportantURL(); - dragMessage->AddData( "text/plain", B_MIME_DATA, link.String(), - link.Length() + 1 ); - - // Query for the system's icon for bookmarks. - BBitmap *bookmarkIcon = new BBitmap( BRect( 0, 0, iconSize - 1, - iconSize - 1 ), B_CMAP8 ); - BMimeType mime( "application/x-vnd.Be-bookmark" ); - if( iconSize == 16 ) mime.GetIcon( bookmarkIcon, B_MINI_ICON ); - else mime.GetIcon( bookmarkIcon, B_LARGE_ICON ); - - // Find the size of the bitmap to drag. If the text is bigger than the - // icon, use that size. Otherwise, use the icon's. Center the icon - // vertically in the bitmap. - BRect urlRect = GetURLRect(); - BRect rect = urlRect; - rect.right += iconSize + 4; - if( (rect.bottom - rect.top) < iconSize ) { - int adjustment = (int) ((iconSize - (rect.bottom - rect.top)) / 2) + 1; - rect.top -= adjustment; - rect.bottom += adjustment; - } - - // Make sure the rectangle starts at 0,0. - rect.bottom += 0 - rect.top; - rect.top = 0; - - // Create the bitmap to draw the dragged image in. - BBitmap *dragBitmap = new BBitmap( rect, B_RGBA32, true ); - BView *dragView = new BView( rect, "Drag View", 0, 0 ); - dragBitmap->Lock(); - dragBitmap->AddChild( dragView ); - - BRect frameRect = dragView->Frame(); - - // Make the background of the dragged image transparent. - dragView->SetHighColor( B_TRANSPARENT_COLOR ); - dragView->FillRect( frameRect ); - - // We want 'g's, etc. to go below the underline. When the BeOS can - // do underlining of any font, this code can be removed. - font_height height; - GetFontHeight( &height ); - float descent = height.descent; - - // Find the vertical center of the view so we can vertically - // center everything. - int centerPixel = (int) ((frameRect.bottom - frameRect.top) / 2); - int textCenter = (int) (descent + underlineThickness) + centerPixel; - - // We want to draw everything only half opaque. - dragView->SetDrawingMode( B_OP_ALPHA ); - dragView->SetHighColor( color.red, color.green, color.blue, 128.0 ); - dragView->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE ); - - // Center the icon in the view. - dragView->MovePenTo( BPoint( frameRect.left, - centerPixel - (iconSize / 2) ) ); - dragView->DrawBitmap( bookmarkIcon ); - - // Draw the text in the same font (size, etc.) as the link view. - // Note: DrawString() draws the text at one pixel above the pen's - // current y coordinate. - BFont font; - GetFont( &font ); - dragView->SetFont( &font ); - dragView->MovePenTo( BPoint( frameRect.left + iconSize + 4, textCenter ) ); - dragView->DrawString( url->String() ); - - // Draw the underline in the requested thickness. - dragView->FillRect( BRect( (float) frameRect.left + iconSize + 4, - (float) (textCenter + 1), - (float) StringWidth( url->String() ) + iconSize + 4, - (float) textCenter + underlineThickness ) ); - - // Be sure to flush the view buffer so everything is drawn. - dragView->Flush(); - dragBitmap->Unlock(); - - // The URL's label is probably not the same size as the URL's - // address, which is what we're going to draw. So horizontally - // offset the bitmap proportionally to where the user clicked - // on the link. - float horiz = dragOffset.x / GetTextRect().Width(); - dragOffset.x = horiz * frameRect.right; - - DragMessage( dragMessage, dragBitmap, B_OP_ALPHA, - BPoint( dragOffset.x, (rect.Height() / 2) + 2 ), this ); - delete dragMessage; - - draggedOut = true; -} - - -void URLView::DoPersonDrag() { - // Handle all of the bookmark dragging. This includes setting up - // the drag message and drawing the dragged bitmap. - - // Set up the drag message to support both BTextView dragging (using - // the e-mail address) and file dropping (to Tracker). - BMessage *dragMessage = new BMessage( B_MIME_DATA ); - dragMessage->AddInt32( "be:actions", B_COPY_TARGET ); - dragMessage->AddString( "be:types", "application/octet-stream" ); - dragMessage->AddString( "be:filetypes", "application/x-person" ); - dragMessage->AddString( "be:type_descriptions", "person" ); - dragMessage->AddString( "be:clip_name", Text() ); - - // This allows the user to drag the e-mail address into a - // standard BTextView. - BString email = GetImportantURL(); - dragMessage->AddData( "text/plain", B_MIME_DATA, email.String(), - email.Length() + 1 ); - - // Query for the system's icon for bookmarks. - BBitmap *personIcon = new BBitmap( BRect( 0, 0, iconSize - 1, - iconSize - 1 ), B_CMAP8 ); - #ifdef ZETA - BMimeType mime( "application/x-vnd.Be-PEPL" ); - #else - BMimeType mime( "application/x-person" ); - #endif - if( iconSize == 16 ) mime.GetIcon( personIcon, B_MINI_ICON ); - else mime.GetIcon( personIcon, B_LARGE_ICON ); - - // Find the size of the bitmap to drag. If the text is bigger than the - // icon, use that size. Otherwise, use the icon's. Center the icon - // vertically in the bitmap. - BRect rect = GetTextRect(); - rect.right += iconSize + 4; - if( (rect.bottom - rect.top) < iconSize ) { - int adjustment = (int) ((iconSize - (rect.bottom - rect.top)) / 2) + 1; - rect.top -= adjustment; - rect.bottom += adjustment; - } - - // Make sure the rectangle starts at 0,0. - rect.bottom += 0 - rect.top; - rect.top = 0; - - // Create the bitmap to draw the dragged image in. - BBitmap *dragBitmap = new BBitmap( rect, B_RGBA32, true ); - BView *dragView = new BView( rect, "Drag View", 0, 0 ); - dragBitmap->Lock(); - dragBitmap->AddChild( dragView ); - - BRect frameRect = dragView->Frame(); - - // Make the background of the dragged image transparent. - dragView->SetHighColor( B_TRANSPARENT_COLOR ); - dragView->FillRect( frameRect ); - - // We want 'g's, etc. to go below the underline. When the BeOS can - // do underlining of any font, this code can be removed. - font_height height; - GetFontHeight( &height ); - float descent = height.descent; - - // Find the vertical center of the view so we can vertically - // center everything. - int centerPixel = (int) ((frameRect.bottom - frameRect.top) / 2); - int textCenter = (int) (descent + underlineThickness) + centerPixel; - - // We want to draw everything only half opaque. - dragView->SetDrawingMode( B_OP_ALPHA ); - dragView->SetHighColor( 0.0, 0.0, 0.0, 128.0 ); - dragView->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE ); - - // Center the icon in the view. - dragView->MovePenTo( BPoint( frameRect.left, - centerPixel - (iconSize / 2) ) ); - dragView->DrawBitmap( personIcon ); - - // Draw the text in the same font (size, etc.) as the link view. - // Note: DrawString() draws the text at one pixel above the pen's - // current y coordinate. - BFont font; - GetFont( &font ); - dragView->SetFont( &font ); - dragView->MovePenTo( BPoint( frameRect.left + iconSize + 4, textCenter ) ); - dragView->DrawString( Text() ); - - // Be sure to flush the view buffer so everything is drawn. - dragView->Flush(); - dragBitmap->Unlock(); - - // The Person icon adds some width to the bitmap that we are - // going to draw. So horizontally offset the bitmap proportionally - // to where the user clicked on the link. - float horiz = dragOffset.x / GetTextRect().Width(); - dragOffset.x = horiz * frameRect.right; - - DragMessage( dragMessage, dragBitmap, B_OP_ALPHA, - BPoint( dragOffset.x, - (rect.Height() + underlineThickness) / 2 + 2), this ); - delete dragMessage; - - draggedOut = true; -} - - - -BString URLView::GetImportantURL() { - // Return the relevant portion of the URL (i.e. strip off "mailto:" from - // e-mail address URLs). - BString returnMe; - - if( IsEmailLink() ) url->CopyInto( returnMe, 7, url->CountChars() - 6 ); - else url->CopyInto( returnMe, 0, url->CountChars() ); - - return returnMe; -} - -BRect URLView::GetTextRect() { - - // This function will return a BRect that contains only the text - // and the underline, so the mouse can change and the link will - // be activated only when the mouse is over the text itself, not - // just within the view. - - // Note: We'll use bounding boxes, because they are the most - // accurate, and since the user is interacting with the - // view, off-by-one-pixel errors look bad. - const char *textArray[1]; - textArray[0] = Text(); - - escapement_delta delta; - delta.nonspace = 0; - delta.space = 0; - escapement_delta escapements[1]; - escapements[0] = delta; - - BRect returnMe; - BRect rectArray[1]; - rectArray[0] = returnMe; - - BFont font; - GetFont( &font ); - font.GetBoundingBoxesForStrings( textArray, 1, B_SCREEN_METRIC, escapements, rectArray ); - - BRect frame = Frame(); - frame.OffsetTo( B_ORIGIN ); - returnMe = rectArray[0]; - - // Get the height of the current font. - font_height height; - GetFontHeight( &height ); - float descent = height.descent; - - // Account for rounding of the floats when drawn to avoid - // one-pixel-off errors. - float lowerBound = 0; - if( (((int) descent) * 2) != ((int) (descent * 2)) ) - lowerBound = 1; - - // Adjust the bounding box to reflect where the text is in the view. - returnMe.bottom += 1; - returnMe.OffsetTo( B_ORIGIN ); - float rectHeight = returnMe.Height(); - returnMe.bottom = frame.bottom - descent; - returnMe.top = returnMe.bottom - rectHeight; - returnMe.bottom += 1 + underlineThickness; - returnMe.OffsetBy( 0.0, -(1 + lowerBound) ); - - return returnMe; -} - - -BRect URLView::GetURLRect() { - //Redraw(); - // This function will return a BRect that contains only the URL - // and the underline, so we can draw it when the user drags. - // We'll use GetFontHeight() instead of bounding boxes here - // because a possible pixel or two off doesn't matter, whereas it - // does when detecting if the user has the cursor over the link. - BRect frame = Frame(); - frame.OffsetTo( B_ORIGIN ); - - // Get the height of the current font. - font_height height; - GetFontHeight( &height ); - - float stringHeight = underlineThickness + height.ascent - 1; - - // Get the rectangle of just the string. - return BRect( frame.left, frame.bottom - stringHeight, - frame.left + StringWidth( url->String() ), - frame.bottom - 1 ); -} - - -bool URLView::IsEmailLink() { - // Is this link an e-mail link? - if( url->FindFirst( "mailto:" ) == 0 ) - return true; - - if( !IsHTMLLink() && !IsFTPLink() && - url->FindFirst( "@" ) != B_ERROR ) { - return true; - } - - return false; -} - - -bool URLView::IsFTPLink() { - // Is this link an FTP link? - return( url->FindFirst( "ftp://" ) == 0 ); -} - - -bool URLView::IsHTMLLink() { - // Is this link an HTML or file link? - return( (url->FindFirst( "http://" ) == 0 ) || - (url->FindFirst( "file://" ) == 0 ) || - (url->FindFirst( "https://" ) == 0 ) ); -} - -void URLView::LaunchURL() { - // Is the URL a mail link or HTTP? - if( IsEmailLink() ) { - // Lock the string buffer and pass it to the mail program. - char *link = url->LockBuffer( url->Length()+1 ); - status_t result = be_roster->Launch( "text/x-email", 1, &link ); - url->UnlockBuffer(); - // Make sure the user has an e-mail program. - if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) { - BAlert *alert = new BAlert( "E-mail Warning", - "There is no e-mail program on your machine that is configured as the default program to send e-mail.", - "Ok", NULL, NULL, B_WIDTH_AS_USUAL, - B_WARNING_ALERT ); - alert->Go(); - } - } - // Handle an HTTP link. - else if( IsHTMLLink() ) { - // Lock the string buffer and pass it to the web browser. - char *link = url->LockBuffer( url->Length()+1 ); - status_t result = be_roster->Launch( "text/html", 1, &link ); - url->UnlockBuffer(); - // Make sure the user has a web browser. - if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) { - BAlert *alert = new BAlert( "Web Browser Warning", - "There is no web browser on your machine that is configured as the default program to view web pages.", - "Ok", NULL, NULL, B_WIDTH_AS_USUAL, - B_WARNING_ALERT ); - alert->Go(); - } - } - // Handle an FTP link. - else if( IsFTPLink() ) { - // Lock the string buffer and pass it to the FTP client. - char *link = url->LockBuffer( url->Length()+1 ); - status_t result = be_roster->Launch( "application/x-vnd.Be.URL.ftp", - 1, &link ); - url->UnlockBuffer(); - // Make sure the user has an FTP client. - if( result != B_NO_ERROR && result != B_ALREADY_RUNNING ) { - BAlert *alert = new BAlert( "FTP Warning", - "There is no FTP client on your machine that is configured as the default program to connect to an FTP server.", - "Ok", NULL, NULL, B_WIDTH_AS_USUAL, - B_WARNING_ALERT ); - alert->Go(); - } - } - - // We don't know how to handle anything else. -} - -void URLView::Redraw() { - // Redraw the link without flicker. - BRect frame = Frame(); - frame.OffsetTo(0,0 ); - Draw( frame ); -} - -void URLView::WriteAttributes( int fd ) { - // Write the developer-defined attributes to the newly-created file. - KeyPair *item; - for( int i = 0; (item = (KeyPair *) attributes->ItemAt(i)); i++ ) { - fs_write_attr( fd, item->key->String(), B_STRING_TYPE, 0, item->value->String(), item->value->Length() + 1 ); - } -} diff --git a/src/URLView.h b/src/URLView.h deleted file mode 100644 index 9d39c6e..0000000 --- a/src/URLView.h +++ /dev/null @@ -1,152 +0,0 @@ -/* 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 -#include -#include -#include -#include -#include - - - -// 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 dark_green = { 107, 142, 035 }; -// 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 ); - //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: - 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; - - - int prevMouseStateInfo; - typedef struct kp { - BString *key; - BString *value; - } KeyPair; -}; - - - -#endif // TH_URL_VIEW diff --git a/src/YAB.rdef b/src/YAB.rdef deleted file mode 100644 index b3cf6c4..0000000 --- a/src/YAB.rdef +++ /dev/null @@ -1,38 +0,0 @@ - -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 = 5, - - variety = B_APPV_FINAL, - internal = 3, - - 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; diff --git a/src/YAB.rdef.rsrc b/src/YAB.rdef.rsrc deleted file mode 100644 index fab91e5..0000000 Binary files a/src/YAB.rdef.rsrc and /dev/null differ diff --git a/src/YabBitmapView.cpp b/src/YabBitmapView.cpp deleted file mode 100644 index ce4d526..0000000 --- a/src/YabBitmapView.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include -#include -#include -#include -#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); -} - diff --git a/src/YabBitmapView.h b/src/YabBitmapView.h deleted file mode 100644 index 0561d6b..0000000 --- a/src/YabBitmapView.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef YABBITMAPVIEW_H -#define YABBITMAPVIEW_H - -#include - -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 diff --git a/src/YabFilePanel.cpp b/src/YabFilePanel.cpp deleted file mode 100644 index ea022cf..0000000 --- a/src/YabFilePanel.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include -#include -#include -#include -#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; -} diff --git a/src/YabFilePanel.h b/src/YabFilePanel.h deleted file mode 100644 index 67b633a..0000000 --- a/src/YabFilePanel.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef YABFILEPANEL_H -#define YABFILEPANEL_H - -class YabFilePanel -{ - public: - BEntry *MyFilePanel(const char *name, const char *directory, const char* filename, int panelType); -}; - -#endif diff --git a/src/YabFilePanelLooper.cpp b/src/YabFilePanelLooper.cpp deleted file mode 100644 index 08a8994..0000000 --- a/src/YabFilePanelLooper.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#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; - } -} - diff --git a/src/YabFilePanelLooper.h b/src/YabFilePanelLooper.h deleted file mode 100644 index 77ebc98..0000000 --- a/src/YabFilePanelLooper.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef YABFPLOOPER_H -#define YABFPLOOPER_H - -#include -#include -#include - -class YabFilePanelLooper : public BLooper -{ - public: - YabFilePanelLooper(sem_id semaphore); - void MessageReceived(BMessage *msg); - BEntry *GetChosenFile(); - private: - BEntry *myEntry; - sem_id mySemaphore; -}; - -#endif diff --git a/src/YabInterface.cpp b/src/YabInterface.cpp deleted file mode 100644 index e2ba054..0000000 --- a/src/YabInterface.cpp +++ /dev/null @@ -1,11085 +0,0 @@ -#include "global.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -//#include "GameSoundDevice.h" -#include -#include -#include -#include -#include -#include -//#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" - -#include "CalendarControl.h" -#include "YabFilePanel.h" -#include "SplitPane.h" -#include "URLView.h" -#include "Spinner.h" -#include "YabTabView.h" -#include "TabView.h" -#ifdef LIBBSVG - #include -#endif - -#include -#include - -#include "YabInterface.h" -#include "YabWindow.h" -#include "YabView.h" -#include "YabBitmapView.h" -#include "YabList.h" - -#include "YabText.h" -#include "YabMenu.h" -#include "YabStackView.h" -#include "column/YabColumnType.h" -#include "column/ColorTools.h" -#include "column/ColumnListView.h" - - -BMediaTrack* playTrack; -media_format playFormat; -BSoundPlayer* player = 0; - - -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 YABSHORTCUT = 'YBsh'; -const uint32 TYPE_YABVIEW = 1; -char * refsRec=(char*)""; - -BCatalog *yabCatalog; - -static bool localize = false; -static bool quitting = false; -static property_info prop_list[] = { - { "YabSendString", {B_SET_PROPERTY, 0}, {B_NAME_SPECIFIER, 0}, "Send a string to MESSAGE$"}, - 0 // terminate list -}; - -const char* _L(const char* text) -{ - if(localize && yabCatalog) - return yabCatalog->GetString(text, NULL); //B_TRANSLATE_CONTEXT); - return text; -} -/** - * Start the interpreter thread - */ -int32 interpreter(void *data) -{ - int argc,t; - char **argv; - YabInterface *yab; - BList *myData = (BList*)data; - argc = (int)(addr_t)myData->ItemAt(0); - argv = (char**)myData->ItemAt(1); - yab = (YabInterface*)myData->ItemAt(2); - - t = mmain(argc,argv, yab); - return t; -} - -/** - * Constructor sets application directory, spawn the interpreter thread - */ -YabInterface::YabInterface(int argc, char **argv, const char* signature) - :BApplication(signature) -{ - BPath AppDirectory; - - // app directory - app_info appinfo; - - if( GetAppInfo( &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()); - } - } - } - - localMessage = ""; - - BList *myData = new BList(3); - myData->AddItem((void*)(addr_t)argc); - myData->AddItem((void*)argv); - myData->AddItem((void*)this); - myThread = spawn_thread(interpreter,"YabInterpreter",B_NORMAL_PRIORITY,(void*)myData); - if(myThread < B_OK) - { - printf("Can not start thread. Out of memory or maximum thread amount reached.\n"); - printf("Exiting now \n\n"); - exit(1); - } - - if(resume_thread(myThread) < B_OK) - { - printf("Error while starting interpreter!\n"); - printf("Exiting now \n\n"); - exit(1); - } - - viewList = new YabList(); - yabbitmaps = new BList(); - yabcanvas = new BList(); - drawStroking = false; - yabPattern = B_SOLID_HIGH; - yabAlpha = 255; - errorCode = 0; - Roster = NULL; - currentLineNumber = -1; - exiting = false; - - for(int i=0; i<63; i++) - mousemessagebuffer[i] = ' '; - mousemessagebuffer[63] = '\0'; - - myProps = new BPropertyInfo(prop_list); - currentLib = ""; - lastMouseMsg = ""; -} - -YabInterface::~YabInterface() -{ - delete mainFileName; - // delete song; - // delete fopen; - // delete fsave; - delete viewList; - // delete Roster; - delete myProps; - delete fPlayer; - if(yabCatalog) - delete yabCatalog; - while(yabbitmaps->CountItems()>0) - { - int i = 0; - BBitmap *b = (BBitmap*)yabbitmaps->RemoveItem(i); - delete b; - } -} - -/** - * Returns the application directory - */ -const char* YabInterface::GetApplicationDirectory() -{ - return (const char*) ApplicationDirectory; -} - -status_t YabInterface::GetSupportedSuites(BMessage *msg) -{ - msg->AddString("suites", "suite/vnd.yab-YabInterface"); - BPropertyInfo prop_info(prop_list); - msg->AddFlat("messages", &prop_info); - return BApplication::GetSupportedSuites(msg); -} - -BHandler* YabInterface::ResolveSpecifier(BMessage *msg, int32 index, BMessage *spec, int32 form, const char *prop) -{ - if (myProps->FindMatch(msg, index, spec, form, prop) >= 0) - return (BHandler*)this; - return BApplication::ResolveSpecifier(msg, index, spec, form, prop); -} - -void YabInterface::MessageReceived(BMessage *message) -{ - // message->PrintToStream(); - switch(message->what) - { - case B_SET_PROPERTY: - { - BMessage msg; - int32 i,w; - const char *prop; - - if(message->GetCurrentSpecifier(&i, &msg, &w, &prop) != B_BAD_SCRIPT_SYNTAX) - { - BString s; - msg.FindString("name", &s); - localMessage += "_Scripting:"; - localMessage += s; - localMessage +="|"; - } - } - break; - case B_REFS_RECEIVED: - { - entry_ref ref; - if(message->FindRef("refs", 0, &ref)==B_OK) - { - BEntry e(&ref); - BPath path; - e.GetPath(&path); - localMessage += "_RefsReceived:"; - localMessage += path.Path(); - localMessage +="|"; - } - } - break; - default: - BApplication::MessageReceived(message); - break; - } -} - -/** - * The QUIT_REQUESTED message arrived. If the interpreter thread is still active, - * kill it, otherwise exit directly. - */ -bool YabInterface::QuitRequested() -{ - //exiting = true; - //return false; - exiting = true; - ExitRequested(); - snooze(20000); - return true; -} - -void YabInterface::RefsReceived(BMessage *message){ - entry_ref ref; - BString tempstr; - if(message->FindRef("refs", 0, &ref)==B_OK) - { - BEntry e(&ref); - BPath path; - e.GetPath(&path); - tempstr += path.Path(); - refsRec = strdup(tempstr.String()); - } -} - -bool YabInterface::ExitRequested() -{ - status_t exit_val; - thread_info t; - // printf("QUITDEBUG: Exit\n"); - Lock(); - // printf("QUITDEBUG: Locked Ok\n"); - // if(!quitting) - // { - // printf("QUITDEBUG: quitting\n"); - // kill_thread(myThread); - // printf("QUITDEBUG: Kill Thread Ok\n"); - // } - // printf("QUITDEBUG: 1\n"); - - for(int i=0; iLock()) - w->Quit(); - } - - snooze(15000); - // printf("QUITDEBUG: 3\n"); - - - // BMessenger(be_app).SendMessage(new BMessage(B_QUIT_REQUESTED)); - Quit(); - // printf("QUITDEBUG: Quit\n"); - // printf("QUITDEBUG: wait\n"); - // wait_for_thread(myThread, &exit_val); - // get_thread_info(myThread, &t); - // kill_team(t.team); - // printf("QUITDEBUG: Stopped waiting\n"); - Unlock(); - // printf("QUITDEBUG: Unlock\n"); - - exit_thread(B_OK); - - return true; -} - -/** - * Open a window, add the main view. - */ -void YabInterface::OpenWindow(const BRect frame, const char* id, const char* title) -{ - YabWindow* w = new YabWindow(frame,title,id, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS); - YabView* myView = new YabView(w->Bounds(), id, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_NAVIGABLE_JUMP); - w->Lock(); - w->AddChild(myView); - - viewList->AddView(id, myView, TYPE_YABVIEW); - // viewList->PrintOut(); - - // w->Minimize(); - w->SetSizeLimits(10,3000,10,3000); - w->Show(); - w->Unlock(); - w->layout = -1; -} - -int YabInterface::CloseWindow(const char* view) -{ - int tmp = 0; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *child, *oldchild; - if(child = myView->ChildAt(0)) - { - while(child) - { - CleanupYabTabView(child); - if(is_kind_of(child, YabBitmapView)) - yabcanvas->RemoveItem(child); - - // viewList->PrintOut(); - CleanupSubchildView(child->ChildAt(0)); - if(viewList->GetView(child->Name())) - { - RemoveView(child); - viewList->DelView(child->Name()); - } - - oldchild = child; - child = child->NextSibling(); - - if(is_kind_of(oldchild, YabView)) - DrawClear(oldchild->Name(), true); - if(is_kind_of(oldchild, BMenuBar)) - { - oldchild->Hide(); - } - oldchild->RemoveSelf(); - delete oldchild; - } - } - if(is_kind_of(myView, YabView)) - DrawClear(myView->Name(), true); - if(is_kind_of(myView, BMenuBar)) - myView->Hide(); - myView->RemoveSelf(); - delete myView; - viewList->DelView(view); - // viewList->PrintOut(); - w->Quit(); - tmp = 1; - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); - - return tmp; -} - -void YabInterface::View(BRect frame, const char* id, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabView *newView = new YabView(frame, id, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_NAVIGABLE_JUMP); - if(w->layout == -1) - newView->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - newView->SetResizingMode(w->layout); - myView->AddChild(newView); - - viewList->AddView(id, newView, TYPE_YABVIEW); - // viewList->PrintOut(); - - newView->Invalidate(); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::BoxView(BRect frame, const char* id, const char* text, int lineType, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBox *newBox = new BBox(frame, id, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE_JUMP); - font_height fh; - (be_bold_font)->GetHeight(&fh); - float y1 = fh.ascent + fh.descent + fh.leading + 1.0; - YabView *newView = new YabView(BRect(3,y1,frame.Width()-3,frame.Height()-3), id, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE_JUMP); - if(w->layout == -1) - { - newBox->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - newView->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - } - else - { - newBox->SetResizingMode(w->layout); - newView->SetResizingMode(w->layout); - } - newBox->SetLabel(text); - switch(lineType) - { - case 0: newBox->SetBorder(B_NO_BORDER); - break; - case 1: newBox->SetBorder(B_PLAIN_BORDER); - break; - default: newBox->SetBorder(B_FANCY_BORDER); - break; - } - - newBox->AddChild(newView); - myView->AddChild(newBox); - viewList->AddView(id, newView, TYPE_YABVIEW); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::BoxViewSet(const char* id, const char* option, const char* value) -{ - - YabView *myView = NULL; - BString tmpOption(option); - BString tmpValue(value); - BBox *myBox = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - - w->Lock(); - - myBox = cast_as(myView->FindView(id), BBox); - if(myBox) - { - if(tmpOption.IFindFirst("label")!=B_ERROR) - { - myBox->SetLabel(tmpValue); - w->Unlock(); - return; - } - if(tmpOption.IFindFirst("line")!=B_ERROR) - { - if(tmpValue.IFindFirst("0")!=B_ERROR) - { - myBox->SetBorder(B_NO_BORDER); - w->Unlock(); - return; - } - if(tmpValue.IFindFirst("1")!=B_ERROR) - { - myBox->SetBorder(B_PLAIN_BORDER); - w->Unlock(); - return; - } - if(tmpValue.IFindFirst("2")!=B_ERROR) - { - myBox->SetBorder(B_FANCY_BORDER); - w->Unlock(); - return; - } - - } - w->Unlock(); - } - else - w->Unlock(); - Error(id, "BOXVIEW"); - - } - - - } - - - } -} -void YabInterface::Tab(BRect frame, const char* id, const char* mode, const char* view) -{ - BTabView::tab_side side; - BString option(mode); - if(option.IFindFirst("top") != B_ERROR) - side = BTabView::kTopSide; - else if(option.IFindFirst("bottom") != B_ERROR) - side = BTabView::kBottomSide; - else if(option.IFindFirst("left") != B_ERROR) - side = BTabView::kLeftSide; - else if(option.IFindFirst("right") != B_ERROR) - side = BTabView::kRightSide; - else ErrorGen("Invalid Option"); - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - - YabTabView *myTabView = new YabTabView(frame, id); - - if(w->layout == -1) - myTabView->SetResizingMode(B_FOLLOW_ALL); - else - myTabView->SetResizingMode(w->layout); - - myTabView->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE|B_NAVIGABLE_JUMP); - - myTabView->SetTabSide(side); - myTabView->SetTabWidth(B_WIDTH_FROM_LABEL); - //myTabView->SetTabWidth(B_WIDTH_AS_USUAL); - - myView->AddChild(myTabView); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::TabAdd(const char* id, const char* tabname) -{ - YabView *myView = NULL; - YabTabView *myTabView = NULL; - - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - //viewList->PrintOut(); - //fprintf(stderr, "Viewlist %d\n",viewList->ItemAt(i)); - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTabView = cast_as(myView->FindView(id), YabTabView); - - //myTabView->FindTabName(tabname); - if(myTabView) - { - BString t(id); - t << myTabView->CountTabs()+1; - BRect contentFrame = myTabView->Bounds(); - YabView *newView = new YabView(contentFrame, t.String(), B_FOLLOW_ALL_SIDES,B_WILL_DRAW|B_NAVIGABLE_JUMP); - viewList->AddView(t.String(), newView, TYPE_YABVIEW); - myTabView->AddTab(newView, tabname); - w->Unlock(); - return; - } - - w->Unlock(); - - } - } - - } - Error(id, "TABVIEW"); -} -void YabInterface::TabDel(const char* id, int num) //Reactivating Lorenz Glaser (aka lorglas) 20200801 -{ - YabView *myView = NULL; - YabTabView *myTabView=NULL; - - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTabView = cast_as(myView->FindView(id), YabTabView); - if(myTabView) - { - if(num>=0 && num<=myTabView->CountTabs() && num != myTabView->Selection()) - { - if (num<=0) { - num=1; //If you deleted Tab Zero you must reselect Tab Zero - } - - myTabView->Select(num-1); //Selection of tab before - YabTabView* tabView = static_cast(myTabView); - YabView *t = static_cast(tabView->TabAt(num)->View()); - RemoveView(t); - //viewList->DelView(t->NameForTabView()); - myTabView->RemoveTab(num); //Remove Tab - - //viewList->PrintOut(); - } - w->Unlock(); - //viewList->PrintOut(); - return ; - } - //w->Unlock(); - } - } - } - Error(id, "TABVIEW"); -} -/* -void YabInterface::TabADD2(const char* id, int num) //Reactivating Lorenz Glaser (aka lorglas) 20200801 -{ - myTabView->AddTab(id, tabname); - myTabView->AddTab(num); - - } - Error(id, "TABVIEW"); -} -/* -void YabInterface::TabDel(const char* id, int num) -{ - - YabView *myView = NULL; - #ifdef BUILD_HAIKUTAB - YabTabView *myTabView = NULL; - #else - BTabView *myTabView = NULL; - #endif - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - - if(w) - { - w->Lock(); - #ifdef BUILD_HAIKUTAB - myTabView = cast_as(myView->FindView(id), YabTabView); - #else - myTabView = cast_as(myView->FindView(id), BTabView); - #endif - if(myTabView) - { - if(num-1<0 || num-1>myTabView->CountTabs()) ErrorGen("Invalid tab number"); - BView *child, *oldchild; - if(child = myView->ChildAt(0)) - { - while(child) - { - BView *subchild; - if(subchild = child->ChildAt(0)) - while(subchild) - { - #ifdef BUILD_HAIKUTAB - if(is_kind_of(subchild, YabTabView)) - { - for(int i = 0; i<((YabTabView*)subchild)->CountTabs(); i++) - { - YabView *t = (YabView*)((YabTabView*)subchild)->TabAt(i); - RemoveView(t); - viewList->DelView(t->Name()); - } - } - #endif - if(viewList->GetView(subchild->Name())) - { - RemoveView(subchild); - viewList->DelView(subchild->Name()); - } - subchild = subchild->NextSibling(); - } - if(viewList->GetView(child->Name())) - { - RemoveView(child); - viewList->DelView(child->Name()); - } - - - oldchild = child; - child = child->NextSibling(); - - if(is_kind_of(oldchild, YabView)) - DrawClear(oldchild->Name(), true); - if(is_kind_of(oldchild, BMenuBar)) - { - oldchild->Hide(); - } - oldchild->RemoveSelf(); - delete oldchild; - } - } - if(is_kind_of(myView, YabView)) - DrawClear(myView->Name(), true); - if(is_kind_of(myView, BMenuBar)) - myView->Hide(); - BBox *box = cast_as(myView->Parent(), BBox); - myView->RemoveSelf(); - delete myView; - //viewList->DelView(w); - //viewList->DelView(window); - //viewList->DelView(id); - viewList->PrintOut(); - if(box) - { - box->RemoveSelf(); - delete box; - } - viewList->PrintOut(); - #ifdef BUILD_HAIKUTAB - WindowClear(myTabView->ItemAt(num-1)->Name()); - RemoveView(myTabView->ItemAt(num-1)); - //#endif - #else - - - //WindowClear((myTabView->Selection())); - //WindowClear(myTabView->TabAt(num-1)->Name()); - - //WindowClear(myTabView->ItemAt(num-1)->Name()); - //RemoveView(myTabView->ItemAt(num-1)); - - #endif - myTabView->RemoveTab(num); - - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TABVIEW"); -}*/ - -void YabInterface::TabSet(const char* id, int num) -{ - YabView *myView = NULL; - YabTabView *myTabView = NULL; - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTabView = cast_as(myView->FindView(id), YabTabView); - if(myTabView) - { - if(num>0 && num<=myTabView->CountTabs() && num != myTabView->Selection()+1) - myTabView->Select(num-1); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TABVIEW"); -} - -int YabInterface::TabViewGet(const char* id) -{ - int ret = -1; - YabView *myView = NULL; - YabTabView *myTabView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTabView = cast_as(myView->FindView(id), YabTabView); - if(myTabView) - { - ret = myTabView->Selection(); - w->Unlock(); - return ret+1; - } - w->Unlock(); - } - } - } - Error(id, "TABVIEW"); -} - -void YabInterface::Launch(const char* strg) -{ - BString tst(strg); - - entry_ref *ref = new entry_ref(); - BEntry entry(strg); - entry.GetRef(ref); - if(entry.IsDirectory()) - { - BMessage msg, reply; - msg.what = B_REFS_RECEIVED; - msg.AddRef("refs", ref); - BMessenger("application/x-vnd.Be-TRAK").SendMessage(&msg, &reply); - return; - } - - status_t t = be_roster->Launch(ref); - if(t != B_OK) - { - if(tst.FindFirst("http://") != B_ERROR || tst.FindFirst("file://") != B_ERROR || tst.FindFirst("www.") != B_ERROR) - { - char *link = tst.LockBuffer( tst.Length()+1 ); - status_t result = be_roster->Launch( "text/html", 1, &link ); - tst.UnlockBuffer(); - } - } - delete ref; -} - -void YabInterface::CreateButton(BRect frame, const char* id, const char* title, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BButton* myButton = new BButton(frame,id,title,new BMessage(YABBUTTON)); - if(w->layout == -1) - myButton->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myButton->SetResizingMode(w->layout); - myButton->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - // trick Haiku, resize button again - myButton->ResizeTo(frame.Width(), frame.Height()); - myView->AddChild(myButton); - // viewList->AddView(id, myButton, TYPE_BBUTTON); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -int YabInterface::CreateImage(BPoint coordinates, const char* FileName, const char* window) -{ - BBitmap* myBitmap = NULL; - BFile imageFile; - BPath imagePath; - int ret = 0; - - if(*FileName=='/') - imageFile.SetTo(FileName, B_READ_ONLY); - else - if(!strcmp(ApplicationDirectory,"")) - { - if(imagePath.SetTo((const char*)ApplicationDirectory, FileName)==B_OK) - imageFile.SetTo(imagePath.Path(), B_READ_ONLY); - } - if(imageFile.InitCheck()!=B_OK) - imageFile.SetTo(FileName, B_READ_ONLY); - - if(imageFile.InitCheck()!=B_OK) - return 1; - - Roster = BTranslatorRoster::Default(); - - if(!Roster) - return 2; - - BBitmapStream Stream; - - if(Roster->Translate(&imageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP)GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 10; - t->x1 = coordinates.x; t->y1 = coordinates.y; - t->bitmap = myBitmap; - myView->drawList->AddItem(t); - myView->Invalidate(BRect(coordinates.x, coordinates.y, coordinates.x+myBitmap->Bounds().Width(), coordinates.y+myBitmap->Bounds().Height())); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - drawing_mode mode = bview->DrawingMode(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->DrawBitmap(myBitmap, coordinates); - bview->SetDrawingMode(mode); - bview->Sync(); - b->Unlock(); - delete Roster; - delete myBitmap; - return 0; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - drawing_mode mode = bView->DrawingMode(); - bView->SetDrawingMode(B_OP_ALPHA); - bView->DrawBitmap(myBitmap, coordinates); - bView->SetDrawingMode(mode); - bView->Sync(); - b->Unlock(); - - myView->Draw(BRect(coordinates.x, coordinates.y, coordinates.x+myBitmap->Bounds().Width(), coordinates.y+myBitmap->Bounds().Height())); - w->Unlock(); - delete Roster; - delete myBitmap; - return 0; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } - delete Roster; - return 0; -} - -int YabInterface::CreateImage(BRect frame, const char* FileName, const char* window) -{ - int scaling = 0; - if(frame.right == -1) scaling = 1; - if(frame.bottom == -1) scaling = 2; - if(frame.right == -1 && frame.bottom == -1) scaling = 3; - - BBitmap* myBitmap = NULL; - BFile ImageFile; - BPath ImagePath; - int ret = 0; - - if(*FileName=='/') - ImageFile.SetTo(FileName, B_READ_ONLY); - else - if(!strcmp(ApplicationDirectory,"")) - { - if( ImagePath.SetTo((const char*)ApplicationDirectory, FileName) == B_OK) - ImageFile.SetTo(ImagePath.Path(), B_READ_ONLY); - } - - if(ImageFile.InitCheck()!=B_OK) - ImageFile.SetTo(FileName, B_READ_ONLY); - - if(ImageFile.InitCheck()!=B_OK) - return 1; - - Roster = BTranslatorRoster::Default(); - - if(!Roster) - return 2; - - BBitmapStream Stream; - - if(Roster->Translate(&ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) < B_OK) - return 3; - - if(Stream.DetachBitmap(&myBitmap) != B_OK) - return 4; - - BRect newframe; - switch(scaling) - { - case 1: - { - BRect t(myBitmap->Bounds()); - double width; - newframe = frame; - width = (t.right-t.left)*((frame.bottom-frame.top)/(t.bottom-t.top)); - newframe.right = newframe.left+width; - } - break; - case 2: - { - BRect t(myBitmap->Bounds()); - double height; - newframe = frame; - height = (t.bottom-t.top)*((frame.right-frame.left)/(t.right-t.left)); - newframe.bottom = newframe.top+height; - } - break; - case 3: newframe = myBitmap->Bounds(); - break; - default: newframe = frame; - } - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 11; - t->x1 = newframe.left; t->y1 = newframe.top; - t->x2 = newframe.right; t->y2 = newframe.bottom; - t->bitmap = myBitmap; - myView->drawList->AddItem(t); - myView->Invalidate(newframe); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - drawing_mode mode = bview->DrawingMode(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->DrawBitmap(myBitmap, newframe); - bview->SetDrawingMode(mode); - bview->Sync(); - b->Unlock(); - delete Roster; - delete myBitmap; - return 0; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - drawing_mode mode = bView->DrawingMode(); - bView->SetDrawingMode(B_OP_ALPHA); - bView->DrawBitmap(myBitmap, newframe); - bView->SetDrawingMode(mode); - bView->Sync(); - b->Unlock(); - - myView->Draw(newframe); - w->Unlock(); - delete Roster; - delete myBitmap; - return 0; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } - delete Roster; - return 0; -} - -int YabInterface::CreateSVG(BRect frame, const char* FileName, const char* window) -{ -#ifdef LIBBSVG - BPath path; - BString file; - file.SetTo(FileName); - if(FileName[0]!='/') - { - if(!strcmp(ApplicationDirectory,"")) - { - if(path.SetTo((const char*)ApplicationDirectory, FileName) == B_OK) - file.SetTo(path.Path()); - } - } - int ret = 0; - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); // untested! - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BSVGView *mySVG = new BSVGView(frame,"svgview",0); - mySVG->SetViewColor(myView->ViewColor()); - mySVG->SetScaleToFit(true); - if(w->layout == -1) - mySVG->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - mySVG->SetResizingMode(w->layout); - mySVG->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE); - - if(mySVG->LoadFromFile(file.String())!=B_OK) - ret = 1; - else - myView->AddChild(mySVG); - myView->Invalidate(); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); - return ret; -#else - return 2; -#endif -} - -void YabInterface::StatusBar(BRect frame, const char* id, const char* label1, const char* label2, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BStatusBar *bar = new BStatusBar(frame, id, label1, label2); - bar->SetBarHeight((float)frame.Height()-(be_plain_font)->Size()-5); - if(w->layout == -1) - bar->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - bar->SetResizingMode(w->layout); - myView->AddChild(bar); - bar->Draw(frame); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::StatusBarSet(const char* id, const char* label1, const char* label2, double state) -{ - YabView *myView = NULL; - BStatusBar *myBar = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myBar = cast_as(myView->FindView(id), BStatusBar); - if(myBar) - { - myBar->Reset(); - myBar->Update((float)state, label1, label2); - w->Unlock(); - return; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - } - Error(id, "STATUSBAR"); -} - -void YabInterface::StatusBarSet(BRect frame, const char* id, const char* view) -{ - // empty! -} - -void YabInterface::StatusBarSet(const char* id, int r, int g, int b) -{ - YabView *myView = NULL; - BStatusBar *myBar = NULL; - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myBar = cast_as(myView->FindView(id), BStatusBar); - if(myBar) - { - rgb_color rgb = {r,g,b,255}; - myBar->SetBarColor(rgb); - w->Unlock(); - return; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - } - Error(id, "STATUSBAR"); -} - -void YabInterface::CreateMenu(const char* menuhead, const char* menuitem, const char *shortcut, const char* window) -{ - char myShortcut; - int32 modifiers = 0; - BString t(shortcut); - if(t.Length()>1) - { - myShortcut = shortcut[t.Length()-1]; - if(t.IFindFirst("s")!=B_ERROR && t.IFindFirst("s")GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - YabMenu *menu = NULL; - BMenuItem *item = NULL; - w->Lock(); - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar == NULL) - { - menubar = new BMenuBar(myView->Bounds(),"menubar"); - myView->AddChild(menubar); - } - for(int i=0; iCountItems(); i++) - if(!strcmp( menubar->ItemAt(i)->Label(), menuhead)) - menu = cast_as(menubar->SubmenuAt(i), YabMenu); - if(menu == NULL) - { - menu = new YabMenu(menuhead); - menubar->AddItem((BMenu*)menu); - } - if(!strcmp(menuitem,"--")) - menu->AddItem(new BSeparatorItem()); - else - menu->AddItem(new BMenuItem(menuitem, new BMessage(YABMENU), myShortcut, modifiers)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateTextControl(BRect frame, const char* id, const char* label, const char* text, const char* window) -{ - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - //viewList->PrintOut(); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BTextControl *textControl = new BTextControl(frame, id ,label, text, new BMessage(YABTEXTCONTROL)); - //If the label is not set, a space of 5 pixels was still reserved to the left of the field. This place is now fully used - if (strcmp(label, "") == 0) //check if Label was set - { - textControl->SetDivider(textControl->StringWidth(label)); //+5.0); - } - else if (strcmp(label,"") != 0) - { - textControl->SetDivider(textControl->StringWidth(label)+5.0); - } - if(w) - { - if(w->layout == -1) - textControl->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - textControl->SetResizingMode(w->layout); - } - textControl->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(textControl); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateCheckBox(double x, double y, const char* id, const char* label, int isActivated, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BRect frame(x,y,x+1,y+1); - BCheckBox *checkBox = new BCheckBox(frame, id, label, new BMessage(YABCHECKBOX)); - checkBox->ResizeToPreferred(); - if(isActivated>0) checkBox->SetValue(B_CONTROL_ON); - if(w->layout == -1) - checkBox->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - checkBox->SetResizingMode(w->layout); - checkBox->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(checkBox); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateRadioButton(double x, double y, const char* groupID, const char* label, int isActivated, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BRect frame(x,y,x+1,y+1); - BRadioButton *radio = new BRadioButton(frame, groupID, label, new BMessage(YABRADIOBUTTON)); - radio->ResizeToPreferred(); - if(isActivated>0) radio->SetValue(B_CONTROL_ON); - if(w->layout == -1) - radio->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - radio->SetResizingMode(w->layout); - radio->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(radio); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateListBox(BRect frame, const char* title, int scrollbar, const char* window) -{ - YabView *myView = cast_as(((BView*)viewList->GetView(window)), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - uint32 resizeMode; - - w->Lock(); - - if(scrollbar == 3 || scrollbar == 1) frame.right -= B_V_SCROLL_BAR_WIDTH; - if(scrollbar>2) frame.bottom -= B_H_SCROLL_BAR_HEIGHT; - - BListView *list = new BListView(frame,title); - if(w->layout == -1) - resizeMode = B_FOLLOW_ALL; - else - resizeMode = w->layout; - list->SetResizingMode(resizeMode); - list->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - list->SetSelectionMessage(new BMessage(YABLISTBOXSELECT)); - list->SetInvocationMessage(new BMessage(YABLISTBOXINVOKE)); - switch(scrollbar) - { - case 3: // both - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, true)); - break; - case 2: // horizontal - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, false)); - break; - case 0: // none - myView->AddChild(list); - break; - default: // vertical is default - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, false, true)); - break; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateDropBox(BRect frame, const char* title, const char* label, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BPopUpMenu *dropmenu = new BPopUpMenu(""); - BMenuField *drop = new BMenuField(frame,title,label, dropmenu, true); - drop->ResizeToPreferred(); - //If the label is not set, a space of 5 pixels was still reserved to the left of the field. This place is now fully used - if (strcmp(label, "") == 0) //check if label was set - { - drop->SetDivider(drop->StringWidth(label)); - } - else if (strcmp(label,"") != 0) - { - drop->SetDivider(drop->StringWidth(label)+5.0); - } - //drop->SetDivider(drop->StringWidth(label)+5.0); - if(w->layout == -1) - drop->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - drop->SetResizingMode(w->layout); - drop->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(drop); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::CreateItem(const char* id, const char* item) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(id), BMenuField); - if(myMenuField) - { - BPopUpMenu *myPopup = cast_as(myMenuField->Menu(), BPopUpMenu); - if(myPopup) - { - if(!strcmp(item,"--")) - myPopup->AddItem(new BSeparatorItem()); - else - { - BMenuItem *tmp = new BMenuItem(item, new BMessage(YABDROPBOX)); - myPopup->AddItem(tmp); - if(myPopup->CountItems()==1) // first Item - tmp->SetMarked(true); - } - w->Unlock(); - return; - } - } - w->Unlock(); - } - } - } - Error(id, "DROPBOX"); -} - -void YabInterface::RemoveItem(const char* title, const char* item) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BListView *myList = cast_as(myView->FindView(title), BListView); - if(myList) - { - for(int i=0; iCountItems(); i++) - { - BStringItem *stritem = cast_as(myList->ItemAt(i), BStringItem); - if(stritem && !strcmp(stritem->Text(), item)) - { - myList->RemoveItem(i); - w->Unlock(); - return; - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(title, "DROPBOX"); -} - -void YabInterface::ClearItems(const char* title) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BListView *myList = cast_as(myView->FindView(title), BListView); - if(myList) - { - myList->RemoveItems(0,myList->CountItems()); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "DROPBOX"); -} - -void YabInterface::DrawText(BPoint coordinates, const char* text, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 0; - t->x1 = coordinates.x; t->y1 = coordinates.y; - t->chardata = strdup(text); - myView->drawList->AddItem(t); - - font_height height; - myView->GetFontHeight(&height); - BRect bbox; - bbox.left = coordinates.x; - bbox.top = coordinates.y - height.ascent; - bbox.right = coordinates.x + myView->StringWidth(text); - bbox.bottom = coordinates.y + height.descent; - - BFont tFont; - myView->GetFont(&tFont); - if(tFont.Rotation() == 0.0 && tFont.Shear() == 90.0) - myView->Invalidate(bbox); - else - myView->Invalidate(); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bview->DrawString(text, coordinates); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bView->DrawString(text, coordinates); - bView->Sync(); - b->Unlock(); - - font_height height; - bView->GetFontHeight(&height); - BRect bbox; - bbox.left = coordinates.x; - bbox.top = coordinates.y - height.ascent; - bbox.right = coordinates.x + bView->StringWidth(text); - bbox.bottom = coordinates.y + height.descent; - - myView->Draw(bbox); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawRect(BRect frame, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - if(drawStroking) - t->command = 4; - else - t->command = 5; - t->x1 = frame.left; t->y1 = frame.top; - t->x2 = frame.right; t->y2 = frame.bottom; - t->p = yabPattern; - myView->drawList->AddItem(t); - myView->Invalidate(frame); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - if(drawStroking) - bview->StrokeRect(frame, yabPattern); - else - bview->FillRect(frame, yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - // bView->SetDrawingMode(B_OP_ALPHA); - //bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - if(drawStroking) - bView->StrokeRect(frame, yabPattern); - else - bView->FillRect(frame, yabPattern); - bView->Sync(); - b->Unlock(); - - myView->Draw(frame); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawClear(const char* window, bool isExit) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - rgb_color lowcolor = myView->LowColor(); - rgb_color highcolor = myView->HighColor(); - BFont lastfont; - myView->GetFont(&lastfont); - while(myView->drawList->CountItems()>0) - { - YabDrawing *t = (YabDrawing*)myView->drawList->LastItem(); - myView->drawList->RemoveItem(t); - if(t->command == 0) delete [] t->chardata; - if(t->command == 10 || t->command == 11) delete t->bitmap; - delete t; - } - YabDrawing *t1 = new YabDrawing(); - t1->command = 7; - t1->r = lowcolor.red; t1->g = lowcolor.green; - t1->b = lowcolor.blue; t1->alpha = yabAlpha; - myView->drawList->AddItem(t1); - YabDrawing *t2 = new YabDrawing(); - t2->command = 6; - t2->r = highcolor.red; t2->g = highcolor.green; - t2->b = highcolor.blue; t2->alpha = yabAlpha; - myView->drawList->AddItem(t2); - YabDrawing *t3 = new YabDrawing(); - t3->command = 12; - t3->font = lastfont; - myView->drawList->AddItem(t3); - myView->Invalidate(); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - if(!isExit) Error(window, "VIEW"); -} - -void YabInterface::DrawDot(double x, double y, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 1; - t->x1 = x; t->y1 = y; - t->x2 = x; t->y2 = y; - t->p = yabPattern; - myView->drawList->AddItem(t); - myView->Invalidate(BRect(x,y,x,y)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bview->StrokeLine(BPoint(x,y), BPoint(x,y), yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - // bView->SetDrawingMode(B_OP_ALPHA); - // bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bView->StrokeLine(BPoint(x,y), BPoint(x,y), yabPattern); - bView->Sync(); - b->Unlock(); - - myView->Draw(BRect(x,y,x,y)); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawLine(double x1, double y1, double x2, double y2, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 1; - t->x1 = x1; t->y1 = y1; - t->x2 = x2; t->y2 = y2; - t->p = yabPattern; - myView->drawList->AddItem(t); - double minx1 = x1Invalidate(BRect(minx1,miny1,minx2,miny2)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bview->StrokeLine(BPoint(x1,y1), BPoint(x2,y2), yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - //bView->SetDrawingMode(B_OP_ALPHA); - //bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - bView->StrokeLine(BPoint(x1,y1), BPoint(x2,y2), yabPattern); - bView->Sync(); - b->Unlock(); - - double minx1 = x1Invalidate(BRect(minx1,miny1,minx2,miny2)); - myView->Draw(BRect(minx1,miny1,minx2,miny2)); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawCircle(double x, double y, double r, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - if(drawStroking) - t->command = 2; - else - t->command = 3; - t->x1 = x; t->y1 = y; - t->x2 = r; t->y2 = r; - t->p = yabPattern; - myView->drawList->AddItem(t); - myView->Invalidate(BRect(x-r,y-r,x+r,y+r)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - - if(drawStroking) - bview->StrokeEllipse(BPoint(x,y), r, r, yabPattern); - else - bview->FillEllipse(BPoint(x,y), r, r, yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - - b->Lock(); - // bView->SetDrawingMode(B_OP_ALPHA); - // bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - // bView->SetDrawingMode(B_OP_OVER); - if(drawStroking) - bView->StrokeEllipse(BPoint(x,y), r, r, yabPattern); - else - bView->FillEllipse(BPoint(x,y), r, r, yabPattern); - bView->Sync(); - b->Unlock(); - - myView->Draw(BRect(x-r,y-r,x+r,y+r)); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawEllipse(double x, double y, double r1, double r2, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - if(drawStroking) - t->command = 2; - else - t->command = 3; - t->x1 = x; t->y1 = y; - t->x2 = r1; t->y2 = r2; - t->p = yabPattern; - myView->drawList->AddItem(t); - myView->Invalidate(BRect(x-r1,y-r2,x+r1,y+r2)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - if(drawStroking) - bview->StrokeEllipse(BPoint(x,y), r1, r2, yabPattern); - else - bview->FillEllipse(BPoint(x,y), r1, r2, yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - // bView->SetDrawingMode(B_OP_ALPHA); - // bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - if(drawStroking) - bView->StrokeEllipse(BPoint(x,y), r1, r2, yabPattern); - else - bView->FillEllipse(BPoint(x,y), r1, r2, yabPattern); - bView->Sync(); - b->Unlock(); - - myView->Draw(BRect(x-r1,y-r2,x+r1,y+r2)); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char* window) -{ - double invx1 = x1x2?x1:x2; invx2 = invx2>x3?invx2:x3; invx2 = invx2>x4?invx2:x4; - double invy1 = y1y2?y1:y2; invy2 = invy2>y3?invy2:y3; invy2 = invy2>y4?invy2:y4; - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabDrawing *t = new YabDrawing(); - if(drawStroking) - t->command = 8; - else - t->command = 9; - t->x1 = x1; t->y1 = y1; - t->x2 = x2; t->y2 = y2; - t->x3 = x3; t->y3 = y3; - t->x4 = x4; t->y4 = y4; - t->p = yabPattern; - myView->drawList->AddItem(t); - myView->Invalidate(BRect(invx1,invy1,invx2,invy2)); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - BPoint p[4]; - p[0].Set(x1,y1); - p[1].Set(x2,y2); - p[2].Set(x3,y3); - p[3].Set(x4,y4); - - if(drawStroking) - { - bview->SetPenSize(1.01); - bview->StrokeBezier(p, yabPattern); - bview->SetPenSize(1.0); - } - else - bview->FillBezier(p, yabPattern); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - // bView->SetDrawingMode(B_OP_ALPHA); - // bView->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_COMPOSITE); - BPoint p[4]; - p[0].Set(x1,y1); - p[1].Set(x2,y2); - p[2].Set(x3,y3); - p[3].Set(x4,y4); - - if(drawStroking) - { - bView->SetPenSize(1.01); - bView->StrokeBezier(p, yabPattern); - bView->SetPenSize(1.0); - } - else - bView->FillBezier(p, yabPattern); - bView->Sync(); - b->Unlock(); - - myView->Draw(BRect(invx1,invy1,invx2,invy2)); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::CreateText(double x, double y, const char* id, const char* text, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - double h,b; - b = be_plain_font->StringWidth(text)+1; - h = be_plain_font->Size(); - BStringView *s = new BStringView(BRect(x,y-3,x+b,y+h-3), id, text); - s->ResizeToPreferred(); - if(w->layout == -1) - s->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - s->SetResizingMode(w->layout); - s->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE); - myView->AddChild(s); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::Text2(BRect frame, const char* id, const char* text, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BStringView *s = new BStringView(frame, id, text); - if(w->layout == -1) - s->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - s->SetResizingMode(w->layout); - s->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE); - myView->AddChild(s); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::TextAlign(const char* txt, const char* option) -{ - BString tmp(option); - alignment align; - if(tmp.IFindFirst("align-left")!=B_ERROR) - align = B_ALIGN_LEFT; - else if(tmp.IFindFirst("align-center")!=B_ERROR) - align = B_ALIGN_CENTER; - else if(tmp.IFindFirst("align-right")!=B_ERROR) - align = B_ALIGN_RIGHT; - else - ErrorGen("Unknown option"); - - YabView *myView = NULL; - BStringView *myStringView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myStringView = cast_as(myView->FindView(txt), BStringView); - if(myStringView) - { - myStringView->SetAlignment(align); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(txt, "TEXT"); -} - -void YabInterface::Slider(BRect frame, const char* id, const char* title, int min, int max, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BSlider *mySlider = new BSlider(frame, id, title, new BMessage(YABSLIDER), min, max); - if(w->layout == -1) - mySlider->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - mySlider->SetResizingMode(w->layout); - mySlider->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(mySlider); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::Slider(BRect frame, const char* id, const char* title, int min, int max, const char* option, const char* view) -{ - BString tmp(option); - bool thumb = true, orient = true; - if(tmp.IFindFirst("vertical")!=B_ERROR) - orient = false; - if(tmp.IFindFirst("triangle")!=B_ERROR) - thumb = false; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BSlider *mySlider = new BSlider(frame, id, title, new BMessage(YABSLIDER), min, max); - if(w->layout == -1) - mySlider->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - mySlider->SetResizingMode(w->layout); - mySlider->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - if(!orient) - { - mySlider->SetOrientation(B_VERTICAL); - mySlider->SetBarThickness(10); - } - if(!thumb) mySlider->SetStyle(B_TRIANGLE_THUMB); - myView->AddChild(mySlider); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::SetSlider(const char* id, const char* label1, const char* label2) -{ - YabView *myView = NULL; - BSlider *mySlider = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySlider = cast_as(myView->FindView(id), BSlider); - if(mySlider) - { - mySlider->SetLimitLabels(label1, label2); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "SLIDER"); -} - -void YabInterface::SetSlider(const char* id, const char* bottomtop, int count) -{ - hash_mark_location location = B_HASH_MARKS_BOTH; - BString tmp(bottomtop); - if(tmp.IFindFirst("none")!=B_ERROR) - location = B_HASH_MARKS_NONE; - if(tmp.IFindFirst("left")!=B_ERROR) - location = B_HASH_MARKS_LEFT; - if(tmp.IFindFirst("right")!=B_ERROR) - location = B_HASH_MARKS_RIGHT; - if(tmp.IFindFirst("top")!=B_ERROR) - location = B_HASH_MARKS_TOP; - if(tmp.IFindFirst("bottom")!=B_ERROR) - location = B_HASH_MARKS_BOTTOM; - YabView *myView = NULL; - BSlider *mySlider = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySlider = cast_as(myView->FindView(id), BSlider); - if(mySlider) - { - mySlider->SetHashMarks(location); - mySlider->SetHashMarkCount(count); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "SLIDER"); -} - -void YabInterface::SetSlider(const char* id, const char* part, int r, int g, int b) -{ - bool barcolor = true; - BString tmp(part); - if(tmp.IFindFirst("fillcolor")) - barcolor = false; - - YabView *myView = NULL; - BSlider *mySlider = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySlider = cast_as(myView->FindView(id), BSlider); - if(mySlider) - { - rgb_color rgb = {r,g,b,255}; - if(barcolor) - mySlider->SetBarColor(rgb); - else - mySlider->UseFillColor(true,&rgb); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "SLIDER"); -} - -void YabInterface::SetSlider(const char* id, int value) -{ - YabView *myView = NULL; - BSlider *mySlider = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySlider = cast_as(myView->FindView(id), BSlider); - if(mySlider) - { - mySlider->SetValue(value); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "SLIDER"); -} - -void YabInterface::SetOption(const char* id, const char* option, const char* value) -{ - bool label = false; - BString tmpOption(option); - if(tmpOption.IFindFirst("label")!=B_ERROR) - label = true; - - if(!label) - ErrorGen("Unknown option"); - - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BControl *target = cast_as(myView->FindView(id), BControl); - if(target) - { - target->SetLabel(value); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "CONTROL"); -} - -void YabInterface::SetOption(const char* id, const char* option, int r, int g, int b) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *target = myView->FindView(id); - if(target) - { - rgb_color rgb = {r,g,b,0}; - target->SetViewColor(rgb); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "VIEW"); -} - -void YabInterface::SetOption(const char* id, const char* option) -{ - BString tmpOption(option); - if(tmpOption.IFindFirst("auto-resize")==B_ERROR) - ErrorGen("Unknown option"); - - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *target = myView->FindView(id); - if(target) - { - target->ResizeToPreferred(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - ErrorGen("View not found"); -} - -void YabInterface::SetOption(const char* id, const char* option, int value) -{ - BString tmpOption(option); - bool isFocus = false; - bool isEnabled = false; - bool isVisible = false; - - if(tmpOption.IFindFirst("enabled")!=B_ERROR) - isEnabled = true; - if(tmpOption.IFindFirst("focus")!=B_ERROR) - isFocus = true; - if(tmpOption.IFindFirst("visible")!=B_ERROR) - isVisible = true; - - if(!isFocus && !isEnabled && !isVisible) - ErrorGen("Unknown option"); - - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *target = myView->FindView(id); - if(target) - { - if(isEnabled) - { - BControl *myControl = cast_as(target, BControl); - if(myControl) - myControl->SetEnabled(value); - else - { - BMenuField *myMenu = cast_as(target, BMenuField); - if(myMenu) - myMenu->SetEnabled(value); - else - Error(id, "CONTROL or DROPBOX"); - } - } - if(isFocus) - { - target->MakeFocus(value); - } - if(isVisible) - { - BControl *myControl = cast_as(target, BControl); - if(myControl) - { - if(value) - { - if (myControl->IsHidden()) - { - myControl->Show(); - } - } - else - { - if (!myControl->IsHidden()) - { - myControl->Hide(); - } - } - - } - - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - ErrorGen("View not found"); -} - -void YabInterface::DropZone(const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - myView->dropZone = true; - else - Error(view, "VIEW"); -} - -void YabInterface::ColorControl(double x, double y, const char* id, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BColorControl *myCControl = new BColorControl(BPoint(x,y), B_CELLS_32x8, 2, id, new BMessage(YABCOLORCONTROL),false); - if(w->layout == -1) - myCControl->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myCControl->SetResizingMode(w->layout); - myCControl->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(myCControl); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::ColorControl(const char* id, int r, int g, int b) -{ - YabView *myView = NULL; - BColorControl *myCControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myCControl = cast_as(myView->FindView(id), BColorControl); - if(myCControl) - { - rgb_color t = {r,g,b,255}; - myCControl->SetValue(t); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "COLORCONTROL"); -} - -void YabInterface::TextControl(const char* id, const char* text) -{ - YabView *myView = NULL; - BTextControl *myTControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTControl = cast_as(myView->FindView(id), BTextControl); - if(myTControl) - { - myTControl->SetText(text); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TEXTCONTROL"); -} - -void YabInterface::TextControl(const char* id, int mode) -{ - YabView *myView = NULL; - BTextControl *myTControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTControl = cast_as(myView->FindView(id), BTextControl); - if(myTControl) - { - BTextView *myTView = myTControl->TextView(); - - switch(mode) - { - case 1: - myTView->HideTyping(true); - break; - - default: - myTView->HideTyping(false); - - break; - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TEXTCONTROL"); -} - -void YabInterface::TextControl(const char* id, const char* option, const char* value) -{ - YabView *myView = NULL; - BString tmpOption(option); - BString tmpValue(value); - BTextControl *myTControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - - if(w) - { - w->Lock(); - int32 x=0; - myTControl = cast_as(myView->FindView(id), BTextControl); - - if(myTControl) - { - - BTextView *myTView = myTControl->TextView(); - if(tmpOption.IFindFirst("focus")!=B_ERROR) - { - if(tmpValue.IFindFirst("true")!=B_ERROR) - { - bool focused = true; - int32 ofset=0; - myTControl -> MakeFocus(focused); - myTView-> Select(ofset,ofset); - } - if(tmpValue.IFindFirst("false")!=B_ERROR) - { - bool focused = false; - myTControl -> MakeFocus(focused); - } - } - if(tmpOption.IFindFirst("Curser")!=B_ERROR || tmpOption.IFindFirst("Cursor")!=B_ERROR ) - { - const char* str_int = tmpValue.String(); - bool focused = true; - int32 ofset=0; - ofset= atoi(str_int); - myTControl -> MakeFocus(focused); - myTView-> Select(ofset,ofset); - } - if(tmpOption.IFindFirst("type")!=B_ERROR) - { - if(tmpValue.IFindFirst("number")!=B_ERROR) - { - - //Changing from for to String Method because it was possible to enter äöü and so on - //20.02.2019 Lorent Glaser - /*for (x=0;x<48; x++) - { - myTView->DisallowChar(x); - } - for (x=58;x<128; x++) - { - myTView->DisallowChar(x); - } - x=46; - myTView-> AllowChar(x);*/ - BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| " - "asdfghjkl:\"zxcvbnm<>?!@#$%^&*()-_=+`´°~\röäüÖÄÜß"); - for(int32 i=0; iDisallowChar(c); - } - } - - if(tmpValue.IFindFirst("alphanumeric")!=B_ERROR) - { - for (x=0;x<128; x++) - { - myTView->AllowChar(x); - } - - } - - } - if(tmpOption.IFindFirst("align")!=B_ERROR) - { - if(tmpValue.IFindFirst("right")!=B_ERROR) - { - myTControl->SetAlignment(B_ALIGN_LEFT,B_ALIGN_RIGHT); - } - if(tmpValue.IFindFirst("center")!=B_ERROR) - { - myTControl->SetAlignment(B_ALIGN_LEFT,B_ALIGN_CENTER); - } - if(tmpValue.IFindFirst("left")!=B_ERROR) - { - myTControl->SetAlignment(B_ALIGN_LEFT,B_ALIGN_LEFT); - } - } - if(tmpOption.IFindFirst("length")!=B_ERROR) - { - const char* str_int = tmpValue.String(); - int i = atoi(str_int); - if (i>0) - { - myTView->SetMaxBytes(i); - myTView->SetFontAndColor(be_fixed_font); - } - if (i=0) - { - ErrorGen("Bad length"); - } - } - - if(tmpOption.IFindFirst("exclude")!=B_ERROR) - { - int i; - for (i=0; i<= tmpValue.CountChars();i++) - { - x=tmpValue.ByteAt(i); - myTView->DisallowChar(x); - } - } - if(tmpOption.IFindFirst("include")!=B_ERROR) - { - int i; - for (i=0; i<= tmpValue.CountChars();i++) - { - x=tmpValue.ByteAt(i); - myTView->AllowChar(x); - } - } - } - w->Unlock(); - return; - } - w->Unlock(); - } - } -Error(id, "TEXTCONTROL"); -} - -void YabInterface::TextControl(const char* id) -{ - YabView *myView = NULL; - BTextControl *myTControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTControl = cast_as(myView->FindView(id), BTextControl); - if(myTControl) - { - myTControl->SetText(""); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TEXTCONTROL"); -} - - -void YabInterface::CreateAlert(const char* text, const char* button1, const char* option) -{ - alert_type tmp; - BString typ(option); - tmp = B_EMPTY_ALERT; - if(typ.IFindFirst("info")!=B_ERROR) tmp = B_INFO_ALERT; - else if(typ.IFindFirst("idea")!=B_ERROR) tmp = B_IDEA_ALERT; - else if(typ.IFindFirst("warning")!=B_ERROR) tmp = B_WARNING_ALERT; - else if(typ.IFindFirst("stop")!=B_ERROR) tmp = B_STOP_ALERT; - - (new BAlert("Alert!",text,button1,NULL,NULL,B_WIDTH_AS_USUAL,tmp))->Go(); -} - -const char* YabInterface::LoadFilePanel(const char *mode, const char* title, const char* directory) -{ - int myMode = -1; - BString opt(mode); - if(opt.IFindFirst("Load-File")!=B_ERROR) - myMode = 0; - if(opt.IFindFirst("Save-File")!=B_ERROR) - myMode = 1; - if(opt.IFindFirst("Load-Directory")!=B_ERROR) - myMode = 2; - if(opt.IFindFirst("Load-File-and-Directory")!=B_ERROR) - myMode = 3; - if(myMode == -1) ErrorGen("Invalid Option"); - - YabFilePanel tmp; - BPath path; - BString myTitle(title); - BEntry *entry = tmp.MyFilePanel(myTitle.String(),directory, "", myMode); - entry->GetPath(&path); - if(myMode != 1 && !entry->Exists()) - loadPanel[0] = '\0'; - else - { - if(path.InitCheck() == B_OK) - strcpy(loadPanel,path.Path()); - else - loadPanel[0] = '\0'; - } - - delete entry; - - return (const char*)loadPanel; -} - -const char* YabInterface::SaveFilePanel(const char *mode, const char* title, const char* directory, const char* filename) -{ - int myMode = -1; - BString opt(mode); - if(opt.IFindFirst("Load-File")!=B_ERROR) - myMode = 0; - if(opt.IFindFirst("Save-File")!=B_ERROR) - myMode = 1; - if(opt.IFindFirst("Load-Directory")!=B_ERROR) - myMode = 2; - if(opt.IFindFirst("Load-File-and-Directory")!=B_ERROR) - myMode = 3; - if(myMode == -1) ErrorGen("Invalid Option"); - - YabFilePanel tmp; - BPath path; - BString myTitle(title); - BEntry *entry = tmp.MyFilePanel(myTitle.String(),directory, filename, myMode); - entry->GetPath(&path); - if(myMode != 1 && !entry->Exists()) - loadPanel[0] = '\0'; - else - { - if(path.InitCheck() == B_OK) - strcpy(loadPanel,path.Path()); - else - loadPanel[0] = '\0'; - } - delete entry; - - return (const char*)loadPanel; -} - -void YabInterface::SetLayout(const char* layout, const char* window) -{ - BString tmp(layout); - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - if(tmp.IFindFirst("standard")!=B_ERROR) - w->layout = -1; - else if(tmp.IFindFirst("all")!=B_ERROR) - w->layout = B_FOLLOW_ALL; - else if(tmp.IFindFirst("none")!=B_ERROR) - w->layout = B_FOLLOW_NONE; - else - { - uint32 horizontal, vertical; - if(tmp.IFindFirst("h-center")!=B_ERROR) - horizontal = B_FOLLOW_H_CENTER; - else if((tmp.IFindFirst("left")!=B_ERROR)&&(tmp.IFindFirst("right")!=B_ERROR)) - horizontal = B_FOLLOW_LEFT_RIGHT; - else if(tmp.IFindFirst("right")!=B_ERROR) - horizontal = B_FOLLOW_RIGHT; - else - horizontal = B_FOLLOW_LEFT; - - if(tmp.IFindFirst("v-center")!=B_ERROR) - vertical = B_FOLLOW_V_CENTER; - else if((tmp.IFindFirst("top")!=B_ERROR)&&(tmp.IFindFirst("bottom")!=B_ERROR)) - vertical = B_FOLLOW_TOP_BOTTOM; - else if(tmp.IFindFirst("bottom")!=B_ERROR) - vertical = B_FOLLOW_BOTTOM; - else - vertical = B_FOLLOW_TOP; - w->layout = horizontal|vertical; - } - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::WindowSet(const char* option, const char* value, const char* window) -{ - BString tmp(option); - BString val(value); - uint32 flags = 0; - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - if(tmp.IFindFirst("Flags")!=B_ERROR) - { - if(val.IFindFirst("Reset")!=B_ERROR) - { - w->SetFlags(0); - w->SetFlags(B_ASYNCHRONOUS_CONTROLS); - } - else - { - flags = w->Flags(); - if(val.IFindFirst("Not-Movable")!=B_ERROR) - flags = flags|B_NOT_MOVABLE; - if(val.IFindFirst("Not-Closable")!=B_ERROR) - flags = flags|B_NOT_CLOSABLE; - if(val.IFindFirst("Not-Zoomable")!=B_ERROR) - flags = flags|B_NOT_ZOOMABLE; - if(val.IFindFirst("Not-Minimizable")!=B_ERROR) - flags = flags|B_NOT_MINIMIZABLE; - if(val.IFindFirst("Not-Resizable")!=B_ERROR) - flags = flags|B_NOT_RESIZABLE; - if(val.IFindFirst("Not-H-Resizable")!=B_ERROR) - flags = flags|B_NOT_H_RESIZABLE; - if(val.IFindFirst("Not-V-Resizable")!=B_ERROR) - flags = flags|B_NOT_V_RESIZABLE; - if(val.IFindFirst("Accept-First-Click")!=B_ERROR) - flags = flags|B_WILL_ACCEPT_FIRST_CLICK; - if(val.IFindFirst("No-Workspace-Activation")!=B_ERROR) - flags = flags|B_NO_WORKSPACE_ACTIVATION; - w->SetFlags(flags|B_ASYNCHRONOUS_CONTROLS); - } - } - else if(tmp.IFindFirst("Look")!=B_ERROR) - { - if(val.IFindFirst("Document")!=B_ERROR) - w->SetLook(B_DOCUMENT_WINDOW_LOOK); - else if(val.IFindFirst("Titled")!=B_ERROR) - w->SetLook(B_TITLED_WINDOW_LOOK); - else if(val.IFindFirst("Floating")!=B_ERROR) - w->SetLook(B_FLOATING_WINDOW_LOOK); - else if(val.IFindFirst("Modal")!=B_ERROR) - w->SetLook(B_MODAL_WINDOW_LOOK); - else if(val.IFindFirst("Bordered")!=B_ERROR) - w->SetLook(B_BORDERED_WINDOW_LOOK); - else if(val.IFindFirst("No-Border")!=B_ERROR) - w->SetLook(B_NO_BORDER_WINDOW_LOOK); - else - ErrorGen("Unknown option"); - } - else if(tmp.IFindFirst("Feel")!=B_ERROR) - { - if(val.IFindFirst("Normal")!=B_ERROR) - w->SetFeel(B_NORMAL_WINDOW_FEEL); - else if(val.IFindFirst("Modal-App")!=B_ERROR) - w->SetFeel(B_MODAL_APP_WINDOW_FEEL); - else if(val.IFindFirst("Modal-All")!=B_ERROR) - w->SetFeel(B_MODAL_ALL_WINDOW_FEEL); - else if(val.IFindFirst("Floating-App")!=B_ERROR) - w->SetFeel(B_FLOATING_APP_WINDOW_FEEL); - else if(val.IFindFirst("Floating-All")!=B_ERROR) - w->SetFeel(B_FLOATING_ALL_WINDOW_FEEL); - else - ErrorGen("Unknown option"); - } - else if(tmp.IFindFirst("Workspace")!=B_ERROR) - { - if(val.IFindFirst("Current")!=B_ERROR) - w->SetWorkspaces(B_CURRENT_WORKSPACE); - else if(val.IFindFirst("All")!=B_ERROR) - w->SetWorkspaces(B_ALL_WORKSPACES); - else if(atoi(val.String()) >= 1) - { - int bit = 1 << atoi(val.String()) - 1; - w->SetWorkspaces(bit); - } - else - ErrorGen("Unknown option"); - } - else if(tmp.IFindFirst("Title")!=B_ERROR) - { - w->SetTitle(value); - } - else - ErrorGen("Unknown option"); - // w->UpdateIfNeeded(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::WindowSet(const char* option, const char* window) -{ - BString tmp(option); - uint32 flags = 0; - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - if(tmp.IFindFirst("maximize")!=B_ERROR) - w->Zoom(); - else if(tmp.IFindFirst("minimize")!=B_ERROR) - w->Minimize(!w->IsMinimized()); - else if(tmp.IFindFirst("deactivate")!=B_ERROR) - w->Activate(false); - else if(tmp.IFindFirst("activate")!=B_ERROR) - w->Activate(true); - else if(tmp.IFindFirst("disable-updates")!=B_ERROR) - w->DisableUpdates(); - else if(tmp.IFindFirst("enable-updates")!=B_ERROR) - w->EnableUpdates(); - else - ErrorGen("Unknown option"); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::WindowSet(const char* option, int r, int g, int b, const char* window) -{ - BString tmp(option); - if(r>255) r=255; if(r<0) r=0; - if(g>255) g=255; if(g<0) g=0; - if(b>255) b=255; if(b<0) b=0; - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - if(tmp.IFindFirst("BGColor")!=B_ERROR) - { - myView->SetViewColor(r,g,b,yabAlpha); - myView->Invalidate(); - } - else if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - if(yabAlpha == 255) - myView->SetDrawingMode(B_OP_COPY); - else - myView->SetDrawingMode(B_OP_ALPHA); - myView->SetHighColor(r,g,b,yabAlpha); - YabDrawing *t = new YabDrawing(); - t->command = 6; - t->r = r; t->g = g; - t->b = b; t->alpha = yabAlpha; - myView->drawList->AddItem(t); - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - if(yabAlpha == 255) - myView->SetDrawingMode(B_OP_COPY); - else - myView->SetDrawingMode(B_OP_ALPHA); - myView->SetLowColor(r,g,b,yabAlpha); - YabDrawing *t = new YabDrawing(); - t->command = 7; - t->r = r; t->g = g; - t->b = b; t->alpha = yabAlpha; - myView->drawList->AddItem(t); - } - else - ErrorGen("Unknown option"); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *bmp = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bView = bmp->FindView(window); - if(bView) - { - if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetHighColor(r,g,b,yabAlpha); - bView->Sync(); - bmp->Unlock(); - return; - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetLowColor(r,g,b,yabAlpha); - bView->Sync(); - bmp->Unlock(); - return; - } - else - ErrorGen("Unknown option"); - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *bmp = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetHighColor(r,g,b,yabAlpha); - bView->Sync(); - bmp->Unlock(); - w->Unlock(); - return; - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetLowColor(r,g,b,yabAlpha); - bView->Sync(); - bmp->Unlock(); - w->Unlock(); - return; - } - else - ErrorGen("Unknown option"); - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::WindowSet(const char* option, double x, double y, const char* window) -{ - BString tmp(option); - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - if(tmp.IFindFirst("ResizeTo")!=B_ERROR) - w->ResizeTo(x,y); - else if(tmp.IFindFirst("MoveTo")!=B_ERROR) - w->MoveTo(x,y); - else if(tmp.IFindFirst("MinimumTo")!=B_ERROR) - { - float x1, x2, y1, y2; - w->GetSizeLimits(&x1,&x2,&y1,&y2); - w->SetSizeLimits((float)x,x2,(float)y,y2); - } - else if(tmp.IFindFirst("MaximumTo")!=B_ERROR) - { - float x1, x2, y1, y2; - w->GetSizeLimits(&x1,&x2,&y1,&y2); - w->SetSizeLimits(x1,(float)x,y1,(float)y); - } - else - ErrorGen("Unknown option"); - w->Unlock(); - // w->UpdateIfNeeded(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::WindowClear(const char* window) -{ - bool delMenuBar; - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w && myView->Parent()) - { - w->Lock(); - BView *child, *oldchild; - if(child = myView->ChildAt(0)) - { - while(child) - { - CleanupYabTabView(child); - if(is_kind_of(child, YabBitmapView)) - yabcanvas->RemoveItem(child); - CleanupSubchildView(child->ChildAt(0)); - if(viewList->GetView(child->Name())) - { - RemoveView(child); - viewList->DelView(child->Name()); - } - - - oldchild = child; - child = child->NextSibling(); - - if(is_kind_of(oldchild, YabView)) - DrawClear(oldchild->Name(), true); - if(is_kind_of(oldchild, BMenuBar)) - { - oldchild->Hide(); - } - oldchild->RemoveSelf(); - delete oldchild; - } - } - if(is_kind_of(myView, YabView)) - DrawClear(myView->Name(), true); - if(is_kind_of(myView, BMenuBar)) - myView->Hide(); - BBox *box = cast_as(myView->Parent(), BBox); - myView->RemoveSelf(); - delete myView; - viewList->DelView(window); - if(box) - { - box->RemoveSelf(); - delete box; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::RemoveView(BView *myView) -{ - BView *child, *oldchild; - if(child = myView->ChildAt(0)) - while(child) - { - CleanupYabTabView(child); - if(is_kind_of(child, YabBitmapView)) - yabcanvas->RemoveItem(child); - CleanupSubchildView(child->ChildAt(0)); - if(viewList->GetView(child->Name())) - { - RemoveView(child); - viewList->DelView(child->Name()); - } - oldchild = child; - child = child->NextSibling(); - - if(is_kind_of(oldchild, YabView)) - DrawClear(oldchild->Name(), true); - if(is_kind_of(oldchild, BMenuBar)) - oldchild->Hide(); - if(is_kind_of(oldchild, BMenuBar)) - { - BMenuBar *b = cast_as(oldchild, BMenuBar); - for(int i=0; iCountItems(); i++) - { - YabMenu *m = (YabMenu*)b->SubmenuAt(i); - if(m) - { - // check for subsubmenus - for(int j=0; jCountItems(); j++) - { - YabMenu *n = (YabMenu*)m->SubmenuAt(j); - if(n) n->MyHide(); - } - m->MyHide(); - // printf("hiden\n"); - } - } - b->Hide(); - } - oldchild->RemoveSelf(); - delete oldchild; - } -} - -void YabInterface::CleanupYabTabView(BView* view) -{ - if(view == NULL || viewList == NULL) return; - - if(is_kind_of(view, YabTabView)) { - YabTabView* tabView = static_cast(view); - for(int i = 0; i < tabView->CountTabs(); i++) - { - YabView *t = static_cast(tabView->TabAt(i)->View()); - RemoveView(t); - viewList->DelView(t->NameForTabView()); - } - } -} - -void YabInterface::CleanupSubchildView(BView* view) -{ - if(view == NULL || viewList == NULL) return; - - while(view) - { - CleanupYabTabView(view); - if(viewList->GetView(view->Name())) - { - RemoveView(view); - viewList->DelView(view->Name()); - } - view = view->NextSibling(); - } -} - -void YabInterface::TextEdit(BRect frame, const char* title, int scrollbar, const char* window) -{ - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - uint32 resizeMode; - BRect textframe; - - w->Lock(); - - if(scrollbar == 3 || scrollbar == 1) frame.right -= B_V_SCROLL_BAR_WIDTH; - if(scrollbar>2) frame.bottom -= B_H_SCROLL_BAR_HEIGHT; - - textframe = frame; - textframe.OffsetTo(B_ORIGIN); - textframe.right -=2; - textframe.bottom -=2; - textframe.top +=2; - textframe.left +=2; - - if(w->layout == -1) - resizeMode = B_FOLLOW_ALL; - else - resizeMode = w->layout; - - // BTextView *txtView = new BTextView(frame, title, textframe, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED|B_NAVIGABLE); - YabText *txtView = new YabText(frame, title, textframe, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED|B_NAVIGABLE); - txtView->SetWordWrap(true); - // txtView->SetFontAndColor(be_fixed_font); - - switch(scrollbar) - { - case 3: // both - myView->AddChild(new BScrollView("scroll_list", txtView, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, true)); - break; - case 2: // horizontal - myView->AddChild(new BScrollView("scroll_list", txtView, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, false)); - break; - case 0: // none - myView->AddChild(txtView); - break; - default: // vertical is default - myView->AddChild(new BScrollView("scroll_list", txtView, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, false, true)); - break; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(window, "VIEW"); -} - -void YabInterface::TextAdd(const char* title, const char* text) -{ - YabView *myView = NULL; - YabText *myText = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - myText->Insert(text); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TextSet(const char* title, const char* option) -{ - BString tmp(option); - YabView *myView = NULL; - YabText *myText = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("Cut")!=B_ERROR) - myText->Cut(be_clipboard); - else if(tmp.IFindFirst("Copy")!=B_ERROR) - { - int32 a,b; - myText->GetSelection(&a, &b); - if(a != b) - myText->Copy(be_clipboard); - } - else if(tmp.IFindFirst("Paste")!=B_ERROR) - myText->Paste(be_clipboard); - else if(tmp.IFindFirst("Clear")!=B_ERROR) - myText->Clear(); - else if(tmp.IFindFirst("Select-All")!=B_ERROR) - myText->SelectAll(); - else if(tmp.IFindFirst("Undo")!=B_ERROR) - myText->Undo(be_clipboard); - else if(tmp.IFindFirst("Redo")!=B_ERROR) - // myText->Redo(be_clipboard); - ; - else - ErrorGen("Unknown option"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TextSet(const char* title, const char* option, const char* value) -{ - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - BString tmp2(value); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - - - - - - if(tmp.IFindFirst("align")!=B_ERROR) - { - if(tmp2.IFindFirst("left")!=B_ERROR) - myText->SetAlignment(B_ALIGN_LEFT); - else if(tmp2.IFindFirst("center")!=B_ERROR) - myText->SetAlignment(B_ALIGN_CENTER); - else if(tmp2.IFindFirst("right")!=B_ERROR) - myText->SetAlignment(B_ALIGN_RIGHT); - } - else if(tmp.IFindFirst("fixed")!=B_ERROR) - { - const char* str_int = tmp2.String(); - int i = atoi(str_int); - if (i>6) - { - BFont myFont=(be_fixed_font); - int myFontSize = i; - myFont.SetSize(myFontSize); - int TL = myText->TextLength(); - const rgb_color Textcolor = {0,0,0,255}; - myText->SetFontAndColor(0,TL,&myFont,B_FONT_ALL,&Textcolor); - } - - } - else if(tmp.IFindFirst("plain")!=B_ERROR) - { - const char* str_int = tmp2.String(); - int i = atoi(str_int); - if (i>6) - { - BFont myFont=(be_plain_font); - int myFontSize = i; - myFont.SetSize(myFontSize); - int TL = myText->TextLength(); - const rgb_color Textcolor = {0,0,0,255}; - myText->SetFontAndColor(0,TL,&myFont,B_FONT_ALL,&Textcolor); - } - - } - else if(tmp.IFindFirst("bold")!=B_ERROR) - { - const char* str_int = tmp2.String(); - int i = atoi(str_int); - if (i>6) - { - BFont myFont=(be_bold_font); - int myFontSize = i; - myFont.SetSize(myFontSize); - int TL = myText->TextLength(); - const rgb_color Textcolor = {0,0,0,255}; - myText->SetFontAndColor(0,TL,&myFont,B_FONT_ALL,&Textcolor); - } - - } - else if(tmp.IFindFirst("autocomplete")!=B_ERROR) - myText->AddWord(new BString(value)); - else if(tmp.IFindFirst("font")!=B_ERROR) - { - BFont myFont; - BString opt; - - // Font family - int pos1 = 0; - int pos2 = tmp2.FindFirst(','); - if(pos2 != B_ERROR) - { - tmp2.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - font_family fam; - sprintf((char*)fam, "%s" , opt.String()); - if(myFont.SetFamilyAndFace(fam, B_REGULAR_FACE) == B_OK) - { - myView->SetFont(&myFont, B_FONT_FAMILY_AND_STYLE); - // Font style - pos1 = pos2+1; - pos2 = tmp2.FindFirst(',', pos2+1); - if(pos2 != B_ERROR) - { - tmp2.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - font_style style; - sprintf((char*)style, "%s" , opt.String()); - if(myFont.SetFamilyAndStyle(fam,style) == B_OK) - { - // Font size - pos1 = pos2+1; - pos2 = tmp2.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) pos2 = tmp2.Length(); - tmp2.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - double size = atof(opt.String()); - myFont.SetSize(size); - } - } - } - } - else if(tmp2.IFindFirst("system-plain")!=B_ERROR) - myFont = be_plain_font; - else if(tmp2.IFindFirst("system-fixed")!=B_ERROR) - myFont = be_fixed_font; - else if(tmp2.IFindFirst("system-bold")!=B_ERROR) - myFont = be_bold_font; - - else - ErrorGen("Unknown option"); - int32 start,finish; - myText->GetSelection(&start, &finish); - myText->SelectAll(); - myText->SetFontAndColor(&myFont); - myText->Select(start,finish); - } - else if (tmp.IFindFirst("focus")!=B_ERROR) - { - if (tmp2.IFindFirst("true")!=B_ERROR) - { - bool focused = true; - myText->MakeFocus(focused); - } - else - { - bool focused = false; - myText->MakeFocus(focused); - } - } - else - - ErrorGen("Unknown option"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TextSet(const char* title, const char* option, int value) -{ - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("autocomplete-start")!=B_ERROR) - myText->SetAutoCompleteStart(value-1); - else if(tmp.IFindFirst("has-autocompletion")!=B_ERROR) - myText->HasAutoCompletion((bool)value); - else if(tmp.IFindFirst("autoindent")!=B_ERROR) - myText->SetAutoindent((bool)value); - else if(tmp.IFindFirst("wordwrap")!=B_ERROR) - myText->SetWordWrap((bool)value); - else if(tmp.IFindFirst("editable")!=B_ERROR) - myText->MakeEditable((bool)value); - else if(tmp.IFindFirst("color-case-sensitive")!=B_ERROR) - myText->SetCaseSensitive((bool)value); - else if(tmp.IFindFirst("tabwidth")!=B_ERROR) - myText->SetTabWidth(value); - else if(tmp.IFindFirst("cursor")!=B_ERROR) - myText->Select(value, value); - else if(tmp.IFindFirst("textwidth")!=B_ERROR) - - { - // BRect txtframe = myText->TextRect(); - // txtframe.right = txtframe.left + value; - // myText->SetTextRect(txtframe); - myText->SetTextRect(BRect(0,0, value,1)); - // BRect txtbounds = myText->Bounds(); - // myText->FrameResized(txtbounds.Width(), txtbounds.Height()); - BRect bounds(myText->Bounds()); - BScrollBar* horizontalScrollBar = myText->ScrollBar(B_HORIZONTAL); - - // do we have a horizontal scroll bar? - if (horizontalScrollBar != NULL) { - long viewWidth = bounds.IntegerWidth(); - long dataWidth = (long)value; - - long maxRange = dataWidth - viewWidth; - maxRange = max_c(maxRange, 0); - - horizontalScrollBar->SetRange(0, 1000); //(float)maxRange); - // horizontalScrollBar->SetProportion((float)viewWidth / (float)dataWidth); - // horizontalScrollBar->SetSteps(10.0, dataWidth / 10); - // std::cout << "dataWidth: " << dataWidth << " maxrange: " << maxRange << std::endl; - } - - } - else if(tmp.IFindFirst("gotoline")!=B_ERROR) - { - if(value<1) value = 1; - myText->GoToLine(value-1); - myText->ScrollToSelection(); - } - else if(tmp.IFindFirst("select")!=B_ERROR) - { - int start, num; - if(value <= 0) - myText->Select(0,0); - else - { - if(value-1 == 0) - start = 0; - else - start = myText->OffsetAt(value-1); - if(myText->CountLines()>value) - num = myText->OffsetAt(value)-start-1; - else - num = myText->OffsetAt(value)-start; - // num = myText->TextLength()-start; - myText->Select(start,start+num); - myText->ScrollToSelection(); - } - } - else if(tmp.IFindFirst("changed")!=B_ERROR) - myText->SetChanged((bool)value); - else - ErrorGen("Unknown option"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TextColor(const char* title, const char* option, const char* command) -{ - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("Color1")!=B_ERROR) - myText->AddCommand(command,0); - else if(tmp.IFindFirst("Color2")!=B_ERROR) - myText->AddCommand(command,1); - else if(tmp.IFindFirst("Color3")!=B_ERROR) - myText->AddCommand(command,2); - else if(tmp.IFindFirst("Color4")!=B_ERROR) - myText->AddCommand(command,3); - else if(tmp.IFindFirst("char-color")!=B_ERROR) - myText->AddCommand(command,4); - else - ErrorGen("Unknown option"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TextColor(const char* title, const char* option, int r, int g, int b) -{ - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("color1")!=B_ERROR) - myText->SetColors(0,r,g,b); - else if(tmp.IFindFirst("color2")!=B_ERROR) - myText->SetColors(1,r,g,b); - else if(tmp.IFindFirst("color3")!=B_ERROR) - myText->SetColors(2,r,g,b); - else if(tmp.IFindFirst("color4")!=B_ERROR) - myText->SetColors(3,r,g,b); - else if(tmp.IFindFirst("char-color")!=B_ERROR) - myText->SetColors(4,r,g,b); - else if(tmp.IFindFirst("bgcolor")!=B_ERROR) - myText->SetColors(5,r,g,b); - else if(tmp.IFindFirst("textcolor")!=B_ERROR) - myText->SetColors(6,r,g,b); - else - ErrorGen("Unknown option"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -int YabInterface::TextGet(const char* title, const char* option, const char* option2) -{ - int ret = -1; - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("case-sensitive-find")!=B_ERROR) - { - int32 startOffset, endOffset; - myText->GetSelection(&startOffset, &endOffset); - bool isFinished = false; - int foundOffset, l = myText->TextLength() - endOffset; - char* s; - s = new char[l+1]; - myText->GetText(endOffset, l, s); - BString line(s); - foundOffset = line.FindFirst(option2); - if(foundOffset == B_ERROR) - { - delete s; - s = new char[endOffset]; - myText->GetText(0, endOffset-1, s); - line = s; - foundOffset = line.FindFirst(option2); - } - else - foundOffset += endOffset; - if(foundOffset != B_ERROR) - { - delete s; - myText->Select(foundOffset, foundOffset+strlen(option2)); - myText->ScrollToSelection(); - ret = myText->LineAt(foundOffset)+1; - // myText->GoToLine(myText->LineAt(foundOffset)); - } - } - else if(tmp.IFindFirst("find")!=B_ERROR) - { - int32 startOffset, endOffset; - myText->GetSelection(&startOffset, &endOffset); - // = myText->OffsetAt(myText->CurrentLine()); - bool isFinished = false; - int foundOffset, l = myText->TextLength() - endOffset; - char* s; - s = new char[l+1]; - myText->GetText(endOffset, l, s); - BString line(s); - foundOffset = line.IFindFirst(option2); - if(foundOffset == B_ERROR) - { - delete s; - s = new char[endOffset]; - myText->GetText(0, endOffset-1, s); - line = s; - foundOffset = line.IFindFirst(option2); - } - else - foundOffset += endOffset; - if(foundOffset != B_ERROR) - { - delete s; - myText->Select(foundOffset, foundOffset+strlen(option2)); - myText->ScrollToSelection(); - ret = myText->LineAt(foundOffset)+1; - // myText->GoToLine(myText->LineAt(foundOffset)); - } - } - else - ErrorGen("Unknown option"); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -double YabInterface::TextGet(const char* title, const char* option, int line) -{ - double ret = -1.0; - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("line-width")!=B_ERROR) - ret = myText->LineWidth(line); - else if(tmp.IFindFirst("line-height")!=B_ERROR) - ret = myText->LineHeight(line); - else - ErrorGen("Unknown option"); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -int YabInterface::TextGet(const char* title, const char* option) -{ - int ret = -1; - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("currentline")!=B_ERROR) - ret = myText->CurrentLine()+1; - else if(tmp.IFindFirst("vertical-scrollbar")!=B_ERROR) - { - float f = -1.0; - BScrollView *s = cast_as(myText->Parent(), BScrollView); - if(s) - { - BScrollBar *b = s->ScrollBar(B_VERTICAL); - if(b) f = b->Value(); - else - ErrorGen("TEXTEDIT has no vertical scrollbar"); - } - else - ErrorGen("TEXTEDIT has no vertical scrollbar"); - ret = (int)f; - } - else if(tmp.IFindFirst("horizontal-scrollbar")!=B_ERROR) - { - float f = -1.0; - BScrollView *s = cast_as(myText->Parent(), BScrollView); - if(s) - { - BScrollBar *b = s->ScrollBar(B_HORIZONTAL); - if(b) f = b->Value(); - else - ErrorGen("TEXTEDIT has no horizontal scrollbar"); - } - else - ErrorGen("TEXTEDIT has no horizontal scrollbar"); - ret = (int)f; - } - else if(tmp.IFindFirst("countlines")!=B_ERROR) - ret = myText->CountLines(); - else if(tmp.IFindFirst("countphysicallines")!=B_ERROR) - ret=myText->CountPhysicalLines(); - else if(tmp.IFindFirst("textlength")!=B_ERROR) - ret = myText->TextLength(); - else if(tmp.IFindFirst("haschanged")!=B_ERROR) - ret = myText->HasChanged()?1:0; - else if(tmp.IFindFirst("cursor-position")!=B_ERROR) - { - int32 start, end, pos1,pos2; - myText->GetSelection(&start, &end); - ret = end; - } - else - ErrorGen("Unknown option"); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -const char* YabInterface::TextGet(const char* title, int linenum) -{ - YabView *myView = NULL; - YabText *myText = NULL; - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - char* ret; - int start, num; - if(linenum-1 == 0) - start = 0; - else - start = myText->OffsetAt(linenum-1); - if(myText->CountLines()>linenum) - num = myText->OffsetAt(linenum)-start-1; - else - num = myText->TextLength()-start; - ret = new char[num+1]; - myText->GetText(start, num, ret); - w->Unlock(); - return (const char*)ret; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -const char* YabInterface::TextGet6(const char* title, const char* option) -{ - YabView *myView = NULL; - YabText *myText = NULL; - BString tmp(option); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(),YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title),YabText); - if(myText) - { - if(tmp.IFindFirst("selection")!=B_ERROR) - { - char* ret; - int32 start, finish; - myText->GetSelection(&start, &finish); - if(finish == 0 || (finish-start)<=0) - { - ret = new char[1]; - ret[0] = '\0'; - } - else - { - ret = new char[finish-start+1]; - myText->GetText(start, finish-start, ret); - } - - w->Unlock(); - return (const char*)ret; - } - else - ErrorGen("Unknown option"); - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -double YabInterface::DrawGet(const char* option, const char* txt, const char* view) -{ - double ret = 0; - BString tmp(option); - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - if(tmp.IFindFirst("Text-Width")!=B_ERROR) - ret = myView->StringWidth(txt); - if(tmp.IFindFirst("Max-Text-Height")!=B_ERROR) - { - font_height height; - myView->GetFontHeight(&height); - ret = height.ascent+height.descent; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), view)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - if(tmp.IFindFirst("Text-Width")!=B_ERROR) - ret = bView->StringWidth(txt); - if(tmp.IFindFirst("Max-Text-Height")!=B_ERROR) - { - font_height height; - bView->GetFontHeight(&height); - ret = height.ascent+height.descent; - } - b->Unlock(); - - w->Unlock(); - return ret; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(view, "VIEW or CANVAS"); - } - return ret; -} - -const char* YabInterface::DrawGet(const char* option) -{ - BString t(option); - char* ret; - if(t.IFindFirst("fontfamily")!=B_ERROR) - { - int32 numFamilies = count_font_families(); - ret = new char[numFamilies*(B_FONT_FAMILY_LENGTH + 1)]; - BString tmp(""); - for(int32 i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title), YabText); - if(myText) - { - myText->SetText("", 0); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -const char* YabInterface::TextGet(const char* title) -{ - const char* tmp; - YabView *myView = NULL; - YabText *myText = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myText = cast_as(myView->FindView(title), YabText); - if(myText) - { - tmp = myText->Text(); - w->Unlock(); - return tmp; - } - w->Unlock(); - } - } - } - Error(title, "TEXTEDIT"); -} - -void YabInterface::TreeBox1(BRect frame, const char* id, int scrollbarType, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - uint32 resizeMode; - - w->Lock(); - - if(scrollbarType == 3 || scrollbarType == 1) frame.right -= B_V_SCROLL_BAR_WIDTH; - if(scrollbarType>2) frame.bottom -= B_H_SCROLL_BAR_HEIGHT; - - BOutlineListView *list = new BOutlineListView(frame,id); - if(w->layout == -1) - resizeMode = B_FOLLOW_ALL; - else - resizeMode = w->layout; - list->SetResizingMode(resizeMode); - list->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - list->SetSelectionMessage(new BMessage(YABTREEBOXSELECT)); - list->SetInvocationMessage(new BMessage(YABTREEBOXINVOKE)); - switch(scrollbarType) - { - case 3: // both - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, true)); - break; - case 2: // horizontal - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, true, false)); - break; - case 0: // none - myView->AddChild(list); - break; - default: // vertical is default - myView->AddChild(new BScrollView("scroll_list", list, resizeMode, B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE, false, true)); - break; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::TreeBox2(const char* id, const char* item) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - myTree->AddItem(new BStringItem(item)); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} -//Correction of Subitem by Stephan Aßmus on BeGeistert 2018 -void YabInterface::TreeBox3(const char* id, const char* head, const char* item, int isExpanded) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - for(int i=0; iFullListCountItems(); i++) - { - BStringItem *stritem = (BStringItem*)myTree->FullListItemAt(i); - if(!strcmp(stritem->Text(), head)) - { - int32 level = stritem->OutlineLevel() + 1; - BStringItem *tmp = new BStringItem(item, level); - //myTree->AddUnder(tmp,stritem); - int32 fullSubItemCount = myTree->CountItemsUnder(stritem, false); - //printf("found item '%s' at %ld with level %ld, number of sub-items: %ld\n", - // head, i, level - 1, fullSubItemCount); - myTree->AddItem(tmp, i + fullSubItemCount + 1); - - if(isExpanded<1) - myTree->Collapse(stritem); - - w->Unlock(); - return; - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox4(const char* id) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - myTree->MakeEmpty(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox5(const char* id, const char* item) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - for(int i=0; iFullListCountItems(); i++) - { - BStringItem *stritem = (BStringItem*)myTree->FullListItemAt(i); - if(!strcmp(stritem->Text(), item)) - { - myTree->RemoveItem(i); - w->Unlock(); - return; - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox7(const char* id, int pos) -{ - pos--; - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - if(pos==0) - myTree->DeselectAll(); - else - { - BListItem *item = myTree->FullListItemAt(pos); - if(item) - myTree->Select(myTree->IndexOf(item)); - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox8(const char* id, int pos) -{ - pos--; - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - myTree->RemoveItem(pos); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} -void YabInterface::TreeBox9(const char* id, const char* head, const char* item) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - for(int i=0; iFullListCountItems(); i++) - { - BStringItem *stritem = (BStringItem*)myTree->FullListItemAt(i); - if(!strcmp(stritem->Text(), head)) - { - for(int j=0; iCountItemsUnder(stritem, false); j++) - { - BStringItem *subitem = (BStringItem*)myTree->FullListItemAt(i+j+1); - if(!strcmp(subitem->Text(), item)) - { - myTree->RemoveItem((BListItem*)subitem); - w->Unlock(); - return; - } - } - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox10(const char* id, const char* head) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - for(int i=0; iFullListCountItems(); i++) - { - BStringItem *stritem = (BStringItem*)myTree->FullListItemAt(i); - if(!strcmp(stritem->Text(), head)) - { - myTree->Expand((BListItem*)stritem); - w->Unlock(); - return; - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} -void YabInterface::TreeBox11(const char* id, const char* head) -{ - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id), BOutlineListView); - if(myTree) - { - for(int i=0; iFullListCountItems(); i++) - { - BStringItem *stritem = (BStringItem*)myTree->FullListItemAt(i); - if(!strcmp(stritem->Text(), head)) - { - myTree->Collapse((BListItem*)stritem); - w->Unlock(); - return; - } - } - w->Unlock(); - ErrorGen("Item not found"); - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -void YabInterface::TreeBox12(const char* id, const char* item, int pos) -{ - if(pos<1) pos = 1; - - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(id),BOutlineListView); - if(myTree) - { - if(pos<=myTree->FullListCountItems()) - { - uint32 outline = (myTree->FullListItemAt(pos-1))->OutlineLevel(); - myTree->AddItem(new BStringItem(item, outline),pos-1); - } - else - myTree->AddItem(new BStringItem(item)); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -const char* YabInterface::TreeboxGet(const char* treebox, int pos) -{ - pos--; - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) //CountItems() - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(treebox), BOutlineListView); - if(myTree) - { - BStringItem *t = (BStringItem*)myTree->FullListItemAt(pos); - if(t) - { - const char* txt = t->Text(); - //printf(txt); - w->Unlock(); - return txt; - } - } - w->Unlock(); - } - } - } - Error(treebox, "TREEBOX"); -} - -int YabInterface::TreeboxCount(const char* treebox) -{ - int32 ret; - YabView *myView = NULL; - BOutlineListView *myTree = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTree = cast_as(myView->FindView(treebox), BOutlineListView); - if(myTree) - { - ret = myTree->FullListCountItems(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(treebox, "TREEBOX"); -} - -BBitmap* YabInterface::loadImage(const char* FileName) -{ - BBitmap* LogoBitmap = NULL; - BFile ImageFile; - BPath ImagePath; - int ret = 0; - - if( *FileName == '/') - ImageFile.SetTo( FileName, B_READ_ONLY); - else - // App directory. - if(!strcmp(ApplicationDirectory,"")) - { - if( ImagePath.SetTo((const char*)ApplicationDirectory, FileName) == B_OK) - ImageFile.SetTo( ImagePath.Path(), B_READ_ONLY); - } - - if( ImageFile.InitCheck() != B_OK) - ImageFile.SetTo( FileName, B_READ_ONLY); - - if( ImageFile.InitCheck() != B_OK) - return NULL; - - Roster = BTranslatorRoster::Default(); - - if( !Roster) - return NULL; - - BBitmapStream Stream; - - if( Roster->Translate( &ImageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP) < B_OK) - return NULL; - - if( Stream.DetachBitmap( &LogoBitmap) != B_OK) - return NULL; - - - return LogoBitmap; -} - -void YabInterface::ButtonImage(double x,double y, const char* id,const char* enabledon, const char* enabledoff, const char* disabled, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BPicture *pic1 = NULL, *pic2 = NULL, *pic3 = NULL; - BBitmap *bitmap = NULL; - BView *tmpView = new BView(BRect(0,0,1000,1000),"tmp",0, B_WILL_DRAW); - w->AddChild(tmpView); - tmpView->SetDrawingMode(B_OP_ALPHA); - - bitmap = loadImage(enabledon); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // tmpView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic1 = tmpView->EndPicture(); - - BRect r; - r.SetLeftTop(BPoint(x,y)); - if(bitmap) - r.SetRightBottom(BPoint(x,y) + bitmap->Bounds().RightBottom()); - else - r.SetRightBottom(BPoint(x,y)); - - bitmap = loadImage(enabledoff); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // tmpView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic2 = tmpView->EndPicture(); - - bitmap = loadImage(disabled); - tmpView->BeginPicture(new BPicture); - if(bitmap) tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - pic3 = tmpView->EndPicture(); - - - BPictureButton *myButton = new BPictureButton(r, id, pic2, pic1, new BMessage(YABBUTTON)); - myButton->SetDisabledOff(pic3); - - if(w->layout == -1) - myButton->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myButton->SetResizingMode(w->layout); - myButton->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(myButton); - tmpView->RemoveSelf(); - delete tmpView; - // delete Roster; - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::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) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BPicture *pic1 = NULL, *pic2 = NULL, *pic3 = NULL, *pic4 = NULL; - BBitmap *bitmap = NULL; - BView *tmpView = new BView(BRect(0,0,1000,1000),"tmp",0, B_WILL_DRAW); - w->AddChild(tmpView); - tmpView->SetDrawingMode(B_OP_ALPHA); - - bitmap = loadImage(enabledon); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // myView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic1 = tmpView->EndPicture(); - - BRect r; - r.SetLeftTop(BPoint(x,y)); - if(bitmap) - r.SetRightBottom(BPoint(x,y) + bitmap->Bounds().RightBottom()); - else - r.SetRightBottom(BPoint(x,y)); - - bitmap = loadImage(enabledoff); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // myView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic2 = tmpView->EndPicture(); - - bitmap = loadImage(disabledon); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // myView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic3 = tmpView->EndPicture(); - - bitmap = loadImage(disabledoff); - tmpView->BeginPicture(new BPicture); - if(bitmap) - { - // drawing_mode mode = myView->DrawingMode(); - // myView->SetDrawingMode(B_OP_ALPHA); - tmpView->DrawBitmap(bitmap,bitmap->Bounds()); - // myView->SetDrawingMode(mode); - } - pic4 = tmpView->EndPicture(); - - BPictureButton *myButton = new BPictureButton(r, id, pic2, pic1, new BMessage(YABCHECKBOX),B_TWO_STATE_BUTTON); - myButton->SetDisabledOn(pic3); - myButton->SetDisabledOff(pic4); - - if(w->layout == -1) - myButton->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myButton->SetResizingMode(w->layout); - myButton->SetValue(isActivated); - myButton->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(myButton); - tmpView->RemoveSelf(); - delete tmpView; - // delete Roster; - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::CheckboxSet(const char* id, int isActivated) -{ - YabView *myView = NULL; - BCheckBox *myCheckBox = NULL; - BPictureButton *myPicButton = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myCheckBox = cast_as(myView->FindView(id), BCheckBox); - if(myCheckBox) - { - myCheckBox->SetValue(isActivated); - w->Unlock(); - return; - } - else - { - myPicButton = cast_as(myView->FindView(id), BPictureButton); - if(myPicButton) - { - if(myPicButton->Behavior() == B_TWO_STATE_BUTTON) - { - myPicButton->SetValue(isActivated); - w->Unlock(); - return; - } - } - } - w->Unlock(); - } - } - } - Error(id, "CHECKBOX"); -} - -void YabInterface::RadioSet(const char* id, int isActivated) -{ - YabView *myView = NULL; - BRadioButton *myRadioButton= NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myRadioButton = cast_as(myView->FindView(id), BRadioButton); - if(myRadioButton) - { - myRadioButton->SetValue(isActivated); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "RADIOBUTTON"); -} - -const char* YabInterface::TextControlGet(const char* id) -{ - const char* tmp = NULL; - YabView *myView = NULL; - BTextControl *myTControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myTControl = cast_as(myView->FindView(id), BTextControl); - if(myTControl) - { - tmp = myTControl->Text(); - w->Unlock(); - return tmp; - } - w->Unlock(); - } - } - } - Error(id, "TEXTCONTROL"); -} - -void YabInterface::ToolTips(const char* view, const char* text) -{ - YabView *myView = NULL; - BView *theView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - theView = w->FindView(view); - if(theView) - { - if(theView->Name()) - { - if(!strcmp(theView->Name(), view)) - { - if(text[0] == '\0') - // tooltip->SetHelp(theView, NULL); - ; - else - theView->SetToolTip(text); - w->Unlock(); - return; - } - } - } - w->Unlock(); - } - } - } - Error(view, "VIEW"); -} - -void YabInterface::ToolTipsNew(const char* view, const char* text, const char* color, int r, int g, int b) -{ - printf("View %s",view); - printf("View %s",text); - printf("View %s",color); - printf("View %d",r); - printf("View %d",g); - printf("View %d",b); - - //SetViewColor(b1); - //SetLowColor(b1); - //SetHighColor(b2); - YabView *myView = NULL; - BView *theView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - theView = w->FindView(view); - if(theView) - { - if(theView->Name()) - { - if(!strcmp(theView->Name(), view)) - { - if(text[0] == '\0') - // tooltip->SetHelp(theView, NULL); - ; - else - theView->SetLowColor(r,g,b,255); - theView->SetToolTip(text); - - w->Unlock(); - return; - } - } - } - w->Unlock(); - } - } - } - Error(view, "VIEW"); -} -void YabInterface::ToolTipsColor(const char* color, int r, int g, int b) -{ - /* - BString tmp(color); - rgb_color rgb = {r,g,b}; - if(tmp.IFindFirst("BGColor")!=B_ERROR) - { - //tooltip->SetColor(rgb); - - } - else if(tmp.IFindFirst("TextColor")!=B_ERROR) - { - //tooltip->SetTextColor(rgb); - - } - */ -} - -void YabInterface::TreeSort(const char* view) -{ - ErrorGen("Sorry, this command is not working yet"); - YabView *myView = NULL; - BOutlineListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(view), BOutlineListView); - if(myList) - { - myList->FullListSortItems((int(*)(const BListItem *, const BListItem *))YabInterface::compare); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(view, "TREEBOX"); -} - -void YabInterface::ListSort(const char* view) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(view), BListView); - if(myList) - { - myList->SortItems((int(*)(const void*, const void*))YabInterface::compare); - w->Unlock(); - return; - - } - w->Unlock(); - } - } - } - Error(view, "LISTBOX"); -} - -int YabInterface::compare(BListItem **firstArg, BListItem **secondArg) -{ - if(firstArg != NULL && secondArg != NULL) - { - BString item1(((BStringItem*)*firstArg)->Text()); - BString item2(((BStringItem*)*secondArg)->Text()); - if(((BListItem*)*firstArg)->OutlineLevel()!=((BListItem*)*secondArg)->OutlineLevel()) - return 0; - return item1.ICompare(item2); - } - return 0; -} - -void YabInterface::FileBox(BRect frame, const char* id, bool hasHScrollbar, const char* option, const char* view) -{ - BString tmp(option); - - border_style plain = B_PLAIN_BORDER; - if(tmp.IFindFirst("no-border")!=B_ERROR) - plain = B_NO_BORDER; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BColumnListView* myColumnList; - myColumnList = new BColumnListView(frame, id, B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE,plain, hasHScrollbar); - BMessage *msg1, *msg2; - msg1 = new BMessage(YABFILEBOXINVOKE); - msg1->AddPointer("source", myColumnList); - msg2 = new BMessage(YABFILEBOXSELECT); - msg2->AddPointer("source", myColumnList); - myColumnList->SetInvocationMessage(msg1); - myColumnList->SetSelectionMessage(msg2); - myColumnList->SetSortingEnabled(false); - myColumnList->SetSelectionMode(B_SINGLE_SELECTION_LIST); - rgb_color rgb = {195,195,195,255}; - myColumnList->SetColor(B_COLOR_SELECTION, rgb); - - int flags = B_ALLOW_COLUMN_NONE; - if(tmp.IFindFirst("movable")!=B_ERROR) - flags += B_ALLOW_COLUMN_MOVE; - if(tmp.IFindFirst("resizable")!=B_ERROR) - flags += B_ALLOW_COLUMN_RESIZE; - if(tmp.IFindFirst("popup")!=B_ERROR) - flags += B_ALLOW_COLUMN_POPUP; - if(tmp.IFindFirst("removable")!=B_ERROR) - flags += B_ALLOW_COLUMN_REMOVE; - myColumnList->SetColumnFlags((column_flags) flags); - myColumnList->SetLatchWidth(0.0); - myView->AddChild(myColumnList); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::ColumnBoxAdd(const char* id, int column, int position, int height, const char* text) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(id), BColumnListView); - if(myColumnList) - { - BRow *myRow = myColumnList->RowAt(position-1); - if(!myRow) - { - myRow = new BRow(height); - myColumnList->AddRow(myRow, position); - for(int j=0; jCountColumns(); j++) - { - BYabField *myField = new BYabField(""); - myRow->SetField(myField, j); - } - } - - BYabField *myField = (BYabField*)myRow->GetField(column-1); - myField->SetString(text, height); - - myColumnList->Refresh(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "COLUMNBOX"); -} - -void YabInterface::FileBoxAdd(const char* columnbox, const char* name, int32 pos, double minWidth, double maxWidth, double width, const char* option) -{ - BString tmp(option); - alignment align = B_ALIGN_LEFT; - if(tmp.IFindFirst("align-left")!=B_ERROR) - align = B_ALIGN_LEFT; - if(tmp.IFindFirst("align-center")!=B_ERROR) - align = B_ALIGN_CENTER; - if(tmp.IFindFirst("align-right")!=B_ERROR) - align = B_ALIGN_RIGHT; - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - BYabColumn *myColumn = new BYabColumn(name,width,maxWidth, minWidth,width, align); - myColumnList->AddColumn(myColumn, pos-1); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -void YabInterface::FileBoxClear(const char* columnbox) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - myColumnList->Clear(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -void YabInterface::ColumnBoxRemove(const char* columnbox, int position) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - BRow *myRow; - myRow = myColumnList->RowAt(position-1); - if(myRow) - { - myColumnList->RemoveRow(myRow); - delete myRow; - } - else - { - w->Unlock(); - ErrorGen("Row not found"); - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -void YabInterface::ColumnBoxColor(const char* columnbox, const char* option, int r, int g, int b) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - BString tmp(option); - ColumnListViewColor col; - if(tmp.IFindFirst("selection-text")!=B_ERROR) - col = B_COLOR_SELECTION_TEXT; - else if(tmp.IFindFirst("non-focus-selection")!=B_ERROR) - col = B_COLOR_NON_FOCUS_SELECTION; - else if(tmp.IFindFirst("selection")!=B_ERROR) - col = B_COLOR_SELECTION; - else if(tmp.IFindFirst("text")!=B_ERROR) - col = B_COLOR_TEXT; - else if(tmp.IFindFirst("row-divider")!=B_ERROR) - col = B_COLOR_ROW_DIVIDER; - else if(tmp.IFindFirst("background")!=B_ERROR) - col = B_COLOR_BACKGROUND; - else - ErrorGen("Invalid option"); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - rgb_color rgb = {r,g,b,255}; - myColumnList->SetColor(col, rgb); - myColumnList->Refresh(); - myColumnList->Invalidate(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -void YabInterface::ColumnBoxSelect(const char* columnbox, int position) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - if(position == 0) - myColumnList->DeselectAll(); - else - { - myColumnList->AddToSelection(myColumnList->RowAt(position-1)); - myColumnList->ScrollTo(myColumnList->RowAt(position-1)); - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -const char* YabInterface::ColumnBoxGet(const char* columnbox, int column, int position) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - BRow* myRow = myColumnList->RowAt(position-1); - if(myRow) - { - BYabField *myField = cast_as(myRow->GetField(column-1), BYabField); - if(myField) - { - const char* t = myField->String(); - w->Unlock(); - return t; - } - w->Unlock(); - ErrorGen("Column not found"); - } - w->Unlock(); - ErrorGen("Row not found"); - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -int YabInterface::ColumnBoxCount(const char* columnbox) -{ - YabView *myView = NULL; - BColumnListView *myColumnList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myColumnList = cast_as(myView->FindView(columnbox), BColumnListView); - if(myColumnList) - { - int32 ret = myColumnList->CountRows(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(columnbox, "COLUMNBOX"); -} - -void YabInterface::ListboxAdd(const char* listbox, const char* item) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(listbox), BListView); - // myList = (BListView*)myView->FindView(listbox); - if(myList) - { - myList->AddItem(new BStringItem(item)); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -void YabInterface::ListboxAdd(const char* listbox, int pos, const char* item) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(listbox), BListView); - if(myList) - { - myList->AddItem(new BStringItem(item), pos-1); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -void YabInterface::ListboxSelect(const char* listbox, int pos) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(listbox), BListView); - if(myList) - { - if(pos == 0) - myList->DeselectAll(); - else - { - myList->Select(pos-1); - myList->ScrollToSelection(); - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -void YabInterface::ListboxRemove(const char* listbox, int pos) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(listbox), BListView); - if(myList) - { - myList->RemoveItem(pos-1); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -const char* YabInterface::ListboxGet(const char* listbox, int pos) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - columntext[0] = '\0'; - myList = cast_as(myView->FindView(listbox), BListView); - if(myList) - { - BStringItem *t = cast_as(myList->ItemAt(pos-1), BStringItem); - if(t) - { - const char* txt = t->Text(); - w->Unlock(); - return txt; - } - else - { - w->Unlock(); - ErrorGen("Item not found"); - } - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -int YabInterface::ListboxCount(const char* listbox) -{ - int ret = 0; - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(listbox), BListView); - if(myList) - { - ret = myList->CountItems(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(listbox, "LISTBOX"); -} - -void YabInterface::DrawSet1(const char* option, const char* window) -{ - BString tmp(option); - - BFont myFont; - BString opt; - - // Font family - int pos1 = 0; - int pos2 = tmp.FindFirst(','); - if(pos2 != B_ERROR) - { - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - font_family fam; - sprintf((char*)fam, "%s" , opt.String()); - if(myFont.SetFamilyAndFace(fam, B_REGULAR_FACE) == B_OK) - { - // myView->SetFont(&myFont, B_FONT_FAMILY_AND_STYLE); - - // Font style - pos1 = pos2+1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 != B_ERROR) - { - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - font_style style; - sprintf((char*)style, "%s" , opt.String()); - if(myFont.SetFamilyAndStyle(fam,style) == B_OK) - { - // myView->SetFont(&myFont, B_FONT_FAMILY_AND_STYLE); - - // Font size - pos1 = pos2+1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) pos2 = tmp.Length(); - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - double size = atof(opt.String()); - myFont.SetSize(size); - // myView->SetFont(&myFont, B_FONT_SIZE); - - if(pos2 != tmp.Length()) - { - pos1 = pos2+1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) pos2 = tmp.Length(); - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - if(opt.IFindFirst("bold") != B_ERROR) - myFont.SetFace(B_BOLD_FACE); - else if(opt.IFindFirst("italic") != B_ERROR) - myFont.SetFace(B_ITALIC_FACE); - else if(opt.IFindFirst("regular") != B_ERROR) - myFont.SetFace(B_REGULAR_FACE); - else if(opt.IFindFirst("outlined") != B_ERROR) - myFont.SetFace(B_OUTLINED_FACE); - else if(opt.IFindFirst("strikeout") != B_ERROR) - myFont.SetFace(B_STRIKEOUT_FACE); - else if(opt.IFindFirst("underscore") != B_ERROR) - myFont.SetFace(B_UNDERSCORE_FACE); - - if(pos2 != tmp.Length()) - { - pos1 = pos2 + 1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) pos2 = tmp.Length(); - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - float rotation = atof(opt.String()); - myFont.SetRotation(rotation); - - if(pos2 != tmp.Length()) - { - pos1 = pos2 + 1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) pos2 = tmp.Length(); - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - float shear = atof(opt.String()); - myFont.SetShear(shear); - } - } - - } - - - // Font flags - /*bool looping = true; - while(looping) - { - pos1 = pos2+1; - pos2 = tmp.FindFirst(',', pos2+1); - if(pos2 == B_ERROR) - { - looping = false; - pos2 = tmp.Length(); - } - tmp.CopyInto(opt, pos1, pos2-pos1); - while(opt[0] == ' ') opt.RemoveFirst(" "); - while(opt[opt.Length()-1] == ' ') opt.RemoveLast(" "); - }*/ - } - } - } - } - else if(tmp.IFindFirst("system-plain")!=B_ERROR) - { - myFont = be_plain_font; - // myView->SetFont(&myFont); - } - else if(tmp.IFindFirst("system-fixed")!=B_ERROR) - { - myFont = be_fixed_font; - // myView->SetFont(&myFont); - } - else if(tmp.IFindFirst("system-bold")!=B_ERROR) - { - myFont = be_bold_font; - // myView->SetFont(&myFont); - } - - YabView *myView = cast_as((BView*)viewList->GetView(window), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myView->SetFont(&myFont); - YabDrawing *t = new YabDrawing(); - t->command = 12; - t->font = myFont; - myView->drawList->AddItem(t); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(window); - if(bview) - { - b->Lock(); - bview->SetFont(&myFont); - bview->Sync(); - b->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), window)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - b->Lock(); - bView->SetFont(&myFont); - bView->Sync(); - b->Unlock(); - - // myView->Draw(myView->Bounds()); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(window, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::DrawSet2(int fillorstroke, const char* mypattern) -{ - BString tmp(mypattern); - if(fillorstroke) drawStroking = true; else drawStroking = false; - if(tmp.IFindFirst("HighSolidFill")!=B_ERROR) - yabPattern = B_SOLID_HIGH; - else if(tmp.IFindFirst("LowSolidFill")!=B_ERROR) - yabPattern = B_SOLID_LOW; - else if(tmp.IFindFirst("CheckeredFill")!=B_ERROR) - yabPattern = B_MIXED_COLORS; - else - { - for(int i = 0; i<8; i++) - if(iGetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - if(opt>0 && opt<5) - { - BRect r = w->Frame(); - switch(opt) - { - case 1: ret = (int)r.LeftTop().x; - break; - case 2: ret = (int)r.LeftTop().y; - break; - case 3: ret = r.IntegerWidth(); - break; - case 4: ret = r.IntegerHeight(); - break; - } - } - if(opt>4) - { - float x1,y1,x2,y2; - w->GetSizeLimits(&x1,&x2,&y1,&y2); - switch(opt) - { - case 5: ret = (int)x1; - break; - case 6: ret = (int)y1; - break; - case 7: ret = (int)x2; - break; - case 8: ret = (int)y2; - break; - case 10: ret = w->IsMinimized(); - break; - } - } - if (opt==9) - { - return true; - } - } - else - { - if (opt==9) - { - return false; - } - else - ErrorGen("Unable to lock window"); - } - } - else - { - if (opt==9) - { - return false; - } - else - Error(view, "VIEW"); - } - return ret; -} - -int YabInterface::ViewGet(const char* view, const char* option) -{ - int opt = 0; - int ret = -1; - BString t(option); - YabView *myView = NULL; - if(t.IFindFirst("position-x")!=B_ERROR) opt = 1; - else if(t.IFindFirst("position-y")!=B_ERROR) opt = 2; - else if(t.IFindFirst("width")!=B_ERROR) opt = 3; - else if(t.IFindFirst("height")!=B_ERROR) opt = 4; - else if(t.IFindFirst("exists")!=B_ERROR) opt = 5; - else if(t.IFindFirst("focused")!=B_ERROR) opt = 6; - else - ErrorGen("Invalid option"); - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *theView = cast_as(myView->FindView(view), BView); - if(theView) - { - BRect r = theView->Frame(); - switch(opt) - { - case 1: ret = (int)r.LeftTop().x; - break; - case 2: ret = (int)r.LeftTop().y; - break; - case 3: ret = r.IntegerWidth(); - break; - case 4: ret = r.IntegerHeight(); - break; - case 5: ret = true; - break; - case 6: ret = theView->IsFocus(); - break; - } - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - if( opt == 5 ) - ret=false; - else - Error(view, "VIEW"); - - return ret; -} - -void YabInterface::ClipboardCopy(const char* text) -{ - BMessage *clip = (BMessage *)NULL; - - if (be_clipboard->Lock()) - { - be_clipboard->Clear(); - if (clip = be_clipboard->Data()) - { - clip->AddData("text/plain", B_MIME_TYPE, text, strlen(text)); - be_clipboard->Commit(); - } - be_clipboard->Unlock(); - } -} - -int YabInterface::Printer(const char* docname, const char *config, const char* view) -{ - BPrintJob job(docname); - BMessage *setup; - BFile myFile(config, B_READ_ONLY); - - if(myFile.InitCheck()!=B_OK) - { - if(job.ConfigPage()==B_OK) - setup = job.Settings(); - else - { - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 1; - } - } - else - { - setup = new BMessage(); - if(setup->Unflatten(&myFile)!=B_OK) - { - if(job.ConfigPage()==B_OK) - setup = job.Settings(); - else - { - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 1; - } - } - else - if(job.IsSettingsMessageValid(setup)) - job.SetSettings(setup); - else - { - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 2; - } - } - - int32 firstPage, lastPage, nbPages; - BRect printableRect = job.PrintableRect(); - firstPage =0 ;//= job.FirstPage(); Since we aren't calling the set-up print pages, firstpage is always 0 - lastPage = job.LastPage(); - // printf("PRINTER DEBUG Printable BRect %f %f %f %f\n", printableRect.left,printableRect.top, printableRect.right, printableRect.bottom); - YabView *myView = NULL; - BView *newView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - newView = myView->FindView(view); - w->Unlock(); - if(newView) - break; - } - } - } - - if(!newView) - { - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 3; - } - - - BWindow *w = newView->Window(); - w->Lock(); - - int32 viewHeight = newView->Bounds().IntegerHeight(); - float viewWidth = newView->Bounds().Width(); - if(is_kind_of(newView, YabText)) - viewHeight = (int32)((YabText*)newView)->TextHeight(0, ((YabText*)newView)->CountLines()); - if(is_kind_of(newView, BScrollView)) - { - float a,b; - - if(((BScrollView*)newView)->ScrollBar(B_VERTICAL)) - { - ((BScrollView*)newView)->ScrollBar(B_VERTICAL)->GetRange(&a, &b); - viewHeight = viewHeight + (int32)b; - if(((BScrollView*)newView)->ScrollBar(B_HORIZONTAL)) - viewHeight -= (int32)B_H_SCROLL_BAR_HEIGHT; - } - if(((BScrollView*)newView)->ScrollBar(B_HORIZONTAL)) - { - ((BScrollView*)newView)->ScrollBar(B_HORIZONTAL)->GetRange(&a, &b); - viewWidth = viewWidth + b; - if(((BScrollView*)newView)->ScrollBar(B_VERTICAL)) - viewWidth -= B_V_SCROLL_BAR_WIDTH; - } - - if(((BScrollView*)newView)->ScrollBar(B_VERTICAL)) - newView = ((BScrollView*)newView)->ScrollBar(B_VERTICAL)->Target(); - else - newView = ((BScrollView*)newView)->ScrollBar(B_HORIZONTAL)->Target(); - } - - // printf(" %d %f \n", viewHeight, viewWidth); - int32 printableHeight = printableRect.IntegerHeight(); - float printableWidth = printableRect.Width(); - w->Unlock(); - - int32 maxPages = viewHeight / printableHeight + 1; - if(lastPage>maxPages) - lastPage = maxPages; - nbPages = lastPage - firstPage + 1; - - //printf("PRINTER DEBUG First Page %d Last Page %d \n", firstPage, lastPage); - // printf("PRINTER DEBUG View Height %d Printable Height %d \n", viewHeight, printableHeight); - - if(nbPages<=0) - { - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 4; - } - - job.BeginJob(); - bool can_continue = job.CanContinue(); - - w->Lock(); - - bool hasWordWrap; - float textWidth, textHeight; - - if(is_kind_of(newView, YabText)) - { - int lineheight; - hasWordWrap = ((YabText*)newView)->DoesWordWrap(); - if(!hasWordWrap) ((YabText*)newView)->SetWordWrap(true); - lineheight = (int)((YabText*)newView)->LineHeight(); - textWidth = ((YabText*)newView)->TextRect().Width(); - textHeight = ((YabText*)newView)->TextRect().Height(); - - ((YabText*)newView)->SetTextRect(BRect(0,0,printableWidth, viewHeight)); - - printableHeight -= printableHeight%lineheight; - } - - int32 newHeight; - if(printableHeightSetWordWrap(hasWordWrap); - ((YabText*)newView)->SetTextRect(BRect(0,0,textWidth, textHeight)); - } - - w->Unlock(); - - if(can_continue) - job.CommitJob(); - else - // (new BAlert(_L("Printer Error!"),_L("Could not setup the printer!"), "Ok"))->Go(); - return 5; - return 0; -} - -void YabInterface::PrinterConfig(const char* config) -{ - BPrintJob job(""); - if(job.ConfigPage()==B_OK) - { - BMessage *setup = job.Settings(); - BFile myFile(config, B_WRITE_ONLY|B_CREATE_FILE|B_ERASE_FILE); - if(myFile.InitCheck()==B_OK) - setup->Flatten(&myFile); - } -} - -const char* YabInterface::ClipboardPaste() -{ - const char *text; - ssize_t textlen; - BString returnstring; - BMessage *clip = (BMessage *)NULL; - - if (be_clipboard->Lock()) - { - BMessage *clip = be_clipboard->Data(); - clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &textlen); - be_clipboard->Unlock(); - if (text != NULL) { - returnstring.SetTo(text, textlen); - } - } - - return returnstring; -} - -int YabInterface::NewAlert(const char* text, const char* button1, const char* button2, const char* button3, const char* option) -{ - alert_type tmp; - BString typ(option); - tmp = B_EMPTY_ALERT; - if(typ.IFindFirst("info")!=B_ERROR) tmp = B_INFO_ALERT; - else if(typ.IFindFirst("idea")!=B_ERROR) tmp = B_IDEA_ALERT; - else if(typ.IFindFirst("warning")!=B_ERROR) tmp = B_WARNING_ALERT; - else if(typ.IFindFirst("stop")!=B_ERROR) tmp = B_STOP_ALERT; - - if(!strcmp(button2,"")) button2 = NULL; - if(!strcmp(button3,"")) button3 = NULL; - - return (new BAlert("Alert!",text,button1,button2,button3,B_WIDTH_AS_USUAL,tmp))->Go() + 1; -} - -void YabInterface::Calendar(double x, double y, const char* id, const char* format, const char* date, const char* view) -{ - int day, month, year, look, myformat; - BString tYear, tMonth, tDay; - BString tDate(date); - tDate.MoveInto(tYear, 6,4); - tDate.MoveInto(tMonth, 3,2); - tDate.MoveInto(tDay, 0,2); - BString tFormat(format); - look = CC_DOT_DIVIDER; - myformat = CC_DD_MM_YYYY_FORMAT; - if(tFormat.FindFirst("/")!=B_ERROR) - look = CC_SLASH_DIVIDER; - else if(tFormat.FindFirst("-")!=B_ERROR) - look = CC_MINUS_DIVIDER; - if(tFormat.IFindFirst("MD")!=B_ERROR) - myformat = CC_MM_DD_YYYY_FORMAT; - - year = atoi(tYear.String()); - if(myformat == CC_MM_DD_YYYY_FORMAT) - { - month = atoi(tDay.String()); - day = atoi(tMonth.String()); - } - else - { - month = atoi(tMonth.String()); - day = atoi(tDay.String()); - } - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - CalendarControl* myCalendar = new CalendarControl(BPoint(x,y),id,day, month, year, myformat, look); - if(w->layout == -1) - myCalendar->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myCalendar->SetResizingMode(w->layout); - myView->AddChild(myCalendar); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -const char* YabInterface::Calendar(const char* id) -{ - const char* txt; - YabView *myView = NULL; - CalendarControl *myCalendar = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myCalendar = cast_as(myView->FindView(id), CalendarControl); - if(myCalendar) - { - txt = myCalendar->Text(); - w->Unlock(); - return txt; - } - w->Unlock(); - } - } - } - Error(id, "CALENDAR"); -} - -void YabInterface::Calendar(const char* id, const char* date) -{ - int day, month, year, look, myformat; - BString tYear, tMonth, tDay; - BString tDate(date); - tDate.MoveInto(tYear, 6,4); - tDate.MoveInto(tMonth, 3,2); - tDate.MoveInto(tDay, 0,2); - - YabView *myView = NULL; - CalendarControl *myCalendar = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myCalendar = cast_as(myView->FindView(id), CalendarControl); - if(myCalendar) - { - myformat = myCalendar->GetFlags(); - year = atoi(tYear.String()); - if(myformat == CC_MM_DD_YYYY_FORMAT) - { - month = atoi(tDay.String()); - day = atoi(tMonth.String()); - } - else - { - month = atoi(tMonth.String()); - day = atoi(tDay.String()); - } - - myCalendar->SetDate(day,month,year); - - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "CALENDAR"); -} - -void YabInterface::Scrollbar(const char* id, int format, const char* view) -{ - YabView *myView = NULL; - BView *myBView = NULL; - if(format != 0) - { - bool hasHor = false, hasVer = false; - if(format>1) hasHor = true; - if(format == 1 || format == 3) hasVer = true; - - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myBView = myView->FindView(view); - if(myBView) - { - if(myView->RemoveChild(myBView)) - { - BScrollView *myScrollView = new BScrollView(id, myBView, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, hasHor, hasVer); - if(w->layout == -1) - myScrollView->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - myScrollView->SetResizingMode(w->layout); - myScrollView->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE|B_NAVIGABLE); - myView->AddChild(myScrollView); - myScrollView->SetViewColor(myBView->ViewColor()); - w->Unlock(); - return; - } - } - w->Unlock(); - } - } - } - Error(view, "VIEW"); - } - ErrorGen("Unknown option"); -} - -void YabInterface::ScrollbarSet(const char* scrollview, const char* option, double position) -{ - BString tOption(option); - orientation isHorizontal; - if(tOption.IFindFirst("Vertical Position")!=B_ERROR) isHorizontal = B_VERTICAL; - if(tOption.IFindFirst("Horizontal Position")!=B_ERROR) isHorizontal = B_HORIZONTAL; - if(isHorizontal == B_VERTICAL || isHorizontal == B_HORIZONTAL) - { - YabView *myView = NULL; - BScrollView *myScrollView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myScrollView = cast_as((BView*)myView->FindView(scrollview),BScrollView); - if(myScrollView) - { - BScrollBar *myScrollbar = myScrollView->ScrollBar(isHorizontal); - if(myScrollbar) - myScrollbar->SetValue(position); - else - ErrorGen("SCROLLBAR is not valid!"); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(scrollview, "SCROLLBAR"); - } - ErrorGen("Unknown option"); -} - -void YabInterface::ScrollbarSet(const char* scrollview, const char* option) -{ - BString tOption(option); - border_style border; - if(tOption.IFindFirst("no-border")!=B_ERROR) - border = B_NO_BORDER; - else if(tOption.IFindFirst("plain-border")!=B_ERROR) - border = B_PLAIN_BORDER; - else if(tOption.IFindFirst("fancy-border")!=B_ERROR) - border = B_FANCY_BORDER; - else - ErrorGen("Invalid option"); - - YabView *myView = NULL; - BScrollView *myScrollView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myScrollView = cast_as((BView*)myView->FindView(scrollview),BScrollView); - if(myScrollView) - { - myScrollView->SetBorder(border); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(scrollview, "SCROLLBAR"); -} - -void YabInterface::ScrollbarSet(const char* scrollview, const char* option, double opt1, double opt2) -{ - BString tOption(option); - orientation isHorizontal; - int isRange = -1; - if(tOption.IFindFirst("Vertical")!=B_ERROR) isHorizontal = B_VERTICAL; - if(tOption.IFindFirst("Horizontal")!=B_ERROR) isHorizontal = B_HORIZONTAL; - if(tOption.IFindFirst("Range")!=B_ERROR) isRange = 1; - if(tOption.IFindFirst("Steps")!=B_ERROR) isRange = 0; - if((isHorizontal == B_VERTICAL || isHorizontal == B_HORIZONTAL) && isRange != -1) - { - YabView *myView = NULL; - BScrollView *myScrollView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myScrollView = cast_as((BView*)myView->FindView(scrollview),BScrollView); - if(myScrollView) - { - /* - if(isRange) - { - BRect f(myView->Bounds()); - // printf("%f %f\n", opt1, opt2); - if(isHorizontal == B_HORIZONTAL) - { - f.left = opt1; - f.right = opt2; - } - else - { - f.top = opt1; - f.bottom = opt2; - } - myScrollView->SetDataRect(f); - } - else - { - BScrollBar *myScrollbar = myScrollView->ScrollBar(isHorizontal); - if(myScrollbar) myScrollbar->SetSteps(opt1,opt2); - }*/ - - BScrollBar *myScrollbar = myScrollView->ScrollBar(isHorizontal); - if(isRange == 1) - { - if(myScrollbar) - myScrollbar->SetRange(opt1,opt2); - else - ErrorGen("SCROLLBAR is not valid!"); - } - else - { - if(myScrollbar) - myScrollbar->SetSteps(opt1,opt2); - else - ErrorGen("SCROLLBAR is not valid!"); - } - - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(scrollview, "SCROLLBAR"); - } - ErrorGen("Unknown option"); -} - -double YabInterface::ScrollbarGet(const char* scrollview, const char* option) -{ - BString tOption(option); - orientation isHorizontal; - double res = 0; - if(tOption.IFindFirst("Vertical")!=B_ERROR) isHorizontal = B_VERTICAL; - if(tOption.IFindFirst("Horizontal")!=B_ERROR) isHorizontal = B_HORIZONTAL; - if(isHorizontal == B_VERTICAL || isHorizontal == B_HORIZONTAL) - { - YabView *myView = NULL; - BScrollView *myScrollView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myScrollView = (BScrollView*)myView->FindView(scrollview); - if(myScrollView) - { - BScrollBar *myScrollbar = myScrollView->ScrollBar(isHorizontal); - if(myScrollbar) - res = myScrollbar->Value(); - else - ErrorGen("SCROLLBAR is not valid!"); - w->Unlock(); - return res; - } - w->Unlock(); - } - } - } - Error(scrollview, "SCROLLBAR"); - } - ErrorGen("Unknown option"); -} - -void YabInterface::SplitView(BRect frame, const char* id, int isVertical, int style, const char* view) -{ - orientation posture = isVertical>0?B_VERTICAL:B_HORIZONTAL; - - double pos; - - if(posture==B_VERTICAL) - pos = (frame.right-frame.left)/2; - else - pos = (frame.bottom-frame.top)/2; - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - - BRect frame1(frame); - BRect frame2(frame); - - if(posture==B_VERTICAL) - { - frame1.Set(0,0,pos,frame.bottom-frame.top); - frame2.Set(pos+10,0,frame.right-frame.left, frame.bottom-frame.top); - } - else - { - frame1.Set(0,0,frame.right-frame.left, pos-10); - frame2.Set(0,pos,frame.right-frame.left,frame.bottom-frame.top); - } - - BString t1(id); t1 += "1"; - BString t2(id); t2 += "2"; - - YabView *newView1 = new YabView(frame1, t1.String(), B_FOLLOW_ALL_SIDES,B_WILL_DRAW|B_NAVIGABLE_JUMP); - viewList->AddView(t1.String(), newView1, TYPE_YABVIEW); - - YabView *newView2 = new YabView(frame2, t2.String(), B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_NAVIGABLE_JUMP); - viewList->AddView(t2.String(), newView2, TYPE_YABVIEW); - - SplitPane *mySplit = new SplitPane(frame, id, (BView*)newView1, (BView*)newView2, 0); - if(style) - mySplit->SetBarThickness(10); - else - mySplit->SetBarThickness(5); - mySplit->SetAlignment(posture); - - if(w->layout == -1) - mySplit->SetResizingMode(B_FOLLOW_ALL_SIDES); - else - mySplit->SetResizingMode(w->layout); - - myView->AddChild(mySplit); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::SplitView(const char* splitView, const char* option, double position) -{ - YabView *myView = NULL; - SplitPane *mySplit = NULL; - BString t(option); - if(t.IFindFirst("Divider")==B_ERROR) - ErrorGen("Unknown option"); - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySplit = cast_as(myView->FindView(splitView), SplitPane); - if(mySplit) - { - mySplit->SetBarPosition((int)position); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(splitView, "SPLITVIEW"); -} - -void YabInterface::SplitView(const char* splitView, const char* option, double left, double right) -{ - YabView *myView = NULL; - SplitPane *mySplit = NULL; - BString t(option); - if(t.IFindFirst("MinimumSizes")==B_ERROR) - ErrorGen("Unknown option"); - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySplit = cast_as(myView->FindView(splitView), SplitPane); - if(mySplit) - { - mySplit->SetMinSizeOne((int)left); - mySplit->SetMinSizeTwo((int)right); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(splitView, "SPLITVIEW"); -} - -double YabInterface::SplitViewGet(const char* splitView, const char* option) -{ - double ret = -1; - YabView *myView = NULL; - SplitPane *mySplit = NULL; - BString t(option); - if(t.IFindFirst("Divider")==B_ERROR) - ErrorGen("Unknown option"); - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySplit = cast_as(myView->FindView(splitView), SplitPane); - if(mySplit) - { - ret = (double)mySplit->GetBarPosition(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(splitView, "SPLITVIEW"); -} - -void YabInterface::StackViews(BRect frame, const char* id, int number, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView && number<1000) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - - YabStackView *myStackView = new YabStackView(frame, id, number); - if(w->layout == -1) - myStackView->SetResizingMode(B_FOLLOW_ALL); - else - myStackView->SetResizingMode(w->layout); - // myTabView->SetFlags(B_WILL_DRAW|B_FULL_UPDATE_ON_RESIZE); - - YabView *newViews[number]; - for(int i=0; iBounds(), t.String(), B_FOLLOW_ALL_SIDES,B_WILL_DRAW|B_NAVIGABLE_JUMP); - viewList->AddView(t.String(), newViews[i], TYPE_YABVIEW); - - } - myStackView->AddViews((BView**)newViews); - - myView->AddChild(myStackView); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - if(number<1000) Error(view, "VIEW"); - else ErrorGen("Too many views!"); -} - -void YabInterface::StackViews(const char* id, int num) -{ - YabView *myView = NULL; - YabStackView *myStackView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myStackView = cast_as(myView->FindView(id), YabStackView); - if(myStackView) - { - myStackView->SelectView(num-1); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "STACKVIEW"); -} - -int YabInterface::StackViewGet(const char* id) -{ - int ret; - YabView *myView = NULL; - YabStackView *myStackView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myStackView = cast_as(myView->FindView(id), YabStackView); - if(myStackView) - { - ret = myStackView->CurrentView(); - w->Unlock(); - return ret+1; - } - w->Unlock(); - } - } - } - Error(id, "STACKVIEW"); -} - -void YabInterface::DrawSet3(const char* option, int transparency) -{ - BString t(option); - if(t.IFindFirst("alpha") != B_ERROR) - { - yabAlpha = transparency; - if(yabAlpha<0) yabAlpha = 0; - if(yabAlpha>255) yabAlpha = 255; - } -} -//Texturl modified by Lorenz Glaser (aka lorglas) 03.10.2019 -void YabInterface::TextURL(double x, double y, const char* id, const char* text, const char* url, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - double h,b; - - b = be_plain_font->StringWidth(text)+1; - h = be_plain_font->Size(); - - URLView *s = new URLView(BRect(x,y,x+b,y+h+3), id, text, url); //Correction of Height +3 added,because text wasn't fully displayed. Lorglas - s->SetHoverEnabled(true); - if(w->layout == -1) - s->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - s->SetResizingMode(w->layout); - s->SetFlags(B_WILL_DRAW); - myView->AddChild(s); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::TextURL(const char* id, const char* option, int r, int g, int b) -{ - int opt = 0; - BString t(option); - if(t.IFindFirst("label") != B_ERROR) opt = 1; - if(t.IFindFirst("click") != B_ERROR) opt = 2; - if(t.IFindFirst("mouse-over") != B_ERROR) opt = 3; - - YabView *myView = NULL; - URLView *myURLView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myURLView = cast_as(myView->FindView(id), URLView); - if(myURLView) - { - rgb_color col = {r,g,b,255}; - switch(opt) - { - case 1: myURLView->SetColor(col); - break; - case 2: myURLView->SetClickColor(col); - break; - case 3: myURLView->SetHoverColor(col); - break; - default: break; - } - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "TEXTURL"); -} - -void YabInterface::Menu(const char* menuHead, int isRadio, const char* view) -{ - bool radio = isRadio?true:false; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - BMenu *menu = NULL; - BMenuItem *item = NULL; - w->Lock(); - - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar != NULL) - { - for(int i=0; iCountItems(); i++) - if(!strcmp( menubar->ItemAt(i)->Label(), menuHead)) - { - menu = menubar->SubmenuAt(i); - menu->SetRadioMode(radio); - break; - } - } - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::SubMenu(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* shortcut, const char* view) -{ - char myShortcut; - int32 modifiers = 0; - BString t(shortcut); - if(t.Length()>1) - { - myShortcut = shortcut[t.Length()-1]; - if(t.IFindFirst("s")!=B_ERROR && t.IFindFirst("s")GetView(view), YabView); - - if(!strcmp(menuItem, "--")) - return; - - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - YabMenu *menu = NULL; - YabMenu *submenu = NULL; - BMenuItem *item = NULL; - w->Lock(); - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar == NULL) - { - menubar = new BMenuBar(myView->Bounds(),"menubar"); - myView->AddChild(menubar); - } - - for(int i=0; iCountItems(); i++) - if(!strcmp( menubar->ItemAt(i)->Label(), menuHead)) - menu = (YabMenu*)menubar->SubmenuAt(i); - - if(menu == NULL) - { - menu = new YabMenu(menuHead); - menubar->AddItem(menu); - } - - int isInMenu = -1; - for(int i=0; iCountItems(); i++) - if(!strcmp(menu->ItemAt(i)->Label(), menuItem)) - { - isInMenu = i; - break; - } - - if(isInMenu == -1) - { - submenu = new YabMenu(menuItem); - menu->AddItem(submenu); - } - else - { - submenu = cast_as(menu->SubmenuAt(isInMenu),YabMenu); - if(submenu == NULL) - { - BMenuItem *myItem = menu->RemoveItem(isInMenu); - delete myItem; - - submenu = new YabMenu(menuItem); - menu->AddItem(submenu, isInMenu); - } - } - - if(!strcmp(subMenuItem,"--")) - submenu->AddItem(new BSeparatorItem()); - else - submenu->AddItem(new BMenuItem(subMenuItem, new BMessage(YABSUBMENU), myShortcut, modifiers)); - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::SubMenu(const char* menuHead, const char* menuItem, int isRadio, const char* view) -{ - bool radio = isRadio?true:false; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - BMenu *menu = NULL; - BMenu *submenu = NULL; - BMenuItem *item = NULL; - w->Lock(); - - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar != NULL) - { - for(int i=0; iCountItems(); i++) - if(!strcmp( menubar->ItemAt(i)->Label(), menuHead)) - { - menu = menubar->SubmenuAt(i); - for(int j=0; jCountItems(); j++) - if(!strcmp( menu->ItemAt(j)->Label(), menuItem)) - { - submenu = menu->SubmenuAt(j); - if(submenu) - { - submenu->SetRadioMode(radio); - break; - } - } - - if(submenu) break; - } - } - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -int YabInterface::ColorControlGet(const char* colorcontrol, const char* option) -{ - int ret = -1; - int myOption = -1; - BString myString(option); - if(myString.IFindFirst("Red") != B_ERROR) myOption = 0; - if(myString.IFindFirst("Green") != B_ERROR) myOption = 1; - if(myString.IFindFirst("Blue") != B_ERROR) myOption = 2; - - if(myOption<0) ErrorGen("Unknown option"); - - YabView *myView = NULL; - BColorControl *myCControl = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView && myOption>-1) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myCControl = cast_as(myView->FindView(colorcontrol), BColorControl); - if(myCControl) - { - rgb_color t = myCControl->ValueAsColor(); - switch(myOption) - { - case 0: ret = t.red; - break; - case 1: ret = t.green; - break; - case 2: ret = t.blue; - break; - } - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(colorcontrol, "COLORCONTROL"); -} - -int YabInterface::SliderGet(const char* slider) -{ - int ret = -1; - YabView *myView = NULL; - BSlider *mySlider = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySlider = cast_as(myView->FindView(slider), BSlider); - if(mySlider) - { - ret = mySlider->Value(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(slider, "SLIDER"); -} - -void YabInterface::SubMenu3(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* option, const char* view) -{ - int myOption = -1; - BString t(option); - if(t.IFindFirst("disable")!=B_ERROR) myOption = 0; - if(t.IFindFirst("enable")!=B_ERROR) myOption = 1; - if(t.IFindFirst("mark")!=B_ERROR) myOption = 2; - if(t.IFindFirst("plain")!=B_ERROR) myOption = 3; - if(t.IFindFirst("remove")!=B_ERROR) myOption = 4; - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView && myOption>-1) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - BMenu *menu = NULL; - BMenu *submenu = NULL; - BMenuItem *item = NULL; - w->Lock(); - - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar) - { - for(int i=0; iCountItems(); i++) - { - if(!strcmp( menubar->ItemAt(i)->Label(), menuHead)) - { - menu = menubar->SubmenuAt(i); - for(int j=0; jCountItems(); j++) - { - if(!strcmp( menu->ItemAt(j)->Label(), menuItem)) - { - submenu = menu->SubmenuAt(j); - if(submenu) - { - for(int k=0; kCountItems(); k++) - { - if(!strcmp( submenu->ItemAt(k)->Label(), subMenuItem)) - { - switch(myOption) - { - case 0: - submenu->ItemAt(k)->SetEnabled(false); - break; - case 1: - submenu->ItemAt(k)->SetEnabled(true); - break; - case 2: - submenu->ItemAt(k)->SetMarked(true); - break; - case 3: - submenu->ItemAt(k)->SetMarked(false); - break; - case 4: - submenu->RemoveItem( submenu->ItemAt(k) ); - if(submenu->CountItems() == 0) { - if(menu->RemoveItem(submenu)) - menu->AddItem(new BMenuItem(menuItem, new BMessage(YABMENU)), j); - } - break; - } - break; - } - } - } - } - } - } - } - } - - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - if(myOption>-1) Error(view, "VIEW"); - else ErrorGen("Unknown option"); -} - -void YabInterface::Menu3(const char* menuHead, const char* menuItem, const char* option,const char* view) -{ - int myOption = -1; - BString t(option); - if(t.IFindFirst("disable")!=B_ERROR) myOption = 0; - if(t.IFindFirst("enable")!=B_ERROR) myOption = 1; - if(t.IFindFirst("mark")!=B_ERROR) myOption = 2; - if(t.IFindFirst("plain")!=B_ERROR) myOption = 3; - if(t.IFindFirst("remove")!=B_ERROR) myOption = 4; - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView && myOption>-1) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BMenuBar *menubar; - BMenu *menu = NULL; -// BMenuItem *item = NULL; - w->Lock(); - - menubar = cast_as(myView->FindView("menubar"), BMenuBar); - if(menubar != NULL) - { - for(int i=0; iCountItems(); i++) - if(!strcmp( menubar->ItemAt(i)->Label(), menuHead)) - { - menu = menubar->SubmenuAt(i); - for(int j=0; jCountItems(); j++) - if(!strcmp( menu->ItemAt(j)->Label(), menuItem)) - { - switch(myOption) - { - case 0: - menu->ItemAt(j)->SetEnabled(false); - break; - case 1: - menu->ItemAt(j)->SetEnabled(true); - break; - case 2: - menu->ItemAt(j)->SetMarked(true); - break; - case 3: - menu->ItemAt(j)->SetMarked(false); - break; - case 4: - menu->RemoveItem( menu->ItemAt(j) ); - } - break; - } - } - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - if(myOption>-1) Error(view, "VIEW"); - else ErrorGen("Unknown option"); -} - -void YabInterface::SpinControl(double x, double y, const char* id, const char* label, int min, int max, int step, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - Spinner *mySpin = new Spinner(BRect(x,y,x+10,y+10), id, label, min, max, step, NULL); - if(w->layout == -1) - mySpin->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - mySpin->SetResizingMode(w->layout); - myView->AddChild(mySpin); - mySpin->SetViewColor(myView->ViewColor()); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); -} - -void YabInterface::SpinControl(const char* spinControl, int value) -{ - YabView *myView = NULL; - Spinner *mySpin = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySpin = cast_as(myView->FindView(spinControl),Spinner); - if(mySpin) - { - mySpin->SetValue(value); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(spinControl, "SPINCONTROL"); -} - -int YabInterface::SpinControlGet(const char *spinControl) -{ - int ret = 0; - YabView *myView = NULL; - Spinner *mySpin = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - mySpin = cast_as(myView->FindView(spinControl),Spinner); - if(mySpin) - { - ret = mySpin->Value(); - w->Unlock(); - return ret; - } - w->Unlock(); - } - } - } - Error(spinControl, "SPINCONTROL"); -} - -const char* YabInterface::PopUpMenu(double x, double y, const char* menuItems, const char* view) -{ - BString t(menuItems); - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - const char* res; - w->Lock(); - BPopUpMenu *returnMe = new BPopUpMenu( "YabPopup", false, false ); - returnMe->SetAsyncAutoDestruct(true); - - int oldi = 0; - for(int i=0; iAddItem(new BSeparatorItem()); - else - returnMe->AddItem(new BMenuItem(_L(j.String()), NULL)); - oldi=i+1; - } - BString j; - t.CopyInto(j,oldi, t.Length()-oldi); - returnMe->AddItem(new BMenuItem(j.String(), NULL)); - - BMenuItem *result = returnMe->Go(myView->ConvertToScreen(BPoint(x,y)), false, true); - if(result) - { - res = result->Label(); - w->Unlock(); - return res; - } - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); - - return ""; -} - -void YabInterface::DropBoxSelect(const char* dropbox, int position) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(dropbox), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - if(position<1) position = 1; - if(position>=myMenu->CountItems()) - position = myMenu->CountItems(); - if(myMenu->CountItems()!=0) - (myMenu->ItemAt(position-1))->SetMarked(true); - w->Unlock(); - return; - } - } - w->Unlock(); - } - } - } - Error(dropbox, "DROPBOX"); -} - -void YabInterface::DropBoxClear(const char* dropbox) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(dropbox), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - while(myMenu->CountItems()>0) - { - BMenuItem *myItem = myMenu->RemoveItem(myMenu->CountItems()-1); - delete myItem; - } - - // bad workaround! Add an empty MenuItem and delete it again - // so that the menu changes - BMenuItem *myItem = new BMenuItem("", NULL); - myMenu->AddItem(myItem); - myItem->SetMarked(true); - myMenu->RemoveItem(myItem); - delete myItem; - - w->Unlock(); - return; - } - } - w->Unlock(); - } - } - } - Error(dropbox, "DROPBOX"); -} - -void YabInterface::DropBoxRemove(const char* dropbox, int position) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(dropbox), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - position --; - if(position<0) position = 0; - if(position>=myMenu->CountItems()) - position = myMenu->CountItems()-1; - - if(myMenu->CountItems()!=0) - { - BMenuItem *myItem = myMenu->ItemAt(position); - if(myItem->IsMarked()) - { - if(myMenu->CountItems()>1 && position>0) - (myMenu->ItemAt(position-1))->SetMarked(true); - else if(myMenu->CountItems()>1 && position == 0) - (myMenu->ItemAt(position+1))->SetMarked(true); - else - { - BMenuItem *myItem = new BMenuItem("", NULL); - myMenu->AddItem(myItem); - myItem->SetMarked(true); - myMenu->RemoveItem(myItem); - delete myItem; - } - - } - myMenu->RemoveItem(myItem); - delete myItem; - } - w->Unlock(); - return; - } - } - w->Unlock(); - } - } - } - Error(dropbox, "DROPBOX"); -} - -int YabInterface::DropBoxCount(const char* dropbox) -{ - int ret = -1; - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(dropbox), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - ret = myMenu->CountItems(); - w->Unlock(); - return ret; - } - } - w->Unlock(); - } - } - } - Error(dropbox, "DROPBOX"); -} - -const char* YabInterface::DropBoxGet(const char* dropbox, int position) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(dropbox), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - const char *ret; - position --; - if(position<0) position = 0; - if(position>=myMenu->CountItems()) - position = myMenu->CountItems()-1; - if(myMenu->CountItems()!=0) - { - ret = (myMenu->ItemAt(position))->Label(); - w->Unlock(); - return ret; - } - else - { - w->Unlock(); - return ""; - } - } - } - w->Unlock(); - } - } - } - Error(dropbox, "DROPBOX"); -} - -double YabInterface::MenuHeight() -{ - double ret = -1; - for(int i=0; iLock(); - menubar = cast_as(w->FindView("menubar"), BMenuBar); - if(menubar) - { - ret = menubar->Bounds().bottom - menubar->Bounds().top; - w->Unlock(); - break; - } - w->Unlock(); - } - } - return ret; -} - -double YabInterface::TabHeight() -{ - BFont f = be_plain_font; - font_height fh; - f.GetHeight(&fh); - return fh.ascent + fh.descent + fh.leading + 10.0f; -} - -double YabInterface::ScrollbarWidth() -{ - return B_H_SCROLL_BAR_HEIGHT; -} - -const int YabInterface::IsMouseIn(const char* view) -{ - int t = 2; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - t = myView->mouseMovedInfo; - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); - return 1-t; -} - -const char* YabInterface::GetMouseIn() -{ - snooze(20000); - BString ts; - mousemessagebuffer[0] = '\0'; - - int handled = -1; - YabView *myView = NULL; - - for(int i=0; iIsActive()) - { - w->Lock(); - - BView *view = w->LastMouseMovedView(); - if(!view) - { - w->Unlock(); - break; - } - - if(is_kind_of(view->Parent(), BTextControl)) - view = view->Parent(); - if(is_kind_of(view->Parent(), Spinner)) - view = view->Parent(); - if(is_kind_of(view->Parent(), CalendarControl)) - view = view->Parent(); - if(is_kind_of(view->Parent(), BColorControl)) - view = view->Parent(); - if(is_kind_of(view->Parent(), YabText)) - view = view->Parent(); - if(is_kind_of(view->Parent(), BColumnListView)) - view = view->Parent(); - if(is_kind_of(view, BBox)) - view = view->Parent(); - if(is_kind_of(view, BMenuBar)) - view = view->Parent(); - - BString name = view->Name(); - BPoint coordinates; - uint32 buttons; - - view->GetMouse(&coordinates, &buttons); - - ts << name << ":" << (int)coordinates.x << ":" << (int)coordinates.y << ":"; - if(buttons & B_PRIMARY_MOUSE_BUTTON) - ts << 1 << ":"; - else - ts << 0 << ":"; - if(buttons & B_TERTIARY_MOUSE_BUTTON) - ts << 1 << ":"; - else - ts << 0 << ":"; - if(buttons & B_SECONDARY_MOUSE_BUTTON) - ts << 1; - else - ts << 0; - - w->Unlock(); - } - } - - strcpy(mousemessagebuffer, ts.String()); - return (char*)mousemessagebuffer; -} - -const char* YabInterface::KeyboardMessages(const char* view) -{ - snooze(20000); - keyboardbuffer[0] = '\0'; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BString t(""); - w->Lock(); - // if(!myView->IsFocus()) myView->MakeFocus(true); - if(myView->IsFocus()) - t << myView->pressedKeys; - w->Unlock(); - strcpy(keyboardbuffer, t.String()); - } - else - ErrorGen("Unable to lock window"); - } - else - Error(view, "VIEW"); - return (char*)keyboardbuffer; -} - -const char* YabInterface::GetMouseMessages(const char* view) -{ - snooze(20000); - mousemessagebuffer[0] = '\0'; - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BString t(""); - w->Lock(); - t << myView->mouseX; t += ":"; - t << myView->mouseY; t += ":"; - t << myView->mouseLButton; t += ":"; - t << myView->mouseMButton; t += ":"; - t << myView->mouseRButton; - w->Unlock(); - strcpy(mousemessagebuffer, t.String()); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), view)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BString t(""); - w->Lock(); - t << myView->mouseX; t += ":"; - t << myView->mouseY; t += ":"; - t << myView->mouseLButton; t += ":"; - t << myView->mouseMButton; t += ":"; - t << myView->mouseRButton; - w->Unlock(); - strcpy(mousemessagebuffer, t.String()); - return (char*)mousemessagebuffer; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(view, "VIEW"); - } - return (char*)mousemessagebuffer; -} - -int YabInterface::ThreadKill(const char* option, int id) -{ - int isTeam = -1; - int ret = 0; - BString t(option); - if(t.IFindFirst("teamid")!=B_ERROR) isTeam = 1; - if(t.IFindFirst("threadid")!=B_ERROR) isTeam = 0; - if(isTeam==1) - { - if(kill_team(id)==B_OK) ret = 1; - } - else if(isTeam==0) - { - if(kill_thread(id)==B_OK) ret = 1; - } - else - ErrorGen("Unknown Option"); - - return ret; -} - -int YabInterface::ThreadGet(const char* option, const char* appname) -{ - int isTeam = -1; - int ret = -1; - BString t(option); - if(t.IFindFirst("teamid")!=B_ERROR) isTeam = 1; - if(t.IFindFirst("threadid")!=B_ERROR) isTeam = 0; - if(isTeam==0) - { - ret = find_thread(appname); - if(ret == B_NAME_NOT_FOUND) ret = -1; - } - else if(isTeam==1) - { - int32 cookie=0; - team_info info; - BString t(appname); - while (get_next_team_info(&cookie, &info) == B_OK) - { - if(t.FindFirst(info.args)==B_OK) - { - ret = info.team; - break; - } - } - } - else - ErrorGen("Unknown Option"); - - return ret; -} -//Correction of Subitem by Stephan Aßmus on BeGeistert 2018 -void YabInterface::Bitmap(double w, double h, const char* id) -{ - char *t; - BBitmap *b = new BBitmap(BRect(0,0,w-1,h-1), B_RGBA32, true); - BView *bview = new BView(BRect(0,0,w-1,h-1), id, B_FOLLOW_NONE, 0); - - //bview->SetDrawingMode(B_OP_ALPHA); - //bview->SetViewColor(255,255,255,255); - b->AddChild(bview); - - memset(b->Bits(), 0, b->BitsLength()); -// t = (char*)b->Bits(); -// for(int i=0; iAddItem(b); -} - -int YabInterface::BitmapColor(double x, double y, const char* bitmap, const char* option) -{ - int rgb = 0; - BString tmp(option); - if(tmp.IFindFirst("red")!=B_ERROR) rgb = 1; - else if(tmp.IFindFirst("green")!=B_ERROR) rgb = 2; - else if(tmp.IFindFirst("blue")!=B_ERROR) rgb = 3; - else - ErrorGen("Unknown Option"); - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(bitmap); - if(bview) - { - int t = b->BytesPerRow()*(int)y + (int)x*4; - unsigned char* bits = (unsigned char*)b->Bits(); - if(t <= b->BitsLength()) - if(rgb == 1) - return (int)bits[t]; - else if(rgb == 2) - return (int)bits[t+1]; - else if(rgb == 3) - return (int)bits[t+2]; - return 0; - } - } - Error(bitmap, "BITMAP"); -} - -void YabInterface::BitmapDraw(double x, double y, const char* bitmap, const char* mode, const char* view) -{ - drawing_mode myMode; - BString tmp(mode); - if(tmp.IFindFirst("copy")!=B_ERROR) - myMode = B_OP_COPY; - else if(tmp.IFindFirst("alpha")!=B_ERROR) - myMode = B_OP_ALPHA; - else - ErrorGen("Unknown option"); - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(bitmap); - if(bview) - { - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BBitmap *newb = new BBitmap(b->Bounds(), B_RGBA32); - - char* newbits = (char*)newb->Bits(); - char* oldbits = (char*)b->Bits(); - for(int j=0; jBitsLength(); j++) - newbits[j] = oldbits[j]; - - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 10; - t->x1 = x; t->y1 = y; - t->bitmap = newb; - myView->drawList->AddItem(t); - myView->Invalidate(); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *bb = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bbview = bb->FindView(view); - if(bbview) - { - bb->Lock(); - drawing_mode t = bbview->DrawingMode(); - bbview->SetDrawingMode(myMode); - bbview->DrawBitmap(b, BPoint(x,y)); - bbview->SetDrawingMode(t); - bbview->Sync(); - bb->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), view)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *bb = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - bb->Lock(); - drawing_mode t = bView->DrawingMode(); - bView->SetDrawingMode(myMode); - bView->DrawBitmap(b, BPoint(x,y)); - bView->Sync(); - bView->SetDrawingMode(t); - bb->Unlock(); - - myView->Draw(BRect(x,y,x+b->Bounds().Width(),y+b->Bounds().Height())); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(view, "VIEW, BITMAP or CANVAS"); - } - } - } - Error(bitmap, "BITMAP"); -} - -void YabInterface::BitmapDraw(BRect frame, const char* bitmap, const char* mode, const char* view) -{ - int scaling = 0; - if(frame.right == -1) scaling = 1; - if(frame.bottom == -1) scaling = 2; - if(frame.right == -1 && frame.bottom == -1) scaling = 3; - - drawing_mode myMode; - BString tmp(mode); - if(tmp.IFindFirst("copy")!=B_ERROR) - myMode = B_OP_COPY; - else if(tmp.IFindFirst("alpha")!=B_ERROR) - myMode = B_OP_ALPHA; - else - ErrorGen("Unknown option"); - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(bitmap); - if(bview) - { - BRect newframe; - switch(scaling) - { - case 1: - { - BRect t(b->Bounds()); - double width; - newframe = frame; - width = (t.right-t.left)*((frame.bottom-frame.top)/(t.bottom-t.top)); - newframe.right = newframe.left+width; - } - break; - case 2: - { - BRect t(b->Bounds()); - double height; - newframe = frame; - height = (t.bottom-t.top)*((frame.right-frame.left)/(t.right-t.left)); - newframe.bottom = newframe.top+height; - } - break; - case 3: newframe = b->Bounds(); - break; - default: newframe = frame; - } - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - BBitmap *newb = new BBitmap(b->Bounds(), B_RGBA32); - char* newbits = (char*)newb->Bits(); - char* oldbits = (char*)b->Bits(); - for(int j=0; jBitsLength(); j++) - newbits[j] = oldbits[j]; - w->Lock(); - YabDrawing *t = new YabDrawing(); - t->command = 11; - t->x1 = newframe.left; t->y1 = newframe.top; - t->x2 = newframe.right; t->y2 = newframe.bottom; - t->bitmap = newb; - myView->drawList->AddItem(t); - myView->Invalidate(); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *bb = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bbview = bb->FindView(view); - if(bbview) - { - bb->Lock(); - drawing_mode t = bbview->DrawingMode(); - bbview->SetDrawingMode(myMode); - bbview->DrawBitmap(b, newframe); - bbview->SetDrawingMode(t); - bbview->Sync(); - bb->Unlock(); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), view)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *bb = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - bb->Lock(); - drawing_mode t = bView->DrawingMode(); - bView->SetDrawingMode(myMode); - bView->DrawBitmap(b, frame); - bView->Sync(); - bView->SetDrawingMode(t); - bb->Unlock(); - - myView->Draw(newframe); - w->Unlock(); - return; - } - else - ErrorGen("Unable to lock window"); - } - } - Error(view, "VIEW, BITMAP or CANVAS"); - } - } - } - Error(bitmap, "BITMAP"); -} -//Correction added of Width and Height and transparency Pixel of the right and bottom side -void YabInterface::BitmapGet(BRect frame, const char* id, const char* bitmap) -{ - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(bitmap); - - if(bview) - { - char *oldbits, *newbits; - - BBitmap *newbmp = new BBitmap(BRect(0,0, frame.Width()-1, frame.Height()-1), B_RGBA32, true); //-1 Added, because correction of right and height limit - BView *newbview = new BView(BRect(0,0, frame.Width()-1, frame.Height()-1), id, B_FOLLOW_NONE, 0);//-1 Added, because correction of right and height limit - - newbmp->AddChild(newbview); - newbits = (char*)newbmp->Bits(); - for(int i=0; i<(frame.Width()-1)*(frame.Height()-1)*4; i = i + 4) //-1 Added, because correction of right and height limit - { - newbits[i] = newbits[i+1] = newbits[i+2] = 255; - newbits[i+3] = 0; - } - oldbits = (char*)b->Bits(); - b->Lock(); - BRect tframe = bview->Bounds(); - b->Unlock(); - if(frame.top>tframe.bottom || frame.left>tframe.right || (frame.bottom-1)>tframe.bottom || (frame.right-1)>tframe.right || frame.top<0 || frame.left<0 || frame.right<0 || frame.bottom<0) - ErrorGen("Out of bounds"); - for(int32 j = 0; jBytesPerRow()+k*4+l] = oldbits[(int32)((j+frame.top)*b->BytesPerRow()+(k+frame.left)*4+l)]; - yabbitmaps->AddItem(newbmp); - return; - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - - if(!strcmp(myView->Name(), bitmap)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *b = myView->GetBitmap(); - char *oldbits, *newbits; - BBitmap *newbmp = new BBitmap(BRect(0,0, frame.Width()-1, frame.Height()-1), B_RGBA32, true);//-1 Added, because correction of right and height limit - BView *newbview = new BView(BRect(0,0, frame.Width()-1, frame.Height()-1), id, B_FOLLOW_NONE, 0);//-1 Added, because correction of right and height limit - newbmp->AddChild(newbview); - newbits = (char*)newbmp->Bits(); - - for(int i=0; i<(frame.Width()-1)*(frame.Height()-1)*4; i = i + 4) //-1 Added, because correction of right and height limit - { - newbits[i] = newbits[i+1] = newbits[i+2] = 255; - newbits[i+3] = 0; - } - oldbits = (char*)b->Bits(); - BRect tframe = myView->Bounds(); - if(frame.top>tframe.bottom || frame.left>tframe.right || (frame.bottom-1)>tframe.bottom || (frame.right-1)>tframe.right || frame.top<0 || frame.left<0 || frame.right<0 || frame.bottom<0) - ErrorGen("Out of bounds"); - for(int32 j = 0; jBytesPerRow()+k*4+l] = oldbits[(int32)((j+frame.top)*b->BytesPerRow()+(k+frame.left)*4+l)]; - yabbitmaps->AddItem(newbmp); - w->Unlock(); - return; - } - } - } - Error(bitmap, "BITMAP or CANVAS"); -} - -void YabInterface::BitmapGet(double w, const char* id, const char* path) -{ - double h = w; - BRect iFrame = BRect(0, 0, w-1, h-1); - BBitmap *iBitmap = new BBitmap(iFrame, B_CMAP8, true); - BBitmap *fBitmap = new BBitmap(iFrame, B_RGBA32, true); - BView *bview = new BView(iFrame, id, B_FOLLOW_NONE, 0); - fBitmap->AddChild(bview); - - - //memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); - char *b; - b = (char*)fBitmap->Bits(); - for(int i=0; iLock(); - bview->DrawBitmap( iBitmap, iFrame ); - fBitmap->Unlock(); - - delete fNode; - delete iBitmap; - yabbitmaps->AddItem(fBitmap); -} - -void YabInterface::BitmapGetIcon(const char* id, const char* option, const char* path) -{ - BString fString(option); - if( fString.IFindFirst("Path") != B_ERROR ) - { - int w; - int h = w = 32; - BRect iFrame = BRect(0, 0, w-1, h-1); - BBitmap *iBitmap = new BBitmap(iFrame, B_CMAP8, true); - BBitmap *fBitmap = new BBitmap(iFrame, B_RGBA32, true); - BView *bview = new BView(iFrame, id, B_FOLLOW_NONE, 0); - fBitmap->AddChild(bview); - - char *b; - //memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); - b = (char*)fBitmap->Bits(); - for(int i=0; iLock(); - bview->DrawBitmap( iBitmap, iFrame ); - fBitmap->Unlock(); - - delete fNode; - delete iBitmap; - yabbitmaps->AddItem(fBitmap); - - } - else if( fString.IFindFirst("Mime") != B_ERROR ) - { - int w; - int h = w = 16; - icon_size iType = B_MINI_ICON; - if( fString.IFindFirst("Mime32") != B_ERROR ) - { - h = w = 32; - iType = B_LARGE_ICON; - } - - BRect iFrame = BRect(0, 0, w-1, h-1); - BBitmap *iBitmap = new BBitmap(iFrame, B_CMAP8, true); - BBitmap *fBitmap = new BBitmap(iFrame, B_RGBA32, true); - BView *bview = new BView(iFrame, id, B_FOLLOW_NONE, 0); - fBitmap->AddChild(bview); - - char *b; - memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); - b = (char*)fBitmap->Bits(); - for(int i=0; iLock(); - bview->DrawBitmap(iBitmap, iFrame); - bview->Sync(); - fBitmap->Unlock(); - - delete iBitmap; - yabbitmaps->AddItem(fBitmap); - } - else - ErrorGen("Unknown option"); - -} - -void YabInterface::BitmapDrag(const char* bitmap) -{ -} - -void YabInterface::BitmapRemove(const char* bitmap) -{ - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(bitmap); - if(bview) - { - yabbitmaps->RemoveItem(i); - delete b; - return; - } - } - Error(bitmap, "BITMAP"); -} - -void YabInterface::Screenshot(BRect frame, const char* bitmap) -{ - char *t; - int w = (int)frame.Width()-1; - int h = (int)frame.Height()-1; - - BRect area = BRect(0,0,w,h); - BBitmap *fBitmap = new BBitmap(area, B_RGBA32, true); - BView *bview = new BView(area, bitmap, B_FOLLOW_NONE, 0); - BScreen screen(B_MAIN_SCREEN_ID); - fBitmap->AddChild(bview); - //memset(fBitmap->Bits(), 0, fBitmap->BitsLength()); - t = (char*)fBitmap->Bits(); - for(int i=0; iAddItem(fBitmap); -} - -int YabInterface::BitmapLoad(const char* FileName, const char* id) -{ - BBitmap* myBitmap = NULL; - BFile imageFile; - BPath imagePath; - int ret = 0; - - if(*FileName=='/') - imageFile.SetTo(FileName, B_READ_ONLY); - else - if(!strcmp(ApplicationDirectory,"")) - { - if(imagePath.SetTo((const char*)ApplicationDirectory, FileName)==B_OK) - imageFile.SetTo(imagePath.Path(), B_READ_ONLY); - } - - if(imageFile.InitCheck()!=B_OK) - imageFile.SetTo(FileName, B_READ_ONLY); - - if(imageFile.InitCheck()!=B_OK) - return 1; - - Roster = BTranslatorRoster::Default(); - - if(!Roster) - return 2; - - BBitmapStream Stream; - - if(Roster->Translate(&imageFile, NULL, NULL, &Stream, B_TRANSLATOR_BITMAP)Bounds(), B_RGBA32, true); - BView *bview = new BView(myBitmap->Bounds(), id, B_FOLLOW_NONE, 0); - b->AddChild(bview); - /* - t = (char*)b->Bits(); - for(int i=0; iLock(); - drawing_mode mode = bview->DrawingMode(); - bview->SetDrawingMode(B_OP_ALPHA); - bview->DrawBitmap(myBitmap, myBitmap->Bounds()); - bview->SetDrawingMode(mode); - bview->Sync(); - b->Unlock(); - - delete Roster; - delete myBitmap; - - yabbitmaps->AddItem(b); - - return 0; -} - -int YabInterface::BitmapGet(const char* id, const char* option) -{ - BString t(option); - bool isWidth = false; - if(t.IFindFirst("height") != B_ERROR) - isWidth = false; - else if(t.IFindFirst("width") != B_ERROR) - isWidth = true; - else - ErrorGen("Unknown option"); - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(id); - if(bview) - { - BRect r = b->Bounds(); - if(isWidth) - return r.IntegerWidth(); //+1; - else - return r.IntegerHeight(); //+1; - } - } - Error(id, "BITMAP"); -} - -int YabInterface::BitmapSave(const char* id, const char* filename, const char* type) -{ - uint32 btype; - BString t(type); - if(t.IFindFirst("png") != B_ERROR) - btype = B_PNG_FORMAT; - else if(t.IFindFirst("jpg") != B_ERROR) - btype = B_JPEG_FORMAT; - else if(t.IFindFirst("tga") != B_ERROR) - btype = B_TGA_FORMAT; - else if(t.IFindFirst("tiff") != B_ERROR) - btype = B_TIFF_FORMAT; - else if(t.IFindFirst("ppm") != B_ERROR) - btype = B_PPM_FORMAT; - else if(t.IFindFirst("bmp") != B_ERROR) - btype = B_BMP_FORMAT; - else - ErrorGen("Unknown type"); - - for(int i=0; iCountItems(); i++) - { - BBitmap *b = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bview = b->FindView(id); - if(bview) - { - BTranslatorRoster *roster = BTranslatorRoster::Default(); - BBitmapStream stream(b); // init with contents of bitmap - BFile file(filename, B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE); - if(roster->Translate(&stream, NULL, NULL, &file, btype) != B_OK) - return 1; - else - return 0; - } - } - Error(id, "BITMAP"); -} - -void YabInterface::Canvas(BRect frame, const char* id, const char* view) -{ - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - YabBitmapView *bmpView = new YabBitmapView(frame, id, B_FOLLOW_NONE, B_WILL_DRAW); - if(w->layout == -1) - bmpView->SetResizingMode(B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM); - else - bmpView->SetResizingMode(w->layout); - myView->AddChild(bmpView); - yabcanvas->AddItem(bmpView); - myView->Invalidate(frame); - w->Unlock(); - return; - } - } - Error(view, "VIEW"); -} -int YabInterface::Sound(const char* filename) //Reactivate Sound Lorglas 2020.01.02 -{ - int soundplayer; - entry_ref ref; - BEntry entry(filename, true); - //Check, if filename is ok - if (entry.InitCheck() == B_OK) - if (entry.GetRef(&ref) == B_OK) - //delete playing fplayer, because we get no ID back from fplayer. So if we didn't deleting fplayer, a second sound will be played and the first one can't be stopped - delete fPlayer; - fPlayer = new BFileGameSound(&ref, false); - fPlayer->StartPlaying(); - soundplayer=1; - return soundplayer; -} - -int YabInterface::SoundStop(int32 soundplayer) //Reactivate Sound Lorglas 2020.01.02 -{ - //Check, if fplayer is NULL, then do nothing - if (fPlayer == NULL) { - } - //Check, if fplayer is Playing, then stop playing and delete fplayer - if (fPlayer->IsPlaying()) { - fPlayer->StopPlaying(); - delete fPlayer; - fPlayer = NULL; - soundplayer=0; - //printf("%d\n",finished); - return soundplayer; - } -} - -int YabInterface::SoundWait(int32 soundplayer) //Reactivate Sound Lorglas 2020.01.03 -{ - //Check, if fplayr is in Paused modus, if so Setpaused to false, so play again, if true fplayer paused - if (fPlayer->IsPaused()) { - fPlayer->SetPaused(false, 2); - } - else { - fPlayer->SetPaused(true, 0); - } - soundplayer=2; - return soundplayer; -} -void play_buffer(void *cookie, void * buffer, size_t size, const media_raw_audio_format & format) -{ - int64 frames = 0; - - playTrack->ReadFrames(buffer, &frames); - - if (frames <=0) { - player->SetHasData(false); - - } -} -int YabInterface::MediaSound(const char* filename) //Implementation MediaSound Lorglas 2020.01.02 code used and modified from media_client -{ - BUrl url; - entry_ref ref; - BMediaFile* playFile; - int finished; - if (get_ref_for_path(filename, &ref) != B_OK) - { - url.SetUrlString(filename); - if (url.IsValid()) - { - playFile = new BMediaFile(url); - } - else - { - return 2; - } - } - else - { - playFile = new BMediaFile(&ref); - } - if (playFile->InitCheck() != B_OK) - { - delete playFile; - return 2; - } - - for (int i = 0; i < playFile->CountTracks(); i++) - { - BMediaTrack* track = playFile->TrackAt(i); - if (track != NULL) - { - playFormat.type = B_MEDIA_RAW_AUDIO; - if ((track->DecodedFormat(&playFormat) == B_OK) && (playFormat.type == B_MEDIA_RAW_AUDIO)) - { - playTrack = track; - break; - } - playFile->ReleaseTrack(track); - } - } - - player = new BSoundPlayer(&playFormat.u.raw_audio, "playFile", play_buffer); - player->SetVolume(1.0f); - player->SetHasData(true); - player->Start(); - finished=1; - //printf(" %s is playing \n",filename); - return finished; - -} -int YabInterface::MediaSoundStop(int32 finished) //New Version Sound Lorglas 2020.01.02 -{ - //Check, if fplayer is NULL, then do nothing - if (finished==1) { - player->Stop(); - delete player; - finished=0; - //printf("%d\n",finished); - return finished; - } -} -void YabInterface::SetOption(const char* id, const char* option, double x, double y) -{ - BString tmp(option); - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BView *theView = cast_as(myView->FindView(id), BView); - if(theView) - { - if(tmp.IFindFirst("ResizeTo")!=B_ERROR) - theView->ResizeTo(x,y); - else if(tmp.IFindFirst("ResizeBy")!=B_ERROR) - theView->ResizeBy(x,y); - else if(tmp.IFindFirst("MoveTo")!=B_ERROR) - theView->MoveTo(x,y); - else if(tmp.IFindFirst("MoveBy")!=B_ERROR) - theView->MoveBy(x,y); - else - ErrorGen("Unknown option"); - theView->Invalidate(); - w->Unlock(); - return; - } - w->Unlock(); - } - } - } - Error(id, "VIEW"); -} - -void YabInterface::DrawSet(const char* option, const char* color,const char* view) -{ - BString tmp(option); - BString colstr(color); - rgb_color col; - if(colstr.IFindFirst("Panel-Background-Color")!=B_ERROR) - col = ui_color(B_PANEL_BACKGROUND_COLOR); - else if(colstr.IFindFirst("Panel-Text-Color")!=B_ERROR) - { - col = ui_color(B_PANEL_TEXT_COLOR); - } - else if(colstr.IFindFirst("Panel-Link-Color")!=B_ERROR) - { - col.red = 0; col.green = 0; col.blue = 255; - } - else if(colstr.IFindFirst("Menu-Background-Color")!=B_ERROR) - col = ui_color(B_MENU_BACKGROUND_COLOR); - else if(colstr.IFindFirst("Menu-Selection-Background-Color")!=B_ERROR) - col = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR); - else if(colstr.IFindFirst("Menu-Item-Text-Color")!=B_ERROR) - col = ui_color(B_MENU_ITEM_TEXT_COLOR); - else if(colstr.IFindFirst("Menu-Selected-Item-Text-Color")!=B_ERROR) - col = ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR); - else if(colstr.IFindFirst("Keyboard-Navigation-Color")!=B_ERROR) - col = ui_color(B_KEYBOARD_NAVIGATION_COLOR); - else if(colstr.IFindFirst("Jan-Favorite-Color")!=B_ERROR) - { - col.red = 220; col.green = 220; col.blue = 250; - } - else - ErrorGen("Invalid color"); - if(colstr.IFindFirst("Lighten-1-Tint")!=B_ERROR) - col = tint_color(col, B_LIGHTEN_1_TINT); - else if(colstr.IFindFirst("Lighten-2-Tint")!=B_ERROR) - col = tint_color(col, B_LIGHTEN_2_TINT); - else if(colstr.IFindFirst("Lighten-Max-Tint")!=B_ERROR) - col = tint_color(col, B_LIGHTEN_MAX_TINT); - else if(colstr.IFindFirst("Darken-1-Tint")!=B_ERROR) - col = tint_color(col, B_DARKEN_1_TINT); - else if(colstr.IFindFirst("Darken-2-Tint")!=B_ERROR) - col = tint_color(col, B_DARKEN_2_TINT); - else if(colstr.IFindFirst("Darken-3-Tint")!=B_ERROR) - col = tint_color(col, B_DARKEN_3_TINT); - else if(colstr.IFindFirst("Darken-4-Tint")!=B_ERROR) - col = tint_color(col, B_DARKEN_4_TINT); - else if(colstr.IFindFirst("Darken-Max-Tint")!=B_ERROR) - col = tint_color(col, B_DARKEN_MAX_TINT); - else if(colstr.IFindFirst("Disabled-Label-Tint")!=B_ERROR) - col = tint_color(col, B_DISABLED_LABEL_TINT); - else if(colstr.IFindFirst("Disabled-Mark-Tint")!=B_ERROR) - col = tint_color(col, B_DISABLED_MARK_TINT); - else if(colstr.IFindFirst("Highlight-Background-Tint")!=B_ERROR) - col = tint_color(col, B_HIGHLIGHT_BACKGROUND_TINT); - col.alpha = yabAlpha; - - YabView *myView = cast_as((BView*)viewList->GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - if(tmp.IFindFirst("BGColor")!=B_ERROR) - { - myView->SetViewColor(col); - myView->Invalidate(); - } - else if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - if(yabAlpha == 255) - myView->SetDrawingMode(B_OP_COPY); - else - myView->SetDrawingMode(B_OP_ALPHA); - myView->SetHighColor(col); - YabDrawing *t = new YabDrawing(); - t->command = 6; - t->r = col.red; t->g = col.green; - t->b = col.blue; t->alpha = yabAlpha; - myView->drawList->AddItem(t); - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - if(yabAlpha == 255) - myView->SetDrawingMode(B_OP_COPY); - else - myView->SetDrawingMode(B_OP_ALPHA); - myView->SetLowColor(col); - YabDrawing *t = new YabDrawing(); - t->command = 7; - t->r = col.red; t->g = col.green; - t->b = col.blue; t->alpha = yabAlpha; - myView->drawList->AddItem(t); - } - else - ErrorGen("Unknown option"); - w->Unlock(); - } - else - ErrorGen("Unable to lock window"); - } - else - { - for(int i=0; iCountItems(); i++) - { - BBitmap *bmp = (BBitmap*)yabbitmaps->ItemAt(i); - BView *bView = bmp->FindView(view); - if(bView) - { - if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetHighColor(col); - bView->Sync(); - bmp->Unlock(); - return; - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetLowColor(col); - bView->Sync(); - bmp->Unlock(); - return; - } - else - ErrorGen("Unknown option"); - } - } - for(int i=0; iCountItems(); i++) - { - YabBitmapView *myView = (YabBitmapView*)yabcanvas->ItemAt(i); - if(!strcmp(myView->Name(), view)) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BBitmap *bmp = myView->GetBitmap(); - BView *bView = myView->GetBitmapView(); - if(tmp.IFindFirst("HighColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetHighColor(col); - bView->Sync(); - bmp->Unlock(); - w->Unlock(); - return; - } - else if(tmp.IFindFirst("LowColor")!=B_ERROR) - { - bmp->Lock(); - if(yabAlpha == 255) - bView->SetDrawingMode(B_OP_COPY); - else - bView->SetDrawingMode(B_OP_ALPHA); - bView->SetLowColor(col); - bView->Sync(); - bmp->Unlock(); - w->Unlock(); - return; - } - else - ErrorGen("Unknown option"); - } - else - ErrorGen("Unable to lock window"); - } - } - Error(view, "VIEW, BITMAP or CANVAS"); - } -} - -void YabInterface::Treebox13(const char* id,const char* option, int pos) -{ -} - -int YabInterface::TreeboxGetOpt(const char* id, const char* option, int pos) -{ -} - -int YabInterface::ListboxGetNum(const char* id) -{ - YabView *myView = NULL; - BListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(id), BListView); - if(myList) - { - int32 t = myList->CurrentSelection(); - w->Unlock(); - return t+1; - } - w->Unlock(); - } - } - } - Error(id, "LISTBOX"); -} - -int YabInterface::DropboxGetNum(const char* id) -{ - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMenuField *myMenuField = cast_as(myView->FindView(id), BMenuField); - if(myMenuField) - { - BMenu *myMenu = (BMenu*)myMenuField->Menu(); - if(myMenu) - { - int32 ret; - ret = myMenu->IndexOf(myMenu->FindMarked()); - w->Unlock(); - return ret; - } - } - w->Unlock(); - } - } - } - Error(id, "DROPBOX"); -} - -int YabInterface::TreeboxGetNum(const char* id) -{ - YabView *myView = NULL; - BOutlineListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(id), BOutlineListView); - if(myList) - { - int32 t = myList->FullListCurrentSelection(); - w->Unlock(); - return t+1; - } - w->Unlock(); - } - } - } - Error(id, "TREEBOX"); -} - -int YabInterface::ColumnboxGetNum(const char* id) -{ - YabView *myView = NULL; - BColumnListView *myList = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - myList = cast_as(myView->FindView(id), BColumnListView); - if(myList) - { - int32 t = myList->IndexOf(myList->CurrentSelection()); - w->Unlock(); - return t+1; - } - w->Unlock(); - } - } - } - Error(id, "COLUMNBOX"); -} - -void YabInterface::Attribute1(const char* type, const char* name, const char* value, const char* filename) -{ - - // fix to work properly with string and bool types. - BNode node(filename); - if(node.InitCheck() != B_OK) - ErrorGen("Attribute file not found!"); - BString tempvalue(value); - - - type_code typecode; - BString typeStr(type); - if(typeStr.IFindFirst("string")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_STRING_TYPE; - x++; - node.WriteAttr(name, typecode, 0, value, x); - } - else if(typeStr.IFindFirst("mime")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_MIME_STRING_TYPE; - x++; - node.WriteAttr(name, typecode, 0, value, x); - } - else if(typeStr.IFindFirst("bool")!=B_ERROR) - { - typecode = B_BOOL_TYPE; - int32 x=1; - char str[1]; - str[0]=1; - const char* tf = str; - if (tempvalue.IFindFirst("false") !=B_ERROR) - tf=""; - node.WriteAttr(name, typecode, 0, tf, x); - } - - - else if(typeStr.IFindFirst("int")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_INT32_TYPE; - node.WriteAttr(name, typecode, 0, value, x); - } - - - else if(typeStr.IFindFirst("double")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_DOUBLE_TYPE; - node.WriteAttr(name, typecode, 0, value, x); - } - else if(typeStr.IFindFirst("float")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_FLOAT_TYPE; - node.WriteAttr(name, typecode, 0, value, x); - } - else if(typeStr.IFindFirst("long")!=B_ERROR) - { - int32 x = tempvalue.Length(); - typecode = B_INT64_TYPE; - node.WriteAttr(name, typecode, 0, value, x); - } - else - ErrorGen("Unknown attribute type!"); - - - -} - -void YabInterface::AttributeClear(const char* name, const char* filename) -{ - BNode node(filename); - if(node.InitCheck() != B_OK) - ErrorGen("Attribute file not found!"); - node.RemoveAttr(name); -} - -const char* YabInterface::AttributeGet1(const char* name, const char* filename) -{ - BString tempname(name); - BNode node(filename); - if(node.InitCheck() != B_OK){ - if (tempname.Length() >0) - ErrorGen("Attribute file not found!"); - BString appdir = mainFileName; - int32 i = appdir.FindLast("/"); - appdir.Truncate(i); - return appdir; - } - - if (tempname.Length() >0) - { - attr_info attr; - if(node.GetAttrInfo(name, &attr) != B_OK) - ErrorGen("Attribute not found!"); - - int size = attr.size; - if(size>32568) - size = 32568; - if(node.ReadAttr(name,attr.type, 0, attrbuffer, size) == 0) - return ""; - - if (attr.type == B_BOOL_TYPE) - { - int x = 0; - if (attrbuffer[0] == x) - { - return "false"; - } - else - { - return "true"; - } - } - - return (char*)attrbuffer; - } - else - { - BString List=""; - BString sp=" | "; - BString Attrtype; - char buf[B_ATTR_NAME_LENGTH]; - while (node.GetNextAttrName(buf) == B_OK) - { - attr_info attr; - if(node.GetAttrInfo(buf, &attr) != B_OK) - ErrorGen("Attribute not found!"); - uint32 attrtype; - attrtype=attr.type; - switch(attrtype) - { - case B_BOOL_TYPE: - Attrtype="Bool"; - break; - case B_STRING_TYPE: - Attrtype = "String"; - break; - case B_MIME_STRING_TYPE: - Attrtype = "Mime"; - break; - case B_INT32_TYPE: - Attrtype = "Int"; - break; - case B_DOUBLE_TYPE: - Attrtype = "Double"; - break; - case B_FLOAT_TYPE: - Attrtype = "Float"; - break; - case B_INT64_TYPE: - Attrtype = "Long"; - break; - default: - Attrtype = "Unsupported"; - break; - } - - - List << buf << sp << Attrtype << sp; - } - - - - return List.String(); - - } -} - -double YabInterface::AttributeGet2(const char* name, const char* filename) -{ - BNode node(filename); - if(node.InitCheck() != B_OK) - ErrorGen("Attribute file not found!"); - - attr_info attr; - if(node.GetAttrInfo(name, &attr) != B_OK) - ErrorGen("Attribute not found!"); - int size = attr.size; - if(size>32568) - size = 32568; - if(node.ReadAttr(name,attr.type, 0, attrbuffer, size) == 0) - return 0.0; - if (attr.type == B_BOOL_TYPE) - { - int x = 0; - if (attrbuffer[0] == x) - { - return 0.0; - } - else - { - return 1.0; - } - } - - - if(node.ReadAttr(name, 0, 0, attrbuffer, size) == 0) - return 0.0; - return atof((char*)attrbuffer); -} -void YabInterface::ShortCut(const char* view, const char* key, const char* msg) -{ - char myShortcut; - int32 modifiers = 0; - BString t(key); - if(t.Length()>1) - { - myShortcut = key[t.Length()-1]; - if(t.IFindFirst("s")!=B_ERROR && t.IFindFirst("s")GetView(view), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - BMessage *mesg = new BMessage(YABSHORTCUT); - mesg->AddString("shortcut", msg); - w->AddShortcut(myShortcut, modifiers, mesg); - w->Unlock(); - return; - } - } - Error(view,"VIEW"); -} - -int YabInterface::IsComputerOn() -{ - return is_computer_on(); -} - -void YabInterface::MouseSet(const char* opt) -{ - BString t(opt); - if(t.IFindFirst("Hide")!=B_ERROR) - HideCursor(); - else if(t.IFindFirst("Show")!=B_ERROR) - ShowCursor(); - else if(t.IFindFirst("Obscure")!=B_ERROR) - ObscureCursor(); - else ErrorGen("Unknown option"); -} - -const char* YabInterface::GetMessageString() -{ - snooze(20000); - BString tmp(""); - if(exiting) - { - tmp += "_QuitRequested|"; - exiting = false; - } - tmp += localMessage; - localMessage = ""; - for(int i=0; iTitle(), "_TOOLTIPWINDOW") && strcmp(WindowAt(i)->Title(), "_CALENDARWINDOW")) - - - YabWindow *w = cast_as(WindowAt(i), YabWindow); - if(w) - { - - w->Sync(); - if(w->Lock()) - { - tmp += w->getMessages(); - if (w->WActivated==1) - { - tmp+=w->idString; - tmp+=":_Activated|"; - w->WActivated=-1; - } - if (w->WActivated==0) - { - tmp+=w->idString; - tmp+=":_Deactivated|"; - w->WActivated=-1; - } -// if (w->WFrameMoved==1) -// { -// w->WFrameMoved=-1; -// tmp+=w->Name(); -// tmp+=":_FrameMoved:"; -// tmp << w->Wpx; -// tmp+=":"; -// tmp << w->Wpy; -// tmp+="|"; -// } -// if (w->WFrameResized==1) -// { -// w->WFrameResized=-1; -// tmp+=w->Name(); -// tmp+=":_FrameResized:"; -// tmp << w->Wpw; -// tmp+=":"; -// tmp << w->Wph; -// tmp+="|"; -// } - w->Unlock(); - } - } - } - - - YabView *myView = NULL; - for(int i=0; iCountItems(); i++) - { - myView = cast_as((BView*)viewList->ItemAt(i), YabView); - if(myView) - { - YabWindow *w = cast_as(myView->Window(), YabWindow); - if(w) - { - w->Lock(); - if (myView->CountChildren()) - { - for (int o=0; oCountChildren(); o++) - { - if (dynamic_cast(myView->ChildAt(o))) - { - YabTabView *target = dynamic_cast(myView->ChildAt(o)); - if (target) - { - if (target->FocusChanged!=target->OldTabView) - { - tmp+=target->Name(); - tmp+=":_TabChanged:"; - tmp+=target->Name(); - tmp << target->FocusChanged; - tmp+="|"; - target->OldTabView=target->FocusChanged; - } - - } - } - - } - } - w->Unlock(); - } - } - } - - if(tmp.Length()>32766) - tmp.Remove(32767, tmp.Length()-32766); - strcpy(messagebuffer, tmp.String()); - return (char*)messagebuffer; -} - -int YabInterface::MessageSend(const char* app, const char* msg) -{ - BMessage message, reply; - status_t result; - - // set the command constant - message.what = B_SET_PROPERTY; - - // construct the specifier stack - message.AddSpecifier("YabSendString", msg); // B_NAME_SPECIFIER - - // send the message and fetch the result - result = BMessenger(app).SendMessage(&message, &reply); - if(result == B_OK) return 0; - if(result == B_BAD_PORT_ID) return 1; - if(result == B_WOULD_BLOCK) return 2; - if(result == B_TIMED_OUT) return 3; - return 4; -} - -void YabInterface::SetLocalize(const char* path) -{ - if(yabCatalog) - delete yabCatalog; - //yabCatalog = new BCatalog(path); -} - -const int YabInterface::GetErrorCode() -{ - return errorCode; -} - -void YabInterface::KillThread(int code) -{ - errorCode = code; - quitting = true; - ExitRequested(); - // BMessenger(be_app).SendMessage(new BMessage(B_QUIT_REQUESTED)); - // while(1){} -} - -void YabInterface::Error(const char* id, const char* type) -{ - fprintf(stderr, "---Error in %s, line %d: \"%s\" is not of type %s\n", currentLib.String(), currentLineNumber, id, type); - fprintf(stderr,"---Error: Program stopped due to an error \n"); - KillThread(-1); - // while(1){} -} - -void YabInterface::ErrorGen(const char* msg) -{ - fprintf(stderr, "---Error in %s, line %d: %s\n", currentLib.String(), currentLineNumber, msg); - fprintf(stderr,"---Error: Program stopped due to an error \n"); - KillThread(-1); - // while(1){} -} - -void YabInterface::SetCurrentLineNumber(int line, const char* libname) -{ - currentLineNumber = line; - if(!strcmp(libname, "main")) - currentLib = mainFileName; - else - currentLib = libname; -} - -void YabInterface::SetMainFileName(const char* name) -{ - mainFileName = strdup(name); -} - -/** - * C interface functions - */ - -const char* yi_GetApplicationDirectory(YabInterface *yab) -{ - return yab->GetApplicationDirectory(); -} - -void yi_OpenWindow(double x1,double y1,double x2,double y2, const char* id, const char* title, YabInterface* yab) -{ - yab->OpenWindow(BRect(x1,y1,x2,y2), id, _L(title)); -} - -int yi_CloseWindow(const char* view, YabInterface* yab) -{ - return yab->CloseWindow(view); -} - -void yi_CreateButton(double x1,double y1,double x2,double y2, const char* id, const char* title, const char* view, YabInterface* yab) -{ - yab->CreateButton(BRect(x1,y1,x2,y2), id, _L(title), view); -} - -int yi_CreateImage(double x,double y,const char* imagefile, const char* window, YabInterface* yab) -{ - return yab->CreateImage(BPoint(x,y),imagefile,window); -} - -int yi_CreateImage2(double x1,double y1,double x2,double y2,const char* imagefile, const char* window, YabInterface* yab) -{ - return yab->CreateImage(BRect(x1,y1,x2,y2),imagefile,window); -} - -int yi_CreateSVG(double x1,double y1,double x2,double y2,const char* imagefile, const char* window, YabInterface* yab) -{ - return yab->CreateSVG(BRect(x1,y1,x2,y2),imagefile,window); -} - -void yi_CreateMenu(const char* menuhead, const char* menuitem, const char *shortcut, const char* window, YabInterface* yab) -{ - yab->CreateMenu(_L(menuhead),_L(menuitem),shortcut,window); -} - -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) -{ - yab->CreateTextControl(BRect(x1,y1,x2,y2),id,_L(label),_L(text),window); -} - -void yi_CreateCheckBox(double x, double y, const char* id, const char* label, int isActivated, const char* window, YabInterface *yab) -{ - yab->CreateCheckBox(x,y,id,_L(label),isActivated,window); -} - -void yi_CreateRadioButton(double x, double y, const char* groupID, const char* label, int isActivated, const char* window, YabInterface *yab) -{ - yab->CreateRadioButton(x,y,groupID,_L(label),isActivated,window); -} - -void yi_CreateListBox(double x1, double y1, double x2, double y2, const char* title, int scrollbar, const char* window, YabInterface *yab) -{ - yab->CreateListBox(BRect(x1,y1,x2,y2),title,scrollbar,window); -} - -void yi_CreateDropBox(double x1, double y1, double x2, double y2, const char* title, const char* label, const char* window, YabInterface *yab) -{ - yab->CreateDropBox(BRect(x1,y1,x2,y2),title,_L(label), window); -} - -void yi_CreateItem(const char* id,const char* item, YabInterface *yab) -{ - yab->CreateItem(id,_L(item)); -} - -void yi_RemoveItem(const char* title,const char* item, YabInterface *yab) -{ - yab->RemoveItem(title,_L(item)); -} - -void yi_ClearItems(const char* title, YabInterface *yab) -{ - yab->ClearItems(title); -} - -void yi_DrawText(double x, double y, const char* text, const char* window, YabInterface* yab) -{ - yab->DrawText(BPoint(x,y), _L(text), window); -} - -void yi_DrawRect(double x1, double y1, double x2, double y2, const char* window, YabInterface* yab) -{ - yab->DrawRect(BRect(x1,y1,x2,y2),window); -} - -void yi_DrawClear(const char* window, YabInterface* yab) -{ - yab->DrawClear(window, false); -} - -void yi_CreateAlert(const char* text, const char* button1, const char* type, YabInterface* yab) -{ - yab->CreateAlert(_L(text),_L(button1),type); -} - -void yi_CreateText(double x, double y, const char* id, const char* text, const char* window, YabInterface* yab) -{ - yab->CreateText(x,y,id,_L(text),window); -} - -void yi_Text2(double x1, double y1, double x2, double y2, const char* id, const char* text, const char* window, YabInterface* yab) -{ - yab->Text2(BRect(x1,y1,x2,y2),id,_L(text),window); -} - -void yi_TextAlign(const char* txt, const char *option, YabInterface *yab) -{ - yab->TextAlign(txt, option); -} - -void yi_Translate(char* text, char result[]) -{ - if(yabCatalog) - { - result[0] = '\0'; - strcpy(result,yabCatalog->GetString(text, NULL)); - } - else - strcpy(result,text); -} - -void yi_MenuTranslate(char* text, char result[]) -{ - if(yabCatalog) - { - result[0] = '\0'; - const char* token; - const char delimiters[] = ":"; - - token = strtok(text, delimiters); - while(token!=NULL) - { - strcat(result,yabCatalog->GetString(token, NULL)); //B_TRANSLATE_CONTEXT)); - token = strtok(NULL, delimiters); - if(token!=NULL) strcat(result,":"); - } - } - else - strcpy(result,text); -} - -void yi_SetLocalize() -{ - localize = true; -} - -void yi_StopLocalize() -{ - localize = false; -} - -void yi_SetLocalize2(const char* , YabInterface *yab) -{ - localize = true; - //yab->SetLocalize(path); -} - -const char* yi_LoadFilePanel(const char* mode, const char* title, const char* directory, YabInterface *yab) -{ - return yab->LoadFilePanel(mode, _L(title), directory); -} - -const char* yi_SaveFilePanel(const char* mode, const char* title, const char* directory, const char*filename, YabInterface *yab) -{ - return yab->SaveFilePanel(mode, _L(title), directory, filename); -} - -void yi_SetLayout(const char* layout, const char* window, YabInterface *yab) -{ - yab->SetLayout(layout, window); -} - -void yi_WindowSet1(const char* option, const char* value, const char* window, YabInterface *yab) -{ - yab->WindowSet(option, value, window); -} - -void yi_WindowSet2(const char* option, int r, int g, int b, const char* window, YabInterface *yab) -{ - yab->WindowSet(option, r, g, b, window); -} - -void yi_WindowSet3(const char* option, double x, double y, const char* window, YabInterface *yab) -{ - yab->WindowSet(option,x,y, window); -} - -void yi_WindowSet4(const char* option, const char* window, YabInterface *yab) -{ - yab->WindowSet(option, window); -} - -void yi_WindowClear(const char* window, YabInterface *yab) -{ - yab->WindowClear(window); -} - -void yi_TextEdit(double x1, double y1, double x2, double y2, const char* title, int scrollbar, const char* window, YabInterface *yab) -{ - yab->TextEdit(BRect(x1,y1,x2,y2), title, scrollbar, window); -} - -void yi_TextAdd(const char* title, const char* text, YabInterface *yab) -{ - yab->TextAdd(title,text); -} - -void yi_TextSet(const char* title, const char* option, YabInterface *yab) -{ - yab->TextSet(title,option); -} - -void yi_TextSet2(const char* title, const char* option, int value, YabInterface *yab) -{ - yab->TextSet(title,option,value); -} - -void yi_TextSet3(const char* title, const char* option, const char* value, YabInterface *yab) -{ - yab->TextSet(title,option,value); -} - -void yi_TextColor1(const char* title, const char* option, const char* command, YabInterface *yab) -{ - yab->TextColor(title,option,command); -} - -void yi_TextColor2(const char* title, const char* option, int r, int g, int b, YabInterface *yab) -{ - yab->TextColor(title,option,r,g,b); -} - -int yi_TextGet2(const char* title, const char* option, YabInterface *yab) -{ - return yab->TextGet(title,option); -} - -const char* yi_TextGet3(const char* title, int linenum, YabInterface *yab) -{ - return yab->TextGet(title,linenum); -} - -double yi_TextGet4(const char* title, const char* option, int linenum, YabInterface *yab) -{ - return yab->TextGet(title,option,linenum); -} - -int yi_TextGet5(const char* title, const char* option, const char* option2, YabInterface *yab) -{ - return yab->TextGet(title,option,option2); -} - -const char* yi_TextGet6(const char* title, const char* option, YabInterface *yab) -{ - return yab->TextGet6(title, option); -} - -void yi_TextClear(const char* title, YabInterface *yab) -{ - yab->TextClear(title); -} - -const char* yi_TextGet(const char* title, YabInterface *yab) -{ - return yab->TextGet(title); -} - -void yi_DrawSet1(const char* option, const char* window, YabInterface *yab) -{ - return yab->DrawSet1(option, window); -} - -void yi_DrawSet2(int fillorstroke, const char* mypattern, YabInterface *yab) -{ - return yab->DrawSet2(fillorstroke, mypattern); -} - -void yi_View(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface *yab) -{ - yab->View(BRect(x1,y1,x2,y2), id, view); -} - -void yi_BoxView(double x1, double y1, double x2, double y2, const char* id, const char* text, int lineType, const char* view, YabInterface *yab) -{ - yab->BoxView(BRect(x1,y1,x2,y2), id, _L(text), lineType, view); -} - -void yi_BoxViewSet(const char* id, const char* option,const char* value, YabInterface *yab) -{ - yab->BoxViewSet(id, option,value); -} - - -void yi_Tab(double x1, double y1, double x2, double y2, const char* id, const char* names, const char* view, YabInterface *yab) -{ - yab->Tab(BRect(x1,y1,x2,y2), id, names, view); -} - -void yi_TabSet(const char* id, int num, YabInterface *yab) -{ - yab->TabSet(id, num); -} - -void yi_TabAdd(const char* id, const char* tabname, YabInterface *yab) -{ - yab->TabAdd(id, _L(tabname)); -} - -void yi_TabDel(const char* id, int num, YabInterface *yab) -{ - yab->TabDel(id, num); -} - -int yi_TabViewGet(const char* id, YabInterface *yab) -{ - return yab->TabViewGet(id); -} - -void yi_DrawDot(double x, double y, const char* window, YabInterface *yab) -{ - yab->DrawDot(x,y, window); -} - -void yi_DrawLine(double x1, double y1, double x2, double y2, const char* window, YabInterface *yab) -{ - yab->DrawLine(x1,y1,x2,y2, window); -} - -void yi_DrawCircle(double x, double y, double r, const char* window, YabInterface *yab) -{ - yab->DrawCircle(x,y,r, window); -} - -void yi_DrawEllipse(double x, double y, double r1, double r2, const char* window, YabInterface *yab) -{ - yab->DrawEllipse(x,y,r1,r2, window); -} - -void yi_DrawCurve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char* window, YabInterface *yab) -{ - yab->DrawCurve(x1,y1,x2,y2,x3,y3,x4,y4, window); -} - -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) -{ - yab->Slider(BRect(x1,y1,x2,y2), id, _L(title), min, max, view); -} - -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) -{ - yab->Slider(BRect(x1,y1,x2,y2), id, _L(title), min, max, option, view); -} - -void yi_SetSlider1(const char* id, const char* label1, const char* label2, YabInterface *yab) -{ - yab->SetSlider(id, _L(label1), _L(label2)); -} - -void yi_SetSlider2(const char* id, const char* bottomtop, int count, YabInterface *yab) -{ - yab->SetSlider(id, bottomtop, count); -} - -void yi_SetSlider3(const char* id, const char* part, int r, int g, int b, YabInterface *yab) -{ - yab->SetSlider(id, part, r,g,b); -} - -void yi_SetSlider4(const char* id, int value, YabInterface *yab) -{ - yab->SetSlider(id, value); -} - -void yi_SetOption1(const char* id, const char* option, const char* value, YabInterface *yab) -{ - yab->SetOption(id,option,value); -} - -void yi_SetOption2(const char* id, const char* option, int r, int g, int b, YabInterface *yab) -{ - yab->SetOption(id,option,r,g,b); -} - -void yi_SetOption3(const char* id, const char* option, double x, double y, YabInterface *yab) -{ - yab->SetOption(id,option,x,y); -} - -void yi_SetOption4(const char* id, const char* option, YabInterface *yab) -{ - yab->SetOption(id,option); -} - -void yi_SetOption5(const char* id, const char* option, int value, YabInterface *yab) -{ - yab->SetOption(id,option,value); -} - -void yi_DropZone(const char* view, YabInterface *yab) -{ - yab->DropZone(view); -} - -void yi_ColorControl1(double x, double y, const char* id, const char* view, YabInterface* yab) -{ - yab->ColorControl(x,y,id,view); -} - -void yi_ColorControl2(const char* id, int r, int g, int b, YabInterface* yab) -{ - yab->ColorControl(id,r,g,b); -} - -void yi_TextControl2(const char* id, const char* text, YabInterface* yab) -{ - yab->TextControl(id,_L(text)); -} - -void yi_TextControl3(const char* id, int mode, YabInterface* yab) -{ - yab->TextControl(id,mode); -} - -void yi_TextControl5(const char* id, YabInterface* yab) -{ - yab->TextControl(id); -} - -void yi_TextControl4(const char* id, const char* option, const char* value, YabInterface* yab) -{ - yab->TextControl(id,option,value); -} - -void yi_TreeBox1(double x1, double y1, double x2, double y2, const char* id, int scrollbarType, const char* view, YabInterface* yab) -{ - yab->TreeBox1(BRect(x1,y1,x2,y2), id, scrollbarType, view); -} - -void yi_TreeBox2(const char* id, const char* item, YabInterface* yab) -{ - yab->TreeBox2(id,_L(item)); -} - -void yi_TreeBox3(const char* id, const char* head, const char* item, int isExpanded, YabInterface* yab) -{ - yab->TreeBox3(id,_L(head),_L(item),isExpanded); -} - -void yi_TreeBox4(const char* id, YabInterface* yab) -{ - yab->TreeBox4(id); -} - -void yi_TreeBox5(const char* id, const char* item, YabInterface* yab) -{ - yab->TreeBox5(id,_L(item)); -} - -void yi_TreeBox7(const char* id, int pos, YabInterface* yab) -{ - yab->TreeBox7(id,pos); -} - -void yi_TreeBox8(const char* id, int pos, YabInterface* yab) -{ - yab->TreeBox8(id,pos); -} - -void yi_TreeBox9(const char* id, const char* head, const char* item, YabInterface* yab) -{ - yab->TreeBox9(id,_L(head), _L(item)); -} - -void yi_TreeBox10(const char* id, const char* head, YabInterface* yab) -{ - yab->TreeBox10(id,_L(head)); -} - -void yi_TreeBox11(const char* id, const char* head, YabInterface* yab) -{ - yab->TreeBox11(id,_L(head)); -} - -void yi_TreeBox12(const char* id, const char* item, int pos, YabInterface* yab) -{ - yab->TreeBox12(id,_L(item), pos); -} - -const char* yi_TreeboxGet(const char* treebox, int pos, YabInterface *yab) -{ - return yab->TreeboxGet(treebox, pos); -} - -int yi_TreeboxCount(const char* treebox, YabInterface *yab) -{ - return yab->TreeboxCount(treebox); -} - -void yi_ButtonImage(double x,double y,const char* id,const char* enabledon, const char* enabledoff, const char *disabled, const char* view, YabInterface *yab) -{ - yab->ButtonImage(x,y, id, enabledon, enabledoff, disabled, view); -} - -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) -{ - yab->CheckboxImage(x,y, id, enabledon, enabledoff, disabledon, disabledoff, isActivated, view); -} - -void yi_CheckboxSet(const char* id, int isActivated, YabInterface* yab) -{ - yab->CheckboxSet(id, isActivated); -} - -void yi_RadioSet(const char* id, int isActivated, YabInterface* yab) -{ - yab->RadioSet(id, isActivated); -} - -void yi_ToolTip(const char* view, const char* text, YabInterface *yab) -{ - yab->ToolTips(view,_L(text)); -} - -void yi_ToolTipNew(const char* view, const char* text,const char* color, int r, int g, int b, YabInterface *yab) -{ - yab->ToolTipsNew(view, _L(text), color, r, g, b); -} - -void yi_ToolTipColor(const char* color, int r, int g, int b, YabInterface *yab) -{ - yab->ToolTipsColor(color,r,g,b); -} - -void yi_TreeSort(const char* view, YabInterface *yab) -{ - yab->TreeSort(view); -} - -void yi_ListSort(const char* view, YabInterface *yab) -{ - yab->ListSort(view); -} - -void yi_FileBox(double x1, double y1, double x2, double y2, const char* id, int scrollbartype, const char *option, const char* view, YabInterface *yab) -{ - yab->FileBox(BRect(x1,y1,x2,y2), id, scrollbartype, option, view); -} - -void yi_FileBoxAdd2(const char* columnbox, const char* name, int pos, double maxWidth, double minWidth, double width, const char* option, YabInterface *yab) -{ - yab->FileBoxAdd(columnbox, _L(name), pos, maxWidth, minWidth, width, option); -} - -void yi_FileBoxClear(const char* view, YabInterface *yab) -{ - yab->FileBoxClear(view); -} - -void yi_ColumnBoxAdd(const char* id, int column, int position, int height, const char* item, YabInterface *yab) -{ - yab->ColumnBoxAdd(id, column, position, height, _L(item)); -} - -void yi_ColumnBoxSelect(const char *columnbox, int position, YabInterface *yab) -{ - yab->ColumnBoxSelect(columnbox, position); -} - -void yi_ColumnBoxRemove(const char *columnbox, int position, YabInterface *yab) -{ - yab->ColumnBoxRemove(columnbox, position); -} - -void yi_ColumnBoxColor(const char *columnbox, const char* option, int r, int g, int b, YabInterface *yab) -{ - yab->ColumnBoxColor(columnbox, option, r,g,b); -} - -const char* yi_ColumnBoxGet(const char *columnbox, int column, int position, YabInterface *yab) -{ - return yab->ColumnBoxGet(columnbox, column, position); -} - -int yi_ColumnBoxCount(const char *columnbox, YabInterface *yab) -{ - return yab->ColumnBoxCount(columnbox); -} - -const char* yi_TextControlGet(const char* id, YabInterface* yab) -{ - return yab->TextControlGet(id); -} - -int yi_DeskbarPosition(YabInterface *yab) -{ - return yab->DeskbarParam("position"); -} - -int yi_DeskbarExpanded(YabInterface *yab) -{ - return yab->DeskbarParam("expanded"); -} - -int yi_DeskbarWidth(YabInterface *yab) -{ - return yab->DeskbarParam("width"); -} - -int yi_DeskbarHeight(YabInterface *yab) -{ - return yab->DeskbarParam("height"); -} - -int yi_DeskbarX(YabInterface *yab) -{ - return yab->DeskbarParam("x"); -} - -int yi_DeskbarY(YabInterface *yab) -{ - return yab->DeskbarParam("y"); -} - -int yi_DesktopWidth(YabInterface *yab) -{ - return yab->DesktopParam(true); -} - -int yi_DesktopHeight(YabInterface *yab) -{ - return yab->DesktopParam(false); -} - -int yi_WindowGet(const char* view, const char* option, YabInterface *yab) -{ - return yab->WindowGet(view,option); -} - -int yi_ViewGet(const char* view, const char* option, YabInterface *yab) //vasper -{ - return yab->ViewGet(view,option); -} - -void yi_ClipboardCopy(const char* text, YabInterface *yab) -{ - yab->ClipboardCopy(text); -} - -int yi_Printer(const char* docname, const char *view, const char* config, YabInterface *yab) -{ - return yab->Printer(docname, view,config); -} - -void yi_PrinterConfig(const char* config, YabInterface *yab) -{ - yab->PrinterConfig(config); -} - -const char* yi_ClipboardPaste(YabInterface *yab) -{ - return yab->ClipboardPaste(); -} - -int yi_NewAlert(const char* text, const char* button1, const char* button2, const char* button3, const char* option, YabInterface *yab) -{ - return yab->NewAlert(_L(text), _L(button1), _L(button2), _L(button3), option); -} - -void yi_Calendar1(double x, double y, const char* id, const char* format, const char* date, const char* view, YabInterface *yab) -{ - yab->Calendar(x,y, id, format, date, view); -} - -const char* yi_Calendar2(const char* id, YabInterface *yab) -{ - return yab->Calendar(id); -} - -void yi_Calendar3(const char* id, const char* date, YabInterface *yab) -{ - yab->Calendar(id, date); -} - -const char* yi_ListboxGet(const char* listbox, int pos, YabInterface *yab) -{ - return yab->ListboxGet(listbox, pos); -} - -int yi_ListboxCount(const char* listbox, YabInterface *yab) -{ - return yab->ListboxCount(listbox); -} - -void yi_ListboxAdd1(const char* listbox, const char* item, YabInterface *yab) -{ - yab->ListboxAdd(listbox,_L(item)); -} - -void yi_ListboxAdd2(const char* listbox, int pos, const char* item, YabInterface *yab) -{ - yab->ListboxAdd(listbox, pos, _L(item)); -} - -void yi_ListboxSelect(const char* listbox, int pos, YabInterface *yab) -{ - yab->ListboxSelect(listbox,pos); -} - -void yi_ListboxRemove(const char* listbox, int pos, YabInterface *yab) -{ - yab->ListboxRemove(listbox,pos); -} - -void yi_Scrollbar(const char* id, int format, const char* view, YabInterface *yab) -{ - yab->Scrollbar(id, format, view); -} - -void yi_ScrollbarSet1(const char* scrollview, const char* option, double position, YabInterface *yab) -{ - yab->ScrollbarSet(scrollview, option, position); -} - -void yi_ScrollbarSet2(const char* scrollview, const char* option, double opt1, double opt2, YabInterface *yab) -{ - yab->ScrollbarSet(scrollview, option, opt1, opt2); -} - -void yi_ScrollbarSet3(const char* scrollview, const char* option, YabInterface *yab) -{ - yab->ScrollbarSet(scrollview, option); -} - -double yi_ScrollbarGet(const char* scrollview, const char* option, YabInterface *yab) -{ - return yab->ScrollbarGet(scrollview, option); -} - -void yi_SplitView1(double x1,double y1,double x2,double y2, const char* id, int isVertical, int style, const char* view, YabInterface *yab) -{ - yab->SplitView(BRect(x1,y1,x2,y2), id, isVertical, style, view); -} - -void yi_SplitView2(const char* splitView, const char* option, double position, YabInterface *yab) -{ - yab->SplitView(splitView, option, position); -} - -void yi_SplitView3(const char* splitView, const char* option, double left, double right, YabInterface *yab) -{ - yab->SplitView(splitView, option, left, right); -} - -double yi_SplitViewGet(const char* splitView, const char* option, YabInterface *yab) -{ - return yab->SplitViewGet(splitView, option); -} - -void yi_StackView1(double x1,double y1,double x2,double y2, const char* id, int number, const char* view, YabInterface *yab) -{ - yab->StackViews(BRect(x1,y1,x2,y2), id, number, view); -} - -void yi_StackView2(const char* stackView, int num, YabInterface *yab) -{ - yab->StackViews(stackView, num); -} - -int yi_StackViewGet(const char* stackView, YabInterface *yab) -{ - return yab->StackViewGet(stackView); -} - -void yi_DrawSet3(const char* option, int transparency, YabInterface *yab) -{ - yab->DrawSet3(option, transparency); -} - -extern void yi_TextURL1(double x, double y, const char* id, const char* text, const char* url, const char* view, YabInterface *yab) -{ - yab->TextURL(x,y, id, _L(text), url, view); -} - -void yi_TextURL2(const char* id, const char* option, int r, int g, int b, YabInterface *yab) -{ - yab->TextURL(id, option, r,g,b); -} - -void yi_Menu2(const char* menuHead, int isRadio, const char* view, YabInterface *yab) -{ - yab->Menu(_L(menuHead), isRadio, view); -} - -void yi_SubMenu1(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* modifiers, const char* view, YabInterface *yab) -{ - yab->SubMenu(_L(menuHead), _L(menuItem), _L(subMenuItem), modifiers, view); -} - -void yi_SubMenu2(const char* menuHead, const char* menuItem, int isRadio, const char* view, YabInterface *yab) -{ - yab->SubMenu(_L(menuHead), _L(menuItem), isRadio, view); -} - -void yi_SpinControl1(double x, double y, const char* id, const char* label, int min, int max, int step, const char* view, YabInterface *yab) -{ - yab->SpinControl(x,y, id, _L(label), min, max, step, view); -} - -void yi_SpinControl2(const char* spinControl, int value, YabInterface *yab) -{ - yab->SpinControl(spinControl, value); -} - -int yi_SpinControlGet(const char *spinControl, YabInterface *yab) -{ - return yab->SpinControlGet(spinControl); -} - -const char* yi_PopUpMenu(double x, double y, const char* menuItems, const char* view, YabInterface *yab) -{ - return yab->PopUpMenu(x,y,menuItems,view); -} - -void yi_DropBoxSelect(const char* dropbox, int position, YabInterface *yab) -{ - yab->DropBoxSelect(dropbox, position); -} - -void yi_DropBoxClear(const char* dropbox, YabInterface *yab) -{ - yab->DropBoxClear(dropbox); -} - -void yi_DropBoxRemove(const char* dropbox, int position, YabInterface *yab) -{ - yab->DropBoxRemove(dropbox,position); -} - -int yi_DropBoxCount(const char* dropbox, YabInterface *yab) -{ - return yab->DropBoxCount(dropbox); -} - -const char* yi_DropBoxGet(const char* dropbox, int position, YabInterface *yab) -{ - return yab->DropBoxGet(dropbox, position); -} - -int yi_ColorControlGet(const char* colorcontrol, const char* option, YabInterface *yab) -{ - return yab->ColorControlGet(colorcontrol, option); -} - -int yi_SliderGet(const char* slider, YabInterface *yab) -{ - return yab->SliderGet(slider); -} - -double yi_DrawGet1(const char* option, const char* txt, const char* view, YabInterface *yab) -{ - return yab->DrawGet(option, txt, view); -} - -double yi_DrawGet2(const char* option, const char* view, YabInterface *yab) -{ - return yab->DrawGet(option, "", view); -} - -const char* yi_DrawGet3(const char* option, YabInterface *yab) -{ - return yab->DrawGet(option); -} - -void yi_SubMenu3(const char* menuHead, const char* menuItem, const char* subMenuItem, const char* option, const char* view, YabInterface *yab) -{ - yab->SubMenu3(_L(menuHead), _L(menuItem), _L(subMenuItem), option, view); -} - -void yi_Menu3(const char* menuHead, const char* menuItem, const char* option,const char* view, YabInterface *yab) -{ - yab->Menu3(_L(menuHead), _L(menuItem), option, view); -} - -double yi_MenuHeight(YabInterface *yab) -{ - return yab->MenuHeight(); -} - -double yi_TabHeight(YabInterface *yab) -{ - return yab->TabHeight(); -} - -double yi_ScrollbarWidth(YabInterface *yab) -{ - return yab->ScrollbarWidth(); -} - -void yi_exit(int code, YabInterface *yab) -{ - yab->KillThread(code); -} - -const int yi_IsMouseIn(const char* view, YabInterface *yab) -{ - return yab->IsMouseIn(view); -} - -const char* yi_GetMouseIn(YabInterface *yab) -{ - return yab->GetMouseIn(); -} - - -const char* yi_KeyboardMessages(const char* view, YabInterface* yab) -{ - return yab->KeyboardMessages(view); -} - -const char* yi_GetMouseMessages(const char* view, YabInterface* yab) -{ - return yab->GetMouseMessages(view); -} - -const char* yi_CheckMessages(YabInterface* yab) -{ - return yab->GetMessageString(); -} - -int yi_MessageSend(const char* app, const char* msg,YabInterface* yab) -{ - return yab->MessageSend(app,msg); -} - -int yi_ThreadKill(const char* option, int id,YabInterface* yab) -{ - return yab->ThreadKill(option, id); -} - -int yi_ThreadGet(const char* option, const char* appname,YabInterface* yab) -{ - return yab->ThreadGet(option, appname); -} - -void yi_SetCurrentLineNumber(int line, const char* libname, YabInterface* yab) -{ - yab->SetCurrentLineNumber(line, libname); -} - -void yi_SetMainFileName(const char* name, YabInterface* yab) -{ - yab->SetMainFileName(name); -} - -void yi_beep() -{ - beep(); -} - -void yi_Bitmap(double w, double h, const char* id,YabInterface* yab) -{ - yab->Bitmap(w,h,id); -} - -int yi_BitmapColor(double x, double y, const char* id, const char* option, YabInterface *yab) -{ - yab->BitmapColor(x,y, id, option); -} - -void yi_BitmapDraw(double x, double y, const char* bitmap, const char* mode, const char* view,YabInterface* yab) -{ - yab->BitmapDraw(x,y, bitmap, mode, view); -} - -void yi_BitmapDraw2(double x1, double y1, double x2, double y2, const char* bitmap, const char* mode, const char* view,YabInterface* yab) -{ - yab->BitmapDraw(BRect(x1,y1,x2,y2), bitmap, mode, view); -} - -void yi_BitmapGet(double x1, double y1, double x2, double y2, const char* id, const char* bitmap, YabInterface* yab) -{ - yab->BitmapGet(BRect(x1,y1,x2,y2), id, bitmap); -} - -void yi_BitmapGet2(double w, const char* id, const char* path, YabInterface* yab) -{ - yab->BitmapGet(w, id, path); -} - -int yi_BitmapGetNum(const char* id, const char* option, YabInterface* yab) -{ - yab->BitmapGet(id, option); -} - -int yi_BitmapLoad(const char* filename, const char* bitmap, YabInterface* yab) -{ - yab->BitmapLoad(filename, bitmap); -} - -void yi_BitmapGetIcon(const char* id, const char* option, const char* path, YabInterface* yab) -{ - yab->BitmapGetIcon(id, option, path); -} - -void yi_BitmapDrag(const char* bitmap,YabInterface* yab) -{ - yab->BitmapDrag(bitmap); -} - -void yi_BitmapRemove(const char* bitmap,YabInterface* yab) -{ - yab->BitmapRemove(bitmap); -} - -void yi_Screenshot(double x1, double y1, double x2, double y2, const char* bitmap, YabInterface *yab) -{ - return yab->Screenshot(BRect(x1,y1,x2,y2), bitmap); -} - -int yi_BitmapSave(const char* id, const char* filename, const char* type, YabInterface* yab) -{ - return yab->BitmapSave(id, filename, type); //, type); -} - -void yi_Canvas(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface *yab) -{ - yab->Canvas(BRect(x1,y1,x2,y2), id,view); -} - -int yi_Sound(const char* filename, YabInterface* yab) //Reactivate Sound Lorglas 2020.01.02 -{ - return yab->Sound(filename); -} - -int yi_SoundStop(int id, YabInterface* yab) //Reactivate Sound Lorglas 2020.01.02 -{ - return yab->SoundStop(id); -} - -int yi_SoundWait(int id, YabInterface* yab) //Reactivate Sound Lorglas 2020.01.03 -{ - return yab->SoundWait(id); -} - -int yi_MediaSound(const char* filename, YabInterface* yab) -{ - return yab->MediaSound(filename); -} - -int yi_MediaSoundStop(int id,YabInterface* yab) -{ - return yab->MediaSoundStop(id); -} -/* -void yi_MediaSoundWait(int id, YabInterface* yab) -{ - yab->MediaSoundWait(id); -} -*/ -void yi_ShortCut(const char* view, const char* key, const char* msg, YabInterface *yab) -{ - yab->ShortCut(view,key,msg); -} - -int yi_IsComputerOn(YabInterface *yab) -{ - return yab->IsComputerOn(); -} - -void yi_DrawSet4(const char* option, const char* color,const char* view, YabInterface* yab) -{ - yab->DrawSet(option, color, view); -} - -void yi_Treebox13(const char* id,const char* option, int pos, YabInterface* yab) -{ - yab->Treebox13(id, option, pos); -} - -int yi_TreeboxGetOpt(const char* id, const char* option, int pos, YabInterface* yab) -{ - return yab->TreeboxGetOpt(id, option, pos); -} - -int yi_ListboxGetNum(const char* id, YabInterface* yab) -{ - return yab->ListboxGetNum(id); -} - -int yi_DropboxGetNum(const char* id, YabInterface* yab) -{ - return yab->DropboxGetNum(id); -} - -int yi_TreeboxGetNum(const char* id, YabInterface* yab) -{ - return yab->TreeboxGetNum(id); -} - -int yi_ColumnboxGetNum(const char* id, YabInterface* yab) -{ - return yab->ColumnboxGetNum(id); -} - -int yi_DrawGet4(double x, double y, const char* option, const char* view, YabInterface* yab) -{ - return yab->DrawGet(BPoint(x,y),option,view); -} - -void yi_MouseSet(const char* opt, YabInterface *yab) -{ - yab->MouseSet(opt); -} - -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) -{ - yab->StatusBar(BRect(x1, y1, x2, y2), id, label1, label2, view); -} - -void yi_StatusBarSet(const char* id, const char* label1, const char* label2, double state, YabInterface *yab) -{ - yab->StatusBarSet(id, label1, label2, state); -} - -void yi_StatusBarSet2(double x1, double y1, double x2, double y2, const char* id, const char* view, YabInterface *yab) -{ - yab->StatusBarSet(BRect(x1, y1, x2, y2), id, view); -} - -void yi_StatusBarSet3(const char* id, int r, int g, int b, YabInterface *yab) -{ - yab->StatusBarSet(id, r, g, b); -} - -void yi_Launch(const char* strg, YabInterface *yab) -{ - yab->Launch(strg); -} - -void yi_Attribute1(const char* type, const char* name, const char* value, const char* filename, YabInterface* yab) -{ - yab->Attribute1(type, name, value, filename); -} - -void yi_AttributeClear(const char* name, const char* filename, YabInterface* yab) -{ - yab->AttributeClear(name, filename); -} - -const char* yi_AttributeGet1(const char* name, const char* filename, YabInterface* yab) -{ - return yab->AttributeGet1(name, filename); -} - -double yi_AttributeGet2(const char* name, const char* filename, YabInterface* yab) -{ - return yab->AttributeGet2(name, filename); -} diff --git a/src/YabInterface.h b/src/YabInterface.h deleted file mode 100644 index 073706a..0000000 --- a/src/YabInterface.h +++ /dev/null @@ -1,534 +0,0 @@ -#ifndef YABINTERFACE_H -#define YABINTERFACE_H - -#ifdef __cplusplus - #include - #include - #include - #include - #include - #include - #include - #include - #include "YabList.h" - #include "global.h" - #include "config.h" - #include - 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 ToolTipsNew(const char* view, const char* text, const char* color, int r, int g, int b); - 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); - int SoundStop(int32 id); - int SoundWait(int32 id); - int MediaSound(const char* filename); - int MediaSoundStop(int32 finished); - 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: - BFileGameSound* fPlayer; - int status; - 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); - void CleanupYabTabView(BView* view); - void CleanupSubchildView(BView* view); - - 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_ToolTipNew(const char* view, const char* text, const char* color, int r, int g, int b, 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 int yi_SoundStop(int id, YabInterface* yab); -extern int yi_SoundWait(int id, YabInterface* yab); -extern int yi_MediaSound(const char* filename, YabInterface* yab); -extern int yi_MediaSoundStop(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*/ diff --git a/src/YabList.cpp b/src/YabList.cpp deleted file mode 100644 index 4216175..0000000 --- a/src/YabList.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include "YabList.h" -#include - -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; iCountItems(); 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*)(addr_t)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)(addr_t)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; iCountItems(); i++) - printf("\t View %s and the id %d %d \n", ((BString*)(idList->ItemAt(i)))->String() , idList->ItemAt(i), viewList->ItemAt(i)); - printf("\n"); -} diff --git a/src/YabList.h b/src/YabList.h deleted file mode 100644 index e56cf76..0000000 --- a/src/YabList.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef YABLIST_H -#define YABLIST_H - -#include -#include - -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 diff --git a/src/YabMain.cpp b/src/YabMain.cpp deleted file mode 100644 index a5fc934..0000000 --- a/src/YabMain.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#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; iRun(); - ret = yabInterface->GetErrorCode(); - delete yabInterface; - return ret; -} diff --git a/src/YabMenu.h b/src/YabMenu.h deleted file mode 100644 index 0bdc0d3..0000000 --- a/src/YabMenu.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef YABMENU_H -#define YABMENU_H - -class YabMenu : public BMenu -{ -public: - YabMenu(const char* name) : BMenu(name) - { - } - - void MyHide() - { - Hide(); - } -}; - -#endif diff --git a/src/YabStackView.cpp b/src/YabStackView.cpp deleted file mode 100644 index 6a1f36c..0000000 --- a/src/YabStackView.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// #include -#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; -} - diff --git a/src/YabStackView.h b/src/YabStackView.h deleted file mode 100644 index 531d293..0000000 --- a/src/YabStackView.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef YAB_STACKVIEW_H_ -#define YAB_STACKVIEW_H_ - -#include - -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 diff --git a/src/YabTabView.cpp b/src/YabTabView.cpp deleted file mode 100644 index 06a5a0d..0000000 --- a/src/YabTabView.cpp +++ /dev/null @@ -1,219 +0,0 @@ -//------------------------------------------------------------------------------ -// 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) -// Modified by Kacper Kasper (kacperkasper@gmail.com) -// 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 -#include -#include -#include -#include -#include "YabTabView.h" - - -YabTabView::YabTabView(BRect frame, const char* name, button_width width, uint32 resizingMode, uint32 flags) - : BTabView(frame, name, width, resizingMode, flags) -{ - fTabNames = new BList; - - FocusChanged = 1; - OldTabView = 1; -} - -YabTabView::~YabTabView() -{ - for(int i=0; iRemoveItem(i); - } - - delete fTabNames; -} - -void YabTabView::AddTab(BView *tabView, const char* label) -{ - if(tabView) - { - BTab *tab = new BTab(); - BTabView::AddTab(tabView, tab); - tab->SetLabel(label); - // HACK - // YAB assumes all views have a window, but that's not true for tabs - if(CountTabs() > 1) - AddChild(tabView); - tabView->Hide(); - - fTabNames->AddItem(new BString(label)); - - } -} - - -void YabTabView::Select(int32 index) -{ - if (index < 0 || index >= CountTabs()) - index = Selection(); - - BTab* tab = TabAt(index); - if (tab) - { - FocusChanged = index+1; - } - - // HACK - // YAB assumes all views have a window, but that's not true for tabs - int32 prevSelected = Selection(); - RemoveChild(tab->View()); - tab->View()->Show(); - BTabView::Select(index); - if(prevSelected > -1) { - BTab* prevTab = TabAt(prevSelected); - prevTab->View()->Hide(); - AddChild(prevTab->View()); - } - -} - -void YabTabView::MakeFocus(bool focused) -{ - BView::MakeFocus(focused); - - SetFocusTab(Selection(), focused); -} - -void YabTabView::SetFocusTab(int32 tab, bool focused) -{ - FocusChanged = (FocusTab() != tab) ? 1 : 0; - - BTabView::SetFocusTab(tab, focused); -} - -void YabTabView::RemovingTab(int32 index) -{ - BTabView::RemoveTab(index); -} -/* -void YabTabView::RemovingTab(int32 index, bool focused) -{ - int oldindex=index; - int index_a; - int tab; - if (index < 0 || index >= CountTabs()) - return NULL; - BTab* tab = (BTab*)fTabNames->RemoveItem(index); - if (tab==NULL) - return NULL; - - tab->Deselect(); - BTab::Private(tab).SetTabView(Null); - if (fContainerView->GetLayout()) - fContainerView->GetLayout()->RemoveItem(index); - if (CountTabs()==0) - fFocus = -1; - else if (index <= fSelection) - Select (fSelection-1); - if (fFocus >=0) { - if(fFocus == CountTabs() -1 || CountTabs() == 0) - BTabView::Select(f.Focus, false); - else - BTabView::Select(f.Focus, true); - } - return tab; - BTabView::RemoveTab(oldindex); - BTabView::Select(1); - - - BTab* tab = TabAt(index); - if (tab) - { - FocusChanged = index; - } - - int32 prevSelected = 1; //Selection(); - RemoveChild(tab->View()); - tab->View()->Show(); - BTabView::Select(index); - if(prevSelected > -1) { - BTab* prevTab = TabAt(prevSelected); //prevSelected); - prevTab->View()->Hide(); - AddChild(prevTab->View()); - } -} - */ - - -const char* YabTabView::GetTabName(int32 index) const -{ - if(index < 0 || index >= CountTabs()) - return NULL; - - return ((BString*)fTabNames->ItemAt(index))->String(); -} -void YabTabView::PrintOut() -{ - //printf("\n %d",fTabNames->CountItems()); - if (fTabNames->CountItems()==0) - { - } - else if(fTabNames->CountItems()>0) - { - printf("\n"); - for(int i=0; iCountItems(); i++) - printf("\t View %s and the id %d\n", ((BString*)(fTabNames->ItemAt(i)))->String() , fTabNames->ItemAt(i)); - printf("\n"); - } -} -void YabTabView::FindTabName(const char* tabname ) -{ - BString test = NULL; - //printf("\n %d",fTabNames->CountItems()); - if (fTabNames->CountItems()<=0) - { - //return NULL; - } - else if(fTabNames->CountItems()>0) - { - //printf("%s \n", tabname); - for(int i=0; iCountItems(); i++) - { - printf("%s\n", ((BString*)(fTabNames->ItemAt(i)))->String()); - test=((BString*)(fTabNames->ItemAt(i)))->String(); - - if (test == tabname) - { - //printf("stimmt"); - printf("%s %d",test,i ); - printf("\n"); - //return tabname; - //return true; - } - } - //printf("\n"); - } -} - diff --git a/src/YabTabView.h b/src/YabTabView.h deleted file mode 100644 index 89cfe58..0000000 --- a/src/YabTabView.h +++ /dev/null @@ -1,73 +0,0 @@ -//------------------------------------------------------------------------------ -// 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) -// Kacper Kasper (kacperkasper@gmail.com) -// Description: YabTabView provides the framework for containing and -// managing groups of BView objects. -//------------------------------------------------------------------------------ - -#ifndef YABTAB_VIEW_H -#define YABTAB_VIEW_H - -// Standard Includes ----------------------------------------------------------- - -#include - -// YabTabView class ------------------------------------------------------------------ -class YabTabView : public BTabView -{ -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 const char* GetTabName(int32 index) const; - -virtual void AddTab(BView *target, const char* tabname); -virtual void Select(int32 index); -virtual void MakeFocus(bool focused = true); -virtual void RemovingTab(int32 index); -virtual void SetFocusTab(int32 tab, bool focused); - void PrintOut(); - void FindTabName(const char* tabname); - int32 FocusChanged; - int32 OldTabView; - -//void MoveTab(int32 index, int32 newIndex); -private: - BList *fTabNames; - - int32 fSelection; - int32 fInitialSelection; - int32 fFocus; - - -}; -//------------------------------------------------------------------------------ - -#endif diff --git a/src/YabText.cpp b/src/YabText.cpp deleted file mode 100644 index 20a245c..0000000 --- a/src/YabText.cpp +++ /dev/null @@ -1,920 +0,0 @@ -#include -#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 sols; - std::vector eols; - FillSolEol(sols,eols,0,TextLength()-1); - - for(int i=0;i= sols[i] && offset <= eols[i]) - return i; - } - return -1; -} - -void YabText::FillSolEol(std::vector& s,std::vector& 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 CountLines()) index = CountLines(); - -// if(index < 0 || index > CountLines() || TextLength() <= 0) -// return; - - std::vector eols; - std::vector sols; - - FillSolEol(sols,eols,0,TextLength()-1); - Select(sols[index],eols[index]); -}*/ - -int32 YabText::CountLines() -{ - std::vector eols; - std::vector 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 eols; - std::vector sols; - FillSolEol(sols,eols,start,finish); - - int i; - int size; - /* - if(!IsInteractive) - { - size = text_length; - std::vector colorVec(size,textcolor); - - for(i=0;i offsets; - offsets.push_back(0); - - for(i=1;icount = offset_size; - for(i=0;iruns[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 colorVec(size,textcolor); - - for(int k=0;k 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& colorVec)//,std::vector& 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= 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& colorVec) -{ - int i; - for(i=sol;i='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=0) - { - if(ByteAt(myOffset) == ' ' || ByteAt(myOffset) == '\n' || ByteAt(myOffset) == '\t') - break; - myOffset --; - } - - if(offset-myOffset>number_of_letters) - { - for(int i=myOffset+1; iItemAt(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& v,BString s) -{ - for(int i=0;iwhat) - { - 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; -} diff --git a/src/YabText.h b/src/YabText.h deleted file mode 100644 index 97effac..0000000 --- a/src/YabText.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef YABTEXT_H -#define YABTEXT_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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& s,std::vector& 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& colorVec); // TODO! - void ICheckWordLists(int sol,int eol,std::vector& 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& 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 green_matches; - std::vector purple_matches; - std::vector generic_matches; - std::vector comment_matches; - std::vector 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 diff --git a/src/YabToolTip.cpp b/src/YabToolTip.cpp deleted file mode 100644 index d1b9523..0000000 --- a/src/YabToolTip.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. - * Distributed under the terms of the MIT License. - */ - - -// #include -#include -#include - -#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; -} - diff --git a/src/YabView.cpp b/src/YabView.cpp deleted file mode 100644 index cb3393e..0000000 --- a/src/YabView.cpp +++ /dev/null @@ -1,341 +0,0 @@ -#include -#include -#include -#include -#include -#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); - - // BTab uses view Name() as displayed label storage, so SetLabel changes it - // this interferes with yab method of referencing views by name - // to be removed - nameWAForTabView = name; -} - -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(); - SetDrawingMode(B_OP_OVER); - for(int i=0; iCountItems(); 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_OVER); - else - SetDrawingMode(B_OP_ALPHA); - SetHighColor(e->r,e->g,e->b,e->alpha); - } - break; - case 7: { - if(e->alpha == 255) - SetDrawingMode(B_OP_OVER); - 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_OVER); - 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_OVER); - 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); -} - diff --git a/src/YabView.h b/src/YabView.h deleted file mode 100644 index 9b40028..0000000 --- a/src/YabView.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef YABVIEW_H -#define YABVIEW_H - -#include -#include - -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); - const char* NameForTabView() { return nameWAForTabView; } - BList *drawList; - int mouseMovedInfo; - int mouseStateInfo; - int mouseX; - int mouseY; - uint mouseLButton; - uint mouseMButton; - uint mouseRButton; - bool dropZone; - BString pressedKeys; - private: - int prevMouseStateInfo; - // TODO: revisit at a later time, more info in constructor - BString nameWAForTabView; -}; - -#endif diff --git a/src/YabWindow.cpp b/src/YabWindow.cpp deleted file mode 100644 index 8e839be..0000000 --- a/src/YabWindow.cpp +++ /dev/null @@ -1,362 +0,0 @@ -#include "global.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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; -} - diff --git a/src/YabWindow.h b/src/YabWindow.h deleted file mode 100644 index cb1c360..0000000 --- a/src/YabWindow.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef YABWINDOW_H -#define YABWINDOW_H - -#include -#include -#include -#include -#include -#include - -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 diff --git a/src/column/ColorTools.cpp b/src/column/ColorTools.cpp deleted file mode 100644 index e4aea31..0000000 --- a/src/column/ColorTools.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* -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 diff --git a/src/column/ColorTools.h b/src/column/ColorTools.h deleted file mode 100644 index 884d856..0000000 --- a/src/column/ColorTools.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -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 - -#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 diff --git a/src/column/ColumnListView.cpp b/src/column/ColumnListView.cpp deleted file mode 100644 index 2b997ce..0000000 --- a/src/column/ColumnListView.cpp +++ /dev/null @@ -1,4887 +0,0 @@ -/* -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.cpp -/ -/ Description: Experimental multi-column list view. -/ -/ Copyright 2000+, Be Incorporated, All Rights Reserved -/ By Jeff Bush -/ -*******************************************************************************/ - -#include "ColumnListView.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ColorTools.h" -#include "ObjectList.h" - -#define DOUBLE_BUFFERED_COLUMN_RESIZE 1 -#define SMART_REDRAW 1 -#define DRAG_TITLE_OUTLINE 1 -#define CONSTRAIN_CLIPPING_REGION 1 -#define LOWER_SCROLLBAR 0 - -namespace BPrivate { - -static const unsigned char kResizeCursorData[] = { - 16, 1, 8, 8, - 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, - 0x1a, 0x58, 0x2a, 0x54, 0x4a, 0x52, 0x8a, 0x51, - 0x8a, 0x51, 0x4a, 0x52, 0x2a, 0x54, 0x1a, 0x58, - 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, - - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, - 0x1b, 0xd8, 0x3b, 0xdc, 0x7b, 0xde, 0xfb, 0xdf, - 0xfb, 0xdf, 0x7b, 0xde, 0x3b, 0xdc, 0x1b, 0xd8, - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 -}; - -static const unsigned char kMaxResizeCursorData[] = { - 16, 1, 8, 8, - 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, - 0x1a, 0x40, 0x2a, 0x40, 0x4a, 0x40, 0x8a, 0x40, - 0x8a, 0x40, 0x4a, 0x40, 0x2a, 0x40, 0x1a, 0x40, - 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, - - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, - 0x1b, 0xc0, 0x3b, 0xc0, 0x7b, 0xc0, 0xfb, 0xc0, - 0xfb, 0xc0, 0x7b, 0xc0, 0x3b, 0xc0, 0x1b, 0xc0, - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 -}; - -static const unsigned char kMinResizeCursorData[] = { - 16, 1, 8, 8, - 0x03, 0xc0, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, - 0x02, 0x58, 0x02, 0x54, 0x02, 0x52, 0x02, 0x51, - 0x02, 0x51, 0x02, 0x52, 0x02, 0x54, 0x02, 0x58, - 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xc0, - - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, - 0x03, 0xd8, 0x03, 0xdc, 0x03, 0xde, 0x03, 0xdf, - 0x03, 0xdf, 0x03, 0xde, 0x03, 0xdc, 0x03, 0xd8, - 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0 -}; - -static const unsigned char kColumnMoveCursorData[] = { - 16, 1, 8, 8, - 0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x08, 0x10, - 0x1e, 0x78, 0x2a, 0x54, 0x4e, 0x72, 0x80, 0x01, - 0x80, 0x01, 0x4e, 0x72, 0x2a, 0x54, 0x1e, 0x78, - 0x08, 0x10, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80, - - 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, - 0x1f, 0xf8, 0x3b, 0xdc, 0x7f, 0xfe, 0xff, 0xff, - 0xff, 0xff, 0x7f, 0xfe, 0x3b, 0xdc, 0x1f, 0xf8, - 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80 -}; - -static const unsigned char kDownSortArrow8x8[] = { - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff -}; - -static const unsigned char kUpSortArrow8x8[] = { - 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff -}; - -static const unsigned char kDownSortArrow8x8Invert[] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff -}; - -static const unsigned char kUpSortArrow8x8Invert[] = { - 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff -}; - -static const float kTintedLineTint = 0.7 * B_NO_TINT + 0.3 * B_DARKEN_1_TINT; - -static const float kTitleHeight = 16.0; -static const float kLatchWidth = 0.0; //5.0; - - -static const rgb_color kColor[B_COLOR_TOTAL] = -{ - {236, 236, 236, 255}, // B_COLOR_BACKGROUND - { 0, 0, 0, 255}, // B_COLOR_TEXT - {148, 148, 148, 255}, // B_COLOR_ROW_DIVIDER - {190, 190, 190, 255}, // B_COLOR_SELECTION - { 0, 0, 0, 255}, // B_COLOR_SELECTION_TEXT - {200, 200, 200, 255}, // B_COLOR_NON_FOCUS_SELECTION - {180, 180, 180, 180}, // B_COLOR_EDIT_BACKGROUND - { 0, 0, 0, 255}, // B_COLOR_EDIT_TEXT - {215, 215, 215, 255}, // B_COLOR_HEADER_BACKGROUND - { 0, 0, 0, 255}, // B_COLOR_HEADER_TEXT - { 0, 0, 0, 255}, // B_COLOR_SEPARATOR_LINE - { 0, 0, 0, 255}, // B_COLOR_SEPARATOR_BORDER -}; - -static const int32 kMaxDepth = 1024; -static const float kLeftMargin = kLatchWidth; -static const float kRightMargin = kLatchWidth; -static const float kOutlineLevelIndent = kLatchWidth; -static const float kColumnResizeAreaWidth = 10.0; -static const float kRowDragSensitivity = 5.0; -static const float kDoubleClickMoveSensitivity = 4.0; -static const float kSortIndicatorWidth = 9.0; -static const float kDropHighlightLineHeight = 2.0; - -static const uint32 kToggleColumn = 'BTCL'; - -class BRowContainer : public BObjectList -{ -}; - -class TitleView : public BView { - typedef BView _inherited; -public: - TitleView(BRect frame, OutlineView* outlineView, - BList* visibleColumns, BList* sortColumns, - BColumnListView* masterView, - uint32 resizingMode); - virtual ~TitleView(); - - void ColumnAdded(BColumn* column); - void ColumnResized(BColumn* column, float oldWidth); - void SetColumnVisible(BColumn* column, bool visible); - - virtual void Draw(BRect updateRect); - virtual void ScrollTo(BPoint where); - virtual void MessageReceived(BMessage* message); - virtual void MouseDown(BPoint where); - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage); - virtual void MouseUp(BPoint where); - virtual void FrameResized(float width, float height); - - void MoveColumn(BColumn* column, int32 index); - void SetColumnFlags(column_flags flags); - - void SetEditMode(bool state) - { fEditMode = state; } - -private: - void GetTitleRect(BColumn* column, BRect* _rect); - int32 FindColumn(BPoint where, float* _leftEdge); - void FixScrollBar(bool scrollToFit); - void DragSelectedColumn(BPoint where); - void ResizeSelectedColumn(BPoint where, - bool preferred = false); - void ComputeDragBoundries(BColumn* column, - BPoint where); - void DrawTitle(BView* view, BRect frame, - BColumn* column, bool depressed); - - float _VirtualWidth() const; - - OutlineView* fOutlineView; - BList* fColumns; - BList* fSortColumns; -// float fColumnsWidth; - BRect fVisibleRect; - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - BBitmap* fDrawBuffer; - BView* fDrawBufferView; -#endif - - enum { - INACTIVE, - RESIZING_COLUMN, - PRESSING_COLUMN, - DRAG_COLUMN_INSIDE_TITLE, - DRAG_COLUMN_OUTSIDE_TITLE - } fCurrentState; - - BPopUpMenu* fColumnPop; - BColumnListView* fMasterView; - bool fEditMode; - int32 fColumnFlags; - - // State information for resizing/dragging - BColumn* fSelectedColumn; - BRect fSelectedColumnRect; - bool fResizingFirstColumn; - BPoint fClickPoint; // offset within cell - float fLeftDragBoundry; - float fRightDragBoundry; - BPoint fCurrentDragPosition; - - - BBitmap* fUpSortArrow; - BBitmap* fDownSortArrow; - - BCursor* fResizeCursor; - BCursor* fMinResizeCursor; - BCursor* fMaxResizeCursor; - BCursor* fColumnMoveCursor; -}; - -class OutlineView : public BView { - typedef BView _inherited; -public: - OutlineView(BRect, BList* visibleColumns, - BList* sortColumns, - BColumnListView* listView); - virtual ~OutlineView(); - - virtual void Draw(BRect); - const BRect& VisibleRect() const; - - void RedrawColumn(BColumn* column, float leftEdge, - bool isFirstColumn); - void StartSorting(); - float GetColumnPreferredWidth(BColumn* column); - - void AddRow(BRow*, int32 index, BRow* TheRow); - BRow* CurrentSelection(BRow* lastSelected) const; - void ToggleFocusRowSelection(bool selectRange); - void ToggleFocusRowOpen(); - void ChangeFocusRow(bool up, bool updateSelection, - bool addToCurrentSelection); - void MoveFocusToVisibleRect(); - void ExpandOrCollapse(BRow* parent, bool expand); - void RemoveRow(BRow*); - BRowContainer* RowList(); - void UpdateRow(BRow*); - bool FindParent(BRow* row, BRow** _parent, - bool* _isVisible); - int32 IndexOf(BRow* row); - void Deselect(BRow*); - void AddToSelection(BRow*); - void DeselectAll(); - BRow* FocusRow() const; - void SetFocusRow(BRow* row, bool select); - BRow* FindRow(float ypos, int32* _indent, - float* _top); - bool FindRect(const BRow* row, BRect* _rect); - void ScrollTo(const BRow* row); - - void Clear(); - void SetSelectionMode(list_view_type type); - list_view_type SelectionMode() const; - void SetMouseTrackingEnabled(bool); - void FixScrollBar(bool scrollToFit); - void SetEditMode(bool state) - { fEditMode = state; } - - virtual void FrameResized(float width, float height); - virtual void ScrollTo(BPoint where); - virtual void MouseDown(BPoint where); - virtual void MouseMoved(BPoint where, uint32 transit, - const BMessage* dragMessage); - virtual void MouseUp(BPoint where); - virtual void MessageReceived(BMessage* message); - -private: - bool SortList(BRowContainer* list, bool isVisible); - static int32 DeepSortThreadEntry(void* outlineView); - void DeepSort(); - void SelectRange(BRow* start, BRow* end); - int32 CompareRows(BRow* row1, BRow* row2); - void AddSorted(BRowContainer* list, BRow* row); - void RecursiveDeleteRows(BRowContainer* list, - bool owner); - void InvalidateCachedPositions(); - bool FindVisibleRect(BRow* row, BRect* _rect); - - BList* fColumns; - BList* fSortColumns; - float fItemsHeight; - BRowContainer fRows; - BRect fVisibleRect; - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - BBitmap* fDrawBuffer; - BView* fDrawBufferView; -#endif - - BRow* fFocusRow; - BRect fFocusRowRect; - BRow* fRollOverRow; - - BRow fSelectionListDummyHead; - BRow* fLastSelectedItem; - BRow* fFirstSelectedItem; - - thread_id fSortThread; - int32 fNumSorted; - bool fSortCancelled; - - enum CurrentState { - INACTIVE, - LATCH_CLICKED, - ROW_CLICKED, - DRAGGING_ROWS - }; - - CurrentState fCurrentState; - - - BColumnListView* fMasterView; - list_view_type fSelectionMode; - bool fTrackMouse; - BField* fCurrentField; - BRow* fCurrentRow; - BColumn* fCurrentColumn; - bool fMouseDown; - BRect fFieldRect; - int32 fCurrentCode; - bool fEditMode; - - // State information for mouse/keyboard interaction - BPoint fClickPoint; - bool fDragging; - int32 fClickCount; - BRow* fTargetRow; - float fTargetRowTop; - BRect fLatchRect; - float fDropHighlightY; - - friend class RecursiveOutlineIterator; -}; - -class RecursiveOutlineIterator { -public: - RecursiveOutlineIterator( - BRowContainer* container, - bool openBranchesOnly = true); - - BRow* CurrentRow() const; - int32 CurrentLevel() const; - void GoToNext(); - -private: - struct { - BRowContainer* fRowSet; - int32 fIndex; - int32 fDepth; - } fStack[kMaxDepth]; - - int32 fStackIndex; - BRowContainer* fCurrentList; - int32 fCurrentListIndex; - int32 fCurrentListDepth; - bool fOpenBranchesOnly; -}; - -} // namespace BPrivate - - -using namespace BPrivate; - - -BField::BField() -{ -} - - -BField::~BField() -{ -} - - -// #pragma mark - - - -void -BColumn::MouseMoved(BColumnListView* /*parent*/, BRow* /*row*/, - BField* /*field*/, BRect /*field_rect*/, BPoint/*point*/, - uint32 /*buttons*/, int32 /*code*/) -{ -} - - -void -BColumn::MouseDown(BColumnListView* /*parent*/, BRow* /*row*/, - BField* /*field*/, BRect /*field_rect*/, BPoint /*point*/, - uint32 /*buttons*/) -{ -} - - -void -BColumn::MouseUp(BColumnListView* /*parent*/, BRow* /*row*/, BField* /*field*/) -{ -} - - -// #pragma mark - - - -BRow::BRow(float height) - : - fChildList(NULL), - fIsExpanded(false), - fHeight(height), - fNextSelected(NULL), - fPrevSelected(NULL), - fParent(NULL), - fList(NULL) -{ -} - - -BRow::~BRow() -{ - while (true) { - BField* field = (BField*) fFields.RemoveItem((int32)0); - if (field == 0) - break; - - delete field; - } -} - - -bool -BRow::HasLatch() const -{ - return fChildList != 0; -} - - -int32 -BRow::CountFields() const -{ - return fFields.CountItems(); -} - - -BField* -BRow::GetField(int32 index) -{ - return (BField*)fFields.ItemAt(index); -} - - -const BField* -BRow::GetField(int32 index) const -{ - return (const BField*)fFields.ItemAt(index); -} - - -void -BRow::SetField(BField* field, int32 logicalFieldIndex) -{ - if (fFields.ItemAt(logicalFieldIndex) != 0) - delete (BField*)fFields.RemoveItem(logicalFieldIndex); - - if (NULL != fList) { - ValidateField(field, logicalFieldIndex); - BRect inv; - fList->GetRowRect(this, &inv); - fList->Invalidate(inv); - } - - fFields.AddItem(field, logicalFieldIndex); -} - - -float -BRow::Height() const -{ - return fHeight; -} - - -bool -BRow::IsExpanded() const -{ - return fIsExpanded; -} - - -void -BRow::ValidateFields() const -{ - for (int32 i = 0; i < CountFields(); i++) - ValidateField(GetField(i), i); -} - - -void -BRow::ValidateField(const BField* field, int32 logicalFieldIndex) const -{ - // The Fields may be moved by the user, but the logicalFieldIndexes - // do not change, so we need to map them over when checking the - // Field types. - BColumn* col = NULL; - int32 items = fList->CountColumns(); - for (int32 i = 0 ; i < items; ++i) { - col = fList->ColumnAt(i); - if( col->LogicalFieldNum() == logicalFieldIndex ) - break; - } - - if (NULL == col) { - BString dbmessage("\n\n\tThe parent BColumnListView does not have " - "\n\ta BColumn at the logical field index "); - dbmessage << logicalFieldIndex << ".\n\n"; - printf(dbmessage.String()); - } else { - if (!col->AcceptsField(field)) { - BString dbmessage("\n\n\tThe BColumn of type "); - dbmessage << typeid(*col).name() << "\n\tat logical field index " - << logicalFieldIndex << "\n\tdoes not support the " - "field type " - << typeid(*field).name() << ".\n\n"; - debugger(dbmessage.String()); - } - } -} - - -// #pragma mark - - - -BColumn::BColumn(float width, float minWidth, float maxWidth, alignment align) - : - fWidth(width), - fMinWidth(minWidth), - fMaxWidth(maxWidth), - fVisible(true), - fList(0), - fShowHeading(true), - fAlignment(align) -{ -} - - -BColumn::~BColumn() -{ -} - - -float -BColumn::Width() const -{ - return fWidth; -} - - -void -BColumn::SetWidth(float width) -{ - fWidth = width; -} - - -float -BColumn::MinWidth() const -{ - return fMinWidth; -} - - -float -BColumn::MaxWidth() const -{ - return fMaxWidth; -} - - -void -BColumn::DrawTitle(BRect, BView*) -{ -} - - -void -BColumn::DrawField(BField*, BRect, BView*) -{ -} - - -int -BColumn::CompareFields(BField*, BField*) -{ - return 0; -} - - -void -BColumn::GetColumnName(BString* into) const -{ - *into = "(Unnamed)"; -} - - -float -BColumn::GetPreferredWidth(BField* field, BView* parent) const -{ - return fWidth; -} - - -bool -BColumn::IsVisible() const -{ - return fVisible; -} - - -void -BColumn::SetVisible(bool visible) -{ - if (fList && (fVisible != visible)) - fList->SetColumnVisible(this, visible); -} - - -bool -BColumn::ShowHeading() const -{ - return fShowHeading; -} - - -void -BColumn::SetShowHeading(bool state) -{ - fShowHeading = state; -} - - -alignment -BColumn::Alignment() const -{ - return fAlignment; -} - - -void -BColumn::SetAlignment(alignment align) -{ - fAlignment = align; -} - - -bool -BColumn::WantsEvents() const -{ - return fWantsEvents; -} - - -void -BColumn::SetWantsEvents(bool state) -{ - fWantsEvents = state; -} - - -int32 -BColumn::LogicalFieldNum() const -{ - return fFieldID; -} - - -bool -BColumn::AcceptsField(const BField*) const -{ - return true; -} - - -// #pragma mark - - - -BColumnListView::BColumnListView(BRect rect, const char* name, - uint32 resizingMode, uint32 flags, border_style border, - bool showHorizontalScrollbar) - : - BView(rect, name, resizingMode, - flags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), - fStatusView(NULL), - fSelectionMessage(NULL), - fSortingEnabled(true), - fLatchWidth(kLatchWidth), - fBorderStyle(border) -{ - _Init(showHorizontalScrollbar); -} - - -BColumnListView::BColumnListView(const char* name, uint32 flags, - border_style border, bool showHorizontalScrollbar) - : - BView(name, flags | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), - fStatusView(NULL), - fSelectionMessage(NULL), - fSortingEnabled(true), - fLatchWidth(kLatchWidth), - fBorderStyle(border) -{ - _Init(showHorizontalScrollbar); -} - - -BColumnListView::~BColumnListView() -{ - while (BColumn* column = (BColumn*)fColumns.RemoveItem((int32)0)) - delete column; -} - - -bool -BColumnListView::InitiateDrag(BPoint, bool) -{ - return false; -} - - -void -BColumnListView::MessageDropped(BMessage*, BPoint) -{ -} - - -void -BColumnListView::ExpandOrCollapse(BRow* row, bool Open) -{ - fOutlineView->ExpandOrCollapse(row, Open); -} - - -status_t -BColumnListView::Invoke(BMessage* message) -{ - if (message == 0) - message = Message(); - - return BInvoker::Invoke(message); -} - - -void -BColumnListView::ItemInvoked() -{ - Invoke(); -} - - -void -BColumnListView::SetInvocationMessage(BMessage* message) -{ - SetMessage(message); -} - - -BMessage* -BColumnListView::InvocationMessage() const -{ - return Message(); -} - - -uint32 -BColumnListView::InvocationCommand() const -{ - return Command(); -} - - -BRow* -BColumnListView::FocusRow() const -{ - return fOutlineView->FocusRow(); -} - - -void -BColumnListView::SetFocusRow(int32 Index, bool Select) -{ - SetFocusRow(RowAt(Index), Select); -} - - -void -BColumnListView::SetFocusRow(BRow* row, bool Select) -{ - fOutlineView->SetFocusRow(row, Select); -} - - -void -BColumnListView::SetMouseTrackingEnabled(bool Enabled) -{ - fOutlineView->SetMouseTrackingEnabled(Enabled); -} - - -list_view_type -BColumnListView::SelectionMode() const -{ - return fOutlineView->SelectionMode(); -} - - -void -BColumnListView::Deselect(BRow* row) -{ - fOutlineView->Deselect(row); -} - - -void -BColumnListView::AddToSelection(BRow* row) -{ - fOutlineView->AddToSelection(row); -} - - -void -BColumnListView::DeselectAll() -{ - fOutlineView->DeselectAll(); -} - - -BRow* -BColumnListView::CurrentSelection(BRow* lastSelected) const -{ - return fOutlineView->CurrentSelection(lastSelected); -} - - -void -BColumnListView::SelectionChanged() -{ - if (fSelectionMessage) - Invoke(fSelectionMessage); -} - - -void -BColumnListView::SetSelectionMessage(BMessage* message) -{ - if (fSelectionMessage == message) - return; - - delete fSelectionMessage; - fSelectionMessage = message; -} - - -BMessage* -BColumnListView::SelectionMessage() -{ - return fSelectionMessage; -} - - -uint32 -BColumnListView::SelectionCommand() const -{ - if (fSelectionMessage) - return fSelectionMessage->what; - - return 0; -} - - -void -BColumnListView::SetSelectionMode(list_view_type mode) -{ - fOutlineView->SetSelectionMode(mode); -} - - -void -BColumnListView::SetSortingEnabled(bool enabled) -{ - fSortingEnabled = enabled; - fSortColumns.MakeEmpty(); - fTitleView->Invalidate(); // Erase sort indicators -} - - -bool -BColumnListView::SortingEnabled() const -{ - return fSortingEnabled; -} - - -void -BColumnListView::SetSortColumn(BColumn* column, bool add, bool ascending) -{ - if (!SortingEnabled()) - return; - - if (!add) - fSortColumns.MakeEmpty(); - - if (!fSortColumns.HasItem(column)) - fSortColumns.AddItem(column); - - column->fSortAscending = ascending; - fTitleView->Invalidate(); - fOutlineView->StartSorting(); -} - - -void -BColumnListView::ClearSortColumns() -{ - fSortColumns.MakeEmpty(); - fTitleView->Invalidate(); // Erase sort indicators -} - - -void -BColumnListView::AddStatusView(BView* view) -{ - BRect bounds = Bounds(); - float width = view->Bounds().Width(); - if (width > bounds.Width() / 2) - width = bounds.Width() / 2; - - fStatusView = view; - - Window()->BeginViewTransaction(); - fHorizontalScrollBar->ResizeBy(-(width + 1), 0); - fHorizontalScrollBar->MoveBy((width + 1), 0); - AddChild(view); - - BRect viewRect(bounds); - viewRect.right = width; - viewRect.top = viewRect.bottom - B_H_SCROLL_BAR_HEIGHT; - if (fBorderStyle == B_PLAIN_BORDER) - viewRect.OffsetBy(1, -1); - else if (fBorderStyle == B_FANCY_BORDER) - viewRect.OffsetBy(2, -2); - - view->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - view->ResizeTo(viewRect.Width(), viewRect.Height()); - view->MoveTo(viewRect.left, viewRect.top); - Window()->EndViewTransaction(); -} - - -BView* -BColumnListView::RemoveStatusView() -{ - if (fStatusView) { - float width = fStatusView->Bounds().Width(); - Window()->BeginViewTransaction(); - fStatusView->RemoveSelf(); - fHorizontalScrollBar->MoveBy(-width, 0); - fHorizontalScrollBar->ResizeBy(width, 0); - Window()->EndViewTransaction(); - } - - BView* view = fStatusView; - fStatusView = 0; - return view; -} - - -void -BColumnListView::AddColumn(BColumn* column, int32 logicalFieldIndex) -{ - ASSERT(column != NULL); - - column->fList = this; - column->fFieldID = logicalFieldIndex; - - // sanity check. If there is already a field with this ID, remove it. - for (int32 index = 0; index < fColumns.CountItems(); index++) { - BColumn* existingColumn = (BColumn*) fColumns.ItemAt(index); - if (existingColumn && existingColumn->fFieldID == logicalFieldIndex) { - RemoveColumn(existingColumn); - break; - } - } - - if (column->Width() < column->MinWidth()) - column->SetWidth(column->MinWidth()); - else if (column->Width() > column->MaxWidth()) - column->SetWidth(column->MaxWidth()); - - fColumns.AddItem((void*) column); - fTitleView->ColumnAdded(column); -} - - -void -BColumnListView::MoveColumn(BColumn* column, int32 index) -{ - ASSERT(column != NULL); - fTitleView->MoveColumn(column, index); -} - - -void -BColumnListView::RemoveColumn(BColumn* column) -{ - if (fColumns.HasItem(column)) { - SetColumnVisible(column, false); - if (Window() != NULL) - Window()->UpdateIfNeeded(); - fColumns.RemoveItem(column); - } -} - - -int32 -BColumnListView::CountColumns() const -{ - return fColumns.CountItems(); -} - - -BColumn* -BColumnListView::ColumnAt(int32 field) const -{ - return (BColumn*) fColumns.ItemAt(field); -} - - -BColumn* -BColumnListView::ColumnAt(BPoint point) const -{ - float left = MAX(kLeftMargin, LatchWidth()); - - for (int i = 0; BColumn* column = (BColumn*)fColumns.ItemAt(i); i++) { - if (!column->IsVisible()) - continue; - - float right = left + column->Width(); - if (point.x >= left && point.x <= right) - return column; - - left = right + 1; - } - - return NULL; -} - - -void -BColumnListView::SetColumnVisible(BColumn* column, bool visible) -{ - fTitleView->SetColumnVisible(column, visible); -} - - -void -BColumnListView::SetColumnVisible(int32 index, bool isVisible) -{ - BColumn* column = ColumnAt(index); - if (column) - column->SetVisible(isVisible); -} - - -bool -BColumnListView::IsColumnVisible(int32 index) const -{ - BColumn* column = ColumnAt(index); - if (column) - return column->IsVisible(); - - return false; -} - - -void -BColumnListView::SetColumnFlags(column_flags flags) -{ - fTitleView->SetColumnFlags(flags); -} - - -void -BColumnListView::ResizeColumnToPreferred(int32 index) -{ - BColumn* column = ColumnAt(index); - if (column == NULL) - return; - - // get the preferred column width - float width = fOutlineView->GetColumnPreferredWidth(column); - - // set it - float oldWidth = column->Width(); - column->SetWidth(width); - - fTitleView->ColumnResized(column, oldWidth); - fOutlineView->Invalidate(); -} - - -void -BColumnListView::ResizeAllColumnsToPreferred() -{ - int32 count = CountColumns(); - for (int32 i = 0; i < count; i++) - ResizeColumnToPreferred(i); -} - - -const BRow* -BColumnListView::RowAt(int32 Index, BRow* parentRow) const -{ - if (parentRow == 0) - return fOutlineView->RowList()->ItemAt(Index); - - return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : NULL; -} - - -BRow* -BColumnListView::RowAt(int32 Index, BRow* parentRow) -{ - if (parentRow == 0) - return fOutlineView->RowList()->ItemAt(Index); - - return parentRow->fChildList ? parentRow->fChildList->ItemAt(Index) : 0; -} - - -const BRow* -BColumnListView::RowAt(BPoint point) const -{ - float top; - int32 indent; - return fOutlineView->FindRow(point.y, &indent, &top); -} - - -BRow* -BColumnListView::RowAt(BPoint point) -{ - float top; - int32 indent; - return fOutlineView->FindRow(point.y, &indent, &top); -} - - -bool -BColumnListView::GetRowRect(const BRow* row, BRect* outRect) const -{ - return fOutlineView->FindRect(row, outRect); -} - - -bool -BColumnListView::FindParent(BRow* row, BRow** _parent, bool* _isVisible) const -{ - return fOutlineView->FindParent(row, _parent, _isVisible); -} - - -int32 -BColumnListView::IndexOf(BRow* row) -{ - return fOutlineView->IndexOf(row); -} - - -int32 -BColumnListView::CountRows(BRow* parentRow) const -{ - if (parentRow == 0) - return fOutlineView->RowList()->CountItems(); - if (parentRow->fChildList) - return parentRow->fChildList->CountItems(); - else - return 0; -} - - -void -BColumnListView::AddRow(BRow* row, BRow* parentRow) -{ - AddRow(row, -1, parentRow); -} - - -void -BColumnListView::AddRow(BRow* row, int32 index, BRow* parentRow) -{ - row->fChildList = 0; - row->fList = this; - row->ValidateFields(); - fOutlineView->AddRow(row, index, parentRow); -} - - -void -BColumnListView::RemoveRow(BRow* row) -{ - fOutlineView->RemoveRow(row); - row->fList = NULL; -} - - -void -BColumnListView::UpdateRow(BRow* row) -{ - fOutlineView->UpdateRow(row); -} - - -void -BColumnListView::ScrollTo(const BRow* row) -{ - fOutlineView->ScrollTo(row); -} - - -void -BColumnListView::ScrollTo(BPoint point) -{ - fOutlineView->ScrollTo(point); -} - - -void -BColumnListView::Clear() -{ - fOutlineView->Clear(); -} - - -void -BColumnListView::SetFont(const BFont* font, uint32 mask) -{ - // This method is deprecated. - fOutlineView->SetFont(font, mask); - fTitleView->SetFont(font, mask); -} - - -void -BColumnListView::SetFont(ColumnListViewFont font_num, const BFont* font, - uint32 mask) -{ - switch (font_num) { - case B_FONT_ROW: - fOutlineView->SetFont(font, mask); - break; - - case B_FONT_HEADER: - fTitleView->SetFont(font, mask); - break; - - default: - ASSERT(false); - break; - } -} - - -void -BColumnListView::GetFont(ColumnListViewFont font_num, BFont* font) const -{ - switch (font_num) { - case B_FONT_ROW: - fOutlineView->GetFont(font); - break; - - case B_FONT_HEADER: - fTitleView->GetFont(font); - break; - - default: - ASSERT(false); - break; - } -} - - -void -BColumnListView::SetColor(ColumnListViewColor color_num, const rgb_color color) -{ - if ((int)color_num < 0) { - ASSERT(false); - color_num = (ColumnListViewColor) 0; - } - - if ((int)color_num >= (int)B_COLOR_TOTAL) { - ASSERT(false); - color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); - } - - fColorList[color_num] = color; -} - - -rgb_color -BColumnListView::Color(ColumnListViewColor color_num) const -{ - if ((int)color_num < 0) { - ASSERT(false); - color_num = (ColumnListViewColor) 0; - } - - if ((int)color_num >= (int)B_COLOR_TOTAL) { - ASSERT(false); - color_num = (ColumnListViewColor) (B_COLOR_TOTAL - 1); - } - - return fColorList[color_num]; -} - - -void -BColumnListView::SetHighColor(rgb_color color) -{ - BView::SetHighColor(color); -// fOutlineView->Invalidate(); // Redraw things with the new color - // Note that this will currently cause - // an infinite loop, refreshing over and over. - // A better solution is needed. -} - - -void -BColumnListView::SetSelectionColor(rgb_color color) -{ - fColorList[B_COLOR_SELECTION] = color; -} - - -void -BColumnListView::SetBackgroundColor(rgb_color color) -{ - fColorList[B_COLOR_BACKGROUND] = color; - fOutlineView->Invalidate(); // Repaint with new color -} - - -void -BColumnListView::SetEditColor(rgb_color color) -{ - fColorList[B_COLOR_EDIT_BACKGROUND] = color; -} - - -const rgb_color -BColumnListView::SelectionColor() const -{ - return fColorList[B_COLOR_SELECTION]; -} - - -const rgb_color -BColumnListView::BackgroundColor() const -{ - return fColorList[B_COLOR_BACKGROUND]; -} - - -const rgb_color -BColumnListView::EditColor() const -{ - return fColorList[B_COLOR_EDIT_BACKGROUND]; -} - - -BPoint -BColumnListView::SuggestTextPosition(const BRow* row, - const BColumn* inColumn) const -{ - BRect rect; - GetRowRect(row, &rect); - if (inColumn) { - float leftEdge = MAX(kLeftMargin, LatchWidth()); - for (int index = 0; index < fColumns.CountItems(); index++) { - BColumn* column = (BColumn*) fColumns.ItemAt(index); - if (!column->IsVisible()) - continue; - - if (column == inColumn) { - rect.left = leftEdge; - rect.right = rect.left + column->Width(); - break; - } - - leftEdge += column->Width() + 1; - } - } - - font_height fh; - fOutlineView->GetFontHeight(&fh); - float baseline = floor(rect.top + fh.ascent - + (rect.Height()+1-(fh.ascent+fh.descent))/2); - return BPoint(rect.left + 8, baseline); -} - - -void -BColumnListView::SetLatchWidth(float width) -{ - fLatchWidth = width; - Invalidate(); -} - - -float -BColumnListView::LatchWidth() const -{ - return fLatchWidth; -} - -void -BColumnListView::DrawLatch(BView* view, BRect rect, LatchType position, BRow*) -{ - const int32 rectInset = 4; - - view->SetHighColor(0, 0, 0); - - // Make Square - int32 sideLen = rect.IntegerWidth(); - if (sideLen > rect.IntegerHeight()) - sideLen = rect.IntegerHeight(); - - // Make Center - int32 halfWidth = rect.IntegerWidth() / 2; - int32 halfHeight = rect.IntegerHeight() / 2; - int32 halfSide = sideLen / 2; - - float left = rect.left + halfWidth - halfSide; - float top = rect.top + halfHeight - halfSide; - - BRect itemRect(left, top, left + sideLen, top + sideLen); - - // Why it is a pixel high? I don't know. - itemRect.OffsetBy(0, -1); - - itemRect.InsetBy(rectInset, rectInset); - - // Make it an odd number of pixels wide, the latch looks better this way - if ((itemRect.IntegerWidth() % 2) == 1) { - itemRect.right += 1; - itemRect.bottom += 1; - } - - switch (position) { - case B_OPEN_LATCH: - view->StrokeRect(itemRect); - view->StrokeLine( - BPoint(itemRect.left + 2, - (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, - (itemRect.top + itemRect.bottom) / 2)); - break; - - case B_PRESSED_LATCH: - view->StrokeRect(itemRect); - view->StrokeLine( - BPoint(itemRect.left + 2, - (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, - (itemRect.top + itemRect.bottom) / 2)); - view->StrokeLine( - BPoint((itemRect.left + itemRect.right) / 2, - itemRect.top + 2), - BPoint((itemRect.left + itemRect.right) / 2, - itemRect.bottom - 2)); - view->InvertRect(itemRect); - break; - - case B_CLOSED_LATCH: - view->StrokeRect(itemRect); - view->StrokeLine( - BPoint(itemRect.left + 2, - (itemRect.top + itemRect.bottom) / 2), - BPoint(itemRect.right - 2, - (itemRect.top + itemRect.bottom) / 2)); - view->StrokeLine( - BPoint((itemRect.left + itemRect.right) / 2, - itemRect.top + 2), - BPoint((itemRect.left + itemRect.right) / 2, - itemRect.bottom - 2)); - break; - - case B_NO_LATCH: - // No drawing - break; - } -} - - -void -BColumnListView::MakeFocus(bool isFocus) -{ - if (fBorderStyle != B_NO_BORDER) { - // Redraw focus marks around view - Invalidate(); - fHorizontalScrollBar->SetBorderHighlighted(isFocus); - fVerticalScrollBar->SetBorderHighlighted(isFocus); - } - - BView::MakeFocus(isFocus); -} - - -void -BColumnListView::MessageReceived(BMessage* message) -{ - // Propagate mouse wheel messages down to child, so that it can - // scroll. Note we have done so, so we don't go into infinite - // recursion if this comes back up here. - if (message->what == B_MOUSE_WHEEL_CHANGED) { - bool handled; - if (message->FindBool("be:clvhandled", &handled) != B_OK) { - message->AddBool("be:clvhandled", true); - fOutlineView->MessageReceived(message); - return; - } - } - - BView::MessageReceived(message); -} - - -void -BColumnListView::KeyDown(const char* bytes, int32 numBytes) -{ - char c = bytes[0]; - switch (c) { - case B_RIGHT_ARROW: - case B_LEFT_ARROW: - { - float minVal, maxVal; - fHorizontalScrollBar->GetRange(&minVal, &maxVal); - float smallStep, largeStep; - fHorizontalScrollBar->GetSteps(&smallStep, &largeStep); - float oldVal = fHorizontalScrollBar->Value(); - float newVal = oldVal; - - if (c == B_LEFT_ARROW) - newVal -= smallStep; - else if (c == B_RIGHT_ARROW) - newVal += smallStep; - - if (newVal < minVal) - newVal = minVal; - else if (newVal > maxVal) - newVal = maxVal; - - fHorizontalScrollBar->SetValue(newVal); - break; - } - - case B_DOWN_ARROW: - fOutlineView->ChangeFocusRow(false, - (modifiers() & B_CONTROL_KEY) == 0, - (modifiers() & B_SHIFT_KEY) != 0); - break; - - case B_UP_ARROW: - fOutlineView->ChangeFocusRow(true, - (modifiers() & B_CONTROL_KEY) == 0, - (modifiers() & B_SHIFT_KEY) != 0); - break; - - case B_PAGE_UP: - case B_PAGE_DOWN: - { - float minValue, maxValue; - fVerticalScrollBar->GetRange(&minValue, &maxValue); - float smallStep, largeStep; - fVerticalScrollBar->GetSteps(&smallStep, &largeStep); - float currentValue = fVerticalScrollBar->Value(); - float newValue = currentValue; - - if (c == B_PAGE_UP) - newValue -= largeStep; - else - newValue += largeStep; - - if (newValue > maxValue) - newValue = maxValue; - else if (newValue < minValue) - newValue = minValue; - - fVerticalScrollBar->SetValue(newValue); - - // Option + pgup or pgdn scrolls and changes the selection. - if (modifiers() & B_OPTION_KEY) - fOutlineView->MoveFocusToVisibleRect(); - - break; - } - - case B_ENTER: - Invoke(); - break; - - case B_SPACE: - fOutlineView->ToggleFocusRowSelection( - (modifiers() & B_SHIFT_KEY) != 0); - break; - - case '+': - fOutlineView->ToggleFocusRowOpen(); - break; - - default: - BView::KeyDown(bytes, numBytes); - } -} - - -void -BColumnListView::AttachedToWindow() -{ - if (!Messenger().IsValid()) - SetTarget(Window()); - - if (SortingEnabled()) fOutlineView->StartSorting(); -} - - -void -BColumnListView::WindowActivated(bool active) -{ - fOutlineView->Invalidate(); - // Focus and selection appearance changes with focus - - Invalidate(); // Redraw focus marks around view - BView::WindowActivated(active); -} - - -void -BColumnListView::Draw(BRect updateRect) -{ - BRect rect = Bounds(); - - if (be_control_look != NULL) { - uint32 flags = 0; - if (IsFocus() && Window()->IsActive()) - flags |= BControlLook::B_FOCUSED; - - rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); - - BRect verticalScrollBarFrame; - if (!fVerticalScrollBar->IsHidden()) - verticalScrollBarFrame = fVerticalScrollBar->Frame(); - BRect horizontalScrollBarFrame; - if (!fHorizontalScrollBar->IsHidden()) - horizontalScrollBarFrame = fHorizontalScrollBar->Frame(); - - if (fBorderStyle == B_NO_BORDER) { - // We still draw the left/top border, but not focused. - // The scrollbars cannot be displayed without frame and - // it looks bad to have no frame only along the left/top - // side. - rgb_color borderColor = tint_color(base, B_DARKEN_2_TINT); - SetHighColor(borderColor); - StrokeLine(BPoint(rect.left, rect.bottom), - BPoint(rect.left, rect.top)); - StrokeLine(BPoint(rect.left + 1, rect.top), - BPoint(rect.right, rect.top)); - } - - be_control_look->DrawScrollViewFrame(this, rect, updateRect, - verticalScrollBarFrame, horizontalScrollBarFrame, - base, fBorderStyle, flags); - - return; - } - - BRect cornerRect(rect.right - B_V_SCROLL_BAR_WIDTH, - rect.bottom - B_H_SCROLL_BAR_HEIGHT, rect.right, rect.bottom); - if (fBorderStyle == B_PLAIN_BORDER) { - BView::SetHighColor(0, 0, 0); - StrokeRect(rect); - cornerRect.OffsetBy(-1, -1); - } else if (fBorderStyle == B_FANCY_BORDER) { - bool isFocus = IsFocus() && Window()->IsActive(); - - if (isFocus) { - // TODO: Need to find focus color programatically - BView::SetHighColor(0, 0, 190); - } else - BView::SetHighColor(255, 255, 255); - - StrokeRect(rect); - if (!isFocus) - BView::SetHighColor(184, 184, 184); - else - BView::SetHighColor(152, 152, 152); - - rect.InsetBy(1,1); - StrokeRect(rect); - cornerRect.OffsetBy(-2, -2); - } - - BView::SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - // fills lower right rect between scroll bars - FillRect(cornerRect); -} - - -void -BColumnListView::SaveState(BMessage* msg) -{ - msg->MakeEmpty(); - - for (int32 i = 0; BColumn* col = (BColumn*)fColumns.ItemAt(i); i++) { - msg->AddInt32("ID",col->fFieldID); - msg->AddFloat("width", col->fWidth); - msg->AddBool("visible", col->fVisible); - } - - msg->AddBool("sortingenabled", fSortingEnabled); - - if (fSortingEnabled) { - for (int32 i = 0; BColumn* col = (BColumn*)fSortColumns.ItemAt(i); - i++) { - msg->AddInt32("sortID", col->fFieldID); - msg->AddBool("sortascending", col->fSortAscending); - } - } -} - - -void -BColumnListView::LoadState(BMessage* msg) -{ - int32 id; - for (int i = 0; msg->FindInt32("ID", i, &id) == B_OK; i++) { - for (int j = 0; BColumn* column = (BColumn*)fColumns.ItemAt(j); j++) { - if (column->fFieldID == id) { - // move this column to position 'i' and set its attributes - MoveColumn(column, i); - float width; - if (msg->FindFloat("width", i, &width) == B_OK) - column->SetWidth(width); - bool visible; - if (msg->FindBool("visible", i, &visible) == B_OK) - column->SetVisible(visible); - } - } - } - bool b; - if (msg->FindBool("sortingenabled", &b) == B_OK) { - SetSortingEnabled(b); - for (int k = 0; msg->FindInt32("sortID", k, &id) == B_OK; k++) { - for (int j = 0; BColumn* column = (BColumn*)fColumns.ItemAt(j); - j++) { - if (column->fFieldID == id) { - // add this column to the sort list - bool value; - if (msg->FindBool("sortascending", k, &value) == B_OK) - SetSortColumn(column, true, value); - } - } - } - } -} - - -void -BColumnListView::SetEditMode(bool state) -{ - fOutlineView->SetEditMode(state); - fTitleView->SetEditMode(state); -} - - -void -BColumnListView::Refresh() -{ - if (LockLooper()) { - Invalidate(); - fOutlineView->FixScrollBar (true); - fOutlineView->Invalidate(); - Window()->UpdateIfNeeded(); - UnlockLooper(); - } -} - - -BSize -BColumnListView::MinSize() -{ - BSize size; - size.width = 100; - size.height = kTitleHeight + 4 * B_H_SCROLL_BAR_HEIGHT; - if (!fHorizontalScrollBar->IsHidden()) - size.height += fHorizontalScrollBar->Frame().Height() + 1; - // TODO: Take border size into account - - return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); -} - - -BSize -BColumnListView::PreferredSize() -{ - BSize size = MinSize(); - size.height += ceilf(be_plain_font->Size()) * 20; - - int32 count = CountColumns(); - if (count > 0) { - // return MinSize().width if there are no columns. - size.width = 40.0f; - for (int32 i = 0; i < count; i++) { - BColumn* column = ColumnAt(i); - if (column != NULL) - size.width += fOutlineView->GetColumnPreferredWidth(column); - } - } - - return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size); -} - - -BSize -BColumnListView::MaxSize() -{ - BSize size(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); - return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); -} - - -void -BColumnListView::InvalidateLayout(bool descendants) -{ - BView::InvalidateLayout(descendants); -} - - -void -BColumnListView::DoLayout() -{ - if (!(Flags() & B_SUPPORTS_LAYOUT)) - return; - - BRect titleRect; - BRect outlineRect; - BRect vScrollBarRect; - BRect hScrollBarRect; - _GetChildViewRects(Bounds(), !fHorizontalScrollBar->IsHidden(), - titleRect, outlineRect, vScrollBarRect, hScrollBarRect); - - fTitleView->MoveTo(titleRect.LeftTop()); - fTitleView->ResizeTo(titleRect.Width(), titleRect.Height()); - - fOutlineView->MoveTo(outlineRect.LeftTop()); - fOutlineView->ResizeTo(outlineRect.Width(), outlineRect.Height()); - - fVerticalScrollBar->MoveTo(vScrollBarRect.LeftTop()); - fVerticalScrollBar->ResizeTo(vScrollBarRect.Width(), - vScrollBarRect.Height()); - - fHorizontalScrollBar->MoveTo(hScrollBarRect.LeftTop()); - fHorizontalScrollBar->ResizeTo(hScrollBarRect.Width(), - hScrollBarRect.Height()); - - fOutlineView->FixScrollBar(true); -} - - -void -BColumnListView::_Init(bool showHorizontalScrollbar) -{ - SetViewColor(B_TRANSPARENT_32_BIT); - - BRect bounds(Bounds()); - if (bounds.Width() <= 0) - bounds.right = 100; - if (bounds.Height() <= 0) - bounds.bottom = 100; - - for (int i = 0; i < (int)B_COLOR_TOTAL; i++) - fColorList[i] = kColor[i]; - - BRect titleRect; - BRect outlineRect; - BRect vScrollBarRect; - BRect hScrollBarRect; - _GetChildViewRects(bounds, showHorizontalScrollbar, titleRect, outlineRect, - vScrollBarRect, hScrollBarRect); - - fOutlineView = new OutlineView(outlineRect, &fColumns, &fSortColumns, this); - AddChild(fOutlineView); - - - fTitleView = new TitleView(titleRect, fOutlineView, &fColumns, - &fSortColumns, this, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); - AddChild(fTitleView); - - fVerticalScrollBar = new BScrollBar(vScrollBarRect, "vertical_scroll_bar", - fOutlineView, 0.0, bounds.Height(), B_VERTICAL); - AddChild(fVerticalScrollBar); - - fHorizontalScrollBar = new BScrollBar(hScrollBarRect, - "horizontal_scroll_bar", fTitleView, 0.0, bounds.Width(), B_HORIZONTAL); - AddChild(fHorizontalScrollBar); - - if (!showHorizontalScrollbar) - fHorizontalScrollBar->Hide(); - - fOutlineView->FixScrollBar(true); -} - - -void -BColumnListView::_GetChildViewRects(const BRect& bounds, - bool showHorizontalScrollbar, BRect& titleRect, BRect& outlineRect, - BRect& vScrollBarRect, BRect& hScrollBarRect) -{ - titleRect = bounds; - titleRect.bottom = titleRect.top + kTitleHeight; -#if !LOWER_SCROLLBAR - titleRect.right -= B_V_SCROLL_BAR_WIDTH; -#endif - - outlineRect = bounds; - outlineRect.top = titleRect.bottom + 1.0; - outlineRect.right -= B_V_SCROLL_BAR_WIDTH; - if (showHorizontalScrollbar) - outlineRect.bottom -= B_H_SCROLL_BAR_HEIGHT; - - vScrollBarRect = bounds; -#if LOWER_SCROLLBAR - vScrollBarRect.top += kTitleHeight; -#endif - - vScrollBarRect.left = vScrollBarRect.right - B_V_SCROLL_BAR_WIDTH; - if (showHorizontalScrollbar) - vScrollBarRect.bottom -= B_H_SCROLL_BAR_HEIGHT; - - hScrollBarRect = bounds; - hScrollBarRect.top = hScrollBarRect.bottom - B_H_SCROLL_BAR_HEIGHT; - hScrollBarRect.right -= B_V_SCROLL_BAR_WIDTH; - - // Adjust stuff so the border will fit. - if (fBorderStyle == B_PLAIN_BORDER || fBorderStyle == B_NO_BORDER) { - titleRect.InsetBy(1, 0); - titleRect.OffsetBy(0, 1); - outlineRect.InsetBy(1, 1); - } else if (fBorderStyle == B_FANCY_BORDER) { - titleRect.InsetBy(2, 0); - titleRect.OffsetBy(0, 2); - outlineRect.InsetBy(2, 2); - - vScrollBarRect.OffsetBy(-1, 0); -#if LOWER_SCROLLBAR - vScrollBarRect.top += 2; - vScrollBarRect.bottom -= 1; -#else - vScrollBarRect.InsetBy(0, 1); -#endif - hScrollBarRect.OffsetBy(0, -1); - hScrollBarRect.InsetBy(1, 0); - } -} - - -// #pragma mark - - - -TitleView::TitleView(BRect rect, OutlineView* horizontalSlave, - BList* visibleColumns, BList* sortColumns, BColumnListView* listView, - uint32 resizingMode) - : - BView(rect, "title_view", resizingMode, B_WILL_DRAW | B_FRAME_EVENTS), - fOutlineView(horizontalSlave), - fColumns(visibleColumns), - fSortColumns(sortColumns), -// fColumnsWidth(0), - fVisibleRect(rect.OffsetToCopy(0, 0)), - fCurrentState(INACTIVE), - fColumnPop(NULL), - fMasterView(listView), - fEditMode(false), - fColumnFlags(B_ALLOW_COLUMN_MOVE | B_ALLOW_COLUMN_RESIZE - | B_ALLOW_COLUMN_POPUP | B_ALLOW_COLUMN_REMOVE) -{ - SetViewColor(B_TRANSPARENT_COLOR); - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - // xxx this needs to be smart about the size of the backbuffer. - BRect doubleBufferRect(0, 0, 600, 35); - fDrawBuffer = new BBitmap(doubleBufferRect, B_RGB32, true); - fDrawBufferView = new BView(doubleBufferRect, "double_buffer_view", - B_FOLLOW_ALL_SIDES, 0); - fDrawBuffer->Lock(); - fDrawBuffer->AddChild(fDrawBufferView); - fDrawBuffer->Unlock(); -#endif - - fUpSortArrow = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8); - fDownSortArrow = new BBitmap(BRect(0, 0, 7, 7), B_CMAP8); - - fUpSortArrow->SetBits((const void*) kUpSortArrow8x8, 64, 0, B_CMAP8); - fDownSortArrow->SetBits((const void*) kDownSortArrow8x8, 64, 0, B_CMAP8); - - fResizeCursor = new BCursor(kResizeCursorData); - fMinResizeCursor = new BCursor(kMinResizeCursorData); - fMaxResizeCursor = new BCursor(kMaxResizeCursorData); - fColumnMoveCursor = new BCursor(kColumnMoveCursorData); - - FixScrollBar(true); -} - - -TitleView::~TitleView() -{ - delete fColumnPop; - fColumnPop = NULL; - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - delete fDrawBuffer; -#endif - delete fUpSortArrow; - delete fDownSortArrow; - - delete fResizeCursor; - delete fMaxResizeCursor; - delete fMinResizeCursor; - delete fColumnMoveCursor; -} - - -void -TitleView::ColumnAdded(BColumn* column) -{ -// fColumnsWidth += column->Width(); - FixScrollBar(false); - Invalidate(); -} - - -void -TitleView::ColumnResized(BColumn* column, float oldWidth) -{ -// fColumnsWidth += column->Width() - oldWidth; - FixScrollBar(false); - Invalidate(); -} - - -void -TitleView::SetColumnVisible(BColumn* column, bool visible) -{ - if (column->fVisible == visible) - return; - - // If setting it visible, do this first so we can find its position - // to invalidate. If hiding it, do it last. - if (visible) - column->fVisible = visible; - - BRect titleInvalid; - GetTitleRect(column, &titleInvalid); - - // Now really set the visibility - column->fVisible = visible; - -// if (visible) -// fColumnsWidth += column->Width(); -// else -// fColumnsWidth -= column->Width(); - - BRect outlineInvalid(fOutlineView->VisibleRect()); - outlineInvalid.left = titleInvalid.left; - titleInvalid.right = outlineInvalid.right; - - Invalidate(titleInvalid); - fOutlineView->Invalidate(outlineInvalid); -} - - -void -TitleView::GetTitleRect(BColumn* findColumn, BRect* _rect) -{ - float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - int32 numColumns = fColumns->CountItems(); - for (int index = 0; index < numColumns; index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column->IsVisible()) - continue; - - if (column == findColumn) { - _rect->Set(leftEdge, 0, leftEdge + column->Width(), - fVisibleRect.bottom); - return; - } - - leftEdge += column->Width() + 1; - } - - TRESPASS(); -} - - -int32 -TitleView::FindColumn(BPoint position, float* _leftEdge) -{ - float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - int32 numColumns = fColumns->CountItems(); - for (int index = 0; index < numColumns; index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column->IsVisible()) - continue; - - if (leftEdge > position.x) - break; - - if (position.x >= leftEdge - && position.x <= leftEdge + column->Width()) { - *_leftEdge = leftEdge; - return index; - } - - leftEdge += column->Width() + 1; - } - - return 0; -} - - -void -TitleView::FixScrollBar(bool scrollToFit) -{ - BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); - if (hScrollBar == NULL) - return; - - float virtualWidth = _VirtualWidth(); - - if (virtualWidth > fVisibleRect.Width()) { - hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth); - - // Perform the little trick if the user is scrolled over too far. - // See OutlineView::FixScrollBar for a more in depth explanation - float maxScrollBarValue = virtualWidth - fVisibleRect.Width(); - if (scrollToFit || hScrollBar->Value() <= maxScrollBarValue) { - hScrollBar->SetRange(0.0, maxScrollBarValue); - hScrollBar->SetSteps(50, fVisibleRect.Width()); - } - } else if (hScrollBar->Value() == 0.0) { - // disable scroll bar. - hScrollBar->SetRange(0.0, 0.0); - } -} - - -void -TitleView::DragSelectedColumn(BPoint position) -{ - float invalidLeft = fSelectedColumnRect.left; - float invalidRight = fSelectedColumnRect.right; - - float leftEdge; - int32 columnIndex = FindColumn(position, &leftEdge); - fSelectedColumnRect.OffsetTo(leftEdge, 0); - - MoveColumn(fSelectedColumn, columnIndex); - - fSelectedColumn->fVisible = true; - ComputeDragBoundries(fSelectedColumn, position); - - // Redraw the new column position - GetTitleRect(fSelectedColumn, &fSelectedColumnRect); - invalidLeft = MIN(fSelectedColumnRect.left, invalidLeft); - invalidRight = MAX(fSelectedColumnRect.right, invalidRight); - - Invalidate(BRect(invalidLeft, 0, invalidRight, fVisibleRect.bottom)); - fOutlineView->Invalidate(BRect(invalidLeft, 0, invalidRight, - fOutlineView->VisibleRect().bottom)); - - DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); -} - - -void -TitleView::MoveColumn(BColumn* column, int32 index) -{ - fColumns->RemoveItem((void*) column); - - if (-1 == index) { - // Re-add the column at the end of the list. - fColumns->AddItem((void*) column); - } else { - fColumns->AddItem((void*) column, index); - } -} - - -void -TitleView::SetColumnFlags(column_flags flags) -{ - fColumnFlags = flags; -} - - -void -TitleView::ResizeSelectedColumn(BPoint position, bool preferred) -{ - float minWidth = fSelectedColumn->MinWidth(); - float maxWidth = fSelectedColumn->MaxWidth(); - - float oldWidth = fSelectedColumn->Width(); - float originalEdge = fSelectedColumnRect.left + oldWidth; - if (preferred) { - float width = fOutlineView->GetColumnPreferredWidth(fSelectedColumn); - fSelectedColumn->SetWidth(width); - } else if (position.x > fSelectedColumnRect.left + maxWidth) - fSelectedColumn->SetWidth(maxWidth); - else if (position.x < fSelectedColumnRect.left + minWidth) - fSelectedColumn->SetWidth(minWidth); - else - fSelectedColumn->SetWidth(position.x - fSelectedColumnRect.left - 1); - - float dX = fSelectedColumnRect.left + fSelectedColumn->Width() - - originalEdge; - if (dX != 0) { - float columnHeight = fVisibleRect.Height(); - BRect originalRect(originalEdge, 0, 1000000.0, columnHeight); - BRect movedRect(originalRect); - movedRect.OffsetBy(dX, 0); - - // Update the size of the title column - BRect sourceRect(0, 0, fSelectedColumn->Width(), columnHeight); - BRect destRect(sourceRect); - destRect.OffsetBy(fSelectedColumnRect.left, 0); - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - fDrawBuffer->Lock(); - DrawTitle(fDrawBufferView, sourceRect, fSelectedColumn, false); - fDrawBufferView->Sync(); - fDrawBuffer->Unlock(); - - CopyBits(originalRect, movedRect); - DrawBitmap(fDrawBuffer, sourceRect, destRect); -#else - CopyBits(originalRect, movedRect); - DrawTitle(this, destRect, fSelectedColumn, false); -#endif - - // Update the body view - BRect slaveSize = fOutlineView->VisibleRect(); - BRect slaveSource(originalRect); - slaveSource.bottom = slaveSize.bottom; - BRect slaveDest(movedRect); - slaveDest.bottom = slaveSize.bottom; - fOutlineView->CopyBits(slaveSource, slaveDest); - fOutlineView->RedrawColumn(fSelectedColumn, fSelectedColumnRect.left, - fResizingFirstColumn); - -// fColumnsWidth += dX; - - // Update the cursor - if (fSelectedColumn->Width() == minWidth) - SetViewCursor(fMinResizeCursor, true); - else if (fSelectedColumn->Width() == maxWidth) - SetViewCursor(fMaxResizeCursor, true); - else - SetViewCursor(fResizeCursor, true); - - ColumnResized(fSelectedColumn, oldWidth); - } -} - - -void -TitleView::ComputeDragBoundries(BColumn* findColumn, BPoint) -{ - float previousColumnLeftEdge = -1000000.0; - float nextColumnRightEdge = 1000000.0; - - bool foundColumn = false; - float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - int32 numColumns = fColumns->CountItems(); - for (int index = 0; index < numColumns; index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column->IsVisible()) - continue; - - if (column == findColumn) { - foundColumn = true; - continue; - } - - if (foundColumn) { - nextColumnRightEdge = leftEdge + column->Width(); - break; - } else - previousColumnLeftEdge = leftEdge; - - leftEdge += column->Width() + 1; - } - - float rightEdge = leftEdge + findColumn->Width(); - - fLeftDragBoundry = MIN(previousColumnLeftEdge + findColumn->Width(), - leftEdge); - fRightDragBoundry = MAX(nextColumnRightEdge, rightEdge); -} - - -void -TitleView::DrawTitle(BView* view, BRect rect, BColumn* column, bool depressed) -{ - BRect drawRect; - rgb_color borderColor = mix_color( - fMasterView->Color(B_COLOR_HEADER_BACKGROUND), - make_color(0, 0, 0), 128); - rgb_color backgroundColor; - - rgb_color bevelHigh; - rgb_color bevelLow; - // Want exterior borders to overlap. - if (be_control_look == NULL) { - rect.right += 1; - drawRect = rect; - drawRect.InsetBy(2, 2); - if (depressed) { - backgroundColor = mix_color( - fMasterView->Color(B_COLOR_HEADER_BACKGROUND), - make_color(0, 0, 0), 64); - bevelHigh = mix_color(backgroundColor, make_color(0, 0, 0), 64); - bevelLow = mix_color(backgroundColor, make_color(255, 255, 255), - 128); - drawRect.left++; - drawRect.top++; - } else { - backgroundColor = fMasterView->Color(B_COLOR_HEADER_BACKGROUND); - bevelHigh = mix_color(backgroundColor, make_color(255, 255, 255), - 192); - bevelLow = mix_color(backgroundColor, make_color(0, 0, 0), 64); - drawRect.bottom--; - drawRect.right--; - } - } else { - drawRect = rect; - } - - font_height fh; - GetFontHeight(&fh); - - float baseline = floor(drawRect.top + fh.ascent - + (drawRect.Height() + 1 - (fh.ascent + fh.descent)) / 2); - - if (be_control_look != NULL) { - BRect bgRect = rect; - - rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); - view->SetHighColor(tint_color(base, B_DARKEN_2_TINT)); - view->StrokeLine(bgRect.LeftBottom(), bgRect.RightBottom()); - - bgRect.bottom--; - bgRect.right--; - - if (depressed) - base = tint_color(base, B_DARKEN_1_TINT); - - be_control_look->DrawButtonBackground(view, bgRect, rect, base, 0, - BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER); - - view->SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_2_TINT)); - view->StrokeLine(rect.RightTop(), rect.RightBottom()); - - } else { - - view->SetHighColor(borderColor); - view->StrokeRect(rect); - view->BeginLineArray(4); - view->AddLine(BPoint(rect.left + 1, rect.top + 1), - BPoint(rect.right - 1, rect.top + 1), bevelHigh); - view->AddLine(BPoint(rect.left + 1, rect.top + 1), - BPoint(rect.left + 1, rect.bottom - 1), bevelHigh); - view->AddLine(BPoint(rect.right - 1, rect.top + 1), - BPoint(rect.right - 1, rect.bottom - 1), bevelLow); - view->AddLine(BPoint(rect.left + 2, rect.bottom-1), - BPoint(rect.right - 1, rect.bottom - 1), bevelLow); - view->EndLineArray(); - - view->SetHighColor(backgroundColor); - view->SetLowColor(backgroundColor); - - view->FillRect(rect.InsetByCopy(2, 2)); - } - - // If no column given, nothing else to draw. - if (!column) - return; - - view->SetHighColor(fMasterView->Color(B_COLOR_HEADER_TEXT)); - - BFont font; - GetFont(&font); - view->SetFont(&font); - - int sortIndex = fSortColumns->IndexOf(column); - if (sortIndex >= 0) { - // Draw sort notation. - BPoint upperLeft(drawRect.right - kSortIndicatorWidth, baseline); - - if (fSortColumns->CountItems() > 1) { - char str[256]; - sprintf(str, "%d", sortIndex + 1); - const float w = view->StringWidth(str); - upperLeft.x -= w; - - view->SetDrawingMode(B_OP_COPY); - view->MovePenTo(BPoint(upperLeft.x + kSortIndicatorWidth, - baseline)); - view->DrawString(str); - } - - float bmh = fDownSortArrow->Bounds().Height()+1; - - view->SetDrawingMode(B_OP_OVER); - - if (column->fSortAscending) { - BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() - - fDownSortArrow->Bounds().IntegerHeight()) / 2); - view->DrawBitmapAsync(fDownSortArrow, leftTop); - } else { - BPoint leftTop(upperLeft.x, drawRect.top + (drawRect.IntegerHeight() - - fUpSortArrow->Bounds().IntegerHeight()) / 2); - view->DrawBitmapAsync(fUpSortArrow, leftTop); - } - - upperLeft.y = baseline - bmh + floor((fh.ascent + fh.descent - bmh) / 2); - if (upperLeft.y < drawRect.top) - upperLeft.y = drawRect.top; - - // Adjust title stuff for sort indicator - drawRect.right = upperLeft.x - 2; - } - - if (drawRect.right > drawRect.left) { -#if CONSTRAIN_CLIPPING_REGION - BRegion clipRegion(drawRect); - view->PushState(); - view->ConstrainClippingRegion(&clipRegion); -#endif - view->MovePenTo(BPoint(drawRect.left + 8, baseline)); - view->SetDrawingMode(B_OP_OVER); - view->SetHighColor(fMasterView->Color(B_COLOR_HEADER_TEXT)); - column->DrawTitle(drawRect, view); - -#if CONSTRAIN_CLIPPING_REGION - view->PopState(); -#endif - } -} - - -float -TitleView::_VirtualWidth() const -{ - float width = 0.0f; - - int32 count = fColumns->CountItems(); - for (int32 i = 0; i < count; i++) { - BColumn* column = reinterpret_cast(fColumns->ItemAt(i)); - width += column->Width(); - } - - return width + MAX(kLeftMargin, - fMasterView->LatchWidth()) + kRightMargin * 2; -} - - -void -TitleView::Draw(BRect invalidRect) -{ - float columnLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - for (int32 columnIndex = 0; columnIndex < fColumns->CountItems(); - columnIndex++) { - - BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); - if (!column->IsVisible()) - continue; - - if (columnLeftEdge > invalidRect.right) - break; - - if (columnLeftEdge + column->Width() >= invalidRect.left) { - BRect titleRect(columnLeftEdge, 0, - columnLeftEdge + column->Width(), fVisibleRect.Height()); - DrawTitle(this, titleRect, column, - (fCurrentState == DRAG_COLUMN_INSIDE_TITLE - && fSelectedColumn == column)); - } - - columnLeftEdge += column->Width() + 1; - } - - - // Bevels for right title margin - if (columnLeftEdge <= invalidRect.right) { - BRect titleRect(columnLeftEdge, 0, Bounds().right + 2, - fVisibleRect.Height()); - DrawTitle(this, titleRect, NULL, false); - } - - // Bevels for left title margin - if (invalidRect.left < MAX(kLeftMargin, fMasterView->LatchWidth())) { - BRect titleRect(0, 0, MAX(kLeftMargin, fMasterView->LatchWidth()) - 1, - fVisibleRect.Height()); - DrawTitle(this, titleRect, NULL, false); - } - -#if DRAG_TITLE_OUTLINE - // (Internal) Column Drag Indicator - if (fCurrentState == DRAG_COLUMN_INSIDE_TITLE) { - BRect dragRect(fSelectedColumnRect); - dragRect.OffsetTo(fCurrentDragPosition.x - fClickPoint.x, 0); - if (dragRect.Intersects(invalidRect)) { - SetHighColor(0, 0, 255); - StrokeRect(dragRect); - } - } -#endif -} - - -void -TitleView::ScrollTo(BPoint position) -{ - fOutlineView->ScrollBy(position.x - fVisibleRect.left, 0); - fVisibleRect.OffsetTo(position.x, position.y); - - // Perform the little trick if the user is scrolled over too far. - // See OutlineView::ScrollTo for a more in depth explanation - float maxScrollBarValue = _VirtualWidth() - fVisibleRect.Width(); - BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); - float min, max; - hScrollBar->GetRange(&min, &max); - if (max != maxScrollBarValue && position.x > maxScrollBarValue) - FixScrollBar(true); - - _inherited::ScrollTo(position); -} - - -void -TitleView::MessageReceived(BMessage* message) -{ - if (message->what == kToggleColumn) { - int32 num; - if (message->FindInt32("be:field_num", &num) == B_OK) { - for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column) - continue; - if (column->LogicalFieldNum() == num) - column->SetVisible(!column->IsVisible()); - } - } - return; - } else { - BView::MessageReceived(message); - } -} - - -void -TitleView::MouseDown(BPoint position) -{ - if(fEditMode) - return; - - int32 buttons = 1; - Window()->CurrentMessage()->FindInt32("buttons", &buttons); - if (buttons == B_SECONDARY_MOUSE_BUTTON - && (fColumnFlags & B_ALLOW_COLUMN_POPUP)) { - // Right mouse button -- bring up menu to show/hide columns. - if (!fColumnPop) fColumnPop = new BPopUpMenu("Columns", false, false); - fColumnPop->RemoveItems(0, fColumnPop->CountItems(), true); - BMessenger me(this); - for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column) continue; - BString name; - column->GetColumnName(&name); - BMessage* msg = new BMessage(kToggleColumn); - msg->AddInt32("be:field_num", column->LogicalFieldNum()); - BMenuItem* it = new BMenuItem(name.String(), msg); - it->SetMarked(column->IsVisible()); - it->SetTarget(me); - fColumnPop->AddItem(it); - } - BPoint screenPosition = ConvertToScreen(position); - BRect sticky(screenPosition, screenPosition); - sticky.InsetBy(-5, -5); - fColumnPop->Go(ConvertToScreen(position), true, false, sticky, true); - return; - } - - fResizingFirstColumn = true; - float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column->IsVisible()) - continue; - - if (leftEdge > position.x + kColumnResizeAreaWidth / 2) - break; - - // Check for resizing a column - float rightEdge = leftEdge + column->Width(); - - if (column->ShowHeading()) { - if (position.x > rightEdge - kColumnResizeAreaWidth / 2 - && position.x < rightEdge + kColumnResizeAreaWidth / 2 - && column->MaxWidth() > column->MinWidth() - && (fColumnFlags & B_ALLOW_COLUMN_RESIZE)) { - - int32 clicks = 0; - Window()->CurrentMessage()->FindInt32("clicks", &clicks); - if (clicks == 2) { - ResizeSelectedColumn(position, true); - fCurrentState = INACTIVE; - break; - } - fCurrentState = RESIZING_COLUMN; - fSelectedColumn = column; - fSelectedColumnRect.Set(leftEdge, 0, rightEdge, - fVisibleRect.Height()); - fClickPoint = BPoint(position.x - rightEdge - 1, - position.y - fSelectedColumnRect.top); - SetMouseEventMask(B_POINTER_EVENTS, - B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); - break; - } - - fResizingFirstColumn = false; - - // Check for clicking on a column. - if (position.x > leftEdge && position.x < rightEdge) { - fCurrentState = PRESSING_COLUMN; - fSelectedColumn = column; - fSelectedColumnRect.Set(leftEdge, 0, rightEdge, - fVisibleRect.Height()); - DrawTitle(this, fSelectedColumnRect, fSelectedColumn, true); - fClickPoint = BPoint(position.x - fSelectedColumnRect.left, - position.y - fSelectedColumnRect.top); - SetMouseEventMask(B_POINTER_EVENTS, - B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); - break; - } - } - leftEdge = rightEdge + 1; - } -} - - -void -TitleView::MouseMoved(BPoint position, uint32 transit, - const BMessage* dragMessage) -{ - if (fEditMode) - return; - - // Handle column manipulation - switch (fCurrentState) { - case RESIZING_COLUMN: - ResizeSelectedColumn(position - BPoint(fClickPoint.x, 0)); - break; - - case PRESSING_COLUMN: { - if (abs((int32)(position.x - (fClickPoint.x - + fSelectedColumnRect.left))) > kColumnResizeAreaWidth - || abs((int32)(position.y - (fClickPoint.y - + fSelectedColumnRect.top))) > kColumnResizeAreaWidth) { - // User has moved the mouse more than the tolerable amount, - // initiate a drag. - if (transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW) { - if(fColumnFlags & B_ALLOW_COLUMN_MOVE) { - fCurrentState = DRAG_COLUMN_INSIDE_TITLE; - ComputeDragBoundries(fSelectedColumn, position); - SetViewCursor(fColumnMoveCursor, true); -#if DRAG_TITLE_OUTLINE - BRect invalidRect(fSelectedColumnRect); - invalidRect.OffsetTo(position.x - fClickPoint.x, 0); - fCurrentDragPosition = position; - Invalidate(invalidRect); -#endif - } - } else { - if(fColumnFlags & B_ALLOW_COLUMN_REMOVE) { - // Dragged outside view - fCurrentState = DRAG_COLUMN_OUTSIDE_TITLE; - fSelectedColumn->SetVisible(false); - BRect dragRect(fSelectedColumnRect); - - // There is a race condition where the mouse may have - // moved by the time we get to handle this message. - // If the user drags a column very quickly, this - // results in the annoying bug where the cursor is - // outside of the rectangle that is being dragged - // around. Call GetMouse with the checkQueue flag set - // to false so we can get the most recent position of - // the mouse. This minimizes this problem (although - // it is currently not possible to completely eliminate - // it). - uint32 buttons; - GetMouse(&position, &buttons, false); - dragRect.OffsetTo(position.x - fClickPoint.x, - position.y - dragRect.Height() / 2); - BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); - } - } - } - - break; - } - - case DRAG_COLUMN_INSIDE_TITLE: { - if (transit == B_EXITED_VIEW - && (fColumnFlags & B_ALLOW_COLUMN_REMOVE)) { - // Dragged outside view - fCurrentState = DRAG_COLUMN_OUTSIDE_TITLE; - fSelectedColumn->SetVisible(false); - BRect dragRect(fSelectedColumnRect); - - // See explanation above. - uint32 buttons; - GetMouse(&position, &buttons, false); - - dragRect.OffsetTo(position.x - fClickPoint.x, - position.y - fClickPoint.y); - BeginRectTracking(dragRect, B_TRACK_WHOLE_RECT); - } else if (position.x < fLeftDragBoundry - || position.x > fRightDragBoundry) { - DragSelectedColumn(position - BPoint(fClickPoint.x, 0)); - } - -#if DRAG_TITLE_OUTLINE - // Set up the invalid rect to include the rect for the previous - // position of the drag rect, as well as the new one. - BRect invalidRect(fSelectedColumnRect); - invalidRect.OffsetTo(fCurrentDragPosition.x - fClickPoint.x, 0); - if (position.x < fCurrentDragPosition.x) - invalidRect.left -= fCurrentDragPosition.x - position.x; - else - invalidRect.right += position.x - fCurrentDragPosition.x; - - fCurrentDragPosition = position; - Invalidate(invalidRect); -#endif - break; - } - - case DRAG_COLUMN_OUTSIDE_TITLE: - if (transit == B_ENTERED_VIEW) { - // Drag back into view - EndRectTracking(); - fCurrentState = DRAG_COLUMN_INSIDE_TITLE; - fSelectedColumn->SetVisible(true); - DragSelectedColumn(position - BPoint(fClickPoint.x, 0)); - } - - break; - - case INACTIVE: - // Check for cursor changes if we are over the resize area for - // a column. - BColumn* resizeColumn = 0; - float leftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - for (int index = 0; index < fColumns->CountItems(); index++) { - BColumn* column = (BColumn*) fColumns->ItemAt(index); - if (!column->IsVisible()) - continue; - - if (leftEdge > position.x + kColumnResizeAreaWidth / 2) - break; - - float rightEdge = leftEdge + column->Width(); - if (position.x > rightEdge - kColumnResizeAreaWidth / 2 - && position.x < rightEdge + kColumnResizeAreaWidth / 2 - && column->MaxWidth() > column->MinWidth()) { - resizeColumn = column; - break; - } - - leftEdge = rightEdge + 1; - } - - // Update the cursor - if (resizeColumn) { - if (resizeColumn->Width() == resizeColumn->MinWidth()) - SetViewCursor(fMinResizeCursor, true); - else if (resizeColumn->Width() == resizeColumn->MaxWidth()) - SetViewCursor(fMaxResizeCursor, true); - else - SetViewCursor(fResizeCursor, true); - } else - SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); - break; - } -} - - -void -TitleView::MouseUp(BPoint position) -{ - if (fEditMode) - return; - - switch (fCurrentState) { - case RESIZING_COLUMN: - ResizeSelectedColumn(position - BPoint(fClickPoint.x, 0)); - fCurrentState = INACTIVE; - FixScrollBar(false); - break; - - case PRESSING_COLUMN: { - if (fMasterView->SortingEnabled()) { - if (fSortColumns->HasItem(fSelectedColumn)) { - if ((modifiers() & B_CONTROL_KEY) == 0 - && fSortColumns->CountItems() > 1) { - fSortColumns->MakeEmpty(); - fSortColumns->AddItem(fSelectedColumn); - } - - fSelectedColumn->fSortAscending - = !fSelectedColumn->fSortAscending; - } else { - if ((modifiers() & B_CONTROL_KEY) == 0) - fSortColumns->MakeEmpty(); - - fSortColumns->AddItem(fSelectedColumn); - fSelectedColumn->fSortAscending = true; - } - - fOutlineView->StartSorting(); - } - - fCurrentState = INACTIVE; - Invalidate(); - break; - } - - case DRAG_COLUMN_INSIDE_TITLE: - fCurrentState = INACTIVE; - -#if DRAG_TITLE_OUTLINE - Invalidate(); // xxx Can make this smaller -#else - Invalidate(fSelectedColumnRect); -#endif - SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); - break; - - case DRAG_COLUMN_OUTSIDE_TITLE: - fCurrentState = INACTIVE; - EndRectTracking(); - SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, true); - break; - - default: - ; - } -} - - -void -TitleView::FrameResized(float width, float height) -{ - fVisibleRect.right = fVisibleRect.left + width; - fVisibleRect.bottom = fVisibleRect.top + height; - FixScrollBar(true); -} - - -// #pragma mark - - - -OutlineView::OutlineView(BRect rect, BList* visibleColumns, BList* sortColumns, - BColumnListView* listView) - : - BView(rect, "outline_view", B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_FRAME_EVENTS), - fColumns(visibleColumns), - fSortColumns(sortColumns), - fItemsHeight(0.0), - fVisibleRect(rect.OffsetToCopy(0, 0)), - fFocusRow(0), - fRollOverRow(0), - fLastSelectedItem(0), - fFirstSelectedItem(0), - fSortThread(B_BAD_THREAD_ID), - fCurrentState(INACTIVE), - fMasterView(listView), - fSelectionMode(B_MULTIPLE_SELECTION_LIST), - fTrackMouse(false), - fCurrentField(0), - fCurrentRow(0), - fCurrentColumn(0), - fMouseDown(false), - fCurrentCode(B_OUTSIDE_VIEW), - fEditMode(false), - fDragging(false), - fClickCount(0), - fDropHighlightY(-1) -{ - SetViewColor(B_TRANSPARENT_COLOR); - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - // TODO: This needs to be smart about the size of the buffer. - // Also, the buffer can be shared with the title's buffer. - BRect doubleBufferRect(0, 0, 600, 35); - fDrawBuffer = new BBitmap(doubleBufferRect, B_RGB32, true); - fDrawBufferView = new BView(doubleBufferRect, "double_buffer_view", - B_FOLLOW_ALL_SIDES, 0); - fDrawBuffer->Lock(); - fDrawBuffer->AddChild(fDrawBufferView); - fDrawBuffer->Unlock(); -#endif - - FixScrollBar(true); - fSelectionListDummyHead.fNextSelected = &fSelectionListDummyHead; - fSelectionListDummyHead.fPrevSelected = &fSelectionListDummyHead; -} - - -OutlineView::~OutlineView() -{ -#if DOUBLE_BUFFERED_COLUMN_RESIZE - delete fDrawBuffer; -#endif - - Clear(); -} - - -void -OutlineView::Clear() -{ - DeselectAll(); - // Make sure selection list doesn't point to deleted rows! - RecursiveDeleteRows(&fRows, false); - Invalidate(); - fItemsHeight = 0.0; - FixScrollBar(true); -} - - -void -OutlineView::SetSelectionMode(list_view_type mode) -{ - DeselectAll(); - fSelectionMode = mode; -} - - -list_view_type -OutlineView::SelectionMode() const -{ - return fSelectionMode; -} - - -void -OutlineView::Deselect(BRow* row) -{ - if (row == NULL) - return; - - if (row->fNextSelected != 0) { - row->fNextSelected->fPrevSelected = row->fPrevSelected; - row->fPrevSelected->fNextSelected = row->fNextSelected; - row->fNextSelected = 0; - row->fPrevSelected = 0; - Invalidate(); - } -} - - -void -OutlineView::AddToSelection(BRow* row) -{ - if (row == NULL) - return; - - if (row->fNextSelected == 0) { - if (fSelectionMode == B_SINGLE_SELECTION_LIST) - DeselectAll(); - - row->fNextSelected = fSelectionListDummyHead.fNextSelected; - row->fPrevSelected = &fSelectionListDummyHead; - row->fNextSelected->fPrevSelected = row; - row->fPrevSelected->fNextSelected = row; - - BRect invalidRect; - if (FindVisibleRect(row, &invalidRect)) - Invalidate(invalidRect); - } -} - - -void -OutlineView::RecursiveDeleteRows(BRowContainer* list, bool isOwner) -{ - if (list == NULL) - return; - - while (true) { - BRow* row = list->RemoveItemAt(0L); - if (row == 0) - break; - - if (row->fChildList) - RecursiveDeleteRows(row->fChildList, true); - - delete row; - } - - if (isOwner) - delete list; -} - - -void -OutlineView::RedrawColumn(BColumn* column, float leftEdge, bool isFirstColumn) -{ - // TODO: Remove code duplication (private function which takes a view - // pointer, pass "this" in non-double buffered mode)! - // Watch out for sourceRect versus destRect though! - if (!column) - return; - - font_height fh; - GetFontHeight(&fh); - float line = 0.0; - bool tintedLine = true; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - line += iterator.CurrentRow()->Height() + 1, iterator.GoToNext()) { - - BRow* row = iterator.CurrentRow(); - float rowHeight = row->Height(); - if (line > fVisibleRect.bottom) - break; - tintedLine = !tintedLine; - - if (line + rowHeight >= fVisibleRect.top) { -#if DOUBLE_BUFFERED_COLUMN_RESIZE - BRect sourceRect(0, 0, column->Width(), rowHeight); -#endif - BRect destRect(leftEdge, line, leftEdge + column->Width(), - line + rowHeight); - - rgb_color highColor; - rgb_color lowColor; - if (row->fNextSelected != 0) { - if (fEditMode) { - highColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); - lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); - } else { - highColor = fMasterView->Color(B_COLOR_SELECTION); - lowColor = fMasterView->Color(B_COLOR_SELECTION); - } - } else { - highColor = fMasterView->Color(B_COLOR_BACKGROUND); - lowColor = fMasterView->Color(B_COLOR_BACKGROUND); - } - if (tintedLine) - lowColor = tint_color(lowColor, kTintedLineTint); - - -#if DOUBLE_BUFFERED_COLUMN_RESIZE - fDrawBuffer->Lock(); - - fDrawBufferView->SetHighColor(highColor); - fDrawBufferView->SetLowColor(lowColor); - - BFont font; - GetFont(&font); - fDrawBufferView->SetFont(&font); - fDrawBufferView->FillRect(sourceRect, B_SOLID_LOW); - - if (isFirstColumn) { - // If this is the first column, double buffer drawing the latch - // too. - destRect.left += iterator.CurrentLevel() * kOutlineLevelIndent - - fMasterView->LatchWidth(); - sourceRect.left += iterator.CurrentLevel() * kOutlineLevelIndent - - fMasterView->LatchWidth(); - - LatchType pos = B_NO_LATCH; - if (row->HasLatch()) - pos = row->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH; - - BRect latchRect(sourceRect); - latchRect.right = latchRect.left + fMasterView->LatchWidth(); - fMasterView->DrawLatch(fDrawBufferView, latchRect, pos, row); - } - - BField* field = row->GetField(column->fFieldID); - if (field) { - BRect fieldRect(sourceRect); - if (isFirstColumn) - fieldRect.left += fMasterView->LatchWidth(); - - #if CONSTRAIN_CLIPPING_REGION - BRegion clipRegion(fieldRect); - fDrawBufferView->PushState(); - fDrawBufferView->ConstrainClippingRegion(&clipRegion); - #endif - fDrawBufferView->SetHighColor(fMasterView->Color( - row->fNextSelected ? B_COLOR_SELECTION_TEXT - : B_COLOR_TEXT)); - float baseline = floor(fieldRect.top + fh.ascent - + (fieldRect.Height() + 1 - (fh.ascent+fh.descent)) / 2); - fDrawBufferView->MovePenTo(fieldRect.left + 8, baseline); - column->DrawField(field, fieldRect, fDrawBufferView); - #if CONSTRAIN_CLIPPING_REGION - fDrawBufferView->PopState(); - #endif - } - - if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() - && Window()->IsActive()) { - fDrawBufferView->SetHighColor(fMasterView->Color( - B_COLOR_ROW_DIVIDER)); - fDrawBufferView->StrokeRect(BRect(-1, sourceRect.top, - 10000.0, sourceRect.bottom)); - } - - fDrawBufferView->Sync(); - fDrawBuffer->Unlock(); - SetDrawingMode(B_OP_COPY); - DrawBitmap(fDrawBuffer, sourceRect, destRect); - -#else - - SetHighColor(highColor); - SetLowColor(lowColor); - FillRect(destRect, B_SOLID_LOW); - - BField* field = row->GetField(column->fFieldID); - if (field) { - #if CONSTRAIN_CLIPPING_REGION - BRegion clipRegion(destRect); - PushState(); - ConstrainClippingRegion(&clipRegion); - #endif - SetHighColor(fMasterView->Color(row->fNextSelected - ? B_COLOR_SELECTION_TEXT : B_COLOR_TEXT)); - float baseline = floor(destRect.top + fh.ascent - + (destRect.Height() + 1 - (fh.ascent + fh.descent)) / 2); - MovePenTo(destRect.left + 8, baseline); - column->DrawField(field, destRect, this); - #if CONSTRAIN_CLIPPING_REGION - PopState(); - #endif - } - - if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() - && Window()->IsActive()) { - SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); - StrokeRect(BRect(0, destRect.top, 10000.0, destRect.bottom)); - } -#endif - } - } -} - - -void -OutlineView::Draw(BRect invalidBounds) -{ -#if SMART_REDRAW - BRegion invalidRegion; - GetClippingRegion(&invalidRegion); -#endif - - font_height fh; - GetFontHeight(&fh); - - float line = 0.0; - bool tintedLine = true; - int32 numColumns = fColumns->CountItems(); - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - BRow* row = iterator.CurrentRow(); - if (line > invalidBounds.bottom) - break; - - tintedLine = !tintedLine; - float rowHeight = row->Height(); - - if (line > invalidBounds.top - rowHeight) { - bool isFirstColumn = true; - float fieldLeftEdge = MAX(kLeftMargin, fMasterView->LatchWidth()); - - // setup background color - rgb_color lowColor; - if (row->fNextSelected != 0) { - if (Window()->IsActive()) { - if (fEditMode) - lowColor = fMasterView->Color(B_COLOR_EDIT_BACKGROUND); - else - lowColor = fMasterView->Color(B_COLOR_SELECTION); - } - else - lowColor = fMasterView->Color(B_COLOR_NON_FOCUS_SELECTION); - } else - lowColor = fMasterView->Color(B_COLOR_BACKGROUND); - if (tintedLine) - lowColor = tint_color(lowColor, kTintedLineTint); - - for (int columnIndex = 0; columnIndex < numColumns; columnIndex++) { - BColumn* column = (BColumn*) fColumns->ItemAt(columnIndex); - if (!column->IsVisible()) - continue; - - if (!isFirstColumn && fieldLeftEdge > invalidBounds.right) - break; - - if (fieldLeftEdge + column->Width() >= invalidBounds.left) { - BRect fullRect(fieldLeftEdge, line, - fieldLeftEdge + column->Width(), line + rowHeight); - - bool clippedFirstColumn = false; - // This happens when a column is indented past the - // beginning of the next column. - - SetHighColor(lowColor); - - BRect destRect(fullRect); - if (isFirstColumn) { - fullRect.left -= fMasterView->LatchWidth(); - destRect.left += iterator.CurrentLevel() - * kOutlineLevelIndent; - if (destRect.left >= destRect.right) { - // clipped - FillRect(BRect(0, line, fieldLeftEdge - + column->Width(), line + rowHeight)); - clippedFirstColumn = true; - } - - FillRect(BRect(0, line, MAX(kLeftMargin, - fMasterView->LatchWidth()), line + row->Height())); - } - - -#if SMART_REDRAW - if (!clippedFirstColumn - && invalidRegion.Intersects(fullRect)) { -#else - if (!clippedFirstColumn) { -#endif - FillRect(fullRect); // Using color set above - - // Draw the latch widget if it has one. - if (isFirstColumn) { - if (row == fTargetRow - && fCurrentState == LATCH_CLICKED) { - // Note that this only occurs if the user is - // holding down a latch while items are added - // in the background. - BPoint pos; - uint32 buttons; - GetMouse(&pos, &buttons); - if (fLatchRect.Contains(pos)) { - fMasterView->DrawLatch(this, fLatchRect, - B_PRESSED_LATCH, fTargetRow); - } else { - fMasterView->DrawLatch(this, fLatchRect, - row->fIsExpanded ? B_OPEN_LATCH - : B_CLOSED_LATCH, fTargetRow); - } - } else { - LatchType pos = B_NO_LATCH; - if (row->HasLatch()) - pos = row->fIsExpanded ? B_OPEN_LATCH - : B_CLOSED_LATCH; - - fMasterView->DrawLatch(this, - BRect(destRect.left - - fMasterView->LatchWidth(), - destRect.top, destRect.left, - destRect.bottom), pos, row); - } - } - - SetHighColor(fMasterView->HighColor()); - // The master view just holds the high color for us. - SetLowColor(lowColor); - - BField* field = row->GetField(column->fFieldID); - if (field) { -#if CONSTRAIN_CLIPPING_REGION - BRegion clipRegion(destRect); - PushState(); - ConstrainClippingRegion(&clipRegion); -#endif - SetHighColor(fMasterView->Color( - row->fNextSelected ? B_COLOR_SELECTION_TEXT - : B_COLOR_TEXT)); - float baseline = floor(destRect.top + fh.ascent - + (destRect.Height() + 1 - - (fh.ascent+fh.descent)) / 2); - MovePenTo(destRect.left + 8, baseline); - column->DrawField(field, destRect, this); -#if CONSTRAIN_CLIPPING_REGION - PopState(); -#endif - } - } - } - - isFirstColumn = false; - fieldLeftEdge += column->Width() + 1; - } - - if (fieldLeftEdge <= invalidBounds.right) { - SetHighColor(lowColor); - FillRect(BRect(fieldLeftEdge, line, invalidBounds.right, - line + rowHeight)); - } - } - - // indicate the keyboard focus row - if (fFocusRow == row && !fEditMode && fMasterView->IsFocus() - && Window()->IsActive()) { - SetHighColor(fMasterView->Color(B_COLOR_ROW_DIVIDER)); - StrokeRect(BRect(0, line, 10000.0, line + rowHeight)); - } - - line += rowHeight + 1; - } - - if (line <= invalidBounds.bottom) { - // fill background below last item - SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); - FillRect(BRect(invalidBounds.left, line, invalidBounds.right, - invalidBounds.bottom)); - } - - // Draw the drop target line - if (fDropHighlightY != -1) { - InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, - 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); - } -} - - -BRow* -OutlineView::FindRow(float ypos, int32* _rowIndent, float* _top) -{ - if (_rowIndent && _top) { - float line = 0.0; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - - BRow* row = iterator.CurrentRow(); - if (line > ypos) - break; - - float rowHeight = row->Height(); - if (ypos <= line + rowHeight) { - *_top = line; - *_rowIndent = iterator.CurrentLevel(); - return row; - } - - line += rowHeight + 1; - } - } - return NULL; -} - -void OutlineView::SetMouseTrackingEnabled(bool enabled) -{ - fTrackMouse = enabled; - if (!enabled && fDropHighlightY != -1) { - // Erase the old target line - InvertRect(BRect(0, fDropHighlightY - kDropHighlightLineHeight / 2, - 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); - fDropHighlightY = -1; - } -} - - -// -// Note that this interaction is not totally safe. If items are added to -// the list in the background, the widget rect will be incorrect, possibly -// resulting in drawing glitches. The code that adds items needs to be a little smarter -// about invalidating state. -// -void -OutlineView::MouseDown(BPoint position) -{ - if (!fEditMode) - fMasterView->MakeFocus(true); - - // Check to see if the user is clicking on a widget to open a section - // of the list. - bool reset_click_count = false; - int32 indent; - float rowTop; - BRow* row = FindRow(position.y, &indent, &rowTop); - if (row != NULL) { - - // Update fCurrentField - bool handle_field = false; - BField* new_field = 0; - BRow* new_row = 0; - BColumn* new_column = 0; - BRect new_rect; - - if (position.y >= 0) { - if (position.x >= 0) { - float x = 0; - for (int32 c = 0; c < fMasterView->CountColumns(); c++) { - new_column = fMasterView->ColumnAt(c); - if (!new_column->IsVisible()) - continue; - if ((MAX(kLeftMargin, fMasterView->LatchWidth()) + x) - + new_column->Width() >= position.x) { - if (new_column->WantsEvents()) { - new_field = row->GetField(c); - new_row = row; - FindRect(new_row,&new_rect); - new_rect.left = MAX(kLeftMargin, - fMasterView->LatchWidth()) + x; - new_rect.right = new_rect.left - + new_column->Width() - 1; - handle_field = true; - } - break; - } - x += new_column->Width(); - } - } - } - - // Handle mouse down - if (handle_field) { - fMouseDown = true; - fFieldRect = new_rect; - fCurrentColumn = new_column; - fCurrentRow = new_row; - fCurrentField = new_field; - fCurrentCode = B_INSIDE_VIEW; - fCurrentColumn->MouseDown(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1); - } - - if (!fEditMode) { - - fTargetRow = row; - fTargetRowTop = rowTop; - FindVisibleRect(fFocusRow, &fFocusRowRect); - - float leftWidgetBoundry = indent * kOutlineLevelIndent - + MAX(kLeftMargin, fMasterView->LatchWidth()) - - fMasterView->LatchWidth(); - fLatchRect.Set(leftWidgetBoundry, rowTop, leftWidgetBoundry - + fMasterView->LatchWidth(), rowTop + row->Height()); - if (fLatchRect.Contains(position) && row->HasLatch()) { - fCurrentState = LATCH_CLICKED; - if (fTargetRow->fNextSelected != 0) - SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); - else - SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); - - FillRect(fLatchRect); - if (fLatchRect.Contains(position)) { - fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, - row); - } else { - fMasterView->DrawLatch(this, fLatchRect, - fTargetRow->fIsExpanded ? B_OPEN_LATCH - : B_CLOSED_LATCH, row); - } - } else { - Invalidate(fFocusRowRect); - fFocusRow = fTargetRow; - FindVisibleRect(fFocusRow, &fFocusRowRect); - - ASSERT(fTargetRow != 0); - - if ((modifiers() & B_CONTROL_KEY) == 0) - DeselectAll(); - - if ((modifiers() & B_SHIFT_KEY) != 0 && fFirstSelectedItem != 0 - && fSelectionMode == B_MULTIPLE_SELECTION_LIST) { - SelectRange(fFirstSelectedItem, fTargetRow); - } - else { - if (fTargetRow->fNextSelected != 0) { - // Unselect row - fTargetRow->fNextSelected->fPrevSelected - = fTargetRow->fPrevSelected; - fTargetRow->fPrevSelected->fNextSelected - = fTargetRow->fNextSelected; - fTargetRow->fPrevSelected = 0; - fTargetRow->fNextSelected = 0; - fFirstSelectedItem = NULL; - } else { - // Select row - if (fSelectionMode == B_SINGLE_SELECTION_LIST) - DeselectAll(); - - fTargetRow->fNextSelected - = fSelectionListDummyHead.fNextSelected; - fTargetRow->fPrevSelected - = &fSelectionListDummyHead; - fTargetRow->fNextSelected->fPrevSelected = fTargetRow; - fTargetRow->fPrevSelected->fNextSelected = fTargetRow; - fFirstSelectedItem = fTargetRow; - } - - Invalidate(BRect(fVisibleRect.left, fTargetRowTop, - fVisibleRect.right, - fTargetRowTop + fTargetRow->Height())); - } - - fCurrentState = ROW_CLICKED; - if (fLastSelectedItem != fTargetRow) - reset_click_count = true; - fLastSelectedItem = fTargetRow; - fMasterView->SelectionChanged(); - - } - } - - SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | - B_NO_POINTER_HISTORY); - - } else if (fFocusRow != 0) { - // User clicked in open space, unhighlight focus row. - FindVisibleRect(fFocusRow, &fFocusRowRect); - fFocusRow = 0; - Invalidate(fFocusRowRect); - } - - // We stash the click counts here because the 'clicks' field - // is not in the CurrentMessage() when MouseUp is called... ;( - if (reset_click_count) - fClickCount = 1; - else - Window()->CurrentMessage()->FindInt32("clicks", &fClickCount); - fClickPoint = position; - -} - - -void -OutlineView::MouseMoved(BPoint position, uint32 /*transit*/, - const BMessage* /*dragMessage*/) -{ - if (!fMouseDown) { - // Update fCurrentField - bool handle_field = false; - BField* new_field = 0; - BRow* new_row = 0; - BColumn* new_column = 0; - BRect new_rect(0,0,0,0); - if (position.y >=0 ) { - float top; - int32 indent; - BRow* row = FindRow(position.y, &indent, &top); - if (row && position.x >=0 ) { - float x=0; - for (int32 c=0;cCountColumns();c++) { - new_column = fMasterView->ColumnAt(c); - if (!new_column->IsVisible()) - continue; - if ((MAX(kLeftMargin, - fMasterView->LatchWidth()) + x) + new_column->Width() - > position.x) { - - if(new_column->WantsEvents()) { - new_field = row->GetField(c); - new_row = row; - FindRect(new_row,&new_rect); - new_rect.left = MAX(kLeftMargin, - fMasterView->LatchWidth()) + x; - new_rect.right = new_rect.left - + new_column->Width() - 1; - handle_field = true; - } - break; - } - x += new_column->Width(); - } - } - } - - // Handle mouse moved - if (handle_field) { - if (new_field != fCurrentField) { - if (fCurrentField) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, - fCurrentCode = B_EXITED_VIEW); - } - fCurrentColumn = new_column; - fCurrentRow = new_row; - fCurrentField = new_field; - fFieldRect = new_rect; - if (fCurrentField) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, - fCurrentCode = B_ENTERED_VIEW); - } - } else { - if (fCurrentField) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, - fCurrentCode = B_INSIDE_VIEW); - } - } - } else { - if (fCurrentField) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 0, - fCurrentCode = B_EXITED_VIEW); - fCurrentField = 0; - fCurrentColumn = 0; - fCurrentRow = 0; - } - } - } else { - if (fCurrentField) { - if (fFieldRect.Contains(position)) { - if (fCurrentCode == B_OUTSIDE_VIEW - || fCurrentCode == B_EXITED_VIEW) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, - fCurrentCode = B_ENTERED_VIEW); - } else { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, - fCurrentCode = B_INSIDE_VIEW); - } - } else { - if (fCurrentCode == B_INSIDE_VIEW - || fCurrentCode == B_ENTERED_VIEW) { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, - fCurrentCode = B_EXITED_VIEW); - } else { - fCurrentColumn->MouseMoved(fMasterView, fCurrentRow, - fCurrentField, fFieldRect, position, 1, - fCurrentCode = B_OUTSIDE_VIEW); - } - } - } - } - - if (!fEditMode) { - - switch (fCurrentState) { - case LATCH_CLICKED: - if (fTargetRow->fNextSelected != 0) - SetHighColor(fMasterView->Color(B_COLOR_SELECTION)); - else - SetHighColor(fMasterView->Color(B_COLOR_BACKGROUND)); - - FillRect(fLatchRect); - if (fLatchRect.Contains(position)) { - fMasterView->DrawLatch(this, fLatchRect, B_PRESSED_LATCH, - fTargetRow); - } else { - fMasterView->DrawLatch(this, fLatchRect, - fTargetRow->fIsExpanded ? B_OPEN_LATCH : B_CLOSED_LATCH, - fTargetRow); - } - break; - - case ROW_CLICKED: - if (abs((int)(position.x - fClickPoint.x)) > kRowDragSensitivity - || abs((int)(position.y - fClickPoint.y)) - > kRowDragSensitivity) { - fCurrentState = DRAGGING_ROWS; - fMasterView->InitiateDrag(fClickPoint, - fTargetRow->fNextSelected != 0); - } - break; - - case DRAGGING_ROWS: -#if 0 - // falls through... -#else - if (fTrackMouse /*&& message*/) { - if (fVisibleRect.Contains(position)) { - float top; - int32 indent; - BRow* target = FindRow(position.y, &indent, &top); - if (target) - SetFocusRow(target, true); - } - } - break; -#endif - - default: { - - if (fTrackMouse /*&& message*/) { - // Draw a highlight line... - if (fVisibleRect.Contains(position)) { - float top; - int32 indent; - BRow* target = FindRow(position.y, &indent, &top); - if (target == fRollOverRow) - break; - if (fRollOverRow) { - BRect rect; - FindRect(fRollOverRow, &rect); - Invalidate(rect); - } - fRollOverRow = target; -#if 0 - SetFocusRow(fRollOverRow,false); -#else - PushState(); - SetDrawingMode(B_OP_BLEND); - SetHighColor(255, 255, 255, 255); - BRect rect; - FindRect(fRollOverRow, &rect); - rect.bottom -= 1.0; - FillRect(rect); - PopState(); -#endif - } else { - if (fRollOverRow) { - BRect rect; - FindRect(fRollOverRow, &rect); - Invalidate(rect); - fRollOverRow = NULL; - } - } - } - } - } - } -} - - -void -OutlineView::MouseUp(BPoint position) -{ - if (fCurrentField) { - fCurrentColumn->MouseUp(fMasterView, fCurrentRow, fCurrentField); - fMouseDown = false; - } - - if (fEditMode) - return; - - switch (fCurrentState) { - case LATCH_CLICKED: - if (fLatchRect.Contains(position)) { - fMasterView->ExpandOrCollapse(fTargetRow, - !fTargetRow->fIsExpanded); - } - - Invalidate(fLatchRect); - fCurrentState = INACTIVE; - break; - - case ROW_CLICKED: - if (fClickCount > 1 - && abs((int)fClickPoint.x - (int)position.x) - < kDoubleClickMoveSensitivity - && abs((int)fClickPoint.y - (int)position.y) - < kDoubleClickMoveSensitivity) { - fMasterView->ItemInvoked(); - } - fCurrentState = INACTIVE; - break; - - case DRAGGING_ROWS: - fCurrentState = INACTIVE; - // Falls through - - default: - if (fDropHighlightY != -1) { - InvertRect(BRect(0, - fDropHighlightY - kDropHighlightLineHeight / 2, - 1000000, fDropHighlightY + kDropHighlightLineHeight / 2)); - // Erase the old target line - fDropHighlightY = -1; - } - } -} - - -void -OutlineView::MessageReceived(BMessage* message) -{ - if (message->WasDropped()) { - fMasterView->MessageDropped(message, - ConvertFromScreen(message->DropPoint())); - } else { - BView::MessageReceived(message); - } -} - - -void -OutlineView::ChangeFocusRow(bool up, bool updateSelection, - bool addToCurrentSelection) -{ - int32 indent; - float top; - float newRowPos = 0; - float verticalScroll = 0; - - if (fFocusRow) { - // A row currently has the focus, get information about it - newRowPos = fFocusRowRect.top + (up ? -4 : fFocusRow->Height() + 4); - if (newRowPos < fVisibleRect.top + 20) - verticalScroll = newRowPos - 20; - else if (newRowPos > fVisibleRect.bottom - 20) - verticalScroll = newRowPos - fVisibleRect.Height() + 20; - } else - newRowPos = fVisibleRect.top + 2; - // no row is currently focused, set this to the top of the window - // so we will select the first visible item in the list. - - BRow* newRow = FindRow(newRowPos, &indent, &top); - if (newRow) { - if (fFocusRow) { - fFocusRowRect.right = 10000; - Invalidate(fFocusRowRect); - } - fFocusRow = newRow; - fFocusRowRect.top = top; - fFocusRowRect.left = 0; - fFocusRowRect.right = 10000; - fFocusRowRect.bottom = fFocusRowRect.top + fFocusRow->Height(); - Invalidate(fFocusRowRect); - - if (updateSelection) { - if (!addToCurrentSelection - || fSelectionMode == B_SINGLE_SELECTION_LIST) { - DeselectAll(); - } - - if (fFocusRow->fNextSelected == 0) { - fFocusRow->fNextSelected - = fSelectionListDummyHead.fNextSelected; - fFocusRow->fPrevSelected = &fSelectionListDummyHead; - fFocusRow->fNextSelected->fPrevSelected = fFocusRow; - fFocusRow->fPrevSelected->fNextSelected = fFocusRow; - } - - fLastSelectedItem = fFocusRow; - } - } else - Invalidate(fFocusRowRect); - - if (verticalScroll != 0) { - BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); - float min, max; - vScrollBar->GetRange(&min, &max); - if (verticalScroll < min) - verticalScroll = min; - else if (verticalScroll > max) - verticalScroll = max; - - vScrollBar->SetValue(verticalScroll); - } - - if (newRow && updateSelection) - fMasterView->SelectionChanged(); -} - - -void -OutlineView::MoveFocusToVisibleRect() -{ - fFocusRow = 0; - ChangeFocusRow(true, true, false); -} - - -BRow* -OutlineView::CurrentSelection(BRow* lastSelected) const -{ - BRow* row; - if (lastSelected == 0) - row = fSelectionListDummyHead.fNextSelected; - else - row = lastSelected->fNextSelected; - - - if (row == &fSelectionListDummyHead) - row = 0; - - return row; -} - - -void -OutlineView::ToggleFocusRowSelection(bool selectRange) -{ - if (fFocusRow == 0) - return; - - if (selectRange && fSelectionMode == B_MULTIPLE_SELECTION_LIST) - SelectRange(fLastSelectedItem, fFocusRow); - else { - if (fFocusRow->fNextSelected != 0) { - // Unselect row - fFocusRow->fNextSelected->fPrevSelected = fFocusRow->fPrevSelected; - fFocusRow->fPrevSelected->fNextSelected = fFocusRow->fNextSelected; - fFocusRow->fPrevSelected = 0; - fFocusRow->fNextSelected = 0; - } else { - // Select row - if (fSelectionMode == B_SINGLE_SELECTION_LIST) - DeselectAll(); - - fFocusRow->fNextSelected = fSelectionListDummyHead.fNextSelected; - fFocusRow->fPrevSelected = &fSelectionListDummyHead; - fFocusRow->fNextSelected->fPrevSelected = fFocusRow; - fFocusRow->fPrevSelected->fNextSelected = fFocusRow; - } - } - - fLastSelectedItem = fFocusRow; - fMasterView->SelectionChanged(); - Invalidate(fFocusRowRect); -} - - -void -OutlineView::ToggleFocusRowOpen() -{ - if (fFocusRow) - fMasterView->ExpandOrCollapse(fFocusRow, !fFocusRow->fIsExpanded); -} - - -void -OutlineView::ExpandOrCollapse(BRow* parentRow, bool expand) -{ - // TODO: Could use CopyBits here to speed things up. - - if (parentRow == NULL) - return; - - if (parentRow->fIsExpanded == expand) - return; - - parentRow->fIsExpanded = expand; - - BRect parentRect; - if (FindRect(parentRow, &parentRect)) { - // Determine my new height - float subTreeHeight = 0.0; - if (parentRow->fIsExpanded) - for (RecursiveOutlineIterator iterator(parentRow->fChildList); - iterator.CurrentRow(); - iterator.GoToNext() - ) - { - subTreeHeight += iterator.CurrentRow()->Height()+1; - } - else - for (RecursiveOutlineIterator iterator(parentRow->fChildList); - iterator.CurrentRow(); - iterator.GoToNext() - ) - { - subTreeHeight -= iterator.CurrentRow()->Height()+1; - } - fItemsHeight += subTreeHeight; - - // Adjust focus row if necessary. - if (FindRect(fFocusRow, &fFocusRowRect) == false) { - // focus row is in a subtree that has collapsed, - // move it up to the parent. - fFocusRow = parentRow; - FindRect(fFocusRow, &fFocusRowRect); - } - - Invalidate(BRect(0, parentRect.top, fVisibleRect.right, - fVisibleRect.bottom)); - FixScrollBar(false); - } -} - -void -OutlineView::RemoveRow(BRow* row) -{ - if (row == NULL) - return; - - BRow* parentRow; - bool parentIsVisible; - float subTreeHeight = row->Height(); - if (FindParent(row, &parentRow, &parentIsVisible)) { - // adjust height - if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) { - if (row->fIsExpanded) { - for (RecursiveOutlineIterator iterator(row->fChildList); - iterator.CurrentRow(); iterator.GoToNext()) - subTreeHeight += iterator.CurrentRow()->Height(); - } - } - } - if (parentRow) { - if (parentRow->fIsExpanded) - fItemsHeight -= subTreeHeight + 1; - } else { - fItemsHeight -= subTreeHeight + 1; - } - FixScrollBar(false); - if (parentRow) - parentRow->fChildList->RemoveItem(row); - else - fRows.RemoveItem(row); - - if (parentRow != 0 && parentRow->fChildList->CountItems() == 0) { - delete parentRow->fChildList; - parentRow->fChildList = 0; - if (parentIsVisible) - Invalidate(); // xxx crude way of redrawing latch - } - - if (parentIsVisible && (parentRow == 0 || parentRow->fIsExpanded)) - Invalidate(); // xxx make me smarter. - - - // Adjust focus row if necessary. - if (fFocusRow && FindRect(fFocusRow, &fFocusRowRect) == false) { - // focus row is in a subtree that is gone, move it up to the parent. - fFocusRow = parentRow; - if (fFocusRow) - FindRect(fFocusRow, &fFocusRowRect); - } - - // Remove this from the selection if necessary - if (row->fNextSelected != 0) { - row->fNextSelected->fPrevSelected = row->fPrevSelected; - row->fPrevSelected->fNextSelected = row->fNextSelected; - row->fPrevSelected = 0; - row->fNextSelected = 0; - fMasterView->SelectionChanged(); - } - - fCurrentColumn = 0; - fCurrentRow = 0; - fCurrentField = 0; -} - - -BRowContainer* -OutlineView::RowList() -{ - return &fRows; -} - - -void -OutlineView::UpdateRow(BRow* row) -{ - if (row) { - // Determine if this row has changed its sort order - BRow* parentRow = NULL; - bool parentIsVisible = false; - FindParent(row, &parentRow, &parentIsVisible); - - BRowContainer* list = (parentRow == NULL) ? &fRows : parentRow->fChildList; - - if(list) { - int32 rowIndex = list->IndexOf(row); - ASSERT(rowIndex >= 0); - ASSERT(list->ItemAt(rowIndex) == row); - - bool rowMoved = false; - if (rowIndex > 0 && CompareRows(list->ItemAt(rowIndex - 1), row) > 0) - rowMoved = true; - - if (rowIndex < list->CountItems() - 1 && CompareRows(list->ItemAt(rowIndex + 1), - row) < 0) - rowMoved = true; - - if (rowMoved) { - // Sort location of this row has changed. - // Remove and re-add in the right spot - SortList(list, parentIsVisible && (parentRow == NULL || parentRow->fIsExpanded)); - } else if (parentIsVisible && (parentRow == NULL || parentRow->fIsExpanded)) { - BRect invalidRect; - if (FindVisibleRect(row, &invalidRect)) - Invalidate(invalidRect); - } - } - } -} - - -void -OutlineView::AddRow(BRow* row, int32 Index, BRow* parentRow) -{ - if (!row) - return; - - row->fParent = parentRow; - - if (fMasterView->SortingEnabled()) { - // Ignore index here. - if (parentRow) { - if (parentRow->fChildList == NULL) - parentRow->fChildList = new BRowContainer; - - AddSorted(parentRow->fChildList, row); - } else - AddSorted(&fRows, row); - } else { - // Note, a -1 index implies add to end if sorting is not enabled - if (parentRow) { - if (parentRow->fChildList == 0) - parentRow->fChildList = new BRowContainer; - - if (Index < 0 || Index > parentRow->fChildList->CountItems()) - parentRow->fChildList->AddItem(row); - else - parentRow->fChildList->AddItem(row, Index); - } else { - if (Index < 0 || Index >= fRows.CountItems()) - fRows.AddItem(row); - else - fRows.AddItem(row, Index); - } - } - - if (parentRow == 0 || parentRow->fIsExpanded) - fItemsHeight += row->Height() + 1; - - FixScrollBar(false); - - BRect newRowRect; - bool newRowIsInOpenBranch = FindRect(row, &newRowRect); - - if (fFocusRow && fFocusRowRect.top > newRowRect.bottom) { - // The focus row has moved. - Invalidate(fFocusRowRect); - FindRect(fFocusRow, &fFocusRowRect); - Invalidate(fFocusRowRect); - } - - if (newRowIsInOpenBranch) { - if (fCurrentState == INACTIVE) { - if (newRowRect.bottom < fVisibleRect.top) { - // The new row is totally above the current viewport, move - // everything down and redraw the first line. - BRect source(fVisibleRect); - BRect dest(fVisibleRect); - source.bottom -= row->Height() + 1; - dest.top += row->Height() + 1; - CopyBits(source, dest); - Invalidate(BRect(fVisibleRect.left, fVisibleRect.top, fVisibleRect.right, - fVisibleRect.top + newRowRect.Height())); - } else if (newRowRect.top < fVisibleRect.bottom) { - // New item is somewhere in the current region. Scroll everything - // beneath it down and invalidate just the new row rect. - BRect source(fVisibleRect.left, newRowRect.top, fVisibleRect.right, - fVisibleRect.bottom - newRowRect.Height()); - BRect dest(source); - dest.OffsetBy(0, newRowRect.Height() + 1); - CopyBits(source, dest); - Invalidate(newRowRect); - } // otherwise, this is below the currently visible region - } else { - // Adding the item may have caused the item that the user is currently - // selected to move. This would cause annoying drawing and interaction - // bugs, as the position of that item is cached. If this happens, resize - // the scroll bar, then scroll back so the selected item is in view. - BRect targetRect; - if (FindRect(fTargetRow, &targetRect)) { - float delta = targetRect.top - fTargetRowTop; - if (delta != 0) { - // This causes a jump because ScrollBy will copy a chunk of the view. - // Since the actual contents of the view have been offset, we don't - // want this, we just want to change the virtual origin of the window. - // Constrain the clipping region so everything is clipped out so no - // copy occurs. - // - // xxx this currently doesn't work if the scroll bars aren't enabled. - // everything will still move anyway. A minor annoyance. - BRegion emptyRegion; - ConstrainClippingRegion(&emptyRegion); - PushState(); - ScrollBy(0, delta); - PopState(); - ConstrainClippingRegion(NULL); - - fTargetRowTop += delta; - fClickPoint.y += delta; - fLatchRect.OffsetBy(0, delta); - } - } - } - } - - // If the parent was previously childless, it will need to have a latch - // drawn. - BRect parentRect; - if (parentRow && parentRow->fChildList->CountItems() == 1 - && FindVisibleRect(parentRow, &parentRect)) - Invalidate(parentRect); -} - - -void -OutlineView::FixScrollBar(bool scrollToFit) -{ - BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); - if (vScrollBar) { - if (fItemsHeight > fVisibleRect.Height()) { - float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); - vScrollBar->SetProportion(fVisibleRect.Height() / fItemsHeight); - - // If the user is scrolled down too far when makes the range smaller, the list - // will jump suddenly, which is undesirable. In this case, don't fix the scroll - // bar here. In ScrollTo, it checks to see if this has occured, and will - // fix the scroll bars sneakily if the user has scrolled up far enough. - if (scrollToFit || vScrollBar->Value() <= maxScrollBarValue) { - vScrollBar->SetRange(0.0, maxScrollBarValue); - vScrollBar->SetSteps(20.0, fVisibleRect.Height()); - } - } else if (vScrollBar->Value() == 0.0) - vScrollBar->SetRange(0.0, 0.0); // disable scroll bar. - } -} - - -void -OutlineView::AddSorted(BRowContainer* list, BRow* row) -{ - if (list && row) { - // Find general vicinity with binary search. - int32 lower = 0; - int32 upper = list->CountItems()-1; - while( lower < upper ) { - int32 middle = lower + (upper-lower+1)/2; - int32 cmp = CompareRows(row, list->ItemAt(middle)); - if( cmp < 0 ) upper = middle-1; - else if( cmp > 0 ) lower = middle+1; - else lower = upper = middle; - } - - // At this point, 'upper' and 'lower' at the last found item. - // Arbitrarily use 'upper' and determine the final insertion - // point -- either before or after this item. - if( upper < 0 ) upper = 0; - else if( upper < list->CountItems() ) { - if( CompareRows(row, list->ItemAt(upper)) > 0 ) upper++; - } - - if (upper >= list->CountItems()) - list->AddItem(row); // Adding to end. - else - list->AddItem(row, upper); // Insert - } -} - - -int32 -OutlineView::CompareRows(BRow* row1, BRow* row2) -{ - int32 itemCount (fSortColumns->CountItems()); - if (row1 && row2) { - for (int32 index = 0; index < itemCount; index++) { - BColumn* column = (BColumn*) fSortColumns->ItemAt(index); - int comp = 0; - BField* field1 = (BField*) row1->GetField(column->fFieldID); - BField* field2 = (BField*) row2->GetField(column->fFieldID); - if (field1 && field2) - comp = column->CompareFields(field1, field2); - - if (!column->fSortAscending) - comp = -comp; - - if (comp != 0) - return comp; - } - } - return 0; -} - - -void -OutlineView::FrameResized(float width, float height) -{ - fVisibleRect.right = fVisibleRect.left + width; - fVisibleRect.bottom = fVisibleRect.top + height; - FixScrollBar(true); - _inherited::FrameResized(width, height); -} - - -void -OutlineView::ScrollTo(BPoint position) -{ - fVisibleRect.OffsetTo(position.x, position.y); - - // In FixScrollBar, we might not have been able to change the size of - // the scroll bar because the user was scrolled down too far. Take - // this opportunity to sneak it in if we can. - BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); - float maxScrollBarValue = fItemsHeight - fVisibleRect.Height(); - float min, max; - vScrollBar->GetRange(&min, &max); - if (max != maxScrollBarValue && position.y > maxScrollBarValue) - FixScrollBar(true); - - _inherited::ScrollTo(position); -} - - -const BRect& -OutlineView::VisibleRect() const -{ - return fVisibleRect; -} - - -bool -OutlineView::FindVisibleRect(BRow* row, BRect* _rect) -{ - if (row && _rect) { - float line = 0.0; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - if (line > fVisibleRect.bottom) - break; - - if (iterator.CurrentRow() == row) { - _rect->Set(fVisibleRect.left, line, fVisibleRect.right, - line + row->Height()); - return true; - } - - line += iterator.CurrentRow()->Height() + 1; - } - } - return false; -} - - -bool -OutlineView::FindRect(const BRow* row, BRect* _rect) -{ - float line = 0.0; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - if (iterator.CurrentRow() == row) { - _rect->Set(fVisibleRect.left, line, fVisibleRect.right, - line + row->Height()); - return true; - } - - line += iterator.CurrentRow()->Height() + 1; - } - - return false; -} - - -void -OutlineView::ScrollTo(const BRow* row) -{ - BRect rect; - if (FindRect(row, &rect)) { - BRect bounds = Bounds(); - if (rect.top < bounds.top) - ScrollTo(BPoint(bounds.left, rect.top)); - else if (rect.bottom > bounds.bottom) - ScrollBy(0, rect.bottom - bounds.bottom); - } -} - - -void -OutlineView::DeselectAll() -{ - // Invalidate all selected rows - float line = 0.0; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - if (line > fVisibleRect.bottom) - break; - - BRow* row = iterator.CurrentRow(); - if (line + row->Height() > fVisibleRect.top) { - if (row->fNextSelected != 0) - Invalidate(BRect(fVisibleRect.left, line, fVisibleRect.right, - line + row->Height())); - } - - line += row->Height() + 1; - } - - // Set items not selected - while (fSelectionListDummyHead.fNextSelected != &fSelectionListDummyHead) { - BRow* row = fSelectionListDummyHead.fNextSelected; - row->fNextSelected->fPrevSelected = row->fPrevSelected; - row->fPrevSelected->fNextSelected = row->fNextSelected; - row->fNextSelected = 0; - row->fPrevSelected = 0; - } -} - - -BRow* -OutlineView::FocusRow() const -{ - return fFocusRow; -} - - -void -OutlineView::SetFocusRow(BRow* row, bool Select) -{ - if (row) { - if (Select) - AddToSelection(row); - - if (fFocusRow == row) - return; - - Invalidate(fFocusRowRect); // invalidate previous - - fTargetRow = fFocusRow = row; - - FindVisibleRect(fFocusRow, &fFocusRowRect); - Invalidate(fFocusRowRect); // invalidate current - - fFocusRowRect.right = 10000; - fMasterView->SelectionChanged(); - } -} - - -bool -OutlineView::SortList(BRowContainer* list, bool isVisible) -{ - if (list) { - // Shellsort - BRow** items = (BRow**) list->AsBList()->Items(); - int32 numItems = list->CountItems(); - int h; - for (h = 1; h < numItems / 9; h = 3 * h + 1) - ; - - for (;h > 0; h /= 3) { - for (int step = h; step < numItems; step++) { - BRow* temp = items[step]; - int i; - for (i = step - h; i >= 0; i -= h) { - if (CompareRows(temp, items[i]) < 0) - items[i + h] = items[i]; - else - break; - } - - items[i + h] = temp; - } - } - - if (isVisible) { - Invalidate(); - - InvalidateCachedPositions(); - int lockCount = Window()->CountLocks(); - for (int i = 0; i < lockCount; i++) - Window()->Unlock(); - - while (lockCount--) - if (!Window()->Lock()) - return false; // Window is gone... - } - } - return true; -} - - -int32 -OutlineView::DeepSortThreadEntry(void* _outlineView) -{ - ((OutlineView*) _outlineView)->DeepSort(); - return 0; -} - - -void -OutlineView::DeepSort() -{ - struct stack_entry { - bool isVisible; - BRowContainer* list; - int32 listIndex; - } stack[kMaxDepth]; - int32 stackTop = 0; - - stack[stackTop].list = &fRows; - stack[stackTop].isVisible = true; - stack[stackTop].listIndex = 0; - fNumSorted = 0; - - if (Window()->Lock() == false) - return; - - bool doneSorting = false; - while (!doneSorting && !fSortCancelled) { - - stack_entry* currentEntry = &stack[stackTop]; - - // xxx Can make the invalidate area smaller by finding the rect for the - // parent item and using that as the top of the invalid rect. - - bool haveLock = SortList(currentEntry->list, currentEntry->isVisible); - if (!haveLock) - return ; // window is gone. - - // Fix focus rect. - InvalidateCachedPositions(); - if (fCurrentState != INACTIVE) - fCurrentState = INACTIVE; // sorry... - - // next list. - bool foundNextList = false; - while (!foundNextList && !fSortCancelled) { - for (int32 index = currentEntry->listIndex; index < currentEntry->list->CountItems(); - index++) { - BRow* parentRow = currentEntry->list->ItemAt(index); - BRowContainer* childList = parentRow->fChildList; - if (childList != 0) { - currentEntry->listIndex = index + 1; - stackTop++; - ASSERT(stackTop < kMaxDepth); - stack[stackTop].listIndex = 0; - stack[stackTop].list = childList; - stack[stackTop].isVisible = (currentEntry->isVisible && parentRow->fIsExpanded); - foundNextList = true; - break; - } - } - - if (!foundNextList) { - // back up - if (--stackTop < 0) { - doneSorting = true; - break; - } - - currentEntry = &stack[stackTop]; - } - } - } - - Window()->Unlock(); -} - - -void -OutlineView::StartSorting() -{ - // If this view is not yet attached to a window, don't start a sort thread! - if (Window() == NULL) - return; - - if (fSortThread != B_BAD_THREAD_ID) { - thread_info tinfo; - if (get_thread_info(fSortThread, &tinfo) == B_OK) { - // Unlock window so this won't deadlock (sort thread is probably - // waiting to lock window). - - int lockCount = Window()->CountLocks(); - for (int i = 0; i < lockCount; i++) - Window()->Unlock(); - - fSortCancelled = true; - int32 status; - wait_for_thread(fSortThread, &status); - - while (lockCount--) - if (!Window()->Lock()) - return ; // Window is gone... - } - } - - fSortCancelled = false; - fSortThread = spawn_thread(DeepSortThreadEntry, "sort_thread", B_NORMAL_PRIORITY, this); - resume_thread(fSortThread); -} - - -void -OutlineView::SelectRange(BRow* start, BRow* end) -{ - if (!start || !end) - return; - - if (start == end) // start is always selected when this is called - return; - - RecursiveOutlineIterator iterator(&fRows, false); - while (iterator.CurrentRow() != 0) { - if (iterator.CurrentRow() == end) { - // reverse selection, swap to fix special case - BRow* temp = start; - start = end; - end = temp; - break; - } else if (iterator.CurrentRow() == start) - break; - - iterator.GoToNext(); - } - - while (true) { - BRow* row = iterator.CurrentRow(); - if (row) { - if (row->fNextSelected == 0) { - row->fNextSelected = fSelectionListDummyHead.fNextSelected; - row->fPrevSelected = &fSelectionListDummyHead; - row->fNextSelected->fPrevSelected = row; - row->fPrevSelected->fNextSelected = row; - } - } else - break; - - if (row == end) - break; - - iterator.GoToNext(); - } - - Invalidate(); // xxx make invalidation smaller -} - - -bool -OutlineView::FindParent(BRow* row, BRow** outParent, bool* out_parentIsVisible) -{ - bool result = false; - if (row && outParent) { - *outParent = row->fParent; - - // Walk up the parent chain to determine if this row is visible - bool isVisible = true; - for (BRow* currentRow = row->fParent; currentRow; currentRow = currentRow->fParent) { - if (!currentRow->fIsExpanded) { - isVisible = false; - break; - } - } - - if (out_parentIsVisible) - *out_parentIsVisible = isVisible; - result = (NULL != *outParent); - } - - return result; -} - - -int32 -OutlineView::IndexOf(BRow* row) -{ - if (row) { - if (row->fParent == 0) - return fRows.IndexOf(row); - - ASSERT(row->fParent->fChildList); - return row->fParent->fChildList->IndexOf(row); - } - - return B_ERROR; -} - - -void -OutlineView::InvalidateCachedPositions() -{ - if (fFocusRow) - FindRect(fFocusRow, &fFocusRowRect); -} - - -float -OutlineView::GetColumnPreferredWidth(BColumn* column) -{ - float preferred = 0.0; - for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow(); - iterator.GoToNext()) { - BRow* row = iterator.CurrentRow(); - BField* field = row->GetField(column->fFieldID); - if (field) { - float width = column->GetPreferredWidth(field, this); - if (preferred < width) - preferred = width; - } - } - // Constrain to preferred width. This makes the method do a little - // more than asked, but it's for convenience. - if (preferred < column->MinWidth()) - preferred = column->MinWidth(); - else if (preferred > column->MaxWidth()) - preferred = column->MaxWidth(); - - return preferred; -} - - -// #pragma mark - - - -RecursiveOutlineIterator::RecursiveOutlineIterator(BRowContainer* list, - bool openBranchesOnly) - : - fStackIndex(0), - fCurrentListIndex(0), - fCurrentListDepth(0), - fOpenBranchesOnly(openBranchesOnly) -{ - if (list == 0 || list->CountItems() == 0) - fCurrentList = 0; - else - fCurrentList = list; -} - - -BRow* -RecursiveOutlineIterator::CurrentRow() const -{ - if (fCurrentList == 0) - return 0; - - return fCurrentList->ItemAt(fCurrentListIndex); -} - - -void -RecursiveOutlineIterator::GoToNext() -{ - if (fCurrentList == 0) - return; - if (fCurrentListIndex < 0 || fCurrentListIndex >= fCurrentList->CountItems()) { - fCurrentList = 0; - return; - } - - BRow* currentRow = fCurrentList->ItemAt(fCurrentListIndex); - if(currentRow) { - if (currentRow->fChildList && (currentRow->fIsExpanded || !fOpenBranchesOnly) - && currentRow->fChildList->CountItems() > 0) { - // Visit child. - // Put current list on the stack if it needs to be revisited. - if (fCurrentListIndex < fCurrentList->CountItems() - 1) { - fStack[fStackIndex].fRowSet = fCurrentList; - fStack[fStackIndex].fIndex = fCurrentListIndex + 1; - fStack[fStackIndex].fDepth = fCurrentListDepth; - fStackIndex++; - } - - fCurrentList = currentRow->fChildList; - fCurrentListIndex = 0; - fCurrentListDepth++; - } else if (fCurrentListIndex < fCurrentList->CountItems() - 1) - fCurrentListIndex++; // next item in current list - else if (--fStackIndex >= 0) { - fCurrentList = fStack[fStackIndex].fRowSet; - fCurrentListIndex = fStack[fStackIndex].fIndex; - fCurrentListDepth = fStack[fStackIndex].fDepth; - } else - fCurrentList = 0; - } -} - - -int32 -RecursiveOutlineIterator::CurrentLevel() const -{ - return fCurrentListDepth; -} - - diff --git a/src/column/ColumnListView.h b/src/column/ColumnListView.h deleted file mode 100644 index 6b9a800..0000000 --- a/src/column/ColumnListView.h +++ /dev/null @@ -1,409 +0,0 @@ -/* -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 -#include -#include -#include -#include - -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 diff --git a/src/column/ColumnTypes.cpp b/src/column/ColumnTypes.cpp deleted file mode 100644 index f5efb23..0000000 --- a/src/column/ColumnTypes.cpp +++ /dev/null @@ -1,704 +0,0 @@ -/* -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 -#include -#include - -#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(_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(dynamic_cast(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(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(dynamic_cast(field)); -} - - diff --git a/src/column/ColumnTypes.h b/src/column/ColumnTypes.h deleted file mode 100644 index 9598c10..0000000 --- a/src/column/ColumnTypes.h +++ /dev/null @@ -1,289 +0,0 @@ -/* -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 -#include -#include - - -//===================================================================== -// 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 - diff --git a/src/column/ObjectList.h b/src/column/ObjectList.h deleted file mode 100644 index afb93d8..0000000 --- a/src/column/ObjectList.h +++ /dev/null @@ -1,800 +0,0 @@ -/* -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 -#endif - -#include - -template class BObjectList; - -template -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; -}; - -template -int -UnaryPredicate::_unary_predicate_glue(const void *item, void *context) -{ - return ((UnaryPredicate *)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 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 first - T *SwapWithItem(int32 index, T *newItem); - // same as ReplaceItem, except does not delete old item at , - // 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 &) const; - T *FindIf(const UnaryPredicate &); - - // 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 &); - - // unique insert, returns false if item already in list - bool BinaryInsertUnique(T *, CompareFunction); - bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state); - bool BinaryInsertUnique(T *, const UnaryPredicate &); - - // insert a copy of the item, returns new inserted item - T *BinaryInsertCopy(const T ©This, CompareFunction); - T *BinaryInsertCopy(const T ©This, 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 ©This, CompareFunction); - T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state); - - - int32 FindBinaryInsertionIndex(const UnaryPredicate &, 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 -Result -WhileEachListItem(BObjectList *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 -Result -WhileEachListItem(BObjectList *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 -Result -WhileEachListItem(BObjectList *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 -Result -WhileEachListItem(BObjectList *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 -Result -WhileEachListItem(BObjectList *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 -void -EachListItemIgnoreResult(BObjectList *list, Result (Item::*func)()) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (list->ItemAt(index)->*func)(); -} - -template -void -EachListItem(BObjectList *list, void (*func)(Item *, Param1), Param1 p1) -{ - int32 count = list->CountItems(); - for (int32 index = 0; index < count; index++) - (func)(list->ItemAt(index), p1); -} - -template -void -EachListItem(BObjectList *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 -void -EachListItem(BObjectList *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 -void -EachListItem(BObjectList *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 -void -EachListItem(BObjectList *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 -BObjectList::BObjectList(int32 itemsPerBlock, bool isOwning) - : _PointerList_(itemsPerBlock, isOwning) -{ -} - -template -BObjectList::BObjectList(const BObjectList &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 -BObjectList::~BObjectList() -{ - if (Owning()) - // have to nuke elements first - MakeEmpty(); - -} - -template -BObjectList & -BObjectList::operator=(const BObjectList &list) -{ - owning = list.owning; - BObjectList &result = (BObjectList &)_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 -bool -BObjectList::AddItem(T *item) -{ - // need to cast to void * to make T work for const pointers - return _PointerList_::AddItem((void *)item); -} - -template -bool -BObjectList::AddItem(T *item, int32 atIndex) -{ - return _PointerList_::AddItem((void *)item, atIndex); -} - -template -bool -BObjectList::AddList(BObjectList *newItems) -{ - return _PointerList_::AddList(newItems); -} - -template -bool -BObjectList::AddList(BObjectList *newItems, int32 atIndex) -{ - return _PointerList_::AddList(newItems, atIndex); -} - - -template -bool -BObjectList::RemoveItem(T *item, bool deleteIfOwning) -{ - bool result = _PointerList_::RemoveItem((void *)item); - - if (result && Owning() && deleteIfOwning) - delete item; - - return result; -} - -template -T * -BObjectList::RemoveItemAt(int32 index) -{ - return (T *)_PointerList_::RemoveItem(index); -} - -template -inline T * -BObjectList::ItemAt(int32 index) const -{ - return (T *)_PointerList_::ItemAt(index); -} - -template -bool -BObjectList::ReplaceItem(int32 index, T *item) -{ - if (owning) - delete ItemAt(index); - return _PointerList_::ReplaceItem(index, (void *)item); -} - -template -T * -BObjectList::SwapWithItem(int32 index, T *newItem) -{ - T *result = ItemAt(index); - _PointerList_::ReplaceItem(index, (void *)newItem); - return result; -} - -template -void -BObjectList::SetItem(int32 index, T *newItem) -{ - _PointerList_::ReplaceItem(index, (void *)newItem); -} - -template -int32 -BObjectList::IndexOf(const T *item) const -{ - return _PointerList_::IndexOf((void *)const_cast(item)); -} - -template -T * -BObjectList::FirstItem() const -{ - return (T *)_PointerList_::FirstItem(); -} - -template -T * -BObjectList::LastItem() const -{ - return (T *)_PointerList_::LastItem(); -} - -template -bool -BObjectList::HasItem(const T *item) const -{ - return _PointerList_::HasItem((void *)item); -} - -template -bool -BObjectList::IsEmpty() const -{ - return _PointerList_::IsEmpty(); -} - -template -int32 -BObjectList::CountItems() const -{ - return _PointerList_::CountItems(); -} - -template -void -BObjectList::MakeEmpty() -{ - if (owning) { - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - delete ItemAt(index); - } - _PointerList_::MakeEmpty(); -} - -template -T * -BObjectList::EachElement(EachFunction func, void *params) -{ - return (T *)_PointerList_::EachElement((GenericEachFunction)func, params); -} - - -template -const T * -BObjectList::EachElement(ConstEachFunction func, void *params) const -{ - return (const T *) - const_cast *>(this)->_PointerList_::EachElement( - (GenericEachFunction)func, params); -} - -template -const T * -BObjectList::FindIf(const UnaryPredicate &predicate) const -{ - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - if (predicate.operator()(ItemAt(index)) == 0) - return ItemAt(index); - return 0; -} - -template -T * -BObjectList::FindIf(const UnaryPredicate &predicate) -{ - int32 count = CountItems(); - for (int32 index = 0; index < count; index++) - if (predicate.operator()(ItemAt(index)) == 0) - return ItemAt(index); - return 0; -} - - -template -void -BObjectList::SortItems(CompareFunction function) -{ - _PointerList_::SortItems((GenericCompareFunction)function); -} - -template -void -BObjectList::SortItems(CompareFunctionWithState function, void *state) -{ - _PointerList_::SortItems((GenericCompareFunctionWithState)function, state); -} - -template -void -BObjectList::HSortItems(CompareFunction function) -{ - _PointerList_::HSortItems((GenericCompareFunction)function); -} - -template -void -BObjectList::HSortItems(CompareFunctionWithState function, void *state) -{ - _PointerList_::HSortItems((GenericCompareFunctionWithState)function, state); -} - -template -const T * -BObjectList::BinarySearch(const T &key, CompareFunction func) const -{ - return (const T *)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)func); -} - -template -const T * -BObjectList::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const -{ - return (const T *)_PointerList_::BinarySearch(&key, - (GenericCompareFunctionWithState)func, state); -} - -template -void -BObjectList::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 -void -BObjectList::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 -bool -BObjectList::BinaryInsertUnique(T *item, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(item, - (GenericCompareFunction)func); - if (index >= 0) - return false; - - AddItem(item, -index - 1); - return true; -} - -template -bool -BObjectList::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 -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); - - if (index >= 0) - index++; - else - index = -index - 1; - - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); - - if (index >= 0) - index++; - else - index = -index - 1; - - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunction func) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunction)func); - if (index >= 0) - return ItemAt(index); - - index = -index - 1; - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func, - void *state) -{ - int32 index = _PointerList_::BinarySearchIndex(©This, - (GenericCompareFunctionWithState)func, state); - if (index >= 0) - return ItemAt(index); - - index = -index - 1; - T *newItem = new T(copyThis); - AddItem(newItem, index); - return newItem; -} - -template -int32 -BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *alreadyInList) - const -{ - int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred, - (UnaryPredicateGlue)&UnaryPredicate::_unary_predicate_glue); - - if (alreadyInList) - *alreadyInList = index >= 0; - - if (index < 0) - index = -index - 1; - - return index; -} - -template -void -BObjectList::BinaryInsert(T *item, const UnaryPredicate &pred) -{ - int32 index = FindBinaryInsertionIndex(pred); - AddItem(item, index); -} - -template -bool -BObjectList::BinaryInsertUnique(T *item, const UnaryPredicate &pred) -{ - bool alreadyInList; - int32 index = FindBinaryInsertionIndex(pred, &alreadyInList); - if (alreadyInList) - return false; - - AddItem(item, index); - return true; -} - - -#endif diff --git a/src/column/YabColumnType.cpp b/src/column/YabColumnType.cpp deleted file mode 100644 index 566d94d..0000000 --- a/src/column/YabColumnType.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* -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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef ZETA - #include -#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); - int i; - i=32; - icon_size ics; - ics=(icon_size)i; - - fInfo.GetTrackerIcon( fBitmap, ics ); - //fInfo.GetTrackerIcon(fBitmap, B_MINI_ICON); - delete fNode; -#endif - } - - - else if( ! fString.FindFirst("__SmIC__=") ) - { - 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, 15, 15), B_RGBA32); - BNode *fNode = new BNode(myPath.String()); - BNodeInfo fInfo(fNode); - int i; - i=16; - icon_size ics; - ics=(icon_size)i; - - fInfo.GetTrackerIcon( fBitmap, ics ); - //fInfo.GetTrackerIcon(fBitmap, B_MINI_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(_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(_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(dynamic_cast(field)); -} - diff --git a/src/column/YabColumnType.h b/src/column/YabColumnType.h deleted file mode 100644 index e69e4d2..0000000 --- a/src/column/YabColumnType.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -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 -#include -#include -#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 diff --git a/src/config.h b/src/config.h deleted file mode 100644 index 19c3c09..0000000 --- a/src/config.h +++ /dev/null @@ -1,216 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#define BEOS -// #define LIBBSVG -#define BUILD_TIME __DATE__ -/* Version number of package */ -#define VERSION "1.7.8" -/* 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 and it should be used (not on Ultrix). - */ -#define HAVE_ALLOCA_H 1 - -/* Define to 1 if you have the 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 header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the 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 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 header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MATH_H 1 - -/* Define to 1 if you have the 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 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 header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STDINT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_STDIO_H 1 - -/* Define to 1 if you have the 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 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 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 header file. */ -#define HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define to 1 if you have the 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 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 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 and . */ -#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 does not define. */ -/* #undef pid_t */ - -/* Define to `unsigned' if does not define. */ -/* #undef size_t */ - -/* Define as `fork' if `vfork' does not work. */ -#define vfork fork - -#endif diff --git a/src/function.c b/src/function.c deleted file mode 100644 index 8b341d5..0000000 --- a/src/function.c +++ /dev/null @@ -1,2061 +0,0 @@ -/* - - YABASIC --- a simple Basic Interpreter - written by Marc-Oliver Ihm 1995-2004 - homepage: www.yabasic.de - - function.c --- code for functions - - 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 - -*/ - - -/* ------------- includes ---------------- */ -#include "YabInterface.h" -#ifndef YABASIC_INCLUDED -#include "yabasic.h" /* all prototypes and structures */ -#endif - - -/* ------------- external references ---------------- */ - -extern int mylineno; /* current line number */ -extern int yyparse(); /* call bison parser */ - - -/* ------------- local functions ---------------- */ - -static char *fromto(char *,int,int); /* get portion of string (mid$ et al) */ -static void clear_buff(); /* clear system-input buffers */ -static void store_buff(char *,int); /* store system-input buffer */ -static int do_glob(char *,char *); /* actually do the globbing */ -static double other2dec(char *,int); /* convert hex to decimal */ -static char *dec2other(double,int); /* convert decimal to hex */ -static double peek(char *, YabInterface *); /* peek into internals */ -static char *peek2(char *,struct command *); /* peek into internals */ -static char *peek3(char *,char *); /* peek into internals */ -static int peekfile(int); /* read a byte from stream */ -static char *do_system(char *); /* executes command via command.com */ -static int do_system2(char *); /* execute command as system */ - - -/* ------------- global variables ---------------- */ - -struct command *lastdata=NULL; /* used to associate all data-commands with each others */ -static struct buff_chain *buffroot; /* start of sys-input buffer */ -static struct buff_chain **buffcurr; /* current entry in buff_chain */ -static int buffcount; /* number of filled buffers */ - - -/* ------------- subroutines ---------------- */ - - -void token(struct command *cmd) /* extract token from variable */ -{ - int split; - struct stackentry *s; - struct symbol *sym; - struct array *ar; - int num=0,i; - char *p,*q; - char **pp; - char *del,*line; - int wasdel,isdel; - - - if (cmd->type==cSPLIT2 || cmd->type==cTOKEN2) - del=pop(stSTRING)->pointer; - else - del=" \t"; - split=(cmd->type==cSPLIT || cmd->type==cSPLIT2); - s=pop(stSTRINGARRAYREF); - line=pop(stSTRING)->pointer; - sym=get_sym(s->pointer,syARRAY,amSEARCH); - if (!sym || !sym->pointer) { - sprintf(string,"array '%s()' is not defined",strip(s->pointer)); - error(ERROR,string); - goto token_done; - } - ar=sym->pointer; - if (ar->dimension>1) { - error(ERROR,"only one dimensional arrays allowed"); - goto token_done; - } - - /* count number of tokens */ - isdel=TRUE; - if (split && *line) num=1; - else num=0; - for(p=line;*p;++p) { - wasdel=isdel; - isdel=(strchr(del,*p)!=NULL); - if (split) { - if (isdel) num++; - } else { - if (isdel && isdel!=wasdel) num++; - } - } - if (!split && !isdel) num++; - - /* free previous array content */ - for(i=0;ibounds[0];i++) free(((char **)ar->pointer)[i]); - free(ar->pointer); - ar->pointer=my_malloc((num+1)*sizeof(char *)); - pp=ar->pointer; - pp[0]=my_strdup(""); - - /* extract tokens */ - i=1; - isdel=TRUE; - if (*line) { - for(p=q=line;;p++) { - wasdel=isdel; - isdel=(strchr(del,*p)!=NULL) || !*p; - if ((split && isdel) || (!split && (isdel && isdel!=wasdel))) { - while(strchr(del,*q) && qbounds[0]=num+1; - token_done: - s=push(); - s->type=stNUMBER; - s->value=num; -} - - -void tokenalt(struct command *cmd) /* extract token from variable with alternate semantics */ -{ - char *del; /* delimiter for strings */ - struct stackentry *t; - char *old,*new,*tok; - int split; - - if (cmd->type==cSPLITALT2 || cmd->type==cTOKENALT2) - del=pop(stSTRING)->pointer; - else - del=" \t"; - split=(cmd->type==cSPLITALT || cmd->type==cSPLITALT2); - - t=pop(stSTRING); - old=t->pointer; - t->pointer=NULL; /* prevent push from freeing the memory */ - t=push(); - t->type=stSTRING; - new=old; - tok=NULL; - while(*new) { - if (!tok && (!strchr(del,*new) || split)) tok=new; /* found start of token */ - if (tok && strchr(del,*new)) break; /* found end of token */ - new++; - } - if (*new) { - *new='\0'; /* terminate token */ - new++; - if (!split) { - while(*new) { - if (!strchr(del,*new)) break; /* found start of next token */ - new++; - } - } - } - t->pointer=my_strdup(tok?tok:""); /* copy token */ - /* move rest of string */ - while(*new) { - *old=*new; - old++; - new++; - }; - *old='\0'; -} - - -void glob(void) /* check, if pattern globs string */ -{ - char *str,*pat; - struct stackentry *stack; - int res; - - pat=(char *)pop(stSTRING)->pointer; - str=(char *)pop(stSTRING)->pointer; - - res=do_glob(str,pat); - stack=push(); - stack->value=res; - stack->type=stNUMBER; -} - - -static int do_glob(char *str,char *pat) /* actually do the globbing */ -{ - int res; - - if (infolevel>=DEBUG) { - sprintf(string,"globbing '%s' on '%s'",str,pat); - error(DEBUG,string); - } - if (*pat=='\0' && *str=='\0') return TRUE; - else if (*pat=='\0') return FALSE; - else if (*pat=='?' && *str=='\0') return FALSE; - else if (*pat=='?') { - if (*str=='\0') return FALSE; - pat++; - str++; - } - else if (*pat=='*') { - pat++; - res=FALSE; - while(*str && !(res=do_glob(str,pat))) str++; - if (res) return TRUE; - } - else if (*str=='\0') return FALSE; - else { - while(*pat && *pat!='?' && *pat!='*') { - if (*pat!=*str) return FALSE; - str++; - pat++; - } - } - return do_glob(str,pat); -} - - -void concat() /* concatenates two strings from stack */ -{ - struct stackentry *c; - char *aa,*bb,*cc; - - aa=pop(stSTRING)->pointer; - bb=pop(stSTRING)->pointer; - cc=(char *) my_malloc(sizeof(char)*(strlen(aa)+strlen(bb)+1)); - strcpy(cc,bb); - strcat(cc,aa); - c=push(); - c->type=stSTRING; - c->pointer=cc; -} - - -void create_changestring(int type) /* create command 'changestring' */ -{ - struct command *cmd; - - cmd=add_command(cCHANGESTRING,FALSE); - cmd->args=type; -} - - -void changestring(struct command *current) /* changes a string */ -{ - int type,a2,a3; - char *newpart; - char *oldstring; - int i,len; - struct stackentry *a1; - - type=current->args; - newpart=pop(stSTRING)->pointer; - if (type>fTWOARGS) a3=(int)pop(stNUMBER)->value; - if (type>fONEARGS) a2=(int)pop(stNUMBER)->value; - a1=pop(stSTRING); - oldstring=a1->pointer; - a1->pointer=NULL; /* this prevents push from freeing the memory */ - - if (!oldstring || !*oldstring) return; - switch(type) { - case fMID: - for(i=1;i=a2) { - if (!newpart[i-a2]) break; - oldstring[i-1]=newpart[i-a2]; - } - } - break; - case fMID2: - len=strlen(oldstring); - for(i=1;i<=len;i++) { - if (!oldstring[i-1]) break; - if (i>=a2) { - if (!newpart[i-a2]) break; - oldstring[i-1]=newpart[i-a2]; - } - } - break; - case fLEFT: - for(i=1;i<=a2;i++) { - if (!oldstring[i-1] || !newpart[i-1]) break; - oldstring[i-1]=newpart[i-1]; - } - break; - case fRIGHT: - len=strlen(oldstring); - for(i=1;i<=len;i++) { - if (i>len-a2) { - if (!newpart[i-1-len+a2]) break; - oldstring[i-1]=newpart[i-1-len+a2]; - } - } - break; - } -} - - -void create_function(int type) /* create command 'function' */ -/* type can be sin,cos,mid$ ... */ -{ - struct command *cmd; - - cmd=add_command(cFUNCTION,FALSE); - cmd->args=type; -} - - -void function(struct command *current,YabInterface* yab) /* performs a function */ -{ - struct stackentry *stack,*a1,*a2,*a3,*a4,*a5,*a6; - char *pointer; - double value; - time_t datetime; - int type,result,len,start,i,max, linenum; - char *str,*str2, *str3, *str4, *str5; - - a3=NULL; - a4=NULL; - a5=NULL; - a6=NULL; - type=current->args; - if (type>fFIVEARGS) a6=pop(stSTRING_OR_NUMBER); - if (type>fFOURARGS) a5=pop(stSTRING_OR_NUMBER); - if (type>fTHREEARGS) a4=pop(stSTRING_OR_NUMBER); - if (type>fTWOARGS) a3=pop(stSTRING_OR_NUMBER); - if (type>fONEARGS) a2=pop(stSTRING_OR_NUMBER); - if (type>fZEROARGS) a1=pop(stSTRING_OR_NUMBER); - linenum = current->line; - - switch (type) { - case fSIN: - value=sin(a1->value); - result=stNUMBER; - break; - case fASIN: - value=asin(a1->value); - result=stNUMBER; - break; - case fCOS: - value=cos(a1->value); - result=stNUMBER; - break; - case fACOS: - value=acos(a1->value); - result=stNUMBER; - break; - case fTAN: - value=tan(a1->value); - result=stNUMBER; - break; - case fATAN: - value=atan(a1->value); - result=stNUMBER; - break; - case fEXP: - value=exp(a1->value); - result=stNUMBER; - break; - case fLOG: - value=log(a1->value); - result=stNUMBER; - break; - case fLOG2: - value=log(a1->value)/log(a2->value); - result=stNUMBER; - break; - case fLEN: - value=(double) strlen(a1->pointer); - result=stNUMBER; - break; - case fSTR: - sprintf(string,"%g",a1->value); - pointer=my_strdup(string); - result=stSTRING; - break; - case fSTR2: - case fSTR3: - result=stSTRING; - if (!myformat(string,a1->value,a2->pointer,a3?a3->pointer:NULL)) { - pointer=my_strdup(""); - sprintf(string,"'%s' is not a valid format",(char *)a2->pointer); - error(ERROR,string); - break; - } - pointer=my_strdup(string); - break; - case fSQRT: - value=sqrt(a1->value); - result=stNUMBER; - break; - case fSQR: - value=a1->value*a1->value; - result=stNUMBER; - break; - case fINT: - if (a1->value<0) - value=-floor(-a1->value); - else - value=floor(a1->value); - result=stNUMBER; - break; - case fFRAC: - if (a1->value<0) - value=a1->value+floor(-a1->value); - else - value=a1->value-floor(a1->value); - result=stNUMBER; - break; - case fABS: - value=fabs(a1->value); - result=stNUMBER; - break; - case fSIG: - if (a1->value<0) value=-1.; - else if (a1->value>0) value=1.; - else value=0.; - result=stNUMBER; - break; - case fMOD: - value=a1->value-a2->value*(int)(a1->value/a2->value); - result=stNUMBER; - break; - case fRAN: - value=a1->value*((double)rand()/RAND_MAX); - result=stNUMBER; - break; - case fRAN2: - value=(double)rand()/RAND_MAX; - result=stNUMBER; - break; - case fMIN: - if (a1->value>a2->value) - value=a2->value; - else - value=a1->value; - result=stNUMBER; - break; - case fMAX: - if (a1->value>a2->value) - value=a1->value; - else - value=a2->value; - result=stNUMBER; - break; - case fVAL: - i=sscanf((char *) a1->pointer,"%lf",&value); - if (i!=1) value=0; - result=stNUMBER; - break; - case fATAN2: - value=atan2(a1->value,a2->value); - result=stNUMBER; - break; - case fLEFT: - str=a1->pointer; - len=(int)a2->value; - pointer=fromto(str,0,len-1); - result=stSTRING; - break; - case fRIGHT: - str=a1->pointer; - max=strlen(str); - len=(int)a2->value; - pointer=fromto(str,max-len,max-1); - result=stSTRING; - break; - case fMID: - str=a1->pointer; - start=(int)a2->value; - len=(int)a3->value; - pointer=fromto(str,start-1,start+len-2); - result=stSTRING; - break; - case fMID2: - str=a1->pointer; - start=(int)a2->value; - pointer=fromto(str,start-1,strlen(str)); - result=stSTRING; - break; - case fINKEY: - pointer=inkey(a1->value); - result=stSTRING; - break; - case fAND: - value=(int)a1->value & (int)a2->value; - result=stNUMBER; - break; - case fOR: - value=(int)a1->value | (int)a2->value; - result=stNUMBER; - break; - case fEOR: - value=(int)a1->value ^ (int)a2->value; - result=stNUMBER; - break; -/* - case fMOUSEX: - getmousexybm(a1->pointer,&i,NULL,NULL,NULL); - value=i; - result=stNUMBER; - break; - case fMOUSEY: - getmousexybm(a1->pointer,NULL,&i,NULL,NULL); - value=i; - result=stNUMBER; - break; - case fMOUSEB: - getmousexybm(a1->pointer,NULL,NULL,&i,NULL); - value=i; - result=stNUMBER; - break; - case fMOUSEMOD: - getmousexybm(a1->pointer,NULL,NULL,NULL,&i); - value=i; - result=stNUMBER; - break;*/ - case fCHR: - pointer=my_malloc(2); - i=(int)floor(a1->value); - if (i>255 || i<0) { - sprintf(string,"can't convert %g to character",a1->value); - error(ERROR,string); - return; - } - pointer[1]='\0'; - pointer[0]=(unsigned char)i; - result=stSTRING; - break; - case fASC: - value=((unsigned char *)a1->pointer)[0]; - result=stNUMBER; - break; - case fBIN: - pointer=dec2other(a1->value,2); - result=stSTRING; - break; - case fHEX: - pointer=dec2other(a1->value,16); - result=stSTRING; - break; - case fDEC: - value=other2dec(a1->pointer,16); - result=stNUMBER; - break; - case fDEC2: - value=other2dec(a1->pointer,(int)(a2->value)); - result=stNUMBER; - break; - case fUPPER: - str=a1->pointer; - pointer=my_malloc(strlen(str)+1); - i=-1; - do { - i++; - pointer[i]=toupper((int)str[i]); - } while(pointer[i]); - result=stSTRING; - break; - case fLOWER: - str=a1->pointer; - pointer=my_malloc(strlen(str)+1); - i=-1; - do { - i++; - pointer[i]=tolower((int)str[i]); - } while(pointer[i]); - result=stSTRING; - break; - case fLTRIM: - str=a1->pointer; - while(isspace(*str)) str++; - pointer=my_strdup(str); - result=stSTRING; - break; - case fRTRIM: - str=a1->pointer; - i=strlen(str)-1; - while(isspace(str[i]) && i>=0) i--; - str[i+1]='\0'; - pointer=my_strdup(str); - result=stSTRING; - break; - case fTRIM: - str=a1->pointer; - i=strlen(str)-1; - while(isspace(str[i]) && i>=0) i--; - str[i+1]='\0'; - while(isspace(*str)) str++; - pointer=my_strdup(str); - result=stSTRING; - break; - case fINSTR: - str=a1->pointer; - str2=a2->pointer; - if (*str2) - pointer=strstr(str,str2); - else - pointer=NULL; - if (pointer==NULL) - value=0; - else - value=pointer-str+1; - result=stNUMBER; - break; - case fINSTR2: - str=a1->pointer; - str2=a2->pointer; - start=(int)a3->value; - if (start>strlen(str)) { - value=0; - } else { - if (start<1) start=1; - pointer=strstr(str+start-1,str2); - if (pointer==NULL) - value=0; - else - value=pointer-str+1; - } - result=stNUMBER; - break; - case fRINSTR: - str=a1->pointer; - str2=a2->pointer; - len=strlen(str2); - for(i=strlen(str)-1;i>=0;i--) if (!strncmp(str+i,str2,len)) break; - value=i+1; - result=stNUMBER; - break; - case fRINSTR2: - str=a1->pointer; - str2=a2->pointer; - len=strlen(str2); - start=(int)a3->value; - if (start<1) { - value=0; - } else { - if (start>strlen(str)) start=strlen(str); - for(i=start-1;i;i--) if (!strncmp(str+i,str2,len)) break; - value=i+1; - } - result=stNUMBER; - break; - case fDATE: - pointer=my_malloc(100); - time(&datetime); - strftime(pointer,100,"%w-%m-%d-%Y-%a-%b",localtime(&datetime)); - result=stSTRING; - break; - case fTIME: - pointer=my_malloc(100); - time(&datetime); - strftime(pointer,100,"%H-%M-%S",localtime(&datetime)); - sprintf(pointer+strlen(pointer),"-%d", - (int)(time(NULL)-compilation_start)); - result=stSTRING; - break; - case fSYSTEM: - str=a1->pointer; - pointer=do_system(str); - result=stSTRING; - break; - case fSYSTEM2: - str=a1->pointer; - value=do_system2(str); - result=stNUMBER; - break; - case fPEEK: - str=a1->pointer; - value=peek(str, yab); - result=stNUMBER; - break; - case fPEEK2: - str=a1->pointer; - pointer=peek2(str,current); - result=stSTRING; - break; - case fPEEK3: - str=a1->pointer; - str2=a2->pointer; - pointer=peek3(str,str2); - result=stSTRING; - break; - case fPEEK4: - value=peekfile((int)a1->value); - result=stNUMBER; - break; - case fGETCHAR: - pointer=getchars((int)a1->value,(int)a2->value,(int)a3->value,(int)a4->value); - result=stSTRING; - break; - case fTELL: - i=(int)(a1->value); - if (badstream(i,0)) return; - if (!(stream_modes[i] & (smREAD | smWRITE| smREADWRITE))) { - sprintf(string,"stream %d not opened",i); - error(ERROR,string); - value=0; - } else { - value=ftell(streams[i]); - } - result=stNUMBER; - break; - case fMESSAGE: - pointer = getmessages(yab,linenum, current->lib->s); - result = stSTRING; - break; - case fMOUSE: - str = a1->pointer; - pointer = getmousemessages(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTRANSLATE: - str = a1->pointer; - pointer = gettranslation(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fMENUTRANSLATE: - str = a1->pointer; - pointer = getmenutranslation(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTEXTGET: - str = a1->pointer; - pointer = textget(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTEXTGET3: - str = a1->pointer; - pointer = textget3(str,a2->value,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTEXTGET6: - str = a1->pointer; - str2 = a2->pointer; - pointer = textget6(str,str2,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTEXTCONTROLGET: - str = a1->pointer; - pointer = textcontrolget(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fNUMWINDOWS: - value = numwindows(); - result = stNUMBER; - break; - case fISMOUSEIN: - str = a1->pointer; - value = ismousein(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fMOUSEMOVE: //vasper - pointer = getmousein(yab,linenum, current->lib->s); - result = stSTRING; - break; - case fDRAWIMAGE: - str=a3->pointer; - str2=a4->pointer; - value = createimage(a1->value,a2->value,str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDRAWIMAGE2: - str=a5->pointer; - str2=a6->pointer; - value = createimage2(a1->value,a2->value,a3->value,a4->value,str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDRAWSVG: - str=a5->pointer; - str2=a6->pointer; - value = createsvg(a1->value,a2->value,a3->value,a4->value,str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fLOAD: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - pointer = getloadfilepanel(str,str2,str3,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fSAVE: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - str4=a4->pointer; - pointer = getsavefilepanel(str,str2,str3,str4,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fKEYBOARD: - str=a1->pointer; - pointer = keyboardmessages(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fCLIPBOARDPASTE: - pointer = clipboardpaste(yab,linenum, current->lib->s); - result = stSTRING; - break; - case fCOLUMNBOXGET: - str=a1->pointer; - pointer = columnboxget(str,a2->value,a3->value,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fLISTBOXGET: - str=a1->pointer; - pointer = listboxget(str,a2->value,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTREEBOXGET: - str=a1->pointer; - pointer = treeboxget(str,a2->value,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fTEXTGET2: - str=a1->pointer; - str2=a2->pointer; - value = textget2(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fTEXTGET4: - str=a1->pointer; - str2=a2->pointer; - value = textget4(str,str2,a3->value,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fTEXTGET5: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - value = textget5(str,str2,str3,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fPOPUPMENU: - str=a3->pointer; - str2=a4->pointer; - pointer = popupmenu(a1->value, a2->value, str, str2,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fSCROLLBARGET: - str=a1->pointer; - str2=a2->pointer; - value = scrollbarget(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fSPLITVIEWGET: - str=a1->pointer; - str2=a2->pointer; - value = splitviewget(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fSTACKVIEWGET: - str=a1->pointer; - value = stackviewget(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fTABVIEWGET: - str=a1->pointer; - value = tabviewget(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fSPINCONTROLGET: - str=a1->pointer; - value = spincontrolget(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fLISTBOXCOUNT: - str=a1->pointer; - value = listboxcount(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fTREEBOXCOUNT: - str=a1->pointer; - value = treeboxcount(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDROPBOXCOUNT: - str=a1->pointer; - value = dropboxcount(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDROPBOXGET: - str=a1->pointer; - pointer = dropboxget(str,a2->value,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fDRAWGET3: - str=a1->pointer; - pointer = drawget3(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fSLIDERGET: - str=a1->pointer; - value = sliderget(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fCOLORCONTROLGET: - str=a1->pointer; - str2=a2->pointer; - value = colorcontrolget(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fCALENDAR: - str=a1->pointer; - pointer = calendar2(str,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fCOLUMNBOXCOUNT: - str=a1->pointer; - value = columnboxcount(str,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fWINDOWGET: - str=a1->pointer; - str2=a2->pointer; - value = windowgetnum(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fVIEWGET: //vasper - str=a1->pointer; - str2=a2->pointer; - value = viewgetnum(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDRAWGET1: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - value = drawget1(str,str2,str3,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDRAWGET2: - str=a1->pointer; - str2=a2->pointer; - value = drawget2(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fDRAWGET4: - str=a3->pointer; - str2=a4->pointer; - value = drawget4(a1->value, a2->value, str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fLISTBOXGETNUM: - str=a1->pointer; - value = listboxgetnum(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fDROPBOXGETNUM: - str=a1->pointer; - value = dropboxgetnum(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fTREEBOXGETNUM: - str=a1->pointer; - value = treeboxgetnum(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fCOLUMNBOXGETNUM: - str=a1->pointer; - value = columnboxgetnum(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fBITMAPLOAD: - str=a1->pointer; - str2=a2->pointer; - value = bitmapload(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fBITMAPGET: - str=a1->pointer; - str2=a2->pointer; - value = bitmapgetnum(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fBITMAPCOLOR: - str = a3->pointer; - str2 = a4->pointer; - value = bitmapcolor(a1->value, a2->value, str, str2, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fBITMAPSAVE: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - value = bitmapsave(str,str2,str3,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fSOUND: - str=a1->pointer; - value = sound(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fMEDIASOUND: - str=a1->pointer; - value = mediasound(str, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fTREEBOXGETOPT: - str=a1->pointer; - str2=a2->pointer; - value = treeboxgetopt(str, str2, a3->value, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fTHREADKILL: - str=a1->pointer; - value = threadkill(str, a2->value, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fTHREADGET: - str=a1->pointer; - str2=a2->pointer; - value = threadget(str, str2, yab, linenum, current->lib->s); - result = stNUMBER; - break; - case fALERT: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - str4=a4->pointer; - str5=a5->pointer; - value = newalert(str,str2,str3,str4,str5,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fPRINTER: - str=a1->pointer; - str2=a2->pointer; - str3=a3->pointer; - value = printer(str,str2,str3,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fISCOMPUTERON: - value = iscomputeron(yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fMESSAGESEND: - str=a1->pointer; - str2=a2->pointer; - value = messagesend(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - case fATTRIBUTEGET1: - str=a1->pointer; - str2=a2->pointer; - pointer = attributeget1(str,str2,yab,linenum, current->lib->s); - result = stSTRING; - break; - case fATTRIBUTEGET2: - str=a1->pointer; - str2=a2->pointer; - value = attributeget2(str,str2,yab,linenum, current->lib->s); - result = stNUMBER; - break; - default: - error(ERROR,"function called but not implemented"); - return; - } - - stack=push(); - /* copy result */ - stack->type=result; - if (result==stSTRING) - stack->pointer=pointer; - else - stack->value=value; -} - - -static int do_system2(char *cmd) /* execute command as system */ -{ -#ifdef UNIX - int ret; - #ifdef BUILD_NCURSES - if (curinized) reset_shell_mode(); - #endif - ret=system(cmd); - #ifdef BUILD_NCURSES - if (curinized) reset_prog_mode(); - #endif - return ret; -#else - STARTUPINFO start; - PROCESS_INFORMATION proc; - DWORD ec; /* exit code */ - SECURITY_ATTRIBUTES prosec; - SECURITY_ATTRIBUTES thrsec; - char *comspec; - - ZeroMemory(&prosec,sizeof(prosec)); - prosec.nLength=sizeof(prosec); - prosec.bInheritHandle=TRUE; - ZeroMemory(&thrsec,sizeof(thrsec)); - thrsec.nLength=sizeof(thrsec); - thrsec.bInheritHandle=TRUE; - ZeroMemory(&start,sizeof(start)); - start.cb=sizeof(STARTUPINFO); - start.dwFlags=STARTF_USESTDHANDLES; - start.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE); - start.hStdError=GetStdHandle(STD_ERROR_HANDLE); - start.hStdInput=GetStdHandle(STD_INPUT_HANDLE); - comspec=getenv("COMSPEC"); - if (!comspec) comspec="command.com"; - sprintf(string,"%s /C %s",comspec,cmd); - if (!CreateProcess(NULL,string,&prosec,&thrsec,TRUE,0, - NULL,NULL,&start,&proc)) { - sprintf(string,"couldn't execute '%s'",cmd); - error(ERROR,string); - return -1; - } - WaitForSingleObject(proc.hProcess,INFINITE); - if (!GetExitCodeProcess(proc.hProcess,&ec)) ec=-1; - CloseHandle(proc.hProcess); - CloseHandle(proc.hThread); - return ec; -#endif -} - - -static void clear_buff() /* clear system-input buffers */ -{ - buffcurr=&buffroot; - buffcount=0; -} - - -static void store_buff(char *buff,int len) /* store system-input buffer */ -{ - *buffcurr=my_malloc(sizeof(struct buff_chain)); - memcpy((*buffcurr)->buff,buff,SYSBUFFLEN+1); - (*buffcurr)->len=len; - buffcurr=&((*buffcurr)->next); - buffcount++; -} - - -char *recall_buff() /* recall store buffer */ -{ - struct buff_chain *curr,*old; - char *result; - int done,len; - - result=(char *)my_malloc(buffcount*(SYSBUFFLEN+1)); - curr=buffroot; - len=0; - for(done=0;donebuff,SYSBUFFLEN); - len+=curr->len; - old=curr; - curr=curr->next; - my_free(old); - } - return result; -} - - -static char *do_system(char *cmd) /* executes command via command.com */ -{ - static char buff[SYSBUFFLEN+1]; /* buffer to store command */ - int len; /* number of bytes read */ -#ifdef UNIX - FILE *p; /* points to pipe */ - int c; /* char read from pipe */ -#else - int ret; - STARTUPINFO start; - PROCESS_INFORMATION proc; - HANDLE piperead,pipewrite; /* both ends of pipes */ - SECURITY_ATTRIBUTES prosec; - SECURITY_ATTRIBUTES thrsec; - char *comspec; -#endif - - clear_buff(); - -#ifdef UNIX - p=popen(cmd,"r"); - if (p==NULL) { - sprintf(string,"couldn't execute '%s'",cmd); - error(ERROR,string); - return my_strdup(""); - } - do { - len=0; - while(len0) store_buff(buff,len); - } while(ret!=ERROR_BROKEN_PIPE && ret!=ERROR_HANDLE_EOF); - CloseHandle(piperead); - CloseHandle(proc.hProcess); - CloseHandle(proc.hThread); -#endif - return recall_buff(); -} - - -void getmousexybm(char *s,int *px,int *py,int *pb,int *pm) /* get mouse coordinates */ -{ - int x=0,y=0,b=0,m=0; - char c; - - if (*s) { - sscanf(s,"MB%d%c+%d:%04d,%04d",&b,&c,&m,&x,&y); - if (px) *px=x; - if (py) *py=y; - if (pb) { - if (c=='d') - *pb=b; - else - *pb=-b; - } - if (pm) *pm=m; - return; - } -/* - if (px) *px=mousex; - if (py) *py=mousey; - if (pb) *pb=mouseb; - if (pm) *pm=mousemod;*/ -} - - -static char *dec2other(double d,int base) /* convert double to hex or binary number */ -{ - int len; - double dec,dec2; - char *other; - int negative=FALSE; - - if (d<0) { - dec2=floor(-d); - negative=TRUE; - } else { - dec2=floor(d); - } - len=negative?2:1; - for(dec=dec2;dec>=base;dec/=base) len++; - other=my_malloc(len+1); - other[len]='\0'; - dec=dec2; - for(len--;len>=0;len--) { - other[len]="0123456789abcdef"[(int)(floor(dec-base*floor(dec/base)+0.5))]; - dec=floor(dec/base); - } - if (negative) other[0]='-'; - return other; -} - - -static double other2dec(char *hex,int base) /* convert hex or binary to double number */ -{ - double dec; - static char *digits="0123456789abcdef"; - char *found; - int i,len; - - if (base!=2 && base !=16) { - sprintf(string,"Cannot convert base-%d numbers",base); - error(ERROR,string); - return 0.; - } - dec=0; - len=strlen(hex); - for(i=0;i=base) { - sprintf(string,"Not a base-%d number: '%s'",base,hex); - error(ERROR,string); - return 0.; - } - dec+=found-digits; - } - return dec; -} - - -int myformat(char *dest,double num,char *format,char *sep) /* format number according to string */ -{ - int i1,i2; /* dummy */ - char c1; /* dummy */ - static char ctrl[6]; - char *found,*form; - int pre,post,dot,len,i,j,digit,colons,dots; - int neg=FALSE; - double ip,fp,round; - static char *digits="0123456789"; - - form=format; - if (*form=='%') { /* c-style format */ - strcpy(ctrl,"+- #0"); /* allowed control chars for c-format */ - form++; - while((found=strchr(ctrl,*form))!=NULL) { - *found='?'; - form++; - } - if (sscanf(form,"%u.%u%c%n",&i1,&i2,&c1,&i)!=3 && - sscanf(form,"%u.%c%n",&i2,&c1,&i)!=2 && - sscanf(form,".%u%c%n",&i2,&c1,&i)!=2 && - sscanf(form,"%u%c%n",&i2,&c1,&i)!=2) return FALSE; - if (!strchr("feEgG",c1) || form[i]) return FALSE; - /* seems okay, let's print */ - sprintf(dest,format,num); - } else { /* basic-style format */ - if (num<0) { - neg=TRUE; - num=-num; - } - colons=0; - dots=0; - pre=0; - post=0; - for(form=format;*form;form++) { - if (*form==',') { - if (dots) return FALSE; - colons++; - } else if (*form=='.') { - dots++; - } else if (*form=='#') { - if (dots) - post++; - else - pre++; - } else { - return FALSE; - } - } - if (dots>1) return FALSE; - len=strlen(format); - dest[len]='\0'; - round=0.5; - for(i=0;i1 || fp<0) fp=0; - dest[pre+colons]=format[pre+colons]; - if ((int)ip) { - for(i=pre+colons-1;i>=0;i--) { - if (neg && !(int)ip) { - neg=0; - dest[i]='-'; - } else { - if (format[i]=='#') { - digit=((int)ip)%10; - ip/=10; - if (((int)ip) || digit>0) - dest[i]=digits[digit]; - else - dest[i]=' '; - } else { - if ((int)ip) - dest[i]=format[i]; - else - dest[i]=' '; - } - } - } - } else { - i=pre+colons-1; - dest[i--]='0'; - } - if ((neg && i<0) || ((int)ip)) { - strcpy(dest,format); - return TRUE; - } - if (neg) dest[i--]='-'; - for(;i>=0;i--) dest[i]=' '; - for(i=pre+colons+1;ito || to<0 || from>len-1) { - /* give back empty string */ - part=my_malloc(1); - part[0]='\0'; - } - else { - if (from<=0) from=0; - if (to>=len) to=len-1; - part=my_malloc(sizeof(char)*(to-from+2)); /* characters and '/0' */ - for(i=from;i<=to;i++) part[i-from]=str[i]; /* copy */ - part[i-from]='\0'; - } - return part; -} - - - -void mywait() /* wait given number of seconds */ -{ - double delay; - -#ifdef UNIX - struct timeval tv; -#else - MSG msg; - int timerid; -#endif - - delay=pop(stNUMBER)->value; - if (delay<0) delay=0.; -#ifdef UNIX - tv.tv_sec=(int)delay; - tv.tv_usec=(delay-(int)delay)*1000000; - select(0,NULL,NULL,NULL,&tv); -#else /* WINDOWS */ - timerid=SetTimer(NULL,0,(int)(delay*1000),(TIMERPROC) NULL); - GetMessage((LPMSG)&msg,NULL,WM_TIMER,WM_TIMER); - KillTimer(NULL,timerid); -#endif -} - - -void mybell() /* ring ascii bell */ -{ -#ifdef UNIX -#ifdef BEOS - yi_beep(); -#else - printf("\007"); - fflush(stdout); -#endif -#else /* WINDOWS */ - Beep(1000,100); -#endif -} - - - -void create_poke(char flag) /* create Command 'cPOKE' */ -{ - struct command *cmd; - - if (flag=='S' || flag=='D') - cmd=add_command(cPOKEFILE,FALSE); - else - cmd=add_command(cPOKE,FALSE); - cmd->tag=flag; -} - - -void poke(struct command *cmd) /* poke into internals */ -{ - char *dest,*s,c; - char *sarg=NULL; - double darg; - - if (cmd->tag=='s') - sarg=pop(stSTRING)->pointer; - else - darg=pop(stNUMBER)->value; - - dest=pop(stSTRING)->pointer; - for(s=dest;*s;s++) *s=tolower((int)*s); - /* - if (!strcmp(dest,"fontheight") && !sarg) { - fontheight=(int)darg; -#ifdef UNIX - calc_psscale(); -#endif - } - else if (!strcmp(dest,"font") && sarg) { - font=my_strdup(sarg); - } */ - if (!strcmp(dest,"dump") && sarg && !strcmp(sarg,"symbols")) { - dump_sym(); - } - else if (!strcmp(dest,"dump") && sarg && - (!strcmp(sarg,"sub") || !strcmp(sarg,"subs") || !strcmp(sarg,"subroutine") || !strcmp(sarg,"subroutines"))) { - dump_sub(0); - } - /* - else if (!strcmp(dest,"winwidth") && !sarg) { - winwidth=(int)darg; - if (winwidth<1) { - error(ERROR,"winwidth less than 1 pixel"); - return; - } -#ifdef UNIX - calc_psscale(); -#endif - } - else if (!strcmp(dest,"winheight") && !sarg) { - winheight=(int)darg; - if (winheight<1) { - error(ERROR,"winheight less than 1 pixel"); - return; - } -#ifdef UNIX - calc_psscale(); -#endif - } - else if (!strcmp(dest,"textalign") && sarg) { - if (!check_alignement(sarg)) return; - strncpy(text_align,sarg,2); - } - else if (!strcmp(dest,"windoworigin") && sarg) { - moveorigin(sarg); - }*/ - else if (!strcmp(dest,"infolevel") && sarg) { - c=tolower((int)*sarg); - switch(c) { - case 'd': infolevel=DEBUG;break; - case 'n': infolevel=NOTE;break; - case 'w': infolevel=WARNING;break; - case 'e': infolevel=ERROR;break; - case 'f': infolevel=FATAL;break; - default: - error(ERROR,"invalid infolevel"); - return; - } - if (infolevel>=DEBUG) { - sprintf(string,"switching infolevel to '%c'",c); - error(DEBUG,string); - } - } - else if (!strcmp(dest,"stdout") && sarg) { - fputs(sarg,stdout); - } - else if (!strcmp(dest,"read_controls") && !sarg) { - read_controls= darg ? 1:0; - } - else if (dest[0]=='#') { - error(ERROR,"don't use quotes when poking into file"); - } - else { - error(ERROR,"invalid poke"); - } - return; -} - - -void pokefile(struct command *cmd) /* poke into file */ -{ - char *sarg=NULL; - double darg; - int stream; - - if (cmd->tag=='S') - sarg=pop(stSTRING)->pointer; - else - darg=pop(stNUMBER)->value; - stream=(int)(pop(stNUMBER)->value); - - if (badstream(stream,0)) return; - - if (!(stream_modes[stream] & smWRITE)) { - sprintf(string,"Stream %d not open for writing",stream); - error(ERROR,string); - return; - } - if (sarg) { - fputs(sarg,streams[stream]); - } else { - if (darg<0 || darg>255) { - error(ERROR,"stream poke out of byte range (0..255)"); - return; - } - fputc((int)darg,streams[stream]); - } -} - - -static double peek(char *dest, YabInterface *yab) /* peek into internals */ -{ - char *s; - - for(s=dest;*s;s++) *s=tolower((int)*s); - /*if (!strcmp(dest,"winwidth")) return winwidth; - else if (!strcmp(dest,"winheight")) return winheight; - else if (!strcmp(dest,"fontheight")) return fontheight; - else*/ - if (!strcmp(dest,"screenheight")) return LINES; - else if (!strcmp(dest,"screenwidth")) return COLS; - else if (!strcmp(dest, "deskbarposition")) return yi_DeskbarPosition(yab); //deskbarposition; - else if (!strcmp(dest, "deskbarexpanded")) return yi_DeskbarExpanded(yab); //deskbarexpanded; - else if (!strcmp(dest, "deskbarwidth")) return yi_DeskbarWidth(yab); //deskbarwidth; - else if (!strcmp(dest, "deskbarheight")) return yi_DeskbarHeight(yab); //deskbarheight; - else if (!strcmp(dest, "deskbar-x")) return yi_DeskbarX(yab); //deskbar-x; - else if (!strcmp(dest, "deskbar-y")) return yi_DeskbarY(yab); //deskbar-y; - else if (!strcmp(dest, "desktopwidth")) return yi_DesktopWidth(yab); //desktopwidth; - else if (!strcmp(dest, "desktopheight")) return yi_DesktopHeight(yab); //desktopheight; - else if (!strcmp(dest, "scrollbarwidth")) return yi_ScrollbarWidth(yab); // scrollbarwidth - else if (!strcmp(dest, "menuheight")) return yi_MenuHeight(yab); // menuheight - else if (!strcmp(dest, "tabheight")) return yi_TabHeight(yab); // tabheight - else if (!strcmp(dest,"argument") || !strcmp(dest,"arguments") ) return yabargc; // number of arguments - else if (!strcmp(dest,"version")) return strtod(VERSION,NULL); - else if (!strcmp(dest,"error")) return errorcode; - else if (!strcmp(dest,"read_controls")) return read_controls; - else if (!strcmp(dest,"isbound")) return is_bound; - - - else if (dest[0]=='#') { - error(ERROR,"don't use quotes when peeking into a file"); - return 0; - } - - sprintf(stderr, "PEEK is set to %s\n", dest); - error(ERROR,"invalid peek"); - return 0; -} - - -static int peekfile(int stream) /* read a byte from stream */ -{ - if (stream && badstream(stream,0)) return 0; - if (stream && !(stream_modes[stream] & smREAD | smREADWRITE)) { - sprintf(string,"stream %d not open for reading",stream); - error(ERROR,string); - return 0; - } - return fgetc(stream?streams[stream]:stdin); -} - - -static char *peek2(char *dest,struct command *curr) /* peek into internals */ -{ - char *s; - - - for(s=dest;*s;s++) *s=tolower((int)*s); - if (!strcmp(dest,"infolevel")) { - if (infolevel==DEBUG) return my_strdup("debug"); - else if (infolevel==NOTE) return my_strdup("note"); - else if (infolevel==WARNING) return my_strdup("warning"); - else if (infolevel==ERROR) return my_strdup("error"); - else if (infolevel==FATAL) return my_strdup("fatal"); - else return my_strdup("unkown"); - } - /* - else if (!strcmp(dest,"textalign")) return my_strdup(text_align); - else if (!strcmp(dest,"windoworigin")) return my_strdup(winorigin);*/ - else if (!strcmp(dest,"error")) return my_strdup(errorstring); - else if (!strcmp(dest,"library")) return my_strdup(curr->lib->s); - else if (!strcmp(dest,"os")) { -#ifdef HAIKU - return my_strdup("Haiku"); -#else - return my_strdup("BeOS"); -#endif - } - else if (!strcmp(dest,"directory")) return my_strdup(appdirectory); - else if (!strcmp(dest,"refsreceived")) return my_strdup(refsRec); - /* else if (!strcmp(dest,"font")) return my_strdup(font); */ - else if (!strcmp(dest,"argument") || !strcmp(dest,"arguments")) { - if (yabargc>0) { - s=yabargv[0]; - yabargc--; - yabargv++; - } - else { - s=""; - } - return my_strdup(s); - } - else { - error(ERROR,"invalid peek"); - } - return my_strdup(""); -} - - -static char *peek3(char *dest,char *cont) /* peek into internals */ -{ - char *s; - - for(s=dest;*s;s++) *s=tolower((int)*s); - if (!strcmp(dest,"env") || !strcmp(dest,"environment")) { - return my_strdup(getenv(cont)); - } else { - error(ERROR,"invalid peek"); - } - return my_strdup(""); -} - - -void create_exception(int flag) /* create command 'exception' */ -{ - struct command *cmd; - - cmd=add_command(cEXCEPTION,FALSE); - cmd->args=flag; -} - - -void exception(struct command *cmd) /* change handling of exceptions */ -{ - if (cmd->args) { - signal(SIGINT,signal_handler); /* enable keyboard interrupt */ -#ifdef SIGHUP - signal(SIGHUP,signal_handler); -#endif -#ifdef SIGQUIT - signal(SIGQUIT,signal_handler); -#endif -#ifdef SIGABRT - signal(SIGABRT,signal_handler); -#endif -#ifdef SIGTERM - signal(SIGTERM,signal_handler); -#endif - } - else { - signal(SIGINT,SIG_IGN); /* ignore keyboard interrupt */ -#ifdef SIGHUP - signal(SIGHUP,SIG_IGN); -#endif -#ifdef SIGQUIT - signal(SIGQUIT,SIG_IGN); -#endif -#ifdef SIGABRT - signal(SIGABRT,SIG_IGN); -#endif -#ifdef SIGTERM - signal(SIGTERM,SIG_IGN); -#endif - } - return; -} - - -void create_restore(char *label) /* create command 'restore' */ -{ - struct command *c; - - c=add_command(cRESTORE,FALSE); - c->pointer=my_strdup(label); -} - - -void restore(struct command *cmd) /* reset data pointer to given label */ -{ - struct command *label; - struct command **datapointer; - - datapointer=&(cmd->lib->datapointer); - if (cmd->type==cRESTORE) { /* first time; got to search the label */ - if (*((char *)cmd->pointer)=='\0') { - /* no label, restore to first command */ - label=cmd->lib->firstdata; - } else { - label=search_label(cmd->pointer,smLABEL|smGLOBAL); - if (!label) { - /* did not find label */ - sprintf(string,"can't find label '%s'",(char *)cmd->pointer); - error(ERROR,string); - return; - } - } - *datapointer=label; - if (lastdata) { - while((*datapointer)->type!=cDATA && (*datapointer)!=cmdhead) { - *datapointer=(*datapointer)->next; - } - } - cmd->pointer=*datapointer; - cmd->type=cQRESTORE; - } else { - *datapointer=cmd->pointer; - } - return; -} - - -void create_dbldata(double value) /* create command dbldata */ -{ - struct command *c; - - c=add_command(cDATA,FALSE); - c->pointer=my_malloc(sizeof(double)); - if (lastdata) lastdata->nextassoc=c; - lastdata=c; - *((double *)c->pointer)=value; - c->tag='d'; /* double value */ -} - - -void create_strdata(char *value) /* create command strdata */ -{ - struct command *c; - - c=add_command(cDATA,FALSE); - if (lastdata) lastdata->nextassoc=c; - lastdata=c; - c->pointer=my_strdup(value); - c->tag='s'; /* string value */ -} - - -void create_readdata(char type) /* create command readdata */ -{ - struct command *cmd; - - cmd=add_command(cREADDATA,FALSE); - cmd->tag=type; -} - - -void readdata(struct command *cmd) /* read data items */ -{ - struct stackentry *read; - char type; - struct command **datapointer; - - datapointer=&(cmd->lib->datapointer); - type=cmd->tag; - while(*datapointer && ((*datapointer)->type!=cDATA || cmd->lib!=(*datapointer)->lib)) { - *datapointer=(*datapointer)->nextassoc; - } - if (!*datapointer) { - error(ERROR,"run out of data items"); - return; - } - if (type!=(*datapointer)->tag) { - error(ERROR,"type of READ and DATA don't match"); - return; - } - read=push(); - if (type=='d') { /* read a double value */ - read->type=stNUMBER; - read->value= *((double *)(*datapointer)->pointer);} - else { - read->type=stSTRING; - read->pointer=my_strdup((*datapointer)->pointer); - } - *datapointer=(*datapointer)->nextassoc; /* next item */ -} - - -void create_dblrelop(char c) /* create command dblrelop */ -{ - int type; - - switch(c) { - case '=': type=cEQ;break; - case '!': type=cNE;break; - case '<': type=cLT;break; - case '{': type=cLE;break; - case '>': type=cGT;break; - case '}': type=cGE;break; - } - add_command(type,FALSE); -} - - -void dblrelop(struct command *type) /* compare topmost double-values */ -{ - double a,b,c; - struct stackentry *result; - - b=pop(stNUMBER)->value; - a=pop(stNUMBER)->value; - switch(current->type) { - case cEQ:c=(a==b);break; - case cNE:c=(a!=b);break; - case cLE:c=(a<=b);break; - case cLT:c=(a=b);break; - case cGT:c=(a>b);break; - } - result=push(); - result->value=c; - result->type=stNUMBER; -} - - -void create_strrelop(char c) /* create command strrelop */ -{ - int type; - - switch(c) { - case '=': type=cSTREQ;break; - case '!': type=cSTRNE;break; - case '<': type=cSTRLT;break; - case '{': type=cSTRLE;break; - case '>': type=cSTRGT;break; - case '}': type=cSTRGE;break; - } - add_command(type,FALSE); -} - - -void strrelop(struct command *type) /* compare topmost string-values */ -{ - char *a,*b; - double c; - struct stackentry *result; - - b=pop(stSTRING)->pointer; - a=pop(stSTRING)->pointer; - switch(current->type) { - case cSTREQ:c=(strcmp(a,b)==0);break; - case cSTRNE:c=(strcmp(a,b)!=0);break; - case cSTRLT:c=(strcmp(a,b)<0);break; - case cSTRLE:c=(strcmp(a,b)<=0);break; - case cSTRGT:c=(strcmp(a,b)>0);break; - case cSTRGE:c=(strcmp(a,b)>=0);break; - } - result=push(); - result->value=c; - result->type=stNUMBER; -} - -void switch_compare(void) /* compare topmost values for switch statement */ -{ - struct stackentry *result,*first,*second; - double r=0.; - - first=pop(stANY); - second=stackhead->prev; - if ((second->type==stSWITCH_STRING || second->type==stSTRING) && first->type==stSTRING) { - if (second->type==stSWITCH_STRING) - r=1.; - else - r=(strcmp(first->pointer,second->pointer)==0)?1.:0.; - } else if ((second->type==stSWITCH_NUMBER || second->type==stNUMBER) && first->type==stNUMBER) { - if (second->type==stSWITCH_NUMBER) - r=1.; - else - r=(first->value==second->value); - } else { - error(ERROR,"Cannot mix strings and numbers in a single switch statement"); - } - result=push(); - result->type=stNUMBER; - result->value=r; -} - - -void logical_shortcut(struct command *type) /* shortcut and/or if possible */ -{ - struct stackentry *result; - double is; - - is=stackhead->prev->value; - if ((type->type==cORSHORT && is!=0) || (type->type==cANDSHORT && is==0)) { - result=push(); - error(DEBUG,"logical shortcut taken"); - result->type=stNUMBER; - result->value=is; - } else { - current=current->next; - } -} - - -void create_boole(char c) /* create command boole */ -{ - int type; - - switch(c) { - case '|': type=cOR;break; - case '&': type=cAND;break; - case '!': type=cNOT;break; - } - add_command(type,FALSE); -} - - -void boole(struct command *type) /* perform and/or/not */ -{ - int a,b,c; - struct stackentry *result; - - a=(int)pop(stNUMBER)->value; - if (current->type==cNOT) - c=!a; - else { - b=(int)pop(stNUMBER)->value; - if (current->type==cAND) - c=a&&b; - else - c=a||b; - } - result=push(); - result->value=c; - result->type=stNUMBER; -} - diff --git a/src/global.h b/src/global.h deleted file mode 100644 index 746450b..0000000 --- a/src/global.h +++ /dev/null @@ -1,3 +0,0 @@ -//define BUILD_NCURSES -#define BUILD_YABTEXT -#define BUILD_GAMESOUND \ No newline at end of file diff --git a/src/graphic.c b/src/graphic.c deleted file mode 100644 index 70c9215..0000000 --- a/src/graphic.c +++ /dev/null @@ -1,2592 +0,0 @@ -/* - - YABASIC --- a simple Basic Interpreter - written by Marc-Oliver Ihm 1995-2004 - homepage: www.yabasic.de - - graphic.c --- code for windowed graphics, printing and plotting - - 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 - -*/ - - -/* ------------- includes ---------------- */ - -//include "YabInterface.h" - -#include "global.h" - -#ifndef YABASIC_INCLUDED -#include "yabasic.h" /* all prototypes and structures */ -#endif -#ifdef UNIX -#ifdef BUILD_NCURSES -#include -#endif -#include -#include -#include -#ifndef KEY_MAX -#define KEY_MAX 0777 -#endif -#endif - - -/* ------------- global variables ---------------- */ - -char translationbuffer[8192]; - -/* mouse and keyboard */ -int mousex=0,mousey=0,mouseb=0,mousemod=0; /* last know mouse coordinates */ -char *ykey[kLASTKEY+1]; /* keys returned by inkey */ - -int winopened = 0; - -/* ------------- functions ---------------- */ - -void create_openwin(int fnt) /* create Command 'openwin' */ -{ - struct command *cmd; - - cmd=add_command(cOPENWIN,FALSE); - cmd->args=fnt; -} - - -void openwin(struct command *cmd, YabInterface* yab) /* open a Window */ -{ - double x1,y1,x2,y2; - char *id, *title; - title = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_OpenWindow(x1,y1,x2,y2, id, title, yab); - - winopened++; -} - -void closewin(struct command *cmd, YabInterface* yab) /* close the window */ -{ - char *id; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - if (yi_CloseWindow(id, yab) == 1) - winopened--; -} - -int numwindows() -{ - return winopened; -} - -void createbutton(struct command *cmd, YabInterface* yab) /* set a button */ -{ - double x1,y1,x2,y2; - char *id, *title, *view; - - view = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateButton(x1,y1,x2,y2, id, title, view, yab); -} - -void createmenu(struct command *cmd, YabInterface* yab) /* add a menu */ -{ - char *menuhead, *menuitem, *shortcut, *window; - window = pop(stSTRING)->pointer; - shortcut = pop(stSTRING)->pointer; - menuitem = pop(stSTRING)->pointer; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateMenu(menuhead, menuitem, shortcut, window, yab); -} - -void createcheckbox(struct command *cmd, YabInterface* yab) /* add a checkbox */ -{ - char *label, *window, *id; - double x,y,isActivated; - - window = pop(stSTRING)->pointer; - isActivated = pop(stNUMBER)->value; - label = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateCheckBox(x,y,id, label,isActivated,window, yab); -} - -void createradiobutton(struct command *cmd, YabInterface* yab) /* add a radio button*/ -{ - char *label, *groupid, *window; - double x,y,isActivated; - - - window = pop(stSTRING)->pointer; - isActivated = pop(stNUMBER)->value; - label = pop(stSTRING)->pointer; - groupid = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateRadioButton(x,y,groupid,label,isActivated,window, yab); -} - -void createtextcontrol(struct command *cmd, YabInterface* yab) /* add a textcontrol */ -{ - char *text, *label, *window, *id; - double x1,y1,x2,y2; - - window = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - label = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateTextControl(x1,y1,x2,y2,id, label, text, window, yab); -} - -void createlistbox(struct command *cmd, YabInterface* yab) /* list box */ -{ - char *title, *window; - double x1,y1,x2,y2,scrollbar; - - window = pop(stSTRING)->pointer; - scrollbar = pop(stNUMBER)->value; - title = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateListBox(x1,y1,x2,y2, title, scrollbar, window, yab); -} - -void createdropbox(struct command *cmd, YabInterface* yab) /* drop box */ -{ - char *title, *label, *window; - double x1,y1,x2,y2; - - window = pop(stSTRING)->pointer; - label = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateDropBox(x1,y1,x2,y2, title, label, window, yab); -} - -void createitem(struct command *cmd, YabInterface* yab) /* item add */ -{ - char *item, *view; - - item = pop(stSTRING)->pointer; - view = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateItem(view,item,yab); -} - -void removeitem(struct command *cmd, YabInterface* yab) /* item add */ -{ - char *title, *item; - - item = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_RemoveItem(title,item,yab); -} - -void clearitems(struct command *cmd, YabInterface* yab) /* clear item list*/ -{ - char *title; - - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ClearItems(title,yab); -} - -int createimage(double x, double y, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname) /* set an image */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_CreateImage(x,y, imagefile, window, yab); -} - -int createimage2(double x1, double y1, double x2, double y2, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_CreateImage2(x1,y1,x2,y2, imagefile, window, yab); -} - -int createsvg(double x1, double y1, double x2, double y2, const char* imagefile, const char* window, YabInterface* yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_CreateSVG(x1,y1,x2,y2, imagefile, window, yab); -} - -void mouseset(struct command *cmd, YabInterface* yab) -{ - char *opt; - opt = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_MouseSet(opt, yab); -} - -void drawtext(struct command *cmd, YabInterface* yab) /* draw text */ -{ - double x,y; - char *text, *window; - - window = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - y=pop(stNUMBER)->value; - x=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawText(x,y,text, window, yab); -} - -void drawrect(struct command *cmd, YabInterface* yab) /* draw rect */ -{ - double x1,y1,x2,y2; - char *window; - - window = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawRect(x1,y1,x2,y2,window, yab); -} - -void drawdot(struct command *cmd, YabInterface* yab) /* draw dot */ -{ - double x1,y1; - char *window; - - window = pop(stSTRING)->pointer; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawDot(x1,y1,window, yab); -} - -void drawline(struct command *cmd, YabInterface* yab) /* draw line */ -{ - double x1,y1,x2,y2; - char *window; - - window = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawLine(x1,y1,x2,y2,window, yab); -} - -void drawcircle(struct command *cmd, YabInterface* yab) /* draw circle */ -{ - double x1,y1,r; - char *window; - - window = pop(stSTRING)->pointer; - r=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawCircle(x1,y1,r,window, yab); -} - -void drawellipse(struct command *cmd, YabInterface* yab) /* draw ellipse */ -{ - double x1,y1,r1,r2; - char *window; - - window = pop(stSTRING)->pointer; - r2=pop(stNUMBER)->value; - r1=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawEllipse(x1,y1,r1,r2,window, yab); -} - -void drawcurve(struct command *cmd, YabInterface* yab) /* draw a curve */ -{ - double x1,y1,x2,y2,x3,y3,x4,y4; - char *window; - - window = pop(stSTRING)->pointer; - y4=pop(stNUMBER)->value; - x4=pop(stNUMBER)->value; - y3=pop(stNUMBER)->value; - x3=pop(stNUMBER)->value; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawCurve(x1,y1,x2,y2,x3,y3,x4,y4,window, yab); -} - -void drawclear(struct command *cmd, YabInterface* yab) /* clear canvas */ -{ - char *window; - - - window = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawClear(window, yab); -} - -void drawset1(struct command *cmd, YabInterface *yab) -{ - char *option, *window; - - window = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawSet1(option,window,yab); -} - -void drawset2(struct command *cmd, YabInterface *yab) -{ - char *pattern; - int mode; - - pattern = pop(stSTRING)->pointer; - mode = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawSet2(mode,pattern,yab); -} - -void drawset3(struct command *cmd, YabInterface *yab) -{ - char *option; - int transparency; - - transparency = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawSet3(option, transparency,yab); -} - -void createtext(struct command *cmd, YabInterface* yab) /* text */ -{ - double x,y; - char *text, *window, *id; - - - window = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y=pop(stNUMBER)->value; - x=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateText(x,y,id,text, window, yab); -} - -void text2(struct command *cmd, YabInterface* yab) /* text */ -{ - double x1,y1,x2,y2; - char *text, *window, *id; - - - window = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2=pop(stNUMBER)->value; - x2=pop(stNUMBER)->value; - y1=pop(stNUMBER)->value; - x1=pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Text2(x1,y1,x2,y2,id,text, window, yab); -} - -void textalign(struct command *cmd, YabInterface* yab) /* align text */ -{ - char *option, *id; - - - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextAlign(id, option, yab); -} - -void createalert(struct command *cmd, YabInterface* yab) /* open an alert window (one button only)*/ -{ - char *text, *button1, *type; - - type = pop(stSTRING)->pointer; - button1 = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CreateAlert(text,button1,type, yab); -} - -void setlayout(struct command *cmd, YabInterface *yab) -{ - char *text, *window; - - - window = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetLayout(text, window, yab); -} - -void winset1(struct command *cmd, YabInterface *yab) -{ - char *option, *value, *window; - - - value = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - window = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_WindowSet1(option,value,window,yab); -} - -void winset2(struct command *cmd, YabInterface *yab) -{ - char *option, *window; - int r, g, b; - - window = pop(stSTRING)->pointer; - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_WindowSet2(option,r,g,b,window,yab); -} - -void winset3(struct command *cmd, YabInterface *yab) -{ - char *option, *window; - double x,y; - - - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - window = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_WindowSet3(option,x,y,window,yab); -} - -void winset4(struct command *cmd, YabInterface *yab) -{ - char *option, *window; - - - option = pop(stSTRING)->pointer; - window = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_WindowSet4(option,window,yab); -} - -void winclear(struct command *cmd, YabInterface *yab) -{ - char *window; - - - window = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_WindowClear(window,yab); -} - -char* gettranslation(const char* text, YabInterface* yab, int line, const char* libname) /* get translation string */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - yi_Translate((char*)text, translationbuffer); - return my_strdup((char*) translationbuffer); -} - -char* getmenutranslation(const char* text, YabInterface* yab, int line, const char* libname) /* get menu translation string */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - yi_MenuTranslate((char*)text, translationbuffer); - return my_strdup((char*) translationbuffer); -} - -void localize() -{ - yi_SetLocalize(); -} - -void localizestop() -{ - yi_StopLocalize(); -} - -void localize2(struct command *cmd, YabInterface *yab) -{ - char *path; - - path = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetLocalize2(path, yab); -} - -char* getloadfilepanel(const char* mode, const char* title, const char* dir, YabInterface *yab, int line, const char* libname) /* load panel */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_LoadFilePanel(mode, title, dir,yab)); -} - -char* getsavefilepanel(const char* mode, const char* title, const char* dir, const char* filename, YabInterface *yab, int line, const char* libname) /* save panel */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_SaveFilePanel(mode, title, dir, filename, yab)); -} - -void textedit(struct command *cmd, YabInterface *yab) -{ - char *window, *title; - double x1,y1,x2,y2; - int scrollbar; - - - window = pop(stSTRING)->pointer; - scrollbar = pop(stNUMBER)->value; - title = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextEdit(x1,y1,x2,y2,title,scrollbar,window,yab); -} - -void textadd(struct command *cmd, YabInterface *yab) -{ - char *title, *text; - - - text = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextAdd(title,text,yab); -} - -void textset(struct command *cmd, YabInterface *yab) -{ - char *title, *option; - - - option = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextSet(title,option,yab); -} - -void textset2(struct command *cmd, YabInterface *yab) -{ - char *title, *option; - int value; - - - value = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextSet2(title,option,value,yab); -} - -void textset3(struct command *cmd, YabInterface *yab) -{ - char *title, *option, *option2; - - - option2 = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextSet3(title,option,option2,yab); -} - -void textcolor1(struct command *cmd, YabInterface *yab) -{ - char *title, *option, *command; - - - command = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextColor1(title,option,command,yab); -} - -void textcolor2(struct command *cmd, YabInterface *yab) -{ - char *title, *option; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextColor2(title,option,r,g,b,yab); -} - -void textclear(struct command *cmd, YabInterface *yab) -{ - char *title; - - - title = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextClear(title,yab); -} - -char* textget(const char* title, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_TextGet(title,yab)); -} - -int textget2(const char* title, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TextGet2(title,option,yab); -} - -char* textget3(const char* title, int linenum, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return (char*)yi_TextGet3(title,linenum,yab); -} - -double textget4(const char* title, const char* option, int linenum, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TextGet4(title,option,linenum,yab); -} - -int textget5(const char* title, const char* option, const char* option2, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TextGet5(title,option,option2,yab); -} - -char* textget6(const char* title, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return (char*)yi_TextGet6(title,option,yab); -} - -void view(struct command *cmd, YabInterface *yab) -{ - char *id, *view; - double x1, y1, x2, y2; - - - view = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_View(x1,y1,x2,y2, id, view, yab); -} - -void boxview(struct command *cmd, YabInterface *yab) -{ - char *id, *view, *text; - double x1, y1, x2, y2; - int linetype; - - - view = pop(stSTRING)->pointer; - linetype = pop(stNUMBER)->value; - text = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BoxView(x1,y1,x2,y2, id, text, linetype, view, yab); -} - -void boxviewset(struct command *cmd, YabInterface *yab) -{ - char *id, *value, *option; - - - - value= pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BoxViewSet(id, option, value, yab); -} - - - -void tab(struct command *cmd, YabInterface *yab) -{ - char *id, *names, *view; - double x1, y1, x2, y2; - - - view = pop(stSTRING)->pointer; - names = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Tab(x1,y1,x2,y2, id, names, view, yab); -} - -void tabset(struct command *cmd, YabInterface *yab) -{ - char *tabname; - int num; - - - num = pop(stNUMBER)->value; - tabname = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TabSet(tabname, num, yab); -} - -void tabadd(struct command *cmd, YabInterface *yab) -{ - char *id, *tabname; - - - tabname = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TabAdd(id, tabname, yab); -} - -void tabdel(struct command *cmd, YabInterface *yab) -{ - char *id; - int num; - - - num = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TabDel(id, num, yab); -} - -void slider1(struct command *cmd, YabInterface *yab) -{ - char *view, *id, *title; - double x1,y1,x2,y2,min,max; - - - view = pop(stSTRING)->pointer; - max = pop(stNUMBER)->value; - min = pop(stNUMBER)->value; - title = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Slider1(x1,y1,x2,y2,id,title,min,max,view,yab); -} - - -void slider2(struct command *cmd, YabInterface *yab) -{ - char *view, *id, *title, *option; - double x1,y1,x2,y2,min,max; - - - view = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - max = pop(stNUMBER)->value; - min = pop(stNUMBER)->value; - title = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Slider2(x1,y1,x2,y2,id,title,min,max,option,view,yab); -} - -void slider3(struct command *cmd, YabInterface *yab) -{ - char *id, *label1, *label2; - - - label2 = pop(stSTRING)->pointer; - label1 = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetSlider1(id,label1,label2,yab); -} - - -void slider4(struct command *cmd, YabInterface *yab) -{ - char *id, *bottomtop; - int count; - - - count = pop(stNUMBER)->value; - bottomtop = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetSlider2(id,bottomtop,count,yab); -} - -void slider5(struct command *cmd, YabInterface *yab) -{ - char *id, *part; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - part = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetSlider3(id,part,r,g,b,yab); -} - -void slider6(struct command *cmd, YabInterface *yab) -{ - char *id; - int value; - - - value = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetSlider4(id,value,yab); -} - -void option1(struct command *cmd, YabInterface *yab) -{ - char *id, *option, *value; - - - value = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetOption1(id,option,value,yab); -} - -void option2(struct command *cmd, YabInterface *yab) -{ - char *id, *part; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - part = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetOption2(id,part,r,g,b,yab); -} - -void option3(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - double x,y; - - - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetOption3(id,option,x,y,yab); -} - -void option4(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - - - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetOption4(id,option,yab); -} - -void option5(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - int value; - - - value = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SetOption5(id,option,value,yab); -} - -void dropzone(struct command *cmd, YabInterface *yab) -{ - char *view; - - - view = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DropZone(view,yab); -} - -void colorcontrol1(struct command *cmd, YabInterface *yab) -{ - char *view, *id; - double x,y; - - - view = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColorControl1(x,y,id,view,yab); -} - -void colorcontrol2(struct command *cmd, YabInterface *yab) -{ - char *id; - double r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColorControl2(id,r,g,b,yab); -} - -void textcontrol2(struct command *cmd, YabInterface *yab) -{ - char *id, *text; - - - text = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextControl2(id,text,yab); -} - -void textcontrol3(struct command *cmd, YabInterface *yab) -{ - char *id; - int mode; - mode = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextControl3(id,mode,yab); -} - -void textcontrol5(struct command *cmd, YabInterface *yab) -{ - char *id; - - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextControl5(id,yab); -} - - -void textcontrol4(struct command *cmd, YabInterface *yab) -{ - char *id, *option, *value; - - - value = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextControl4(id,option,value,yab); -} - - - - -void treebox1(struct command *cmd, YabInterface *yab) -{ - char *id, *view; - double x1,y1,x2,y2; - int scrollbarType; - - - view = pop(stSTRING)->pointer; - scrollbarType = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox1(x1,y1,x2,y2,id,scrollbarType,view,yab); -} - -void treebox2(struct command *cmd, YabInterface *yab) -{ - char *id, *item; - - - item = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox2(id,item,yab); -} - -void treebox3(struct command *cmd, YabInterface *yab) -{ - char *id, *head, *item; - int isExpanded; - - - isExpanded = pop(stNUMBER)->value; - item = pop(stSTRING)->pointer; - head = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox3(id,head,item,isExpanded,yab); -} - -void treebox4(struct command *cmd, YabInterface *yab) -{ - char *id; - - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox4(id,yab); -} - -void treebox5(struct command *cmd, YabInterface *yab) -{ - char *id,*item; - - - item = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox5(id,item,yab); -} - -void treebox7(struct command *cmd, YabInterface *yab) -{ - char *id; - int pos; - - - pos = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox7(id,pos,yab); -} - -void treebox8(struct command *cmd, YabInterface *yab) -{ - char *id; - int pos; - - - pos = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox8(id,pos,yab); -} - -void treebox9(struct command *cmd, YabInterface *yab) -{ - char *id, *head, *item; - - - item = pop(stSTRING)->pointer; - head = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox9(id,head,item,yab); -} - -void treebox10(struct command *cmd, YabInterface *yab) -{ - char *id, *head; - - - head = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox10(id,head,yab); -} - -void treebox11(struct command *cmd, YabInterface *yab) -{ - char *id, *head; - - - head = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox11(id,head,yab); -} - -void treebox12(struct command *cmd, YabInterface *yab) -{ - char *id, *item; - int pos; - - - pos = pop(stNUMBER)->value; - item = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeBox12(id,item,pos,yab); -} - -void buttonimage(struct command *cmd, YabInterface *yab) -{ - char *id, *enabledon, *enabledoff, *disabled, *view; - double x,y; - - - view = pop(stSTRING)->pointer; - disabled = pop(stSTRING)->pointer; - enabledoff = pop(stSTRING)->pointer; - enabledon = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ButtonImage(x,y,id,enabledon, enabledoff, disabled, view,yab); -} - -void checkboximage(struct command *cmd, YabInterface *yab) -{ - char *id, *enabledon, *enabledoff, *disabledon, *disabledoff, *view; - double x,y; - int isActivated; - - - view = pop(stSTRING)->pointer; - isActivated = pop(stNUMBER)->value; - disabledoff = pop(stSTRING)->pointer; - disabledon = pop(stSTRING)->pointer; - enabledoff = pop(stSTRING)->pointer; - enabledon = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CheckboxImage(x,y,id,enabledon, enabledoff, disabledon, disabledoff, isActivated, view,yab); -} - -void checkboxset(struct command *cmd, YabInterface *yab) -{ - char *id; - int isActivated; - - - isActivated = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_CheckboxSet(id,isActivated,yab); -} - -void radioset(struct command *cmd, YabInterface *yab) -{ - char *id; - int isActivated; - - - isActivated = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_RadioSet(id,isActivated,yab); -} - -char* textcontrolget(const char* textcontrol, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_TextControlGet(textcontrol,yab)); -} - -void tooltip(struct command *cmd, YabInterface *yab) -{ - char *view,*text; - - - text = pop(stSTRING)->pointer; - view = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ToolTip(view,text,yab); -} -void tooltipnew(struct command *cmd, YabInterface *yab) -{ - char *view, *text, *color; - int r,g,b; - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - - color = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - view = pop(stSTRING)->pointer; - - - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ToolTipNew(view,text,color,r,g,b,yab); -} -void tooltipcolor(struct command *cmd, YabInterface *yab) -{ - char *color; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - color = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ToolTipColor(color,r,g,b,yab); -} - -void listsort(struct command *cmd, YabInterface *yab) -{ - char *id; - - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ListSort(id,yab); -} - -void treesort(struct command *cmd, YabInterface *yab) -{ - char *id; - - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TreeSort(id,yab); -} - -void filebox(struct command *cmd, YabInterface *yab) -{ - char *id,*view, *option; - int scrollbar; - double x1,y1,x2,y2; - - - view = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - scrollbar = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_FileBox(x1,y1,x2,y2,id,scrollbar,option,view,yab); -} - -void fileboxadd2(struct command *cmd, YabInterface *yab) -{ - char *columnbox, *name, *option; - double width, maxWidth, minWidth; - int pos; - - - option = pop(stSTRING)->pointer; - width = pop(stNUMBER)->value; - minWidth = pop(stNUMBER)->value; - maxWidth = pop(stNUMBER)->value; - pos = pop(stNUMBER)->value; - name = pop(stSTRING)->pointer; - columnbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_FileBoxAdd2(columnbox, name, pos, maxWidth, minWidth, width, option, yab); -} - -void fileboxclear(struct command *cmd, YabInterface *yab) -{ - char *id; - - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_FileBoxClear(id,yab); -} - -void columnboxadd(struct command *cmd, YabInterface *yab) -{ - char *id, *item ; - int position, height, column; - - - item = pop(stSTRING)->pointer; - height = pop(stNUMBER)->value; - position = pop(stNUMBER)->value; - column = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColumnBoxAdd(id,column,position,height,item,yab); -} - -void columnboxremove(struct command *cmd, YabInterface *yab) -{ - char *columnbox; - int pos; - - - pos = pop(stNUMBER)->value; - columnbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColumnBoxRemove(columnbox,pos,yab); -} - -void columnboxselect(struct command *cmd, YabInterface *yab) -{ - char *columnbox; - int pos; - - - pos = pop(stNUMBER)->value; - columnbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColumnBoxSelect(columnbox,pos,yab); -} - -void columnboxcolor(struct command *cmd, YabInterface *yab) -{ - char *columnbox, *option; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - columnbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ColumnBoxColor(columnbox,option,r,g,b,yab); -} - -void dropboxselect(struct command *cmd, YabInterface *yab) -{ - char *dropbox; - int num; - - - num = pop(stNUMBER)->value; - dropbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DropBoxSelect(dropbox,num,yab); -} - -void menu2(struct command *cmd, YabInterface *yab) -{ - char *menuhead, *view; - int radio; - - - view = pop(stSTRING)->pointer; - radio = pop(stNUMBER)->value; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Menu2(menuhead,radio,view,yab); -} - -void submenu1(struct command *cmd, YabInterface *yab) -{ - char *menuhead, *menuitem, *submenuitem, *modifier, *view; - - - view = pop(stSTRING)->pointer; - modifier = pop(stSTRING)->pointer; - submenuitem = pop(stSTRING)->pointer; - menuitem = pop(stSTRING)->pointer; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SubMenu1(menuhead,menuitem,submenuitem,modifier,view,yab); -} - -void submenu2(struct command *cmd, YabInterface *yab) -{ - char *menuhead, *menuitem, *view; - int radio; - - - view = pop(stSTRING)->pointer; - radio = pop(stNUMBER)->value; - menuitem = pop(stSTRING)->pointer; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SubMenu2(menuhead,menuitem,radio,view,yab); -} - -void submenu3(struct command *cmd, YabInterface *yab) -{ - char *menuhead, *menuitem, *submenuitem, *option, *view; - - - view = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - submenuitem = pop(stSTRING)->pointer; - menuitem = pop(stSTRING)->pointer; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SubMenu3(menuhead,menuitem,submenuitem,option,view,yab); -} - -void menu3(struct command *cmd, YabInterface *yab) -{ - char *menuhead, *menuitem, *option, *view; - - - view = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - menuitem = pop(stSTRING)->pointer; - menuhead = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Menu3(menuhead,menuitem,option,view,yab); -} - -int sliderget(const char *slider, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_SliderGet(slider, yab); -} - -int colorcontrolget(const char* colorcontrol, const char* option, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ColorControlGet(colorcontrol, option, yab); -} - -void spincontrol1(struct command *cmd, YabInterface *yab) -{ - char *id, *view, *label; - int min, max, step; - double x,y; - - - view = pop(stSTRING)->pointer; - step = pop(stNUMBER)->value; - max = pop(stNUMBER)->value; - min = pop(stNUMBER)->value; - label = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SpinControl1(x,y,id,label,min,max,step,view,yab); -} - -void spincontrol2(struct command *cmd, YabInterface *yab) -{ - char *spincontrol; - int value; - - - value = pop(stNUMBER)->value; - spincontrol = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SpinControl2(spincontrol,value,yab); -} - -int spincontrolget(const char* view, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_SpinControlGet(view,yab); -} - -char* popupmenu(double x, double y, const char* menuitems, const char* view, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_PopUpMenu(x,y,menuitems,view,yab)); -} - -void dropboxremove(struct command *cmd, YabInterface *yab) -{ - char *dropbox; - int value; - - - value = pop(stNUMBER)->value; - dropbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DropBoxRemove(dropbox,value,yab); -} - -void dropboxclear(struct command *cmd, YabInterface *yab) -{ - char *dropbox; - - - dropbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DropBoxClear(dropbox,yab); -} - -int dropboxcount(const char* id, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_DropBoxCount(id,yab); -} - -char* dropboxget(const char* id, int position, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_DropBoxGet(id,position,yab)); -} - -void splitview1(struct command *cmd, YabInterface *yab) -{ - char *id, *view; - double x1,y1,x2,y2; - int isVertical, NormalStyle; - - - view = pop(stSTRING)->pointer; - NormalStyle = pop(stNUMBER)->value; - isVertical = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SplitView1(x1,y1,x2,y2, id, isVertical, NormalStyle, view, yab); -} - -void splitview2(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - double value; - - - value = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SplitView2(id, option, value, yab); -} - -void splitview3(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - double left, right; - - - right = pop(stNUMBER)->value; - left = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SplitView3(id, option, left, right, yab); -} - -double splitviewget(const char* id, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_SplitViewGet(id, option, yab); -} - -void stackview1(struct command *cmd, YabInterface *yab) -{ - char *id, *view; - double x1,y1,x2,y2; - int number; - - - view = pop(stSTRING)->pointer; - number = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StackView1(x1,y1,x2,y2, id, number, view, yab); -} - -void stackview2(struct command *cmd, YabInterface *yab) -{ - char *id; - int num; - - - num = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StackView2(id, num, yab); -} - -int stackviewget(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_StackViewGet(id, yab); -} - -int tabviewget(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TabViewGet(id, yab); -} - -void calendar1(struct command *cmd, YabInterface *yab) -{ - char *format, *id, *date, *view; - double x,y; - - - view = pop(stSTRING)->pointer; - date = pop(stSTRING)->pointer; - format = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Calendar1(x,y, id, format, date, view, yab); -} - -char* calendar2(const char* id, YabInterface *yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_Calendar2(id, yab)); -} - -void calendar3(struct command *cmd, YabInterface *yab) -{ - char *id, *date; - - - date = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Calendar3(id, date, yab); -} - -void scrollbar(struct command *cmd, YabInterface *yab) -{ - char *view, *id; - int format; - - view = pop(stSTRING)->pointer; - format = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Scrollbar(id, format, view, yab); -} - -void scrollbarset1(struct command *cmd, YabInterface *yab) -{ - char *scrollbar, *option; - double position; - - - position = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - scrollbar = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ScrollbarSet1(scrollbar, option, position, yab); -} - -void scrollbarset2(struct command *cmd, YabInterface *yab) -{ - char *scrollbar, *option; - double a,b; - - - b = pop(stNUMBER)->value; - a = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - scrollbar = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ScrollbarSet2(scrollbar, option, a, b, yab); -} - -void scrollbarset3(struct command *cmd, YabInterface *yab) -{ - char *scrollbar, *option; - double a,b; - - - option = pop(stSTRING)->pointer; - scrollbar = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ScrollbarSet3(scrollbar, option, yab); -} - -void texturl1(struct command *cmd, YabInterface *yab) -{ - char *id, *text, *url, *view; - double x,y; - - - view = pop(stSTRING)->pointer; - url = pop(stSTRING)->pointer; - text = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextURL1(x,y, id, text, url, view, yab); -} - -void texturl2(struct command *cmd, YabInterface *yab) -{ - char *id, *color; - int r,g,b; - - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - color = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_TextURL2(id, color,r,g,b,yab); -} - -double scrollbarget(const char* scrollbar, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ScrollbarGet(scrollbar, option, yab); -} - -void clipboardcopy(struct command *cmd, YabInterface *yab) -{ - char *text; - text = pop(stSTRING)->pointer; - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ClipboardCopy(text,yab); -} - -int printer(const char* docname, const char *view, const char* config, YabInterface *yab,int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_Printer(docname, view,config,yab); -} - -void printerconfig(struct command *cmd, YabInterface *yab) -{ - char *config, *docname; - - config = pop(stSTRING)->pointer; - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_PrinterConfig(config,yab); -} - -void listboxadd1(struct command *cmd, YabInterface *yab) -{ - char *listbox, *item; - - - item = pop(stSTRING)->pointer; - listbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ListboxAdd1(listbox, item, yab); -} - -void listboxadd2(struct command *cmd, YabInterface *yab) -{ - char *listbox, *item; - int position; - - - item = pop(stSTRING)->pointer; - position = pop(stNUMBER)->value; - listbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ListboxAdd2(listbox, position, item, yab); -} - -void listboxselect(struct command *cmd, YabInterface *yab) -{ - char *listbox; - int position; - - - position = pop(stNUMBER)->value; - listbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ListboxSelect(listbox, position, yab); -} - -void listboxremove(struct command *cmd, YabInterface *yab) -{ - char *listbox; - int position; - - - position = pop(stNUMBER)->value; - listbox = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ListboxRemove(listbox, position, yab); -} - -char* clipboardpaste(YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_ClipboardPaste(yab)); -} - -char* keyboardmessages(const char* view, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_KeyboardMessages(view,yab)); -} - -char* columnboxget(const char* columnbox, int column, int position, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_ColumnBoxGet(columnbox,column,position,yab)); -} - -int columnboxcount(const char* columnbox, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ColumnBoxCount(columnbox, yab); -} - -int windowgetnum(const char* view, const char *option, YabInterface* yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_WindowGet(view,option,yab); -} - -int viewgetnum(const char* view, const char *option, YabInterface* yab, int line, const char* libname) //vasper -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ViewGet(view,option,yab); -} - -double drawget1(const char* option, const char* txt, const char* view, YabInterface* yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_DrawGet1(option, txt, view, yab); -} - -double drawget2(const char* option, const char* view, YabInterface* yab, int line, const char* libname) -{ - - yi_SetCurrentLineNumber(line, libname, yab); - return yi_DrawGet2(option, view, yab); -} - -char* drawget3(const char* option, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_DrawGet3(option, yab)); -} - -int drawget4(double x, double y, const char* rgb, const char* view, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_DrawGet4(x,y,rgb, view, yab); -} - -int newalert(const char* text, const char* button1, const char* button2, const char* button3, const char* option, YabInterface* yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_NewAlert(text,button1,button2,button3,option,yab); -} - -char* listboxget(const char* listbox, int position, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_ListboxGet(listbox,position,yab)); -} - -int listboxcount(const char* listbox, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ListboxCount(listbox, yab); -} - -char* treeboxget(const char* treebox, int position, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_TreeboxGet(treebox,position,yab)); -} - -int treeboxcount(const char* treebox, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TreeboxCount(treebox, yab); -} - -int ismousein(const char* view, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_IsMouseIn(view,yab); -} - -char* getmousein(YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_GetMouseIn(yab)); -} - -char* getmousemessages(const char* view, YabInterface* yab, int line, const char* libname) /* get a mouse message string */ -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_GetMouseMessages(view, yab)); -} - -char* getmessages(YabInterface* yab, int line, const char* libname) /* get message string */ -{ - // char tmp[1024]; - //strcpy(tmp, yi_CheckMessages(yab)); - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_CheckMessages(yab)); -} - -int messagesend(const char* app, const char *msg, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_MessageSend(app, msg, yab); -} - -int threadkill(const char* option, int id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ThreadKill(option, id, yab); -} - -int threadget(const char* option, const char* appname, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ThreadGet(option, appname, yab); -} - -void bitmap(struct command *cmd, YabInterface *yab) -{ - char *id; - double w,h; - - id = pop(stSTRING)->pointer; - h = pop(stNUMBER)->value; - w = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Bitmap(w, h, id, yab); -} - -void bitmapdraw(struct command *cmd, YabInterface *yab) -{ - char *id, *mask, *view; - double x,y; - - view = pop(stSTRING)->pointer; - mask = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y = pop(stNUMBER)->value; - x = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapDraw(x,y, id, mask, view, yab); -} - -void bitmapdraw2(struct command *cmd, YabInterface *yab) -{ - char *id, *mask, *view; - double x1,y1,x2,y2; - - view = pop(stSTRING)->pointer; - mask = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapDraw2(x1,y1,x2,y2, id, mask, view, yab); -} - -void bitmapget(struct command *cmd, YabInterface *yab) -{ - char *id, *bitmap; - double x1,y1,x2,y2; - - bitmap = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapGet(x1,y1, x2,y2, id, bitmap, yab); -} - -void bitmapget2(struct command *cmd, YabInterface *yab) -{ - char *id, *path; - double w; - - path = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - w = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapGet2(w, id, path, yab); -} - -void bitmapgeticon(struct command *cmd, YabInterface *yab) -{ - char *id, *option, *path; - - path = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapGetIcon(id, option, path, yab); -} - -void bitmapdrag(struct command *cmd, YabInterface *yab) -{ - char *id; - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapDrag(id, yab); -} - -void screenshot(struct command *cmd, YabInterface *yab) -{ - char *bitmap; - double x1,y1,x2,y2; - - bitmap = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Screenshot(x1,y1,x2,y2, bitmap, yab); -} - -void statusbar(struct command *cmd, YabInterface *yab) -{ - char *view, *label2, *label1, *id; - double x1, y1, x2, y2; - - view = pop(stSTRING)->pointer; - label2 = pop(stSTRING)->pointer; - label1 = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StatusBar(x1,y1,x2,y2, id, label1, label2, view, yab); -} - -void statusbarset(struct command *cmd, YabInterface *yab) -{ - double state; - char *label2, *label1, *id; - - state = pop(stNUMBER)->value; - label2 = pop(stSTRING)->pointer; - label1 = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StatusBarSet(id, label1, label2, state, yab); -} - -void statusbarset2(struct command *cmd, YabInterface *yab) -{ - double x1, y1, x2, y2; - char *id, *view; - - view = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StatusBarSet2(x1,y1,x2,y2, id, view, yab); -} - -void statusbarset3(struct command *cmd, YabInterface *yab) -{ - int r,g,b; - char *id; - - b = pop(stNUMBER)->value; - g = pop(stNUMBER)->value; - r = pop(stNUMBER)->value; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_StatusBarSet3(id, r, g, b, yab); -} - -void bitmapremove(struct command *cmd, YabInterface *yab) -{ - char *id; - - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_BitmapRemove(id, yab); -} - -int bitmapsave(const char* id, const char* filename, const char* type, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_BitmapSave(id, filename, type, yab); -} - -int bitmapload(const char* filename, const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_BitmapLoad(filename, id, yab); -} - -int bitmapgetnum(const char* id, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_BitmapGetNum(id, option, yab); -} - -int bitmapcolor(double x, double y, const char* id, const char* option, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_BitmapColor(x,y,id,option,yab); -} - -void canvas(struct command *cmd, YabInterface *yab) -{ - char *id, *view; - double x1,y1,x2,y2; - - - view = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - y2 = pop(stNUMBER)->value; - x2 = pop(stNUMBER)->value; - y1 = pop(stNUMBER)->value; - x1 = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Canvas(x1,y1,x2,y2,id,view, yab); -} - -int listboxgetnum(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ListboxGetNum(id, yab); -} - -int dropboxgetnum(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_DropboxGetNum(id, yab); -} - -int columnboxgetnum(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_ColumnboxGetNum(id, yab); -} - -int treeboxgetnum(const char* id, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TreeboxGetNum(id, yab); -} - -int treeboxgetopt(const char* id, const char* option, int pos, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_TreeboxGetOpt(id, option, pos, yab); -} - -void treebox13(struct command *cmd, YabInterface *yab) -{ - char *id, *option; - int pos; - - pos = pop(stNUMBER)->value; - option = pop(stSTRING)->pointer; - id = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Treebox13(id,option,pos, yab); -} - -void drawset4(struct command *cmd, YabInterface *yab) -{ - char *option, *color, *view; - - view = pop(stSTRING)->pointer; - color = pop(stSTRING)->pointer; - option = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_DrawSet4(option, color, view, yab); -} - -void launch(struct command *cmd, YabInterface *yab) -{ - char *strg; - strg = pop(stSTRING)->pointer; - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Launch(strg, yab); -} - -int sound(const char* filename, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_Sound(filename, yab); -} - -void soundstop(struct command *cmd, YabInterface *yab) -{ - int id; - - id = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SoundStop(id, yab); -} - -void soundwait(struct command *cmd, YabInterface *yab) -{ - int id; - - id = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_SoundWait(id, yab); -} - -int mediasound(const char* filename, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_MediaSound(filename, yab); -} - -void mediasoundstop(struct command *cmd, YabInterface *yab) -{ - int id; - - id = pop(stNUMBER)->value; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_MediaSoundStop(id, yab); -} -int iscomputeron(YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_IsComputerOn(yab); -} - -void attribute1(struct command *cmd, YabInterface *yab) -{ - char *type, *name, *value, *filename; - - filename = pop(stSTRING)->pointer; - value = pop(stSTRING)->pointer; - name = pop(stSTRING)->pointer; - type = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_Attribute1(type, name, value, filename, yab); -} - -void attributeclear(struct command *cmd, YabInterface *yab) -{ - char *name, *filename; - - filename = pop(stSTRING)->pointer; - name = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_AttributeClear(name, filename, yab); -} - - -char* attributeget1(const char* name, const char* filename, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return my_strdup((char*)yi_AttributeGet1(name, filename, yab)); -} - -double attributeget2(const char* name, const char* filename, YabInterface *yab, int line, const char* libname) -{ - yi_SetCurrentLineNumber(line, libname, yab); - return yi_AttributeGet2(name, filename, yab); -} - -void shortcut(struct command *cmd, YabInterface *yab) -{ - char *view, *key, *msg; - - msg = pop(stSTRING)->pointer; - key = pop(stSTRING)->pointer; - view = pop(stSTRING)->pointer; - - yi_SetCurrentLineNumber(cmd->line, (const char*)cmd->lib->s, yab); - yi_ShortCut(view, key, msg, yab); -} - -void gettermkey(char *keybuff) /* read a key from terminal */ -{ -#ifdef BUILD_NCURSES - char *skey=NULL; - int key; /* returned key */ - - do key=getch(); while(key==ERR); - switch(key) { - case KEY_UP: skey=ykey[kUP];break; - case KEY_DOWN: skey=ykey[kDOWN];break; - case KEY_LEFT: skey=ykey[kLEFT];break; - case KEY_RIGHT: skey=ykey[kRIGHT];break; - case KEY_DC: skey=ykey[kDEL];break; - case KEY_IC: skey=ykey[kINS];break; - case KEY_IL: skey=ykey[kINS];break; - case KEY_CLEAR: skey=ykey[kCLEAR];break; - case KEY_HOME: skey=ykey[kHOME];break; -#ifdef KEY_END - case KEY_END: skey=ykey[kEND];break; -#endif - case KEY_F0: skey=ykey[kF0];break; - case KEY_F(1): skey=ykey[kF1];break; - case KEY_F(2): skey=ykey[kF2];break; - case KEY_F(3): skey=ykey[kF3];break; - case KEY_F(4): skey=ykey[kF4];break; - case KEY_F(5): skey=ykey[kF5];break; - case KEY_F(6): skey=ykey[kF6];break; - case KEY_F(7): skey=ykey[kF7];break; - case KEY_F(8): skey=ykey[kF8];break; - case KEY_F(9): skey=ykey[kF9];break; - case KEY_F(10): skey=ykey[kF10];break; - case KEY_F(11): skey=ykey[kF11];break; - case KEY_F(12): skey=ykey[kF12];break; - case KEY_F(13): skey=ykey[kF13];break; - case KEY_F(14): skey=ykey[kF14];break; - case KEY_F(15): skey=ykey[kF15];break; - case KEY_F(16): skey=ykey[kF16];break; - case KEY_F(17): skey=ykey[kF17];break; - case KEY_F(18): skey=ykey[kF18];break; - case KEY_F(19): skey=ykey[kF19];break; - case KEY_F(20): skey=ykey[kF20];break; - case KEY_F(21): skey=ykey[kF21];break; - case KEY_F(22): skey=ykey[kF22];break; - case KEY_F(23): skey=ykey[kF23];break; - case KEY_F(24): skey=ykey[kF24];break; - case KEY_BACKSPACE: skey=ykey[kBACKSPACE];break; - case KEY_NPAGE: skey=ykey[kSCRNDOWN];break; - case KEY_PPAGE: skey=ykey[kSCRNUP];break; - case KEY_ENTER: skey=ykey[kENTER];break; - default: - if (isprint(key)) { - keybuff[0]=key; - keybuff[1]='\0'; - } else if (key<0 || key>=KEY_MAX) { - keybuff[0]='\0'; - } else { - switch(key) { - case 0x1b:skey=ykey[kESC];break; - case 0x7f:skey=ykey[kDEL];break; - case 0xa:skey=ykey[kENTER];break; - case 0x9:skey=ykey[kTAB];break; - default: - sprintf(keybuff,"key%x",key); - } - } - break; - } - if (skey) strcpy(keybuff,skey); - snooze(20000); -#endif -} - diff --git a/src/io.c b/src/io.c deleted file mode 100644 index 93015d8..0000000 --- a/src/io.c +++ /dev/null @@ -1,1598 +0,0 @@ -/* - - YABASIC --- a simple Basic Interpreter - written by Marc-Oliver Ihm 1995-2004 - homepage: www.yabasic.de - - io.c --- code for screen and file i/o - - 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 - -*/ - - -/* ------------- defines ---------------- */ - -#ifdef WINDOWS -#define WM_WANTKEY (WM_APP+7) -#endif - -/* ------------- includes ---------------- */ - -#ifndef YABASIC_INCLUDED -#include "yabasic.h" /* all prototypes and structures */ -#endif - - -/* ------------- local defines ----------------- */ - -#define YC_BLACK 0 -#define YC_WHITE 1 -#define YC_RED 2 -#define YC_BLUE 3 -#define YC_GREEN 4 -#define YC_YELLOW 5 -#define YC_CYAN 6 -#define YC_MAGENTA 7 - -#ifndef COLOR_BLACK -#define COLOR_BLACK 0 -#define COLOR_RED 1 -#define COLOR_GREEN 2 -#define COLOR_YELLOW 3 -#define COLOR_BLUE 4 -#define COLOR_MAGENTA 5 -#define COLOR_CYAN 6 -#define COLOR_WHITE 7 -#endif -#ifndef A_COLOR -#define A_COLOR 0xff00 -#endif - -/* ------------- external references ---------------- */ - -extern int mylineno; /* current line number */ -extern int yyparse(); /* call bison parser */ - - -/* ------------- local functions ---------------- */ - -static int onechar(void); /* read one char from currentinstream */ -static void backchar(int); /* put char back into stream */ -static void readline(void); /* read one line from current stream */ -static void curinit(void); /* initialize curses */ -static void initcol(void); /* initialize curses colors */ -void myswitch(int); /* switch to specified stream */ -int checkstream(void); /* test if currst is still valid */ -#ifdef WINDOWS -static DWORD keythread(LPWORD); /* wait for key input from console */ -static int is_valid_key(INPUT_RECORD *); /* check if input rec is valid key */ -#endif -int name2yc(char *); /* convert a color name to an integer */ -int yc2oc(int,int); /* convert a yabasic color to operating system color */ -char *yc2short(int); /* convert yabasic colours to short colour name */ -#ifdef UNIX -int oc2yc(int); /* convert an operating system color to yabasic color */ -#endif - -/* ------------- global variables ---------------- */ - -static int prompted; /* TRUE, if prompt is fresh */ -int read_controls; /* TRUE, if input should read control characters */ -FILE *streams[FOPEN_MAX]; /* file streams */ -int stream_modes[FOPEN_MAX]; /* modes for streams */ -int lprstream=-1; /* stream associated with lineprinter */ -static int currstr=STDIO_STREAM; /* currently switched stream */ -static FILE *cinstr; /* current stream for input */ -static FILE *coutstr; /* current stream for output */ -static char linebuffer[INBUFFLEN]; /* buffer for one line of input */ -int curinized=FALSE; /* true, if curses has been initialized */ -static char *currchar; /* current char to read */ -static short stdfc; /* standard foreground color of window */ -static short stdbc; /* standard background color of window */ -#ifdef UNIX -int winpid=-1; /* pid of process waiting for window keys */ -int termpid=-1; /* pid of process waiting for terminal keys */ -FILE *lineprinter=NULL; /* handle for line printer */ -#ifndef BUILD_NCURSES -int COLS = 80; -int LINES = 25; -#endif -#else -HANDLE wantkey=INVALID_HANDLE_VALUE; /* mutex to signal key desire */ -HANDLE gotkey=INVALID_HANDLE_VALUE; /* mutex to signal key reception */ -HANDLE wthandle=INVALID_HANDLE_VALUE; /* handle of win thread */ -HANDLE kthandle=INVALID_HANDLE_VALUE; /* handle of inkey thread */ -DWORD ktid; /* id of inkey thread */ -int LINES=0; /* number of lines on screen */ -int COLS=0; /* number of columns on screen */ -HANDLE ConsoleInput; /* handle for console input */ -HANDLE ConsoleOutput; /* handle for console output */ -HANDLE lineprinter=INVALID_HANDLE_VALUE; /* handle for line printer */ -#endif - - -/* ------------- functions ---------------- */ - -void create_print(char type) /* create command 'print' */ -{ - struct command *cmd; - - cmd=add_command(cPRINT,NULL); - cmd->pointer=my_malloc(sizeof(int)); - /* store type of print */ - cmd->tag=type; -} - - -void print(struct command *cmd) /* print on screen */ -{ - int type; - struct stackentry *p,*q,*r; - static int last='n'; - char *s; - int x,y; - long int n; - double d; -#ifdef WINDOWS - CONSOLE_SCREEN_BUFFER_INFO csbi; - SMALL_RECT screen; - COORD to; - CHAR_INFO ci; -#endif - - r=NULL; - type=cmd->tag; - if (!checkstream()) return; - switch(type) { - case 'n': /* print newline */ - if (curinized && coutstr==stdout) { -#ifdef WINDOWS - GetConsoleScreenBufferInfo(ConsoleOutput,&csbi); - x=csbi.dwCursorPosition.X; - y=csbi.dwCursorPosition.Y; - if (y>=LINES-1) { - screen.Left=0; - screen.Right=COLS; - screen.Top=1; - screen.Bottom=LINES; - to.X=0; - to.Y=0; - ci.Char.AsciiChar=' '; - ci.Attributes=FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED; - ScrollConsoleScreenBuffer(ConsoleOutput,&screen,NULL,to,&ci); - to.X=0; - to.Y=y; - } else { - to.X=0; - to.Y=y+1; - } - SetConsoleCursorPosition(ConsoleOutput,to); - break; -#else -#ifdef BUILD_NCURSES - getyx(stdscr,y,x); - if (y>=LINES-1) { - scrl(1); - y=y-1; - } - move(y+1,0); - refresh(); -#endif - break; -#endif - } else { - string[0]='\n'; - if (abs(currstr)==lprstream) { - string[1]='\r'; - string[2]='\0'; - } else { - string[1]='\0'; - } - } - onestring(string); - break; - case 't': /* print tab */ - string[0]='\t'; - string[1]='\0'; - onestring(string); - break; - case 'd': /* print double value */ - p=pop(stNUMBER); - d=p->value; - n=(int)d; - if (n==d && dLONG_MIN) - sprintf(string,"%s%ld",(last=='d')?" ":"",n); - else - sprintf(string,"%s%g",(last=='d')?" ":"",d); - onestring(string); - break; - case 'U': - r=pop(stSTRING); - case 'u': /* print using */ - p=pop(stSTRING); - q=pop(stNUMBER); - type='d'; - s=string; - if (last=='d') { - *s=' '; - s++; - } - if (!myformat(s,q->value,p->pointer,r?r->pointer:NULL)) { - sprintf(string,"'%s' is not a valid format",(char *)p->pointer); - error(ERROR,string); - break; - } - onestring(string); - break; - case 's': - p=pop(stSTRING); - onestring((char *)p->pointer); - break; - } - last=type; -} - - -void mymove() /* move to specific position on screen */ -{ -#ifdef BUILD_NCURSES - int x,y; -#ifdef WINDOWS - COORD coord; -#endif - - y=(int)pop(stNUMBER)->value; - if (y<0) y=0; - if (y>LINES-1) y=LINES-1; - x=(int)pop(stNUMBER)->value; - if (x<0) x=0; - if (x>COLS-1) x=COLS-1; - if (!curinized) { - error(ERROR,"need to call 'clear screen' first"); - return; - } -#ifdef UNIX - move(y,x); - refresh(); -#else - coord.X=x; - coord.Y=y; - SetConsoleCursorPosition(ConsoleOutput,coord); -#endif -#endif -} - - -void clearscreen() /* clear entire screen */ -{ -#ifdef WINDOWS - DWORD written; /* number of chars actually written */ - COORD coord; /* coordinates to start writing */ -#endif - - if (!curinized) curinit(); -#ifdef UNIX -#ifdef BUILD_NCURSES - clear(); - refresh(); -#else - error(ERROR,"ncurses support was not compiled!"); -#endif -#else - coord.X=0; - coord.Y=0; - FillConsoleOutputCharacter(ConsoleOutput,' ',LINES*COLS,coord,&written); - FillConsoleOutputAttribute(ConsoleOutput, - FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE, - LINES*COLS, - coord,&written); - SetConsoleCursorPosition(ConsoleOutput,coord); -#endif -} - - -static void curinit(void) /* initialize curses */ -{ -#ifdef WINDOWS - CONSOLE_SCREEN_BUFFER_INFO coninfo; /* receives console size */ -#endif - -#ifdef UNIX -#ifdef BUILD_NCURSES - initscr(); - initcol(); - setscrreg(0,LINES); - scrollok(stdscr,TRUE); - leaveok(stdscr,TRUE); - keypad(stdscr,TRUE); - intrflush(stdscr,FALSE); - curs_set(0); - def_prog_mode(); -#endif -#else - GetConsoleScreenBufferInfo(ConsoleOutput,&coninfo); - COLS=coninfo.dwSize.X; - LINES=coninfo.dwSize.Y; -#endif - curinized=TRUE; -} - - -char *inkey(double maxtime) /* get char from keyboard */ -{ - char *skey; -#ifdef WINDOWS - int ms; /* number of milliseconds to wait*/ - DWORD oflags; /* saves normal state of console input buffer */ - DWORD flags; /* new input mode for console input buffer */ - static char conkeybuff[100],winkeybuff[100]; -#else - fd_set readfds; - struct timeval tv; - int maxfd; - int winfd[2],termfd[2]; - char retkey[100]; - int status,ret; -#endif - - - if (maxtime>=0.0 && maxtime<0.01) maxtime=0.01; - if (!curinized) { - error(ERROR,"need to call 'clear screen' first"); - return my_strdup(""); - } -#ifdef UNIX -#ifdef BUILD_NCURSES - retkey[0]='\0'; - winfd[0]=winfd[1]=termfd[0]=termfd[1]=-1; - winpid=termpid=-1; - if (pipe(winfd) || pipe(termfd)) { - error(ERROR,"Couldn't open pipes"); - goto sane_state; - } - - winpid=fork(); - if (winpid==0) { - /* this is the child */ - signal(SIGINT,SIG_DFL); - signal(SIGFPE,SIG_DFL); - signal(SIGSEGV,SIG_DFL); - retkey[0]='\0'; -#ifndef BEOS - if (winopened) getwinkey(retkey); -#endif - if (*retkey) write(winfd[1],retkey,strlen(retkey)); - wait(&status); - exit(0); - } else if (winpid==-1) { - error(ERROR,"couldn't fork child"); - goto sane_state; - } - - termpid=fork(); - if (termpid==0) { - /* this is the child */ - signal(SIGINT,SIG_DFL); - signal(SIGFPE,SIG_DFL); - signal(SIGSEGV,SIG_DFL); - retkey[0]='\0'; - noecho(); - cbreak(); - timeout(-1); - gettermkey(retkey); - if (*retkey) write(termfd[1],retkey,strlen(retkey)); - wait(&status); - exit(0); - } else if (termpid==-1) { - error(ERROR,"Couldn't fork child"); - goto sane_state; - } - - FD_ZERO(&readfds); - FD_SET(termfd[0],&readfds); - FD_SET(winfd[0],&readfds); - fflush(stdout); - maxfd=(termfd[0]>winfd[0])?termfd[0]:winfd[0]; - if (maxtime>=0) { - tv.tv_sec=(int)maxtime; - tv.tv_usec=(maxtime-(int)maxtime)*1000000.; - ret=select(maxfd+1,&readfds,NULL,NULL,&tv); - } else { - ret=select(maxfd+1,&readfds,NULL,NULL,NULL); - } - if (ret==-1) { - error(ERROR,"select failed"); - goto sane_state; - } - - if (FD_ISSET(termfd[0],&readfds)) { - ret=read(termfd[0],retkey,100); - } else if (FD_ISSET(winfd[0],&readfds)) { - ret=read(winfd[0],retkey,100); - // if (!strncmp("MB",retkey,2)) getmousexybm(retkey,&mousex,&mousey,&mouseb,&mousemod); - } - else ret=0; - retkey[ret]='\0'; - sane_state: - skey=retkey; - if (winfd[0]>0) close(winfd[0]); - if (winfd[1]>0) close(winfd[1]); - if (termfd[0]>0) close(termfd[0]); - if (termfd[1]>0) close(termfd[1]); - if (termpid>0) { - kill(termpid,SIGTERM); - waitpid(termpid,&status,0); - termpid=-1; - } - if (winpid>0) { - kill(winpid,SIGTERM); - waitpid(winpid,&status,0); - winpid=-1; - } - reset_prog_mode(); /* prepare for input afterwards */ -#endif -#elif WINDOWS - /* create event to signal key */ - if (gotkey==INVALID_HANDLE_VALUE) gotkey=CreateEvent(NULL,FALSE,FALSE,NULL); - if (wantkey==INVALID_HANDLE_VALUE) wantkey=CreateEvent(NULL,TRUE,FALSE,NULL); - - conkeybuff[0]=winkeybuff[0]='\0'; - - GetConsoleMode(ConsoleInput,&oflags); - flags=oflags&~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT); - SetConsoleMode(ConsoleInput,flags); - - /* create thread to observe console */ - if (kthandle==INVALID_HANDLE_VALUE) { - kthandle=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)keythread, - (LPVOID)conkeybuff,0,(LPDWORD)&ktid); - } - /* signal, that we want a key */ - if (winopened) { - SendMessage(window,WM_WANTKEY,0,(LPARAM)winkeybuff); - } - SetEvent(wantkey); - ms=(int)(1000*maxtime); - if (ms<0) - WaitForSingleObject(gotkey,INFINITE); - else - WaitForSingleObject(gotkey,ms); - - ResetEvent(wantkey); - SetConsoleMode(ConsoleInput,oflags); - if (*winkeybuff) - skey=winkeybuff; - else - skey=conkeybuff; -#endif - return my_strdup(skey); -} - - -#ifdef WINDOWS -static DWORD keythread(LPWORD lparam) /* wait for key input from console */ -{ - INPUT_RECORD inrec; /* for reading key-event */ - int key,skey; - int num; - char *keybuff; - HANDLE evn[2]; - - keybuff=(char *)lparam; - keybuff[0]='\0'; - evn[0]=wantkey; - evn[1]=ConsoleInput; - do { - do { - do { - WaitForMultipleObjects(2,evn,TRUE,INFINITE); - ReadConsoleInput(ConsoleInput,&inrec,1,&num); - } while(!is_valid_key(&inrec)); - if (isprint(inrec.Event.KeyEvent.uChar.AsciiChar)) { - keybuff[0]=inrec.Event.KeyEvent.uChar.AsciiChar; - keybuff[1]='\0'; - } else { - key=inrec.Event.KeyEvent.wVirtualKeyCode; - skey=-1; - switch(key) { - case 0x1b: skey=kESC;break; - case 0x0d: skey=kENTER;break; - case 0x09: skey=kTAB;break; - case 0x21: skey=kSCRNUP;break; - case 0x22: skey=kSCRNDOWN;break; - case 0x70: skey=kF1;break; - case 0x71: skey=kF2;break; - case 0x72: skey=kF3;break; - case 0x73: skey=kF4;break; - case 0x74: skey=kF5;break; - case 0x75: skey=kF6;break; - case 0x76: skey=kF7;break; - case 0x77: skey=kF8;break; - case 0x78: skey=kF9;break; - case 0x79: skey=kF10;break; - case 0x7a: skey=kF11;break; - case 0x7b: skey=kF12;break; - case 0x24: skey=kHOME;break; - case 0x23: skey=kEND;break; - case 0x2d: skey=kINS;break; - case 0x2e: skey=kDEL;break; - case 0x08: skey=kBACKSPACE;break; - case 0x27: skey=kRIGHT;break; - case 0x25: skey=kLEFT;break; - case 0x28: skey=kDOWN;break; - case 0x26: skey=kUP;break; - default: - sprintf(keybuff,"key%x",key); - } - if (skey>0) strcpy(keybuff,ykey[skey]); - } - if (!keybuff[0]) printf("Loop !\n"); - } while(!keybuff[0]); - ResetEvent(wantkey); - SetEvent(gotkey); - }while(TRUE); - - return 0; -} - - -static int is_valid_key(INPUT_RECORD *rec) /* check if input rec contains valid key */ -{ - if (rec->EventType!=KEY_EVENT || - !rec->Event.KeyEvent.bKeyDown || - rec->Event.KeyEvent.wVirtualKeyCode==VK_SHIFT || - rec->Event.KeyEvent.wVirtualKeyCode==VK_CONTROL) { - return FALSE; - } - return TRUE; -} -#endif - - -char *replace(char *string) /* replace \n,\a, etc. */ -{ - char *from,*to; - char *p; - int val; - static char *hexdigits="0123456789abcdef"; - - from=to=string; - while(*from) { - if (*from=='\\') { - from++; - switch(*from) { - case 'n': *to='\n';break; - case 't': *to='\t';break; - case 'v': *to='\v';break; - case 'b': *to='\b';break; - case 'r': *to='\r';break; - case 'f': *to='\f';break; - case 'a': *to='\a';break; - case '\\': *to='\\';break; - case '\?': *to='\?';break; - case '\'': *to='\'';break; - case '\"': *to='\"';break; - case 'x': - val=0; - if ((p=strchr(hexdigits,tolower(*(from+1)))) && p-hexdigits<16) { - from++; - val=p-hexdigits; - if ((p=strchr(hexdigits,tolower(*(from+1)))) && p-hexdigits<16) { - from++; - val*=16; - val+=p-hexdigits; - } - } - *to=(char)val; - break; - default: - *to='\\'; - to++; - *to=*from; - } - } - else - *to=*from; - from++; - to++; - } - *to='\0'; - return string; -} - - -void create_myopen(int num) /* create command 'myopen' */ -{ - struct command *cmd; - - cmd=add_command(cOPEN,NULL); - cmd->tag=num; -} - - -void myopen(struct command *cmd) /* open specified file for given name */ -{ -#ifdef WINDOWS - char PrinterName[200]; /* Name of default Printer */ - char *n; /* points into PrinterName */ - DOC_INFO_1 di; -#endif - FILE *handle=NULL; - int stream,i; - char *name=NULL; - char *mode=NULL; - char **pmode; - static char *valid_modes[]={"r+","r","w","a","rb","wb","ab",""}; - static int smodes[]={smREADWRITE,smREAD,smWRITE,smWRITE,smREAD,smWRITE,smWRITE,smREAD}; - int smode; - - struct stackentry *p; - int has_mode,has_stream,printer=0; - /* decode cmd->tag */ - has_stream=cmd->tag&OPEN_HAS_STREAM; - has_mode=cmd->tag&OPEN_HAS_MODE; - /* printer=cmd->tag&OPEN_PRINTER;*/ - - if (has_mode) - mode=my_strdup(pop(stSTRING)->pointer); - else - mode=printer ? my_strdup("w") : my_strdup("r"); - if (printer) - name=my_strdup("/usr/bin/lpr"); - else - name=my_strdup(pop(stSTRING)->pointer); - - if (has_stream) { - stream=(int)pop(stNUMBER)->value; - } else { - stream=0; - for(i=1;ivalue=0.; - p->type=stNUMBER; - -/* - if (printer && print_to_file) { - sprintf(errorstring,"cannot open printer: already printing grafics"); - errorcode=6; - goto open_done; - }*/ - - if (badstream(stream,1)) { - sprintf(errorstring,"invalid stream number %d",stream); - errorcode=9; - goto open_done; - } - if (stream_modes[stream]!=smCLOSED) { - sprintf(errorstring,"stream already in use"); - errorcode=2; - goto open_done; - } - - smode=0; - for(pmode=valid_modes;**pmode;pmode++) { - if (!strcmp(*pmode,mode)) break; - smode++; - } - if (!**pmode) { - sprintf(errorstring,"\'%s\' is not a valid filemode",mode); - errorcode=3; - goto open_done; - } - - if (printer) { -#ifdef UNIX - lineprinter=popen(name,"w"); - if (!lineprinter) { - sprintf(errorstring,"could not open line printer"); - errorcode=7; - goto open_done; - } -#else - /* query win.ini for default printer */ - GetProfileString("windows","device",",,,",PrinterName,200); - - /* truncate printer name */ - n=PrinterName; - while(*n && *n!=',') n++; - *n='\0'; - - OpenPrinter(PrinterName,&lineprinter,NULL); - di.pDocName="yabasic text"; - di.pOutputFile=(LPTSTR)NULL; - di.pDatatype="RAW"; - if (!StartDocPrinter(lineprinter,1,(LPBYTE)&di)) { - sprintf(errorstring,"could not open line printer"); - errorcode=7; - goto open_done; - } - StartPagePrinter(lineprinter); -#endif - lprstream=stream; - } else { - handle=fopen(name,mode); - if (handle==NULL) { - sprintf(errorstring,"could not open '%s': %s",name,my_strerror(errno)); - errorcode=4; - goto open_done; - } - streams[stream]=handle; - } - stream_modes[stream]=smodes[smode]; - errorcode=0; - p->value=stream; - open_done: - if (name) my_free(name); - if (mode) my_free(mode); -} - - -void checkopen(void) /* check, if open has been sucessfull */ -{ - double result; - - result=pop(stNUMBER)->value; - if (result<=0) { - error(ERROR,errorstring); - } -} - - -void myclose(void) /* close the specified stream */ -{ - int s; -#ifdef WINDOWS - DWORD written; -#endif - - s=(int)pop(stNUMBER)->value; - if (s == -2){ - for(s=1;stype==cSEEK2) - mode=(char *)my_strdup(pop(stSTRING)->pointer); - else - mode=my_strdup("begin"); - p=(int)pop(stNUMBER)->value; - s=(int)pop(stNUMBER)->value; - pp=push(); - pp->value=0.; - pp->type=stNUMBER; - for(i=0;mode[i];i++) mode[i]=tolower(mode[i]); - if (!strcmp(mode,"begin")) { - m=SEEK_SET; - } else if (!strcmp(mode,"end")) { - m=SEEK_END; - } else if (!strcmp(mode,"here")) { - m=SEEK_CUR; - } else { - sprintf(errorstring,"seek mode '%s' is none of begin,end,here",mode); - errorcode=12; - my_free(mode); - return; - } - my_free(mode); - if (abs(s)==STDIO_STREAM || badstream(s,0)) return; - if (!(stream_modes[s] & (smREAD | smWRITE | smREADWRITE))) { - sprintf(errorstring,"stream %d not open",s); - errorcode=11; - return; - } - if (fseek(streams[s],(long)p,m)) { - sprintf(errorstring,"could not position stream %d to byte %d",s,p); - errorcode=10; - return; - } - pp->value=1.0; -} - - -void create_pps(int type,int input) /* create command pushswitch or popswitch */ -{ - struct command *cmd; - - cmd=add_command(type,NULL); - cmd->args=input; -} - - -void push_switch(struct command *cmd) /* push current stream on stack and switch to new one */ -{ - static int oldstream=STDIO_STREAM; - struct stackentry *s; - int stream; - - stream=(int)pop(stNUMBER)->value; - if (badstream(stream,0)) return; - if (!cmd->args) stream=-stream; - - s=push(); - s->type=stNUMBER; - s->value=oldstream; - if (infolevel>=DEBUG) { - sprintf(string,"pushing %d on stack, switching to %d",oldstream,stream); - error(DEBUG,string); - } - oldstream=stream; - myswitch(stream); -} - - -void pop_switch(void) /* pop current stream from stack and switch to it */ -{ - int stream; - - stream=(int)pop(stNUMBER)->value; - if (infolevel>=DEBUG) { - sprintf(string,"popping %d from stack, switching to it",stream); - error(DEBUG,string); - } - myswitch(stream); -} - - -void myswitch(int stream) /* switch to specified stream */ -{ - int stdio,input; - - stdio=(abs(stream)==STDIO_STREAM); - input=(stream>0); - currstr=stream; - if (stream<0) stream=-stream; - if (badstream(stream,0)) return; - - if (stdio) { - cinstr=stdin; - coutstr=stdout; - } else { - cinstr=coutstr=NULL; - if (input) - cinstr=streams[stream]; - else - coutstr=streams[stream]; - } -} - - -int checkstream(void) /* test if currst is still valid */ -{ - int stdio,input; - - stdio=(abs(currstr)==STDIO_STREAM); - input=(currstr>0); - - if (!stdio) { - if (input && !(stream_modes[abs(currstr)] & smREAD| smREADWRITE)) { - sprintf(string,"stream %d not open for reading",abs(currstr)); - error(ERROR,string); - return FALSE; - } - if (!input && !(stream_modes[abs(currstr)] & (smWRITE | smPRINT))) { - sprintf(string,"stream %d not open for writing or printing",abs(currstr)); - error(ERROR,string); - return FALSE; - } - } - return TRUE; -} - - -void testeof(struct command *cmd) /* close the specified stream */ -{ - int s,c; - struct stackentry *result; - - s=(int)pop(stNUMBER)->value; - if (s!=STDIO_STREAM && badstream(s,0)) return; - result=push(); - result->type=stNUMBER; - if (s && !(stream_modes[s] & smREAD)) { - result->value=1.; - return; - } - if (!s) { - result->value=0.; - return; - } - c=getc(streams[s]); - if (c==EOF) { - result->value=1.; - return; - } - - result->value=0.; - ungetc(c,streams[s]); - return; -} - - -int badstream(int stream,int errcode) /* test for valid stream id */ -{ - if (stream!=STDIO_STREAM && (stream>FOPEN_MAX-4 || stream<=0)) { - sprintf(errcode?errorstring:string,"invalid stream: %d (can handle only streams from 1 to %d)",stream,FOPEN_MAX-4); - if (errcode) - errorcode=errcode; - else - error(ERROR,string); - return TRUE; - } - return FALSE; -} - - -void create_myread(char type,int tileol) /* create command 'read' */ -{ - struct command *cmd; - - cmd=add_command(cREAD,NULL); - cmd->args=tileol; /* true, if read should go til eol */ - cmd->tag=type; /* can be 'd' or 's' */ -} - - -void myread(struct command *cmd) /* read string or double */ -{ - double d; - static char buffer[INBUFFLEN]; /* buffer with current input */ - int numread; /* number of bytes read */ - int tileol; /* true, if read should go til end of line */ - struct stackentry *s; - int currch; /* current character */ - - numread=0; /* no chars read'til now */ - buffer[0]='\0'; - tileol=cmd->args; - - /* skip leading whitespace */ - if (!tileol) { - do { - currch=onechar(); - } while(currch==' ' || currch=='\t'); - /* put back last char */ - if (currch!=EOF && currch!='\0') backchar(currch); - if (currch=='\0' || currch==EOF) goto done; - } - - /* read chars */ - do { - currch=onechar(); - buffer[numread]=currch; - numread++; - } while(((tileol && currch!='\0') || - (!tileol && currch!=' ' && - currch!='\t' && currch!='\0')) && - currch!=EOF && numreadtag=='s') { /* read string */ - s=push(); - s->type=stSTRING; - s->pointer=my_strdup(buffer);} - else { /* read double */ - s=push(); - s->type=stNUMBER; - s->value=0.0; - if (buffer[0] && (sscanf(buffer,"%lf",&d)==1)) s->value=d; - } -} - - -static void readline(void) /* read one line from current stream */ -{ -#ifdef UNIX - char *nl; /* position of newline */ - int x,y; -#else - int read; -#endif - - if (!checkstream()) return; - linebuffer[0]='\0'; -#ifdef UNIX - if (curinized && cinstr==stdin) { - ; - #ifdef BUILD_NCURSES - getyx(stdscr,y,x); -#ifdef HAVE_GETNSTR - getnstr(linebuffer,INBUFFLEN); -#else - getstr(linebuffer); -#endif - if ((nl=strchr(linebuffer,'\0'))) { - *nl='\n'; - *(nl+1)='\0'; - } - if (y>=LINES-1) scrl(1); - refresh(); - #endif - } -#else - if (curinized && cinstr==stdin) { - ; - #ifdef BUILD_NCURSES - FlushConsoleInputBuffer(ConsoleInput); - ReadConsole(ConsoleInput,linebuffer,INBUFFLEN,&read,NULL); - if (read>=2) { - linebuffer[read-2]='\n'; - linebuffer[read-1]='\0'; - } - #endif - } -#endif - else { - fgets(linebuffer,INBUFFLEN,cinstr); - } - currchar=linebuffer; - prompted=FALSE; -} - - -static int onechar() /* read one char from cinstr */ -{ - int ch; - - if (!checkstream()) return '\0'; - if (cinstr==stdin) { - if (!currchar || !*currchar) { - readline(); - } - do { - ch=*currchar; - currchar++; - } while(! (!iscntrl(ch) || strchr(" \t\n",ch) || read_controls || ch=='\0')); - } else { - do { - ch=fgetc(cinstr); - } while(! (!iscntrl(ch) || strchr(" \t\n",ch) || read_controls || ch=='\0' || ch==EOF)); - } - - if (ch=='\n' || ch==EOF) - return '\0'; - else - return ch; -} - - -static void backchar(int ch) /* put char back into stream */ -{ - if (!checkstream()) return; - if (cinstr==stdin) { - if (currchar>linebuffer) currchar--; - } - else { - ungetc(ch,cinstr); - } -} - - -void chkprompt() /* print an intermediate prompt if necessary */ -{ - if (cinstr==stdin && (!currchar || !*currchar) && !prompted) onestring("?"); -} - - -void create_onestring(char *str) /* create command 'onestring' */ -{ - struct command *cmd; - - cmd=add_command(cONESTRING,NULL); - cmd->pointer=my_strdup(str); -} - - -void onestring(char *s) /* write string to file */ -{ -#ifdef WINDOWS - DWORD len,written; -#endif - - if (!checkstream()) return; - if (curinized && abs(currstr)==STDIO_STREAM) { - ; - #ifdef BUILD_NCURSES -#ifdef UNIX - addstr(s); - refresh(); -#else - len=strlen(s); - WriteConsole(ConsoleOutput,s,len,&written,NULL); -#endif -#endif - } else if (abs(currstr)==lprstream) { -#ifdef UNIX - fprintf(lineprinter,"%s",s); - fflush(lineprinter); -#else - len=strlen(s); - WritePrinter(lineprinter,s,len,&written); -#endif - } else { - fprintf(coutstr,"%s",s); - fflush(coutstr); - } - prompted=TRUE; -} - - -void create_colour(int flag) /* create command 'colour' */ -{ - struct command *c; - - c=add_command(cCOLOUR,NULL); - c->args=flag; -} - - -void colour(struct command *cmd) /* switch on colour */ -{ - char *fore=NULL,*back=NULL,*p; - int fc,bc; - - if (cmd->args && !curinized) { - error(ERROR,"need to call 'clear screen' first"); - return; - } - if (cmd->args==0) { - if (!curinized) return; -#ifdef UNIX - ; - #ifdef BUILD_NCURSES - if (has_colors()) - attrset(A_NORMAL|COLOR_PAIR(stdfc*8+stdbc)); - else - attrset(A_NORMAL); - return; - #endif -#else - SetConsoleTextAttribute(ConsoleOutput,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); - return; -#endif - } else if (cmd->args==1) { -#ifdef UNIX - ; - #ifdef BUILD_NCURSES - if (has_colors()) - attrset(A_NORMAL|COLOR_PAIR(stdbc*8+stdfc)); - else { - attrset(A_REVERSE); - return; - } - #endif -#else - SetConsoleTextAttribute(ConsoleOutput,BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE); - return; -#endif - } else { /* decode colours */ -#ifdef UNIX - ; - #ifdef BUILD_NCURSES - if (!has_colors()) { - pop(stSTRING); - if (cmd->args==3) pop(stSTRING); - attrset(A_REVERSE); - return; - } - #endif -#endif - if (cmd->args==2) { - back=NULL; - fore=pop(stSTRING)->pointer; - for(p=fore;*p;p++) *p=tolower(*p); - } else { - back=pop(stSTRING)->pointer; - for(p=back;*p;p++) *p=tolower(*p); - fore=pop(stSTRING)->pointer; - for(p=fore;*p;p++) *p=tolower(*p); - } - fc=name2yc(fore); - if (fc<0) { - sprintf(string,"unknown foreground colour: '%s'",fore); - error(ERROR,string); - } - bc=stdbc; - if (back) { - bc=name2yc(back); - if (fc<0) { - sprintf(string,"unknown background colour: '%s'",back); - error(ERROR,string); - } - } -#ifdef UNIX - #ifdef BUILD_NCURSES - attrset(COLOR_PAIR(fc*8+bc)); - #endif -#else - SetConsoleTextAttribute(ConsoleOutput,(WORD)(yc2oc(fc,TRUE)|yc2oc(bc,FALSE))); -#endif - } -} - - -static void initcol(void) /* initialize curses colors */ -{ - static int first=TRUE; -#ifdef UNIX - int i,j,col; - short f,b; -#else - CONSOLE_SCREEN_BUFFER_INFO csbi; -#endif - - if (!first) return; - first=FALSE; -#ifdef UNIX - #ifdef BUILD_NCURSES - if (!has_colors()) return; - start_color(); - - for(i=0;i<8;i++) { - for(j=0;j<8;j++) { - if (!i && !j) continue; - init_pair(i*8+j,yc2oc(i,TRUE),yc2oc(j,FALSE)); - } - } - init_color(COLOR_YELLOW,1000,1000,0); - - col=inch()&A_COLOR; - pair_content(col,&f,&b); - stdfc=oc2yc(f); - stdbc=oc2yc(b); - bkgdset(COLOR_PAIR(stdfc*8+stdbc)); -#endif -#else - GetConsoleScreenBufferInfo(ConsoleOutput,&csbi); - stdfc=csbi.wAttributes & (FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED); - stdbc=csbi.wAttributes & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED); -#endif -} - - -int name2yc(char *name) /* convert a color name to an integer */ -{ - char *c; - - for(c=name;*c;c++) *c=tolower(*c); - if (!strcmp(name,"black") || !strcmp(name,"bla")) return YC_BLACK; - if (!strcmp(name,"white") || !strcmp(name,"whi")) return YC_WHITE; - if (!strcmp(name,"red") || !strcmp(name,"red")) return YC_RED; - if (!strcmp(name,"blue") || !strcmp(name,"blu")) return YC_BLUE; - if (!strcmp(name,"green") || !strcmp(name,"gre")) return YC_GREEN; - if (!strcmp(name,"yellow") || !strcmp(name,"yel")) return YC_YELLOW; - if (!strcmp(name,"cyan") || !strcmp(name,"cya")) return YC_CYAN; - if (!strcmp(name,"magenta") || !strcmp(name,"mag")) return YC_MAGENTA; - return -1; -} - - -int yc2oc(int yc,int fore) /* convert a yabasic color to operating system color */ -{ -#ifdef UNIX - fore=0; /* stop gcc from complaining */ - if (yc==YC_BLACK) return COLOR_BLACK; - if (yc==YC_WHITE) return COLOR_WHITE; - if (yc==YC_RED) return COLOR_RED; - if (yc==YC_BLUE) return COLOR_BLUE; - if (yc==YC_GREEN) return COLOR_GREEN; - if (yc==YC_YELLOW) return COLOR_YELLOW; - if (yc==YC_CYAN) return COLOR_CYAN; - if (yc==YC_MAGENTA) return COLOR_MAGENTA; -#else - if (fore) { - if (yc==YC_BLACK) return 0; - if (yc==YC_WHITE) return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - if (yc==YC_RED) return FOREGROUND_RED; - if (yc==YC_BLUE) return FOREGROUND_BLUE; - if (yc==YC_GREEN) return FOREGROUND_GREEN; - if (yc==YC_YELLOW) return FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY; - if (yc==YC_CYAN) return FOREGROUND_GREEN | FOREGROUND_BLUE; - if (yc==YC_MAGENTA) return FOREGROUND_BLUE | FOREGROUND_RED; - } else { - if (yc==YC_BLACK) return 0; - if (yc==YC_WHITE) return BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; - if (yc==YC_RED) return BACKGROUND_RED; - if (yc==YC_BLUE) return BACKGROUND_BLUE; - if (yc==YC_GREEN) return BACKGROUND_GREEN; - if (yc==YC_YELLOW) return BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY; - if (yc==YC_CYAN) return BACKGROUND_GREEN | BACKGROUND_BLUE; - if (yc==YC_MAGENTA) return BACKGROUND_BLUE | BACKGROUND_RED; - } -#endif - return -1; -} - - -int oc2yc(int oc) /* convert an operating system color to yabasic color */ -{ -#ifdef UNIX - if (oc==COLOR_BLACK) return YC_BLACK; - if (oc==COLOR_WHITE) return YC_WHITE; - if (oc==COLOR_RED) return YC_RED; - if (oc==COLOR_BLUE) return YC_BLUE; - if (oc==COLOR_GREEN) return YC_GREEN; - if (oc==COLOR_YELLOW) return YC_YELLOW; - if (oc==COLOR_CYAN) return YC_CYAN; - if (oc==COLOR_MAGENTA) return YC_MAGENTA; -#else - if (oc==0) return YC_BLACK; - if (oc==(FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN) || - oc==(BACKGROUND_RED|BACKGROUND_BLUE|BACKGROUND_GREEN)) return YC_WHITE; - if (oc==(FOREGROUND_RED) || - oc==(BACKGROUND_RED)) return YC_RED; - if (oc==(FOREGROUND_BLUE) || - oc==(BACKGROUND_BLUE)) return YC_BLUE; - if (oc==(FOREGROUND_GREEN) || - oc==(BACKGROUND_GREEN)) return YC_GREEN; - if (oc==(FOREGROUND_RED|FOREGROUND_GREEN) || - oc==(BACKGROUND_RED|BACKGROUND_GREEN) || - oc==(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY) || - oc==(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_INTENSITY)) return YC_YELLOW; - if (oc==(FOREGROUND_BLUE|FOREGROUND_GREEN) || - oc==(BACKGROUND_BLUE|BACKGROUND_GREEN)) return YC_CYAN; - if (oc==(FOREGROUND_RED|FOREGROUND_BLUE) || - oc==(BACKGROUND_RED|BACKGROUND_BLUE)) return YC_MAGENTA; -#endif - return -1; -} - - -void putchars(void) /* put rect onto screen */ -{ - char *ch,text,fore[4],back[4]; - int n,sx,sy,x,y,f,b; - int tox,toy; - int oldx,oldy; -#ifdef WINDOWS - CONSOLE_SCREEN_BUFFER_INFO csbi; - COORD cp; - char buff[2]; - int written; -#endif - - toy=(int)(pop(stNUMBER)->value); - tox=(int)(pop(stNUMBER)->value); - ch=pop(stSTRING)->pointer; -#ifdef UNIX -#ifdef BUILD_NCURSES - getyx(stdscr,oldy,oldx); -#endif -#else - GetConsoleScreenBufferInfo(ConsoleOutput,&csbi); - oldx=csbi.dwCursorPosition.X; - oldy=csbi.dwCursorPosition.Y; -#endif - if (sscanf(ch,"%d,%d:%n",&sx,&sy,&n)!=2) { - error(ERROR,"illegal screen string"); - return; - } - ch+=n; - for(x=tox;x=COLS) continue; - for(y=toy;y=COLS || y<0 || y>=LINES) { - for(n=0;n<10;n++) if (*ch) ch++; - continue; - } - if (!*ch) { - text=' '; - f=YC_BLACK; - b=YC_BLACK; - } else { - text=*ch; - strncpy(fore,ch+2,3); - fore[3]='\0'; - strncpy(back,ch+6,3); - back[3]='\0'; - for(n=0;n<10;n++) if (*ch) ch++; - f=name2yc(fore); - if (f<0) f=YC_WHITE; - b=name2yc(back); - if (b<0) b=YC_WHITE; - } -#ifdef UNIX - #ifdef BUILD_NCURSES - if (has_colors()) attrset(COLOR_PAIR(f*8+b)); - mvaddch(y,x,text); - #endif -#else - cp.X=x; - cp.Y=y; - SetConsoleCursorPosition(ConsoleOutput,cp); - SetConsoleTextAttribute(ConsoleOutput,(WORD)(yc2oc(f,TRUE)|yc2oc(b,FALSE))); - buff[0]=text; - buff[1]='\0'; - WriteConsole(ConsoleOutput,buff,1,&written,NULL); -#endif - } - } -#ifdef UNIX - #ifdef BUILD_NCURSES - if (has_colors()) - attrset(A_NORMAL|COLOR_PAIR(stdfc*8+stdbc)); - else - attrset(A_NORMAL); - move(y,x); - refresh(); - #endif -#else - cp.X=oldx; - cp.Y=oldy; - SetConsoleCursorPosition(ConsoleOutput,cp); - SetConsoleTextAttribute(ConsoleOutput,(WORD)(stdfc|stdbc)); -#endif - - return; -} - - -char *getchars(int xf,int yf,int xt,int yt) /* get rect from screen */ -{ - int x,y; -#ifdef UNIX - int c,ct,cc; -#endif - int cf,cb; - int oldx,oldy; - char *res; - char cols[20]; -#ifdef WINDOWS - CONSOLE_SCREEN_BUFFER_INFO csbi; - COORD cp; - char charbuff[2]; - WORD attrbuff[2]; - int read; -#endif - - if (xf>xt) {x=xf;xf=xt;xt=x;} - if (yf>yt) {y=yf;yf=yt;yt=y;} - - res=my_malloc(12+(xt-xf+1)*(yt-yf+1)*12); - sprintf(res,"%d,%d:",xt-xf+1,yt-yf+1); -#ifdef UNIX -#ifdef BUILD_NCURSES - getyx(stdscr,oldy,oldx); -#endif -#else - GetConsoleScreenBufferInfo(ConsoleOutput,&csbi); - oldx=csbi.dwCursorPosition.X; - oldy=csbi.dwCursorPosition.Y; -#endif - - for(x=xf;x<=xt;x++) { - for(y=yf;y<=yt;y++) { - if (y<0 || y>=LINES || x<0 || x>=COLS) { - strcat(res," blbl"); - } else { -#ifdef UNIX -#ifdef BUILD_NCURSES - c=mvinch(y,x); - ct=c&A_CHARTEXT; - if (!isprint(ct)) ct=' '; - cc=PAIR_NUMBER(c&A_COLOR); - cb=cc&7; - cf=(cc-cb)/8; - if (has_colors()) { - sprintf(cols,"%c:%s:%s,",ct,yc2short(cf),yc2short(cb)); - } else - { - - sprintf(cols,"%c:???:???,",ct); - } -#endif -#else - cp.X=x; - cp.Y=y; - ReadConsoleOutputCharacter(ConsoleOutput,charbuff,1,cp,&read); - charbuff[1]='\0'; - ReadConsoleOutputAttribute(ConsoleOutput,attrbuff,1,cp,&read); - cf=oc2yc(attrbuff[0]&(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)); - cb=oc2yc(attrbuff[0]&(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE)); - sprintf(cols,"%c:%s:%s,",charbuff[0],yc2short(cf),yc2short(cb)); -#endif - strcat(res,cols); - } - } - } -#ifdef UNIX -#ifdef BUILD_NCURSES - move(oldy,oldx); -#endif -#endif - res[strlen(res)-1]='\0'; - return res; -} - - -char *yc2short(int col) /* convert yabasic colours to short colour name */ -{ - static char r1[4],r2[4]; - static char *pr=r1; - - if (pr==r1) - pr=r2; - else - pr=r1; - - strcpy(pr,"***"); - if (col==YC_BLACK) strcpy(pr,"Bla"); - if (col==YC_WHITE) strcpy(pr,"Whi"); - if (col==YC_RED) strcpy(pr,"Red"); - if (col==YC_BLUE) strcpy(pr,"Blu"); - if (col==YC_GREEN) strcpy(pr,"Gre"); - if (col==YC_YELLOW) strcpy(pr,"Yel"); - if (col==YC_CYAN) strcpy(pr,"Cya"); - if (col==YC_MAGENTA) strcpy(pr,"Mag"); - - return pr; -} - diff --git a/src/libyab1.so b/src/libyab1.so deleted file mode 100755 index 7539119..0000000 Binary files a/src/libyab1.so and /dev/null differ diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 0d54a7f..0000000 --- a/src/main.c +++ /dev/null @@ -1,2252 +0,0 @@ -/* - -YABASIC --- a simple Basic Interpreter -written by Marc-Oliver Ihm 1995-2004 -homepage: www.yabasic.de - -main.c --- main() and auxilliary functions - -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 - -*/ - - -/* ------------- includes ---------------- */ - -// include "YabInterface.h" - -#ifndef YABASIC_INCLUDED -#include "yabasic.h" /* all prototypes and structures */ -#endif - - -/* ------------- defines ---------------- */ - -#define DONE {current=current->next;break;} /* reduces type-work */ -#define COPYRIGHT " Original yabasic Copyright 1995-2006 by Marc-Oliver Ihm\n\tyab Copyright 2006-2014 by Jan Bungeroth\n\tyab improvements Copyright 2013-2020 by Jim Saxton\n\tyab improvements Copyright 2018-2020 by BeSly Software Solutions\n\t\t(Thanks to Stephan Aßmus for Correction of Code)\n" -#define BANNER \ -"\n yab is yabasic, a BASIC programming language for Haiku.\n This is version " VERSION ", built on "\ -ARCHITECTURE " on " BUILD_TIME "\n\n " COPYRIGHT "\n\n" -#define BANNER_VERSION \ -"yab " VERSION ", built on " ARCHITECTURE "\n" COPYRIGHT -#define YABFORHELP "(type 'yab -help' for help)" -#define YABMAGIC "__YaBaSiC_MaGiC_CoOkIe__" - -/* ------------- external references ---------------- */ - -extern int mylineno; /* current line number */ -extern int yyparse(); /* call bison parser */ - - -/* ------------- local functions ---------------- */ - -static void std_diag(char *,int,char *); /* produce standard diagnostic */ -static void parse_arguments(int,char *argv[]); /* parse cmd line arguments */ -static void initialize(void); /* give correct values to pointers etc ... */ -static void run_it(YabInterface* yab); /* execute the compiled code */ -static void end_it(void); /* perform shutdown operations */ -#ifdef WINDOWS -static void chop_command(char *,int *,char ***); /* chops WIN95-commandline */ -#endif -void create_docu_array(void); /* create array with documentation */ -int equal(char *,char *,int); /* helper for processing options */ -void do_help(char *); /* process help option */ -static int mybind(char *); /* bind a program to the interpreter and save it */ -char *find_interpreter(char *); /* find interpreter with full path */ - -/* ------------- global variables ---------------- */ - -struct command *cmdroot; /* first command */ -struct command *cmdhead; /* next command */ -struct command *lastcmd; /* last command */ -struct command *current; /* currently executed command */ -int infolevel; /* controls issuing of error messages */ -int errorlevel; /* highest level of error message seen til now */ -static int debug_count; /* number of debug messages */ -static int note_count; /* number of notes */ -static int warning_count; /* number of warning messages */ -static int error_count; /* number of error messages */ -int interactive; /* true, if commands come from stdin */ -int is_bound; /* true, if this executable is bound */ -char* appdirectory; -static char *to_bind=NULL; /* name bound program to be written */ -FILE *bound_program=NULL; /* points to embedded yabasic program (if any) */ -char *string; /* for trash-strings */ -char *errorstring; /* for error-strings */ -int errorcode; /* error-codes */ -int enterkeyflag = 0; /* press enter to end program */ -static int commandcount; /* total number of commands */ -int program_state; /* state of program */ -char *progname=NULL; /* name of yabasic-program */ -int print_docu=FALSE; /* TRUE, if only docu should be printed */ -int hold_docu=FALSE; /* TRUE, if docu should be printed in portions */ -#ifdef WINDOWS -DWORD InitialConsole; /* initial state of console window */ -#endif -char *explanation[cLAST_COMMAND-cFIRST_COMMAND+1]; /* explanations of commands */ -char *explicit=NULL; /* yabasic commands given on the command line */ -char **yabargv; /* arguments for yabasic */ -int yabargc; /* number of arguments in yabargv */ -static int endreason=erNONE; /* reason for termination */ -static int exitcode=0; -static int signal_arrived=0; -/* timing */ -time_t compilation_start,compilation_end,execution_end; -char library_path[200]; /* full path to search libraries */ -char library_default[200]; /* default full path to search libraries */ -static struct command *docuhead=NULL; /* first docu in main */ -static int docucount=0; /* number of docu-lines in array */ -int check_compat=0; /* true, if compatibility should be checked */ -static char *interpreter_path=NULL; /* name of interpreter executing; i.e. ARGV[0] */ -static char *main_file_name=NULL; /* name of program to be executed */ - -YabInterface *yab; - -/* ------------- main program ---------------- */ - -int mmain(int argc,char **argv, YabInterface* y) -{ -#ifdef WINDOWS - CONSOLE_SCREEN_BUFFER_INFO csbi; - char *lp; - int fromlibpath; -#endif - int len; - - yab = y; - appdirectory = yi_GetApplicationDirectory(yab); - - // appdirectory=(char *)my_malloc(sizeof(argv[0])); - // strcpy(appdirectory, argv[0]); - - string=(char *)my_malloc(sizeof(char)*INBUFFLEN); - errorstring=(char *)my_malloc(sizeof(char)*INBUFFLEN); - *errorstring='\0'; - errorcode=0; - - program_state=HATCHED; - infolevel=WARNING; /* set the initial Infolevel */ - -#ifdef WINDOWS - /* get handle for current thread */ - DuplicateHandle(GetCurrentProcess(),GetCurrentThread(), - GetCurrentProcess(),&mainthread,THREAD_ALL_ACCESS,FALSE,0); - - /* get handle of instance */ - this_instance=GetModuleHandle(NULL); - - /* define my window class */ - myclass.style=0; - myclass.lpfnWndProc=(LPVOID)mywindowproc; - myclass.cbClsExtra=0; /* no extra bytes */ - myclass.cbWndExtra=0; - myclass.hInstance=this_instance; - myclass.hIcon=LoadIcon(this_instance,"yabasicIcon"); - myclass.hCursor=LoadCursor(NULL,IDC_ARROW); /* standard cursor */ - myclass.hbrBackground=(HBRUSH)COLOR_WINDOW; /* default-background */ - myclass.lpszMenuName=NULL; - myclass.lpszClassName=my_class; - - RegisterClass(&myclass); - - /* get console handles */ - ConsoleInput=GetStdHandle(STD_INPUT_HANDLE); - ConsoleOutput=GetStdHandle(STD_OUTPUT_HANDLE); - GetConsoleMode(ConsoleInput,&InitialConsole); - - /* find out, if launched from commandline */ - GetConsoleScreenBufferInfo(ConsoleOutput,&csbi); - Commandline=!((csbi.dwCursorPosition.X==0) && (csbi.dwCursorPosition.Y==0)); - if ((csbi.dwSize.X<=0) || (csbi.dwSize.Y <= 0)) Commandline=TRUE; - -#endif - /* get library path */ - library_path[0]='\0'; - library_default[0]='\0'; -#ifdef UNIX - strcpy(library_default,LIBRARY_PATH); -#else - fromlibpath=TRUE; - if (lp=getreg("librarypath")) { - strcpy(library_default,lp); - fromlibpath=TRUE; - } else if (lp=getreg("path")) { - strcpy(library_default,lp); - fromlibpath=FALSE; - } else { - library_default[0]='\0'; - fromlibpath=FALSE; - } -#endif - - /* find out, if this executable is bound to a yabasic program */ - interpreter_path=find_interpreter(argv[0]); - is_bound=isbound(); - - /* parse arguments */ - parse_arguments(argc,argv); - - /* brush up library path */ - if (!library_path[0]) strcpy(library_path,library_default); - len=strlen(library_path); -#ifdef UNIX - if (library_path[len-1]=='/' || library_path[len-1]=='\\') library_path[len-1]='\0'; -#else - if (library_path[0]) { - if (library_path[len-1]!='/' && library_path[len-1]!='\\') strcat(library_path,"\\"); - if (!fromlibpath) strcat(library_path,"lib\\"); - } -#endif - - time(&compilation_start); - error(DEBUG,"this is yab " VERSION); - initialize(); - program_state=INITIALIZED; - - error(NOTE,"calling parser/compiler"); - - if (interactive) { - printf("%s",BANNER); - printf("Enter your program and type RETURN twice when done.\n\n"); - printf("Your program will execute immediately and CANNOT BE SAVED;\n"); - printf("create your program with an EXTERNAL EDITOR, if you want to keep it.\n"); -#ifdef UNIX -#ifndef BEOS - printf("Type 'man yabasic' or see the file yabasic.htm for more information.\n\n"); -#else - printf("See the documentation for more information.\n\n"); -#endif -#else - printf("See the documentation within the start-menu for more information.\n\n"); -#endif - } - program_state=COMPILING; - if (yyparse() && errorlevel>ERROR) error(ERROR,"Couldn't parse program"); - - if (errorlevel>ERROR) create_docu_array(); - - add_command(cEND,NULL); - sprintf(string,"read %d line(s) and generated %d command(s)",mylineno,commandcount); - error(NOTE,string); - - time(&compilation_end); - - if (to_bind) { - struct libfile_name *lib; - if (mybind(to_bind)) { - sprintf(string,"Successfully bound '%s' and '%s' into '%s'",interpreter_path,main_file_name,to_bind); - error(INFO,string); - end_it(); - } else { - sprintf(string,"could not bind '%s' and '%s' into '%s'",interpreter_path,main_file_name,to_bind); - error(ERROR,string); - end_it(); - } - } - - if (errorlevel>ERROR && !check_compat) { - program_state=RUNNING; - run_it(yab); - } else { - program_state=FINISHED; - if (check_compat) - printf("Check for possible compatibility problems done\nProgram will not be executed, %d possible problem(s) reported\n",warning_count); - else - error(ERROR,"Program not executed"); - } - - program_state=FINISHED; - sprintf(string,"%d debug(s), %d note(s), %d warning(s), %d error(s)", - debug_count,note_count,warning_count,error_count); - error(NOTE,string); - time(&execution_end); - sprintf(string,"compilation time %g second(s), execution %g", - (double)(compilation_end-compilation_start),(double)(execution_end-compilation_end)); - error(NOTE,string); - end_it(); - return !(errorlevel>ERROR); -} - - - -/* ------------- subroutines ---------------- */ - - -static void std_diag(char *head,int type,char *name) /* produce standard diagnostic */ -{ - int n,i; - char *s; - struct stackentry *sp; - - if (infolevel>=DEBUG) { - s=string; - if (type>cLAST_COMMAND || typeprev!=stackroot) { - sprintf(s,"t["); - s+=2; - sp=stackhead; - for(i=0;TRUE;i++) { - sp=sp->prev; - if (sp==stackroot) break; - if (i>=5) continue; - if (i>0) { - sprintf(s,","); - s++; - } - switch(sp->type) { - case stGOTO: - sprintf(s,"goto%n",&n); - break; - case stSTRINGARRAYREF: - case stNUMBERARRAYREF: - if (sp->pointer) - sprintf(s,"%s()%n",(char *)sp->pointer,&n); - else - sprintf(s,"ARRAY()%n",&n); - break; - case stSTRING: - sprintf(s,"'%s'%n",(char *)sp->pointer,&n); - break; - case stNUMBER: - sprintf(s,"%g%n",sp->value,&n); - break; - case stLABEL: - sprintf(s,"label%n",&n); - break; - case stRETADD: - sprintf(s,"retadd%n",&n); - break; - case stRETADDCALL: - sprintf(s,"retaddcall%n",&n); - break; - case stSWITCH_MARK: - sprintf(s,"switch_mark%n",&n); - break; - case stFREE: - sprintf(s,"free%n",&n); - break; - case stROOT: - sprintf(s,"root%n",&n); - break; - case stSWITCH_STRING: - sprintf(s,"switch_string%n",&n); - break; - case stSWITCH_NUMBER: - sprintf(s,"switch_number%n",&n); - break; - default: - sprintf(s,"unknown%n",&n); - break; - } - s+=n; - } - if (i>5) { - sprintf(s,";+%d%n",i-5,&n); - s+=n; - } - strcat(s,"]b"); - } - error(DEBUG,string); - } -} - - -struct command *add_command(int type,char *name) - /* get room for new command, and make a link from old one */ -{ - struct command *new; - - if (infolevel>=DEBUG) std_diag("creating",type,name); - cmdhead->type=type; /* store command */ - cmdhead->line=mylineno; - cmdhead->lib=currlib; - cmdhead->cnt=commandcount; - if (!name || !*name) - cmdhead->name=NULL; - else - cmdhead->name=my_strdup(name); - commandcount++; - cmdhead->pointer=NULL; /* no data yet */ - cmdhead->jump=NULL; - cmdhead->nextassoc=NULL; - cmdhead->switch_id=get_switch_id(); - if (!currlib->datapointer && cmdhead->type==cDATA) currlib->firstdata=currlib->datapointer=cmdhead; - - /* link into chain of commands referencing a symbol */ - if (name) { - if (lastref) lastref->nextref=cmdhead; - lastref=cmdhead; - } - - /* create new command */ - new=(struct command *)my_malloc(sizeof(struct command)); - /* and initialize */ - new->next=NULL; - new->prev=cmdhead; - new->pointer=NULL; - new->symbol=NULL; - new->nextref=NULL; - new->nextassoc=NULL; - new->name=NULL; - - cmdhead->next=new; - lastcmd=cmdhead; - cmdhead=cmdhead->next; - return lastcmd; -} - - -static void parse_arguments(int cargc,char *cargv[]) - /* parse arguments from the command line */ -{ - char **argv; - int argc,larg; -#ifdef UNIX - char *parg; - int i; -#endif - int ar; - FILE *inputfile=NULL; - char *option; - char *info; - int options_done=FALSE; - - if (cargc>1) larg=strlen(cargv[1]); - else larg=0; -#ifdef UNIX - if (cargc>0) { - /* get room for arguments */ - argv=(char **)my_malloc((larg+cargc+1)*sizeof(char *)); - /* copy zero argument */ - argv[0]=cargv[0]; - argc=0; - /* chop first argument into pieces */ - if (cargc>=2) { - parg=strtok(my_strdup(cargv[1])," \t"); - for(argc=1;parg;argc++) { - argv[argc]=parg; - parg=strtok(NULL," \t"); - } - } - /* copy other arguments */ - for(i=2;i=argc) { - error(ERROR,"no infolevel specified " YABFORHELP); - end_it(); - } - info=argv[ar]; - if (!strncmp(info,"debug",strlen(info))) infolevel=DEBUG; - else if (!strncmp(info,"note",strlen(info))) infolevel=NOTE; - else if (!strncmp(info,"warning",strlen(info))) infolevel=WARNING; - else if (!strncmp(info,"error",strlen(info))) infolevel=ERROR; - else if (!strncmp(info,"fatal",strlen(info))) infolevel=FATAL; - else if (!strncmp(info,"bison",strlen(info))) {yydebug=1;infolevel=DEBUG;} - else { - sprintf(string,"there's no infolevel '%s' " YABFORHELP,argv[ar]); - error(ERROR,string); - end_it(); - } - } - /*else if (equal("-fg",option,3) || equal("-foreground",option,4)) { - ar++; - if (ar>=argc) { - error(ERROR,"no foreground colour specified " YABFORHELP); - end_it(); - } - foreground=my_strdup(argv[ar]); - } - else if (equal("-bg",option,2) || equal("-background",option,2)) { - ar++; - if (ar>=argc) { - error(ERROR,"no background colour specified (-h for help)"); - end_it(); - } - background=my_strdup(argv[ar]); - } - else if (equal("-geometry",option,2)) { - ar++; - if (ar>=argc) { - error(ERROR,"no geometry string specified (-h for help)"); - end_it(); - } - geometry=my_strdup(argv[ar]); - }*/ - else if (equal("-bind",option,3)) { - ar++; - if (ar>=argc) { - error(ERROR,"name of bound program to be written is missing"); - end_it(); - } - to_bind=my_strdup(argv[ar]); - } - else if (equal("-execute",option,2)) { - ar++; - if (ar>=argc) { - error(ERROR,"no commands specified (-h for help)"); - end_it(); - } - explicit=my_strdup(argv[ar]); - } - else if (equal("-librarypath",option,4)) { - ar++; - if (ar>=argc) { - error(ERROR,"no library path specified (-h for help)"); - end_it(); - } - strcpy(library_path,argv[ar]); - }/* - else if (equal("-display",option,3)) { - ar++; - if (ar>=argc) { - error(ERROR,"no display name specified (-h for help)"); - end_it(); - } - displayname=my_strdup(argv[ar]); - } - else if (equal("-font",option,4)) { - ar++; - if (ar>=argc) { - error(ERROR,"no font specified (-h for help)"); - end_it(); - } - font=my_strdup(argv[ar]); - }*/ else if (!print_docu && - (!strcmp("-doc",option) || !strncmp("-doc_",option,5) || - !strcmp("-docu",option) || !strncmp("-docu_",option,6))) { - print_docu=TRUE; - if (!strncmp("-doc_",option,5)) { - ar--; - hold_docu=TRUE; - main_file_name=my_strdup(option+5); - } else if (!strncmp("-docu_",option,6)) { - ar--; - hold_docu=TRUE; - main_file_name=my_strdup(option+6); - } else { - if (ar>=argc-1) { - error(ERROR,"no filename specified (-h for help)"); - end_it(); - } - hold_docu=FALSE; - main_file_name=my_strdup(argv[ar+1]); - } - } else if (!print_docu && *option=='-') { - sprintf(string,"unknown or ambigous option '%s' " YABFORHELP,option); - error(ERROR,string); - end_it(); - } else if (!is_bound && !inputfile && !explicit) { /* not an option */ - if (!main_file_name) main_file_name=my_strdup(argv[ar]); - inputfile=fopen(main_file_name,"r"); - if (inputfile==NULL) { - sprintf(string,"could not open '%s': %s",main_file_name,my_strerror(errno)); - error(ERROR,string); - endreason=erERROR; - exitcode=1; - end_it(); - } else { - progname=strrchr(main_file_name,'\\'); - if (!progname) progname=strrchr(main_file_name,'/'); - if (progname) - progname++; - else - progname=main_file_name; - if (!progname) progname="yab"; - } - } else { /* option for yabasic program */ - yabargv[yabargc]=my_strdup(argv[ar]); - yabargc++; - } - } else { - yabargv[yabargc]=my_strdup(argv[ar]); - yabargc++; - } - } - - interactive=FALSE; - -#ifdef WINDOWS - if (is_bound || !progname) { - SetConsoleTitle(""); - } else { - SetConsoleTitle(progname); - } -#endif - - if (is_bound) { - inputfile=bound_program; - main_file_name=my_strdup(interpreter_path); - } else if (!inputfile && !explicit) { - interactive=TRUE; - inputfile=stdin; - main_file_name="standard input"; - } - if (explicit) main_file_name="command line"; - - yi_SetMainFileName(main_file_name, yab); - - /* open a flex buffer for the initial file */ - open_main(inputfile,explicit,main_file_name); - return; - -} - -void do_help(char *op) /* process help option */ -{ - char *ooop=op; - char *oop=op; - if (op[0]=='-' && op[1]=='-') op++; - oop=op; - op=strchr(++op,'-'); - if (!op) { - if (equal("-version",oop,2)) { - fprintf(stderr,"%s\n",BANNER_VERSION); - } else if (equal("-license",oop,2) || equal("-licence",oop,2)) { - fprintf(stderr,"\n%s\n",YABLICENSE); - } else { - fprintf(stderr,"%s",BANNER); - fprintf(stderr,"For more help try one of these options:\n"); - fprintf(stderr," -help-license : show license and conditions of copying\n"); - fprintf(stderr," -help-usage : invoking yabasic and commandline options\n\n"); -#ifdef UNIX -#ifndef BEOS - fprintf(stderr,"Type 'man yabasic' or see the file yabasic.htm for a description\n"); -#else - fprintf(stderr,"Read the documentation for a description of the language.\n\n"); -#endif -#else - fprintf(stderr,"See the file yabasic.htm (accessible from the start-menu) for a\ndescription"); -#endif -// fprintf(stderr,"of the language, or go to www.yabasic.de for the latest\n"); -// fprintf(stderr,"information and other yabasic resources.\n\n"); - } - } else if (equal("-license",op,2) || equal("-licence",op,2)) { - fprintf(stderr,"\n%s\n",YABLICENSE); - } else if (equal("-usage",op,2)) { - fprintf(stderr,"\nUsage: yab [OPTIONS] [FILENAME [ARGUMENTS]]\n\n"); - fprintf(stderr,"FILENAME : file, which contains the yab program; omit it to type\n"); - fprintf(stderr," in your program on the fly (terminated by a double newline)\n"); - fprintf(stderr,"ARGUMENTS : strings, that are available from within the yab program\n\n"); - fprintf(stderr,"available OPTIONS:\n"); - fprintf(stderr," -help : print help message and other help options\n"); - fprintf(stderr," -version : show version of yab\n"); - fprintf(stderr," -infolevel [dnwefb] : set infolevel to debug,note,warning,error or fatal\n"); - fprintf(stderr," -execute COMMANDS : execute yab COMMANDS right away\n"); - fprintf(stderr," -bind BOUND : bind interpreter with FILENAME into BOUND\n"); -// fprintf(stderr," -geometry x+y : position graphic window at x,y\n"); -#ifdef UNIX -// fprintf(stderr," -fg,-bg COL : specify fore/background color of graphic window\n"); -// fprintf(stderr," -display DISP : display, where window will show up\n"); -// fprintf(stderr," -font FONT : font for graphic window\n"); -#else -// fprintf(stderr," -font FONT : font for graphic, supply style (decorative,dontcare,\n"); -// fprintf(stderr," modern,roman,script or swiss) and size, e.g. swiss10\n"); -#endif - fprintf(stderr," -docu NAME : print embedded docu of program or library\n"); - fprintf(stderr," -check : check for possible compatibility problems\n"); - fprintf(stderr," -- : pass any subsequent words as arguments to yab\n"); - fprintf(stderr," -librarypath PATH : directory to search libraries not found in\n"); - fprintf(stderr," current dir (default %s)\n",library_default); - fprintf(stderr," -enter : waits for the user to press the return key after\n"); - fprintf(stderr," the program finished\n"); - fprintf(stderr,"\n"); - } else { - sprintf(string,"unknown or ambigous option '%s' " YABFORHELP,ooop); - error(ERROR,string); - } -} - - -int equal(char *a,char *b,int min) /* helper for processing options */ -{ - int len; - if (b[0]=='-' && b[1]=='-' && b[2]) b++; - if (min<0) { - min=-min; - len=min; - } else { - len=strlen(b); - } - - return (!strncmp(a,b,len) && len>=min); -} - - -#ifdef WINDOWS -static void chop_command(char *command,int *argc,char ***argv) - /* chop the WIN95-commandline into seperate strings */ -{ - int i,j,count; - int quote; - char c,last; - char *curr; - char **list; - - /* count, how many arguments */ - count=i=0; - last=' '; - quote=FALSE; - while((c=*(command+i))!='\0') { - if (!quote && c!=' ' && last==' ') count++; - if (c=='\"') quote=!quote; - last=c; - i++; - } - - /* fill yabasic into argv[0] */ - *argv=my_malloc((count+1)*sizeof(char *)); - list=*argv; - *argc=count+1; - *list=my_strdup("yabasic"); - - /* fill in other strings */ - i=0; - count=1; - last=' '; - quote=FALSE; - do { - c=*(command+i); - if (!quote && c!=' ' && last==' ') j=i; - if (c=='\"') { - quote=!quote; - if (quote) j++; - } - if (((c==' ' && !quote) || c=='\0') && last!=' ') { - *(list+count)=my_malloc((i-j+1)*sizeof(char)); - strncpy(*(list+count),command+j,i-j); - curr=*(list+count)+i-j; - *curr='\0'; - if (*(curr-1)=='\"') *(curr-1)='\0'; - count++; - } - last=c; - i++; - } while(c!='\0'); -} -#endif - - -static void end_it(void) /* perform shutdown-operations */ -{ - char l[2]; -#ifdef UNIX - int status; -#ifndef BEOS - if (winpid==0 || termpid==0 || backpid==0) - yi_exit(1,yab); - if (backpid>0) { - kill(backpid,SIGTERM); - waitpid(backpid,&status,0); - backpid=-1; - } -#else - if(enterkeyflag) - { - printf("---Press RETURN to continue "); - getchar(); - // fgets(1,2,stdin); - } - if (winpid==0 || termpid==0) yi_exit(1,yab); -#endif - if ((curinized || winopened) && endreason!=erREQUEST) { -#else - if (!Commandline && endreason!=erREQUEST) { -#endif - myswitch(STDIO_STREAM); - onestring("---Program done, press RETURN---\n"); -#ifdef WINDOWS - SetConsoleMode(ConsoleInput,InitialConsole & (~ENABLE_ECHO_INPUT)); - FlushConsoleInputBuffer(ConsoleInput); -#endif - fgets(l,2,stdin); -#ifdef WINDOWS - if (wthandle!=INVALID_HANDLE_VALUE) TerminateThread(wthandle,0); -#endif -#ifdef UNIX - } -#else - } -#endif - -#ifdef UNIX -#ifdef BUILD_NCURSES - if (curinized) endwin(); -#endif -#else - if (printerfont) DeleteObject(printerfont); - if (myfont) DeleteObject(myfont); - if (printer) DeleteDC(printer); -#endif - yi_exit(exitcode,yab); -} - - -static void initialize(void) - /* give correct values to pointers etc ... */ -{ - struct symbol *s; - struct stackentry *base; - int i; - - /* install exception handler */ - /*signal(SIGFPE,signal_handler); - signal(SIGSEGV,signal_handler); - signal(SIGINT,signal_handler); -#ifdef SIGHUP - signal(SIGHUP,signal_handler); -#endif -#ifdef SIGQUIT - signal(SIGQUIT,signal_handler); -#endif -#ifdef SIGABRT - signal(SIGABRT,signal_handler); -#endif */ - - /* initialize error handling: no errors seen 'til now */ - errorlevel=DEBUG; - debug_count=0; - note_count=0; - warning_count=0; - error_count=0; - - /* initialize stack of symbol lists */ - pushsymlist(); - - /* initialize random number generator */ - srand((unsigned)time(NULL)); - - /* initialize numeric stack */ - /* create first : */ - stackroot=(struct stackentry *)my_malloc(sizeof(struct stackentry)); - stackroot->next=NULL; - stackroot->prev=NULL; - stackhead=stackroot; /* stack of double values */ - - /* initialize command stack */ - /* create first: */ - cmdroot=(struct command *)my_malloc(sizeof(struct command)); - cmdroot->next=cmdroot->prev=NULL; - - /* initialize random number generator */ - //srand((unsigned int)time(NULL)); - - /* specify default text-alignement and window origin */ - /* - text_align=my_strdup("lb"); - winorigin=my_strdup("lt");*/ - - /* initialize stack */ - base=push(); - base->type=stROOT; /* push nil, so that pop will not crash */ - cmdhead=cmdroot; /* list of commands */; - commandcount=0; - - /* add internal string variables */ - s=get_sym("yabos$",sySTRING,amADD_GLOBAL); - if (s->pointer) my_free(s->pointer); -#ifdef UNIX -#ifndef BEOS - s->pointer=my_strdup("unix"); -#elseifdef HAIKU - s->pointer=my_strdup("Haiku"); -#else - s->pointer=my_strdup("BeOS"); -#endif -#else - s->pointer=my_strdup("windows"); -#endif - - /* set default-scales for grafics */ - /* - fontheight=10; - winheight=100; - winwidth=100; -#ifdef UNIX - calc_psscale(); -#endif*/ - - - /* file stuff */ - for(i=1;i<=9;i++) { - streams[i]=NULL; - stream_modes[i]=smCLOSED; - } - streams[0]=stdin; - stream_modes[0]=smREAD | smWRITE | smREADWRITE; -#ifdef UNIX - /* printerfile=NULL; /* no ps-file yet */ -#endif - - /* array with explanation */ - for(i=cFIRST_COMMAND;i<=cLAST_COMMAND;i++) explanation[i]="???"; - explanation[cFIRST_COMMAND]="FIRST_COMMAND"; - explanation[cFINDNOP]="FINDNOP"; - explanation[cEXCEPTION]="EXCEPTION"; - explanation[cLABEL]="LABEL"; - explanation[cSUBLINK]="cSUBLINK"; - explanation[cTOKEN]="TOKEN"; - explanation[cTOKEN2]="TOKEN2"; - explanation[cTOKENALT]="TOKENALT"; - explanation[cTOKENALT2]="TOKENALT2"; - explanation[cSPLIT]="SPLIT"; - explanation[cSPLIT2]="SPLIT2"; - explanation[cSPLITALT]="SPLITALT"; - explanation[cSPLITALT2]="SPLITALT2"; - explanation[cGOTO]="GOTO"; - explanation[cQGOTO]="QGOTO"; - explanation[cGOSUB]="GOSUB"; - explanation[cQGOSUB]="QGOSUB"; - explanation[cCALL]="CALL"; - explanation[cQCALL]="QCALL"; - explanation[cRETURN]="RETURN"; - explanation[cRET_FROM_FUN]="RET_FROM_FUN"; - explanation[cRETVAL]="RETVAL"; - explanation[cSWAP]="SWAP"; - explanation[cDECIDE]="DECIDE"; - explanation[cANDSHORT]="ANDSHORT"; - explanation[cORSHORT]="ORSHORT"; - explanation[cSKIPPER]="SKIPPER"; - explanation[cSKIPONCE]="SKIPONCE"; - explanation[cRESETSKIPONCE]="RESETSKIPONCE"; - explanation[cNOP]="NOP"; - explanation[cEND_FUNCTION]="END_FUNCTION"; - explanation[cDIM]="DIM"; - explanation[cFUNCTION]="FUNCTION"; - explanation[cDOARRAY]="DOARRAY"; - explanation[cDBLADD]="DBLADD"; - explanation[cDBLMIN]="DBLMIN"; - explanation[cDBLMUL]="DBLMUL"; - explanation[cDBLDIV]="DBLDIV"; - explanation[cDBLPOW]="DBLPOW"; - explanation[cNEGATE]="NEGATE"; - explanation[cPUSHDBLSYM]="PUSHDBLSYM"; - explanation[cREQUIRE]="REQUIRE"; - explanation[cCLEARREFS]="CLEARREFS"; - explanation[cPUSHSYMLIST]="PUSHSYMLIST"; - explanation[cPOPSYMLIST]="POPSYMLIST"; - explanation[cMAKELOCAL]="MAKELOCAL"; - explanation[cNUMPARAM]="NUMPARAM"; - explanation[cMAKESTATIC]="MAKESTATIC"; - explanation[cARRAYLINK]="ARRAYLINK"; - explanation[cPUSHARRAYREF]="PUSHARRAYREF"; - explanation[cARDIM]="ARRAYDIMENSION"; - explanation[cARSIZE]="ARRAYSIZE"; - explanation[cUSER_FUNCTION]="USER_FUNCTION"; - explanation[cFUNCTION_OR_ARRAY]="FUNCTION_OR_ARRAY"; - explanation[cSTRINGFUNCTION_OR_ARRAY]="STRINGFUNCTION_OR_ARRAY"; - explanation[cPUSHFREE]="PUSHFREE"; - explanation[cPOPDBLSYM]="POPDBLSYM"; - explanation[cPOP]="POP"; - explanation[cPUSHDBL]="PUSHDBL"; - explanation[cPOKE]="POKE"; - explanation[cPOKEFILE]="POKEFILE"; - explanation[cAND]="AND"; - explanation[cOR]="OR"; - explanation[cNOT]="NOT"; - explanation[cLT]="LT"; - explanation[cGT]="GT"; - explanation[cLE]="LE"; - explanation[cGE]="GE"; - explanation[cEQ]="EQ"; - explanation[cNE]="NE"; - explanation[cSTREQ]="STREQ"; - explanation[cSTRNE]="STRNE"; - explanation[cPUSHSTRSYM]="PUSHSTRSYM"; - explanation[cPOPSTRSYM]="POPSTRSYM"; - explanation[cPUSHSTR]="PUSHSTR"; - explanation[cCONCAT]="CONCAT"; - explanation[cPUSHSTRPTR]="PUSHSTRPTR"; - explanation[cCHANGESTRING]="CHANGESTRING"; - explanation[cGLOB]="GLOB"; - explanation[cPRINT]="PRINT"; - explanation[cREAD]="READ"; - explanation[cRESTORE]="RESTORE"; - explanation[cQRESTORE]="QRESTORE"; - explanation[cREADDATA]="READDATA"; - explanation[cONESTRING]="ONESTRING"; - explanation[cDATA]="DATA"; - explanation[cOPEN]="OPEN"; - explanation[cCHECKOPEN]="CHECKOPEN"; - explanation[cCHECKSEEK]="CHECKSEEK"; - explanation[cCOMPILE]="COMPILE"; - explanation[cEXECUTE]="EXECUTE"; - explanation[cEXECUTE2]="EXECUTE$"; - explanation[cCLOSE]="CLOSE"; - explanation[cSEEK]="SEEK"; - explanation[cSEEK2]="SEEK2"; - explanation[cPUSHSTREAM]="cPUSHSTREAM"; - explanation[cPOPSTREAM]="cPOPSTREAM"; - explanation[cWAIT]="WAIT"; - explanation[cBELL]="BELL"; - explanation[cMOVE]="MOVE"; - explanation[cCLEARSCR]="CLEARSCR"; - explanation[cOPENWIN]="OPENWIN"; - explanation[cDOT]="DOT"; - explanation[cPUTCHAR]="PUTCHAR"; - explanation[cLINE]="LINE"; - explanation[cCIRCLE]="CIRCLE"; - explanation[cTEXT]="TEXT"; - explanation[cCLOSEWIN]="CLOSEWIN"; - explanation[cTESTEOF]="TESTEOF"; - explanation[cCOLOUR]="COLOUR"; - explanation[cDUPLICATE]="DUPLICATE"; - explanation[cDOCU]="DOCU"; - explanation[cEND]="END"; - explanation[cEXIT]="EXIT"; - explanation[cBIND]="BIND"; - explanation[cERROR]="ERROR"; - explanation[cSTARTFOR]="STARTFOR"; - explanation[cFORCHECK]="FORCHECK"; - explanation[cFORINCREMENT]="FORINCREMENT"; - explanation[cBREAK_MARK]="BREAK_MARK"; - explanation[cPUSH_SWITCH_MARK]="PUSH_SWITCH_MARK"; - explanation[cCLEAN_SWITCH_MARK]="CLEAN_SWITCH_MARK"; - explanation[cSWITCH_COMPARE]="SWITCH_COMPARE"; - explanation[cNEXT_CASE]="NEXT_CASE"; - explanation[cBREAK]="BREAK"; - explanation[cMINOR_BREAK]="MINOR_BREAK"; - explanation[cCONTINUE]="CONTINUE"; - explanation[cBREAK_HERE]="BREAK_HERE"; - explanation[cCONTINUE_HERE]="CONTINUE_HERE"; - explanation[cBREAK_MARK]="BREAK_MARK"; - explanation[cCONTINUE_CORRECTION]="CONTINUE_CORRECTION"; - explanation[cLAST_COMMAND]="???"; - - ykey[kERR]="error"; - ykey[kUP]="up"; - ykey[kDOWN]="down"; - ykey[kLEFT]="left"; - ykey[kRIGHT]="right"; - ykey[kDEL]="del"; - ykey[kINS]="ins"; - ykey[kCLEAR]="clear"; - ykey[kHOME]="home"; - ykey[kEND]="end"; - ykey[kF0]="f0"; - ykey[kF1]="f1"; - ykey[kF2]="f2"; - ykey[kF3]="f3"; - ykey[kF4]="f4"; - ykey[kF5]="f5"; - ykey[kF6]="f6"; - ykey[kF7]="f7"; - ykey[kF8]="f8"; - ykey[kF9]="f9"; - ykey[kF10]="f10"; - ykey[kF11]="f11"; - ykey[kF12]="f12"; - ykey[kF13]="f13"; - ykey[kF14]="f14"; - ykey[kF15]="f15"; - ykey[kF16]="f16"; - ykey[kF17]="f17"; - ykey[kF18]="f18"; - ykey[kF19]="f19"; - ykey[kF20]="f20"; - ykey[kF21]="f21"; - ykey[kF22]="f22"; - ykey[kF23]="f23"; - ykey[kF24]="f24"; - ykey[kBACKSPACE]="backspace"; - ykey[kSCRNDOWN]="scrndown"; - ykey[kSCRNUP]="scrnup"; - ykey[kENTER]="enter"; - ykey[kESC]="esc"; - ykey[kTAB]="tab"; - ykey[kLASTKEY]=""; -} - -void signal_handler(int sig) /* handle signals */ -{ - signal(sig,SIG_DFL); - if (program_state==FINISHED) { - yi_exit(1,yab); - } - signal_arrived=sig; - -#ifdef WINDOWS - if (signal_arrived) { - SuspendThread(mainthread); - if (wthandle!=INVALID_HANDLE_VALUE) SuspendThread(wthandle); - if (kthandle!=INVALID_HANDLE_VALUE) TerminateThread(kthandle,0); - } -#endif - - switch(sig) { - case SIGFPE: - error(FATAL,"floating point exception, cannot proceed."); - case SIGSEGV: - error(FATAL,"segmentation fault, cannot proceed."); - case SIGINT: -#ifdef UNIX -#ifndef BEOS - if (winpid==0 || termpid==0 || backpid==0) yi_exit(1,yab); -#endif -#endif - error(FATAL,"keyboard interrupt, cannot proceed."); -#ifdef SIGHUP - case SIGHUP: - error(FATAL,"received signal HANGUP, cannot proceed."); -#endif -#ifdef SIGQUIT - case SIGQUIT: - error(FATAL,"received signal QUIT, cannot proceed."); -#endif -#ifdef SIGABRT - case SIGABRT: - error(FATAL,"received signal ABORT, cannot proceed."); -#endif - default: - break; - } -} - - -static void run_it(YabInterface* yab) - /* execute the compiled code */ -{ - int l=0; - - current=cmdroot; /* start with first comand */ - if (print_docu) { /* don't execute program, just print docu */ - while(current!=cmdhead) { - if (current->type==cDOCU) { - if (infolevel>=DEBUG) std_diag("executing",current->type,current->name); - printf("%s\n",(char *)current->pointer); - l++; - if (hold_docu && !(l%24)) { - printf("---Press RETURN to continue "); - fgets(string,20,stdin); - } - } else { - if (infolevel>=DEBUG) std_diag("skipping",current->type,current->name); - } - current=current->next; - } - if (!l) printf("---No embbeded documentation\n"); - if (hold_docu) { - printf("---End of embbedded documentation, press RETURN "); - fgets(string,20,stdin); - } - } else { - while(current!=cmdhead && endreason==erNONE) { - if (infolevel>=DEBUG) std_diag("executing",current->type,current->name); - switch(current->type) { - case cGOTO:case cQGOTO:case cGOSUB:case cQGOSUB:case cCALL:case cQCALL: - jump(current); DONE; - case cEXCEPTION: - exception(current); DONE; - case cSKIPPER: - skipper(); break; - case cSKIPONCE: - skiponce(current); DONE; - case cRESETSKIPONCE: - resetskiponce(current); DONE; - case cNEXT_CASE: - next_case(); DONE; - case cBREAK:case cMINOR_BREAK: - mybreak(current); DONE; - case cSWITCH_COMPARE: - switch_compare(); DONE; - case cPUSH_SWITCH_MARK: - push_switch_mark(); DONE; - case cCLEAN_SWITCH_MARK: - clean_switch_mark(current); DONE; - case cCONTINUE: - mycontinue(current); DONE; - case cFINDNOP: - findnop(); DONE; - case cFUNCTION_OR_ARRAY: case cSTRINGFUNCTION_OR_ARRAY: - function_or_array(current); - break; /* NOT 'DONE' ! */ - case cLABEL:case cDATA:case cNOP:case cUSER_FUNCTION: - case cSUBLINK:case cEND_FUNCTION: case cDOCU: case cBREAK_HERE: - case cCONTINUE_HERE:case cBREAK_MARK:case cCONTINUE_CORRECTION: - DONE; - case cERROR: - do_error(current); DONE; - case cCOMPILE: - compile(); DONE; - case cEXECUTE: case cEXECUTE2: - execute(current); DONE; - case cRETURN:case cRET_FROM_FUN: - myreturn(current); DONE; - case cRETVAL: - retval(current); DONE; - case cPUSHDBLSYM: - pushdblsym(current); DONE; - case cPUSHDBL: - pushdbl(current); DONE; - case cPOPDBLSYM: - popdblsym(current); DONE; - case cPOP: - pop(stANY); DONE; - case cPOPSTRSYM: - popstrsym(current); DONE; - case cPUSHSTRSYM: - pushstrsym(current); DONE; - case cPUSHSTR: - pushstr(current); DONE; - case cCLEARREFS: - clearrefs(current); DONE; - case cPUSHSYMLIST: - pushsymlist(); DONE; - case cPOPSYMLIST: - popsymlist(); DONE; - case cREQUIRE: - require(current); DONE; - case cMAKELOCAL: - makelocal(current); DONE; - case cNUMPARAM: - numparam(current); DONE; - case cMAKESTATIC: - makestatic(current); DONE; - case cARRAYLINK: - arraylink(current); DONE; - case cPUSHARRAYREF: - pusharrayref(current); DONE; - case cTOKEN: case cTOKEN2: case cSPLIT: case cSPLIT2: - token(current); DONE; - case cTOKENALT: case cTOKENALT2: case cSPLITALT: case cSPLITALT2: - tokenalt(current); DONE; - case cARDIM: case cARSIZE: - query_array(current); DONE; - case cPUSHFREE: - push()->type=stFREE; DONE; - case cCONCAT: - concat(); DONE; - case cPRINT: - print(current); DONE; - case cMOVE: - mymove(); DONE; - case cCOLOUR: - colour(current); DONE; - case cCLEARSCR: - clearscreen(); DONE; - case cONESTRING: - onestring(current->pointer); DONE; - case cTESTEOF: - testeof(current); DONE; - case cOPEN: - myopen(current); DONE; - case cCHECKOPEN:case cCHECKSEEK: - checkopen(); DONE; - case cCLOSE: - myclose(); DONE; - case cSEEK:case cSEEK2: - myseek(current); DONE; - case cPUSHSTREAM: - push_switch(current); DONE; - case cPOPSTREAM: - pop_switch(); DONE; - case cCHKPROMPT: - chkprompt(); DONE; - case cREAD: - myread(current); DONE; - case cRESTORE:case cQRESTORE: - restore(current); DONE; - case cREADDATA: - readdata(current); DONE; - case cDBLADD:case cDBLMIN:case cDBLMUL:case cDBLDIV:case cDBLPOW: - dblbin(current); DONE; - case cNEGATE: - negate(); DONE; - case cEQ:case cNE:case cGT:case cGE:case cLT:case cLE: - dblrelop(current); DONE; - case cSTREQ:case cSTRNE:case cSTRLT:case cSTRLE:case cSTRGT:case cSTRGE: - strrelop(current); DONE; - case cAND:case cOR:case cNOT: - boole(current); DONE; - case cFUNCTION: - function(current, yab); DONE; - case cGLOB: - glob(); DONE; - case cDOARRAY: - doarray(current); DONE; - case cCHANGESTRING: - changestring(current); DONE; - case cPUSHSTRPTR: - pushstrptr(current); DONE; - case cDIM: - dim(current); DONE; - case cDECIDE: - decide(); DONE; - case cANDSHORT:case cORSHORT: - logical_shortcut(current); DONE; - case cOPENWIN: - openwin(current, yab); DONE; - case cBUTTON: - createbutton(current, yab); DONE; - case cALERT: - createalert(current, yab); DONE; - case cWINSET1: - winset1(current, yab); DONE; - case cWINSET2: - winset2(current, yab); DONE; - case cWINSET3: - winset3(current, yab); DONE; - case cWINSET4: - winset4(current, yab); DONE; - case cWINCLEAR: - winclear(current, yab); DONE; - case cLAYOUT: - setlayout(current,yab); DONE; - case cTEXTEDIT: - textedit(current,yab); DONE; - case cTEXTADD: - textadd(current,yab); DONE; - case cTEXTSET: - textset(current,yab); DONE; - case cTEXTSET2: - textset2(current,yab); DONE; - case cTEXTSET3: - textset3(current,yab); DONE; - case cTEXTCOLOR1: - textcolor1(current,yab); DONE; - case cTEXTCOLOR2: - textcolor2(current,yab); DONE; - case cTEXTCLEAR: - textclear(current,yab); DONE; - case cDRAWSET1: - drawset1(current,yab); DONE; - case cDRAWSET2: - drawset2(current,yab); DONE; - case cDRAWSET3: - drawset3(current,yab); DONE; - case cTEXT: - createtext(current, yab); DONE; - case cTEXT2: - text2(current, yab); DONE; - case cTEXTALIGN: - textalign(current, yab); DONE; - case cTEXTURL1: - texturl1(current, yab); DONE; - case cTEXTURL2: - texturl2(current, yab); DONE; - case cLOCALIZE: - localize(); DONE; - case cLOCALIZESTOP: - localizestop(); DONE; - case cLOCALIZE2: - localize2(current, yab); DONE; - case cMENU: - createmenu(current, yab); DONE; - case cCHECKBOX: - createcheckbox(current, yab); DONE; - case cRADIOBUTTON: - createradiobutton(current, yab); DONE; - case cTEXTCONTROL: - createtextcontrol(current, yab); DONE; - case cLAUNCH: - launch(current, yab); DONE; - case cLISTBOX: - createlistbox(current, yab); DONE; - case cDROPBOX: - createdropbox(current, yab); DONE; - case cITEMADD: - createitem(current, yab); DONE; - case cITEMDEL: - removeitem(current, yab); DONE; - case cITEMCLEAR: - clearitems(current, yab); DONE; - case cDRAWRECT: - drawrect(current, yab); DONE; - case cDRAWTEXT: - drawtext(current, yab); DONE; - case cDRAWCLEAR: - drawclear(current, yab); DONE; - case cDOT: - drawdot(current,yab); DONE; - case cPUTCHAR: - putchars(); DONE; - case cLINE: - drawline(current,yab); DONE; - case cCIRCLE: - drawcircle(current,yab); DONE; - case cCURVE: - drawcurve(current,yab); DONE; - case cELLIPSE: - drawellipse(current,yab); DONE; -/* case cTEXT: - text(current); DONE;*/ - case cCLOSEWIN: - closewin(current,yab); DONE; - case cVIEW: - view(current, yab); DONE; - case cBOXVIEW: - boxview(current, yab); DONE; - case cBOXVIEWSET: - boxviewset(current, yab); DONE; - case cTAB: - tab(current, yab); DONE; - case cTABSET: - tabset(current, yab); DONE; - case cTABADD: - tabadd(current, yab); DONE; - case cTABDEL: - tabdel(current, yab); DONE; - case cSLIDER1: - slider1(current, yab); DONE; - case cSLIDER2: - slider2(current, yab); DONE; - case cSLIDER3: - slider3(current, yab); DONE; - case cSLIDER4: - slider4(current, yab); DONE; - case cSLIDER5: - slider5(current, yab); DONE; - case cSLIDER6: - slider6(current, yab); DONE; - case cOPTION1: - option1(current, yab); DONE; - case cOPTION2: - option2(current, yab); DONE; - case cOPTION3: - option3(current, yab); DONE; - case cOPTION4: - option4(current, yab); DONE; - case cOPTION5: - option5(current, yab); DONE; - case cDROPZONE: - dropzone(current, yab); DONE; - case cCOLORCONTROL1: - colorcontrol1(current, yab); DONE; - case cCOLORCONTROL2: - colorcontrol2(current, yab); DONE; - case cTEXTCONTROL2: - textcontrol2(current, yab); DONE; - case cTEXTCONTROL3: - textcontrol3(current, yab); DONE; - case cTEXTCONTROL4: - textcontrol4(current, yab); DONE; - case cTEXTCONTROL5: - textcontrol5(current, yab); DONE; - case cTREEBOX1: - treebox1(current, yab); DONE; - case cTREEBOX2: - treebox2(current, yab); DONE; - case cTREEBOX3: - treebox3(current, yab); DONE; - case cTREEBOX4: - treebox4(current, yab); DONE; - case cTREEBOX5: - treebox5(current, yab); DONE; - case cTREEBOX7: - treebox7(current, yab); DONE; - case cTREEBOX8: - treebox8(current, yab); DONE; - case cTREEBOX9: - treebox9(current, yab); DONE; - case cTREEBOX10: - treebox10(current, yab); DONE; - case cTREEBOX11: - treebox11(current, yab); DONE; - case cTREEBOX12: - treebox12(current, yab); DONE; - case cBUTTONIMAGE: - buttonimage(current, yab); DONE; - case cCHECKBOXIMAGE: - checkboximage(current, yab); DONE; - case cCHECKBOXSET: - checkboxset(current, yab); DONE; - case cRADIOSET: - radioset(current, yab); DONE; - case cTOOLTIP: - tooltip(current, yab); DONE; - case cTOOLTIPNEW: - tooltipnew(current, yab); DONE; - case cTOOLTIPCOLOR: - tooltipcolor(current, yab); DONE; - case cFILEBOX: - filebox(current, yab); DONE; - case cFILEBOXADD2: - fileboxadd2(current, yab); DONE; - case cFILEBOXCLEAR: - fileboxclear(current, yab); DONE; - case cCOLUMNBOXADD: - columnboxadd(current, yab); DONE; - case cCOLUMNBOXREMOVE: - columnboxremove(current, yab); DONE; - case cCOLUMNBOXSELECT: - columnboxselect(current, yab); DONE; - case cCOLUMNBOXCOLOR: - columnboxcolor(current, yab); DONE; - case cDROPBOXSELECT: - dropboxselect(current, yab); DONE; - case cDROPBOXREMOVE: - dropboxremove(current, yab); DONE; - case cDROPBOXCLEAR: - dropboxclear(current, yab); DONE; - case cPRINTERCONFIG: - printerconfig(current, yab); DONE; - case cMENU2: - menu2(current, yab); DONE; - case cMENU3: - menu3(current, yab); DONE; - case cSUBMENU1: - submenu1(current, yab); DONE; - case cSUBMENU2: - submenu2(current, yab); DONE; - case cSUBMENU3: - submenu3(current, yab); DONE; - case cCLIPBOARDCOPY: - clipboardcopy(current, yab); DONE; - case cLISTSORT: - listsort(current, yab); DONE; - case cTREESORT: - treesort(current, yab); DONE; - case cCALENDAR: - calendar1(current, yab); DONE; - case cCALENDARSET: - calendar3(current, yab); DONE; - case cSCROLLBAR: - scrollbar(current, yab); DONE; - case cSCROLLBARSET1: - scrollbarset1(current, yab); DONE; - case cSCROLLBARSET2: - scrollbarset2(current, yab); DONE; - case cSCROLLBARSET3: - scrollbarset3(current, yab); DONE; - case cLISTBOXADD1: - listboxadd1(current, yab); DONE; - case cLISTBOXADD2: - listboxadd2(current, yab); DONE; - case cLISTBOXSELECT: - listboxselect(current, yab); DONE; - case cLISTBOXDEL2: - listboxremove(current, yab); DONE; - case cSOUNDSTOP: - soundstop(current, yab); DONE; - case cSOUNDWAIT: - soundwait(current, yab); DONE; - case cMEDIASOUNDSTOP: - mediasoundstop(current, yab); DONE; - case cSHORTCUT: - shortcut(current, yab); DONE; - case cTREEBOX13: - treebox13(current, yab); DONE; - case cDRAWSET4: - drawset4(current, yab); DONE; - case cSPLITVIEW1: - splitview1(current, yab); DONE; - case cSPLITVIEW2: - splitview2(current, yab); DONE; - case cSPLITVIEW3: - splitview3(current, yab); DONE; - case cSTACKVIEW1: - stackview1(current, yab); DONE; - case cSTACKVIEW2: - stackview2(current, yab); DONE; - case cSPINCONTROL1: - spincontrol1(current, yab); DONE; - case cSPINCONTROL2: - spincontrol2(current, yab); DONE; - case cBITMAP: - bitmap(current, yab); DONE; - case cBITMAPDRAW: - bitmapdraw(current, yab); DONE; - case cBITMAPDRAW2: - bitmapdraw2(current, yab); DONE; - case cBITMAPGET: - bitmapget(current, yab); DONE; - case cBITMAPGET2: - bitmapget2(current, yab); DONE; - case cBITMAPGETICON: - bitmapgeticon(current, yab); DONE; - case cBITMAPDRAG: - bitmapdrag(current, yab); DONE; - case cSCREENSHOT: - screenshot(current, yab); DONE; - case cBITMAPREMOVE: - bitmapremove(current, yab); DONE; - case cSTATUSBAR: - statusbar(current, yab); DONE; - case cSTATUSBARSET: - statusbarset(current, yab); DONE; - case cSTATUSBARSET2: - statusbarset2(current, yab); DONE; - case cSTATUSBARSET3: - statusbarset3(current, yab); DONE; - case cCANVAS: - canvas(current, yab); DONE; - case cMOUSESET: - mouseset(current, yab); DONE; - case cATTRIBUTE1: - attribute1(current, yab); DONE; - case cATTRIBUTECLEAR: - attributeclear(current, yab); DONE; - case cWAIT: - mywait(); DONE; - case cRESTORE2: { - struct command *c; - char *s; - c = add_command(cRESTORE, FALSE); - s = pop(stSTRING)->pointer; - if(!strcmp(s, "")) - c->pointer=my_strdup(s); - else - c->pointer=my_strdup(dotify(s, TRUE)); - restore(c); - } DONE; - case cBELL: - mybell(); DONE; - case cPOKE: - poke(current); DONE; - case cPOKEFILE: - pokefile(current); DONE; - case cSWAP: - swap(); DONE; - case cDUPLICATE: - duplicate(); DONE; - case cFORCHECK: - forcheck(); DONE; - case cFORINCREMENT: - forincrement(); DONE; - case cSTARTFOR: - startfor(); DONE; - case cBIND: - mybind(pop(stSTRING)->pointer); DONE; - case cEND: - endreason=erEOF; break; - case cEXIT: - exitcode=(int)pop(stNUMBER)->value;endreason=erREQUEST; break; - default: - sprintf(string,"Command %s (%d, right before '%s') not implemented", - explanation[current->type],current->type,explanation[current->type+1]); - error(ERROR,string); - } - } - } - program_state=FINISHED; - switch(errorlevel) { - case NOTE:case DEBUG: - error(NOTE,"Program ended normally."); break; - case WARNING: - error(WARNING,"Program ended with a warning"); break; - case ERROR: - error(ERROR,"Program stopped due to an error"); break; - case FATAL: /* should not come here ... */ - error(FATAL,"Program terminated due to FATAL error"); - break; - } -} - - -void error(int severity, char *messageline) - /* reports an basic error to the user and possibly exits */ -{ - if (program_state==COMPILING) - error_with_line(severity,messageline,mylineno); - else if (program_state==RUNNING && current->line>0) - error_with_line(severity,messageline,current->line); - else - error_with_line(severity,messageline,-1); -} - - -void error_with_line(int severity, char *message,int line) - /* reports an basic error to the user and possibly exits */ -{ - char *callstack; - char *stext; - char *f=NULL; - int l; - static int lastline; - static int first=TRUE; - - if (severity<=infolevel) { -#ifdef UNIX -#ifdef BUILD_NCURSES - if (curinized) reset_shell_mode(); -#endif -#endif - - switch(severity) { - case(INFO): - stext="---Info"; - break; - case(DUMP): - stext="---Dump"; - break; - case(DEBUG): - stext="---Debug"; - debug_count++; - break; - case(NOTE): - stext="---Note"; - note_count++; - break; - case(WARNING): - stext="---Warning"; - warning_count++; - break; - case(ERROR): - stext="---Error"; - error_count++; - break; - case(FATAL): - stext="---Fatal"; - break; - } - fprintf(stderr,"%s",stext); - if (line>=0) { - if (program_state==COMPILING) { - f=currlib->l; - l=mylineno; - } else if (program_state==RUNNING && current->line>0) { - f=current->lib->l; - l=current->line; - } - if (f) { - if (first || lastline!=l) { - fprintf(stderr," in %s, line %d",f,l); - } - lastline=l; - first=FALSE; - } - } - fprintf(stderr,": %s\n",message); - if (program_state==RUNNING && severity<=ERROR && severity!=DUMP) dump_sub(1); - } - if (severitynext) { - if (!strcmp(curr->l,l)) { - if (is_bound) - return curr; - else - return NULL; - } - } - - new=my_malloc(sizeof(struct libfile_name)); - new->next=NULL; - new->lineno=1; - if (last) last->next=new; - last=new; - - new->l=my_strdup(l); - new->llen=strlen(new->l); - - if (s) { - new->s=my_strdup(s); - } else { - /* no short name supplied get piece from l */ - end=strlen(l); - for(start=end;start>0;start--) { - if (l[start-1]=='\\' || l[start-1]=='/') break; - if (l[start]=='.') end=start; - } - end--; - new->s=my_malloc(end-start+2); - strncpy(new->s,new->l+start,end-start+1); - new->s[end-start+1]='\0'; - } - new->slen=strlen(new->s); - new->datapointer=new->firstdata=NULL; - - return new; -} - - -char *dotify(char *name,int addfun) /* add library name, if not already present */ -{ - static char buff[200]; - if (!strchr(name,'.')) { - strcpy(buff,currlib->s); - strcat(buff,"."); - strcat(buff,name); - } else { - strcpy(buff,name); - } - if (addfun && !strchr(name,'@')) { - strcat(buff,"@"); - strcat(buff,current_function); - } - return buff; -} - - -char *strip(char *name) /* strip down to minimal name */ -{ - static char buff[300]; - char *at,*dot; - - if (infolevel>=DEBUG) return name; - dot=strchr(name,'.'); - if (dot) - strcpy(buff,dot+1); - else - strcpy(buff,name); - at=strchr(buff,'@'); - if (at) *at='\0'; - - return buff; -} - - -void do_error(struct command *cmd) /* issue user defined error */ -{ - struct stackentry *s; - struct command *r; - - s=stackhead; - while(s!=stackroot) { - if (s->type==stRETADDCALL) { - r=s->pointer; - cmd->line=r->line; - cmd->lib=r->lib; - break; - } - s=s->prev; - } - error(ERROR,pop(stSTRING)->pointer); -} - - -void compile() /* create s subroutine at runtime */ -{ - open_string(pop(stSTRING)->pointer); - yyparse(); - add_command(cEND,NULL); -} - - -void create_execute(int string) /* create command 'cEXECUTESUB' */ -{ - struct command *cmd; - - cmd=add_command(string?cEXECUTE2:cEXECUTE,NULL); - cmd->pointer=my_strdup(dotify("",FALSE)); -} - - -void execute(struct command *cmd) /* execute a subroutine */ -{ - struct stackentry *st,*ret; - char *fullname,*shortname; - struct command *newcurr; - - st=stackhead; - do {st=st->prev;} while(st->type!=stFREE); - st=st->next; - if (st->type!=stSTRING) { - error(ERROR,"need a string as a function name"); - return; - } - shortname=st->pointer; - if ((shortname[strlen(shortname)-1]=='$')!=(cmd->type==cEXECUTE2)) { - if (cmd->type==cEXECUTE2) - sprintf(string,"expecting the name of a string function (not '%s')",shortname); - else - sprintf(string,"expecting the name of a numeric function (not '%s')",shortname); - error(ERROR,string); - return; - } - fullname=my_malloc(strlen(cmd->pointer)+strlen(shortname)+2); - strcpy(fullname,cmd->pointer); - strcat(fullname,shortname); - free(st->pointer); - st->type=stFREE; - newcurr=search_label(fullname,smSUB); - if (!newcurr) { - sprintf(string,"subroutine '%s' not defined",fullname); - error(ERROR,string); - return; - } - ret=push(); - ret->pointer=current; - ret->type=stRETADDCALL; - reshufflestack(ret); - current=newcurr; - free(fullname); -} - - -void create_docu(char *doc) /* create command 'docu' */ -{ - struct command *cmd; - static struct command *previous=NULL; - - if (inlib) return; - cmd=add_command(cDOCU,NULL); - cmd->pointer=doc; - if (previous) - previous->nextassoc=cmd; - else - docuhead=cmd; - previous=cmd; - docucount++; -} - - -void create_docu_array(void) /* create array with documentation */ -{ - struct array *ar; - struct command *doc; - int i; - - /* create and prepare docu-array */ - ar=create_array('s',1); - ar->bounds[0]=docucount+1; - ar->pointer=my_malloc((docucount+1)*sizeof(char *)); - ((char **)ar->pointer)[0]=my_strdup(""); - doc=docuhead; - i=1; - while(doc) { - ((char **)ar->pointer)[i]=doc->pointer; - doc=doc->nextassoc; - i++; - } - get_sym("main.docu$",syARRAY,amADD_GLOBAL)->pointer=ar; -} - - -int isbound(void) /* check if this interpreter is bound to a program */ -{ -/* - if (!interpreter_path || !interpreter_path[0]) { - error(FATAL,"interpreter_path is not set !"); - return 0; - } - if (!(interpreter=fopen(interpreter_path,"r"))) { - sprintf(string,"Couldn't open '%s' to check, if it is bound: %s",interpreter_path,my_strerror(errno)); - error(WARNING,string); - return 0; - } - - if(sizeof(myProg)>1) - return 1; - else - return 0; - */ - FILE *interpreter; - int i; - int c; - int proglen=0; - int bound=1; - - if (!interpreter_path || !interpreter_path[0]) { - error(FATAL,"interpreter_path is not set !"); - return 0; - } - if (!(interpreter=fopen(interpreter_path,"r"))) { - sprintf(string,"Couldn't open '%s' to check, if it is bound: %s",interpreter_path,my_strerror(errno)); - error(WARNING,string); - return 0; - } - - if (fseek(interpreter,0-strlen(YABMAGIC)-1,SEEK_END)) { - sprintf(string,"Couldn't seek within '%s': %s",interpreter_path,my_strerror(errno)); - error(WARNING,string); - return 0; - } - for(i=0;i=NOTE) { - error(NOTE,"Dumping the embedded program, that will be executed:"); - fprintf(stderr," "); - for(i=0;i=DEBUG) { - sprintf(string,"binding %s and %s into %s",interpreter_path,main_file_name,bound); - error(NOTE,string); - } - - while((c=fgetc(fyab))!=EOF) { - fputc(c,fbound); - } - for (i=1;il,"rb"))) { - sprintf(string,"could not open '%s' for reading: %s",libfile_chain[i]->l,my_strerror(errno)); - error(ERROR,string); - fclose(flib); - return 0; - } - sprintf(string,"\nimport %s\n",libfile_chain[i]->s); - for (pc=string;*pc;pc++) { - fputc(*pc,fbound); - proglen++; - } - while((c=fgetc(flib))!=EOF) { - fputc(c,fbound); - proglen++; - } - } - - for (pc="\nimport main\n";*pc;pc++) { - fputc(*pc,fbound); - proglen++; - } - for (pc="\nimport __END_OF_IMPORT\n";*pc;pc++) { - fputc(*pc,fbound); - proglen++; - } - while((c=fgetc(fprog))!=EOF) { - fputc(c,fbound); - proglen++; - } - fprintf(fbound,"\nend\n"); - fprintf(fbound,"rem %08d\n",proglen); - fprintf(fbound,"rem %s\n",YABMAGIC); - fclose(fyab); - fclose(fprog); - fclose(fbound); - - return 1; -} - -char *find_interpreter(char *name) /* find interpreter with full path */ -{ - FILE *f; - char *path=NULL; - -#ifdef WINDOWS - path=my_malloc(1000); - GetModuleFileName(NULL,path,1000); - if (f=fopen(path,"r")) { - fclose(f); - return path; - } else { - my_free(path); - return my_strdup(name); - } - -#else - if (f=fopen(name,"r")) { - fclose(f); - path=my_strdup(name); - return path; - } else { - char *from,*to,*try; - from=to=path=getenv("PATH"); - try=my_malloc(strlen(path)+strlen(name)+2); - to=strchr(to+1,':'); - while(to) { - strncpy(try,from,to-from); - try[to-from]=0; - if (try[to-from-1]!='/') strcat(try,"/"); - strcat(try,name); - if (f=fopen(try,"r")) { - fclose(f); - return try; - } - from=to+1; - to=strchr(to+1,':'); - } - return name; - } -#endif -} - - -char *my_strerror(int err) { /* return description of error */ -#ifdef WINDOWS - return strerror(err); -#else -#ifdef HAVE_STRERROR - return strerror(err); -#else - char buff[100]; - sprintf(buff,"errno=%d",err); - return buff; -#endif -#endif -} diff --git a/src/resattr.cpp b/src/resattr.cpp deleted file mode 100644 index ec02f48..0000000 --- a/src/resattr.cpp +++ /dev/null @@ -1,313 +0,0 @@ -// resattr.cpp - -#include -#include -#include - -#include -#include -#include -#include - -// usage -static const char *kUsage = -"Usage: %s [ ] -o [ ... ]\n" -"\n" -"Reads resources from zero or more input files and adds them as attributes\n" -"to the specified output file, or (in reverse mode) reads attributes from\n" -"zero or more input files and adds them as resources to the specified output\n" -"file. If not existent the output file is created as an empty file.\n" -"\n" -"Options:\n" -" -h, --help - Print this text.\n" -" -o - Specifies the output file.\n" -" -O, --overwrite - Overwrite existing attributes. regardless of whether\n" -" an attribute does already exist, it is always written\n" -" when a respective resource is encountered in an input\n" -" file. The last input file specifying the attribute\n" -" wins. If the options is not given, already existing\n" -" attributes remain untouched. Otherwise the first input\n" -" file specifying an attribute wins.\n" -" -r, --reverse - Reverse mode: Reads attributes from input files and\n" -" writes resources. A unique resource ID is assigned to\n" -" each attribute, so there will be no conflicts if two\n" -" input files feature the same attribute.\n" -; - -// command line args -static int sArgc; -static const char *const *sArgv; - -// print_usage -void -print_usage(bool error) -{ - // get nice program name - const char *programName = (sArgc > 0 ? sArgv[0] : "resattr"); - if (const char *lastSlash = strrchr(programName, '/')) - programName = lastSlash + 1; - - // print usage - fprintf((error ? stderr : stdout), kUsage, programName); -} - -// print_usage_and_exit -static -void -print_usage_and_exit(bool error) -{ - print_usage(error); - exit(error ? 1 : 0); -} - -// next_arg -static -const char* -next_arg(int argc, const char* const* argv, int& argi, bool dontFail = false) -{ - if (argi + 1 >= argc) { - if (dontFail) - return NULL; - print_usage_and_exit(true); - } - - return argv[++argi]; -} - -// write_attributes -static -void -write_attributes(BNode &out, const char *inFileName, BResources &resources, - bool overwrite) -{ - // iterate through the resources - type_code type; - int32 id; - const char *name; - size_t size; - for (int resIndex = 0; - resources.GetResourceInfo(resIndex, &type, &id, &name, &size); - resIndex++) { - // if we shall not overwrite attributes, we skip the attribute, if it - // already exists - attr_info attrInfo; - if (!overwrite && out.GetAttrInfo(name, &attrInfo) == B_OK) - continue; - - // get the resource - const void *data = resources.LoadResource(type, id, &size); - if (!data && size > 0) { - // should not happen - fprintf(stderr, "Failed to get resource `%s', type: %" B_PRIx32 - ", id: %" B_PRId32 " from input file `%s'\n", name, type, id, - inFileName); - exit(1); - } - - // construct a name, if the resource doesn't have one - char nameBuffer[32]; - if (!name) { - sprintf(nameBuffer, "unnamed_%d\n", resIndex); - name = nameBuffer; - } - - // write the attribute - ssize_t bytesWritten = out.WriteAttr(name, type, 0LL, data, size); - if (bytesWritten < 0) { - fprintf(stderr, "Failed to write attribute `%s' to output file: " - "%s\n", name, strerror(bytesWritten)); - } - } -} - -// write_resources -static -void -write_resources(BResources &resources, const char *inFileName, BNode &in, - int32 &resID) -{ - // iterate through the attributes - char name[B_ATTR_NAME_LENGTH]; - while (in.GetNextAttrName(name) == B_OK) { - // get attribute info - attr_info attrInfo; - status_t error = in.GetAttrInfo(name, &attrInfo); - if (error != B_OK) { - fprintf(stderr, "Failed to get info for attribute `%s' of input " - "file `%s': %s\n", name, inFileName, strerror(error)); - exit(1); - } - - // read attribute - char *data = new char[attrInfo.size]; - ssize_t bytesRead = in.ReadAttr(name, attrInfo.type, 0LL, data, - attrInfo.size); - if (bytesRead < 0) { - fprintf(stderr, "Failed to read attribute `%s' of input " - "file `%s': %s\n", name, inFileName, strerror(bytesRead)); - delete[] data; - exit(1); - } - - // find unique ID - const char *existingName; - size_t existingSize; - while (resources.GetResourceInfo(attrInfo.type, resID, &existingName, - &existingSize)) { - resID++; - } - - // write resource - error = resources.AddResource(attrInfo.type, resID++, data, - attrInfo.size, name); - if (error != B_OK) { - fprintf(stderr, "Failed to write resource `%s' to output " - "file: %s\n", name, strerror(error)); - } - delete[] data; - } -} - -// resources_to_attributes -static -void -resources_to_attributes(const char *outputFile, const char **inputFiles, - int inputFileCount, bool overwrite) -{ - // create output file, if it doesn't exist - if (!BEntry(outputFile).Exists()) { - BFile createdOut; - status_t error = createdOut.SetTo(outputFile, - B_READ_WRITE | B_CREATE_FILE); - if (error != B_OK) { - fprintf(stderr, "Failed to create output file `%s': %s\n", - outputFile, strerror(error)); - exit(1); - } - } - - // open output file - BNode out; - status_t error = out.SetTo(outputFile); - if (error != B_OK) { - fprintf(stderr, "Failed to open output file `%s': %s\n", outputFile, - strerror(error)); - exit(1); - } - - // iterate through the input files - for (int i = 0; i < inputFileCount; i++) { - // open input file - BFile in; - error = in.SetTo(inputFiles[i], B_READ_ONLY); - if (error != B_OK) { - fprintf(stderr, "Failed to open input file `%s': %s\n", - inputFiles[i], strerror(error)); - exit(1); - } - - // open resources - BResources resources; - error = resources.SetTo(&in, false); - if (error != B_OK) { - fprintf(stderr, "Failed to read resources of input file `%s': %s\n", - inputFiles[i], strerror(error)); - exit(1); - } - - // add the attributes - write_attributes(out, inputFiles[i], resources, overwrite); - } -} - -// resources_to_attributes -static -void -attributes_to_resources(const char *outputFile, const char **inputFiles, - int inputFileCount) -{ - // open output file - BFile out; - status_t error = out.SetTo(outputFile, B_READ_WRITE | B_CREATE_FILE); - if (error != B_OK) { - fprintf(stderr, "Failed to open output file `%s': %s\n", outputFile, - strerror(error)); - exit(1); - } - - // init output resources - BResources resources; - error = resources.SetTo(&out, false); - if (error != B_OK) { - fprintf(stderr, "Failed to init resources of output file `%s': %s\n", - outputFile, strerror(error)); - exit(1); - } - - int32 resID = 0; - - // iterate through the input files - for (int i = 0; i < inputFileCount; i++) { - // open input file - BNode in; - error = in.SetTo(inputFiles[i]); - if (error != B_OK) { - fprintf(stderr, "Failed to open input file `%s': %s\n", - inputFiles[i], strerror(error)); - exit(1); - } - - // add the resources - - write_resources(resources, inputFiles[i], in, resID); - } -} - -// main -int -main(int argc, const char *const *argv) -{ - sArgc = argc; - sArgv = argv; - - // parameters - const char *outputFile = NULL; - bool overwrite = false; - bool reverse = false; - const char **inputFiles = new const char*[argc]; - int inputFileCount = 0; - - // parse arguments - for (int argi = 1; argi < argc; argi++) { - const char *arg = argv[argi]; - if (arg[0] == '-') { - if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { - print_usage_and_exit(false); - } else if (strcmp(arg, "-o") == 0) { - outputFile = next_arg(argc, argv, argi); - } else if (strcmp(arg, "-O") == 0) { - overwrite = true; - } else if (strcmp(arg, "-r") == 0 - || strcmp(arg, "--reverse") == 0) { - reverse = true; - } else { - print_usage_and_exit(true); - } - } else { - inputFiles[inputFileCount++] = arg; - } - } - - // check parameters - if (!outputFile) - print_usage_and_exit(true); - - if (reverse) { - attributes_to_resources(outputFile, inputFiles, inputFileCount); - } else { - resources_to_attributes(outputFile, inputFiles, inputFileCount, - overwrite); - } - - return 0; -} diff --git a/src/resattrMakefile b/src/resattrMakefile deleted file mode 100644 index 9c9320d..0000000 --- a/src/resattrMakefile +++ /dev/null @@ -1,27 +0,0 @@ -NAME= resattr -TYPE= APP -SRCS= resattr.cpp -RSRCS= -LIBS= /boot/develop/lib/x86/libroot.so /boot/develop/lib/x86/libbe.so -LIBPATHS= -SYSTEM_INCLUDE_PATHS= /boot/develop/headers/be /boot/develop/headers/cpp /boot/develop/headers/posix /boot/home/config/include -LOCAL_INCLUDE_PATHS= -OPTIMIZE=NONE -# specify any preprocessor symbols to be defined. The symbols will not -# have their values set automatically; you must supply the value (if any) -# to use. For example, setting DEFINES to "DEBUG=1" will cause the -# compiler option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" -# would pass "-DDEBUG" on the compiler's command line. -DEFINES= -# specify special warning levels -# if unspecified default warnings will be used -# NONE = supress all warnings -# ALL = enable all warnings -WARNINGS = -# Build with debugging symbols if set to TRUE -SYMBOLS= -COMPILER_FLAGS= -LINKER_FLAGS= - -## include the makefile-engine -include $(BUILDHOME)/etc/makefile-engine diff --git a/src/symbol.c b/src/symbol.c deleted file mode 100644 index e582a07..0000000 --- a/src/symbol.c +++ /dev/null @@ -1,1775 +0,0 @@ -/* - - YABASIC --- a simple Basic Interpreter - written by Marc-Oliver Ihm 1995-2004 - homepage: www.yabasic.de - - symbol.c --- code for control structures, symbol and stack management - - 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 - -*/ - -/* ------------- includes ---------------- */ - -#ifndef YABASIC_INCLUDED -#include "yabasic.h" /* all prototypes and structures */ -#endif - - -/* ------------- external references ---------------- */ - -extern int mylineno; /* current line number */ -extern int yyparse(); /* call bison parser */ - - -/* ------------- local defines ---------------- */ -struct switch_id { - int id; - int depth; - struct switch_id *next; - struct switch_id *prev; -}; - - -/* ------------- local functions ---------------- */ - -static struct symbol *create_symbol(int,char *); /* create a new symbol */ -static void link_label(struct command *); /* link label into list of labels */ -static int count_args(int); /* count number of arguments on stack */ -static void stackdesc(int,char *); /* give back string describing stackentry */ -static void freesym(struct symbol *); /* free contents of symbol */ -static int ind_to_off(int *,int *); /* convert array of indices to single offset */ -static void off_to_ind(int,int *,int *); /* convert a single offset to an array of indices */ - - -/* ------------- global variables ---------------- */ - -static struct symstack *symroot=NULL; /* first element in symbol list */ -static struct symstack *symhead=NULL; /* last element ind symbol list */ -struct stackentry *stackroot; /* lowest element in stack */ -struct stackentry *stackhead; /* topmost element in stack */ -static struct command *labelroot=NULL; /* first label among commands */ -static struct command *labelhead=NULL; /* last label seen so far */ -extern char *current_function; /* name of currently defined function */ -struct command *lastref; /* last command in UDS referencing a symbol */ -struct command *firstref; /* first command in UDS referencing a symbol */ -int labelcount=0; /* count self-generated labels */ -int in_switch=0; /* true, if in switch (at compile-time) */ -struct switch_id *switch_id_stackhead=NULL; /* topmost (and valid) element of switch_id stack */ -struct switch_id *switch_id_stackroot=NULL; /* bottommost element of switch_id stack */ - - -/* ------------- subroutines ---------------- */ - - -void pushsymlist(void) /* push a new list of symbols on symbol stack */ -{ - struct symstack *new; - - new=my_malloc(sizeof(struct symstack)); - if (symhead) - symhead->next_in_stack=new; - else - symroot=new; /* first time called */ - new->prev_in_stack=symhead; - new->next_in_stack=NULL; - new->next_in_list=NULL; - symhead=new; -} - - -void popsymlist(void) /* pop list of symbols and free symbol contents */ -{ - struct symstack *prevstack; - struct symbol *currsym,*nextsym; - int count=0; - - currsym=symhead->next_in_list; - while(currsym) { /* loop through symbol list */ - freesym(currsym); - count++; - nextsym=currsym->next_in_list; - my_free(currsym); - currsym=nextsym; - } - if (infolevel>=DEBUG) { - sprintf(string,"removed symbol list with %d symbols",count); - error(DEBUG,string); - } - prevstack=symhead->prev_in_stack; - my_free(symhead); - prevstack->next_in_stack=NULL; - symhead=prevstack; -} - - -static void freesym(struct symbol *s) /* free contents of symbol */ -{ - int i; - int total; - - struct array *ar; - if (s->link) { /* it's a link, don't remove memory */ - sprintf(string,"removing linked symbol '%s'",s->name); - error(DEBUG,string); - my_free(s->name); - return; - } - if (s->type==sySTRING) { - if (infolevel>=DEBUG) { - sprintf(string,"removing string symbol '%s'",s->name); - error(DEBUG,string); - } - my_free(s->pointer); - } else if (s->type==syARRAY) { - if (infolevel>=DEBUG) { - sprintf(string,"removing array symbol '%s()'",s->name); - error(DEBUG,string); - } - ar=s->pointer; - if (ar->dimension>0) { - /* count total amount of memory */ - total=1; - for(i=0;idimension;i++) total*=(ar->bounds)[i]; - if (ar->type=='s') { /* string array */ - for(i=0;ipointer+i)); - } - my_free(ar->pointer); - } - my_free(ar); - } else if (s->type==syNUMBER) { - if (infolevel>=DEBUG) { - sprintf(string,"removing numeric symbol '%s'",s->name); - error(DEBUG,string); - } - } - my_free(s->name); - return; -} - - -void clearrefs(struct command *cmd) /* clear references for commands within function */ -{ - struct command *curr; - int n=0; - - curr=cmd->nextref; - while(curr) { - n++; - curr->symbol=NULL; - curr=curr->nextref; - } - sprintf(string,"removed references from %d symbols",n); - error(DEBUG,string); -} - - -struct symbol *get_sym(char *name,int type,int add) -/* get the value of a symbol, or create it with given type */ -{ - struct symstack *currstack; - struct symbol **currsym; - struct symbol *prelink; - struct symbol *new; - int stackcount=0; - int symbolcount=0; - int linked=FALSE; - - if (!name) return NULL; - /* go through all lists */ - currstack=symhead; /* start with symhead */ - if (add==amSEARCH_PRE && symhead->prev_in_stack) currstack=symhead->prev_in_stack; - while(TRUE) { - stackcount++; - currsym=&(currstack->next_in_list); - while(*currsym) { - prelink=*currsym; - symbolcount++; - if ((*currsym)->type==type && !strcmp(name,(*currsym)->name)) { /* do the types and names match ? */ - if ((*currsym)->link) { - currsym=&((*currsym)->link); - linked=TRUE; - } - if (infolevel>=DEBUG) { - if (linked) - sprintf(string,"found symbol '%s%s', linked to %s after searching %d symbol(s) in %d stack(s)", - name,(type==syARRAY)?"()":"",(*currsym)->name,symbolcount,stackcount); - else - sprintf(string,"found symbol '%s%s' after searching %d symbol(s) in %d stack(s)", - name,(type==syARRAY)?"()":"",symbolcount,stackcount); - error(DEBUG,string); - } - return *currsym; /* give back address */ - } - currsym=&((*currsym)->next_in_list); /* try next entry */ - } - /* not found in first list */ - if (add==amSEARCH_VERY_LOCAL) return NULL; - if (add==amADD_LOCAL) { - new=create_symbol(type,name); - (*currsym)=new; - if (infolevel>=DEBUG) { - sprintf(string,"created local symbol %s%s",name,(type==syARRAY)?"()":""); - error(DEBUG,string); - } - return new; - } - if (currstack!=symroot) - currstack=symroot; - else - break; - } - if (add==amADD_GLOBAL) { - new=create_symbol(type,name); - (*currsym)=new; - if (infolevel>=DEBUG) { - sprintf(string,"created global symbol %s%s",name,(type==syARRAY)?"()":""); - error(DEBUG,string); - } - return new; - } - return NULL; -} - - -void link_symbols(struct symbol *from,struct symbol *to) { /* link one symbol to the other */ - from->link=to; - if (infolevel>=DEBUG) { - sprintf(string,"linking symbol '%s' to '%s'",from->name,to->name); - error(DEBUG,string); - } -} - - -void create_retval(int is,int should) /* create command 'cRETVAL' */ -{ - struct command *cmd; - - cmd=add_command(cRETVAL,NULL); - cmd->args=is; - cmd->tag=should; -} - - -void retval(struct command *cmd) /* check return value of function */ -{ - int is,should; - struct stackentry *s; - - is=cmd->args; - should=cmd->tag; - if (is==should) { - /* okay, function returns expected type */ - } else if (is==ftNONE) { /* no element on stack, create one */ - s=push(); - if (should==ftNUMBER) { - s->type=stNUMBER; - s->value=0.0; - } else { - s->type=stSTRING; - s->pointer=my_strdup(""); - } - } else { - sprintf(string,"subroutine returns %s but should return %s", - (is==ftSTRING)?"a string":"a number",(should==ftSTRING)?"a string":"a number"); - error(ERROR,string); - } - if (infolevel>=DEBUG) { - s=stackhead->prev; - if (s->type==stNUMBER) - sprintf(string,"subroutine returns number %g",s->value); - else if (s->type==stSTRING) - sprintf(string,"subroutine returns string '%s'",(char *)s->pointer); - else - sprintf(string,"subroutine returns something strange (%d)",s->type); - error(DEBUG,string); - } - swap(); -} - - -void create_endfunction(void) /* create command cEND_FUNCTION */ -{ - struct command *cmd; - - cmd=add_command(cEND_FUNCTION,NULL); - link_label(cmd); -} - - -void dump_sym(void) /* dump the stack of lists of symbols */ -{ - struct symstack *currstack; - struct symbol **currsym; - - /* go through all lists */ - error(DUMP,"head of symbol stack"); - currstack=symhead; - while(currstack) { /* search 'til last element of stack */ - currsym=&(currstack->next_in_list); - string[0]='\0'; - while(*currsym) { - switch((*currsym)->type) { - case sySTRING: strcat(string," STRING:"); break; - case syNUMBER: strcat(string," NUMBER:"); break; - case syFREE: strcat(string," FREE:"); break; - case syARRAY: strcat(string," ARRAY:"); break; - default:sprintf(string," UNKNOWN:"); break; - } - strcat(string,(*currsym)->name); - - currsym=&((*currsym)->next_in_list); /* try next entry */ - } - error(DUMP,string); - currstack=currstack->prev_in_stack; - } - error(DUMP,"root of symbol stack"); - return; -} - - -void dump_sub(int short_dump) /* dump the stack of subroutine calls */ -{ - struct stackentry *st=stackhead; - struct command *cmd; - int first=TRUE; - do { - if (st->type==stRETADDCALL) { - cmd=st->pointer; - if (cmd->type==cCALL || cmd->type==cQCALL) { - char *dot; - dot=strchr(cmd->pointer,'.'); - if (first && !short_dump) error(DUMP,"Executing in:"); - sprintf(string,"sub %s() called in %s,%d",dot ? (dot+1):cmd->pointer,cmd->lib->l,cmd->line); - error(DUMP,string); - first=FALSE; - } - } - st=st->prev; - } while(st && st!=stackroot); - if (first && !short_dump) { - if (!short_dump) error(DUMP,"Executing in:"); - } - if (!short_dump) error(DUMP,"main program"); - - return; -} - - -static struct symbol *create_symbol(int type,char *name) /* create a new symbol */ -{ - struct symbol *new; - - new=my_malloc(sizeof(struct symbol)); - new->type=type; - new->next_in_list=NULL; - new->name=my_strdup(name); - new->pointer=NULL; - new->args=NULL; - new->value=0.0; - new->link=NULL; - - return new; -} - - -void function_or_array(struct command *cmd) /* decide whether to perform function or array */ -{ - struct command *fu; - - fu=search_label(cmd->name,smSUB|smLINK); - if (fu) { - cmd->type=cCALL; - cmd->pointer=cmd->name; - cmd->name=NULL; - error(DEBUG,"converting FUNCTION_OR_ARRAY to FUNCTION"); - } else { - if (cmd->type==cFUNCTION_OR_ARRAY) - cmd->tag=CALLARRAY; - else - cmd->tag=CALLSTRINGARRAY; - cmd->type=cDOARRAY; - cmd->args=-1; - error(DEBUG,"converting FUNCTION_OR_ARRAY to ARRAY"); - } -} - - -void swap() /* swap topmost elements on stack */ -{ - struct stackentry *a,*b; - - if ((a=stackhead->prev)==NULL || (b=a->prev)==NULL) { - error(ERROR,"Nothing to swap on stack !"); - return; - } - a->prev=b->prev;b->next=a->next; /* just swap the pointers */ - a->next=b;b->prev=a; - stackhead->prev=b; - (a->prev)->next=a; -} - - -struct stackentry *push() -/* push element on stack and enlarge stack it */ -{ - struct stackentry *new; - - if (!stackhead->next) { /* no next element */ - /* create new element */ - new=(struct stackentry *)my_malloc(sizeof(struct stackentry)); - /* and initialize it */ - new->next=NULL; - new->value=0.0; - new->type=stFREE; - new->prev=stackhead; - new->pointer=NULL; - stackhead->next=new; - } else if (stackhead->pointer!=NULL && (stackhead->type==stSTRING || stackhead->type==stSTRINGARRAYREF || stackhead->type==stNUMBERARRAYREF || stackhead->type==stLABEL)) { - /* any content is set free */ - my_free(stackhead->pointer); - stackhead->pointer=NULL; - } - stackhead=stackhead->next; /* advance head */ - return stackhead->prev; -} - - -struct stackentry *pop(int etype) -/* pops element to memory and looks for pop-error */ -{ - static char expected[50]; - static char found[50]; - int ftype; - struct stackentry *s; - - /* test if there is something on the stack */ - if (stackhead==stackroot) { - error(FATAL,"Popped too much."); - return stackhead; - } - stackhead=stackhead->prev; /* move down in stack */ - ftype=stackhead->type; - if (etype==ftype || etype==stANY || - (etype==stSTRING_OR_NUMBER && (ftype==stNUMBER || ftype==stSTRING)) || - (etype==stSTRING_OR_NUMBER_ARRAYREF && (ftype==stSTRINGARRAYREF || ftype==stNUMBERARRAYREF))) - return stackhead; /* this is your value; use it quickly ! */ - - /* expected and found don't match */ - stackdesc(etype,expected); - stackdesc(ftype,found); - sprintf(string,"expected %s but found %s",expected,found); - if (etype==stNUMBER || etype==stSTRING || etype==stSTRING_OR_NUMBER) { - s=push(); - if (etype==stNUMBER) { - s->type=stNUMBER; - s->value=0.0; - } else { - s->type=stSTRING; - s->pointer=my_strdup(""); - } - error(ERROR,string); - return s; - } else { - error(FATAL,string); - } - return stackhead; -} - - -static void stackdesc(int type,char *desc) /* give back string describing stackentry */ -{ - switch(type) { - case stGOTO: strcpy(desc,"a goto");break; - case stSTRING: strcpy(desc,"a string");break; - case stSTRINGARRAYREF: strcpy(desc,"a reference to a string array");break; - case stNUMBER: strcpy(desc,"a number");break; - case stNUMBERARRAYREF: strcpy(desc,"a reference to a numeric array");break; - case stLABEL: strcpy(desc,"a label");break; - case stRETADD: strcpy(desc,"a return address for gosub");break; - case stRETADDCALL: strcpy(desc,"a return address for a subroutine");break; - case stFREE: strcpy(desc,"nothing");break; - case stROOT: strcpy(desc,"the root of the stack");break; - case stANY: strcpy(desc,"anything");break; - case stSTRING_OR_NUMBER: strcpy(desc,"a string or a number");break; - case stSTRING_OR_NUMBER_ARRAYREF: strcpy(desc,"reference to a string or an array");break; - case stSWITCH_STRING: strcpy(desc,"number for switch");break; - case stSWITCH_NUMBER: strcpy(desc,"string for switch");break; - default: sprintf(desc,"type %d",type);break; - } -} - - -void pushname(char *name) /* bison: push a name on stack */ -{ - struct stackentry *s; - - s=push(); - s->pointer=my_strdup(name); - s->type=stSTRING; -} - - -void pushlabel() /* bison: generate goto and push label on stack */ -{ - char *st; - struct stackentry *en; - - st=(char *) my_malloc(sizeof(char)*20); - sprintf(st,"***%d",labelcount); - labelcount++; - create_goto(st); - en=push(); - en->type=stLABEL; - en->pointer=st; -} - - -void poplabel() /* bison: pops a label and generates the matching command */ -{ - create_label(pop(stLABEL)->pointer,cLABEL); /* and create it */ -} - - -void pushgoto() /* bison: generate label and push goto on stack */ -{ - char *st; - struct stackentry *en; - - st=(char *) my_malloc(sizeof(char)*20); - sprintf(st,"***%d",labelcount); - labelcount++; - create_label(st,cLABEL); - en=push(); - en->type=stGOTO; - en->pointer=st; -} - - -void popgoto() /* bison: pops a goto and generates the matching command */ -{ - create_goto(pop(stGOTO)->pointer); /* and create it */ -} - - -void storelabel() /* bison: push label on stack */ -{ - char *st; - struct stackentry *en; - - st=(char *)my_malloc(sizeof(char)*20); - sprintf(st,"***%d",labelcount); - labelcount++; - en=push(); - en->type=stLABEL; - en->pointer=st; -} - - -void matchgoto() /* bison: generate goto matching label on stack */ -{ - create_goto(stackhead->prev->pointer); -} - - -void create_pushdbl(double value) /* create command 'cPUSHDBL' */ -{ - struct command *cmd; - - cmd=add_command(cPUSHDBL,NULL); - cmd->pointer=my_malloc(sizeof(double)); - *(double *)(cmd->pointer)=value; -} - - -void pushdbl(struct command *cmd) -{ - /* push double onto stack */ - struct stackentry *p; - - p=push(); - p->value= *(double *)cmd->pointer; - p->type=stNUMBER; -} - - -void pushdblsym(struct command *cmd) -{ - /* push double symbol onto stack */ - struct stackentry *p; - - p=push(); - if (!cmd->name) error(WARNING,"invalid pushdblsym"); - - if (!cmd->symbol) cmd->symbol=&(get_sym(cmd->name,syNUMBER,amADD_GLOBAL)->value); - p->value=*(double *)cmd->symbol; - p->type=stNUMBER; -} - - -void popdblsym(struct command *cmd) /* pop double from stack */ -{ - double d; - - d=pop(stNUMBER)->value; - if (!cmd->symbol) cmd->symbol=&(get_sym(cmd->name,syNUMBER,amADD_GLOBAL)->value); - *(double *)(cmd->symbol)=d; -} - - -void create_makelocal(char *name,int type) /* create command 'cMAKELOCAL' */ -{ - struct command *cmd; - - cmd=add_command(cMAKELOCAL,name); - cmd->args=type; -} - - -void makelocal(struct command *cmd) /* makes symbol local */ -{ - if (get_sym(cmd->name,cmd->args,amSEARCH_VERY_LOCAL)) { - sprintf(string,"local variable '%s' already defined within this subroutine",strip(cmd->name)); - error(ERROR,string); - return; - } - get_sym(cmd->name,cmd->args,amADD_LOCAL); -} - - -void create_numparam(void) /* create command 'cNUMPARAM' */ -{ - struct command *cmd; - - /* dotifying numparams at compiletime (as opposed to runtime) is essential, - because the function name is not known at runtime */ - cmd=add_command(cNUMPARAM,dotify("numparams",FALSE)); -} - - -void numparam(struct command *cmd) /* count number of function parameters */ -{ - struct symbol *sym; - - sym=get_sym(cmd->name,syNUMBER,amADD_LOCAL); - sym->value=abs(count_args(FALSE)); -} - - -void create_makestatic(char *name,int type) /* create command 'cMAKESTATIC' */ -{ - struct command *cmd; - - cmd=add_command(cMAKESTATIC,name); - cmd->args=type; -} - - -void makestatic(struct command *cmd) /* makes symbol static */ -{ - struct symbol *l,*g; - char *at=NULL; - - - /* mask function name */ - if ((at=strchr(cmd->name,'@'))!=NULL) *at='\0'; - - if (get_sym(cmd->name,cmd->args,amSEARCH_VERY_LOCAL)) { - sprintf(string,"static variable '%s' already defined within this subroutine",strip(cmd->name)); - error(ERROR,string); - return; - } - - /* create global variable with unique name */ - if (at) *at='@'; - g=get_sym(cmd->name,cmd->args,amADD_GLOBAL); - if (at) *at='\0'; - - /* create local variable */ - l=get_sym(cmd->name,cmd->args,amADD_LOCAL); - if (at) *at='@'; - /* link those two together */ - link_symbols(l,g); -} - - -void create_arraylink(char *name,int type) /* create command 'cARRAYLINK' */ -{ - struct command *cmd; - - cmd=add_command(cARRAYLINK,name); - cmd->pointer=current_function; - cmd->args=type; -} - - -void arraylink(struct command *cmd) /* link a local symbol to a global array */ -{ - struct symbol *l,*g; - struct array *ar; - - if (get_sym(cmd->name,cmd->args,amSEARCH_VERY_LOCAL)) { - sprintf(string,"'%s()' already defined within this subroutine",strip(cmd->name)); - error(ERROR,string); - return; - } - /* get globally defined array */ - g=get_sym(pop(cmd->args)->pointer,syARRAY,amSEARCH_PRE); - /* create local array */ - l=get_sym(cmd->name,syARRAY,amADD_LOCAL); - if (!l) return; - if (!g || !g->pointer) { /* no global array supplied, create one */ - error(DEBUG,"creating dummy array"); - ar=create_array((cmd->args==stNUMBERARRAYREF)?'d':'s',0); - l->pointer=ar; - if (infolevel>=DEBUG) { - sprintf(string,"creating 0-dimensional dummy array '%s()'",cmd->name); - error(DEBUG,string); - } - } else { - /* link those two together */ - link_symbols(l,g); - } -} - - -void create_pusharrayref(char *name,int type) /* create command 'cPUSHARRAYREF' */ -{ - struct command *cmd; - - cmd=add_command(cPUSHARRAYREF,name); - cmd->args=type; -} - - -void pusharrayref(struct command *cmd) /* push an array reference onto stack */ -{ - struct stackentry *s; - s=push(); - s->type=cmd->args; - s->pointer=my_strdup(cmd->name); -} - - -void create_require(int type) /* create command 'cREQUIRE' */ -{ - struct command *cmd; - - cmd=add_command(cREQUIRE,NULL); - cmd->args=type; -} - - -void require(struct command *cmd) /* check, that item on stack has right type */ -{ - char *expected,*supplied; - struct stackentry *s; - - if (stackhead->prev->type==cmd->args) return; /* okay, they match */ - - if (stackhead->prev->type==stFREE) { /* no argument supplied, create it */ - s=push(); - if (cmd->args==stSTRING) { - s->type=stSTRING; - s->pointer=my_strdup(""); - return; - } else if (cmd->args==stNUMBER) { - s->type=stNUMBER; - s->value=0.0; - return; - } else { - /* create array */ - s->type=cmd->args; - s->pointer=NULL; - return; - } - } - - s=stackhead->prev; - if (s->type==stSTRING) - supplied="string"; - else if (s->type==stNUMBER) - supplied="number"; - else if (s->type==stSTRINGARRAYREF) - supplied="string array"; - else if (s->type==stNUMBERARRAYREF) - supplied="numeric array"; - else if (s->type==stFREE) - supplied="nothing"; - else - supplied="something strange"; - - if (cmd->args==stSTRING) - expected="string"; - else if (cmd->args==stNUMBER) - expected="number"; - else if (cmd->args==stSTRINGARRAYREF) - expected="string array"; - else if (cmd->args==stNUMBERARRAYREF) - expected="numeric array"; - else if (cmd->args==stFREE) - expected="nothing"; - else - expected="something strange"; - - sprintf(string,"invalid subroutine call: %s expected, %s supplied",expected,supplied); - error(ERROR,string); -} - - -void create_dblbin(char c) /* create command for binary double operation */ -{ - switch(c) { - case '+':add_command(cDBLADD,NULL);break; - case '-':add_command(cDBLMIN,NULL);break; - case '*':add_command(cDBLMUL,NULL);break; - case '/':add_command(cDBLDIV,NULL);break; - case '^':add_command(cDBLPOW,NULL);break; - } - /* no specific information needed */ -} - - -void dblbin(struct command *cmd) /* compute with two numbers from stack */ -{ - struct stackentry *d; - double a,b,c; - - b=pop(stNUMBER)->value; - a=pop(stNUMBER)->value; - d=push(); - switch(cmd->type) { - case(cDBLADD):c=a+b; break; - case(cDBLMIN):c=a-b; break; - case(cDBLMUL):c=a*b; break; - case(cDBLDIV): - if (fabs(b)value=c; - d->type=stNUMBER; -} - - -void negate() /* negates top of stack */ -{ - stackhead->prev->value=-stackhead->prev->value; -} - - -void pushstrptr(struct command *cmd) /* push string-pointer onto stack */ -{ - struct stackentry *p; - - p=push(); - if (!cmd->symbol) cmd->symbol=&(get_sym(cmd->name,sySTRING,amADD_GLOBAL)->pointer); - p->pointer=*(char **)cmd->symbol; - if (!p->pointer) p->pointer=my_strdup(""); - p->type=stSTRING; -} - - -void pushstrsym(struct command *cmd) /* push string-symbol onto stack */ -{ - struct stackentry *p; - - p=push(); - if (!cmd->symbol) cmd->symbol=&(get_sym(cmd->name,sySTRING,amADD_GLOBAL)->pointer); - p->pointer=my_strdup(*(char **)cmd->symbol); - p->type=stSTRING; -} - - -void popstrsym(struct command *cmd) /* pop string from stack */ -{ - if (!cmd->name) return; - if (!cmd->symbol) cmd->symbol= &(get_sym(cmd->name,sySTRING,amADD_GLOBAL)->pointer); - if (*(char **)cmd->symbol!=NULL) my_free(*(char **)cmd->symbol); - *(char **)cmd->symbol=my_strdup(pop(stSTRING)->pointer); -} - - -void create_pushstr(char *s) /* creates command pushstr */ -{ - struct command *cmd; - - cmd=add_command(cPUSHSTR,NULL); - cmd->pointer=my_strdup(s); /* store string */ -} - - -void pushstr(struct command *cmd) -{ - /* push string onto stack */ - struct stackentry *p; - - p=push(); - p->pointer=my_strdup((char *)cmd->pointer); - p->type=stSTRING; -} - - -void duplicate(void) /* duplicate topmost element of stack */ -{ - struct stackentry *s; - double actual; - - actual=stackhead->prev->value; - s=push(); - s->type=stNUMBER; - s->value=actual; -} - - -void create_goto(char *label) /* creates command goto */ -{ - struct command *cmd; - - cmd=add_command(cGOTO,NULL); - /* specific info */ - cmd->pointer=my_strdup(label); -} - - -void create_gosub(char *label) /* creates command gosub */ -{ - struct command *cmd; - - cmd=add_command(cGOSUB,NULL); - /* specific info */ - cmd->pointer=my_strdup(label); -} - - -void create_call(char *label) /* creates command function call */ -{ - struct command *cmd; - - cmd=add_command(cCALL,NULL); - /* specific info */ - cmd->pointer=my_strdup(label); -} - - -static void link_label(struct command *cmd) /* link label into list of labels */ -{ - if (!labelroot) - labelroot=cmd; - else - labelhead->nextassoc=cmd; - labelhead=cmd; -} - - -struct command *search_label(char *name,int type) /* search label */ -{ - struct command *curr; - char *at=NULL; - - curr=labelroot; - if (type&smGLOBAL) { - at=strchr(name,'@'); - if (at) *at='\0'; - } - while(curr) { - if ((type&smSUB) && curr->type==cUSER_FUNCTION && !strcmp(curr->pointer,name)) { - if (at) *at='@'; - return curr; - } - if ((type&smLINK) && curr->type==cSUBLINK && !strcmp(curr->pointer,name)) { - if (at) *at='@'; - return curr->next; - } - if ((type&smLABEL) && curr->type==cLABEL && !strcmp(curr->pointer,name)) { - if (at) *at='@'; - return curr; - } - curr=curr->nextassoc; - } - return NULL; -} - - -void jump(struct command *cmd) -/* jump to specific Label; used as goto, gosub or function call */ -{ - struct command *label; - struct stackentry *ret; - int type; - char *dot; - - type=cmd->type; - if (type==cGOSUB || type==cQGOSUB || type==cCALL || type==cQCALL) { - /* leave return address for return */ - ret=push(); - ret->pointer=current; - if (type==cGOSUB || type==cQGOSUB) { - ret->type=stRETADD; - } else { - ret->type=stRETADDCALL; - reshufflestack(ret); - } - } - - if (type==cQGOSUB || type==cQGOTO || type==cQCALL) { - current=(struct command *)cmd->jump; /* use remembered address */ - return; - } - label=search_label(cmd->pointer,smSUB|smLINK|smLABEL); - if (!label && type==cCALL && (dot=strchr(cmd->pointer,'.'))) { - strcpy(string,"main"); - strcat(string,dot); - label=search_label(string,smLINK); - } - if (label) { - /* found right label */ - current=label; /* jump to new location */ - /* use the address instead of the name next time */ - cmd->jump=label; - switch(cmd->type) { - case cGOTO: cmd->type=cQGOTO; break; - case cGOSUB: cmd->type=cQGOSUB; break; - case cCALL: cmd->type=cQCALL; break; - } - } else { - /* label not found */ - sprintf(string,"can't find %s '%s'",(type==cCALL)?"subroutine":"label",strip((char *)cmd->pointer)); - if (strchr(cmd->pointer,'@')) strcat(string," (not in this sub)"); - error(ERROR,string); - } - - /* check, if goto enters or leaves a switch_statement */ - if (cmd->type==cQGOTO) { - if (label->switch_id && !cmd->switch_id) - error(ERROR,"cannot jump into switch-statement"); - else if (!label->switch_id && cmd->switch_id) - error(ERROR,"cannot jump out of switch-statement"); - else if (label->switch_id!=cmd->switch_id) - error(ERROR,"cannot jump between switch statements"); - } -} - - -void reshufflestack(struct stackentry *ret) /* reorganize stack for function call */ -{ - struct stackentry *a,*b,*c; - struct stackentry *top,*bot; - struct stackentry *ttop,*bbot; - int args; - - - /* this is a function call; revert stack and shuffle return address to bottom */ - /* push address below parameters */ - args=0; - top=a=ret->prev; - while(a->type!=stFREE) { - a=a->prev; - args++; - } - bot=a->next; - b=a->prev; - /* remove ret */ - ret->prev->next=ret->next; - ret->next->prev=ret->prev; - /* squeeze ret between a and b */ - ret->next=a; - a->prev=ret; - b->next=ret; - ret->prev=b; - /* revert stack between top and bot */ - if (args>1) { - a=bot; - b=a->next; - bbot=bot->prev; - ttop=top->next; - for(;args>1;args--) { - a->prev=b; - c=b->next; - b->next=a; - a=b; - b=c; - } - bot->next=ttop; - bot->next->prev=bot; - top->prev=bbot; - top->prev->next=top; - } -} - - -void myreturn(struct command *cmd) /* return from gosub of function call */ -{ - struct stackentry *address; - - address=pop(stANY); - if (cmd->type==cRET_FROM_FUN) { - if (address->type!=stRETADDCALL) { - error(ERROR,"RETURN from a subroutine without CALL"); - return; - } - } else { - if (address->type!=stRETADD) { - error(ERROR,"RETURN without GOSUB"); - return; - } - } - current=(struct command *)address->pointer; - return; -} - - -void create_label(char *label,int type) /* creates command label */ -{ - struct command *cmd; - - /* check, if label is duplicate */ - if (search_label(label,smSUB|smLINK|smLABEL)) { - sprintf(string,"duplicate %s '%s'",(type==cLABEL)?"label":"subroutine",strip(label)); - error(ERROR,string); - return; - } - - cmd=add_command(type,NULL); - /* store label */ - cmd->pointer=my_strdup(label); - link_label(cmd); -} - - -void create_sublink(char *label) /* create link to subroutine */ -{ - char global[200]; - char *dot; - struct command *cmd; - - if (!inlib) return; - dot=strchr(label,'.'); - strcpy(global,"main"); - strcat(global,dot); - - /* check, if label is duplicate */ - if (search_label(global,smSUB|smLINK|smLABEL)) { - sprintf(string,"duplicate subroutine '%s'",strip(global)); - error(ERROR,string); - return; - } - - cmd=add_command(cSUBLINK,NULL); - /* store label */ - cmd->pointer=my_strdup(global); - link_label(cmd); -} - - -void decide() /* skips next command, if not 0 on stack */ -{ - if (pop(stNUMBER)->value!=0) current=current->next; /* skip one command */ -} - - -void create_dim(char *name,char type) /* create command 'dim' */ -/* type can be 's'=string or 'd'=double Array */ -{ - struct command *cmd; - - cmd=add_command(cDIM,name); - cmd->tag=type; /* type: string or double */ - cmd->args=-1; -} - - -void dim(struct command *cmd) /* get room for array */ -{ - struct array *nar,*oar; - char *nul; - int ntotal,ototal,esize,i,j; - int ind[10],nbounds[10],larger; - struct symbol *s; - int local; - - local=((cmd->tag==tolower(cmd->tag))?TRUE:FALSE); - if (cmd->args<0) cmd->args=count_args(FALSE); - if (cmd->args<0) { - error(ERROR,"only numerical indices allowed for arrays"); - return; - } - s=get_sym(cmd->name,syARRAY,local?amADD_LOCAL:amADD_GLOBAL); - if (search_label(cmd->name,smSUB|smLINK)) { - sprintf(string,"array '%s()' conflicts with user subroutine",strip(cmd->name)); - error(ERROR,string); - return; - } - - /* check for dimensions */ - if (cmd->args>10) { - error(ERROR,"more than 10 indices"); - return; - } - oar=s->pointer; - if (oar) { - /* check, if old and new array are compatible */ - if (cmd->args!=oar->dimension) { - sprintf(string,"cannot change dimension of '%s()' from %d to %d", - strip(cmd->name),oar->dimension,cmd->args); - error(ERROR,string); - } - } - /* check, if redim is actually needed */ - for(i=0;i<10;i++) nbounds[i]=0; - larger=FALSE; - for(i=0;iargs;i++) { - nbounds[i]=1+(int)pop(stNUMBER)->value; - if (nbounds[i]<=1) { - sprintf(string,"array index %d is less or equal zero",cmd->args-i); - error(ERROR,string); - return; - } - if (oar) { - if (nbounds[i]>oar->bounds[i]) - larger=TRUE; - else - nbounds[i]=oar->bounds[i]; - } - } - pop(stFREE); /* remove left over stFREE */ - if (oar && !larger) return; /* new array won't be larger than old one */ - - /* create array */ - nar=create_array(tolower(cmd->tag),cmd->args); - - /* count needed memory */ - ntotal=1; - for(i=0;idimension;i++) { - (nar->bounds)[i]=nbounds[i]; - ntotal*=nbounds[i]; - } - esize=(nar->type=='s')?sizeof(char *):sizeof(double); /* size of one array element */ - nar->pointer=my_malloc(ntotal*esize); - - if (oar) { /* array already exists, get its size */ - ototal=1; - for(i=0;idimension;i++) ototal*=(oar->bounds)[i]; - } - - /* initialize Array */ - for(i=0;itype=='s') { - nul=my_malloc(sizeof(char)); - *nul='\0'; - ((char **)nar->pointer)[i]=nul; - } else { - ((double *)nar->pointer)[i]=0.0; - } - } - - if (oar) { /* copy contents of old array onto new */ - for(i=0;ibounds,ind); - j=ind_to_off(ind,nar->bounds); - if (nar->type=='s') { - my_free(((char **)nar->pointer)[j]); - ((char **)nar->pointer)[j]= ((char **)oar->pointer)[i]; - } else { - ((double *)nar->pointer)[j]= ((double *)oar->pointer)[i]; - } - } - my_free(oar->pointer); - my_free(oar); - } - - s->pointer=nar; - cmd->symbol=nar; -} - - -static int ind_to_off(int *ind,int *bound) /* convert array of indices to single offset */ -{ - int i; - int cur,off; - - off=0; - cur=1; - for(i=0;i<10 && bound[i];i++) { - off+=ind[i]*cur; - cur*=bound[i]; - } - return off; -} - - -static void off_to_ind(int off,int *bound,int *ind) /* convert a single offset to an array of indices */ -{ - int i; - int cur; - - cur=1; - for(i=0;i<10;i++) { - if (bound[i]) cur*=bound[i]; - ind[i]=0; - } - for(i=9;i>=0;i--) { - if (bound[i]) { - cur/=bound[i]; - ind[i]=off/cur; - off-=ind[i]*cur; - } else { - ind[i]=0; - } - } -} - - -void query_array(struct command *cmd) /* query array */ -{ - int index; - struct stackentry *s; - struct array *ar; - struct symbol *sym; - - if (cmd->type==cARSIZE) index=(int)pop(stNUMBER)->value; - - s=pop(stSTRING_OR_NUMBER_ARRAYREF); - - if (!cmd->symbol) { - sym=get_sym(s->pointer,syARRAY,amSEARCH); - if (!sym || !sym->pointer) { - sprintf(string,"array '%s()' is not defined",strip(s->pointer)); - error(ERROR,string); - return; - } - cmd->symbol=sym; - } - - ar=((struct symbol *)cmd->symbol)->pointer; - - if (cmd->type==cARSIZE && (index<1 || index>ar->dimension)) { - sprintf(string,"only indices between 1 and %d allowed",ar->dimension); - error(ERROR,string); - return; - } - s=push(); - s->type=stNUMBER; - if (cmd->type==cARSIZE) - s->value=ar->bounds[ar->dimension-index]-1; - else - s->value=ar->dimension; - - return; -} - - -void create_doarray(char *symbol,int command) /* creates array-commands */ -{ - struct command *cmd; - - cmd=add_command(cDOARRAY,symbol); - cmd->tag=command; /* operation to perform */ - cmd->args=-1; -} - - -void doarray(struct command *cmd) /* call an array */ -{ - struct array *ar; - struct stackentry *stack; - struct symbol *sym; - void *p; - char **str; - double *dbl; - int i,j,bnd,index,cur,rval; - - - if (!cmd->symbol) { - sym=get_sym(cmd->name,syARRAY,amSEARCH); - if (!sym || !sym->pointer) { - sprintf(string,"'%s()' is neither array nor subroutine",strip(cmd->name)); - error(ERROR,string); - return; - } - cmd->symbol=sym; - } - rval=(current->tag==CALLARRAY || current->tag==CALLSTRINGARRAY || current->tag==GETSTRINGPOINTER); - if (cmd->args<0) cmd->args=count_args(!rval); - if (cmd->args<0) { - error(ERROR,"only numerical indices allowed for arrays"); - return; - } - cmd->args=abs(cmd->args); - if (!cmd->args) { /* no indizes supplied, create a reference to an array */ - pop(stFREE); /* remove left over stFREE */ - stack=push(); - if (cmd->tag==CALLARRAY) - stack->type=stNUMBERARRAYREF; - else - stack->type=stSTRINGARRAYREF; - stack->pointer=my_strdup(cmd->name); - return; - } - - ar=((struct symbol *)cmd->symbol)->pointer; - - if (!ar->dimension) { - sprintf(string,"array parameter '%s()' has not been supplied",strip(cmd->name)); - error(ERROR,string); - return; - } - if (cmd->args!=ar->dimension) { - sprintf(string,"%d indices supplied, %d expected for '%s()'",cmd->args,ar->dimension,strip(cmd->name)); - error(ERROR,string); - return; - } - - if (!rval) stack=pop(stSTRING_OR_NUMBER); - index=0; - cur=1; - for(i=0;idimension;i++) { - bnd=(ar->bounds[i]); - j=(int)pop(stNUMBER)->value; - if (j<0 || j>=bnd) { - sprintf(string,"index %d (=%d) out of range",ar->dimension-i,j); - error(ERROR,string); - return; - } - index+=j*cur; - cur*=bnd; - } - - pop(stFREE); /* remove left over stFREE */ - if (rval) stack=push(); - - p=ar->pointer; - switch(current->tag) { - case CALLARRAY: - dbl=(double *)p+index; - stack->value= *dbl; - stack->type=stNUMBER; - break; - case ASSIGNARRAY: - dbl=(double *)p+index; - *dbl=stack->value; - break; - case CALLSTRINGARRAY: - str=((char **)p+index); - stack->pointer=my_strdup(*str); - stack->type=stSTRING; - break; - case ASSIGNSTRINGARRAY: - str=((char **)p+index); - if (*str!=NULL)my_free(*str); - *str=my_strdup(stack->pointer); - break; - case GETSTRINGPOINTER: - str=((char **)p+index); - stack->pointer=*str; - stack->type=stSTRING; - break; - } -} - - -struct array *create_array(int type,int dimension) /* create an array */ -{ - int i; - struct array *ar; - - ar=my_malloc(sizeof(struct array)); - ar->type=type; - ar->dimension=dimension; - ar->pointer=NULL; - for(i=0;i<10;i++) ar->bounds[i]=0; - - return ar; -} - - -static int count_args(int skipfirst) /* count number of numeric arguments on stack */ -{ - int i=0; - int sign=1; - struct stackentry *curr; - - curr=stackhead->prev; - if (skipfirst) curr=curr->prev; - while(curr) { - if (curr->type==stFREE) return i*sign; - if (curr->type!=stNUMBER) sign=-1; - curr=curr->prev; - i++; - } - return -1; -} - - -void skipper() -/* used for on_goto/gosub, skip specified number of commands */ -{ - int i,len; - struct command *ahead; /* command to follow */ - - len=(int)pop(stNUMBER)->value; - i=1; - current=current->next; /* advance to first goto/gosub */ - for(i=1;inext->next; /* skip interleaving findnop statement */ - if (ahead->type==cNOP) - break; - else - current=ahead; - } -} - - -void skiponce(struct command *cmd) /* skip next command exectly once */ -{ - if (cmd->tag) current=current->next; - cmd->tag=0; -} - - -void resetskiponce(struct command *cmd) /* find and reset next skip */ -{ - struct command *c; - - c=cmd; - while(c->type!=cSKIPONCE) c=c->next; - c->tag=1; -} - -void create_break_mark(int minor,int major) /* create marks for break */ -{ - struct command *cmd; - - in_loop+=major; - cmd=add_command(cBREAK_MARK,NULL); - cmd->tag=(major+2)*16+minor+2; -} - - -void next_case(void) /* go to next case in switch statement */ -{ - if (stackhead->prev->type==stSTRING || stackhead->prev->type==stSWITCH_STRING) - stackhead->prev->type=stSWITCH_STRING; - else - stackhead->prev->type=stSWITCH_NUMBER; -} - - -void push_switch_id(void) /* generate a new switch id */ -{ - static int max_switch_id=0; - static int switch_stack_depth=1; - - struct switch_id *new_id; - if (switch_id_stackhead==NULL || switch_id_stackhead->next==NULL) { - if (switch_id_stackroot && switch_id_stackhead==NULL) { - new_id=switch_id_stackroot; - } else { - new_id=my_malloc(sizeof(struct switch_id)); - new_id->next=NULL; - new_id->depth=switch_stack_depth++; - } - } else { - new_id=switch_id_stackhead->next; - } - max_switch_id++; - new_id->id=max_switch_id; - if (switch_id_stackhead==NULL) { - switch_id_stackhead=new_id; - switch_id_stackhead->prev=NULL; - } else { - switch_id_stackhead->next=new_id; - new_id->prev=switch_id_stackhead; - switch_id_stackhead=new_id; - } -} - - -void pop_switch_id(void) /* get previous switch id */ -{ - if (switch_id_stackhead) switch_id_stackhead=switch_id_stackhead->prev; -} - - -int get_switch_id(void) /* get current switch id */ -{ - return switch_id_stackhead ? switch_id_stackhead->id : 0; -} - - -int get_switch_depth(void) /* get current depth of switch id stack */ -{ - return switch_id_stackhead ? switch_id_stackhead->depth : 0; -} - - -void push_switch_mark(void) /* push a switch mark */ -{ - push()->type=stSWITCH_MARK; -} - - -void create_clean_switch_mark(int keep,int ret) /* add command clean_switch_mark */ -{ - struct command *cmd; - - cmd=add_command(cCLEAN_SWITCH_MARK,NULL); - cmd->args=keep; - cmd->tag=ret; -} - - -void clean_switch_mark(struct command *cmd) /* pop everything up to (and including) first switch_mark from stack */ -{ - struct stackentry *t,*tt,*b,*bb,*s; - int keep,k,ret; - - k=keep=cmd->args; - ret=cmd->tag; - s=stackhead->prev; - while(k && s!=stackroot) { - k--; - s=s->prev; - } - t=s; - tt=s->next; - while(((ret && s->type!=stRETADDCALL) || (!ret && s->type!=stSWITCH_MARK)) && s!=stackroot) { - s=s->prev; - } - if (ret) { - bb=s; - b=s->next; - } else { - b=s; - bb=s->prev; - } - - /* cut part between (and including) b and t out of stack */ - bb->next=tt; - tt->prev=bb; - /* insert cut-out part between stackhead and stackhead->prev */ - stackhead->prev->next=b; - b->prev=stackhead->prev; - t->next=stackhead; - stackhead->prev=t; - if (keep) - stackhead=tt->next; - else - stackhead=bb->next; -} - - -void mybreak(struct command *cmd) /* find break_here statement */ -{ - struct command *curr; - int major,minor; - int major_nesting=0; - int minor_nesting=0; - - if (cmd->type==cBREAK) - major_nesting=1; - else - minor_nesting=0; - curr=cmd; - while(curr->type!=cBREAK_HERE || major_nesting || minor_nesting) { - if (curr->type==cBREAK_MARK) { - minor=(curr->tag&15)-2; - major=((curr->tag&240)/16)-2; - if (!major_nesting) minor_nesting+=minor; - major_nesting+=major; - if (infolevel>=DEBUG) { - sprintf(string,"searching break-mark: diff(%d,%d), total(%d,%d)",minor,major,minor_nesting,major_nesting); - error(DEBUG,string); - } - } - curr=curr->next; - if (!curr) error(FATAL,"break has left program"); - } - cmd->type=cQGOTO; - if (infolevel>=DEBUG) error(DEBUG,"converting cBREAK to cQGOTO"); - cmd->jump=current=curr; -} - - -void mycontinue(struct command *cmd) /* find continue_here statement */ -{ - struct command *curr; - int major; - int major_nesting=-1; - - curr=cmd; - while(curr->type!=cCONTINUE_HERE || major_nesting) { - if (curr->type==cBREAK_MARK) { - major=((curr->tag&240)>>4)-2; - major_nesting+=major; - } - if (curr->type==cCONTINUE_CORRECTION) major_nesting--; - curr=curr->prev; - if (!curr) error(FATAL,"continue has left program"); - } - cmd->type=cQGOTO; - if (infolevel>=DEBUG) error(DEBUG,"converting cCONTINUE to cQGOTO"); - cmd->jump=current=curr; -} - - -void findnop() -/* used for on_gosub, find trailing nop command */ -{ - while(current->type!=cNOP) { - current=current->next; /* next label */ - } -} - - -void forcheck(void) /* check, if for-loop is done */ -{ - double start,bound,step,val; - - val=pop(stNUMBER)->value; - step=pop(stNUMBER)->value; - bound=pop(stNUMBER)->value; - start=stackhead->prev->value; - if ((val<=bound && val>=start && step>=0) || (val<=start && val>=bound && step<=0)) - stackhead->prev->value=1.; - else - stackhead->prev->value=0.; -} - - -void forincrement(void) /* increment value on stack */ -{ -/* expecting on stack: BOUND,STEP,VAL,stackhead - where for VAL=START to BOUND step STEP */ - stackhead->prev->value+=stackhead->prev->prev->value; -} - - -void startfor(void) /* compute initial value of for-variable */ -{ - struct stackentry *p; - - p=push(); - p->value=stackhead->prev->prev->prev->prev->value-stackhead->prev->prev->value; - p->type=stNUMBER; - - return; -} - - diff --git a/src/yabasic.bison b/src/yabasic.bison deleted file mode 100644 index d19f24c..0000000 --- a/src/yabasic.bison +++ /dev/null @@ -1,944 +0,0 @@ -%{ -/* - - 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 - -#if HAVE_ALLOCA_H -#ifndef WINDOWS -#include -#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 const -%type number -%type symbol_or_lineno -%type function_name -%type function_or_array -%type stringfunction_or_array -%type tSEP sep_list - -%token tFNUM -%token tSYMBOL -%token tSTRSYM -%token tDOCU -%token tDIGITS -%token 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 tTOOLTIPNEW tCALENDAR -%token tCLIPBOARD tCOPY tSUBMENU tSELECT tSCROLLBAR tEXPAND tCOLLAPSE tSPLITVIEW tSTACKVIEW -%token tPOPUPMENU tSPINCONTROL tMSEND tNUMMESSAGE tTHREAD tSOUND tPLAY tSTOP tMEDIASOUND 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);} - | tTOOLTIPNEW string_expression ',' string_expression ',' string_expression ',' expression ',' expression ',' expression {add_command(cTOOLTIPNEW,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);} - | tMEDIASOUND tSTOP expression {add_command(cMEDIASOUNDSTOP,NULL);} - | tMEDIASOUND tSTOP '(' expression ')' {add_command(cMEDIASOUNDSTOP,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);} - | tMEDIASOUND tPLAY string_expression {create_function(fMEDIASOUND);} - | 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);} - ; - diff --git a/src/yabasic.flex b/src/yabasic.flex deleted file mode 100644 index e74b317..0000000 --- a/src/yabasic.flex +++ /dev/null @@ -1,562 +0,0 @@ -%{ -/* - - 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 -#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 - -%% -<> { - 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;} -[0-9]+ { - BEGIN(PASTLNO); - yylval.symbol=(char *)my_strdup(yytext); - return tSYMBOL; -} -.* {BEGIN(INITIAL);flex_line+=yylval.sep=0;yyless(0);return tSEP;} -\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);} -{WS}+{NAME} {if (!import_lib(yytext)) return 0;BEGIN(IMPORT_DONE);return tIMPORT;} -(.|\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; -TOOLTIPNEW return tTOOLTIPNEW; -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; -MEDIASOUND return tMEDIASOUND; -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); -} - - diff --git a/src/yabasic.h b/src/yabasic.h deleted file mode 100644 index 471529e..0000000 --- a/src/yabasic.h +++ /dev/null @@ -1,888 +0,0 @@ -/* - - 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 -#include -#include -#include -#include -#include -#include -#include -#ifdef WINDOWS -#include -#include -#include -#define ARCHITECTURE "windows" -#ifdef __LCC__ /* fix for lccwin32 */ -#include -#endif -#endif - -#include "YabInterface.h" - - -#ifdef UNIX -#define ARCHITECTURE UNIX_ARCHITECTURE -#ifdef HAS_STRING_HEADER -#include -#elif HAS_STRINGS_HEADER -#include -#endif - -#include -#include - -#ifndef BEOS - #include - #include - #include - #include - #define XK_LATIN1 - #define XK_MISCELLANY - #include -#endif - -#include -#include -#ifdef BUILD_NCURSES -#include -// #else -// #ifdef HAVE_CURSES_HEADER -// #include -// #endif -#endif -#ifndef KEY_MAX -#define KEY_MAX 0777 -#endif -#endif - -#ifndef FOPEN_MAX -#define FOPEN_MAX 24 -#endif - -#include -#include - -#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,smREADWRITE=3 -}; - -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, fMEDIASOUND, - 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, cTOOLTIPNEW, 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, cMEDIASOUNDSTOP, /* 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 doesnt 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 tooltipnew(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); -int mediasound(const char*, YabInterface *yab, int line, const char* libname); -void mediasoundstop(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 */