signs_gui.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "company_gui.h"
00014 #include "company_func.h"
00015 #include "signs_base.h"
00016 #include "signs_func.h"
00017 #include "debug.h"
00018 #include "command_func.h"
00019 #include "strings_func.h"
00020 #include "window_func.h"
00021 #include "map_func.h"
00022 #include "gfx_func.h"
00023 #include "viewport_func.h"
00024 #include "querystring_gui.h"
00025 #include "sortlist_type.h"
00026 #include "string_func.h"
00027 #include "core/geometry_func.hpp"
00028 #include "hotkeys.h"
00029 #include "transparency.h"
00030 
00031 #include "widgets/sign_widget.h"
00032 
00033 #include "table/strings.h"
00034 #include "table/sprites.h"
00035 
00041 struct FilterInfo {
00042   const char *string;  
00043   bool case_sensitive; 
00044 };
00045 
00046 struct SignList {
00051   typedef GUIList<const Sign *, FilterInfo> GUISignList;
00052 
00053   static const Sign *last_sign;
00054   GUISignList signs;
00055 
00056   char filter_string[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH]; 
00057   static bool match_case;                                           
00058 
00062   SignList()
00063   {
00064     filter_string[0] = '\0';
00065   }
00066 
00067   void BuildSignsList()
00068   {
00069     if (!this->signs.NeedRebuild()) return;
00070 
00071     DEBUG(misc, 3, "Building sign list");
00072 
00073     this->signs.Clear();
00074 
00075     const Sign *si;
00076     FOR_ALL_SIGNS(si) *this->signs.Append() = si;
00077 
00078     this->signs.SetFilterState(true);
00079     this->FilterSignList();
00080     this->signs.Compact();
00081     this->signs.RebuildDone();
00082   }
00083 
00085   static int CDECL SignNameSorter(const Sign * const *a, const Sign * const *b)
00086   {
00087     static char buf_cache[64];
00088     char buf[64];
00089 
00090     SetDParam(0, (*a)->index);
00091     GetString(buf, STR_SIGN_NAME, lastof(buf));
00092 
00093     if (*b != last_sign) {
00094       last_sign = *b;
00095       SetDParam(0, (*b)->index);
00096       GetString(buf_cache, STR_SIGN_NAME, lastof(buf_cache));
00097     }
00098 
00099     int r = strnatcmp(buf, buf_cache); // Sort by name (natural sorting).
00100 
00101     return r != 0 ? r : ((*a)->index - (*b)->index);
00102   }
00103 
00104   void SortSignsList()
00105   {
00106     if (!this->signs.Sort(&SignNameSorter)) return;
00107 
00108     /* Reset the name sorter sort cache */
00109     this->last_sign = NULL;
00110   }
00111 
00113   static bool CDECL SignNameFilter(const Sign * const *a, FilterInfo filter_info)
00114   {
00115     /* Get sign string */
00116     char buf1[MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH];
00117     SetDParam(0, (*a)->index);
00118     GetString(buf1, STR_SIGN_NAME, lastof(buf1));
00119 
00120     return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
00121   }
00122 
00124   static bool CDECL OwnerDeityFilter(const Sign * const *a, FilterInfo filter_info)
00125   {
00126     /* You should never be able to edit signs of owner DEITY */
00127     return (*a)->owner != OWNER_DEITY;
00128   }
00129 
00131   static bool CDECL OwnerVisibilityFilter(const Sign * const *a, FilterInfo filter_info)
00132   {
00133     assert(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
00134     /* Hide sign if non-own signs are hidden in the viewport */
00135     return (*a)->owner == _local_company;
00136   }
00137 
00139   void FilterSignList()
00140   {
00141     FilterInfo filter_info = {this->filter_string, this->match_case};
00142     this->signs.Filter(&SignNameFilter, filter_info);
00143     this->signs.Filter(&OwnerDeityFilter, filter_info);
00144     if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
00145       this->signs.Filter(&OwnerVisibilityFilter, filter_info);
00146     }
00147   }
00148 };
00149 
00150 const Sign *SignList::last_sign = NULL;
00151 bool SignList::match_case = false;
00152 
00154 enum SignListHotkeys {
00155   SLHK_FOCUS_FILTER_BOX, 
00156 };
00157 
00158 struct SignListWindow : QueryStringBaseWindow, SignList {
00159   int text_offset; 
00160   Scrollbar *vscroll;
00161 
00162   SignListWindow(const WindowDesc *desc, WindowNumber window_number) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00163   {
00164     this->CreateNestedTree(desc);
00165     this->vscroll = this->GetScrollbar(WID_SIL_SCROLLBAR);
00166     this->FinishInitNested(desc, window_number);
00167     this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case);
00168 
00169     /* Initialize the text edit widget */
00170     this->afilter = CS_ALPHANUMERAL;
00171     InitializeTextBuffer(&this->text, this->edit_str_buf, MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS);
00172     ClearFilterTextWidget();
00173 
00174     /* Initialize the filtering variables */
00175     this->SetFilterString("");
00176 
00177     /* Create initial list. */
00178     this->signs.ForceRebuild();
00179     this->signs.ForceResort();
00180     this->BuildSortSignList();
00181   }
00182 
00187   void ClearFilterTextWidget()
00188   {
00189     this->edit_str_buf[0] = '\0';
00190     UpdateTextBufferSize(&this->text);
00191 
00192     this->SetWidgetDirty(WID_SIL_FILTER_TEXT);
00193   }
00194 
00201   void SetFilterString(const char *new_filter_string)
00202   {
00203     /* check if there is a new filter string */
00204     if (!StrEmpty(new_filter_string)) {
00205       /* Copy new filter string */
00206       strecpy(this->filter_string, new_filter_string, lastof(this->filter_string));
00207 
00208       this->EnableWidget(WID_SIL_FILTER_CLEAR_BTN);
00209     } else {
00210       /* There is no new string -> clear this->filter_string */
00211       this->filter_string[0] = '\0';
00212 
00213       this->DisableWidget(WID_SIL_FILTER_CLEAR_BTN);
00214     }
00215 
00216     /* Repaint the clear button since its disabled state may have changed */
00217     this->SetWidgetDirty(WID_SIL_FILTER_CLEAR_BTN);
00218 
00219     /* Rebuild the list of signs */
00220     this->InvalidateData();
00221   }
00222 
00223   virtual void OnPaint()
00224   {
00225     if (this->signs.NeedRebuild()) this->BuildSortSignList();
00226     this->DrawWidgets();
00227     if (!this->IsShaded()) this->DrawEditBox(WID_SIL_FILTER_TEXT);
00228   }
00229 
00230   virtual void DrawWidget(const Rect &r, int widget) const
00231   {
00232     switch (widget) {
00233       case WID_SIL_LIST: {
00234         uint y = r.top + WD_FRAMERECT_TOP; // Offset from top of widget.
00235         /* No signs? */
00236         if (this->vscroll->GetCount() == 0) {
00237           DrawString(r.left + WD_FRAMETEXT_LEFT, r.right, y, STR_STATION_LIST_NONE);
00238           return;
00239         }
00240 
00241         bool rtl = _current_text_dir == TD_RTL;
00242         int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 + 1;
00243         uint icon_left  = 4 + (rtl ? r.right - this->text_offset : r.left);
00244         uint text_left  = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
00245         uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
00246 
00247         /* At least one sign available. */
00248         for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
00249           const Sign *si = this->signs[i];
00250 
00251           if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, icon_left, y + sprite_offset_y);
00252 
00253           SetDParam(0, si->index);
00254           DrawString(text_left, text_right, y, STR_SIGN_NAME, TC_YELLOW);
00255           y += this->resize.step_height;
00256         }
00257         break;
00258       }
00259     }
00260   }
00261 
00262   virtual void SetStringParameters(int widget) const
00263   {
00264     if (widget == WID_SIL_CAPTION) SetDParam(0, this->vscroll->GetCount());
00265   }
00266 
00267   virtual void OnClick(Point pt, int widget, int click_count)
00268   {
00269     switch (widget) {
00270       case WID_SIL_LIST: {
00271         uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SIL_LIST, WD_FRAMERECT_TOP);
00272         if (id_v == INT_MAX) return;
00273 
00274         const Sign *si = this->signs[id_v];
00275         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00276         break;
00277       }
00278       case WID_SIL_FILTER_CLEAR_BTN:
00279         this->ClearFilterTextWidget(); // Empty the text in the EditBox widget
00280         this->SetFilterString("");     // Use empty text as filter text (= view all signs)
00281         break;
00282 
00283       case WID_SIL_FILTER_MATCH_CASE_BTN:
00284         SignList::match_case = !SignList::match_case; // Toggle match case
00285         this->SetWidgetLoweredState(WID_SIL_FILTER_MATCH_CASE_BTN, SignList::match_case); // Toggle button pushed state
00286         this->InvalidateData(); // Rebuild the list of signs
00287         break;
00288     }
00289   }
00290 
00291   virtual void OnResize()
00292   {
00293     this->vscroll->SetCapacityFromWidget(this, WID_SIL_LIST, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
00294   }
00295 
00296   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00297   {
00298     switch (widget) {
00299       case WID_SIL_LIST: {
00300         Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
00301         this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2; // 2 pixels space between icon and the sign text.
00302         resize->height = max<uint>(FONT_HEIGHT_NORMAL, spr_dim.height);
00303         Dimension d = {this->text_offset + WD_FRAMETEXT_RIGHT, WD_FRAMERECT_TOP + 5 * resize->height + WD_FRAMERECT_BOTTOM};
00304         *size = maxdim(*size, d);
00305         break;
00306       }
00307 
00308       case WID_SIL_CAPTION:
00309         SetDParam(0, max<size_t>(1000, Sign::GetPoolSize()));
00310         *size = GetStringBoundingBox(STR_SIGN_LIST_CAPTION);
00311         size->height += padding.height;
00312         size->width  += padding.width;
00313         break;
00314     }
00315   }
00316 
00317   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00318   {
00319     EventState state = ES_NOT_HANDLED;
00320     switch (this->HandleEditBoxKey(WID_SIL_FILTER_TEXT, key, keycode, state)) {
00321       case HEBR_EDITING:
00322         this->SetFilterString(this->text.buf);
00323         break;
00324 
00325       case HEBR_CONFIRM: // Enter pressed -> goto first sign in list
00326         if (this->signs.Length() >= 1) {
00327           const Sign *si = this->signs[0];
00328           ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00329         }
00330         return state;
00331 
00332       case HEBR_CANCEL: // ESC pressed, clear filter.
00333         this->OnClick(Point(), WID_SIL_FILTER_CLEAR_BTN, 1); // Simulate click on clear button.
00334         this->UnfocusFocusedWidget();                    // Unfocus the text box.
00335         return state;
00336 
00337       case HEBR_NOT_FOCUSED: // The filter text box is not globaly focused.
00338         if (CheckHotkeyMatch(signlist_hotkeys, keycode, this) == SLHK_FOCUS_FILTER_BOX) {
00339           this->SetFocusedWidget(WID_SIL_FILTER_TEXT);
00340           SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
00341           state = ES_HANDLED;
00342         }
00343         break;
00344 
00345       default:
00346         NOT_REACHED();
00347     }
00348 
00349     if (state == ES_HANDLED) OnOSKInput(WID_SIL_FILTER_TEXT);
00350 
00351     return state;
00352   }
00353 
00354   virtual void OnOSKInput(int widget)
00355   {
00356     if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->text.buf);
00357   }
00358 
00359   virtual void OnMouseLoop()
00360   {
00361     this->HandleEditBox(WID_SIL_FILTER_TEXT);
00362   }
00363 
00364   void BuildSortSignList()
00365   {
00366     if (this->signs.NeedRebuild()) {
00367       this->BuildSignsList();
00368       this->vscroll->SetCount(this->signs.Length());
00369       this->SetWidgetDirty(WID_SIL_CAPTION);
00370     }
00371     this->SortSignsList();
00372   }
00373 
00374   virtual void OnHundredthTick()
00375   {
00376     this->BuildSortSignList();
00377     this->SetDirty();
00378   }
00379 
00385   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00386   {
00387     /* When there is a filter string, we always need to rebuild the list even if
00388      * the amount of signs in total is unchanged, as the subset of signs that is
00389      * accepted by the filter might has changed. */
00390     if (data == 0 || data == -1 || !StrEmpty(this->filter_string)) { // New or deleted sign, changed visibility setting or there is a filter string
00391       /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
00392       this->signs.ForceRebuild();
00393     } else { // Change of sign contents while there is no filter string
00394       this->signs.ForceResort();
00395     }
00396   }
00397 
00398   static Hotkey<SignListWindow> signlist_hotkeys[];
00399 };
00400 
00401 Hotkey<SignListWindow> SignListWindow::signlist_hotkeys[] = {
00402   Hotkey<SignListWindow>('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX),
00403   HOTKEY_LIST_END(SignListWindow)
00404 };
00405 Hotkey<SignListWindow> *_signlist_hotkeys = SignListWindow::signlist_hotkeys;
00406 
00407 static const NWidgetPart _nested_sign_list_widgets[] = {
00408   NWidget(NWID_HORIZONTAL),
00409     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00410     NWidget(WWT_CAPTION, COLOUR_GREY, WID_SIL_CAPTION), SetDataTip(STR_SIGN_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00411     NWidget(WWT_SHADEBOX, COLOUR_GREY),
00412     NWidget(WWT_STICKYBOX, COLOUR_GREY),
00413   EndContainer(),
00414   NWidget(NWID_HORIZONTAL),
00415     NWidget(NWID_VERTICAL),
00416       NWidget(WWT_PANEL, COLOUR_GREY, WID_SIL_LIST), SetMinimalSize(WD_FRAMETEXT_LEFT + 16 + 255 + WD_FRAMETEXT_RIGHT, 50),
00417                 SetResize(1, 10), SetFill(1, 0), SetScrollbar(WID_SIL_SCROLLBAR), EndContainer(),
00418       NWidget(NWID_HORIZONTAL),
00419         NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1),
00420           NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SIL_FILTER_TEXT), SetMinimalSize(80, 12), SetResize(1, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
00421               SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
00422         EndContainer(),
00423         NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SIL_FILTER_MATCH_CASE_BTN), SetDataTip(STR_SIGN_LIST_MATCH_CASE, STR_SIGN_LIST_MATCH_CASE_TOOLTIP),
00424         NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SIL_FILTER_CLEAR_BTN), SetDataTip(STR_SIGN_LIST_CLEAR, STR_SIGN_LIST_CLEAR_TOOLTIP),
00425       EndContainer(),
00426     EndContainer(),
00427     NWidget(NWID_VERTICAL),
00428       NWidget(NWID_VERTICAL), SetFill(0, 1),
00429         NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SIL_SCROLLBAR),
00430       EndContainer(),
00431       NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00432     EndContainer(),
00433   EndContainer(),
00434 };
00435 
00436 static const WindowDesc _sign_list_desc(
00437   WDP_AUTO, 358, 138,
00438   WC_SIGN_LIST, WC_NONE,
00439   WDF_UNCLICK_BUTTONS,
00440   _nested_sign_list_widgets, lengthof(_nested_sign_list_widgets)
00441 );
00442 
00448 Window *ShowSignList()
00449 {
00450   return AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
00451 }
00452 
00453 EventState SignListGlobalHotkeys(uint16 key, uint16 keycode)
00454 {
00455   int num = CheckHotkeyMatch<SignListWindow>(_signlist_hotkeys, keycode, NULL, true);
00456   if (num == -1) return ES_NOT_HANDLED;
00457   Window *w = ShowSignList();
00458   if (w == NULL) return ES_NOT_HANDLED;
00459   return w->OnKeyPress(key, keycode);
00460 }
00461 
00468 static bool RenameSign(SignID index, const char *text)
00469 {
00470   bool remove = StrEmpty(text);
00471   DoCommandP(0, index, 0, CMD_RENAME_SIGN | (StrEmpty(text) ? CMD_MSG(STR_ERROR_CAN_T_DELETE_SIGN) : CMD_MSG(STR_ERROR_CAN_T_CHANGE_SIGN_NAME)), NULL, text);
00472   return remove;
00473 }
00474 
00475 struct SignWindow : QueryStringBaseWindow, SignList {
00476   SignID cur_sign;
00477 
00478   SignWindow(const WindowDesc *desc, const Sign *si) : QueryStringBaseWindow(MAX_LENGTH_SIGN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_SIGN_NAME_CHARS)
00479   {
00480     this->caption = STR_EDIT_SIGN_CAPTION;
00481     this->afilter = CS_ALPHANUMERAL;
00482 
00483     this->InitNested(desc, WN_QUERY_STRING_SIGN);
00484 
00485     this->LowerWidget(WID_QES_TEXT);
00486     UpdateSignEditWindow(si);
00487     this->SetFocusedWidget(WID_QES_TEXT);
00488   }
00489 
00490   void UpdateSignEditWindow(const Sign *si)
00491   {
00492     char *last_of = &this->edit_str_buf[this->edit_str_size - 1]; // points to terminating '\0'
00493 
00494     /* Display an empty string when the sign hasnt been edited yet */
00495     if (si->name != NULL) {
00496       SetDParam(0, si->index);
00497       GetString(this->edit_str_buf, STR_SIGN_NAME, last_of);
00498     } else {
00499       GetString(this->edit_str_buf, STR_EMPTY, last_of);
00500     }
00501     *last_of = '\0';
00502 
00503     this->cur_sign = si->index;
00504     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, this->max_chars);
00505 
00506     this->SetWidgetDirty(WID_QES_TEXT);
00507     this->SetFocusedWidget(WID_QES_TEXT);
00508   }
00509 
00515   const Sign *PrevNextSign(bool next)
00516   {
00517     /* Rebuild the sign list */
00518     this->signs.ForceRebuild();
00519     this->signs.NeedResort();
00520     this->BuildSignsList();
00521     this->SortSignsList();
00522 
00523     /* Search through the list for the current sign, excluding
00524      * - the first sign if we want the previous sign or
00525      * - the last sign if we want the next sign */
00526     uint end = this->signs.Length() - (next ? 1 : 0);
00527     for (uint i = next ? 0 : 1; i < end; i++) {
00528       if (this->cur_sign == this->signs[i]->index) {
00529         /* We've found the current sign, so return the sign before/after it */
00530         return this->signs[i + (next ? 1 : -1)];
00531       }
00532     }
00533     /* If we haven't found the current sign by now, return the last/first sign */
00534     return this->signs[next ? 0 : this->signs.Length() - 1];
00535   }
00536 
00537   virtual void SetStringParameters(int widget) const
00538   {
00539     switch (widget) {
00540       case WID_QES_CAPTION:
00541         SetDParam(0, this->caption);
00542         break;
00543     }
00544   }
00545 
00546   virtual void OnPaint()
00547   {
00548     this->DrawWidgets();
00549     if (!this->IsShaded()) this->DrawEditBox(WID_QES_TEXT);
00550   }
00551 
00552   virtual void OnClick(Point pt, int widget, int click_count)
00553   {
00554     switch (widget) {
00555       case WID_QES_PREVIOUS:
00556       case WID_QES_NEXT: {
00557         const Sign *si = this->PrevNextSign(widget == WID_QES_NEXT);
00558 
00559         /* Rebuild the sign list */
00560         this->signs.ForceRebuild();
00561         this->signs.NeedResort();
00562         this->BuildSignsList();
00563         this->SortSignsList();
00564 
00565         /* Scroll to sign and reopen window */
00566         ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
00567         UpdateSignEditWindow(si);
00568         break;
00569       }
00570 
00571       case WID_QES_DELETE:
00572         /* Only need to set the buffer to null, the rest is handled as the OK button */
00573         RenameSign(this->cur_sign, "");
00574         /* don't delete this, we are deleted in Sign::~Sign() -> DeleteRenameSignWindow() */
00575         break;
00576 
00577       case WID_QES_OK:
00578         if (RenameSign(this->cur_sign, this->text.buf)) break;
00579         /* FALL THROUGH */
00580 
00581       case WID_QES_CANCEL:
00582         delete this;
00583         break;
00584     }
00585   }
00586 
00587   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00588   {
00589     EventState state = ES_NOT_HANDLED;
00590     switch (this->HandleEditBoxKey(WID_QES_TEXT, key, keycode, state)) {
00591       default: break;
00592 
00593       case HEBR_CONFIRM:
00594         if (RenameSign(this->cur_sign, this->text.buf)) break;
00595         /* FALL THROUGH */
00596 
00597       case HEBR_CANCEL: // close window, abandon changes
00598         delete this;
00599         break;
00600     }
00601     return state;
00602   }
00603 
00604   virtual void OnMouseLoop()
00605   {
00606     this->HandleEditBox(WID_QES_TEXT);
00607   }
00608 
00609   virtual void OnOpenOSKWindow(int wid)
00610   {
00611     ShowOnScreenKeyboard(this, wid, WID_QES_CANCEL, WID_QES_OK);
00612   }
00613 };
00614 
00615 static const NWidgetPart _nested_query_sign_edit_widgets[] = {
00616   NWidget(NWID_HORIZONTAL),
00617     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00618     NWidget(WWT_CAPTION, COLOUR_GREY, WID_QES_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00619   EndContainer(),
00620   NWidget(WWT_PANEL, COLOUR_GREY),
00621     NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QES_TEXT), SetMinimalSize(256, 12), SetDataTip(STR_EDIT_SIGN_SIGN_OSKTITLE, STR_NULL), SetPadding(2, 2, 2, 2),
00622   EndContainer(),
00623   NWidget(NWID_HORIZONTAL),
00624     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_OK), SetMinimalSize(61, 12), SetDataTip(STR_BUTTON_OK, STR_NULL),
00625     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_CANCEL), SetMinimalSize(60, 12), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
00626     NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_QES_DELETE), SetMinimalSize(60, 12), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_NULL),
00627     NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), EndContainer(),
00628     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_PREVIOUS), SetMinimalSize(11, 12), SetDataTip(AWV_DECREASE, STR_EDIT_SIGN_PREVIOUS_SIGN_TOOLTIP),
00629     NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_QES_NEXT), SetMinimalSize(11, 12), SetDataTip(AWV_INCREASE, STR_EDIT_SIGN_NEXT_SIGN_TOOLTIP),
00630   EndContainer(),
00631 };
00632 
00633 static const WindowDesc _query_sign_edit_desc(
00634   WDP_AUTO, 0, 0,
00635   WC_QUERY_STRING, WC_NONE,
00636   WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
00637   _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets)
00638 );
00639 
00644 void HandleClickOnSign(const Sign *si)
00645 {
00646   if (_ctrl_pressed && si->owner == _local_company) {
00647     RenameSign(si->index, NULL);
00648     return;
00649   }
00650   ShowRenameSignWindow(si);
00651 }
00652 
00657 void ShowRenameSignWindow(const Sign *si)
00658 {
00659   /* Delete all other edit windows */
00660   DeleteWindowByClass(WC_QUERY_STRING);
00661 
00662   new SignWindow(&_query_sign_edit_desc, si);
00663 }
00664 
00669 void DeleteRenameSignWindow(SignID sign)
00670 {
00671   SignWindow *w = dynamic_cast<SignWindow *>(FindWindowById(WC_QUERY_STRING, WN_QUERY_STRING_SIGN));
00672 
00673   if (w != NULL && w->cur_sign == sign) delete w;
00674 }